Skip to content

Commit

Permalink
[FAB-5997] cleanup transientstore from ledger
Browse files Browse the repository at this point in the history
As the transientstore is moved out of ledger and committer fetches
private write set from transient store and pass it to ledger for
commit, ledger no longer use transient store directly to fetch private
write set. Hence, transientstore usage in ledger is cleaned up in this
CR.

Change-Id: Ic55940abab32ab7e25c9d3f7d899183ed599ab7b
Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu committed Sep 5, 2017
1 parent db18d92 commit 46d2109
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 479 deletions.
13 changes: 3 additions & 10 deletions core/ledger/kvledger/history/historydb/historyleveldb/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/transientstore"
"github.com/spf13/viper"
)

Expand All @@ -39,9 +38,8 @@ type levelDBLockBasedHistoryEnv struct {
t testing.TB
testBlockStorageEnv *testBlockStoreEnv

testDBEnv privacyenabledstate.TestEnv
testTransientStoreEnv *transientstore.StoreEnv
txmgr txmgr.TxMgr
testDBEnv privacyenabledstate.TestEnv
txmgr txmgr.TxMgr

testHistoryDBProvider historydb.HistoryDBProvider
testHistoryDB historydb.HistoryDB
Expand All @@ -57,17 +55,14 @@ func newTestHistoryEnv(t *testing.T) *levelDBLockBasedHistoryEnv {
testDBEnv.Init(t)
testDB := testDBEnv.GetDBHandle(testLedgerID)

testTStoreEnv := transientstore.NewTestStoreEnv(t)

txMgr := lockbasedtxmgr.NewLockBasedTxMgr(testDB)
testHistoryDBProvider := NewHistoryDBProvider()
testHistoryDB, err := testHistoryDBProvider.GetDBHandle("TestHistoryDB")
testutil.AssertNoError(t, err, "")

return &levelDBLockBasedHistoryEnv{t,
blockStorageTestEnv, testDBEnv,
testTStoreEnv, txMgr,
testHistoryDBProvider, testHistoryDB}
txMgr, testHistoryDBProvider, testHistoryDB}
}

func (env *levelDBLockBasedHistoryEnv) cleanup() {
Expand All @@ -77,13 +72,11 @@ func (env *levelDBLockBasedHistoryEnv) cleanup() {

// clean up history
env.testHistoryDBProvider.Close()
env.testTransientStoreEnv.Cleanup()
removeDBPath(env.t)
}

func removeDBPath(t testing.TB) {
removePath(t, ledgerconfig.GetHistoryLevelDBPath())
removePath(t, ledgerconfig.GetTransientStorePath())
}

func removePath(t testing.TB, path string) {
Expand Down
57 changes: 4 additions & 53 deletions core/ledger/kvledger/kv_ledger.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package kvledger
Expand All @@ -20,22 +10,18 @@ import (
"errors"
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/flogging"
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/privacyenabledstate"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/pvtdatatxmgr"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/ledgerstorage"
"github.com/hyperledger/fabric/core/transientstore"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/ledger/rwset"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
)

var logger = flogging.MustGetLogger("kvledger")
Expand All @@ -57,7 +43,7 @@ func newKVLedger(ledgerID string, blockStore *ledgerstorage.Store,

//Initialize transaction manager using state database
var txmgmt txmgr.TxMgr
txmgmt = pvtdatatxmgr.NewLockbasedTxMgr(versionedDB)
txmgmt = lockbasedtxmgr.NewLockBasedTxMgr(versionedDB)

// Create a kvLedger for this chain/ledger, which encasulates the underlying
// id store, blockstore, txmgr (state database), history database
Expand Down Expand Up @@ -270,38 +256,3 @@ func (l *kvLedger) Close() {
l.blockStore.Shutdown()
l.txtmgmt.Shutdown()
}

// retrievePrivateData retrieves the pvt data from the transient store for committing it into the
// pvt data store along with block commit.
// KVLedger does this job temporarily for phase-1 and will be moved out to committer
func retrievePrivateData(transientStore transientstore.Store, block *common.Block) (map[uint64]*ledger.TxPvtData, error) {
pvtdata := make(map[uint64]*ledger.TxPvtData)
for txIndex, envBytes := range block.Data.Data {
env, err := utils.GetEnvelopeFromBlock(envBytes)
if err != nil {
return nil, err
}
payload, err := utils.GetPayload(env)
if err != nil {
return nil, err
}
chdr, err := utils.UnmarshalChannelHeader(payload.Header.ChannelHeader)
if err != nil {
return nil, err
}
pvtEndorsement, err := transientStore.GetSelfSimulatedTxPvtRWSetByTxid(chdr.TxId)
if err != nil {
return nil, err
}
if pvtEndorsement == nil {
continue
}
txPvtRWSet := &rwset.TxPvtReadWriteSet{}
if err := proto.Unmarshal(pvtEndorsement.PvtSimulationResults, txPvtRWSet); err != nil {
return nil, err
}
seqInBlock := uint64(txIndex)
pvtdata[seqInBlock] = &ledger.TxPvtData{SeqInBlock: seqInBlock, WriteSet: txPvtRWSet}
}
return pvtdata, nil
}
16 changes: 2 additions & 14 deletions core/ledger/kvledger/kv_ledger_provider.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package kvledger
Expand Down Expand Up @@ -70,8 +60,6 @@ func NewProvider() (ledger.PeerLedgerProvider, error) {
if err != nil {
return nil, err
}
// Initialize the transient store (temporary storage of private rwset)
//transientStoreProvider := transientstore.NewCustomPathStoreProvider(ledgerconfig.GetTransientStorePath())

// Initialize the history database (index for history of values by key)
var historydbProvider historydb.HistoryDBProvider
Expand Down
5 changes: 0 additions & 5 deletions core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/privacyenabledstate"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
"github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/core/transientstore"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/ledger/rwset"
)
Expand Down Expand Up @@ -60,8 +59,6 @@ type lockBasedEnv struct {
testDBEnv privacyenabledstate.TestEnv
testDB privacyenabledstate.DB

testTStoreEnv *transientstore.StoreEnv

txmgr txmgr.TxMgr
}

Expand All @@ -75,7 +72,6 @@ func (env *lockBasedEnv) init(t *testing.T, testLedgerID string) {
env.testDBEnv.Init(t)
env.testDB = env.testDBEnv.GetDBHandle(testLedgerID)
testutil.AssertNoError(t, err, "")
env.testTStoreEnv = transientstore.NewTestStoreEnv(t)
env.txmgr = NewLockBasedTxMgr(env.testDB)
}

Expand All @@ -90,7 +86,6 @@ func (env *lockBasedEnv) getVDB() privacyenabledstate.DB {
func (env *lockBasedEnv) cleanup() {
env.txmgr.Shutdown()
env.testDBEnv.Cleanup()
env.testTStoreEnv.Cleanup()
}

//////////// txMgrTestHelper /////////////
Expand Down
63 changes: 0 additions & 63 deletions core/ledger/kvledger/txmgmt/txmgr/pvtdatatxmgr/pkg_test.go

This file was deleted.

67 changes: 0 additions & 67 deletions core/ledger/kvledger/txmgmt/txmgr/pvtdatatxmgr/pvtdata_txmgr.go

This file was deleted.

Loading

0 comments on commit 46d2109

Please sign in to comment.