workflow-core
workflow-core copied to clipboard
MongoDb provider does not support stand-alone servers after v3.6.5
Hi @viktorshevchenko210
After #1079 is merged (release v3.7.0) WorkflowCore.Persistence.MongoDB does not allow stand alone MongoDb servers due to addition of transaction support.
Issue in this file : workflow-core/src/providers/WorkflowCore.Persistence.MongoDB/Services/MongoPersistenceProvider.cs for method public async Task PersistWorkflow(WorkflowInstance workflow, List<EventSubscription> subscriptions, CancellationToken cancellationToken = default)
Reproduce:
Persist workflow which contains more than one subscriptions so that if (subscriptions == null || subscriptions.Count < 1) is not true.
Result
The line session.StartTransaction() in below method throws:
public async Task PersistWorkflow(WorkflowInstance workflow, List<EventSubscription> subscriptions, CancellationToken cancellationToken = default)
{
if (subscriptions == null || subscriptions.Count < 1)
{
await PersistWorkflow(workflow, cancellationToken);
return;
}
using (var session = await _database.Client.StartSessionAsync(cancellationToken: cancellationToken))
{
session.StartTransaction(); //<---- this throws
await PersistWorkflow(workflow, cancellationToken);
await EventSubscriptions.InsertManyAsync(subscriptions, cancellationToken: cancellationToken);
await session.CommitTransactionAsync(cancellationToken);
}
}
The exception:
System.NotSupportedException: Standalone servers do not support transactions.
at MongoDB.Driver.Core.Bindings.CoreSession.EnsureTransactionsAreSupported()
at MongoDB.Driver.Core.Bindings.CoreSession.EnsureStartTransactionCanBeCalled()
at MongoDB.Driver.Core.Bindings.CoreSession.StartTransaction(TransactionOptions transactionOptions)
at MongoDB.Driver.Core.Bindings.WrappingCoreSession.StartTransaction(TransactionOptions transactionOptions)
at MongoDB.Driver.Core.Bindings.WrappingCoreSession.StartTransaction(TransactionOptions transactionOptions)
at MongoDB.Driver.ClientSessionHandle.StartTransaction(TransactionOptions transactionOptions)
@glucaci
You can convert your standalone server to a replica set. how-to
Also if you need it in tests please take a look to the WorkflowCore.Tests.MongoDB
Yeah that's what I did for my local MongoDB instance for testing. I guess leave it as it is and maybe add a comment in the docs that you'll need a cluster or replica set for working-core to work on MongoDB.