Commit Hooks
Commit hooks are executed when an object is updated in Antidote. Pre-Commit hooks are execute before the object is updated and post-commit hooks after the update is executed successfully.
Commit hooks are erlang functions which can be called with in Antidote. A commit hook function must take one argument of typeupdate_object()
and returns update_object()
.
Commit hooks can be registered per bucket.
Pre-Commit hooks
Pre-commit hooks are executed before an object is being updated. If pre-commit hook fails, the entire transaction is aborted.
Pre-commit hooks takes one argument which is the client issued update operation to the object. It can then return a modified operation. This modified operation will be used to update the object.
Following is a pre-commit hook which modifies single increment to increment by two.
Post-commit hooks
Post commit hooks are executed after the transaction is successfully committed and before the reply is sent to the client. Currently if post commit hook is failed, it is ignored and transaction is still considered to be successfully committed.
Similar to pre-commit hooks, post-commit hooks receives an operation to the object. This operation is either
client issued update operation, if there was no pre-commit hook executed
operation returned by pre-commit hook, if there was a pre-commit hook
Following is a post commit hook which increments a commit-count for every update to a key.
Note that if post commit hook update objects, it may trigger more hooks and result in infinite cycles of hooks execution. Therefore, hook functions should be carefully written.
Registering Commit hooks
A commit hook is registered per bucket. A bucket can have any number of pre and post commit hooks. However, the order of execution of these hooks (if more than one exist) cannot be specified.
Last updated