From 44eb993bb064e1078dd2947e9aa609d7df1e02e3 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Thu, 22 Dec 2022 21:31:07 +0700 Subject: [PATCH] Patch static persistence ID in suicide actor (#154) --- .../AkkaPersistenceLivenessProbe.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs b/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs index cc1f794..07a2b89 100644 --- a/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs +++ b/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs @@ -23,10 +23,12 @@ public class AkkaPersistenceLivenessProbe : ActorBase, IWithUnboundedStash private int _probeCounter; private bool _snapshotStoreLive; private readonly TimeSpan _delay; + private readonly string _id; public AkkaPersistenceLivenessProbe(TimeSpan delay) { _delay = delay; + _id = Guid.NewGuid().ToString("N"); } public AkkaPersistenceLivenessProbe() : this(TimeSpan.FromSeconds(10)) { @@ -121,7 +123,7 @@ protected override void PreStart() private void CreateProbe(bool firstTime) { - _probe = Context.ActorOf(Props.Create(() => new SuicideProbe(Self, firstTime))); + _probe = Context.ActorOf(Props.Create(() => new SuicideProbe(Self, firstTime, _id))); if(firstTime) { _probe.Tell("hit" + _probeCounter++); @@ -168,11 +170,11 @@ public class SuicideProbe : ReceivePersistentActor private bool _recoveredJournal; private bool _recoveredSnapshotStore; - public SuicideProbe(IActorRef probe, bool firstAttempt) + public SuicideProbe(IActorRef probe, bool firstAttempt, string id) { _probe = probe; _firstAttempt = firstAttempt; - PersistenceId = "Akka.HealthCheck"; + PersistenceId = $"Akka.HealthCheck-{id}"; Recover(str => { @@ -202,7 +204,7 @@ public SuicideProbe(IActorRef probe, bool firstAttempt) if (!_firstAttempt) { DeleteMessages(save.Metadata.SequenceNr - 1); - DeleteSnapshots(new SnapshotSelectionCriteria(save.Metadata.SequenceNr - 1)); + DeleteSnapshots(new SnapshotSelectionCriteria(save.Metadata.SequenceNr - 1)); } Context.Stop(Self);