Skip to content
Open
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: 21 additions & 0 deletions oxia/batch/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"io"
"sync/atomic"
"time"

"github.com/oxia-db/oxia/oxia/internal/model"
)

var ErrShuttingDown = errors.New("shutting down")
Expand Down Expand Up @@ -78,13 +80,31 @@
batch = nil
}

var prevCallIsDelete *bool = nil

Check failure on line 83 in oxia/batch/batcher.go

View workflow job for this annotation

GitHub Actions / Build & Test

var-declaration: should drop = nil from declaration of var prevCallIsDelete; it is the zero value (revive)
for {
select {
case call := <-b.callC:
var del = false
switch call.(type) {
case model.DeleteCall:
del = true
case model.DeleteRangeCall:
del = true
}
if prevCallIsDelete == nil {
prevCallIsDelete = &del
}

if batch == nil {
newBatch()
}
canAdd := batch.CanAdd(call)
if canAdd {
if del && !*prevCallIsDelete || !del && *prevCallIsDelete {
canAdd = false
}
}

if !canAdd {
completeBatch()
newBatch()
Expand All @@ -93,6 +113,7 @@
if batch.Size() == b.maxRequestsPerBatch || b.linger == 0 {
completeBatch()
}
prevCallIsDelete = &del

case <-timeout:
if batch != nil {
Expand Down
29 changes: 29 additions & 0 deletions oxiad/dataserver/public_rpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/oxia-db/oxia/oxia"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand Down Expand Up @@ -83,3 +84,31 @@ func TestWriteClientClose(t *testing.T) {
assert.Error(t, err)
assert.ErrorIs(t, err, io.EOF)
}

func TestPutThenDeleteThenPut(t *testing.T) {
standaloneServer, err := NewStandalone(NewTestConfig(t.TempDir()))
assert.NoError(t, err)
defer standaloneServer.Close()

client, err := oxia.NewAsyncClient(standaloneServer.ServiceAddr(), oxia.WithBatchLinger(1*time.Second), oxia.WithMaxRequestsPerBatch(1000))
assert.NoError(t, err)

defer client.Close()

putResult := client.Put("test-key", []byte("test-value"))
deleteResult := client.Delete("test-key")
putResult2 := client.Put("test-key", []byte("test-value2"))

r1 := <-putResult
r2 := <-deleteResult
r3 := <-putResult2

assert.NoError(t, r1.Err)
assert.NoError(t, r2)
assert.NoError(t, r3.Err)

v := <-client.Get("test-key")
assert.NoError(t, v.Err)

assert.Equal(t, []byte("test-value2"), v.Value)
}
Loading