Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
c850c41e
Commit
c850c41e
authored
Jun 19, 2015
by
obscuren
Committed by
Jeffrey Wilcke
Jun 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie: Implemented a batch write approach for flushing
parent
76821d16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
cache.go
trie/cache.go
+18
-8
No files found.
trie/cache.go
View file @
c850c41e
package
trie
package
trie
import
"github.com/ethereum/go-ethereum/logger/glog"
import
(
"github.com/ethereum/go-ethereum/compression/rle"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/syndtr/goleveldb/leveldb"
)
type
Backend
interface
{
type
Backend
interface
{
Get
([]
byte
)
([]
byte
,
error
)
Get
([]
byte
)
([]
byte
,
error
)
...
@@ -8,12 +13,13 @@ type Backend interface {
...
@@ -8,12 +13,13 @@ type Backend interface {
}
}
type
Cache
struct
{
type
Cache
struct
{
batch
*
leveldb
.
Batch
store
map
[
string
][]
byte
store
map
[
string
][]
byte
backend
Backend
backend
Backend
}
}
func
NewCache
(
backend
Backend
)
*
Cache
{
func
NewCache
(
backend
Backend
)
*
Cache
{
return
&
Cache
{
make
(
map
[
string
][]
byte
),
backend
}
return
&
Cache
{
new
(
leveldb
.
Batch
),
make
(
map
[
string
][]
byte
),
backend
}
}
}
func
(
self
*
Cache
)
Get
(
key
[]
byte
)
[]
byte
{
func
(
self
*
Cache
)
Get
(
key
[]
byte
)
[]
byte
{
...
@@ -26,19 +32,23 @@ func (self *Cache) Get(key []byte) []byte {
...
@@ -26,19 +32,23 @@ func (self *Cache) Get(key []byte) []byte {
}
}
func
(
self
*
Cache
)
Put
(
key
[]
byte
,
data
[]
byte
)
{
func
(
self
*
Cache
)
Put
(
key
[]
byte
,
data
[]
byte
)
{
// write the data to the ldb batch
self
.
batch
.
Put
(
key
,
rle
.
Compress
(
data
))
self
.
store
[
string
(
key
)]
=
data
self
.
store
[
string
(
key
)]
=
data
}
}
// Flush flushes the trie to the backing layer. If this is a leveldb instance
// we'll use a batched write, otherwise we'll use regular put.
func
(
self
*
Cache
)
Flush
()
{
func
(
self
*
Cache
)
Flush
()
{
for
k
,
v
:=
range
self
.
store
{
if
db
,
ok
:=
self
.
backend
.
(
*
ethdb
.
LDBDatabase
);
ok
{
if
err
:=
self
.
backend
.
Put
([]
byte
(
k
),
v
);
err
!=
nil
{
if
err
:=
db
.
LDB
()
.
Write
(
self
.
batch
,
nil
);
err
!=
nil
{
glog
.
Fatal
(
"db write err:"
,
err
)
glog
.
Fatal
(
"db write err:"
,
err
)
}
}
}
else
{
for
k
,
v
:=
range
self
.
store
{
self
.
backend
.
Put
([]
byte
(
k
),
v
)
}
}
}
// This will eventually grow too large. We'd could
// do a make limit on storage and push out not-so-popular nodes.
//self.Reset()
}
}
func
(
self
*
Cache
)
Copy
()
*
Cache
{
func
(
self
*
Cache
)
Copy
()
*
Cache
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment