Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-845

Retry query in the case of network error

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • legacy-1.1.0
    • None
    • None

    Description

      While reading from a replica set and the primary node stepped down, the cursor may return a NULL pointer.

      Example code (legacy driver 1.1.0) :

      mongo::DBClientReplicaSet connection("replicaName", hosts, 0);
          const bool connected = connection.connect();    
       
          for( int i=0; i<1000; ++i)
          {
              mongo::BSONObj query = BSON( "fieldA" << i );
              mongo::Query mQuery = mongo::Query( query );
              mongo::BSONArray bsonTags;
              mQuery.readPref( mongo::ReadPreference_PrimaryPreferred, bsonTags );
              std::auto_ptr<mongo::DBClientCursor> cursor = connection.query( "database.collection",
                                                       mQuery,
                                                       0, 0, 0,
                                                       mongo::QueryOption_SlaveOk, 0 );
              // If there has been an election in the replica set, the cursor could be NULL. 
              if (cursor.get() != NULL){
                  while(cursor->more()){
                      mongo::BSONObj p = cursor->next();
                      std::cout << p.getStringField("fieldB")<< std::endl;
                  }
              }
              else {
                  std::cout<< "cursor is NULL, handle error" <<std::endl;
              }
          }
      

      Attachments

        Activity

          People

            backlog-server-platform DO NOT USE - Backlog - Platform Team
            wan.bachtiar@mongodb.com Wan Bachtiar
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: