diff --git a/batch_attr.go b/batch_attr.go index e8232897..95e997b1 100644 --- a/batch_attr.go +++ b/batch_attr.go @@ -42,6 +42,9 @@ 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 == "" { @@ -49,10 +52,6 @@ func newBatchAttrOps(rp *BatchPolicy, wp *BatchWritePolicy, ops []*Operation) { } hasRead = true - if op.headerOnly { - readHeader = true - } - default: hasWriteOp = true } @@ -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: } } @@ -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: } diff --git a/cdt_list_test.go b/cdt_list_test.go index 99c2ead6..cfa7e16c 100644 --- a/cdt_list_test.go +++ b/cdt_list_test.go @@ -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) @@ -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()) diff --git a/command.go b/command.go index e7ef433f..583d91d5 100644 --- a/command.go +++ b/command.go @@ -2235,21 +2235,15 @@ 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 { @@ -2257,9 +2251,6 @@ func (cmd *baseCommand) writeBatchReadOperations(ops []*Operation, readAttr int) } } - if readHeader && !readBin { - readAttr |= _INFO1_NOBINDATA - } return byte(readAttr), nil } diff --git a/operate_args.go b/operate_args.go index 6d8b1f65..2afe5365 100644 --- a/operate_args.go +++ b/operate_args.go @@ -39,7 +39,7 @@ func newOperateArgs( write := false readBin := false readHeader := false - respondAllOps := policy.RespondPerEachOp + respondAllOps := false for _, operation := range operations { switch operation.opType { @@ -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 @@ -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 diff --git a/operation.go b/operation.go index 333b8c5b..ac384668 100644 --- a/operation.go +++ b/operation.go @@ -20,8 +20,9 @@ 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 @@ -29,34 +30,33 @@ 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: @@ -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. @@ -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.