using lightchaindata db dir

This commit is contained in:
zsfelfoldi 2016-06-27 02:54:59 +02:00
parent 4ad808f4dc
commit 658292f934
6 changed files with 26 additions and 15 deletions

View file

@ -128,7 +128,7 @@ func removeDB(ctx *cli.Context) error {
fmt.Println("Removing chaindata...") fmt.Println("Removing chaindata...")
start := time.Now() start := time.Now()
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata")) os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), utils.ChainDbName(ctx)))
fmt.Printf("Removed in %v\n", time.Since(start)) fmt.Printf("Removed in %v\n", time.Since(start))
} else { } else {
@ -153,7 +153,7 @@ func upgradeDB(ctx *cli.Context) error {
utils.Fatalf("Unable to export chain for reimport %s", err) utils.Fatalf("Unable to export chain for reimport %s", err)
} }
chainDb.Close() chainDb.Close()
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata")) os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), utils.ChainDbName(ctx)))
// Import the chain file. // Import the chain file.
chain, chainDb = utils.MakeChain(ctx) chain, chainDb = utils.MakeChain(ctx)

View file

@ -291,7 +291,7 @@ func initGenesis(ctx *cli.Context) error {
utils.Fatalf("must supply path to genesis JSON file") utils.Fatalf("must supply path to genesis JSON file")
} }
chainDb, err := ethdb.NewLDBDatabase(filepath.Join(utils.MustMakeDataDir(ctx), "chaindata"), 0, 0) chainDb, err := ethdb.NewLDBDatabase(filepath.Join(utils.MustMakeDataDir(ctx), utils.ChainDbName(ctx)), 0, 0)
if err != nil { if err != nil {
utils.Fatalf("could not open database: %v", err) utils.Fatalf("could not open database: %v", err)
} }

View file

@ -708,8 +708,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
Genesis: MakeGenesisBlock(ctx), Genesis: MakeGenesisBlock(ctx),
FastSync: ctx.GlobalBool(FastSyncFlag.Name), FastSync: ctx.GlobalBool(FastSyncFlag.Name),
LightMode: ctx.GlobalBool(LightModeFlag.Name), LightMode: ctx.GlobalBool(LightModeFlag.Name),
LightServ: ctx.GlobalInt(LightServFlag.Name), LightServ: ctx.GlobalInt(LightServFlag.Name),
LightPeers: ctx.GlobalInt(LightPeersFlag.Name), LightPeers: ctx.GlobalInt(LightPeersFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
DatabaseCache: ctx.GlobalInt(CacheFlag.Name), DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
DatabaseHandles: MakeDatabaseHandles(), DatabaseHandles: MakeDatabaseHandles(),
@ -866,15 +866,24 @@ func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainC
return &core.ChainConfig{HomesteadBlock: homesteadBlockNo} return &core.ChainConfig{HomesteadBlock: homesteadBlockNo}
} }
func ChainDbName(ctx *cli.Context) string {
if ctx.GlobalBool(LightModeFlag.Name) {
return "lightchaindata"
} else {
return "chaindata"
}
}
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails. // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
func MakeChainDatabase(ctx *cli.Context) ethdb.Database { func MakeChainDatabase(ctx *cli.Context) ethdb.Database {
var ( var (
datadir = MustMakeDataDir(ctx) datadir = MustMakeDataDir(ctx)
cache = ctx.GlobalInt(CacheFlag.Name) cache = ctx.GlobalInt(CacheFlag.Name)
handles = MakeDatabaseHandles() handles = MakeDatabaseHandles()
name = ChainDbName(ctx)
) )
chainDb, err := ethdb.NewLDBDatabase(filepath.Join(datadir, "chaindata"), cache, handles) chainDb, err := ethdb.NewLDBDatabase(filepath.Join(datadir, name), cache, handles)
if err != nil { if err != nil {
Fatalf("Could not open database: %v", err) Fatalf("Could not open database: %v", err)
} }

View file

@ -157,7 +157,7 @@ func (s *FullNodeService) AddLesServer(ls LesServer) {
// New creates a new FullNodeService object (including the // New creates a new FullNodeService object (including the
// initialisation of the common Ethereum object) // initialisation of the common Ethereum object)
func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) { func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) {
chainDb, dappDb, err := CreateDBs(ctx, config) chainDb, dappDb, err := CreateDBs(ctx, config, "chaindata")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -257,9 +257,9 @@ func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) {
} }
// CreateDBs creates the chain and dapp databases for an Ethereum service // CreateDBs creates the chain and dapp databases for an Ethereum service
func CreateDBs(ctx *node.ServiceContext, config *Config) (chainDb, dappDb ethdb.Database, err error) { func CreateDBs(ctx *node.ServiceContext, config *Config, name string) (chainDb, dappDb ethdb.Database, err error) {
// Open the chain database and perform any upgrades needed // Open the chain database and perform any upgrades needed
chainDb, err = ctx.OpenDatabase("chaindata", config.DatabaseCache, config.DatabaseHandles) chainDb, err = ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View file

@ -39,15 +39,17 @@ var OpenFileLimit = 64
// cacheRatio specifies how the total alloted cache is distributed between the // cacheRatio specifies how the total alloted cache is distributed between the
// various system databases. // various system databases.
var cacheRatio = map[string]float64{ var cacheRatio = map[string]float64{
"dapp": 0.0, "dapp": 0.0,
"chaindata": 1.0, "chaindata": 1.0,
"lightchaindata": 1.0,
} }
// handleRatio specifies how the total alloted file descriptors is distributed // handleRatio specifies how the total alloted file descriptors is distributed
// between the various system databases. // between the various system databases.
var handleRatio = map[string]float64{ var handleRatio = map[string]float64{
"dapp": 0.0, "dapp": 0.0,
"chaindata": 1.0, "chaindata": 1.0,
"lightchaindata": 1.0,
} }
type LDBDatabase struct { type LDBDatabase struct {

View file

@ -72,7 +72,7 @@ type LightNodeService struct {
} }
func New(ctx *node.ServiceContext, config *eth.Config) (*LightNodeService, error) { func New(ctx *node.ServiceContext, config *eth.Config) (*LightNodeService, error) {
chainDb, dappDb, err := eth.CreateDBs(ctx, config) chainDb, dappDb, err := eth.CreateDBs(ctx, config, "lightchaindata")
if err != nil { if err != nil {
return nil, err return nil, err
} }