Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1944

Getting error when reading from secondary nodes with async driver

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.3
    • Component/s: Async
    • None
    • Environment:
      Ubuntu 14.04, Java 8, Vertx

      When i use the async driver and connect to a replica set (3 nodes), i get most of the time (66%+) and error:

      com.mongodb.MongoNotPrimaryException: The server is not the primary and did not execute the operation

      final MongoClientSettings clientSettings = MongoClientSettings.builder()
              .codecRegistry(CodecRegistries.fromRegistries(
                      CodecRegistries.fromProviders(asList(new ValueCodecProvider(), new DocumentCodecProvider(), new BsonValueCodecProvider())),
                      new VertxCodecRegistry()
              ))
              .clusterSettings(ClusterSettings.builder()
                      .hosts(Lists.newArrayList(new ServerAddress(host, port)))
                      .build())
              .readPreference(ReadPreference.nearest())                
              .build();
      
      mongoClient = MongoClients.create(clientSettings);
      
      FindIterable<JsonObject> find = mongoDatabase.getCollection(collectionName)
              .find(BsonDocument.parse(matcher.encode()), JsonObject.class);
      
      if (projection != null && !projection.isEmpty()) {
          find = find.projection(BsonDocument.parse(projection.encode()));
      }
      
      if (page != null && !page.isEmpty()) {
          find.limit(page.getInteger("limit", 10));
          find.skip(page.getInteger("offset", 0));
      }
      
      find.into(new ArrayList<>(), (List<JsonObject> elements, Throwable error) -> {
          if (error != null) {
              LOG.warning("Could not execute query: " + matcher);
              message.fail(500, error.getMessage());
          } else {
              message.reply(new JsonArray(elements));
          }
      });
      

      If i use the sync driver or change the read preferences to primary everthing works fine. I suppose it is a bug?

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            j_muecke Jonas Mücke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: