ClusterTransaction
public class ClusterTransaction : Transaction
This class represents a transaction against a real database cluster.
-
Undocumented
Declaration
Swift
public let eventLoop: EventLoop
-
The database this transaction is on.
Declaration
Swift
public let database: ClusterDatabaseConnection
-
This method reads a single value from the database.
This will automatically add a read conflict, so if another transaction has changed the value since this transaction started reading, this transaction will not commit.
Declaration
Swift
public func read(_ key: DatabaseValue, snapshot: Bool) -> EventLoopFuture<DatabaseValue?>
Parameters
key
The key to read.
snapshot
Whether we should perform a snapshot read.
Return Value
The value that we read.
-
This method finds a key using a key selector.
Declaration
Swift
public func findKey(selector: KeySelector, snapshot: Bool) -> EventLoopFuture<DatabaseValue?>
Parameters
selector
The selector telling us where to find the key.
snapshot
Whether we should perform a snapshot read when finding the key.
Return Value
The first key matching this selector.
-
This method reads a range of values for a range of keys matching two key selectors.
The keys included in the result range will be from the first key matching the start key selector to the first key matching the end key selector. The start key will be included in the results, but the end key will not.
The results will be ordered in lexographic order by their keys.
This will automatically add a read conflict for the range, so that if any key has changed in this range since the start of this transaction this transaction will not be accepted.
Declaration
Swift
public func readSelectors(from start: KeySelector, to end: KeySelector, limit: Int?, mode: StreamingMode, snapshot: Bool, reverse: Bool) -> EventLoopFuture<ResultSet>
Parameters
from
The key selector for the beginning of the range.
end
The key selector for the end of the range.
limit
The maximum number of results to return.
mode
The streaming mode to use.
snapshot
Whether we should perform a snapshot read.
reverse
Whether we should return the rows in reverse order.
Return Value
A list of keys and their corresponding values.
-
This method stores a value in the database.
Declaration
Swift
public func store(key: DatabaseValue, value: DatabaseValue)
Parameters
key
The key to store.
value
The value to store for the key.
-
This method clears the value for a key in the database.
Declaration
Swift
public func clear(key: DatabaseValue)
Parameters
key
The key to clear.
-
This method clears the value for a range of keys in the database.
This will not clear the last value in the range.
Declaration
Swift
public func clear(range: Range<DatabaseValue>)
Parameters
range
The range of keys to clear.
-
This method adds a read conflict for this transaction.
This will cause the transaction to fail if any of the keys in the range have been changed since this transaction started.
Declaration
Swift
public func addReadConflict(on range: Range<DatabaseValue>)
Parameters
range
The range of keys to add the conflict on.
-
This method adds a range of keys that we want to reserve for writing.
If the system commits this transaction, and another transaction has a read conflict on one of these keys, that second transaction will then fail to commit.
Declaration
Swift
public func addWriteConflict(on range: Range<DatabaseValue>)
Parameters
range
The range of keys to add the conflict on.
-
This method gets the version of the database that this transaction is reading from.
Declaration
Swift
public func getReadVersion() -> EventLoopFuture<Int64>
-
This method gets the version of the database that this transaction should read from.
Declaration
Swift
public func setReadVersion(_ version: Int64)
Parameters
version
The new version.
-
This method gets the version of the database that this transaction committed its changes at.
If the transaction has not committed, this will return -1.
Declaration
Swift
public func getCommittedVersion() -> EventLoopFuture<Int64>
-
This method attempts to retry a transaction after an error.
If the error is retryable, this will reset the transaction and fire the returned future when the transaction is ready to use again. If the error is not retryable, the returned future will rethrow the error.
Declaration
Swift
public func attemptRetry(error: Error) -> EventLoopFuture<()>
Parameters
error
The error that the system encountered.
Return Value
A future indicating when the transaction is ready again.
-
This method resets the transaction to its initial state.
Declaration
Swift
public func reset()
-
This method cancels the transaction, preventing it from being committed and freeing up some associated resources.
Declaration
Swift
public func cancel()
-
This method performs an atomic operation against a key and value.
Declaration
Swift
public func performAtomicOperation(operation: MutationType, key: DatabaseValue, value: DatabaseValue)
Parameters
operation
The operation to perform.
key
The key to read for the operation.
value
The new value to provide to the operation.
-
This method gets a version stamp, which is a key segment containing the committed version of the transaction.
This can be called before the transaction is committed, and it will only return a value once the transaction is committed.
Declaration
Swift
public func getVersionStamp() -> EventLoopFuture<DatabaseValue>
-
This method sets an option on the transaction.
Declaration
Swift
public func setOption(_ option: TransactionOption, value: DatabaseValue?)
Parameters
option
The option to set.
value
The value to set for the option.