Skip to content

Commit

Permalink
Merge pull request #823 from ahrtr/rollback_alloc_20240819_1.3
Browse files Browse the repository at this point in the history
[1.3] Rollback alloc map: remove all page ids which are allocated by the txid
  • Loading branch information
ahrtr authored Aug 20, 2024
2 parents 8c9b349 + 94db72d commit d128a10
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions freelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ func (f *freelist) rollback(txid txid) {
}
// Remove pages from pending list and mark as free if allocated by txid.
delete(f.pending, txid)

// Remove pgids which are allocated by this txid
for pgid, tid := range f.allocs {
if tid == txid {
delete(f.allocs, pgid)
}
}

f.mergeSpans(m)
}

Expand Down
34 changes: 34 additions & 0 deletions freelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sort"
"testing"
"unsafe"

"github.com/stretchr/testify/require"
)

// TestFreelistType is used as a env variable for test to indicate the backend type
Expand Down Expand Up @@ -253,6 +255,38 @@ func TestFreelistArray_allocate(t *testing.T) {
}
}

func Test_Freelist_Rollback(t *testing.T) {
f := newTestFreelist()

f.readIDs([]pgid{3, 5, 6, 7, 12, 13})

f.free(100, &page{
id: 20,
flags: 0,
count: 0,
overflow: 1,
})
f.allocate(100, 3)
f.free(100, &page{
id: 25,
flags: 0,
count: 0,
overflow: 0,
})
f.allocate(100, 2)

require.Equal(t, map[pgid]txid{5: 100, 12: 100}, f.allocs)
require.Equal(t, map[txid]*txPending{100: {
ids: []pgid{20, 21, 25},
alloctx: []txid{0, 0, 0},
}}, f.pending)

f.rollback(100)

require.Equal(t, map[pgid]txid{}, f.allocs)
require.Equal(t, map[txid]*txPending{}, f.pending)
}

// Ensure that a freelist can deserialize from a freelist page.
func TestFreelist_read(t *testing.T) {
// Create a page.
Expand Down

0 comments on commit d128a10

Please sign in to comment.