Skip to content

Commit 1893808

Browse files
manish-sethidenyeart
authored andcommitted
Remove rollback code from private data store
Now that the private data store can be ahead of block store the private data store can be ahead of block store (in order to support reset and rollback), the rollback function can be removed. Also, this fixes the bug mentioned in FAB-17293 Signed-off-by: manish <manish.sethi@gmail.com>
1 parent f354c81 commit 1893808

5 files changed

Lines changed: 8 additions & 127 deletions

File tree

core/ledger/ledgerstorage/store.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ func (s *Store) CommitWithPvtData(blockAndPvtdata *ledger.BlockAndPvtData) error
143143
}
144144

145145
if err := s.AddBlock(blockAndPvtdata.Block); err != nil {
146-
s.pvtdataStore.Rollback()
147146
return err
148147
}
149148

core/ledger/ledgerstorage/store_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,10 @@ func TestAddAfterBlkStoreError(t *testing.T) {
416416
assert.NoError(t, err)
417417
assert.Equal(t, uint64(9), pvtStoreCommitHt)
418418

419+
// pvt store should have a pending batch
419420
pvtStorePndingBatch, err := store.pvtdataStore.HasPendingBatch()
420421
assert.NoError(t, err)
421-
assert.False(t, pvtStorePndingBatch)
422+
assert.True(t, pvtStorePndingBatch)
422423
}
423424

424425
func TestPvtStoreAheadOfBlockStore(t *testing.T) {

core/ledger/pvtdatastorage/store.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ type Provider interface {
1919
}
2020

2121
// Store manages the permanent storage of private write sets for a ledger
22-
// Beacsue the pvt data is supposed to be in sync with the blocks in the
23-
// ledger, both should logically happen in an atomic operation. In order
24-
// to accomplish this, an implementation of this store should provide
25-
// support for a two-phase like commit/rollback capability.
2622
// The expected use is such that - first the private data will be given to
2723
// this store (via `Prepare` funtion) and then the block is appended to the block storage.
28-
// Finally, one of the functions `Commit` or `Rollback` is invoked on this store based
29-
// on whether the block was written successfully or not. The store implementation
30-
// is expected to survive a server crash between the call to `Prepare` and `Commit`/`Rollback`
24+
// Finally, the functions `Commit` invoked on this store. The store implementation
25+
// is expected to survive a server crash between the call to `Prepare` and `Commit`.
3126
type Store interface {
3227
// Init initializes the store. This function is expected to be invoked before using the store
3328
Init(btlPolicy pvtdatapolicy.BTLPolicy)
@@ -51,15 +46,13 @@ type Store interface {
5146
// for which this peer is a member; `ineligible` denotes that the missing private data belong to a
5247
// collection for which this peer is not a member.
5348
// This call does not commit the pvt data and store missing private data. Subsequently, the caller
54-
// is expected to call either `Commit` or `Rollback` function. Return from this should ensure
49+
// is expected to call `Commit` function. Return from this should ensure
5550
// that enough preparation is done such that `Commit` function invoked afterwards can commit the
5651
// data and the store is capable of surviving a crash between this function call and the next
5752
// invoke to the `Commit`
5853
Prepare(blockNum uint64, pvtData []*ledger.TxPvtData, missingPvtData ledger.TxMissingPvtDataMap) error
5954
// Commit commits the pvt data passed in the previous invoke to the `Prepare` function
6055
Commit() error
61-
// Rollback rolls back the pvt data passed in the previous invoke to the `Prepare` function
62-
Rollback() error
6356
// ProcessCollsEligibilityEnabled notifies the store when the peer becomes eligible to recieve data for an
6457
// existing collection. Parameter 'committingBlk' refers to the block number that contains the corresponding
6558
// collection upgrade transaction and the parameter 'nsCollMap' contains the collections for which the peer
@@ -86,7 +79,7 @@ type Store interface {
8679
Shutdown()
8780
}
8881

89-
// ErrIllegalCall is to be thrown by a store impl if the store does not expect a call to Prepare/Commit/Rollback/InitLastCommittedBlock
82+
// ErrIllegalCall is to be thrown by a store impl if the store does not expect a call to Prepare/Commit/InitLastCommittedBlock
9083
type ErrIllegalCall struct {
9184
msg string
9285
}

core/ledger/pvtdatastorage/store_impl.go

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (s *store) Init(btlPolicy pvtdatapolicy.BTLPolicy) {
165165
func (s *store) Prepare(blockNum uint64, pvtData []*ledger.TxPvtData, missingPvtData ledger.TxMissingPvtDataMap) error {
166166
if s.batchPending {
167167
return &ErrIllegalCall{`A pending batch exists as as result of last invoke to "Prepare" call.
168-
Invoke "Commit" or "Rollback" on the pending batch before invoking "Prepare" function`}
168+
Invoke "Commit" on the pending batch before invoking "Prepare" function`}
169169
}
170170
expectedBlockNum := s.nextBlockNum()
171171
if expectedBlockNum != blockNum {
@@ -235,38 +235,6 @@ func (s *store) Commit() error {
235235
return nil
236236
}
237237

238-
// Rollback implements the function in the interface `Store`
239-
// This deletes the existing data entries and eligible missing data entries.
240-
// However, this does not delete ineligible missing data entires as the next try
241-
// would have exact same entries and will overwrite those. This also leaves the
242-
// existing expiry entires as is because, most likely they will also get overwritten
243-
// per new data entries. Even if some of the expiry entries does not get overwritten,
244-
// (because of some data may be missing next time), the additional expiry entries are just
245-
// a Noop
246-
func (s *store) Rollback() error {
247-
if !s.batchPending {
248-
return &ErrIllegalCall{"No pending batch to rollback"}
249-
}
250-
blkNum := s.nextBlockNum()
251-
batch := leveldbhelper.NewUpdateBatch()
252-
itr := s.db.GetIterator(datakeyRange(blkNum))
253-
for itr.Next() {
254-
batch.Delete(itr.Key())
255-
}
256-
itr.Release()
257-
itr = s.db.GetIterator(eligibleMissingdatakeyRange(blkNum))
258-
for itr.Next() {
259-
batch.Delete(itr.Key())
260-
}
261-
itr.Release()
262-
batch.Delete(pendingCommitKey)
263-
if err := s.db.WriteBatch(batch, true); err != nil {
264-
return err
265-
}
266-
s.batchPending = false
267-
return nil
268-
}
269-
270238
// CommitPvtDataOfOldBlocks commits the pvtData (i.e., previously missing data) of old blocks.
271239
// The parameter `blocksPvtData` refers a list of old block's pvtdata which are missing in the pvtstore.
272240
// Given a list of old block's pvtData, `CommitPvtDataOfOldBlocks` performs the following four

core/ledger/pvtdatastorage/store_impl_test.go

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ func TestStoreBasicCommitAndRetrieval(t *testing.T) {
9090
assert.NoError(store.Prepare(1, testData, blk1MissingData))
9191
assert.NoError(store.Commit())
9292

93-
// pvt data with block 2 - rollback
94-
assert.NoError(store.Prepare(2, testData, nil))
95-
assert.NoError(store.Rollback())
96-
9793
// pvt data retrieval for block 0 should return nil
9894
var nilFilter ledger.PvtNsCollFilter
9995
retrievedData, err := store.GetPvtDataByBlockNum(0, nilFilter)
@@ -773,83 +769,7 @@ func testCollElgEnabled(t *testing.T) {
773769
assert.Equal(expectedMissingPvtDataInfo, missingPvtDataInfo)
774770
}
775771

776-
func TestRollBack(t *testing.T) {
777-
btlPolicy := btltestutil.SampleBTLPolicy(
778-
map[[2]string]uint64{
779-
{"ns-1", "coll-1"}: 0,
780-
{"ns-1", "coll-2"}: 0,
781-
},
782-
)
783-
env := NewTestStoreEnv(t, "TestRollBack", btlPolicy)
784-
defer env.Cleanup()
785-
assert := assert.New(t)
786-
store := env.TestStore
787-
assert.NoError(store.Prepare(0, nil, nil))
788-
assert.NoError(store.Commit())
789-
790-
pvtdata := []*ledger.TxPvtData{
791-
produceSamplePvtdata(t, 0, []string{"ns-1:coll-1", "ns-1:coll-2"}),
792-
produceSamplePvtdata(t, 5, []string{"ns-1:coll-1", "ns-1:coll-2"}),
793-
}
794-
missingData := make(ledger.TxMissingPvtDataMap)
795-
missingData.Add(1, "ns-1", "coll-1", true)
796-
missingData.Add(5, "ns-1", "coll-1", true)
797-
missingData.Add(5, "ns-2", "coll-2", false)
798-
799-
for i := 1; i <= 9; i++ {
800-
assert.NoError(store.Prepare(uint64(i), pvtdata, missingData))
801-
assert.NoError(store.Commit())
802-
}
803-
804-
datakeyTx0 := &dataKey{
805-
nsCollBlk: nsCollBlk{ns: "ns-1", coll: "coll-1"},
806-
txNum: 0,
807-
}
808-
datakeyTx5 := &dataKey{
809-
nsCollBlk: nsCollBlk{ns: "ns-1", coll: "coll-1"},
810-
txNum: 5,
811-
}
812-
eligibleMissingdatakey := &missingDataKey{
813-
nsCollBlk: nsCollBlk{ns: "ns-1", coll: "coll-1"},
814-
isEligible: true,
815-
}
816-
817-
// test store state before preparing for block 10
818-
testPendingBatch(false, assert, store)
819-
testLastCommittedBlockHeight(10, assert, store)
820-
821-
// prepare for block 10 and test store for presence of datakeys and eligibile missingdatakeys
822-
assert.NoError(store.Prepare(10, pvtdata, missingData))
823-
testPendingBatch(true, assert, store)
824-
testLastCommittedBlockHeight(10, assert, store)
825-
826-
datakeyTx0.blkNum = 10
827-
datakeyTx5.blkNum = 10
828-
eligibleMissingdatakey.blkNum = 10
829-
assert.True(testDataKeyExists(t, store, datakeyTx0))
830-
assert.True(testDataKeyExists(t, store, datakeyTx5))
831-
assert.True(testMissingDataKeyExists(t, store, eligibleMissingdatakey))
832-
833-
// rollback last prepared block and test store for absence of datakeys and eligibile missingdatakeys
834-
store.Rollback()
835-
testPendingBatch(false, assert, store)
836-
testLastCommittedBlockHeight(10, assert, store)
837-
assert.False(testDataKeyExists(t, store, datakeyTx0))
838-
assert.False(testDataKeyExists(t, store, datakeyTx5))
839-
assert.False(testMissingDataKeyExists(t, store, eligibleMissingdatakey))
840-
841-
// For previously committed blocks the datakeys and eligibile missingdatakeys should still be present
842-
for i := 1; i <= 9; i++ {
843-
datakeyTx0.blkNum = uint64(i)
844-
datakeyTx5.blkNum = uint64(i)
845-
eligibleMissingdatakey.blkNum = uint64(i)
846-
assert.True(testDataKeyExists(t, store, datakeyTx0))
847-
assert.True(testDataKeyExists(t, store, datakeyTx5))
848-
assert.True(testMissingDataKeyExists(t, store, eligibleMissingdatakey))
849-
}
850-
}
851-
852-
// TODO Add tests for simulating a crash between calls `Prepare` and `Commit`/`Rollback` - [FAB-13099]
772+
// TODO Add tests for simulating a crash between calls `Prepare` and `Commit` - [FAB-13099]
853773

854774
func testEmpty(expectedEmpty bool, assert *assert.Assertions, store Store) {
855775
isEmpty, err := store.IsEmpty()

0 commit comments

Comments
 (0)