Hi Team,
Thanks for replying! I hope you might have got some bit of the
background of the requirement from my previous mail. If not, below is the
example of the class that will be consumed by a microservice (A console
app/background service). And using docker there will be multiple instances
of the same service hosted!
In the example below, I have only single operations per function, so do I
really need transactions? Thinking about multiple instance/process
implementation I currently have them, But I am not really sure whether I
really need them, Or having just atomic mode will be fine?
Dose atomic mode guaranty prevention of dirty read and sequential execution?
Scenario 1
If thead1 trying to update tradeid 1 with version 1 started before thread 2
Thread 2 trying to update tradeid 1 with version 2 started after thread 1
(both trying to update the same key)
if there is a race condition wherein trade 1 take time to complete its work,
will thread 2 wait for it? and commit in a sequential manner even in atomic
mode?
public class TradeCache
{
private IIgnite igniteClient { get; set; }
private ICache<TradeId, TradeDetails> cache { get; set; }
public TradeCache(IgniteConfiguration configuration)
{
igniteClient = Ignition.Start(configuration);
cache= igniteClient.GetCache<TradeId,
TradeDetails>("TradeDetailsCache");
}
public async Task<bool> PutAsync(TradeId tradeId,TradeDetails
tradeDetails)
{
using (ITransaction transaction =
igniteClient.GetTransactions().TxStart(
TransactionConcurrency.Pessimistic,
TransactionIsolation.RepeatableRead,
TimeSpan.FromMilliseconds(300), 0))
{
bool result = await cache.PutIfAbsentAsync(tradeId,
tradeDetails);
transaction.Commit();
return result;
}
}
public async Task<bool> ReplaceAsync(TradeId tradeId, TradeDetails
tradeDetails)
{
using (ITransaction transaction =
igniteClient.GetTransactions().TxStart(
TransactionConcurrency.Pessimistic,
TransactionIsolation.RepeatableRead,
TimeSpan.FromMilliseconds(300), 0))
{
bool result = await cache.ReplaceAsync(tradeId,
tradeDetails);
transaction.Commit();
return result;
}
}
public async Task<bool> RemoveAsync(TradeId tradeId)
{
using (ITransaction transaction =
igniteClient.GetTransactions().TxStart(
TransactionConcurrency.Pessimistic,
TransactionIsolation.RepeatableRead,
TimeSpan.FromMilliseconds(300), 0))
{
bool result = await cache.RemoveAsync(tradeId);
transaction.Commit();
return result;
}
}
}
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/