Skip to content

Commit

Permalink
fix delete undos till end block
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Apr 4, 2024
1 parent 6ca06c8 commit 0205920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ func (db *OperationDB) Flush(ctx context.Context, cursor *sink.Cursor) (count in
func (db *OperationDB) PurgeUndoOperations(ctx context.Context, finalBlockHeight uint64) error {
keys := make([][]byte, 0)

scanOutput := db.store.Scan(ctx, undoKey(finalBlockHeight), undoKey(finalBlockHeight-1000), 0)
if finalBlockHeight < 200 {
return nil
}

scanOutput := db.store.Scan(ctx, undoKey(finalBlockHeight), undoKey(finalBlockHeight-200), 0)

if scanOutput.Err() != nil {
return fmt.Errorf("scanning undo operations for block %d: %w", finalBlockHeight, scanOutput.Err())
Expand Down
14 changes: 7 additions & 7 deletions db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestDB_HandleOperations(t *testing.T) {
name: "undo deletion",
blocks: []blockOperations{
{
blockNumber: 1,
blockNumber: 200,
operations: &pbkv.KVOperations{
Operations: []*pbkv.KVOperation{
{
Expand All @@ -67,10 +67,10 @@ func TestDB_HandleOperations(t *testing.T) {
},
},
},
finalBlockHeight: 1,
finalBlockHeight: 200,
},
{
blockNumber: 2,
blockNumber: 201,
operations: &pbkv.KVOperations{
Operations: []*pbkv.KVOperation{
{
Expand All @@ -80,10 +80,10 @@ func TestDB_HandleOperations(t *testing.T) {
},
},
},
finalBlockHeight: 1,
finalBlockHeight: 200,
},
{
blockNumber: 3,
blockNumber: 202,
operations: &pbkv.KVOperations{
Operations: []*pbkv.KVOperation{
{
Expand All @@ -93,10 +93,10 @@ func TestDB_HandleOperations(t *testing.T) {
},
},
},
finalBlockHeight: 1,
finalBlockHeight: 200,
},
},
expectedRemainingKey: [][]byte{userKey("key.1"), userKey("key.2"), userKey("key.3"), []byte("xc"), undoKey(3), undoKey(2)},
expectedRemainingKey: [][]byte{userKey("key.1"), userKey("key.2"), userKey("key.3"), []byte("xc"), undoKey(202), undoKey(201)},
},
}

Expand Down

0 comments on commit 0205920

Please sign in to comment.