Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]Maximum number of transactions reached #1772

Closed
5d2 opened this issue Aug 2, 2020 · 9 comments
Closed

[BUG]Maximum number of transactions reached #1772

5d2 opened this issue Aug 2, 2020 · 9 comments
Labels

Comments

@5d2
Copy link

5d2 commented Aug 2, 2020

V5.08

Exception Maximum number of transactions reached

CODE

var col = _db.GetCollection<T>(typeof(T).Name); result = col.Find(bse).ToList();
var col = _db.GetCollection<T>(typeof(T).Name); t = col.FindById(new ObjectId(Id)) :

@5d2 5d2 added the bug label Aug 2, 2020
@lbnascimento
Copy link
Collaborator

@5d2 I could not reproduce the issue. What .NET implementation are you using? Could you provide a complete sample code that I could use to reproduce the issue?

@mookid8000
Copy link

mookid8000 commented Sep 1, 2020

In case this could help, I can report having experienced the following (with LiteDB 5.0.9): Following some fairly heavy load, the following error error occurred:

System.ArgumentException: An entry with the same key already exists.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.SortedList`2.Add(TKey key, TValue value)
   at LiteDB.Engine.BasePage.Defrag()
   at LiteDB.Engine.BasePage.InternalInsert(UInt16 bytesLength, Byte& index)
   at LiteDB.Engine.BasePage.Update(Byte index, UInt16 bytesLength)
   at LiteDB.Engine.DataPage.UpdateBlock(DataBlock currentBlock, Int32 bytesLength)
   at LiteDB.Engine.DataService.<>c__DisplayClass4_0.<<Update>g__source|0>d.MoveNext()
   at LiteDB.Engine.BufferWriter..ctor(IEnumerable`1 source)
   at LiteDB.Engine.DataService.Update(CollectionPage col, PageAddress blockAddress, BsonDocument doc)
   at LiteDB.Engine.LiteEngine.UpdateDocument(Snapshot snapshot, CollectionPage col, BsonDocument doc, IndexService indexer, DataService data)
   at LiteDB.Engine.LiteEngine.<>c__DisplayClass26_0.<Update>b__0(TransactionService transaction)
   at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn)
   at FleetManager.Model.Tech.LiteDb.LiteDbProjection`1.<Flush>d__16.MoveNext() in C:\projects-rebusfm\fm7-server\FleetManager.Model.Tech\LiteDb\LiteDbProjection.cs:line 159

when calling ILiteCollection<T>.Update(IEnumerable<T> entities).

After having thrown that error for a while, LiteDB started giving off error messages like

LiteDB.LiteException: Invalid Data on 0. Full zero: True. Page Type: Empty. Prev/Next: 0/0. UniqueID: 1959. ShareCounter: -1. 

System.InvalidCastException: Unable to cast object of type 'LiteDB.Engine.HeaderPage' to type 'LiteDB.Engine.DataPage'.

LiteDB.LiteException: Invalid Data on 0. Full zero: True. Page Type: Empty. Prev/Next: 0/0. UniqueID: 5674. ShareCounter: -1. 

LiteDB.LiteException: Invalid Collection on 1365001555. Full zero: False. Page Type: 65. Prev/Next: 1768835387/1818323316. UniqueID: 7045. ShareCounter: 9. 

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

until finally settling on

LiteDB.LiteException: Maximum number of transactions reached
   at LiteDB.Engine.TransactionMonitor.GetTransaction(Boolean create, Boolean queryOnly, Boolean& isNew)
   at LiteDB.Engine.QueryExecutor.ExecuteQuery(Boolean executionPlan)
   at LiteDB.Engine.LiteEngine.Query(String collection, Query query)
   at LiteDB.LiteQueryable`1.<ToDocuments>d__26.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at FleetManager.Model.Tech.LiteDb.LiteDbProjection`1.<WarmUp>d__14.MoveNext() in C:\projects-rebusfm\fm7-server\FleetManager.Model.Tech\LiteDb\LiteDbProjection.cs:line 93

until the process was stopped.

@KC7465128305
Copy link

KC7465128305 commented Sep 19, 2020

I have the same problem and I am using v5.0.9 so the bug hasn't been fixed. This is what triggers this exception:

((LiteCollection)MyDB.NoSqlDB.GetCollection("Frm")).FindOne(p => p.Id == ID);

Where POCOFrm is a very simple POCO class with four properties, two are of type string and two are of type int.

@KC7465128305
Copy link

Got another "Maximum number of transactions reached" bug when my program run the following statement:

LiteDB.IBsonDataReader reader = MyDB.NoSqlDB.Execute($"SELECT _id FROM Ctl ORDER BY _id DESC LIMIT 1");

@frankneumann
Copy link
Contributor

I encountered the same exception, which was caused by the heavy use of threads within Parallel.ForEach. Unfortunately, the TransactionService for a closed thread will not be removed from the _transactions dictionary within the TransactionMonitor.
Here a finalizer for the TransactionService has to be added, which takes care of removing the transaction from the _transactions dictionary. I will provide a fix for this.

frankneumann added a commit to frankneumann/LiteDB that referenced this issue Dec 26, 2020
… closed thread was not be removed from the _transactions dictionary within the TransactionMonitor.

Therefore a finalizer for the TransactionService was added, which takes care of removing the transaction from the _transactions dictionary.
@mbdavid
Copy link
Owner

mbdavid commented Jan 22, 2021

Hi @frankneumann , thanks for solving this. Can you submit a Pull Request about this bugfix?

@frankneumann
Copy link
Contributor

It is here:
#1906

mbdavid added a commit that referenced this issue Jan 22, 2021
Fixed issue #1772: Unfortunately, the TransactionService for a closed…
@balverio
Copy link

balverio commented Feb 5, 2021

@mbdavid @frankneumann My company needs this fix, do you know when it will be released and what version?

@lbnascimento
Copy link
Collaborator

It is fixed in the latest release.

gzatravkin pushed a commit to gzatravkin/LiteDB that referenced this issue Jan 25, 2022
… closed thread was not be removed from the _transactions dictionary within the TransactionMonitor.

Therefore a finalizer for the TransactionService was added, which takes care of removing the transaction from the _transactions dictionary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants