Skip to content

Commit

Permalink
RavenDB-16460 Refactoring how we get the merged transaction data to b…
Browse files Browse the repository at this point in the history
…e flushed
  • Loading branch information
ayende committed Aug 28, 2024
1 parent 6d76dcb commit 96874a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 4 additions & 8 deletions src/Voron/Impl/Journal/WriteAheadJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,13 @@ public void ApplyLogsToDataFile(CancellationToken token, TimeSpan timeToWait)
{
// RavenDB-13302: we need to force a re-check this before we make decisions here
_waj._env.ActiveTransactions.ForceRecheckingOldestTransactionByFlusherThread();
if (_waj._env.TryGetLatestEnvironmentStateToFlush(
uptoTxIdExclusive: _waj._env.ActiveTransactions.OldestTransaction,
out _applyLogsToDataFileStateFromPreviousFailedAttempt) == false)
{
Debug.Assert(_applyLogsToDataFileStateFromPreviousFailedAttempt.Buffers.Count == 0);
_applyLogsToDataFileStateFromPreviousFailedAttempt = _waj._env.TryGetLatestEnvironmentStateToFlush(
uptoTxIdExclusive: _waj._env.ActiveTransactions.OldestTransaction);
if (_applyLogsToDataFileStateFromPreviousFailedAttempt == null)
return; // nothing to do
}

Debug.Assert(_applyLogsToDataFileStateFromPreviousFailedAttempt != null);
}

Debug.Assert(_applyLogsToDataFileStateFromPreviousFailedAttempt is { Record: not null, Buffers: not null });
var currentTotalCommittedSinceLastFlushPages = TotalCommittedSinceLastFlushPages;

Pager.State dataPagerState;
Expand Down
9 changes: 5 additions & 4 deletions src/Voron/StorageEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ private void UpdateStateOnCommit(LowLevelTransaction tx)
private readonly List<PageFromScratchBuffer> _cachedScratchBuffers = [];
private readonly List<long> _cachedSparseRegionsList = [];

internal bool TryGetLatestEnvironmentStateToFlush(long uptoTxIdExclusive, out ApplyLogsToDataFileState state)
internal ApplyLogsToDataFileState TryGetLatestEnvironmentStateToFlush(long uptoTxIdExclusive)
{
if (uptoTxIdExclusive == 0)
uptoTxIdExclusive = long.MaxValue;
Expand All @@ -1633,16 +1633,17 @@ internal bool TryGetLatestEnvironmentStateToFlush(long uptoTxIdExclusive, out Ap
scratchBuffers.Clear();
var sparseRegions = _cachedSparseRegionsList;
sparseRegions.Clear();
state = null;
bool found = false;
EnvironmentStateRecord record = null;
while (true)
{
if (_transactionsToFlush.TryPeek(out var maybe) == false ||
maybe.TransactionId >= uptoTxIdExclusive)
{
state = new ApplyLogsToDataFileState(scratchBuffers, sparseRegions, record);
return found;
if (found == false)
return null;
Debug.Assert(record is not null);
return new ApplyLogsToDataFileState(scratchBuffers, sparseRegions, record);
}
if (_transactionsToFlush.TryDequeue(out record) == false)
throw new InvalidOperationException("Failed to get transaction to flush after already peeked successfully");
Expand Down

0 comments on commit 96874a9

Please sign in to comment.