Skip to content

*: '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

Merged
merged 9 commits into from
Jan 14, 2017

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented Nov 23, 2016

Fix #6848.

@gyuho gyuho force-pushed the preserve-value branch 2 times, most recently from f100bdf to f6ca32b Compare November 23, 2016 07:08
@gyuho
Copy link
Contributor Author

gyuho commented Nov 23, 2016

@xiang90 Please review. Thanks.

@xiang90
Copy link
Contributor

xiang90 commented Nov 23, 2016

/cc @sinsharat

I think @sinsharat is working on the similar thing. Can you look through this?

@sinsharat
Copy link
Contributor

@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.
Thanks!

@@ -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 |
Copy link
Contributor

@sinsharat sinsharat Nov 30, 2016

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.?

@heyitsanthony
Copy link
Contributor

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.
Copy link
Contributor

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")
Copy link
Contributor

@sinsharat sinsharat Nov 30, 2016

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.?

@sinsharat
Copy link
Contributor

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.

@gyuho
Copy link
Contributor Author

gyuho commented Nov 30, 2016

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

@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 gyuho added the WIP label Nov 30, 2016
@sinsharat
Copy link
Contributor

@gyuho if that's the case we probably need to work on correcting comments as well. Will give a deeper look to this.
Thanks!

@gyuho gyuho removed the WIP label Dec 1, 2016
@gyuho gyuho force-pushed the preserve-value branch 2 times, most recently from 5ae6001 to 2149698 Compare December 1, 2016 06:42
@sinsharat
Copy link
Contributor

sinsharat commented Dec 1, 2016

@gyuho Do we support lease flag or prev kv along with preserver value? Have you tested it?

@gyuho gyuho added the WIP label Dec 1, 2016
@gyuho gyuho removed the WIP label Dec 1, 2016

// 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;
Copy link
Contributor

@heyitsanthony heyitsanthony Dec 1, 2016

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?

Copy link
Contributor Author

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.

@gyuho gyuho added the WIP label Dec 1, 2016
@gyuho gyuho changed the title *: 'preserve_value' to detach lease with PutRequest *: 'no_value' to detach lease with PutRequest Dec 1, 2016
Copy link
Contributor

@heyitsanthony heyitsanthony left a 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
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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
}
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe ErrGRPCValue?

Copy link
Contributor Author

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!

@gyuho gyuho removed the WIP label Dec 2, 2016
@gyuho
Copy link
Contributor Author

gyuho commented Dec 2, 2016

@heyitsanthony All addressed. PTAL. Thanks!

Please note that applyUnion method signature changed.

/cc @sinsharat

@heyitsanthony
Copy link
Contributor

@gyuho yeah, shouldn't need to import etcdserver; the tests are already using rpctypes

@gyuho gyuho added this to the v3.2.0 milestone Dec 5, 2016
@gyuho gyuho added the WIP label Dec 6, 2016
@gyuho gyuho force-pushed the preserve-value branch 2 times, most recently from 7e82472 to 4d282de Compare December 9, 2016 03:33
@gyuho gyuho force-pushed the preserve-value branch 3 times, most recently from 469dbd7 to 7ddc71f Compare December 16, 2016 21:53
@gyuho gyuho removed the WIP label Jan 13, 2017
@gyuho
Copy link
Contributor Author

gyuho commented Jan 13, 2017

This has been reviewed. Just rebased on master branch. Merging in greens. Thanks.

@xiang90
Copy link
Contributor

xiang90 commented Jan 13, 2017

@gyuho I put a release note on this.

@gyuho
Copy link
Contributor Author

gyuho commented Jan 13, 2017

Ok ack (for v3.2)

@gyuho gyuho merged commit 118fd18 into etcd-io:master Jan 14, 2017
@gyuho gyuho deleted the preserve-value branch January 14, 2017 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants