Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Riak bucket over cURL

Tags:

http

curl

riak

I would like to be able to create a Riak bucket over cURL. I have been searching online and cant seem to find a way to do it. I know there are ways to do it easily with the drivers but need to be able to do it with cURL for the Saas application I am working on.

like image 868
WojonsTech Avatar asked Dec 08 '22 20:12

WojonsTech


2 Answers

You would do a PUT passing the bucket properties you want as a json object, e.g.

curl -v http://riak3.local:8098/riak/newBucket -X PUT -H Content-Type:application/json --data-binary '{"props":{"n_val":5}}'

The docs has more complete details.

like image 187
superfell Avatar answered Dec 13 '22 22:12

superfell


One other thing - the important thing to remember is that, there is no way to 'create' a bucket explicitly, with a call (via CURL or a client api).

You can only create custom buckets via the call above.

The reason for that is -- buckets are simply just a prefix to the keys. There is no object anywhere in the Riak system that keeps track of buckets. There is no file somewhere, no variable in memory, or anything like that. That is why the simple "list buckets" commands is so expensive: Riak literally has to go through every key in the cluster, and assemble a list of buckets by looking at the key prefixes.

The only thing that exists as actual objects are buckets with non-default settings, ie, custom buckets. That's what that curl command above does -- it keeps track of some non-default settings for Riak to consult if a call ever comes in to that bucket.

Anyways, the moral of the story is: you don't need to create buckets in the normal course of operations. You can just start writing to them, and they will come into being (again, in the sense of, keys with bucket prefixes will come into being, which means they can now be iterated over by the expensive 'list buckets' call).

You only have to issue the call for custom buckets (and also, you don't want to do that too much, either, as there is a practical limit to the number of custom buckets created in a cluster, somewhere around 9000).

like image 22
Dmitri Zagidulin Avatar answered Dec 13 '22 21:12

Dmitri Zagidulin