Unable to create session after MongoDB migration from version 2.6 to 3.6 while using ReactiveStreams Java driver

Hi,

  HighLevel Problem statement: We are getting the exception “com.mongodb.MongoClientException: Sessions are not supported by the MongoDB” while creating the session from the MongoClient API when using ReactiveStreams MongoDB Java driver version 3.6.0.

  Recently we migrated from MongoDB version 2.6 to 3.6 and We used ReactiveStreams MongoDB Java driver version 3.6.0 to create session out of MongoClient API.
  Creation of session failed with “Sessions are not supported by the MongoDB”.

  However from the mongo shell, we can see the replica set status and in fact was able to execute  db.getMongo().startSession() successfully.
  We tested the same by created a new instance of MongoDB version 3.6 directly and this time MongoClient api was able to create the session with out issues.

  Not sure why session is not getting created while in the migration environment. 
  Is it the issue with the migration? or with the driver?
  Any help on this.

 Java code Snippet:
            MongoClient client;
            ClientSession clientSession = null;
            MongoDatabase mongoDatabase = null;
            MongoCollection<Document> fromCollection = null;
            Builder clientBuilder = null;
            MongoClientSettings settings = null;
            ConnectionString conn = null;
            
            clientBuilder = MongoClientSettings.builder();
            conn = new ConnectionString(clientURI);
            clientBuilder = clientBuilder.applyConnectionString(conn);
            settings = clientBuilder.retryReads(true).readPreference(ReadPreference.primary()).build();

            client = MongoClients.create(settings);

            Publisher<ClientSession> session =  client.startSession(); // fails here
            MongoDBOperationsSubscriber<ClientSession> sub = new
                                    MongoDBOperationsSubscriber<>();
            sub.setCallingMethodName(“ClientSession”);
            session.subscribe(sub);

            if (sub.hasErrors()) {
                sub.cancelSubscription();
                System.out.println(
                        “Error occurred when MongoDBOperationsSubscriber is
          receiving the documents from publisher.“);
                System.out.println(“Error is [ ” + sub.getError().getMessage() +
          ” ].“);
                throw new MongoDBCaptureException(sub.getError().getMessage());
            }
            if(!sub.getData().isEmpty()) {
                clientSession = sub.getData().get(0);
            }
  MongoShell outputs:
rs01:PRIMARY> rs.conf();
                    {
                    “_id” : “rs01",
                    “version” : 25828,
                    “protocolVersion” : NumberLong(1),
                    “members” : [
                      {
                        “_id” : 5,
                        “host” : “mongodb03:27017",
                        “arbiterOnly” : false,
                        “buildIndexes” : true,
                        “hidden” : true,
                        “priority” : 0,
                        “tags” : {

                        },
                        “slaveDelay” : NumberLong(0),
                        “votes” : 1
                      },
                      {
                        “_id” : 8,
                        “host” : “mongodb02:27017",
                        “arbiterOnly” : false,
                        “buildIndexes” : true,
                        “hidden” : true,
                        “priority” : 0,
                        “tags” : {

                        },
                        “slaveDelay” : NumberLong(0),
                        “votes” : 1
                      },
                      {
                        “_id” : 9,
                        “host” : “mongodb04:27017",
                        “arbiterOnly” : false,
                        “buildIndexes” : true,
                        “hidden” : false,
                        “priority” : 4,
                        “tags” : {

                        },
                        “slaveDelay” : NumberLong(0),
                        “votes” : 1
                      },
                      {
                        “_id” : 12,
                        “host” : “mongodb05:27017",
                        “arbiterOnly” : false,
                        “buildIndexes” : true,
                        “hidden” : false,
                        “priority” : 2,
                        “tags” : {

                        },
                        “slaveDelay” : NumberLong(0),
                        “votes” : 1
                      },
                      {
                        “_id” : 13,
                        “host” : “mongodb06:27017",
                        “arbiterOnly” : false,
                        “buildIndexes” : true,
                        “hidden” : false,
                        “priority” : 2,
                        “tags” : {

                        },
                        “slaveDelay” : NumberLong(0),
                        “votes” : 1
                      }
                    ],
                    “settings” : {
                      “chainingAllowed” : true,
                      “heartbeatIntervalMillis” : 2000,
                      “heartbeatTimeoutSecs” : 10,
                      “electionTimeoutMillis” : 10000,
                      “catchUpTimeoutMillis” : 60000,
                      “catchUpTakeoverDelayMillis” : 30000,
                      “getLastErrorModes” : {

                      },
                      “getLastErrorDefaults” : {
                        “w” : 1,
                        “wtimeout” : 0
                      }
                    }
                    }
    MongoDB logs has this message:

{“log”:“2023-03-03T06:44:44.298+0000 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist\n”,“stream”:“stdout”,“time”:“2023-03-03T06:44:44.298265861Z”}

Hi @Anwesh_Kota

Sessions will not be supported by a 3.6 cluster until 3.6 features are configured to be available. Please see the documentation at https://www.mongodb.com/docs/manual/release-notes/3.6-upgrade-replica-set/#enable-backwards-incompatible-features for instructions on how to do that.

If you’ve already done that procedure and sessions still don’t work, please let us know.

1 Like

Hi @Jeffrey_Yemin ,

Thank you, Session issue got resolved.

But our code is still unable to read data/transactions from “oplog”.

Below is the snapshot of reading the “oplog”. The test instance where we directly installed 3.6, the same code works.

Please let us know if there is any additional setting which need to be done for reading the “oplog”.

private void readOplog() {

       Publisher<Document> pubDoc = null;
       MongoDBOperationsSubscriber<Document> sub = null;

       Document filter = new Document();
       filter.put("ns", namespace);
      
       pubDoc = fromCollection.find(clientSession, filter);
       sub = new MongoDBOperationsSubscriber<Document>();
       pubDoc.subscribe(sub);
       try {
           sub.await();
           sub.onComplete();
       } catch (Throwable e) {
           System.out.println(
                   "Read from Start, Error occurred while subscriber is in wait for messages from MongoDB publisher."
                           + e);
       }
       fetchedOplogDocs = sub.getData();
       System.out.println("Total documents fetched so far are [ "+ fetchedOplogDocs.size() +" ].");
 }

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.