Skip to content

Commit ecfed25

Browse files
committed
FAB-15086 Use config for history db path
Remove ledgerconfig.GetHistoryLevelDBPath and pass path via config. Change-Id: Ia7b89ebbeb3ae8a760e9a9cf832be31a34553d8b Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent fe3b07b commit ecfed25

File tree

6 files changed

+32
-39
lines changed

6 files changed

+32
-39
lines changed

core/ledger/kvledger/history/historydb/historyleveldb/historyleveldb.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type HistoryDBProvider struct {
3131
}
3232

3333
// NewHistoryDBProvider instantiates HistoryDBProvider
34-
func NewHistoryDBProvider() *HistoryDBProvider {
35-
dbPath := ledgerconfig.GetHistoryLevelDBPath()
34+
func NewHistoryDBProvider(dbPath string) *HistoryDBProvider {
3635
logger.Debugf("constructing HistoryDBProvider dbPath=%s", dbPath)
3736
dbProvider := leveldbhelper.NewProvider(&leveldbhelper.Conf{DBPath: dbPath})
3837
return &HistoryDBProvider{dbProvider}

core/ledger/kvledger/history/historydb/historyleveldb/pkg_test.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/privacyenabledstate"
2929
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
3030
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr"
31-
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
3231
"github.com/hyperledger/fabric/core/ledger/mock"
3332
"github.com/spf13/viper"
3433
"github.com/stretchr/testify/assert"
@@ -37,16 +36,14 @@ import (
3736
/////// levelDBLockBasedHistoryEnv //////
3837

3938
type levelDBLockBasedHistoryEnv struct {
40-
t testing.TB
41-
testBlockStorageEnv *testBlockStoreEnv
42-
43-
testDBEnv privacyenabledstate.TestEnv
44-
testBookkeepingEnv *bookkeeping.TestEnv
45-
46-
txmgr txmgr.TxMgr
47-
39+
t testing.TB
40+
testBlockStorageEnv *testBlockStoreEnv
41+
testDBEnv privacyenabledstate.TestEnv
42+
testBookkeepingEnv *bookkeeping.TestEnv
43+
txmgr txmgr.TxMgr
4844
testHistoryDBProvider historydb.HistoryDBProvider
4945
testHistoryDB historydb.HistoryDB
46+
testHistoryDBPath string
5047
}
5148

5249
func newTestHistoryEnv(t *testing.T) *levelDBLockBasedHistoryEnv {
@@ -60,15 +57,27 @@ func newTestHistoryEnv(t *testing.T) *levelDBLockBasedHistoryEnv {
6057
testDB := testDBEnv.GetDBHandle(testLedgerID)
6158
testBookkeepingEnv := bookkeeping.NewTestEnv(t)
6259

60+
testHistoryDBPath, err := ioutil.TempDir("", "historyldb")
61+
if err != nil {
62+
t.Fatalf("Failed to create history database directory: %s", err)
63+
}
64+
6365
txMgr, err := lockbasedtxmgr.NewLockBasedTxMgr(testLedgerID, testDB, nil, nil, testBookkeepingEnv.TestProvider, &mock.DeployedChaincodeInfoProvider{})
6466
assert.NoError(t, err)
65-
testHistoryDBProvider := NewHistoryDBProvider()
67+
testHistoryDBProvider := NewHistoryDBProvider(testHistoryDBPath)
6668
testHistoryDB, err := testHistoryDBProvider.GetDBHandle("TestHistoryDB")
6769
assert.NoError(t, err)
6870

69-
return &levelDBLockBasedHistoryEnv{t,
70-
blockStorageTestEnv, testDBEnv, testBookkeepingEnv,
71-
txMgr, testHistoryDBProvider, testHistoryDB}
71+
return &levelDBLockBasedHistoryEnv{
72+
t,
73+
blockStorageTestEnv,
74+
testDBEnv,
75+
testBookkeepingEnv,
76+
txMgr,
77+
testHistoryDBProvider,
78+
testHistoryDB,
79+
testHistoryDBPath,
80+
}
7281
}
7382

7483
func (env *levelDBLockBasedHistoryEnv) cleanup() {
@@ -78,18 +87,7 @@ func (env *levelDBLockBasedHistoryEnv) cleanup() {
7887
env.testBookkeepingEnv.Cleanup()
7988
// clean up history
8089
env.testHistoryDBProvider.Close()
81-
removeDBPath(env.t)
82-
}
83-
84-
func removeDBPath(t testing.TB) {
85-
removePath(t, ledgerconfig.GetHistoryLevelDBPath())
86-
}
87-
88-
func removePath(t testing.TB, path string) {
89-
if err := os.RemoveAll(path); err != nil {
90-
t.Fatalf("Err: %s", err)
91-
t.FailNow()
92-
}
90+
os.RemoveAll(env.testHistoryDBPath)
9391
}
9492

9593
/////// testBlockStoreEnv//////

core/ledger/kvledger/kv_ledger_provider.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ type Provider struct {
5656
// This is not thread-safe and assumed to be synchronized be the caller
5757
func NewProvider() (ledger.PeerLedgerProvider, error) {
5858
logger.Info("Initializing ledger provider")
59-
// Initialize the history database (index for history of values by key)
60-
historydbProvider := historyleveldb.NewHistoryDBProvider()
59+
6160
logger.Info("ledger provider Initialized")
62-
p := &Provider{nil, nil,
63-
nil, historydbProvider, nil, nil, nil, nil, nil, nil}
61+
p := &Provider{}
6462
return p, nil
6563
}
6664

@@ -73,6 +71,10 @@ func (p *Provider) Initialize(initializer *ledger.Initializer) error {
7371
idStore := openIDStore(filepath.Join(p.initializer.Config.RootFSPath, "ledgerProvider"))
7472
// initialize ledger storage
7573
ledgerStoreProvider := ledgerstorage.NewProvider(p.initializer.Config.RootFSPath)
74+
// Initialize the history database (index for history of values by key)
75+
historydbProvider := historyleveldb.NewHistoryDBProvider(
76+
filepath.Join(p.initializer.Config.RootFSPath, "historyLeveldb"),
77+
)
7678
// initialize config history for chaincode
7779
configHistoryMgr := confighistory.NewMgr(initializer.DeployedChaincodeInfoProvider)
7880
// initialize the collection eligibility notifier
@@ -88,6 +90,7 @@ func (p *Provider) Initialize(initializer *ledger.Initializer) error {
8890

8991
p.idStore = idStore
9092
p.ledgerStoreProvider = ledgerStoreProvider
93+
p.historydbProvider = historydbProvider
9194
p.configHistoryMgr = configHistoryMgr
9295
p.stateListeners = stateListeners
9396
p.collElgNotifier = collElgNotifier

core/ledger/kvledger/kv_ledger_provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ func TestLedgerBackup(t *testing.T) {
227227
// remove the statedb, historydb, and block indexes (they are supposed to be auto created during opening of an existing ledger)
228228
// and rename the originalPath to restorePath
229229
assert.NoError(t, os.RemoveAll(ledgerconfig.GetStateLevelDBPath()))
230-
assert.NoError(t, os.RemoveAll(ledgerconfig.GetHistoryLevelDBPath()))
231230
//TODO: revisit once all paths are derived from Config
231+
assert.NoError(t, os.RemoveAll(filepath.Join(originalPath, "historyLeveldb")))
232232
assert.NoError(t, os.RemoveAll(filepath.Join(originalPath, "chains", fsblkstorage.IndexDir)))
233233
assert.NoError(t, os.Rename(originalPath, restorePath))
234234
defer env.cleanup()

core/ledger/ledgerconfig/ledger_config.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ func GetStateLevelDBPath() string {
5353
return filepath.Join(GetRootPath(), confStateleveldb)
5454
}
5555

56-
// GetHistoryLevelDBPath returns the filesystem path that is used to maintain the history level db
57-
func GetHistoryLevelDBPath() string {
58-
return filepath.Join(GetRootPath(), confHistoryLeveldb)
59-
}
60-
6156
// GetInternalBookkeeperPath returns the filesystem path that is used for bookkeeping the internal stuff by by KVledger (such as expiration time for pvt)
6257
func GetInternalBookkeeperPath() string {
6358
return filepath.Join(GetRootPath(), confBookkeeper)

core/ledger/ledgerconfig/ledger_config_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func TestLedgerConfigPathDefault(t *testing.T) {
5151
assert.Equal(t, "/var/hyperledger/production/ledgersData", GetRootPath())
5252
assert.Equal(t, "/var/hyperledger/production/ledgersData/ledgerProvider", GetLedgerProviderPath())
5353
assert.Equal(t, "/var/hyperledger/production/ledgersData/stateLeveldb", GetStateLevelDBPath())
54-
assert.Equal(t, "/var/hyperledger/production/ledgersData/historyLeveldb", GetHistoryLevelDBPath())
5554
assert.Equal(t, "/var/hyperledger/production/ledgersData/bookkeeper", GetInternalBookkeeperPath())
5655
}
5756

@@ -62,7 +61,6 @@ func TestLedgerConfigPath(t *testing.T) {
6261
assert.Equal(t, "/tmp/hyperledger/production/ledgersData", GetRootPath())
6362
assert.Equal(t, "/tmp/hyperledger/production/ledgersData/ledgerProvider", GetLedgerProviderPath())
6463
assert.Equal(t, "/tmp/hyperledger/production/ledgersData/stateLeveldb", GetStateLevelDBPath())
65-
assert.Equal(t, "/tmp/hyperledger/production/ledgersData/historyLeveldb", GetHistoryLevelDBPath())
6664
assert.Equal(t, "/tmp/hyperledger/production/ledgersData/bookkeeper", GetInternalBookkeeperPath())
6765
}
6866

0 commit comments

Comments
 (0)