Skip to content

Feature/heap - #3

Merged
theweird-kid merged 13 commits into
mainfrom
feature/heap
Sep 27, 2026
Merged

theweird-kid merged 13 commits into
mainfrom
feature/heap

Conversation

@theweird-kid

Copy link
Copy Markdown
Owner

Implements DD-004: the slotted heap page and the table heap built on top of it.

What's in it

  • HeapPage — slotted page over the 4064-byte body. Slots never move; tuple bytes move freely,
    so compaction rewrites the tuple region without invalidating any RID. Dead-slot reuse,
    dead_bytes accounting, and CheckInvariants() after every mutation.
  • TableHeap — a chain of HEAP pages linked through next_page_id. Insert/Get/Delete/Update/Scan.
    • Chain extension uses the last page's write latch as the extension lock; the link is re-read
      under the latch, so concurrent inserters never allocate over each other.
    • v1 free-space reuse: a rotating insert hint plus compact-on-probe, bounded at 4 probes before
      appending.
    • Update relocates when a row outgrows its page (insert first, then delete) and returns the new RID.
  • TableIterator — forward scan that holds one guard at a time and copies each tuple out.
    Documented hazard: mutating through a live iterator self-deadlocks; use collect-then-mutate.
  • BufferPoolManager fix — FetchFrame rejects INVALID_PAGE / META_PAGE_ID up front.
    Previously both took the miss path and aborted debug builds on an assert in AbandonLoad.

Tests

  • heap_page_test.cpp and table_heap_test.cpp (32 tests, six tiers: durability across reopen,
    row lifecycle and error codes, chain and scan, space accounting and compaction, update, concurrency).
  • Concurrency tests cover the chain-extension race and check the file itself:
    PageCount() == chain pages + reserved, so a leaked page fails the test.
  • 144/144 ctest green under asan and tsan locally; concurrency tests 30/30 under tsan.

Co-authored-by: theweird-kid <62593159+theweird-kid@users.noreply.github.com>
Co-authored-by: theweird-kid <62593159+theweird-kid@users.noreply.github.com>
@theweird-kid
theweird-kid merged commit 2ecbe2a into main Sep 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants