Protocol Buffer API
Here we describe the Erlang client for Antidote’s protocol buffer interface.
Last updated
Here we describe the Erlang client for Antidote’s protocol buffer interface.
Last updated
A unit of operation in Antidote is a transaction. A client should first start a transaction, then read and/or update multiple objects, and finally commit the transaction.
All transaction functions take as first parameter the process identifier (pid) of the local Antidote proxy. Calling antidotec_pb_socket:start(?ADDRESS, ?PORT)
starts this proxy and returns its pid.
start_transaction(Pid::term(), Timestamp::term(), TxnProperties::term()) -> {ok, TxnId::term()} | {error, Reason::term()}
This function starts a new transaction and returns a transaction identifier. This transaction identifier can be used to mark all further operations of this transaction. The Timestamp
provides the causality information, that is, the dependency information regarding other transactions. Via TxnProperties
you can pass a list of configuration parameters. Currently, only one property is supported: static = true
starts a static transaction, while static = false
initiates an interactive transaction (default).
Example
Reading objects
read_objects(Pid::term(), Objects::[term()], TxId::term()) -> {ok, [term()]} | {error, term()}
reads a set of keys.
Update objects
Example
commit_transaction(Pid::term(), TxId::term()}) -> {ok, term()} | {error, term()}
To end a transaction, it has to be committed. All updates then performed against the stored data. These modifications are observable by later transactions that are (transitively) dependent on this transaction.
abort_transaction(Pid::term(), TxId::term()) -> ok
Transactions can be stopped and canceled by calling abort_transaction
. All updates for this transaction are then revoked.
Example
The following code snippet increments two counters atomically.
The client side representation of replicated counter antidote_counter
provides the following interface:
new(integer()) -> antidotec_counter()
creates a local proxy (with an initial value).
increment(integer(), antidotec_counter()) -> antidotec_counter()
increments the local proxy by the specified value.
decrement(integer(), antidotec_counter()) -> antidotec_counter()
decrements the local proxy by the specified value.
to_ops(term(), antidotec_counter()) -> [term()]
converts the local operations to right format for sending it to Antidote via antidotec_pb:update_object/3
.
value(antidotec_counter()) -> integer()
returns an integer representing the current local value of the counter.
Similar to the counter, we have a client side representation of an replicated OR-set. The antidotec_set
provides following interface:
new/1
creates a local proxy with some initial value.
add/2, remove/2
insert and remove elements from the set.
to_ops/2
converts the local operations to right format for sending it to Antidote via antidotec_pb:update_object/3
.
value/1
returns a set representing the current local value of the replicated set, that is a list of elements which are in the set.
update_objects(Pid::term(), Updates::[{term(), term(), term()}], TxId::term()) -> ok | {error, term()}
takes a set of object with the operations and corresponding parameters as list of triples. More on data types and operations can be found .
Antidote supports several replicated data types (more information at ). However, the protocol buffer interface currently supports only counters and sets.