PUT aborted by pre-commit hook

Sean Cribbs sean at basho.com
Wed Mar 28 10:01:05 EDT 2012


Replies inline:

> Hello,
> I am just starting out with Riak and want to use Pre-Commit Hooks to
> automatically add links to keys in a different bucket. To give a
> simple example, when I add '/bucket2/object2' I want to add a link to
> the object in '/bucket1/object1' that points to the new object. I
> would like to do this in javascript and would appreciate if someone
> could help me get started. I could not find a single working example,
> and have had difficulties in even getting the basics up and running.
> What I have done so far is:
> - Changed the js_source_dir directory to './js_source'
> - In js_source, I added a file 'validate.js':
> var validateFunctions = {
>  validate: function(v) {
>     return v;
>  }
> };
> module.exports = {'name': validateFunctions }
Riak's JS engine doesn't use CommonJS modules, so whatever you define in
the global namespace will be visible. module.exports will probably cause an
evaluation error.

> - I created a new bucket as such:
> curl -v -X PUT -H "Content-Type: application/json" -d '{"props":
> {"precommit": [{"name": "validate"}]}}'
Because it's in the global namespace, you should refer to it like so:

> - I added a new key to this bucket:
> curl -v -X PUT -d '{"bar":"baz"}' -H "Content-Type: application/json"
>  -H "X-Riak-Vclock: a85hYGBgzGDKBVIszMk55zKYEhnzWBlKIniO8mUBAA=="
> This results in a 403 "PUT aborted by pre-commit hook" failure.
Because of the namespacing issue, the error was probably a function
dispatch problem.

> Aside from the obvious "how do I get it to work?" question, I would like
> to know
> 1) if there is a working example on the web or a tutorial that shows
> all the required steps (the Basho Commit Hooks tutorial does not
> actually show how to enable these hooks)

Unfortunately, no. That's something we should address soon.

> 2) if I need to do anything when I change my Javascript files (restart
> server, re-initialize my buckets, ..)

You can run `riak-admin js_reload` to reload your JS files that are in the

> 3) if there is a naming convention that I need to follow for my *.js files

All *.js files from the js_source_dir (non-recursive) will be read and
evaluated on startup.

> 4) how to process links in Javascript
The format of the object is the same as in MapReduce, so refer to that


Basically, "Links" will be an entry in the metadata sub-object. IIRC each
link is an object with keys "bucket","key","tag".

> So far, I have a a great experience getting to know Riak, but the
> limited documentation really hinders my progress :)
Sorry for that! I understand we'll be improving the experience a lot over
the next quarter.

> Thanks,
> Sebastian
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Sean Cribbs <sean at basho.com>
Software Engineer
Basho Technologies, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20120328/109f11c1/attachment.html>

More information about the riak-users mailing list