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

About transaction availability #100

Closed
realLiangshiwei opened this issue Sep 9, 2020 · 2 comments · Fixed by #101
Closed

About transaction availability #100

realLiangshiwei opened this issue Sep 9, 2020 · 2 comments · Fixed by #101

Comments

@realLiangshiwei
Copy link
Contributor

realLiangshiwei commented Sep 9, 2020

Mongo2Go is a great library, but we found some problems when using.

The document explains to use single server replica set mode to enable transactions, but after testing I think it is invalid.

Test code is very simple:

var runner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 65535); // max timeout value

var client = new MongoClient(runner.ConnectionString);

using (var session = client.StartSession())
{
    session.StartTransaction();
}

The result:

image

I see that you use the transition to primary complete; database writes are now permitted message to determine whether the transaction is available, but this is not enough.

wrappedProcess.OutputDataReceived += (_, args) => replicaSetReady |= !string.IsNullOrWhiteSpace(args.Data) && args.Data.Contains(ReplicaSetReadyIdentifier);

This is the code for mongo driver to determine whether the transaction is available

https://github.com/mongodb/mongo-csharp-driver/blob/44fff3f7d618ade5eed7a3e874407ecbc231997c/src/MongoDB.Driver.Core/Core/Bindings/CoreSession.cs#L461

I think we can use the same logic

// wait until transaction is ready or until the timeout is reached
SpinWait.SpinUntil(() => client.Cluster.Description.Servers.Where(s => s.State == ServerState.Connected && s.IsDataBearing).Any(), TimeSpan.FromSeconds(singleNodeReplSetWaitTimeout));

Now, it works:

image

What do you think?

@JohannesHoppe
Copy link
Member

👍

JohannesHoppe added a commit that referenced this issue Oct 17, 2020
@JohannesHoppe
Copy link
Member

New version released. Please try out Mongo2Go 2.2.13.

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 a pull request may close this issue.

2 participants