@@ -19,14 +19,13 @@ package kvledger
19
19
import (
20
20
"errors"
21
21
"fmt"
22
- "strings"
23
22
24
23
"github.com/hyperledger/fabric/core/ledger"
25
24
"github.com/hyperledger/fabric/core/ledger/blkstorage"
26
25
"github.com/hyperledger/fabric/core/ledger/blkstorage/fsblkstorage"
27
26
"github.com/hyperledger/fabric/core/ledger/history"
28
27
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/couchdbtxmgmt"
29
- "github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb/stateleveldb "
28
+ "github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
30
29
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
31
30
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr"
32
31
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
@@ -39,45 +38,28 @@ import (
39
38
40
39
var logger = logging .MustGetLogger ("kvledger" )
41
40
42
- // Conf captures `KVLedger` configurations
43
- type Conf struct {
44
- blockStorageDir string
45
- maxBlockfileSize int
46
- txMgrDBPath string
47
- }
48
-
49
- // NewConf constructs new `Conf`.
50
- // filesystemPath is the top level directory under which `KVLedger` manages its data
51
- func NewConf (filesystemPath string , maxBlockfileSize int ) * Conf {
52
- if ! strings .HasSuffix (filesystemPath , "/" ) {
53
- filesystemPath = filesystemPath + "/"
54
- }
55
- blocksStorageDir := filesystemPath + "blocks"
56
- txMgrDBPath := filesystemPath + "txMgmgt/db"
57
- return & Conf {blocksStorageDir , maxBlockfileSize , txMgrDBPath }
58
- }
59
-
60
41
// KVLedger provides an implementation of `ledger.ValidatedLedger`.
61
42
// This implementation provides a key-value based data model
62
43
type KVLedger struct {
44
+ ledgerID string
63
45
blockStore blkstorage.BlockStore
64
46
txtmgmt txmgr.TxMgr
65
47
historymgmt history.HistMgr
66
48
}
67
49
68
50
// NewKVLedger constructs new `KVLedger`
69
- func NewKVLedger (conf * Conf ) (* KVLedger , error ) {
70
-
71
- logger .Debugf ("Creating KVLedger using config: " , conf )
72
-
51
+ func NewKVLedger (versionedDBProvider statedb.VersionedDBProvider , ledgerID string ) (* KVLedger , error ) {
52
+ logger .Debugf ("Creating KVLedger ledgerID=%s: " , ledgerID )
73
53
attrsToIndex := []blkstorage.IndexableAttr {
74
54
blkstorage .IndexableAttrBlockHash ,
75
55
blkstorage .IndexableAttrBlockNum ,
76
56
blkstorage .IndexableAttrTxID ,
77
57
blkstorage .IndexableAttrBlockNumTranNum ,
78
58
}
79
59
indexConfig := & blkstorage.IndexConfig {AttrsToIndex : attrsToIndex }
80
- blockStorageConf := fsblkstorage .NewConf (conf .blockStorageDir , conf .maxBlockfileSize )
60
+
61
+ blockStorageDir := ledgerconfig .GetBlockStoragePath (ledgerID )
62
+ blockStorageConf := fsblkstorage .NewConf (blockStorageDir , ledgerconfig .GetMaxBlockfileSize ())
81
63
blockStore := fsblkstorage .NewFsBlockStore (blockStorageConf , indexConfig )
82
64
83
65
//State and History database managers
@@ -91,14 +73,14 @@ func NewKVLedger(conf *Conf) (*KVLedger, error) {
91
73
couchDBDef := ledgerconfig .GetCouchDBDefinition ()
92
74
93
75
//create new transaction manager based on couchDB
94
- txmgmt = couchdbtxmgmt .NewCouchDBTxMgr (& couchdbtxmgmt.Conf {DBPath : conf . txMgrDBPath },
76
+ txmgmt = couchdbtxmgmt .NewCouchDBTxMgr (& couchdbtxmgmt.Conf {DBPath : "" },
95
77
couchDBDef .URL , //couchDB connection URL
96
78
"system" , //couchDB db name matches ledger name, TODO for now use system ledger, eventually allow passing in subledger name
97
79
couchDBDef .Username , //enter couchDB id here
98
80
couchDBDef .Password ) //enter couchDB pw here
99
81
} else {
100
82
// Fall back to using goleveldb lockbased transaction manager
101
- db := stateleveldb . NewVersionedDBProvider ( & stateleveldb. Conf { DBPath : conf . txMgrDBPath }). GetDBHandle ("Default" )
83
+ db := versionedDBProvider . GetDBHandle (ledgerID )
102
84
txmgmt = lockbasedtxmgr .NewLockBasedTxMgr (db )
103
85
}
104
86
@@ -114,7 +96,7 @@ func NewKVLedger(conf *Conf) (*KVLedger, error) {
114
96
couchDBDef .Password ) //enter couchDB pw here
115
97
}
116
98
117
- l := & KVLedger {blockStore , txmgmt , historymgmt }
99
+ l := & KVLedger {ledgerID , blockStore , txmgmt , historymgmt }
118
100
119
101
if err := recoverStateDB (l ); err != nil {
120
102
panic (fmt .Errorf (`Error during state DB recovery:%s` , err ))
0 commit comments