Closed alexlll80 closed 4 years ago
The insert operation blocked thread, when 2 transactions in the different threads are trying to insert value under the same key simultaneously.
Is it production db?
[Fact]
public void ParallelAccessTest()
{
const string column = "Col1";
const string value1 = "val1";
const string value2 = "val2";
var engine = new DBreezeEngine(dbfolder);
Barrier firstBarier = new Barrier(participantCount: 2);
Barrier secondBarier = new Barrier(participantCount: 2);
Barrier thirdBarier = new Barrier(participantCount: 3);
new Thread(() => {
try
{
var transaction1 = engine.GetTransaction();
transaction1.Insert(table1, column, value1);
firstBarier.SignalAndWait();
var val = transaction1.Select<String, String>(table1, column, true);
val = transaction1.Select<String, String>(table1, column, false);
secondBarier.SignalAndWait();
transaction1.Commit();
val = transaction1.Select<String, String>(table1, column, true);
}catch(Exception ex)
{
}
thirdBarier.SignalAndWait();
})
.Start();
new Thread(() => {
try
{
var transaction2 = engine.GetTransaction();
transaction2.Insert(table1, column, value2);
firstBarier.SignalAndWait();
var val = transaction2.Select<String, String>(table1, column, true);
val = transaction2.Select<String, String>(table1, column, false);
val = transaction2.Select<String, String>(table1, column, true);
secondBarier.SignalAndWait();
transaction2.Rollback();
val = transaction2.Select<String, String>(table1, column, true);
}catch(Exception ex)
{
}
thirdBarier.SignalAndWait();
}).Start();
thirdBarier.SignalAndWait();
engine.Dispose();
}
It is a production DB. Problem is a Barrier internal implementation. Please read docu Parallel reads in the same thread
In 2 words, you can run transactions in many parallel "new Thread()" without Barrier code inside.
For one ManagedThread you must use one transaction to settle all operations. One function opens transaction and transfers it between all functions which need to work with the db data. It also can mean that for that transaction only once will be called tran.SynchronizeTables(list of tables).
The insert operation blocked thread, when 2 transactions in the different threads are trying to insert value under the same key simultaneously.
Where does this message come from?
It is a production DB. Problem is a Barrier internal implementation. Please read docu Parallel reads in the same thread
In 2 words, you can run transactions in many parallel "new Thread()" without Barrier code inside.
Could you provide more details? Does it mean that transaction has not write-lock-timeout? It's intresting for me. I can provide threaddumps if it helps. This issue has 2 questions. The first one was about two transactions in the same thread. Thanks advance
Rules are following:
There is no timeouts.
Transaction isolation does not work when 2 transactions in the the same thread. trans1.insert(table,key,value1); trans2.insert(table,key,value2);
var val = trans1.select(table,key); // val equals value2,
I understand that transactions usually are used in different threads, but In that case of one thread we have unpredictable behaviour