Skip to content

Commit

Permalink
[CLIENT-2811] RespondPerEachOp doesn't work for list operation
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Mar 19, 2024
1 parent 166f719 commit 59a5d86
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 65 deletions.
22 changes: 9 additions & 13 deletions batch_attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ func newBatchAttrOps(rp *BatchPolicy, wp *BatchWritePolicy, ops []*Operation) {

for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readHeader = true
hasRead = true
case _BIT_READ, _EXP_READ, _HLL_READ, _MAP_READ, _CDT_READ, _READ:
// _Read all bins if no bin is specified.
if op.binName == "" {
readAllBins = true
}
hasRead = true

if op.headerOnly {
readHeader = true
}

default:
hasWriteOp = true
}
Expand Down Expand Up @@ -141,15 +140,13 @@ func (ba *batchAttr) adjustRead(ops []*Operation) {

for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readHeader = true
case _BIT_READ, _EXP_READ, _HLL_READ, _MAP_READ, _CDT_READ, _READ:
// _Read all bins if no bin is specified.
// Read all bins if no bin is specified.
if op.binName == "" {
readAllBins = true
}
if op.headerOnly {
readHeader = true
}

default:
}
}
Expand Down Expand Up @@ -232,16 +229,15 @@ func (ba *batchAttr) adjustWrite(ops []*Operation) {

for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readHeader = true
hasRead = true
case _BIT_READ, _EXP_READ, _HLL_READ, _MAP_READ, _CDT_READ, _READ:
// _Read all bins if no bin is specified.
if op.binName == "" {
readAllBins = true
}
hasRead = true
if op.headerOnly {
readHeader = true
hasRead = true
}

default:
}
Expand Down
4 changes: 2 additions & 2 deletions cdt_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ var _ = gg.Describe("CDT List Test", func() {
for i := 0; i < listSize; i++ {
cdtListRes, err := client.Operate(wpolicy, key, as.ListSetOp(cdtBinName, i, math.MaxInt64))
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(cdtListRes.Bins).To(gm.Equal(as.BinMap{cdtBinName: nil}))
gm.Expect(cdtListRes.Bins).To(gm.Equal(as.BinMap{}))

elems = append(elems, math.MaxInt64)

Expand All @@ -543,7 +543,7 @@ var _ = gg.Describe("CDT List Test", func() {
gg.It("should set the last element", func() {
cdtListRes, err := client.Operate(wpolicy, key, as.ListSetOp(cdtBinName, -1, math.MaxInt64))
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(cdtListRes.Bins).To(gm.Equal(as.BinMap{cdtBinName: nil}))
gm.Expect(cdtListRes.Bins).To(gm.Equal(as.BinMap{}))

cdtListRes, err = client.Operate(wpolicy, key, as.ListGetOp(cdtBinName, -1))
gm.Expect(err).ToNot(gm.HaveOccurred())
Expand Down
13 changes: 2 additions & 11 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2235,31 +2235,22 @@ func (cmd *baseCommand) writeOperationForBinNameAndValue(name string, val interf
}

func (cmd *baseCommand) writeBatchReadOperations(ops []*Operation, readAttr int) (byte, Error) {
readBin := false
readHeader := false

for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readAttr |= _INFO1_NOBINDATA
case _READ:
// Read all bins if no bin is specified.
if len(op.binName) == 0 {
readAttr |= _INFO1_GET_ALL
}
readBin = true

if op.headerOnly {
readHeader = true
}
default:
}
if err := cmd.writeOperationForOperation(op); err != nil {
return byte(readAttr), err
}
}

if readHeader && !readBin {
readAttr |= _INFO1_NOBINDATA
}
return byte(readAttr), nil
}

Expand Down
23 changes: 11 additions & 12 deletions operate_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newOperateArgs(
write := false
readBin := false
readHeader := false
respondAllOps := policy.RespondPerEachOp
respondAllOps := false

for _, operation := range operations {
switch operation.opType {
Expand All @@ -49,18 +49,16 @@ func newOperateArgs(
// Fall through to read.
fallthrough
case _CDT_READ, _READ:
if operation.headerOnly {
rattr |= _INFO1_READ
readHeader = true
} else {
rattr |= _INFO1_READ
rattr |= _INFO1_READ

// Read all bins if no bin is specified.
if len(operation.binName) == 0 {
rattr |= _INFO1_GET_ALL
}
readBin = true
// Read all bins if no bin is specified.
if len(operation.binName) == 0 {
rattr |= _INFO1_GET_ALL
}
readBin = true
case _READ_HEADER:
rattr |= _INFO1_READ
readHeader = true
case _BIT_MODIFY, _EXP_MODIFY, _HLL_MODIFY, _MAP_MODIFY:
// Map operations require respondAllOps to be true.
respondAllOps = true
Expand All @@ -79,7 +77,8 @@ func newOperateArgs(
}
res.readAttr = rattr

if respondAllOps {
// When GET_ALL is specified, RESPOND_ALL_OPS must be disabled.
if (respondAllOps || res.writePolicy.RespondPerEachOp) && (rattr&_INFO1_GET_ALL) == 0 {
wattr |= _INFO2_RESPOND_ALL_OPS
}
res.writeAttr = wattr
Expand Down
51 changes: 24 additions & 27 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,43 @@ import (

// OperationType determines operation type
type OperationType struct {
op byte
isWrite bool
op byte
isWrite bool
enumDist byte // make the values like enum to distinguish them from each other
}

type operationSubType *int

// Valid OperationType values that can be used to create custom Operations.
// The names are self-explanatory.
var (
_READ = OperationType{1, false}
// _READ_HEADER = OperationType{1, false}
_WRITE = OperationType{2, true}
_CDT_READ = OperationType{3, false}
_CDT_MODIFY = OperationType{4, true}
_MAP_READ = OperationType{3, false}
_MAP_MODIFY = OperationType{4, true}
_ADD = OperationType{5, true}
_EXP_READ = OperationType{7, false}
_EXP_MODIFY = OperationType{8, true}
_APPEND = OperationType{9, true}
_PREPEND = OperationType{10, true}
_TOUCH = OperationType{11, true}
_BIT_READ = OperationType{12, false}
_BIT_MODIFY = OperationType{13, true}
_DELETE = OperationType{14, true}
_HLL_READ = OperationType{15, false}
_HLL_MODIFY = OperationType{16, true}
_READ = OperationType{1, false, 0}
_READ_HEADER = OperationType{1, false, 1}
_WRITE = OperationType{2, true, 2}
_CDT_READ = OperationType{3, false, 3}
_CDT_MODIFY = OperationType{4, true, 4}
_MAP_READ = OperationType{3, false, 5}
_MAP_MODIFY = OperationType{4, true, 6}
_ADD = OperationType{5, true, 7}
_EXP_READ = OperationType{7, false, 8}
_EXP_MODIFY = OperationType{8, true, 9}
_APPEND = OperationType{9, true, 10}
_PREPEND = OperationType{10, true, 11}
_TOUCH = OperationType{11, true, 12}
_BIT_READ = OperationType{12, false, 13}
_BIT_MODIFY = OperationType{13, true, 14}
_DELETE = OperationType{14, true, 15}
_HLL_READ = OperationType{15, false, 16}
_HLL_MODIFY = OperationType{16, true, 17}
)

func (o *Operation) grpc_op_type() kvs.OperationType {
// case _READ: return kvs.OperationType_READ
switch o.opType {
case _READ:
if o.headerOnly {
return kvs.OperationType_READ_HEADER
}
return kvs.OperationType_READ
case _READ_HEADER:
return kvs.OperationType_READ_HEADER
case _WRITE:
return kvs.OperationType_WRITE
case _CDT_READ:
Expand Down Expand Up @@ -112,9 +112,6 @@ type Operation struct {

// binValue (Optional) determines bin value used in operation.
binValue Value

// will be true ONLY for GetHeader() operation
headerOnly bool
}

// size returns the size of the operation on the wire protocol.
Expand Down Expand Up @@ -163,7 +160,7 @@ func GetOp() *Operation {

// GetHeaderOp creates read record header database operation.
func GetHeaderOp() *Operation {
return &Operation{opType: _READ, headerOnly: true, binValue: NewNullValue()}
return &Operation{opType: _READ_HEADER, binValue: NewNullValue()}
}

// PutOp creates set database operation.
Expand Down

0 comments on commit 59a5d86

Please sign in to comment.