diff options
Diffstat (limited to 'src/mongo/s/query')
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor.h | 6 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor_impl.h | 2 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor_mock.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor_mock.h | 2 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_cursor_manager.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_cursor_manager.h | 5 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_find.cpp | 3 |
8 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/s/query/cluster_client_cursor.h b/src/mongo/s/query/cluster_client_cursor.h index a263a77f56e..742d294f107 100644 --- a/src/mongo/s/query/cluster_client_cursor.h +++ b/src/mongo/s/query/cluster_client_cursor.h @@ -30,6 +30,7 @@ #include <boost/optional.hpp> +#include "mongo/client/read_preference.h" #include "mongo/db/auth/user_name.h" #include "mongo/db/jsobj.h" #include "mongo/db/logical_session_id.h" @@ -137,6 +138,11 @@ public: * Returns the logical session id for this cursor. */ virtual boost::optional<LogicalSessionId> getLsid() const = 0; + + /** + * Returns the readPreference for this cursor. + */ + virtual boost::optional<ReadPreferenceSetting> getReadPreference() const = 0; }; } // namespace mongo diff --git a/src/mongo/s/query/cluster_client_cursor_impl.cpp b/src/mongo/s/query/cluster_client_cursor_impl.cpp index 1cad6ef0830..9a2d5de4444 100644 --- a/src/mongo/s/query/cluster_client_cursor_impl.cpp +++ b/src/mongo/s/query/cluster_client_cursor_impl.cpp @@ -146,6 +146,10 @@ boost::optional<LogicalSessionId> ClusterClientCursorImpl::getLsid() const { return _lsid; } +boost::optional<ReadPreferenceSetting> ClusterClientCursorImpl::getReadPreference() const { + return _params.readPreference; +} + namespace { /** diff --git a/src/mongo/s/query/cluster_client_cursor_impl.h b/src/mongo/s/query/cluster_client_cursor_impl.h index f325be6ca4d..67e334a7f47 100644 --- a/src/mongo/s/query/cluster_client_cursor_impl.h +++ b/src/mongo/s/query/cluster_client_cursor_impl.h @@ -113,6 +113,8 @@ public: boost::optional<LogicalSessionId> getLsid() const final; + boost::optional<ReadPreferenceSetting> getReadPreference() const final; + public: /** private for tests */ /** diff --git a/src/mongo/s/query/cluster_client_cursor_mock.cpp b/src/mongo/s/query/cluster_client_cursor_mock.cpp index 4899e0f3056..f2327f861fa 100644 --- a/src/mongo/s/query/cluster_client_cursor_mock.cpp +++ b/src/mongo/s/query/cluster_client_cursor_mock.cpp @@ -115,4 +115,8 @@ boost::optional<LogicalSessionId> ClusterClientCursorMock::getLsid() const { return _lsid; } +boost::optional<ReadPreferenceSetting> ClusterClientCursorMock::getReadPreference() const { + return boost::none; +} + } // namespace mongo diff --git a/src/mongo/s/query/cluster_client_cursor_mock.h b/src/mongo/s/query/cluster_client_cursor_mock.h index 5cc6b2149a8..c63a2654cda 100644 --- a/src/mongo/s/query/cluster_client_cursor_mock.h +++ b/src/mongo/s/query/cluster_client_cursor_mock.h @@ -69,6 +69,8 @@ public: boost::optional<LogicalSessionId> getLsid() const final; + boost::optional<ReadPreferenceSetting> getReadPreference() const final; + /** * Returns true unless marked as having non-exhausted remote cursors via * markRemotesNotExhausted(). diff --git a/src/mongo/s/query/cluster_cursor_manager.cpp b/src/mongo/s/query/cluster_cursor_manager.cpp index ed34635a8fc..fd7927e90ea 100644 --- a/src/mongo/s/query/cluster_cursor_manager.cpp +++ b/src/mongo/s/query/cluster_cursor_manager.cpp @@ -139,6 +139,12 @@ bool ClusterCursorManager::PinnedCursor::isTailableAndAwaitData() const { return _cursor->isTailableAndAwaitData(); } +boost::optional<ReadPreferenceSetting> ClusterCursorManager::PinnedCursor::getReadPreference() + const { + invariant(_cursor); + return _cursor->getReadPreference(); +} + UserNameIterator ClusterCursorManager::PinnedCursor::getAuthenticatedUsers() const { invariant(_cursor); return _cursor->getAuthenticatedUsers(); diff --git a/src/mongo/s/query/cluster_cursor_manager.h b/src/mongo/s/query/cluster_cursor_manager.h index 6bd9e20c3a6..d82e1727e15 100644 --- a/src/mongo/s/query/cluster_cursor_manager.h +++ b/src/mongo/s/query/cluster_cursor_manager.h @@ -206,6 +206,11 @@ public: CursorId getCursorId() const; /** + * Returns the read preference setting for this cursor. + */ + boost::optional<ReadPreferenceSetting> getReadPreference() const; + + /** * Returns the number of result documents returned so far by this cursor via the next() * method. */ diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp index 589917cd46b..ac055b83fd4 100644 --- a/src/mongo/s/query/cluster_find.cpp +++ b/src/mongo/s/query/cluster_find.cpp @@ -422,6 +422,9 @@ StatusWith<CursorResponse> ClusterFind::runGetMore(OperationContext* opCtx, << " was not created by the authenticated user"}; } + if (auto readPref = pinnedCursor.getValue().getReadPreference()) { + ReadPreferenceSetting::get(opCtx) = *readPref; + } if (pinnedCursor.getValue().isTailableAndAwaitData()) { // Default to 1-second timeout for tailable awaitData cursors. If an explicit maxTimeMS has // been specified, do not apply it to the opCtx, since its deadline will already have been |