Skip to content

Commit 2d86b37

Browse files
committed
return error for txn condition not succeeded
1 parent d33f2fc commit 2d86b37

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

store/etcdv3/workload.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,22 @@ func (m *Mercury) doOpsWorkload(ctx context.Context, workload *types.Workload, p
278278
filepath.Join(workloadDeployPrefix, appname, entrypoint, workload.Nodename, workload.ID): workloadData,
279279
}
280280

281+
var resp *clientv3.TxnResponse
281282
if create {
282283
if processing != nil {
283284
processingKey := m.getProcessingKey(processing)
284285
err = m.BatchCreateAndDecr(ctx, data, processingKey)
285286
} else {
286-
_, err = m.BatchCreate(ctx, data)
287+
resp, err = m.BatchCreate(ctx, data)
287288
}
288289
} else {
289-
_, err = m.BatchUpdate(ctx, data)
290+
resp, err = m.BatchUpdate(ctx, data)
290291
}
291-
return err
292+
if err != nil {
293+
return err
294+
}
295+
if !resp.Succeeded {
296+
return types.ErrTxnConditionFailed
297+
}
298+
return nil
292299
}

types/errors.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ var (
6666
ErrRunAndWaitCountOneWithStdin = errors.New("Count must be 1 if OpenStdin is true")
6767
ErrUnknownControlType = errors.New("Unknown control type")
6868

69-
ErrNoETCD = errors.New("ETCD must be set")
70-
ErrKeyNotExists = errors.New("Key not exists")
71-
ErrKeyExists = errors.New("Key exists")
72-
ErrNoOps = errors.New("No txn ops")
69+
ErrNoETCD = errors.New("ETCD must be set")
70+
ErrKeyNotExists = errors.New("Key not exists")
71+
ErrKeyExists = errors.New("Key exists")
72+
ErrNoOps = errors.New("No txn ops")
73+
ErrTxnConditionFailed = errors.New("ETCD Txn condition failed")
7374

7475
ErrNotSupport = errors.New("Not Support")
7576
ErrSCMNotSet = errors.New("SCM not set")

0 commit comments

Comments
 (0)