-
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
Akka.Persistence: Made DateTime.UtcNow
the default timestamp for SnapshotMetdata
#7313
Conversation
Not done with this PR by a long shot - looking at doing some potential fixes around the |
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.
Detailed my changes
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Just marked the old CTOR as Obsolete
- no other API changes.
@@ -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 comment
The 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 ITimeProvider
built into the IScheduler
.
@@ -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 comment
The 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.
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.
After thinking over about it, I think the change is dangerous
@@ -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 comment
The 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 comment
The 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 comment
The 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)]
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.
Self review
// 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() |
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.
This is a side effect of the changes made in this PR.
User need to either have a SnapshotMetadata.Timestamp
that is greater than or equals to the stored value, or equals to DateTime.MinValue
for the actual Snapshot
to be deleted.
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.
We either have this as an actual spec, or change the code to disregard SnapshotMetadata.Timestamp
altogether when deleting a Snapshot
.
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.
Should we add an overrideable virtual
variable that allows this spec to be enable / disable on an implementation by implementation basis?
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.
The unit test methods themselves are virtual, and this is part of the spec now.
I think it is reasonable to force the other SQL implementation to adhere to the new spec?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, I missed that. You're right. LGTM.
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.
Left some comments
@@ -463,7 +463,7 @@ protected virtual void SetManifestParameters(object snapshot, DbCommand command) | |||
await connection.ExecuteInTransaction(WriteIsolationLevel, cancellationToken, async (tx, token) => | |||
{ | |||
var sql = timestamp.HasValue | |||
? DeleteSnapshotRangeSql + " AND { Configuration.TimestampColumnName} = @Timestamp" | |||
? DeleteSnapshotSql + $" AND {Configuration.TimestampColumnName} <= @Timestamp" |
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
// 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() |
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.
Should we add an overrideable virtual
variable that allows this spec to be enable / disable on an implementation by implementation basis?
Left-over bugs from akkadotnet#7313
* fixed Akka.Persistence.Tck snapshot load specs Left-over bugs from #7313 * fixed the specs
…estamp for `SnapshotMetdata`
…estamp for `SnapshotMetdata` (cherry picked from commit 916d18b)
* Bump AkkaVersion from 1.5.26 to 1.5.28 Bumps `AkkaVersion` from 1.5.26 to 1.5.28. Updates `Akka.Cluster.Sharding` from 1.5.26 to 1.5.28 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.5.26...1.5.28) Updates `Akka.Persistence.Query` from 1.5.26 to 1.5.28 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.5.26...1.5.28) Updates `Akka.Persistence.TCK` from 1.5.26 to 1.5.28 - [Release notes](https://github.com/akkadotnet/akka.net/releases) - [Changelog](https://github.com/akkadotnet/akka.net/blob/dev/RELEASE_NOTES.md) - [Commits](akkadotnet/akka.net@1.5.26...1.5.28) --- updated-dependencies: - dependency-name: Akka.Cluster.Sharding dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Persistence.Query dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: Akka.Persistence.TCK dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Port akkadotnet/akka.net#7313: Made `DateTime.UtcNow` the default timestamp for `SnapshotMetdata` (cherry picked from commit 916d18b) * Make operation cheaper (cherry picked from commit 1f8c3f6) * Fix port code to take DateTime.MinValue into account --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
Changes
Fixes #7312
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):
SnapshotMetadata
always usesDateTime.MinValue
, which creates "duplicate key" exceptions when multiple snapshots are taken at sameseqNr
#7312