Skip to content

Commit

Permalink
fix: remove truncate api
Browse files Browse the repository at this point in the history
Removing the truncate API for now since compaction isn't really a function of the B+ tree and we'll migrate it elsewhere.
  • Loading branch information
kevmo314 committed Jan 20, 2024
1 parent d5e2537 commit 6180185
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions pkg/btree/bptree.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ type MetaPage interface {
SetRoot(MemoryPointer) error
}

type ReadWriteSeekTruncater interface {
io.ReadWriteSeeker
Truncate(size int64) error
}

type BPTree struct {
tree ReadWriteSeekTruncater
tree io.ReadWriteSeeker
meta MetaPage

maxPageSize int
}

func NewBPTree(tree ReadWriteSeekTruncater, meta MetaPage, maxPageSize int) *BPTree {
func NewBPTree(tree io.ReadWriteSeeker, meta MetaPage, maxPageSize int) *BPTree {
return &BPTree{tree: tree, meta: meta, maxPageSize: maxPageSize}
}

Expand Down Expand Up @@ -184,7 +179,11 @@ func (t *BPTree) Insert(key ReferencedValue, value MemoryPointer) error {
n.Pointers = n.Pointers[:mid+1]
n.Keys = n.Keys[:mid]
}
noffset := moffset + msize
// seek has to be done again to trigger a new page allocation
noffset, err := t.tree.Seek(0, io.SeekEnd)
if err != nil {
return err
}
nsize, err := n.WriteTo(t.tree)
if err != nil {
return err
Expand Down Expand Up @@ -406,9 +405,9 @@ func (t *BPTree) compact() error {
}

// truncate the file
if err := t.tree.Truncate(int64(offset)); err != nil {
return err
}
// if err := t.tree.Truncate(int64(offset)); err != nil {
// return err
// }

// update the parent pointers
if _, err := t.tree.Seek(0, io.SeekStart); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/btree/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ func (m *LinkedMetaPage) Reset() error {
return nil
}

func NewMultiBPTree(t ReadWriteSeekTruncater) *LinkedMetaPage {
func NewMultiBPTree(t io.ReadWriteSeeker) *LinkedMetaPage {
return &LinkedMetaPage{rws: t, offset: 0}
}
Empty file added src/bptree.ts
Empty file.

0 comments on commit 6180185

Please sign in to comment.