Construct a new Aerospike Transaction instance.
Optional
reads_capacity: numberOptional
writes_capacity: numberStatic
abortTransaction abort status code.
Transaction has already been aborted.
Transaction has been rolled back, but client transaction close was abandoned. Server will eventually close the transaction.
Abort succeeded.
Client roll back abandoned. Server will eventually abort the transaction.
Static
capacityDefault Transaction capacity values.
Contains the default reeadDefault for aerospike.Transaction
Contains the default writeCapacity for aerospike.Transaction
Static
commitTransaction commit status code.
Transaction has already been committed.
Transaction has been rolled forward, but client transaction close was abandoned. Server will eventually close the transaction.
Transaction mark roll forward abandoned. Transaction will be aborted when error is not in doubt. If the error is in doubt (usually timeout), the commit is in doubt.
Commit succeeded.
Client roll forward abandoned. Server will eventually commit the transaction.
Transaction verify failed. Transaction will be aborted.
Static
stateTransaction state enumeration
Transaction was aborted.
Transaction was commited.
Transaction is still open.
Transaction was verified.
Destroys all open transactions
Use of this API is only necessary when the client is closed with the destroyTransactions parameter set is set to false. See example below for usage details.
To avoid using this API, close the final connected client in the process with destroyTransactions set to true (default is true), and the transaction will be destroyed automatically.
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
let tran1 = new Aerospike.Transaction()
let client = await Aerospike.connect(config)
client.close(false, true) // `destroyTransactions is true`, tran1 is no longer usable.
let tran2 = new Aerospike.Transaction()
client = await Aerospike.connect(config)
client.close(false, true) // `destroyTransactions is false`, tran2 can still be used.
// In order to properly manage the memory at this point, do one of two things before the process exits:
// 1: call destroyAll() to destroy all outstanding transactions from this process.
tran1.destroyAll()
// 2: reopen and close the final connected client with destroyTransactions
// client = await Aerospike.connect(config)
// client.close() // Default will destory the transactions
})();
Get ID for this transaction
Transaction ID
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
let id = tran.getId()
})();
Get inDoubt status for this transaction.
Transaction inDoubt status
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
let inDoubt = tran.getInDoubt()
})();
Gets the expected number of record reads in the Transaction. Minimum value is 16.
number of records reads in the Transaction.
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
let readsCapacity = tran.getReadsCapacity()
console.log(readsCapacity) // 128
})();
Gets the current state of the Transaction.
Transaction timeout in seconds
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
let state = tran.getState()
})();
Gets the current Transaction timeout value.
Transaction timeout in seconds
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
let timeout = tran.getTimeout()
})();
Gets the expected number of record reads in the tran. Minimum value is 16.
number of records reads in the tran.
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
let writesCapacity = tran.getWritesCapacity()
console.log(writesCapacity) // 128
})();
Set transaction timeout in seconds. The timer starts when the transaction monitor record is created. This occurs when the first command in the transaction is executed.
If the timeout is reached before a commit or abort is called, the server will expire and rollback the transaction.
If the transaction timeout is zero, the server configuration mrt-duration is used. The default mrt-duration is 10 seconds.
Default Client transaction timeout is 0.
Transaction timeout in seconds
const Aerospike = require('aerospike')
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0}),
}
}
;(async () => {
// Establishes a connection to the server
let tran = new Aerospike.Transaction()
tran.setTimeout(5) // Set timeout for 5 seconds!
console.log(tran.getTimeout()) // 5
})();
Transaction class. Each command in a transaction must use the same namespace.
note: By default, open transactions are destroyed when the final client in a process is closed. If you need your transaction to persist after the last client has been closed, provide
false
for the destroy Transactions argument in Client#close. For more information on memory management, see Transaction.destroyAll.Example: Commit a simple transaction.
Example: Abort a transaction.
Since
v6.0.0