Skip to content

Commit

Permalink
Rename Batch.Indexed to Batch.Type
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Apr 17, 2024
1 parent 1cf9740 commit eec65c3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
16 changes: 15 additions & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ type Committer interface {
OnClose(func(b Batch))
}

type BatchType int

const (
BatchTypeWriteOnly BatchType = iota
BatchTypeReadWrite
)

type Batch interface {
ID() uint64
Len() int
Empty() bool
Reset()

Indexed() bool
Type() BatchType

Getter
Setter
Expand Down Expand Up @@ -66,6 +73,13 @@ func (b *_batch) ID() uint64 {
return b.id
}

func (b *_batch) Type() BatchType {
if b.Batch.Indexed() {
return BatchTypeReadWrite
}
return BatchTypeWriteOnly
}

func (b *_batch) Reset() {
b.Batch.Reset()

Expand Down
7 changes: 0 additions & 7 deletions bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ type DeleterWithRange interface {
DeleteRange(start []byte, end []byte, opt WriteOptions, batch ...Batch) error
}

type BatchType int

const (
BatchTypeWriteOnly BatchType = iota
BatchTypeReadWrite
)

type Batcher interface {
Batch(bType BatchType) Batch
}
Expand Down
10 changes: 5 additions & 5 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ func (m *MockBatch) ID() uint64 {
panic("implement me")
}

func (m *MockBatch) Len() int {
func (m *MockBatch) Type() BatchType {
//TODO implement me
panic("implement me")
}

func (m *MockBatch) Empty() bool {
func (m *MockBatch) Len() int {
//TODO implement me
panic("implement me")
}

func (m *MockBatch) Reset() {
func (m *MockBatch) Empty() bool {
//TODO implement me
panic("implement me")
}

func (m *MockBatch) ResetRetained() {
func (m *MockBatch) Reset() {
//TODO implement me
panic("implement me")
}

func (m *MockBatch) Indexed() bool {
func (m *MockBatch) ResetRetained() {
//TODO implement me
panic("implement me")
}
Expand Down
36 changes: 18 additions & 18 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ func (t *_table[T]) Insert(ctx context.Context, trs []T, optBatch ...Batch) erro
t.mutex.RUnlock()

var (
batch Batch
batchIndexed Batch
externalBatch = len(optBatch) > 0 && optBatch[0] != nil
batch Batch
batchReadWrite Batch
externalBatch = len(optBatch) > 0 && optBatch[0] != nil
)

if externalBatch {
Expand All @@ -354,8 +354,8 @@ func (t *_table[T]) Insert(ctx context.Context, trs []T, optBatch ...Batch) erro
defer batch.Close()
}

if batch.Indexed() {
batchIndexed = batch
if batch.Type() == BatchTypeReadWrite {
batchReadWrite = batch
}

var (
Expand Down Expand Up @@ -391,7 +391,7 @@ func (t *_table[T]) Insert(ctx context.Context, trs []T, optBatch ...Batch) erro
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
},
}, batchIndexed)
}, batchReadWrite)
defer iter.Close()

// process rows
Expand Down Expand Up @@ -456,9 +456,9 @@ func (t *_table[T]) Update(ctx context.Context, trs []T, optBatch ...Batch) erro
t.mutex.RUnlock()

var (
batch Batch
batchIndexed Batch
externalBatch = len(optBatch) > 0 && optBatch[0] != nil
batch Batch
batchReadWrite Batch
externalBatch = len(optBatch) > 0 && optBatch[0] != nil
)

if externalBatch {
Expand All @@ -468,8 +468,8 @@ func (t *_table[T]) Update(ctx context.Context, trs []T, optBatch ...Batch) erro
defer batch.Close()
}

if batch.Indexed() {
batchIndexed = batch
if batch.Type() == BatchTypeReadWrite {
batchReadWrite = batch
}

var (
Expand Down Expand Up @@ -510,7 +510,7 @@ func (t *_table[T]) Update(ctx context.Context, trs []T, optBatch ...Batch) erro
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
},
}, batchIndexed)
}, batchReadWrite)
defer iter.Close()

for i, key := range keys {
Expand Down Expand Up @@ -641,9 +641,9 @@ func (t *_table[T]) Upsert(ctx context.Context, trs []T, onConflict func(old, ne
t.mutex.RUnlock()

var (
batch Batch
batchIndexed Batch
externalBatch = len(optBatch) > 0 && optBatch[0] != nil
batch Batch
batchReadWrite Batch
externalBatch = len(optBatch) > 0 && optBatch[0] != nil
)

if externalBatch {
Expand All @@ -653,8 +653,8 @@ func (t *_table[T]) Upsert(ctx context.Context, trs []T, onConflict func(old, ne
defer batch.Close()
}

if batch.Indexed() {
batchIndexed = batch
if batch.Type() == BatchTypeReadWrite {
batchReadWrite = batch
}

var (
Expand Down Expand Up @@ -695,7 +695,7 @@ func (t *_table[T]) Upsert(ctx context.Context, trs []T, onConflict func(old, ne
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
},
}, batchIndexed)
}, batchReadWrite)
defer iter.Close()

for i := 0; i < len(keys); {
Expand Down

0 comments on commit eec65c3

Please sign in to comment.