Skip to content

Commit

Permalink
remove get then put method
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Dec 4, 2019
1 parent ea6bab7 commit af8c8e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
5 changes: 3 additions & 2 deletions store/etcdv3/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ func (m *Mercury) SetContainerStatus(ctx context.Context, container *types.Conta
}
opts = append(opts, clientv3.WithLease(lease.ID))
}
containerKey := fmt.Sprintf(containerInfoKey, container.ID)
_, err = m.GetThenPut(ctx, []string{containerKey}, statusKey, string(data), opts...)
ops := []clientv3.Op{clientv3.OpPut(statusKey, string(data), opts...)}
conds := []clientv3.Cmp{clientv3.Compare(clientv3.Version(fmt.Sprintf(containerInfoKey, container.ID)), "!=", 0)}
_, err = m.doBatchOp(ctx, conds, ops, []clientv3.Op{})
return err
}

Expand Down
11 changes: 0 additions & 11 deletions store/etcdv3/mercury.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,6 @@ func (m *Mercury) Update(ctx context.Context, key, val string, opts ...clientv3.
return m.batchUpdate(ctx, map[string]string{key: val}, opts...)
}

// GetThenPut if key exists, then put
func (m *Mercury) GetThenPut(ctx context.Context, getKeys []string, key, val string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
ops := []clientv3.Op{clientv3.OpPut(key, val, opts...)}
conds := []clientv3.Cmp{}
for _, getKey := range getKeys {
cond := clientv3.Compare(clientv3.Version(getKey), "!=", 0)
conds = append(conds, cond)
}
return m.doBatchOp(ctx, conds, ops, []clientv3.Op{})
}

// Watch wath a key
func (m *Mercury) watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan {
return m.cliv3.Watch(ctx, key, opts...)
Expand Down

0 comments on commit af8c8e4

Please sign in to comment.