-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FAB-17800] Reset/Rollback returns error if a channel was bootstrapped from a snapshot #1990
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ package tests | |
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hyperledger/fabric-protos-go/common" | ||
"github.com/hyperledger/fabric/common/ledger/blkstorage" | ||
|
@@ -217,3 +218,58 @@ func TestResetLedgerWithoutDroppingDBs(t *testing.T) { | |
"This is possible when the state database is not dropped after a ledger reset/rollback. "+ | ||
"The state database can safely be dropped and will be rebuilt up to block store height upon the next peer start") | ||
} | ||
|
||
func TestResetFailIfAnyLedgerBootstrappedFromSnapshot(t *testing.T) { | ||
env := newEnv(t) | ||
defer env.cleanup() | ||
env.initLedgerMgmt() | ||
|
||
// populate ledgers with sample data | ||
ledgerID := "testLedgerFromSnapshot" | ||
dataHelper := newSampleDataHelper(t) | ||
h := env.newTestHelperCreateLgr(ledgerID, t) | ||
dataHelper.populateLedger(h) | ||
dataHelper.verifyLedgerContent(h) | ||
bcInfo, err := h.lgr.GetBlockchainInfo() | ||
require.NoError(t, err) | ||
|
||
// create a sanapshot | ||
blockNum := bcInfo.Height - 1 | ||
require.NoError(t, h.lgr.SubmitSnapshotRequest(blockNum)) | ||
// wait until snapshot is generated | ||
snapshotGenerated := func() bool { | ||
requests, err := h.lgr.PendingSnapshotRequests() | ||
require.NoError(t, err) | ||
return len(requests) == 0 | ||
} | ||
require.Eventually(t, snapshotGenerated, time.Minute, 100*time.Millisecond) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100ms seem unnecessarily long to me... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sample ledger has 9 blocks. When running UT locally, there were the following timestamps, so the elapsed time was 337-202=135ms. 2020-10-09 16:21:59.202 EDT [kvledger] func2 -> INFO 1dd^[[0m Generating snapshot channelID=testLedgerFromSnapshot lastCommittedBlockNumber=8 2020-10-09 16:21:59.337 EDT [kvledger] func2 -> INFO 200^[[0m Generated snapshot channelID=testLedgerFromSnapshot lastCommittedBlockNumber=8 |
||
snapshotDir := kvledger.SnapshotDirForLedgerBlockNum(env.initializer.Config.SnapshotsConfig.RootDir, ledgerID, blockNum) | ||
env.closeLedgerMgmt() | ||
|
||
// creates a new env with multiple ledgers, some from genesis block and some from a snapshot | ||
env2 := newEnv(t) | ||
defer env2.cleanup() | ||
env2.initLedgerMgmt() | ||
|
||
for i := 0; i < 2; i++ { | ||
ledgerID := fmt.Sprintf("ledger-%d", i) | ||
env2.newTestHelperCreateLgr(ledgerID, t) | ||
} | ||
|
||
callbackCounter := 0 | ||
callback := func(l ledger.PeerLedger, cid string) { callbackCounter++ } | ||
require.NoError(t, env2.ledgerMgr.CreateLedgerFromSnapshot(snapshotDir, callback)) | ||
|
||
// wait until ledger creation is done | ||
ledgerCreated := func() bool { | ||
status := env2.ledgerMgr.JoinBySnapshotStatus() | ||
return !status.InProgress && status.BootstrappingSnapshotDir == "" | ||
} | ||
require.Eventually(t, ledgerCreated, time.Minute, 100*time.Microsecond) | ||
require.Equal(t, 1, callbackCounter) | ||
env2.closeLedgerMgmt() | ||
|
||
wenjianqiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// reset should fail | ||
err = kvledger.ResetAllKVLedgers(env2.initializer.Config.RootFSPath) | ||
require.EqualError(t, err, "cannot reset channels because at least one channel was bootstrapped from a snapshot: [testLedgerFromSnapshot]") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to remove "defer"