-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Akka.Persistence: Made DateTime.UtcNow
the default timestamp for SnapshotMetdata
#7313
Changes from all commits
333b5c2
930414f
788111a
28b94b5
64b00ed
736d3b8
6851492
85c143a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,7 +587,8 @@ namespace Akka.Persistence | |
} | ||
public sealed class SnapshotMetadata : System.IEquatable<Akka.Persistence.SnapshotMetadata> | ||
{ | ||
public static System.DateTime TimestampNotSpecified; | ||
[System.ObsoleteAttribute("This constructor is deprecated and will be removed in v1.6. Use the constructor w" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just marked the old CTOR as |
||
"ith the timestamp parameter instead. Since v1.5.28", true)] | ||
public SnapshotMetadata(string persistenceId, long sequenceNr) { } | ||
[Newtonsoft.Json.JsonConstructorAttribute()] | ||
public SnapshotMetadata(string persistenceId, long sequenceNr, System.DateTime timestamp) { } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,7 +587,8 @@ namespace Akka.Persistence | |
} | ||
public sealed class SnapshotMetadata : System.IEquatable<Akka.Persistence.SnapshotMetadata> | ||
{ | ||
public static System.DateTime TimestampNotSpecified; | ||
[System.ObsoleteAttribute("This constructor is deprecated and will be removed in v1.6. Use the constructor w" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little nitpick, Would be better if we follow english language sentence breaking point here, makes it easier to read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point - I can fix that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no I can't - that's an artifact from the rendering of the API diff. The real code looks like this: [Obsolete("This constructor is deprecated and will be removed in v1.6. Use the constructor with the timestamp parameter instead.", true)] |
||
"ith the timestamp parameter instead. Since v1.5.28", true)] | ||
public SnapshotMetadata(string persistenceId, long sequenceNr) { } | ||
[Newtonsoft.Json.JsonConstructorAttribute()] | ||
public SnapshotMetadata(string persistenceId, long sequenceNr, System.DateTime timestamp) { } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,7 +247,7 @@ protected IActorRef WriteSnapshot(string persistenceId, int n) | |
ExpectMsg($"{persistenceId}-{i}-done"); | ||
} | ||
|
||
var metadata = new SnapshotMetadata(persistenceId, n + 10); | ||
var metadata = new SnapshotMetadata(persistenceId, n + 10, Sys.Scheduler.Now.DateTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standard call we're going to use to get the current UTC time from the |
||
SnapshotStore.Tell(new SaveSnapshot(metadata, $"s-{n}"), _senderProbe.Ref); | ||
_senderProbe.ExpectMsg<SaveSnapshotSuccess>(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
using Akka.Persistence.Fsm; | ||
using Akka.Persistence.TCK.Serialization; | ||
using Akka.TestKit; | ||
using FluentAssertions.Extensions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
|
@@ -100,7 +101,7 @@ private IEnumerable<SnapshotMetadata> WriteSnapshots() | |
{ | ||
for (int i = 1; i <= 5; i++) | ||
{ | ||
var metadata = new SnapshotMetadata(Pid, i + 10); | ||
var metadata = new SnapshotMetadata(Pid, i + 10, Sys.Scheduler.Now.DateTime); | ||
SnapshotStore.Tell(new SaveSnapshot(metadata, $"s-{i}"), _senderProbe.Ref); | ||
yield return _senderProbe.ExpectMsg<SaveSnapshotSuccess>().Metadata; | ||
} | ||
|
@@ -177,11 +178,13 @@ public virtual void SnapshotStore_should_load_the_most_recent_snapshot_matching_ | |
&& result.Snapshot.Snapshot.ToString() == "s-3"); | ||
} | ||
|
||
// Issue #7312 | ||
// Backward compatibility check, SnapshotMetadata .ctor should work if we pass in UtcNow | ||
[Fact] | ||
public virtual void SnapshotStore_should_delete_a_single_snapshot_identified_by_SequenceNr_in_snapshot_metadata() | ||
{ | ||
var md = Metadata[2]; | ||
md = new SnapshotMetadata(md.PersistenceId, md.SequenceNr); // don't care about timestamp for delete of a single snap | ||
md = new SnapshotMetadata(md.PersistenceId, md.SequenceNr, Sys.Scheduler.Now.DateTime); | ||
var command = new DeleteSnapshot(md); | ||
var sub = CreateTestProbe(); | ||
|
||
|
@@ -198,6 +201,54 @@ public virtual void SnapshotStore_should_delete_a_single_snapshot_identified_by_ | |
&& result.Snapshot.Snapshot.ToString() == "s-2"); | ||
} | ||
|
||
// Issue #7312 | ||
// Backward compatibility check, old SnapshotMetadata .ctor default value should work as expected | ||
[Fact] | ||
public virtual void SnapshotStore_should_delete_a_single_snapshot_identified_by_SequenceNr_in_snapshot_metadata_if_timestamp_is_MinValue() | ||
{ | ||
var md = Metadata[2]; | ||
// In previous incarnation, timestamp argument defaults to DateTime.MinValue | ||
md = new SnapshotMetadata(md.PersistenceId, md.SequenceNr, DateTime.MinValue); | ||
var command = new DeleteSnapshot(md); | ||
var sub = CreateTestProbe(); | ||
|
||
Subscribe<DeleteSnapshot>(sub.Ref); | ||
SnapshotStore.Tell(command, _senderProbe.Ref); | ||
sub.ExpectMsg(command); | ||
_senderProbe.ExpectMsg<DeleteSnapshotSuccess>(); | ||
|
||
SnapshotStore.Tell(new LoadSnapshot(Pid, new SnapshotSelectionCriteria(md.SequenceNr), long.MaxValue), _senderProbe.Ref); | ||
_senderProbe.ExpectMsg<LoadSnapshotResult>(result => | ||
result.ToSequenceNr == long.MaxValue | ||
&& result.Snapshot != null | ||
&& result.Snapshot.Metadata.Equals(Metadata[1]) | ||
&& result.Snapshot.Snapshot.ToString() == "s-2"); | ||
} | ||
|
||
// Issue #7312, this is a side effect of the ctor signature changes | ||
// DeleteSnapshot should not delete snapshot if timestamp value does not meet deletion criteria | ||
[Fact] | ||
public virtual void SnapshotStore_should_not_delete_snapshot_identified_by_SequenceNr_if_metadata_timestamp_is_less_than_stored_timestamp() | ||
Comment on lines
+228
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a side effect of the changes made in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We either have this as an actual spec, or change the code to disregard There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add an overrideable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unit test methods themselves are virtual, and this is part of the spec now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, "force", someone can always override and skip the test in implementation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doh, I missed that. You're right. LGTM. |
||
{ | ||
var md = Metadata[2]; | ||
// timestamp argument is less than the actual metadata data stored in the database, no deletion occured | ||
md = new SnapshotMetadata(md.PersistenceId, md.SequenceNr, md.Timestamp - 2.Seconds()); | ||
var command = new DeleteSnapshot(md); | ||
var sub = CreateTestProbe(); | ||
|
||
Subscribe<DeleteSnapshot>(sub.Ref); | ||
SnapshotStore.Tell(command, _senderProbe.Ref); | ||
sub.ExpectMsg(command); | ||
_senderProbe.ExpectMsg<DeleteSnapshotSuccess>(); | ||
|
||
SnapshotStore.Tell(new LoadSnapshot(Pid, new SnapshotSelectionCriteria(md.SequenceNr), long.MaxValue), _senderProbe.Ref); | ||
_senderProbe.ExpectMsg<LoadSnapshotResult>(result => | ||
result.ToSequenceNr == long.MaxValue | ||
&& result.Snapshot != null | ||
&& result.Snapshot.Metadata.Equals(Metadata[2]) | ||
&& result.Snapshot.Snapshot.ToString() == "s-3"); | ||
} | ||
|
||
[Fact] | ||
public virtual void SnapshotStore_should_delete_all_snapshots_matching_upper_sequence_number_and_timestamp_bounds() | ||
{ | ||
|
@@ -260,7 +311,7 @@ public virtual void SnapshotStore_should_save_and_overwrite_snapshot_with_same_s | |
[Fact] | ||
public virtual void SnapshotStore_should_save_bigger_size_snapshot() | ||
{ | ||
var metadata = new SnapshotMetadata(Pid, 100); | ||
var metadata = new SnapshotMetadata(Pid, 100, Sys.Scheduler.Now.DateTime); | ||
var bigSnapshot = new byte[SnapshotByteSizeLimit]; | ||
new Random().NextBytes(bigSnapshot); | ||
SnapshotStore.Tell(new SaveSnapshot(metadata, bigSnapshot), _senderProbe.Ref); | ||
|
@@ -274,7 +325,7 @@ public virtual void ShouldSerializeSnapshots() | |
if (!SupportsSerialization) return; | ||
|
||
var probe = CreateTestProbe(); | ||
var metadata = new SnapshotMetadata(Pid, 100L); | ||
var metadata = new SnapshotMetadata(Pid, 100L, Sys.Scheduler.Now.DateTime); | ||
var snap = new TestPayload(probe.Ref); | ||
|
||
SnapshotStore.Tell(new SaveSnapshot(metadata, snap), _senderProbe.Ref); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,7 @@ public void LoadSnapshot(string persistenceId, SnapshotSelectionCriteria criteri | |
/// <param name="snapshot">TBD</param> | ||
public void SaveSnapshot(object snapshot) | ||
{ | ||
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(SnapshotterId, SnapshotSequenceNr), snapshot)); | ||
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(SnapshotterId, SnapshotSequenceNr, Context.System.Scheduler.Now.Date), snapshot)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the same standard call now for both saving and deleting snapshots - big question I have though: does this break deleting snapshots? It SHOULDN'T, but we'll need to see how the specs perform to know for certain. |
||
} | ||
|
||
/// <summary> | ||
|
@@ -230,7 +230,7 @@ public void SaveSnapshot(object snapshot) | |
/// <param name="sequenceNr">TBD</param> | ||
public void DeleteSnapshot(long sequenceNr) | ||
{ | ||
SnapshotStore.Tell(new DeleteSnapshot(new SnapshotMetadata(SnapshotterId, sequenceNr))); | ||
SnapshotStore.Tell(new DeleteSnapshot(new SnapshotMetadata(SnapshotterId, sequenceNr, DateTime.MinValue))); | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - bugfix