private boolean isSlaveOk() { return (readPreference != null && readPreference.isSlaveOk()) || isDirectConnectionToNonShardRouter(); }
private ReadPreference getReadPreferenceForCursor() { ReadPreference readPreference = getReadPreference(); if ((options & Bytes.QUERYOPTION_SLAVEOK) != 0 && !readPreference.isSlaveOk()) { readPreference = ReadPreference.secondaryPreferred(); } return readPreference; }
connection.queryAsync(getIndexNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, decoder, new SingleResultCallback<QueryResult<T>>() { @Override
@Override public BsonDocument call(final Connection connection) { if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { return executeWrappedCommandProtocol(binding, "admin", new BsonDocument("currentOp", new BsonInt32(1)), connection); } else { return connection.query(new MongoNamespace("admin", "$cmd.sys.inprog"), new BsonDocument(), null, 0, 1, 0, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec()) .getResults().get(0); } } });
} else { connection.queryAsync(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec(), new SingleResultCallback<QueryResult<BsonDocument>>() { @Override
@Override public BatchCursor<T> call(final ConnectionSource source, final Connection connection) { if (serverIsAtLeastVersionThreeDotZero(connection.getDescription())) { try { return executeWrappedCommandProtocol(binding, databaseName, getCommand(), createCommandDecoder(), connection, commandTransformer(source)); } catch (MongoCommandException e) { return rethrowIfNotNamespaceError(e, createEmptyBatchCursor(createNamespace(), decoder, source.getServerDescription().getAddress(), batchSize)); } } else { return new ProjectingBatchCursor(new QueryBatchCursor<BsonDocument>(connection.query(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec()), 0, batchSize, new BsonDocumentCodec(), source)); } } });
limit, batchSize, isSlaveOk() || binding.getReadPreference().isSlaveOk(), isTailableCursor(), isAwaitData(),
@SuppressWarnings("deprecation") private <TResult> FindOperation<TResult> createFindOperation(final MongoNamespace findNamespace, final Bson filter, final Class<TResult> resultClass, final FindOptions options) { return new FindOperation<TResult>(findNamespace, codecRegistry.get(resultClass)) .filter(filter == null ? new BsonDocument() : filter.toBsonDocument(documentClass, codecRegistry)) .batchSize(options.getBatchSize()) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .maxAwaitTime(options.getMaxAwaitTime(MILLISECONDS), MILLISECONDS) .modifiers(toBsonDocumentOrNull(options.getModifiers())) .projection(toBsonDocumentOrNull(options.getProjection())) .sort(toBsonDocumentOrNull(options.getSort())) .cursorType(options.getCursorType()) .noCursorTimeout(options.isNoCursorTimeout()) .oplogReplay(options.isOplogReplay()) .partial(options.isPartial()) .slaveOk(readPreference.isSlaveOk()) .collation(options.getCollation()) .comment(options.getComment()) .hint(toBsonDocumentOrNull(options.getHint())) .min(toBsonDocumentOrNull(options.getMin())) .max(toBsonDocumentOrNull(options.getMax())) .maxScan(options.getMaxScan()) .returnKey(options.isReturnKey()) .showRecordId(options.isShowRecordId()) .snapshot(options.isSnapshot()); }
private boolean isSlaveOk() { return (readPreference != null && readPreference.isSlaveOk()) || isDirectConnectionToNonShardRouter(); }
private ReadPreference getReadPreferenceForCursor() { ReadPreference readPreference = getReadPreference(); if ((options & Bytes.QUERYOPTION_SLAVEOK) != 0 && !readPreference.isSlaveOk()) { readPreference = ReadPreference.secondaryPreferred(); } return readPreference; }
connection.queryAsync(getIndexNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, decoder, new SingleResultCallback<QueryResult<T>>() { @Override
MongoCollection<BasicDBObject> dbCollection = getDBCollection(collection, readPreference); if(readPreference.isSlaveOk()){ LOG.trace("Routing call to secondary for fetching [{}]", key); isSlaveOk = true;
MongoCollection<BasicDBObject> dbCollection = getDBCollection(collection, readPreference); if(readPreference.isSlaveOk()){ LOG.trace("Routing call to secondary for fetching [{}]", key); isSlaveOk = true;
@Override public BsonDocument call(final Connection connection) { if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) { return executeWrappedCommandProtocol(binding, "admin", new BsonDocument("currentOp", new BsonInt32(1)), connection); } else { return connection.query(new MongoNamespace("admin", "$cmd.sys.inprog"), new BsonDocument(), null, 0, 1, 0, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec()) .getResults().get(0); } } });
getMongoReadPreference(collection, parentId, getDefaultReadPreference(collection)); if(readPreference.isSlaveOk()){ isSlaveOk = true; LOG.trace("Routing call to secondary for fetching children from [{}] to [{}]", fromKey, toKey);
getMongoReadPreference(collection, parentId, getDefaultReadPreference(collection)); if(readPreference.isSlaveOk()){ isSlaveOk = true; LOG.trace("Routing call to secondary for fetching children from [{}] to [{}]", fromKey, toKey);
} else { connection.queryAsync(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec(), new SingleResultCallback<QueryResult<BsonDocument>>() { @Override
@Override public BatchCursor<T> call(final ConnectionSource source, final Connection connection) { if (serverIsAtLeastVersionThreeDotZero(connection.getDescription())) { try { return executeWrappedCommandProtocol(binding, databaseName, getCommand(), createCommandDecoder(), connection, commandTransformer(source)); } catch (MongoCommandException e) { return rethrowIfNotNamespaceError(e, createEmptyBatchCursor(createNamespace(), decoder, source.getServerDescription().getAddress(), batchSize)); } } else { return new ProjectingBatchCursor(new QueryBatchCursor<BsonDocument>(connection.query(getNamespace(), asQueryDocument(connection.getDescription(), binding.getReadPreference()), null, 0, 0, batchSize, binding.getReadPreference().isSlaveOk(), false, false, false, false, false, new BsonDocumentCodec()), 0, batchSize, new BsonDocumentCodec(), source)); } } });
limit, batchSize, isSlaveOk() || binding.getReadPreference().isSlaveOk(), isTailableCursor(), isAwaitData(),
@SuppressWarnings("deprecation") private <TResult> FindOperation<TResult> createFindOperation(final MongoNamespace findNamespace, final Bson filter, final Class<TResult> resultClass, final FindOptions options) { return new FindOperation<TResult>(findNamespace, codecRegistry.get(resultClass)) .filter(filter == null ? new BsonDocument() : filter.toBsonDocument(documentClass, codecRegistry)) .batchSize(options.getBatchSize()) .skip(options.getSkip()) .limit(options.getLimit()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .maxAwaitTime(options.getMaxAwaitTime(MILLISECONDS), MILLISECONDS) .modifiers(toBsonDocumentOrNull(options.getModifiers())) .projection(toBsonDocumentOrNull(options.getProjection())) .sort(toBsonDocumentOrNull(options.getSort())) .cursorType(options.getCursorType()) .noCursorTimeout(options.isNoCursorTimeout()) .oplogReplay(options.isOplogReplay()) .partial(options.isPartial()) .slaveOk(readPreference.isSlaveOk()) .collation(options.getCollation()) .comment(options.getComment()) .hint(toBsonDocumentOrNull(options.getHint())) .min(toBsonDocumentOrNull(options.getMin())) .max(toBsonDocumentOrNull(options.getMax())) .maxScan(options.getMaxScan()) .returnKey(options.isReturnKey()) .showRecordId(options.isShowRecordId()) .snapshot(options.isSnapshot()); }