ArangoDB v4.x is under development and not released yet.
This documentation is not final and potentially incomplete.
Stream Transaction HTTP API
Stream Transactions allow you to perform a multi-document transaction with individual begin and commit/abort commands
For an introduction to this transaction type, see Stream Transactions.
To use a Stream Transaction, a client first sends the configuration of the transaction to the ArangoDB server.
The Stream Transaction API works in conjunction with other APIs in ArangoDB.
To use the transaction for a supported operation a client needs to specify
the transaction identifier in the x-arango-trx-id HTTP header on each request.
This automatically causes these operations to use the specified transaction.
Supported transactional API operations include:
- All operations in the Document API
- Get the number of documents via the Collection API
- Truncate a collection via the Collection API
- Create an AQL cursor via the Cursor API
- Handle nodes and edges of managed graphs (General Graph / Gharial API)
Begin a Stream Transaction
Begin a Stream Transaction that allows clients to call selected APIs over a short period of time, referencing the transaction ID, and have the server execute the operations transactionally.
Committing or aborting a running transaction must be done by the client. It is bad practice to not commit or abort a transaction once you are done using it. It forces the server to keep resources and collection locks until the entire transaction times out.
The transaction description must be passed in the body of the POST request.
x-arango-allow-dirty-read boolean
Set this header to
trueto allow the Coordinator to ask any shard replica for the data, not only the shard leader. This may result in “dirty reads”.This header decides about dirty reads for the entire transaction. Individual read operations, that are performed as part of the transaction, cannot override it.
collections object, required
Must be a JSON object that can have the sub-attributes
read,write, andexclusive, each being an array of collection names or a single collection name as string. Collections that will be written to in the transaction must be declared with thewriteorexclusiveattribute or the respective write operations will fail (but not automatically abort the Stream Transaction), whereas non-declared collections from which is solely read will be added lazily.maxTransactionSize integer
Transaction size limit in bytes.
Default: Controlled by the
--transaction.streaming-max-transaction-sizestartup option.skipFastLockRound boolean (default:
false)Whether to disable fast locking for write operations.
Skipping the fast lock round can be faster overall if there are many concurrent Stream Transactions queued that all try to lock the same collection exclusively. It avoids deadlocking and retrying which can occur with the fast locking by guaranteeing a deterministic locking order at the expense of each actual locking operation taking longer.
Fast locking should not be skipped for read-only Stream Transactions because it degrades performance if there are no concurrent transactions that use exclusive locks on the same collection.
Examples
Executing a transaction on a single collection
curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/transaction/begin
{
"collections": {
"write": "products"
}
}Show output
HTTP/1.1 201 Created
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 69
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"code" : 201,
"error" : false,
"result" : {
"id" : "70863",
"status" : "running"
}
}Referring to a non-existing collection
curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/transaction/begin
{
"collections": {
"read": "products"
}
}Show output
HTTP/1.1 404 Not Found
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 97
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"code" : 404,
"error" : true,
"errorMessage" : "collection or view not found: products",
"errorNum" : 1203
}Get the status of a Stream Transaction
Retrieve the status of a Stream Transaction by its identifier.
After a transaction is committed or aborted, the server remembers its
final state for a limited time. During this window, querying the
transaction returns its final status (committed or aborted). Once
the server garbage-collects this record, the same identifier becomes
unknown and the endpoint returns 404.
Examples
Get transaction status
curl --header 'accept: application/json' --dump - http://localhost:8529/_api/transaction/71072Show output
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 69
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"code" : 200,
"error" : false,
"result" : {
"id" : "71072",
"status" : "running"
}
}Commit a Stream Transaction
Commit a running server-side transaction. Committing is an idempotent operation. It is not an error to commit a transaction more than once.
The server remembers a transaction’s final state for a limited time after it ends. As a result, the response can vary depending on when you call this endpoint:
- While the transaction is still tracked: committing an already-committed
transaction returns
200(idempotent), and committing an already-aborted transaction returns400. - Once the server has garbage-collected the transaction’s record, the
identifier is no longer known and the endpoint returns
404.
Examples
Committing a transaction:
curl -X PUT --header 'accept: application/json' --dump - http://localhost:8529/_api/transaction/71212Show output
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 71
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"code" : 200,
"error" : false,
"result" : {
"id" : "71212",
"status" : "committed"
}
}Abort a Stream Transaction
Abort a running server-side transaction. Aborting is an idempotent operation. It is not an error to abort a transaction more than once.
The server remembers a transaction’s final state for a limited time after it ends. As a result, the response can vary depending on when you call this endpoint:
- While the transaction is still tracked: aborting an already-aborted
transaction returns
200(idempotent), and aborting an already-committed transaction returns400. - The first abort against an unknown identifier returns
404and records it as aborted. Subsequent aborts for the same identifier return200until the record is garbage-collected, after which the identifier is again unknown and the next abort once more returns404.
Examples
Aborting a transaction:
curl -X DELETE --header 'accept: application/json' --dump - http://localhost:8529/_api/transaction/71353Show output
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 69
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"code" : 200,
"error" : false,
"result" : {
"id" : "71353",
"status" : "aborted"
}
}List the running Stream Transactions
Examples
Get currently running transactions
curl --header 'accept: application/json' --dump - http://localhost:8529/_api/transactionShow output
HTTP/1.1 200 OK
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 51
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"transactions" : [
{
"id" : "71465",
"state" : "running"
}
]
}