I'm using etcd v3.3 in my application and communicate with it over its WEB API. According to documentation I don't need to explicitly create directories when putting key-value pairs on some path. Here is an example what I doing (note that the path /base-test-path/level1/level2/level3/ does not exist yet):
curl -X PUT -d value=foo http://localhost:2379/v2/keys/base-test-path/level1/level2/level3/
The result was:
{"action":"set","node":{"key":"/base-test-path/test/test/test","value":"foo","modifiedIndex":347017,"createdIndex":347017}}
But when I try to add a new value a bit deeper into existing path, I get an error (note that the path /base-test-path/level1/level2/level3/ already exists because I run previous command before):
curl -X PUT -d value=foo http://localhost:2379/v2/keys/base-test-path/level1/level2/level3/level4
Response:
{"errorCode":104,"message":"Not a directory","cause":"/base-test-path/level1/level2/level3","index":347018}
It seems like etcd does not create directories when any part of the path already exists.
The question is: can I keep my code simple so I don't need to care about etcd directories and still be able to put values on every etcd's path I want?
It seems like etcd, when speak it with API v2, can not create directories when some key is already on the place. E.g. when you have a key
/base-test-path/level1/somekey
You can not create such key ("Not a directory"):
/base-test-path/level1/somekey/subkey
When I switched to API v3 this problem is eliminated as it does not have directories at all. See a comment here or official documentation here.