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...")
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))
} else {
@ -153,7 +153,7 @@ func upgradeDB(ctx *cli.Context) error {
utils.Fatalf("Unable to export chain for reimport %s", err)
}
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.
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")
}
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 {
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),
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
LightMode: ctx.GlobalBool(LightModeFlag.Name),
LightServ: ctx.GlobalInt(LightServFlag.Name),
LightPeers: ctx.GlobalInt(LightPeersFlag.Name),
LightServ: ctx.GlobalInt(LightServFlag.Name),
LightPeers: ctx.GlobalInt(LightPeersFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
DatabaseHandles: MakeDatabaseHandles(),
@ -789,7 +789,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
}); err != nil {
Fatalf("Failed to register the account manager service: %v", err)
}
if ethConf.LightMode {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, ethConf)
@ -866,15 +866,24 @@ func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainC
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.
func MakeChainDatabase(ctx *cli.Context) ethdb.Database {
var (
datadir = MustMakeDataDir(ctx)
cache = ctx.GlobalInt(CacheFlag.Name)
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 {
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
// initialisation of the common Ethereum object)
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 {
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
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
chainDb, err = ctx.OpenDatabase("chaindata", config.DatabaseCache, config.DatabaseHandles)
chainDb, err = ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
if err != nil {
return nil, nil, err
}

View file

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

View file

@ -72,7 +72,7 @@ type LightNodeService struct {
}
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 {
return nil, err
}