Skip to content
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

Merged

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Aug 6, 2024

Changes

Fixes #7312

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

@Aaronontheweb
Copy link
Member Author

Not done with this PR by a long shot - looking at doing some potential fixes around the ITimeProvider implementation we have first in order to ensure that we ACTUALLY support dependency injection with it.

Copy link
Member Author

@Aaronontheweb Aaronontheweb left a 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" +
Copy link
Member Author

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);
Copy link
Member Author

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));
Copy link
Member Author

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.

@Aaronontheweb Aaronontheweb marked this pull request as ready for review August 6, 2024 17:39
Copy link
Contributor

@Arkatufus Arkatufus left a 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" +
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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)]

src/core/Akka.Persistence/SnapshotProtocol.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review

Comment on lines +228 to +231
// 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()
Copy link
Contributor

@Arkatufus Arkatufus Aug 8, 2024

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Member Author

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.

@Aaronontheweb Aaronontheweb added the akka-persistence-sql-common Akka.Persistence.Sql.Common label Aug 8, 2024
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a 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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - bugfix

Comment on lines +228 to +231
// 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()
Copy link
Member Author

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?

@Aaronontheweb Aaronontheweb merged commit d6a8063 into akkadotnet:dev Aug 8, 2024
7 of 12 checks passed
@Aaronontheweb Aaronontheweb deleted the fix-7312-SnapshotMetadata branch August 8, 2024 20:23
Aaronontheweb added a commit to Aaronontheweb/akka.net that referenced this pull request Aug 16, 2024
Arkatufus pushed a commit that referenced this pull request Aug 16, 2024
* fixed Akka.Persistence.Tck snapshot load specs

Left-over bugs from #7313

* fixed the specs
Arkatufus added a commit to Arkatufus/Akka.Persistence.Sql that referenced this pull request Aug 30, 2024
Aaronontheweb pushed a commit to akkadotnet/Akka.Persistence.Sql that referenced this pull request Sep 4, 2024
Arkatufus added a commit to Arkatufus/Akka.Persistence.Azure that referenced this pull request Sep 11, 2024
Arkatufus added a commit to Arkatufus/Akka.Persistence.Azure that referenced this pull request Sep 11, 2024
…estamp for `SnapshotMetdata`

(cherry picked from commit 916d18b)
Arkatufus added a commit to petabridge/Akka.Persistence.Azure that referenced this pull request Sep 11, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants