mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 08:10:50 +00:00
force transactional etcd reads
This commit is contained in:
parent
590dc3b226
commit
4be4097edd
1 changed files with 9 additions and 5 deletions
|
|
@ -648,16 +648,20 @@ func (e *Etcd) putKey(ctx context.Context, key, val string, opts ...clientv3.OpO
|
|||
|
||||
func (e *Etcd) getKeyBytes(ctx context.Context, key string) ([]byte, error) {
|
||||
// Get the current value for the key.
|
||||
kv := e.e.Server.KV()
|
||||
resp, err := kv.Range([]byte(key), nil, mvcc.RangeOptions{})
|
||||
op := clientv3.OpGet(key)
|
||||
resp, err := e.cli.Txn(ctx).Then(op).Commit()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kvs := resp.KVs
|
||||
|
||||
// TODO: consider returning a "key does not exist" error instead of (nil, nil)
|
||||
kvs := resp.Responses[0].GetResponseRange().Kvs
|
||||
|
||||
if !resp.Succeeded {
|
||||
return nil, errors.New("tx failed")
|
||||
}
|
||||
|
||||
if len(kvs) == 0 {
|
||||
return nil, nil
|
||||
return nil, errors.New("key does not exist")
|
||||
}
|
||||
|
||||
return kvs[0].Value, nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue