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

Experiments #141

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
name
pkieltyka committed Mar 21, 2025
commit cceed08fbbff462a1fab8c327bee9c7b8a26a0ac
2 changes: 1 addition & 1 deletion batch.go
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ type Batch interface {
Setter
Deleter
DeleterWithRange
Iterationer
Iterable

Applier
Committer
64 changes: 32 additions & 32 deletions bond.go
Original file line number Diff line number Diff line change
@@ -29,14 +29,44 @@ const (
BOND_DB_DATA_USER_SPACE_INDEX_ID = 0xFF
)

const exportFileSize = 17 << 20
const exportFileSize = 17 << 20 // 17 MB

const PebbleFormatFile = "PEBBLE_FORMAT_VERSION"

var (
ErrNotFound = fmt.Errorf("bond: not found")
)

const DefaultKeyBufferSize = 2048
const DefaultValueBufferSize = 2048
const DefaultNumberOfKeyBuffersInMultiKeyBuffer = 1000

const DefaultNumberOfPreAllocKeyBuffers = 2 * persistentBatchSize
const DefaultNumberOfPreAllocMultiKeyBuffers = 10
const DefaultNumberOfPreAllocValueBuffers = 10 * DefaultScanPrefetchSize
const DefaultNumberOfPreAllocBytesArrays = 50

type DB interface {
internalPools

Backend() *pebble.DB
Serializer() Serializer[any]

Getter
Setter
Deleter
DeleterWithRange
Iterable

Batcher
Applier

Closer
Backup

OnClose(func(db DB))
}

type WriteOptions struct {
Sync bool
}
@@ -66,7 +96,7 @@ type Batcher interface {
Batch(bType BatchType) Batch
}

type Iterationer interface { // TODO: weird name
type Iterable interface {
Iter(opt *IterOptions, batch ...Batch) Iterator
}

@@ -81,15 +111,6 @@ type Backup interface {

type Closer io.Closer

const DefaultKeyBufferSize = 2048
const DefaultValueBufferSize = 2048
const DefaultNumberOfKeyBuffersInMultiKeyBuffer = 1000

const DefaultNumberOfPreAllocKeyBuffers = 2 * persistentBatchSize
const DefaultNumberOfPreAllocMultiKeyBuffers = 10
const DefaultNumberOfPreAllocValueBuffers = 10 * DefaultScanPrefetchSize
const DefaultNumberOfPreAllocBytesArrays = 50

type internalPools interface {
getKeyBufferPool() *utils.PreAllocatedPool[[]byte]
getMultiKeyBufferPool() *utils.PreAllocatedPool[[]byte]
@@ -101,27 +122,6 @@ type internalPools interface {
putValueArray(arr [][]byte)
}

type DB interface {
internalPools

Backend() *pebble.DB
Serializer() Serializer[any]

Getter
Setter
Deleter
DeleterWithRange
Iterationer

Batcher
Applier

Closer
Backup

OnClose(func(db DB))
}

type _db struct {
pebble *pebble.DB

2 changes: 1 addition & 1 deletion index.go
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ func (idx *Index[T]) Name() string {

// Iter returns an iterator for the index.
func (idx *Index[T]) Iter(table Table[T], selector Selector[T], optBatch ...Batch) Iterator {
var iterConstructor Iterationer = table.DB()
var iterConstructor Iterable = table.DB()
if len(optBatch) > 0 {
iterConstructor = optBatch[0]
}
4 changes: 2 additions & 2 deletions iter.go
Original file line number Diff line number Diff line change
@@ -73,11 +73,11 @@ type _iteratorMulti struct {
iteratorOptions []*IterOptions
iteratorOptionsIndex int

iteratorConstuctor Iterationer
iteratorConstuctor Iterable
iterator Iterator
}

func newIteratorMulti(itc Iterationer, opts []*IterOptions) *_iteratorMulti {
func newIteratorMulti(itc Iterable, opts []*IterOptions) *_iteratorMulti {
return &_iteratorMulti{
iteratorOptions: opts,
iteratorOptionsIndex: 0,
2 changes: 2 additions & 0 deletions serializers/serializers_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package serializers_test

// TODOXXX: delete..

// TODO: lets inspect how cbor is marshalling this.. maybe we can make it
// more efficient out of the gate..? by having it implement the encoding.BinaryMarshaler
// interface. ....??..
4 changes: 2 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ type TableScanner[T any] interface {
ScanIndexForEach(ctx context.Context, idx *Index[T], s Selector[T], f func(keyBytes KeyBytes, t Lazy[T]) (bool, error), reverse bool, optBatch ...Batch) error
}

type TableIterationer[T any] interface {
type TableIterable[T any] interface {
Iter(sel Selector[T], optBatch ...Batch) Iterator
}

@@ -76,7 +76,7 @@ type TableReader[T any] interface {
TableQuerier[T]

TableScanner[T]
TableIterationer[T]
TableIterable[T]
}

type TableInserter[T any] interface {