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

Create /path/key if-and-only-if /path exists but key does not #2857

Closed
schmichael opened this issue May 21, 2015 · 2 comments
Closed

Create /path/key if-and-only-if /path exists but key does not #2857

schmichael opened this issue May 21, 2015 · 2 comments

Comments

@schmichael
Copy link
Contributor

Current behavior

As of etcd 2.0.11 the following creates /path/key iff /path/key does not exist. However, it will create /path/key regardless of whether or not /path exists.

curl -XPUT localhost:2379/v2/keys/path/key?prevExist=false
{"action":"create","node":{"key":"/path/key","value":"","modifiedIndex":7,"createdIndex":7}}

Desired behavior

Have an option (recursive=false perhaps?) to cause PUTs to fail if the parent path component doesn't exist.

Workaround

Depending on your use case the following may be a sufficient workaround:

  • PUT /path/key?prevExist=false
  • GET /path
    • If /path's CreatedIndex == /path/key's CreatedIndex, then: DELETE /path?recursive=true

Obviously this method isn't an atomic operation, so it's not suitable for all cases the Desired Behavior above covers.

@barakmich
Copy link
Contributor

More importantly, you might like the byte-keyspace (and atomic transactions!) of the v3 API which is underway. We're holding off on extending v2 -- but if there is a clear bug here (ie, the creation of the /path/key) but I think that's documented that way -- if it's unexpected behavior then feel free to reopen!

schmichael added a commit to lytics/metafora that referenced this issue May 22, 2015
This introduces an extra GET (and potentially DELETE) into the task
claim flow which is unfortunate. I don't see another way of guaranteeing
a claim can't recreate a deleted task without the extra check though.

Looks like we're going to have to wait for a new etcd in order to get a
more efficient way of doing this:

etcd-io/etcd#2857

Fixes #124
@schmichael
Copy link
Contributor Author

Oops, I didn't mean to repoen this with an unrelated ticket in a totally different project! Sorry!

However:

I don't see Create/PUT's recursive behavior documented anywhere, and other operations with recursive abilities (e.g. GET/DELETE) have the recursive=... option to toggle the behavior.

So I'd say this is a documentation "bug" and a missing feature. v3's atomic transactions is definitely a solution though, so feel free to re-close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants