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 |
Aaronontheweb
left a comment
There was a problem hiding this comment.
Detailed my changes
| 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.
Just marked the old CTOR as Obsolete - no other API changes.
| } | ||
|
|
||
| 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.
Standard call we're going to use to get the current UTC time from the ITimeProvider built into the IScheduler.
| 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.
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.
Arkatufus
left a comment
There was a problem hiding this comment.
After thinking over about it, I think the change is dangerous
| 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.
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.
Good point - I can fix that.
There was a problem hiding this comment.
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)]| // 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.
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.
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.
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.
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.
Well, "force", someone can always override and skip the test in implementation
There was a problem hiding this comment.
Doh, I missed that. You're right. LGTM.
Aaronontheweb
left a comment
There was a problem hiding this comment.
Left some comments
| { | ||
| var sql = timestamp.HasValue | ||
| ? DeleteSnapshotRangeSql + " AND { Configuration.TimestampColumnName} = @Timestamp" | ||
| ? DeleteSnapshotSql + $" AND {Configuration.TimestampColumnName} <= @Timestamp" |
| // 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.
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):
SnapshotMetadataalways usesDateTime.MinValue, which creates "duplicate key" exceptions when multiple snapshots are taken at sameseqNr#7312