Apache Ignite.NET

The Apache Ignite .NET Developer Hub

Welcome to the Apache Ignite .NET developer hub. You'll find comprehensive guides and documentation to help you start working with Apache Ignite.NET as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

TransactionScope API

Besides explicit ITransactions API described in Transactions, you can use Ignite transactions via the standard System.Transactions.TransactionScope API.

using (var ts = new TransactionScope())
{
  cache.Put(1, "x");
  cache.Put(2, "y");

  ts.Complete();
}

When a cache is Transactional, the above code will cause ITransactions.TxStart() and ITransaction.Commit() to be called automatically.

If an Ignite transaction is started manually, TransactionScope is ignored and won't cause a Commit or Rollback.

// Assigning a value for the key.
cache[1] = 0;

using (var tx = transactions.TxStart())            
{
  // Ignite transaction is started manually, TransactionScope below will not have any effect.
  using (new TransactionScope())
  {
    cache[1] = 2; // The update is enlisted into the outer Ignite transaction.
  }  // TransactionScope attempts to revert changes, will have no effect on the outer Ignite transaction.

  tx.Commit(); // Committing Ignite transaction.
}

cache.Get(1); // Returns 2.

Transaction Isolation

Ignite has three isolation modes, while System.Transactions.IsolationLevel has more. The table below shows how System.Transactions.IsolationLevel maps to Apache.Ignite.Core.Transactions.TransactionIsolation.

`IsolationLevel`
`TransactionIsolation`

Serializable

Serializable

RepeatableRead

RepeatableRead

ReadCommitted
ReadUncommitted
Snapshot
Chaos

ReadCommitted

Default TransactionOptions.IsolationLevel is Serializable.

using (var ts = new TransactionScope(
  TransactionScopeOption.Required, 
  new TransactionOptions 
  {
    IsolationLevel = IsolationLevel.ReadCommitted
  }))
{
  cache[1] = 2;
  ts.Complete();
}

Transaction Concurrency

Ignite transactions have TransactionConcurrency setting (Pessimistic / Optimistic), while TransactionScope API does not have such thing. Therefore, when an Ignite transaction is started with TransactionScope, it uses the default TransactionConcurrency which is configured with IgniteConfiguration.TransactionConfiguration.DefaultTransactionConcurrency property, which is Pessimistic by default.

var cfg = new IgniteConfiguration
{
  TransactionConfiguration = new TransactionConfiguration
  {
    DefaultTransactionConcurrency = TransactionConcurrency.Optimistic
  }
};

using (var ignite = Ignition.Start(cfg))
{
  using (var ts = new TransactionScope()) // Optimistic, Serializable
  {
    cache[1] = 2;
    ts.Complete();
  }
}

Nested Transaction Scopes

TransactionScope can be nested within another TransactionScope. However, Ignite does not allow more than one transaction in a given thread. Depending on TransactionScopeOption, the behavior is as follows:

TransactionScopeOption.Suppress:
All Ignite operations participate in an existing transaction (suppression is ignored).

TransactionScopeOption.Required:
All Ignite operations participate in an existing transaction (expected behavior).

TransactionScopeOption.RequiresNew:
All Ignite operations participate in an existing transaction (new transaction is not created). Ignite transaction will be completed upon nested TransactionScope block exit. - either commit or rollback will be performed. Outer scope won't have any effect after that.

Async Operations

All transactional async operations must be completed before leaving TransactionScope. The behavior is undefined otherwise. Make sure to call Wait() or await on asynchronous operations.

using (var ts = new TransactionScope())
{
  cache.PutAsync(1, "x").Wait();
  await cache.PutAsync(2, "y");

  ts.Complete();
}

TransactionScope API