Apache Ignite.NET
Apache.Ignite.Core.Transactions.ITransaction Interface Reference

Grid cache transaction. More...

Inheritance diagram for Apache.Ignite.Core.Transactions.ITransaction:

Public Member Functions

bool SetRollbackonly ()
 Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction. More...
 
void Commit ()
 Commits this transaction. More...
 
Task CommitAsync ()
 Commits this transaction. More...
 
void Rollback ()
 Rolls back this transaction. More...
 
Task RollbackAsync ()
 Rolls back this transaction. More...
 
void AddMeta< TV > (string name, TV val)
 Adds a new metadata. More...
 
TV Meta< TV > (string name)
 Gets metadata by name. More...
 
TV RemoveMeta< TV > (string name)
 Removes metadata by name. More...
 

Properties

Guid NodeId [get]
 ID of the node on which this transaction started. More...
 
long ThreadId [get]
 ID of the thread in which this transaction started. More...
 
DateTime StartTime [get]
 Start time of this transaction on this node. More...
 
TransactionIsolation Isolation [get]
 Transaction isolation level. More...
 
TransactionConcurrency Concurrency [get]
 Transaction concurrency mode. More...
 
TransactionState State [get]
 Current transaction state. More...
 
TimeSpan Timeout [get]
 Timeout for this transaction. If transaction times out prior to it's completion, an exception will be thrown. TimeSpan.Zero for infinite timeout. More...
 
bool IsRollbackOnly [get]
 Gets a value indicating whether this transaction was marked as rollback-only. More...
 

Detailed Description

Cache transactions support the following isolation levels:

  • TransactionIsolation.ReadCommitted isolation level means that always a committed value will be provided for read operations. With this isolation level values are always read from cache global memory or persistent store every time a value is accessed. In other words, if the same key is accessed more than once within the same transaction, it may have different value every time since global cache memory may be updated concurrently by other threads.
  • TransactionIsolation.RepeatableRead isolation level means that if a value was read once within transaction, then all consecutive reads will provide the same in-transaction value. With this isolation level accessed values are stored within in-transaction memory, so consecutive access to the same key within the same transaction will always return the value that was previously read or updated within this transaction. If concurrency is TransactionConcurrency.Pessimistic, then a lock on the key will be acquired prior to accessing the value.
  • TransactionIsolation.Serializable isolation level means that all transactions occur in a completely isolated fashion, as if all transactions in the system had executed serially, one after the other. Read access with this level happens the same way as with TransactionIsolation.RepeatableRead level. However, in TransactionConcurrency.Optimistic mode, if some transactions cannot be serially isolated from each other, then one winner will be picked and the other transactions in conflict will result in TransactionOptimisticException being thrown on Java side.

Cache transactions support the following concurrency models:

  • TransactionConcurrency.Optimistic - in this mode all cache operations are not distributed to other nodes until ITransaction.Commit(). In this mode one PREPARE message will be sent to participating cache nodes to start acquiring per-transaction locks, and once all nodes reply OK (i.e. Phase 1 completes successfully), a one-way COMMIT message is sent without waiting for reply. If it is necessary to know whenever remote nodes have committed as well, synchronous commit or synchronous rollback should be enabled via CacheConfiguration.setWriteSynchronizationMode.

    Note that in this mode, optimistic failures are only possible in conjunction with TransactionIsolation.Serializable isolation level. In all other cases, optimistic transactions will never fail optimistically and will always be identically ordered on all participating Ignite nodes.

  • TransactionConcurrency.Pessimistic - in this mode a lock is acquired on all cache operations with exception of read operations in TransactionIsolation.ReadCommitted mode. All optional filters passed into cache operations will be evaluated after successful lock acquisition. Whenever ITransaction.Commit() is called, a single one-way COMMIT message is sent to participating cache nodes without waiting for reply. Note that there is no reason for distributed PREPARE step, as all locks have been already acquired. Just like with optimistic mode, it is possible to configure synchronous commit or rollback and wait till transaction commits on all participating remote nodes.

In addition to standard CacheAtomicityMode.TRANSACTIONAL behavior, Ignite also supports a lighter CacheAtomicityMode.ATOMIC mode as well. In this mode distributed transactions and distributed locking are not supported. Disabling transactions and locking allows to achieve much higher performance and throughput ratios. It is recommended that CacheAtomicityMode.TRANSACTIONAL mode is used whenever full ACID-compliant transactions are not needed.

You can use cache transactions as follows:

ICacheTx tx = cache.TxStart();
try
{
int v1 = cache<string, int>.Get("k1");
// Check if v1 satisfies some condition before doing a put.
if (v1 > 0)
cache.Put<string, int>("k1", 2);
cache.Removex("k2);
// Commit the transaction.
tx.Commit();
}
finally
{
tx.Dispose();
}

Member Function Documentation

void Apache.Ignite.Core.Transactions.ITransaction.AddMeta< TV > ( string  name,
TV  val 
)
Parameters
nameMetadata name.
valMetadata value.
void Apache.Ignite.Core.Transactions.ITransaction.Commit ( )
Task Apache.Ignite.Core.Transactions.ITransaction.CommitAsync ( )
TV Apache.Ignite.Core.Transactions.ITransaction.Meta< TV > ( string  name)
Parameters
nameMetadata name.
Returns
Metadata value.
Exceptions
KeyNotFoundExceptionIf metadata key was not found.
TV Apache.Ignite.Core.Transactions.ITransaction.RemoveMeta< TV > ( string  name)
Parameters
nameMetadata name.
Returns
Value of removed metadata or default value for V type.
void Apache.Ignite.Core.Transactions.ITransaction.Rollback ( )
Task Apache.Ignite.Core.Transactions.ITransaction.RollbackAsync ( )
bool Apache.Ignite.Core.Transactions.ITransaction.SetRollbackonly ( )
Returns
True if rollback-only flag was set as a result of this operation, false if it was already set prior to this call or could not be set because transaction is already finishing up committing or rolling back.

Property Documentation

TransactionConcurrency Apache.Ignite.Core.Transactions.ITransaction.Concurrency
get
TransactionIsolation Apache.Ignite.Core.Transactions.ITransaction.Isolation
get
bool Apache.Ignite.Core.Transactions.ITransaction.IsRollbackOnly
get
Guid Apache.Ignite.Core.Transactions.ITransaction.NodeId
get

Originating node ID.

DateTime Apache.Ignite.Core.Transactions.ITransaction.StartTime
get
TransactionState Apache.Ignite.Core.Transactions.ITransaction.State
get
long Apache.Ignite.Core.Transactions.ITransaction.ThreadId
get
TimeSpan Apache.Ignite.Core.Transactions.ITransaction.Timeout
get