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

Fix persistence allocations part 2. #6487

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/core/Akka.Persistence/Eventsourced.Recovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Akka.Actor;
using Akka.Persistence.Internal;

Expand Down Expand Up @@ -334,11 +332,11 @@ private void FlushBatch()
{
if (_eventBatch.Count > 0)
{
foreach (var p in _eventBatch.Reverse())
foreach (var p in _eventBatch)
{
_journalBatch.Add(p);
}
_eventBatch = new LinkedList<IPersistentEnvelope>();
_eventBatch.Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

}

FlushJournalBatch();
Expand Down
10 changes: 5 additions & 5 deletions src/core/Akka.Persistence/Eventsourced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void Persist<TEvent>(TEvent @event, Action<TEvent> handler)

_pendingStashingPersistInvocations++;
_pendingInvocations.AddLast(new StashingHandlerInvocation(@event, o => handler((TEvent)o)));
_eventBatch.AddFirst(new AtomicWrite(new Persistent(@event, persistenceId: PersistenceId,
_eventBatch.AddLast(new AtomicWrite(new Persistent(@event, persistenceId: PersistenceId,
Aaronontheweb marked this conversation as resolved.
Show resolved Hide resolved
sequenceNr: NextSequenceNr(), writerGuid: _writerGuid, sender: Sender)));
}

Expand Down Expand Up @@ -335,7 +335,7 @@ public void PersistAll<TEvent>(IEnumerable<TEvent> events, Action<TEvent> handle
}

if (persistents.Count > 0)
_eventBatch.AddFirst(new AtomicWrite(persistents.ToImmutable()));
_eventBatch.AddLast(new AtomicWrite(persistents.ToImmutable()));
}

/// <summary>
Expand Down Expand Up @@ -374,7 +374,7 @@ public void PersistAsync<TEvent>(TEvent @event, Action<TEvent> handler)
}

_pendingInvocations.AddLast(new AsyncHandlerInvocation(@event, o => handler((TEvent)o)));
_eventBatch.AddFirst(new AtomicWrite(new Persistent(@event, persistenceId: PersistenceId,
_eventBatch.AddLast(new AtomicWrite(new Persistent(@event, persistenceId: PersistenceId,
sequenceNr: NextSequenceNr(), writerGuid: _writerGuid, sender: Sender)));
}

Expand All @@ -400,7 +400,7 @@ public void PersistAllAsync<TEvent>(IEnumerable<TEvent> events, Action<TEvent> h
_pendingInvocations.AddLast(new AsyncHandlerInvocation(@event, Inv));
}

_eventBatch.AddFirst(new AtomicWrite(enumerable.Select(e => new Persistent(e, persistenceId: PersistenceId,
_eventBatch.AddLast(new AtomicWrite(enumerable.Select(e => new Persistent(e, persistenceId: PersistenceId,
sequenceNr: NextSequenceNr(), writerGuid: _writerGuid, sender: Sender))
.ToImmutableList<IPersistentRepresentation>()));
}
Expand Down Expand Up @@ -440,7 +440,7 @@ public void DeferAsync<TEvent>(TEvent evt, Action<TEvent> handler)
else
{
_pendingInvocations.AddLast(new AsyncHandlerInvocation(evt, o => handler((TEvent)o)));
_eventBatch.AddFirst(new NonPersistentMessage(evt, Sender));
_eventBatch.AddLast(new NonPersistentMessage(evt, Sender));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Persistence/Journal/AsyncWriteJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void HandleWriteMessages(WriteMessages message)
*/
var self = Self;
_resequencerCounter += message.Messages.Aggregate(1, (acc, m) => acc + m.Size);
var atomicWriteCount = message.Messages.OfType<AtomicWrite>().Count();
var atomicWriteCount = message.Messages.Count(x => x is AtomicWrite);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


// Using an async local function instead of ContinueWith
#pragma warning disable CS4014
Expand Down
Loading