Skip to content

Commit a1926f0

Browse files
authored
Merge pull request #1864 from mirasrael/fix-manual-transaction-checkpoints
Fixed: Pragma checkpoint ignored for manual transactions (BeginTrans/Commit)
2 parents 7730685 + edb32ae commit a1926f0

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

LiteDB/Engine/Engine/Transaction.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public bool Commit()
3939

4040
if (transaction.State == TransactionState.Active)
4141
{
42-
transaction.Commit();
43-
44-
_monitor.ReleaseTransaction(transaction);
42+
this.CommitAndReleaseTransaction(transaction);
4543

4644
return true;
4745
}
@@ -82,11 +80,7 @@ private T AutoTransaction<T>(Func<TransactionService, T> fn)
8280

8381
// if this transaction was auto-created for this operation, commit & dispose now
8482
if (isNew)
85-
{
86-
transaction.Commit();
87-
88-
_monitor.ReleaseTransaction(transaction);
89-
}
83+
this.CommitAndReleaseTransaction(transaction);
9084

9185
return result;
9286
}
@@ -100,17 +94,14 @@ private T AutoTransaction<T>(Func<TransactionService, T> fn)
10094

10195
throw;
10296
}
103-
finally
104-
{
105-
//TODO: acho que não é este o lugar para fazer o teste - devo capturar o ReleaseTransaction para isso
106-
// (ou seja, faz no final da transacao)
97+
}
10798

108-
// do auto-checkpoint if enabled (default: 1000 pages)
109-
if (_header.Pragmas.Checkpoint > 0 && _disk.GetLength(FileOrigin.Log) > (_header.Pragmas.Checkpoint * PAGE_SIZE))
110-
{
111-
_walIndex.TryCheckpoint();
112-
}
113-
}
99+
private void CommitAndReleaseTransaction(TransactionService transaction)
100+
{
101+
transaction.Commit();
102+
_monitor.ReleaseTransaction(transaction);
103+
if (_header.Pragmas.Checkpoint > 0 && _disk.GetLength(FileOrigin.Log) > (_header.Pragmas.Checkpoint * PAGE_SIZE))
104+
_walIndex.TryCheckpoint();
114105
}
115106
}
116107
}

0 commit comments

Comments
 (0)