hhblaze/DBreeze

Transaction doesn't exist exception

thecodrr opened this issue · 8 comments

Here's my code for inserting records:

 using (var tran = _engine.GetTransaction())
                {
                    if (records.Any())
                    {
                        tran.Technical_SetTable_OverwriteIsNotAllowed(_tableName); //exception hits here. Removing this DOESN'T solve the issue.

                        foreach (var record in records.ToList())
                        {
                            record.Id = tran.ObjectGetNewIdentity<long>(_tableName);
                            var ir = tran.ObjectInsert(_tableName, new DBreezeObject<IDbRecord>
                            {
                                Indexes = new List<DBreezeIndex>
                                        {
                                            new DBreezeIndex(1, record.Id) {PrimaryIndex = true }
                                        },
                                NewEntity = true,
                                //Changes Select-Insert pattern to Insert (speeds up insert process)
                                Entity = record //Entity itself
                            },
                                true);
                            //Using text-search engine for the free text search
                            tran.TextInsert(_textTableName, record.Id.To_8_bytes_array_BigEndian(), record.GetTextSearchKey());
                        }

                        tran.Commit();
                    }
                }

Here's the exception details:

Stacktrace:

   at DBreeze.Transactions.TransactionsCoordinator.GetTable_WRITE(String tableName, Int32 transactionThreadId)
   at DBreeze.Transactions.Transaction.GetWriteTableFromBuffer(String tableName)
   at DBreeze.Transactions.Transaction.Technical_SetTable_OverwriteIsNotAllowed(String tableName)
   at BreadPlayer.Database.KeyValueStoreDatabaseService.<>c__DisplayClass15_0.<InsertRecords>b__0()
   at System.Threading.Tasks.Task.Execute()

Please help, thanks.

Hi, transaction can be executed in one .net managed thread and can't be delegated to others. One of the latest DBreeze releases permits execution of parallel reads in separated threads - read documents. So, looks like you have transfered transaction from thread to thread, parent thread has disposed it to the moment when the other thread wanted to use it.

That's what I figured too after a lot of debugging. But the problem is I can't figure out where the disposal is happening. Obviously, this is a problem on my end as it works when I insert other entities.

Can you create separate project repeating behavior and mistake to share it here?

How is it going, did you figure out the problem?

No, I couldn't figure anything out really. I tried removing all Task and working synchronously but it still gave me the same error.

Can you create simplified project as an example?

Yes, I will do that and post here ASAP.

Ok, then reopen when you got smth.