Skip to content

Commit

Permalink
[CLIENT-2223] Reset the BatchRecord.Err when it is reused
Browse files Browse the repository at this point in the history
Improve the BatchOperate test
  • Loading branch information
khaf committed May 8, 2024
1 parent 6031dd6 commit 2ebeb8c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion batch_command_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ func (cmd *batchCommandDelete) transactionType() transactionType {
}

func (cmd *batchCommandDelete) executeSingle(client *Client) Error {
policy := cmd.batchDeletePolicy.toWritePolicy(cmd.policy)
for i, key := range cmd.keys {
res, err := client.Operate(cmd.batchDeletePolicy.toWritePolicy(cmd.policy), key, DeleteOp())
res, err := client.Operate(policy, key, DeleteOp())
cmd.records[i].setRecord(res)
if err != nil {
cmd.records[i].setRawError(err)
Expand Down
1 change: 0 additions & 1 deletion batch_command_operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ func (cmd *batchCommandOperate) executeSingle(client *Client) Error {
br.setRecord(res)
case *BatchDelete:
policy := br.Policy.toWritePolicy(cmd.policy)
policy.RespondPerEachOp = true
res, err = client.Operate(policy, br.Key, DeleteOp())
br.setRecord(res)
case *BatchUDF:
Expand Down
2 changes: 2 additions & 0 deletions batch_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ func (br *BatchRecord) resultCode() types.ResultCode {
func (br *BatchRecord) prepare() {
br.Record = nil
br.ResultCode = types.NO_RESPONSE
br.Err = nil
br.InDoubt = false
}

// Set record result. For internal use only.
func (br *BatchRecord) setRecord(record *Record) {
br.Record = record
br.ResultCode = types.OK
br.Err = nil
}

// Set error result directly.
Expand Down
18 changes: 12 additions & 6 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ var _ = gg.Describe("Aerospike", func() {
err := client.BatchOperate(bpolicy, brecs)
gm.Expect(err).ToNot(gm.HaveOccurred())

// Since the ops will run out of order, there is always a chance that
// the read operation will run first and return a KEY_NOT_FOUND error.
// As a result we run the operate command twice.
err = client.BatchOperate(bpolicy, brecs)
gm.Expect(err).ToNot(gm.HaveOccurred())

gm.Expect(op1.BatchRec().Err).ToNot(gm.HaveOccurred())
gm.Expect(op1.BatchRec().ResultCode).To(gm.Equal(types.OK))
gm.Expect(op1.BatchRec().Record.Bins).To(gm.Equal(as.BinMap{"bin1": nil, "bin2": nil}))
Expand Down Expand Up @@ -279,6 +285,10 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(op1.BatchRec().Record.Bins).To(gm.Equal(as.BinMap{"bin1": nil, "bin2": nil}))
gm.Expect(op1.BatchRec().InDoubt).To(gm.BeFalse())

brecs = []as.BatchRecordIfc{op1, op3}
err = client.BatchOperate(bpolicy, brecs)
gm.Expect(err).ToNot(gm.HaveOccurred())

// There is no guarantee for the order of execution for different commands
gm.Expect(op3.BatchRec().Err).ToNot(gm.HaveOccurred())
gm.Expect(op3.BatchRec().Record).ToNot(gm.BeNil())
Expand All @@ -288,15 +298,10 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(exists).To(gm.BeTrue())

brecs = []as.BatchRecordIfc{op1, op2}
brecs = []as.BatchRecordIfc{op2}
err = client.BatchOperate(bpolicy, brecs)
gm.Expect(err).ToNot(gm.HaveOccurred())

gm.Expect(op1.BatchRec().Err).ToNot(gm.HaveOccurred())
gm.Expect(op1.BatchRec().ResultCode).To(gm.Equal(types.OK))
gm.Expect(op1.BatchRec().Record.Bins).To(gm.Equal(as.BinMap{"bin1": nil, "bin2": nil}))
gm.Expect(op1.BatchRec().InDoubt).To(gm.BeFalse())

gm.Expect(op2.BatchRec().Err).ToNot(gm.HaveOccurred())
gm.Expect(op2.BatchRec().ResultCode).To(gm.Equal(types.OK))
gm.Expect(op2.BatchRec().Record.Bins).To(gm.Equal(as.BinMap{}))
Expand Down Expand Up @@ -671,6 +676,7 @@ var _ = gg.Describe("Aerospike", func() {
bp := as.NewBatchPolicy()
bp.RespondAllKeys = false
err := client.BatchOperate(bp, batchRecords)
err = client.BatchOperate(bp, batchRecords)
// gm.Expect(err).ToNot(gm.HaveOccurred())

gm.Expect(batchRecords[0].BatchRec().Err.Matches(types.INVALID_NAMESPACE)).To(gm.BeTrue())
Expand Down

0 comments on commit 2ebeb8c

Please sign in to comment.