Skip to content

Commit

Permalink
Merge "cache config via core.yaml"
Browse files Browse the repository at this point in the history
  • Loading branch information
denyeart authored and Gerrit Code Review committed Nov 20, 2019
2 parents 0f2c4b6 + e9be627 commit e08ff81
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions core/ledger/kvledger/kv_ledger_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ func (p *Provider) initStateDBProvider() error {
StateDBConfig: p.initializer.Config.StateDBConfig,
LevelDBPath: StateDBPath(p.initializer.Config.RootFSPath),
}
sysNamespaces := p.initializer.DeployedChaincodeInfoProvider.Namespaces()
p.vdbProvider, err = privacyenabledstate.NewCommonStorageDBProvider(
p.bookkeepingProvider,
p.initializer.MetricsProvider,
p.initializer.HealthCheckRegistry,
stateDB,
sysNamespaces,
)
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ type StateDBConfig struct {
// It is internally computed by the ledger component,
// so it is not in ledger.StateDBConfig and not exposed to other components.
LevelDBPath string
// Size of the stateDB cache.
CacheSizeMBs int
}

// CommonStorageDBProvider implements interface DBProvider
Expand All @@ -59,15 +57,14 @@ func NewCommonStorageDBProvider(
metricsProvider metrics.Provider,
healthCheckRegistry ledger.HealthCheckRegistry,
stateDBConf *StateDBConfig,
sysNamespaces []string,
) (DBProvider, error) {

var vdbProvider statedb.VersionedDBProvider
var err error
// TODO: system namespaces needed for the cache would be passed from kvLedger using
// the DeployedChaincodeProvider in FAB-13314
sysNamespaces := []string{"lscc", "_lifecycle"}
cache := statedb.NewCache(stateDBConf.CacheSizeMBs, sysNamespaces)

if stateDBConf != nil && stateDBConf.StateDatabase == couchDB {
cache := statedb.NewCache(stateDBConf.CouchDB.UserCacheSizeMBs, sysNamespaces)
if vdbProvider, err = statecouchdb.NewVersionedDBProvider(stateDBConf.CouchDB, metricsProvider, cache); err != nil {
return nil, err
}
Expand All @@ -87,6 +84,7 @@ func NewCommonStorageDBProvider(
return dbProvider, nil
}

// RegisterHealthChecker implements function from interface DBProvider
func (p *CommonStorageDBProvider) RegisterHealthChecker() error {
if healthChecker, ok := p.VersionedDBProvider.(healthz.HealthChecker); ok {
return p.HealthCheckRegistry.RegisterChecker("couchdb", healthChecker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (env *LevelDBCommonStorageTestEnv) Init(t testing.TB) {
&StateDBConfig{
&ledger.StateDBConfig{},
dbPath,
0,
},
[]string{"lscc", "_lifecycle"},
)
assert.NoError(t, err)
env.t = t
Expand Down Expand Up @@ -151,6 +151,7 @@ func (env *CouchDBCommonStorageTestEnv) Init(t testing.TB) {
&disabled.Provider{},
&mock.HealthCheckRegistry{},
stateDBConfig,
[]string{"lscc", "_lifecycle"},
)
assert.NoError(t, err)
env.t = t
Expand Down
5 changes: 5 additions & 0 deletions core/ledger/util/couchdb/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ type Config struct {
CreateGlobalChangesDB bool
// RedoLogPath is the directory where the CouchDB redo log files are stored.
RedoLogPath string
// UserCacheSizeMBs denotes the user specified maximum mega bytes (MB) to be allocated
// for the user state cache (i.e., all chaincodes deployed by the user). Note that
// UserCacheSizeMBs needs to be a multiple of 32 MB. If it is not a multiple of 32 MB,
// the peer would round the size to the next multiple of 32 MB.
UserCacheSizeMBs int
}

//CouchInstance represents a CouchDB instance
Expand Down
1 change: 1 addition & 0 deletions internal/peer/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func ledgerConfig() *ledger.Config {
WarmIndexesAfterNBlocks: warmAfterNBlocks,
CreateGlobalChangesDB: viper.GetBool("ledger.state.couchDBConfig.createGlobalChangesDB"),
RedoLogPath: filepath.Join(rootFSPath, "couchdbRedoLogs"),
UserCacheSizeMBs: viper.GetInt("ledger.state.couchDBConfig.cacheSize"),
}
}
return conf
Expand Down
4 changes: 4 additions & 0 deletions internal/peer/node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestLedgerConfig(t *testing.T) {
"ledger.state.couchDBConfig.maxRetriesOnStartup": 10,
"ledger.state.couchDBConfig.requestTimeout": "30s",
"ledger.state.couchDBConfig.createGlobalChangesDB": true,
"ledger.state.couchDBConfig.cacheSize": 64,
},
expected: &ledger.Config{
RootFSPath: "/peerfs/ledgersData",
Expand All @@ -74,6 +75,7 @@ func TestLedgerConfig(t *testing.T) {
WarmIndexesAfterNBlocks: 1,
CreateGlobalChangesDB: true,
RedoLogPath: "/peerfs/ledgersData/couchdbRedoLogs",
UserCacheSizeMBs: 64,
},
},
PrivateDataConfig: &ledger.PrivateDataConfig{
Expand Down Expand Up @@ -101,6 +103,7 @@ func TestLedgerConfig(t *testing.T) {
"ledger.state.couchDBConfig.maxBatchUpdateSize": 600,
"ledger.state.couchDBConfig.warmIndexesAfterNBlocks": 5,
"ledger.state.couchDBConfig.createGlobalChangesDB": true,
"ledger.state.couchDBConfig.cacheSize": 64,
"ledger.pvtdataStore.collElgProcMaxDbBatchSize": 50000,
"ledger.pvtdataStore.collElgProcDbBatchesInterval": 10000,
"ledger.pvtdataStore.purgeInterval": 1000,
Expand All @@ -122,6 +125,7 @@ func TestLedgerConfig(t *testing.T) {
WarmIndexesAfterNBlocks: 5,
CreateGlobalChangesDB: true,
RedoLogPath: "/peerfs/ledgersData/couchdbRedoLogs",
UserCacheSizeMBs: 64,
},
},
PrivateDataConfig: &ledger.PrivateDataConfig{
Expand Down
5 changes: 5 additions & 0 deletions sampleconfig/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,11 @@ ledger:
# This is optional. Creating the global changes database will require
# additional system resources to track changes and maintain the database
createGlobalChangesDB: false
# CacheSize denotes the maximum mega bytes (MB) to be allocated for the in-memory state
# cache. Note that CacheSize needs to be a multiple of 32 MB. If it is not a multiple
# of 32 MB, the peer would round the size to the next multiple of 32 MB.
# To disable the cache, 0 MB needs to be assigned to the cacheSize.
cacheSize: 64

history:
# enableHistoryDatabase - options are true or false
Expand Down

0 comments on commit e08ff81

Please sign in to comment.