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: ranges in txn comparisons #7924

Closed
heyitsanthony opened this issue May 12, 2017 · 0 comments
Closed

api: ranges in txn comparisons #7924

heyitsanthony opened this issue May 12, 2017 · 0 comments
Assignees
Milestone

Comments

@heyitsanthony
Copy link
Contributor

Currently the Txn API only supports comparisons on single keys. However, comparisons on ranges that check whether all keys match the comparison target are useful for implementing higher-level functionality over etcd.

Disconnected linearized reads would use range comparisons to check for leased keys on a range before deleting a range:

cli.Txn(ctx)
.If(Compare(CreateRevision(leasingPfx + "a", WithCmpRange(leasingPfx + "b")), "=", 0)
.Then(OpDelete("a", WithRange("b"))
.Commit()

STM could be extended to support key intervals with range comparisons to check for read conflicts:

cli.Txn(ctx)
.If(Compare(ModRevision("a", WithCmpRange("b")), "<", maxRangeModRev+1)
.Then(/* put write buffer */)
.Else("failure")
.Commit()

The protocol change would add a range_end field to the Compare protobuf message:

message Compare {
  ...
  oneof target_union {
    // version is the version of the given key
    int64 version = 4;
    // create_revision is the creation revision of the given key
    int64 create_revision = 5;
    // mod_revision is the last modified revision of the given key.
    int64 mod_revision = 6;
    // value is the value of the given key, in bytes.
    bytes value = 7;
  }
  bytes range_end = 8;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant