Skip to content
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

api: txn comparisons on ranges #8025

Merged
merged 6 commits into from
Jun 18, 2017

Conversation

heyitsanthony
Copy link
Contributor

Server and client support for txn comparisons over ranges.

Fixes #7924

@gyuho gyuho added this to the v3.3.0 milestone Jun 2, 2017
@heyitsanthony heyitsanthony force-pushed the txn-cmp-range branch 5 times, most recently from 28c1e4b to 943d6b7 Compare June 6, 2017 23:43
@codecov-io
Copy link

codecov-io commented Jun 7, 2017

Codecov Report

Merging #8025 into master will decrease coverage by 0.08%.
The diff coverage is 92.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8025      +/-   ##
==========================================
- Coverage   76.49%   76.41%   -0.09%     
==========================================
  Files         342      342              
  Lines       26549    26561      +12     
==========================================
- Hits        20309    20296      -13     
- Misses       4785     4800      +15     
- Partials     1455     1465      +10
Impacted Files Coverage Δ
clientv3/namespace/kv.go 80.58% <100%> (+0.38%) ⬆️
etcdserver/apply.go 89.29% <100%> (+0.47%) ⬆️
etcdserver/apply_auth.go 75.2% <100%> (ø) ⬆️
proxy/grpcproxy/kv.go 95.23% <100%> (ø) ⬆️
clientv3/compare.go 69.64% <50%> (-2.36%) ⬇️
proxy/grpcproxy/register.go 69.44% <0%> (-13.89%) ⬇️
pkg/fileutil/purge.go 73.68% <0%> (-7.9%) ⬇️
etcdserver/api/v3rpc/lease.go 92.85% <0%> (-7.15%) ⬇️
pkg/adt/interval_tree.go 83.84% <0%> (-4.88%) ⬇️
pkg/netutil/netutil.go 62.35% <0%> (-3.53%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 933aa09...2256599. Read the comment docs.

@@ -510,6 +510,9 @@ message Compare {
// value is the value of the given key, in bytes.
bytes value = 7;
}
// range_end compares over the range [key, range_end). See RangeRequest.
bytes range_end = 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

when range_end is given, all the keys within the range will be compared against the same target? Probably we should make the comment more clear?

Also can you give me an example use case of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's the same target; will clarify comment

An example use case from the leasing kv: delete range. To safely delete a range of keys the leasing kv must ensure no other client holds a key lease (represented as a "leasing key" controlled by the leasing protocol) on any key in the range. The leasing kv can acquire/revoke key leases such that so long as there are no new key leases acquired on a range, that range is safe to delete. This check can be done with a ranged comparison over the corresponding leasing keys and testing CreateRev < safeToDeleteRev.

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm

Copy link
Contributor

Choose a reason for hiding this comment

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

but i can see people might want multiple targets eventually. but it is something easy to support i feel.

@@ -99,6 +99,18 @@ func (cmp *Cmp) ValueBytes() []byte {
// WithValueBytes sets the byte slice for the comparison's value.
func (cmp *Cmp) WithValueBytes(v []byte) { cmp.TargetUnion.(*pb.Compare_Value).Value = v }

// WithRange sets the comparison to scan the range [key, end).
func (cmp Cmp) WithRange(end string) Cmp {
Copy link
Contributor

Choose a reason for hiding this comment

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

(cmp *Cmp)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it that way but clientv3.Compare(...).WithRange(...) will complain that the result from Compare() is not a pointer and it doesn't seem worth changing Compare()'s return value to a pointer to support this

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh it returns Cmp anyway. Nvm.

}

// WithPrefix sets the comparison to scan all keys prefixed by the key.
func (cmp Cmp) WithPrefix() Cmp {
Copy link
Contributor

Choose a reason for hiding this comment

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

(cmp *Cmp)?

@xiang90
Copy link
Contributor

xiang90 commented Jun 18, 2017

lgtm

@heyitsanthony
Copy link
Contributor Author

proxy tests failing on fixed grpc data race; merging

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.

None yet

4 participants