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

Upgrade package dependencies #163

Merged
merged 24 commits into from
Mar 21, 2023
Merged

Conversation

CumpsD
Copy link
Member

@CumpsD CumpsD commented Mar 19, 2023

Upgrade dependencies and make sure the code still works

@CumpsD
Copy link
Member Author

CumpsD commented Mar 20, 2023

@Aaronontheweb I'm a little bit stuck, if you have some time and could have a look if you find something please?

There are 3 failing tests:
image

The rest are ok:
image

If you debug at src\Akka.Persistence.Sql\Db\AkkaPersistenceDataConnectionFactory.cs inside the HasConversion funcs (you can temporarly use HasConversionFunc if the breakpoints don't get hit), you will see the DateTime gets converted into Ticks when the test prepares its snapshot data and writes it to MS Sqlite.

if (config.ProviderName.ToLower().Contains("sqlite") ||
    config.ProviderName.ToLower().Contains("postgresql"))
{
    builder
        .Member(r => r.Created)
        .HasDataType(DataType.Int64)
        .HasConversion(
            r => r.Ticks,
            r => new DateTime(r));
}

However, when it tries to read them, it fails with:

Got a message of the expected type <Akka.Persistence.LoadSnapshotResult>. Also expected the predicate to return true but the message {LoadSnapshotResult<toSeqNr: 9223372036854775807, snapshot: >} of type <Akka.Persistence.LoadSnapshotResult> did not match
Expected: True
Actual:   False
   at Akka.TestKit.Xunit2.XunitAssertions.AssertTrue(Boolean condition, String format, Object[] args)
   at Akka.TestKit.TestKitBase.AssertPredicateIsTrueForMessage[T](Predicate`1 isMessage, T m, String hint)
   at Akka.TestKit.TestKitBase.<>c__DisplayClass121_0`1.<ExpectMsgAsync>b__0(T m, IActorRef sender)
   at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelopeAsync[T](Nullable`1 timeout, Action`2 assert, String hint, CancellationToken cancellationToken, Boolean shouldLog)
   at Akka.TestKit.TestKitBase.InternalExpectMsgAsync[T](Nullable`1 timeout, Action`2 assert, String hint, CancellationToken cancellationToken)
   at Akka.TestKit.TestKitBase.ExpectMsgAsync[T](Predicate`1 isMessage, Nullable`1 timeout, String hint, CancellationToken cancellationToken)
   at Akka.TestKit.TestKitBase.ExpectMsg[T](Predicate`1 isMessage, Nullable`1 timeout, String hint, CancellationToken cancellationToken)
   at Akka.Persistence.TCK.Snapshot.SnapshotStoreSpec.SnapshotStore_should_delete_all_snapshots_matching_upper_sequence_number_and_timestamp_bounds()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

If you debug src\Akka.Persistence.Sql\Snapshot\ByteArraySnapshotDao.cs at SnapshotForMaxSequenceNrAndMaxTimestamp you will see the values being passed into it are fine, however the FirstOrDefaultAsync returns null, even though the row is there:

image

I currently have no idea yet why this is happening. I was trying to find a way to debug the exact query being sent to Sqlite, maybe it doesn't convert the timestamp parameter to ticks properly?

@CumpsD
Copy link
Member Author

CumpsD commented Mar 20, 2023

Of course, by typing out my problem I get a step closer to the answer :) I managed to find the query it sends to the database:

SELECT
	[r].[persistence_id],
	[r].[sequence_number],
	[r].[created],
	[r].[snapshot],
	[r].[manifest],
	[r].[serializer_id]
FROM
	[snapshot] [r]
WHERE
	[r].[persistence_id] = @persistenceId AND [r].[sequence_number] <= @sequenceNr AND
	DateTime([r].[created]) <= DateTime(@timestamp_1)
ORDER BY
	[r].[sequence_number] DESC
LIMIT @take

That DateTime([r].[created]) <= DateTime(@timestamp_1) is probably the problem, I'll try to figure out why it does that and not simply does the comparison with ticks.

@Arkatufus
Copy link
Contributor

@CumpsD I'll look into it

@CumpsD
Copy link
Member Author

CumpsD commented Mar 20, 2023

Just checked with the dev branch, the query there is:

SELECT
	[r].[persistence_id],
	[r].[sequence_number],
	[r].[created],
	[r].[snapshot],
	[r].[manifest],
	[r].[serializer_id]
FROM
	[snapshot] [r]
WHERE
	[r].[persistence_id] = @persistenceId AND [r].[sequence_number] <= @sequenceNr AND
	[r].[created] <= @timestamp_1
ORDER BY
	[r].[sequence_number] DESC
LIMIT @take

I'll have a look at linq2db, I'm guessing something changed in the breaking changes from 3->5. I've read all the release notes though, guess I missed something

@CumpsD
Copy link
Member Author

CumpsD commented Mar 20, 2023

Upgrading linq2db to 3.7.0 already changed it to

SELECT
	[r].[persistence_id],
	[r].[sequence_number],
	[r].[created],
	[r].[snapshot],
	[r].[manifest],
	[r].[serializer_id]
FROM
	[snapshot] [r]
WHERE
	[r].[persistence_id] = @persistenceId AND [r].[sequence_number] <= @sequenceNr AND
	DateTime([r].[created]) <= DateTime(@timestamp_1)
ORDER BY
	[r].[sequence_number] DESC
LIMIT @take

So not even in the breaking changes ;) I will look further as to where it happened

@CumpsD
Copy link
Member Author

CumpsD commented Mar 20, 2023

3.5.2 is the last version the test succeeds.

3.6.0 broke it
Release notes: https://github.com/linq2db/linq2db/wiki/Release-Notes-3.0.0#release-360
PR: linq2db/linq2db#3343

I'll have a look at what changed, also asked it in their repo: linq2db/linq2db#3343 (comment)

@CumpsD
Copy link
Member Author

CumpsD commented Mar 20, 2023

Another tidbit of information: linq2db/linq2db#2432
Wrapping with DateTime() got added via linq2db/linq2db#478 at linq2db/linq2db@9f6d92c#diff-311134ff10546110237f8b2ee7c7fd039c27a57a2fccacf819266612e02363a1R133

@CumpsD CumpsD marked this pull request as ready for review March 21, 2023 06:49
@CumpsD
Copy link
Member Author

CumpsD commented Mar 21, 2023

For some reason, the azure checks don't run anymore

@Aaronontheweb
Copy link
Member

Aaronontheweb commented Mar 21, 2023 via email

@CumpsD
Copy link
Member Author

CumpsD commented Mar 21, 2023

@Arkatufus @Aaronontheweb it's ready for review now, the pipelines are fixed and ran everything succesfully.

Upgrading Linq2db will be in a different PR since it has more impact, and is harder to upgrade (see above)

@CumpsD CumpsD mentioned this pull request Mar 21, 2023
Copy link
Member

@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.

LGTM

@Aaronontheweb Aaronontheweb merged commit 73aa93c into akkadotnet:dev Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants