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

[1.3] Rollback alloc map: remove all page ids which are allocated by the txid #823

Merged
merged 1 commit into from
Aug 20, 2024
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
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
Loading