-
Notifications
You must be signed in to change notification settings - Fork 10k
*: 'ignore_value' to detach lease with PutRequest #6894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f100bdf
to
f6ca32b
Compare
@xiang90 Please review. Thanks. |
/cc @sinsharat I think @sinsharat is working on the similar thing. Can you look through this? |
@gyuho thanks for working on this as i am stuck with travel. Please give me some time to review this as i am still on travel for another 4days and don't have my laptop or internet connection with me to review it properly. |
@@ -616,6 +616,7 @@ Empty field. | |||
| value | value is the value, in bytes, to associate with the key in the key-value store. | bytes | | |||
| lease | lease is the lease ID to associate with the key in the key-value store. A lease value of 0 indicates no lease. | int64 | | |||
| prev_kv | If prev_kv is set, etcd gets the previous key-value pair before changing it. The previous key-value pair will be returned in the put response. | bool | | |||
| preserve_value | If preserve_value is set, etcd overwrites the key with previous value. Use this to detach a lease by overwriting the key. | bool | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If preserve_value is set, etcd preserves the key by detaching or replacing lease if any associated with it. Use this to detach the lease or replace lease for the key.
?
missing grpcproxy support? |
@@ -43,6 +43,8 @@ PUT assigns the specified value with the specified key. If key already holds a v | |||
|
|||
- lease -- lease ID (in hexadecimal) to attach to the key. | |||
|
|||
- preserve-value -- allow empty value to overwrite key with previous value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detatch or replace lease for key-value pair
?
@@ -51,6 +53,7 @@ will store the content of the file to <key>. | |||
} | |||
cmd.Flags().StringVar(&leaseStr, "lease", "0", "lease ID (in hexadecimal) to attach to the key") | |||
cmd.Flags().BoolVar(&putPrevKV, "prev-kv", false, "return the previous key-value pair before modification") | |||
cmd.Flags().BoolVar(&putPreserveVal, "preserve-value", false, "allow empty value to overwrite key with previous value") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detach lease if any for the key to preserve it.
?
i am not convinced about putting a new key with an empty value when preserve-value is passed and the key doesn't exist. I feel it should return an error instead, since the main purpose of this flag is to detach lease for an existing key without passing value to it. |
@sinsharat Actually this PR returns error here a8104dd? But we need better documentation on that case. @heyitsanthony I will work on grpc-proxy part as well. Thanks! |
@gyuho if that's the case we probably need to work on correcting comments as well. Will give a deeper look to this. |
5ae6001
to
2149698
Compare
@gyuho Do we support lease flag or prev kv along with preserver value? Have you tested it? |
|
||
// If preserve_value is set, etcd preserves the key by detaching or replacing | ||
// lease if any. Use this to detach a lease or replace lease of the key. | ||
bool preserve_value = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ignore_value
(no_value
?) so it's talking about value
from the rpc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ignore-value sounds clear. Will change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs some testing around case where the key doesn't exist for put and txn puts
@@ -423,6 +423,10 @@ message PutRequest { | |||
// If prev_kv is set, etcd gets the previous key-value pair before changing it. | |||
// The previous key-value pair will be returned in the put response. | |||
bool prev_kv = 4; | |||
|
|||
// If preserve_value is set, etcd preserves the key by detaching or replacing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
etcd updates the key using its current value. Returns an error if the key does not exist.
I think the docs can ignore the lease use case. There's been a few requests for a similar feature with leases-- modify the key but keep the lease the same. If we add preserve_lease
in the future, then the preserve_value = true
won't necessarily imply a lease attach/detach.
@@ -113,6 +113,64 @@ func TestKVPut(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestKVPutDetachLease(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does too much server testing for a client test. Checking that a Put WithPreserveValue doesn't clobber the old value should be OK.
clus := NewClusterV3(t, &ClusterConfig{Size: 1}) | ||
defer clus.Terminate(t) | ||
|
||
// create lease |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need all the lease testing? it's not really a special case in the implementation. Can probably get away with only checking that the value isn't clobbered.
@@ -62,6 +63,35 @@ func putTest(cx ctlCtx) { | |||
} | |||
} | |||
|
|||
func putTestPreserveValue(cx ctlCtx) { | |||
id, err := ctlV3LeaseGrant(cx, 30) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the lease stuff necessary?
@@ -175,6 +175,10 @@ func (a *applierV3backend) Put(txnID int64, p *pb.PutRequest) (*pb.PutResponse, | |||
} | |||
} | |||
|
|||
if p.PreserveValue && rr != nil && len(rr.KVs) != 0 { | |||
p.Value = rr.KVs[0].Value | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p.PreserveValue && (rr == nil || len(rr.Kvs) == 0)
should be an error since it shouldn't create a new key. Txns will need a special case to check that all keys exist before doing the puts.
ErrGRPCFutureRev = grpc.Errorf(codes.OutOfRange, "etcdserver: mvcc: required revision is a future revision") | ||
ErrGRPCNoSpace = grpc.Errorf(codes.ResourceExhausted, "etcdserver: mvcc: database space exceeded") | ||
ErrGRPCEmptyKey = grpc.Errorf(codes.InvalidArgument, "etcdserver: key is not provided") | ||
ErrGRPCNotEmptyValue = grpc.Errorf(codes.InvalidArgument, "etcdserver: value is provided") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ErrGRPCValue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah will rework on these. Thanks!
@heyitsanthony All addressed. PTAL. Thanks! Please note that /cc @sinsharat |
@gyuho yeah, shouldn't need to import |
7e82472
to
4d282de
Compare
469dbd7
to
7ddc71f
Compare
This has been reviewed. Just rebased on master branch. Merging in greens. Thanks. |
@gyuho I put a release note on this. |
Ok ack (for v3.2) |
Fix #6848.