Skip to content

Commit

Permalink
chore: address the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai Kumar committed Feb 28, 2022
1 parent 3d09bbd commit 808fc1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 8 additions & 5 deletions store/v2/multi/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ func (rs *Store) Restore(
var subStore *substore
var storeSchemaReceived = false

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 @@ -153,15 +156,15 @@ func (rs *Store) Restore(
subStore.Set(item.KV.Key, item.KV.Value)

default:
return *snapshotItem, nil
break loop
}
}

// commit the all key/values to store
_, err := rs.commit(height)
if err != nil {
return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(err, fmt.Sprintf("error during commit the store at height %d", height))
return snapshotItem, sdkerrors.Wrap(err, fmt.Sprintf("error during commit the store at height %d", height))
}

return snapshottypes.SnapshotItem{}, nil
return snapshotItem, nil
}
15 changes: 14 additions & 1 deletion store/v2/multi/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,32 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
// check for target store restore
require.Equal(t, target.LastCommitID().Version, int64(0))

dummyExtensionItem := snapshottypes.SnapshotItem{
Item: &snapshottypes.SnapshotItem_Extension{
Extension: &snapshottypes.SnapshotExtensionMeta{
Name: "test",
Format: 1,
},
},
}

chunks := make(chan io.ReadCloser, 100)
go func() {
streamWriter := snapshots.NewStreamWriter(chunks)
require.NotNil(t, streamWriter)
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())

Expand Down

0 comments on commit 808fc1e

Please sign in to comment.