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

fix: remove truncate api #48

Closed
wants to merge 1 commit into from
Closed
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
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.
Loading