From 6835465a2c638b74e01d659c64bc81f7b8ff9287 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 22 Jul 2024 14:20:22 -0500 Subject: [PATCH 1/3] remove unused `reference.confg` from DistributedData.LightningDb These configuration values are read from and used by `DistributedData/reference.conf`, so this unused duplicate file is confusing and unnecessary. --- .../Akka.DistributedData.LightningDB.csproj | 1 - .../reference.conf | 27 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 src/contrib/cluster/Akka.DistributedData.LightningDB/reference.conf diff --git a/src/contrib/cluster/Akka.DistributedData.LightningDB/Akka.DistributedData.LightningDB.csproj b/src/contrib/cluster/Akka.DistributedData.LightningDB/Akka.DistributedData.LightningDB.csproj index b2e80e28b34..70b5ea22487 100644 --- a/src/contrib/cluster/Akka.DistributedData.LightningDB/Akka.DistributedData.LightningDB.csproj +++ b/src/contrib/cluster/Akka.DistributedData.LightningDB/Akka.DistributedData.LightningDB.csproj @@ -8,7 +8,6 @@ - diff --git a/src/contrib/cluster/Akka.DistributedData.LightningDB/reference.conf b/src/contrib/cluster/Akka.DistributedData.LightningDB/reference.conf deleted file mode 100644 index fc1732599c6..00000000000 --- a/src/contrib/cluster/Akka.DistributedData.LightningDB/reference.conf +++ /dev/null @@ -1,27 +0,0 @@ -akka.cluster.distributed-data.lmdb { - # Directory of LMDB file. There are two options: - # 1. A relative or absolute path to a directory that ends with 'ddata' - # the full name of the directory will contain name of the ActorSystem - # and its remote port. - # 2. Otherwise the path is used as is, as a relative or absolute path to - # a directory. - # - # When running in production you may want to configure this to a specific - # path (alt 2), since the default directory contains the remote port of the - # actor system to make the name unique. If using a dynamically assigned - # port (0) it will be different each time and the previously stored data - # will not be loaded. - dir = "ddata" - - # Size in bytes of the memory mapped file. - map-size = 100 MiB - - # Accumulate changes before storing improves performance with the - # risk of losing the last writes if the JVM crashes. - # The interval is by default set to 'off' to write each update immediately. - # Enabling write behind by specifying a duration, e.g. 200ms, is especially - # efficient when performing many writes to the same key, because it is only - # the last value for each key that will be serialized and stored. - # write-behind-interval = 200 ms - write-behind-interval = off -} \ No newline at end of file From 5502ac1b9bba6cf6c7e65b19348e7d399e7c11ec Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 22 Jul 2024 15:00:37 -0500 Subject: [PATCH 2/3] clean up specs --- .../PersistentShardingMigrationSpec.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs index 99408730a11..86589960e8e 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs @@ -21,7 +21,7 @@ namespace Akka.Cluster.Sharding.Tests { /// /// Test migration from old persistent shard coordinator with remembered - /// entities to using a ddatabacked shard coordinator with an event sourced + /// entities to using a ddata-backed shard coordinator with an event sourced /// replicated entity store. /// public class PersistentShardingMigrationSpec : AkkaSpec @@ -171,11 +171,11 @@ class = ""Akka.Cluster.Sharding.Tests.MemorySnapshotStoreShared, Akka.Cluster.Sh }"); - private Config configForNewMode; + private readonly Config _configForNewMode; public PersistentShardingMigrationSpec(ITestOutputHelper helper) : base(SpecConfig, helper) { - configForNewMode = ConfigForNewMode.WithFallback(Sys.Settings.Config); + _configForNewMode = ConfigForNewMode.WithFallback(Sys.Settings.Config); } protected override void AtStartup() @@ -187,7 +187,7 @@ protected override void AtStartup() [Fact] public void Migration_should_allow_migration_of_remembered_shards_and_not_allow_going_back() { - var typeName = "Migration"; + const string typeName = "Migration"; WithSystem(Sys.Settings.Config, typeName, "OldMode", (_, region, _) => { @@ -200,7 +200,7 @@ public void Migration_should_allow_migration_of_remembered_shards_and_not_allow_ ExpectMsg("ack"); }); - WithSystem(configForNewMode, typeName, "NewMode", (system, region, rememberedEntitiesProbe) => + WithSystem(_configForNewMode, typeName, "NewMode", (system, region, rememberedEntitiesProbe) => { AssertRegionRegistrationComplete(region); var probe = CreateTestProbe(system); @@ -224,11 +224,11 @@ public void Migration_should_allow_migration_of_remembered_shards_and_not_allow_ [Fact] public void Migration_should_not_allow_going_back_to_persistence_mode_based_on_a_snapshot() { - var typeName = "Snapshots"; - WithSystem(configForNewMode, typeName, "NewMode", (system, region, _) => + const string typeName = "Snapshots"; + WithSystem(_configForNewMode, typeName, "NewMode", (system, region, _) => { var probe = CreateTestProbe(system); - for (int i = 1; i <= 5; i++) + for (var i = 1; i <= 5; i++) { region.Tell(new Message(i), probe.Ref); probe.ExpectMsg("ack"); From 9451d354c4ce78c9ee94352104414b8cb0382854 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 22 Jul 2024 15:14:43 -0500 Subject: [PATCH 3/3] hardened `PersistentShardingMigrationSpec` --- .../PersistentShardingMigrationSpec.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs index 86589960e8e..b311e699a7a 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardingMigrationSpec.cs @@ -206,10 +206,22 @@ public void Migration_should_allow_migration_of_remembered_shards_and_not_allow_ var probe = CreateTestProbe(system); region.Tell(new Message(1), probe.Ref); probe.ExpectMsg("ack"); - ImmutableHashSet.Create( - rememberedEntitiesProbe.ExpectMsg(), - rememberedEntitiesProbe.ExpectMsg(), - rememberedEntitiesProbe.ExpectMsg()).Should().BeEquivalentTo("1", "2", "3"); // 1-2 from the snapshot, 3 from a replayed message + + // due to retries in the remember-entities system, we have to tolerate + // potentially receiving a duplicate message for the same entity + // therefore, we need to wait for at least 3 distinct messages or until the timeout + var maxTimeout = TimeSpan.FromSeconds(5); + var found = ImmutableHashSet.Empty; + Within(maxTimeout, () => + { + while(found.Count < 3 && RemainingOrDefault > TimeSpan.Zero) + { + var msg = rememberedEntitiesProbe.ExpectMsg(); + found = found.Add(msg); + } + }); + + found.Should().BeEquivalentTo("1", "2", "3"); // 1-2 from the snapshot, 3 from a replayed message rememberedEntitiesProbe.ExpectNoMsg(); });