Skip to content

Commit ccdaa40

Browse files
Merge pull request #111 from akkadotnet/dev
v1.4.0-beta3 Release
2 parents 601b781 + 23ed8e9 commit ccdaa40

15 files changed

+268
-57
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ akka.persistence {
4747
4848
# metadata collection
4949
metadata-collection = "Metadata"
50+
51+
# For users with legacy data, who want to keep writing data to MongoDb using the original BSON format
52+
# and not the standard binary format introduced in v1.4.0 (see https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72)
53+
# enable this setting via `legacy-serialization = on`.
54+
#
55+
# NOTE: this will likely break features such as Akka.Cluster.Sharding, IActorRef serialization, AtLeastOnceDelivery, and more.
56+
legacy-serialization = off
5057
}
5158
}
5259
@@ -66,16 +73,44 @@ akka.persistence {
6673
6774
# MongoDb collection corresponding with persistent snapshot store
6875
collection = "SnapshotStore"
76+
77+
# For users with legacy data, who want to keep writing data to MongoDb using the original BSON format
78+
# and not the standard binary format introduced in v1.4.0 (see https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72)
79+
# enable this setting via `legacy-serialization = on`.
80+
#
81+
# NOTE: this will likely break features such as Akka.Cluster.Sharding, IActorRef serialization, AtLeastOnceDelivery, and more.
82+
legacy-serialization = off
6983
}
7084
}
7185
}
7286
```
7387

7488
### Serialization
75-
The events and snapshots are stored as BsonDocument. On the previous version of this driver you needed to register your types with BsonClassMap before you could use your persistence actor, otherwise the recovery would fail and you'd receive a RecoveryFailure with the message:
76-
>An error occurred while deserializing the Payload property of class \<Journal or Snapshot class>: Unknown discriminator value '\<your type>'
89+
[Going from v1.4.0 onwards, all events and snapshots are saved as byte arrays using the standard Akka.Persistence format](https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72).
90+
91+
However, in the event that you have one of the following use cases:
92+
93+
1. Legacy data all stored in the original BSON / "object" format;
94+
2. A use case where BSON is preferable, i.e. so it can be queried directly via MongoDb queries rather than Akka.Persistence.Query; or
95+
3. A requirement to keep all data in human-readable form.
96+
97+
Then you can disable binary serialization (enabled by default) via the following HOCON:
98+
99+
```
100+
akka.persistence.mongodb{
101+
journal{
102+
legacy-serialization = off
103+
}
104+
105+
snapshot-store{
106+
legacy-serialization = off
107+
}
108+
}
109+
```
110+
111+
Setting `legacy-serialization = on` will allow you to save objects in a BSON format.
77112

78-
#### **Since now, all types are registered automatically for you so you don't need to use BsonClassMap to serialize/deserialize your types!**
113+
**WARNING**: However, `legacy-serialization = on` will break Akka.NET serialization. `IActorRef`s, Akka.Cluster.Sharding, `AtLeastOnceDelivery` actors, and other built-in Akka.NET use cases can't be properly supported using this format. Use it at your own risk.
79114

80115
### Notice
81116
- The MongoDB operator to limit the number of documents in a query only accepts an integer while akka provides a long as maximum for the loading of events during the replay. Internally the long value is cast to an integer and if the value is higher then Int32.MaxValue, Int32.MaxValue is used. So if you have stored more then 2,147,483,647 events for a single PersistenceId, you may have a problem :wink:

RELEASE_NOTES.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
#### 1.4.0-beta2 October 31 2019 ####
2-
Fixed [an issue with Snapshot serialization in v1.4.0-beta1](https://github.com/akkadotnet/Akka.Persistence.MongoDB/pull/98)
1+
#### 1.4.0-beta3 February 04 2020 ####
2+
3+
Introduced legacy serialization modes.
4+
5+
[Going from v1.4.0 onwards, all events and snapshots are saved as byte arrays using the standard Akka.Persistence format](https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72).
6+
7+
However, in the event that you have one of the following use cases:
8+
9+
1. Legacy data all stored in the original BSON / "object" format;
10+
2. A use case where BSON is preferable, i.e. so it can be queried directly via MongoDb queries rather than Akka.Persistence.Query; or
11+
3. A requirement to keep all data in human-readable form.
12+
13+
Then you can disable binary serialization (enabled by default) via the following HOCON:
14+
15+
```
16+
akka.persistence.mongodb{
17+
journal{
18+
legacy-serialization = off
19+
}
20+
21+
snapshot-store{
22+
legacy-serialization = off
23+
}
24+
}
25+
```
26+
27+
Setting `legacy-serialization = on` will allow you to save objects in a BSON format.
28+
29+
**WARNING**: However, `legacy-serialization = on` will break Akka.NET serialization. `IActorRef`s, Akka.Cluster.Sharding, `AtLeastOnceDelivery` actors, and other built-in Akka.NET use cases can't be properly supported using this format. Use it at your own risk.

build.fsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ let solutionFile = FindFirstMatchingFile "*.sln" __SOURCE_DIRECTORY__ // dynami
2323
let buildNumber = environVarOrDefault "BUILD_NUMBER" "0"
2424
let hasTeamCity = (not (buildNumber = "0")) // check if we have the TeamCity environment variable for build # set
2525
let preReleaseVersionSuffix = "beta" + (if (not (buildNumber = "0")) then (buildNumber) else DateTime.UtcNow.Ticks.ToString())
26+
let releaseNotes =
27+
File.ReadLines (__SOURCE_DIRECTORY__ @@ "RELEASE_NOTES.md")
28+
|> ReleaseNotesHelper.parseReleaseNotes
29+
30+
let versionFromReleaseNotes =
31+
match releaseNotes.SemVer.PreRelease with
32+
| Some r -> r.Origin
33+
| None -> ""
34+
2635
let versionSuffix =
2736
match (getBuildParam "nugetprerelease") with
2837
| "dev" -> preReleaseVersionSuffix
29-
| "" -> ""
38+
| "" -> versionFromReleaseNotes
3039
| str -> str
31-
32-
let releaseNotes =
33-
File.ReadLines "./RELEASE_NOTES.md"
34-
|> ReleaseNotesHelper.parseReleaseNotes
3540

3641
// Directories
3742
let toolsDir = __SOURCE_DIRECTORY__ @@ "tools"
@@ -139,7 +144,7 @@ Target "SignPackages" (fun _ ->
139144
if(canSign) then
140145
log "Signing information is available."
141146

142-
let assemblies = !! (outputNuGet @@ "*.nupkg")
147+
let assemblies = !! (outputNuGet @@ "*.*upkg")
143148

144149
let signPath =
145150
let globalTool = tryFindFileOnPath "SignClient.exe"

src/Akka.Persistence.MongoDb.Tests/Akka.Persistence.MongoDb.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
1111
<PackageReference Include="xunit" Version="$(XunitVersion)" />
1212
<PackageReference Include="Akka.Persistence.TCK" Version="$(AkkaVersion)" />
13-
<PackageReference Include="FluentAssertions" Version="5.9.0" />
13+
<PackageReference Include="FluentAssertions" Version="5.10.0" />
1414
<PackageReference Include="Mongo2Go" Version="2.2.12" />
1515
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
1616
</ItemGroup>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="MongoDbJournalSpec.cs" company="Akka.NET Project">
3+
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
4+
// Copyright (C) 2013-2019 Akka.NET project <https://github.com/akkadotnet/akka.net>
5+
// </copyright>
6+
//-----------------------------------------------------------------------
7+
8+
using Akka.Configuration;
9+
using Akka.Persistence.TCK.Journal;
10+
using Xunit;
11+
12+
namespace Akka.Persistence.MongoDb.Tests
13+
{
14+
[Collection("MongoDbSpec")]
15+
public class MongoDbLegacySerializationJournalSpec : JournalSpec, IClassFixture<DatabaseFixture>
16+
{
17+
protected override bool SupportsRejectingNonSerializableObjects { get; } = false;
18+
19+
protected override bool SupportsSerialization => false;
20+
21+
public MongoDbLegacySerializationJournalSpec(DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture), "MongoDbJournalSpec")
22+
{
23+
Initialize();
24+
}
25+
26+
private static Config CreateSpecConfig(DatabaseFixture databaseFixture)
27+
{
28+
var specString = @"
29+
akka.test.single-expect-default = 3s
30+
akka.persistence {
31+
publish-plugin-commands = on
32+
journal {
33+
plugin = ""akka.persistence.journal.mongodb""
34+
mongodb {
35+
class = ""Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb""
36+
connection-string = """ + databaseFixture.ConnectionString + @"""
37+
auto-initialize = on
38+
collection = ""EventJournal""
39+
legacy-serialization = on
40+
}
41+
}
42+
}";
43+
44+
return ConfigurationFactory.ParseString(specString);
45+
}
46+
}
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="MongoDbSnapshotStoreSpec.cs" company="Akka.NET Project">
3+
// Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
4+
// Copyright (C) 2013-2016 Akka.NET project <https://github.com/akkadotnet/akka.net>
5+
// </copyright>
6+
//-----------------------------------------------------------------------
7+
8+
using Akka.Configuration;
9+
using Akka.Persistence.TCK.Snapshot;
10+
using Xunit;
11+
12+
namespace Akka.Persistence.MongoDb.Tests
13+
{
14+
// TODO: enable this spec once https://github.com/akkadotnet/akka.net/pull/4190 is available via Akka.NET v1.4.0-beta5 or higher
15+
//[Collection("MongoDbSpec")]
16+
//public class MongoDbLegacySerializationSnapshotStoreSpec : SnapshotStoreSpec, IClassFixture<DatabaseFixture>
17+
//{
18+
// protected override bool SupportsSerialization => false;
19+
20+
// public MongoDbLegacySerializationSnapshotStoreSpec(DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture), "MongoDbSnapshotStoreSpec")
21+
// {
22+
// Initialize();
23+
// }
24+
25+
// private static Config CreateSpecConfig(DatabaseFixture databaseFixture)
26+
// {
27+
// var specString = @"
28+
// akka.test.single-expect-default = 3s
29+
// akka.persistence {
30+
// publish-plugin-commands = on
31+
// snapshot-store {
32+
// plugin = ""akka.persistence.snapshot-store.mongodb""
33+
// mongodb {
34+
// class = ""Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb""
35+
// connection-string = """ + databaseFixture.ConnectionString + @"""
36+
// auto-initialize = on
37+
// collection = ""SnapshotStore""
38+
// legacy-serialization = on
39+
// }
40+
// }
41+
// }";
42+
43+
// return ConfigurationFactory.ParseString(specString);
44+
// }
45+
//}
46+
}

src/Akka.Persistence.MongoDb.Tests/MongoDbSettingsSpec.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void Mongo_JournalSettings_must_have_default_values()
2222
mongoPersistence.JournalSettings.AutoInitialize.Should().BeFalse();
2323
mongoPersistence.JournalSettings.Collection.Should().Be("EventJournal");
2424
mongoPersistence.JournalSettings.MetadataCollection.Should().Be("Metadata");
25+
mongoPersistence.JournalSettings.LegacySerialization.Should().BeFalse();
2526
}
2627

2728
[Fact]
@@ -32,6 +33,7 @@ public void Mongo_SnapshotStoreSettingsSettings_must_have_default_values()
3233
mongoPersistence.SnapshotStoreSettings.ConnectionString.Should().Be(string.Empty);
3334
mongoPersistence.SnapshotStoreSettings.AutoInitialize.Should().BeFalse();
3435
mongoPersistence.SnapshotStoreSettings.Collection.Should().Be("SnapshotStore");
36+
mongoPersistence.SnapshotStoreSettings.LegacySerialization.Should().BeFalse();
3537
}
3638
}
3739
}

src/Akka.Persistence.MongoDb.Tests/MongoDbSnapshotStoreSpec.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,4 @@ class = ""Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persisten
3939
return ConfigurationFactory.ParseString(specString);
4040
}
4141
}
42-
43-
[Collection("MongoDbSpec")]
44-
public class MongoDbBinarySnapshotStoreSpec : SnapshotStoreSpec, IClassFixture<DatabaseFixture>
45-
{
46-
public MongoDbBinarySnapshotStoreSpec(DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture), "MongoDbSnapshotStoreSpec")
47-
{
48-
Initialize();
49-
}
50-
51-
private static Config CreateSpecConfig(DatabaseFixture databaseFixture)
52-
{
53-
var specString = @"
54-
akka.test.single-expect-default = 3s
55-
akka.persistence {
56-
publish-plugin-commands = on
57-
snapshot-store {
58-
plugin = ""akka.persistence.snapshot-store.mongodb""
59-
mongodb {
60-
class = ""Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb""
61-
connection-string = """ + databaseFixture.ConnectionString + @"""
62-
auto-initialize = on
63-
collection = ""SnapshotStore""
64-
stored-as = binary
65-
}
66-
}
67-
}";
68-
69-
return ConfigurationFactory.ParseString(specString);
70-
}
71-
}
7242
}

src/Akka.Persistence.MongoDb.Tests/Serialization/MongoDbJournalSerializationSpec.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class = ""Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.Mong
3333
connection-string = """ + databaseFixture.ConnectionString + @"""
3434
auto-initialize = on
3535
collection = ""EventJournal""
36-
stored-as = object
3736
}
3837
}
3938
}";

src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
</ItemGroup>
1111
<ItemGroup>
1212
<PackageReference Include="Akka.Persistence.Query" Version="$(AkkaVersion)" />
13-
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
13+
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
1414
</ItemGroup>
1515
</Project>

0 commit comments

Comments
 (0)