Skip to content

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Jun 29, 2023

Changes

Fixes #191

Checklist

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

@Aaronontheweb Aaronontheweb marked this pull request as ready for review June 29, 2023 20:29
@Aaronontheweb Aaronontheweb requested a review from Arkatufus June 29, 2023 20:29
using (var session = await _journalCollection.Value.Database.Client.StartSessionAsync(sessionOptions/*, cancellationToken*/))
using (var session =
await _journalCollection.Value.Database.Client.StartSessionAsync(
sessionOptions /*, cancellationToken*/))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we pass in a cancellation token here?

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.

Forgot to press submit

```hocon
akka.persistence {
journal {
plugin = "akka.persistence.journal.mongodb"
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated README to include call-timeout settings.

mongoPersistence.JournalSettings.Collection.Should().Be("EventJournal");
mongoPersistence.JournalSettings.MetadataCollection.Should().Be("Metadata");
mongoPersistence.JournalSettings.LegacySerialization.Should().BeFalse();
mongoPersistence.JournalSettings.CallTimeout.Should().Be(10.Seconds());
Copy link
Member Author

Choose a reason for hiding this comment

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

Validate new settings as part of our normal MongoDbSettingsSpecs.


<PropertyGroup>
<TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks>
<LangVersion>latest</LangVersion>
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this in order to support using statements, which I ended up not even needing in most cases.

/// <summary>
/// Used to cancel all outstanding commands when the actor is stopped.
/// </summary>
private readonly CancellationTokenSource _pendingCommandsCancellation = new();
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to what we do in Akka.Persistence.Sql.Common - have a global CTS for aborting all in-process operations when the Journal shuts down. This same architecture is mirrored in the SnapshotStore as well.

.IndexKeys
.Ascending(entry => entry.PersistenceId)
.Descending(entry => entry.SequenceNr));
var (perCallCts, unitedCts) = CreatePerCalLCts();
Copy link
Member Author

Choose a reason for hiding this comment

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

Helper method to create a per-call CTS that is also linked to the global "operation CTS" is created here. We wrap both CTS in a using statement so they're safely disposed of afterwards.

/// <summary>
/// Used to cancel all outstanding commands when the actor is stopped.
/// </summary>
private readonly CancellationTokenSource _pendingCommandsCancellation = new();
Copy link
Member Author

Choose a reason for hiding this comment

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

Identical to what we did in journal

_serialization = Context.System.Serialization;
}

private (CancellationTokenSource perCallCts, CancellationTokenSource untiedCts) CreatePerCalLCts()
Copy link
Member Author

Choose a reason for hiding this comment

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

Identical to what we did in journal

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.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to add CancellationToken support to all MongoClient calls
2 participants