From 64e864d9285f8be81eeecbe08725c5f1da444841 Mon Sep 17 00:00:00 2001 From: pokeeffe-molecula Date: Tue, 28 Mar 2023 09:15:45 -0500 Subject: [PATCH] fixed some bugs --- tstore/btree.go | 18 ++++++------------ tstore/btree_test.go | 30 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/tstore/btree.go b/tstore/btree.go index cc8e24159..ea012cddc 100644 --- a/tstore/btree.go +++ b/tstore/btree.go @@ -17,15 +17,9 @@ import ( // TODO(pok) // ▶ on open index run the aries recovery -// ▶ move latchState into Page ✅ -// ▶ latch buffer pool ✅ -// ▶ schema versioning on the page 🔧 -// ▶ write initial schema version on the root page ✅ -// ▶ write new schema versions on the root page - what happens when we have more schema version than fit on the root page -// hint - schema should probably be its own b-tree (sigh) -// ▶ handle schema version overflow ✅ - // ▶ put the insert into the split routine, so we don't have the do the insert after the fact +// ▶ add a BTreeFile struct to wrap n (data, schema) BTrees +// ▶ move bootstrap into BTreeFile ? // - [x] Tuple format // writeTID (int64) @@ -37,9 +31,6 @@ import ( // [valueLen (int32)] optional only used for variable length types (right now varchar) // valueBytes -// ▶ math that that works out max payload length for a tuple ✅ -// - tries to key fanout min >= 4 ✅ - // ▶ WAL // ▶ implement log buffers for wal files // in the buffer pool keep some buffers @@ -57,7 +48,6 @@ import ( // ▶ implement a checkpoint that scans the pool and writes out dirty pages periodically // ▶ MVCC versioning -// ▶ 3000+ columns (thanks Q2) ✅ // ▶ handle nulls on insert // ▶ backup/restore @@ -247,6 +237,7 @@ func NewBTree(maxKeySize int, objectID int32, shard int32, schema types.Schema, return nil, err } tree.schemaVersion = 1 + tree.schema = schema // TODO(pok) - can take this out once we have logging and checkpoints tree.bufferpool.FlushPage(schemaNode.page.ID()) } else { @@ -911,6 +902,9 @@ func (b *BTree) writeLeafEntryInSlot(node *BTreeNode, slotNumber int16, keyBytes // set the payload chunk length to the free space on the page // less the 2 byte chunk length payloadChunkLength := overflowFreeSpace - 2 + if payloadChunkLength > bytesRemaining { + payloadChunkLength = bytesRemaining + } hiWater += payloadChunkLength overflowPage.page.WriteNextPointer(bufferpool.PageID{ObjectID: b.objectID, Shard: b.shard, Page: nextOverflowPtr}) diff --git a/tstore/btree_test.go b/tstore/btree_test.go index 445f5b98f..07ddda329 100644 --- a/tstore/btree_test.go +++ b/tstore/btree_test.go @@ -49,12 +49,14 @@ func TestAddItemsToBTreeAndValidate(t *testing.T) { } inserts := make([]int, 0) - for i := 1; i <= 300; i++ { + for i := 1; i <= 3000; i++ { inserts = append(inserts, i) } rand.Shuffle(len(inserts), func(i, j int) { inserts[i], inserts[j] = inserts[j], inserts[i] }) rr := make(types.Row, 2) + + start := time.Now() for _, i := range inserts { rr[0] = int64(i) rr[1] = fmt.Sprintf("This is a test of things %d", i) @@ -72,9 +74,29 @@ func TestAddItemsToBTreeAndValidate(t *testing.T) { } } - key, tuple, _ := b.Search(nil, Int(33)) + duration := time.Since(start) + fmt.Printf("inserted %d rows in %v\n", 3000, duration) - fmt.Printf("%v, %v\n\n", key, tuple) + start = time.Now() + key, tuple, _ := b.Search(nil, Int(33)) + duration = time.Since(start) + + vals := "[" + for i, v := range tuple.Tuple { + if i > 10 { + vals += "..." + break + } + if i != 0 { + vals += ", " + } + vals += fmt.Sprintf("%v", v) + } + vals += "]" + + fmt.Printf("retrieved key %v, tuple (%d columns), %s in %v\n", key, len(tuple.TupleSchema), vals, duration) + + fmt.Printf("\n\n") b.Dump(0) } @@ -93,7 +115,7 @@ func TestAddItemsToBTreeAndValidate_VeryWide(t *testing.T) { tableSchema := make(types.Schema, 0) var numCols = 3000 - var numRecs = 1000000 + var numRecs = 3000 // build schema for i := 0; i < numCols; i++ {