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
c7e7778f
Commit
c7e7778f
authored
Jul 22, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd, core, eth, ethdb: cache flag to allocate memory for db internal use
parent
f1daed65
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
15 deletions
+43
-15
main.go
cmd/geth/main.go
+2
-1
flags.go
cmd/utils/flags.go
+12
-4
bench_test.go
core/bench_test.go
+1
-1
backend.go
eth/backend.go
+2
-1
database.go
ethdb/database.go
+25
-6
database_test.go
ethdb/database_test.go
+1
-2
No files found.
cmd/geth/main.go
View file @
c7e7778f
...
...
@@ -281,6 +281,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils
.
BootnodesFlag
,
utils
.
DataDirFlag
,
utils
.
BlockchainVersionFlag
,
utils
.
CacheFlag
,
utils
.
JSpathFlag
,
utils
.
ListenPortFlag
,
utils
.
MaxPeersFlag
,
...
...
@@ -492,7 +493,7 @@ func blockRecovery(ctx *cli.Context) {
cfg
:=
utils
.
MakeEthConfig
(
ClientIdentifier
,
nodeNameVersion
,
ctx
)
utils
.
CheckLegalese
(
cfg
.
DataDir
)
blockDb
,
err
:=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
cfg
.
DataDir
,
"blockchain"
))
blockDb
,
err
:=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
cfg
.
DataDir
,
"blockchain"
)
,
cfg
.
DatabaseCache
)
if
err
!=
nil
{
glog
.
Fatalln
(
"could not open db:"
,
err
)
}
...
...
cmd/utils/flags.go
View file @
c7e7778f
...
...
@@ -126,6 +126,11 @@ var (
Name
:
"natspec"
,
Usage
:
"Enable NatSpec confirmation notice"
,
}
CacheFlag
=
cli
.
IntFlag
{
Name
:
"cache"
,
Usage
:
"Megabytes of memory allocated to internal caching"
,
Value
:
0
,
}
// miner settings
MinerThreadsFlag
=
cli
.
IntFlag
{
...
...
@@ -384,6 +389,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
GenesisNonce
:
ctx
.
GlobalInt
(
GenesisNonceFlag
.
Name
),
GenesisFile
:
ctx
.
GlobalString
(
GenesisFileFlag
.
Name
),
BlockChainVersion
:
ctx
.
GlobalInt
(
BlockchainVersionFlag
.
Name
),
DatabaseCache
:
ctx
.
GlobalInt
(
CacheFlag
.
Name
),
SkipBcVersionCheck
:
false
,
NetworkId
:
ctx
.
GlobalInt
(
NetworkIdFlag
.
Name
),
LogFile
:
ctx
.
GlobalString
(
LogFileFlag
.
Name
),
...
...
@@ -425,15 +431,17 @@ func SetupLogger(ctx *cli.Context) {
// MakeChain creates a chain manager from set command line flags.
func
MakeChain
(
ctx
*
cli
.
Context
)
(
chain
*
core
.
ChainManager
,
blockDB
,
stateDB
,
extraDB
common
.
Database
)
{
dd
:=
ctx
.
GlobalString
(
DataDirFlag
.
Name
)
datadir
:=
ctx
.
GlobalString
(
DataDirFlag
.
Name
)
cache
:=
ctx
.
GlobalInt
(
CacheFlag
.
Name
)
var
err
error
if
blockDB
,
err
=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
d
d
,
"blockchain"
)
);
err
!=
nil
{
if
blockDB
,
err
=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
d
atadir
,
"blockchain"
),
cache
);
err
!=
nil
{
Fatalf
(
"Could not open database: %v"
,
err
)
}
if
stateDB
,
err
=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
d
d
,
"state"
)
);
err
!=
nil
{
if
stateDB
,
err
=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
d
atadir
,
"state"
),
cache
);
err
!=
nil
{
Fatalf
(
"Could not open database: %v"
,
err
)
}
if
extraDB
,
err
=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
d
d
,
"extra"
)
);
err
!=
nil
{
if
extraDB
,
err
=
ethdb
.
NewLDBDatabase
(
filepath
.
Join
(
d
atadir
,
"extra"
),
cache
);
err
!=
nil
{
Fatalf
(
"Could not open database: %v"
,
err
)
}
...
...
core/bench_test.go
View file @
c7e7778f
...
...
@@ -153,7 +153,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
b
.
Fatalf
(
"cannot create temporary directory: %v"
,
err
)
}
defer
os
.
RemoveAll
(
dir
)
db
,
err
=
ethdb
.
NewLDBDatabase
(
dir
)
db
,
err
=
ethdb
.
NewLDBDatabase
(
dir
,
0
)
if
err
!=
nil
{
b
.
Fatalf
(
"cannot create temporary database: %v"
,
err
)
}
...
...
eth/backend.go
View file @
c7e7778f
...
...
@@ -80,6 +80,7 @@ type Config struct {
BlockChainVersion
int
SkipBcVersionCheck
bool
// e.g. blockchain export
DatabaseCache
int
DataDir
string
LogFile
string
...
...
@@ -261,7 +262,7 @@ func New(config *Config) (*Ethereum, error) {
newdb
:=
config
.
NewDB
if
newdb
==
nil
{
newdb
=
func
(
path
string
)
(
common
.
Database
,
error
)
{
return
ethdb
.
NewLDBDatabase
(
path
)
}
newdb
=
func
(
path
string
)
(
common
.
Database
,
error
)
{
return
ethdb
.
NewLDBDatabase
(
path
,
config
.
DatabaseCache
)
}
}
blockDb
,
err
:=
newdb
(
filepath
.
Join
(
config
.
DataDir
,
"blockchain"
))
if
err
!=
nil
{
...
...
ethdb/database.go
View file @
c7e7778f
...
...
@@ -17,6 +17,7 @@
package
ethdb
import
(
"path/filepath"
"strconv"
"strings"
"sync"
...
...
@@ -36,6 +37,14 @@ import (
var
OpenFileLimit
=
64
// cacheRatio specifies how the total alloted cache is distributed between the
// various system databases.
var
cacheRatio
=
map
[
string
]
float64
{
"blockchain"
:
1.0
/
13.0
,
"extra"
:
2.0
/
13.0
,
"state"
:
10.0
/
13.0
,
}
type
LDBDatabase
struct
{
fn
string
// filename for reporting
db
*
leveldb
.
DB
// LevelDB instance
...
...
@@ -57,14 +66,24 @@ type LDBDatabase struct {
// NewLDBDatabase returns a LevelDB wrapped object. LDBDatabase does not persist data by
// it self but requires a background poller which syncs every X. `Flush` should be called
// when data needs to be stored and written to disk.
func
NewLDBDatabase
(
file
string
)
(
*
LDBDatabase
,
error
)
{
// Open the db
db
,
err
:=
leveldb
.
OpenFile
(
file
,
&
opt
.
Options
{
OpenFilesCacheCapacity
:
OpenFileLimit
})
// check for corruption and attempt to recover
if
_
,
iscorrupted
:=
err
.
(
*
errors
.
ErrCorrupted
);
iscorrupted
{
func
NewLDBDatabase
(
file
string
,
cache
int
)
(
*
LDBDatabase
,
error
)
{
// Calculate the cache allowance for this particular database
cache
=
int
(
float64
(
cache
)
*
cacheRatio
[
filepath
.
Base
(
file
)])
if
cache
<
16
{
cache
=
16
}
glog
.
V
(
logger
.
Info
)
.
Infof
(
"Alloted %dMB cache to %s"
,
cache
,
file
)
// Open the db and recover any potential corruptions
db
,
err
:=
leveldb
.
OpenFile
(
file
,
&
opt
.
Options
{
OpenFilesCacheCapacity
:
OpenFileLimit
,
BlockCacheCapacity
:
cache
/
2
*
opt
.
MiB
,
WriteBuffer
:
cache
/
4
*
opt
.
MiB
,
// Two of these are used internally
})
if
_
,
corrupted
:=
err
.
(
*
errors
.
ErrCorrupted
);
corrupted
{
db
,
err
=
leveldb
.
RecoverFile
(
file
,
nil
)
}
// (
re)
check for errors and abort if opening of the db failed
// (
Re)
check for errors and abort if opening of the db failed
if
err
!=
nil
{
return
nil
,
err
}
...
...
ethdb/database_test.go
View file @
c7e7778f
...
...
@@ -28,8 +28,7 @@ func newDb() *LDBDatabase {
if
common
.
FileExist
(
file
)
{
os
.
RemoveAll
(
file
)
}
db
,
_
:=
NewLDBDatabase
(
file
)
db
,
_
:=
NewLDBDatabase
(
file
,
0
)
return
db
}
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