Skip to content
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

fix: rootmulti's Restore don't return the next unknown item as expected #11286

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion store/rootmulti/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
target := newMultiStoreWithMixedMounts(dbm.NewMemDB())
version := uint64(source.LastCommitID().Version)
require.EqualValues(t, 3, version)
dummyExtensionItem := snapshottypes.SnapshotItem{
Item: &snapshottypes.SnapshotItem_Extension{
Extension: &snapshottypes.SnapshotExtensionMeta{
Name: "test",
Format: 1,
},
},
}

chunks := make(chan io.ReadCloser, 100)
go func() {
Expand All @@ -190,12 +198,16 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
defer streamWriter.Close()
err := source.Snapshot(version, streamWriter)
require.NoError(t, err)
// write an extension metadata
err = streamWriter.WriteMsg(&dummyExtensionItem)
require.NoError(t, err)
}()

streamReader, err := snapshots.NewStreamReader(chunks)
require.NoError(t, err)
_, err = target.Restore(version, snapshottypes.CurrentFormat, streamReader)
nextItem, err := target.Restore(version, snapshottypes.CurrentFormat, streamReader)
require.NoError(t, err)
require.Equal(t, *dummyExtensionItem.GetExtension(), *nextItem.GetExtension())

assert.Equal(t, source.LastCommitID(), target.LastCommitID())
for key, sourceStore := range source.GetStores() {
Expand Down
11 changes: 6 additions & 5 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,11 @@ func (rs *Store) Restore(
// a SnapshotStoreItem, telling us which store to import into. The following items will contain
// SnapshotNodeItem (i.e. ExportNode) until we reach the next SnapshotStoreItem or EOF.
var importer *iavltree.Importer
var snapshotItem snapshottypes.SnapshotItem
loop:
for {
snapshotItem := &snapshottypes.SnapshotItem{}
err := protoReader.ReadMsg(snapshotItem)
snapshotItem = snapshottypes.SnapshotItem{}
err := protoReader.ReadMsg(&snapshotItem)
if err == io.EOF {
break
} else if err != nil {
Expand Down Expand Up @@ -811,8 +813,7 @@ func (rs *Store) Restore(
}

default:
// pass back the unrecognized item.
return *snapshotItem, nil
break loop
}
}

Expand All @@ -825,7 +826,7 @@ func (rs *Store) Restore(
}

flushMetadata(rs.db, int64(height), rs.buildCommitInfo(int64(height)), []int64{})
return snapshottypes.SnapshotItem{}, rs.LoadLatestVersion()
return snapshotItem, rs.LoadLatestVersion()
}

func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID, params storeParams) (types.CommitKVStore, error) {
Expand Down
Loading