Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1703

Change Session examples to use transactions

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.5
    • Fix Version/s: 1.4.1
    • Component/s: Documentation
    • Security Level: Public
    • Labels:
      None
    • Environment:
      go 1.14 on mac os x

      Description

      Updated Description

      https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#example-Client.UseSessionWithOptions uses the DefaultReadConcern option, which only applies to transactions started within a session, but does not start a transaction. This is confusing, so we should change the example to start a transaction. We should also verify that other sessions-related examples don't do the same thing.

       

      Previous Description 

      Using a session with readpref=Secondary results in queries against the primary.

      Please see the attached test case that demonstrates the issue.

      My setup:

      • Local Replica Set called "ci" with two nodes: port 27017 is the primary, 27016 is the secondary
      • RS config sets the secondary with priority=0 so it doesn't become primary
      • I use toxiproxy to artificially add latency from primary to secondary. This isn't necessary, but makes the test more reliably reproducible.

      Debugging FindOne() it seems like the read preference setting for the session is ignored if not inside a transaction. Setting the read preference on the Collection makes the test pass.

      I'm roughly following the example from https://godoc.org/go.mongodb.org/mongo-driver/mongo#Client.UseSession . Am I using the API incorrectly?

        Attachments

          Activity

            People

            Assignee:
            divjot.arora Divjot Arora
            Reporter:
            dv@glyphy.com D V
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: