workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

MongoDb provider does not support stand-alone servers after v3.6.5

Open brettwinters opened this issue 2 years ago • 3 comments
trafficstars

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)

brettwinters avatar Jan 09 '23 11:01 brettwinters

@glucaci

danielgerlag avatar Jan 26 '23 15:01 danielgerlag

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

glucaci avatar Jan 27 '23 07:01 glucaci

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.

brettwinters avatar Jan 27 '23 08:01 brettwinters