summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2018-09-24 16:27:58 -0400
committerTed Tuckman <ted.tuckman@mongodb.com>2018-10-04 11:22:05 -0400
commitc589abf31b748d0f13e710d8d59394b65ab6891d (patch)
tree637288a6b560f8906bc0dd6ff3bf1b55eb709b79 /src/mongo/s
parentf9436146f64ad7caa2ce525c1d75a85f918d68c0 (diff)
downloadmongo-c589abf31b748d0f13e710d8d59394b65ab6891d.tar.gz
SERVER-37005 Add fields to GenericCursor
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/query/cluster_client_cursor.h25
-rw-r--r--src/mongo/s/query/cluster_client_cursor_impl.cpp31
-rw-r--r--src/mongo/s/query/cluster_client_cursor_impl.h19
-rw-r--r--src/mongo/s/query/cluster_client_cursor_mock.cpp20
-rw-r--r--src/mongo/s/query/cluster_client_cursor_mock.h16
-rw-r--r--src/mongo/s/query/cluster_cursor_manager.cpp31
-rw-r--r--src/mongo/s/query/cluster_cursor_manager.h25
-rw-r--r--src/mongo/s/query/cluster_find.cpp2
8 files changed, 166 insertions, 3 deletions
diff --git a/src/mongo/s/query/cluster_client_cursor.h b/src/mongo/s/query/cluster_client_cursor.h
index 5ad4ec4298f..8e993d7a737 100644
--- a/src/mongo/s/query/cluster_client_cursor.h
+++ b/src/mongo/s/query/cluster_client_cursor.h
@@ -160,6 +160,31 @@ public:
*/
virtual boost::optional<ReadPreferenceSetting> getReadPreference() const = 0;
+ /**
+ * Returns the creation date of the cursor.
+ */
+ virtual Date_t getCreatedDate() const = 0;
+
+ /**
+ * Returns the date the cursor was last used.
+ */
+ virtual Date_t getLastUseDate() const = 0;
+
+ /**
+ * Set the last use date to the provided time.
+ */
+ virtual void setLastUseDate(Date_t now) = 0;
+
+ /**
+ * Returns the number of batches returned by this cursor.
+ */
+ virtual std::uint64_t getNBatches() const = 0;
+
+ /**
+ * Increment the number of batches returned so far by one.
+ */
+ virtual void incNBatches() = 0;
+
//
// maxTimeMS support.
//
diff --git a/src/mongo/s/query/cluster_client_cursor_impl.cpp b/src/mongo/s/query/cluster_client_cursor_impl.cpp
index acda45f66f0..e58bbd1accc 100644
--- a/src/mongo/s/query/cluster_client_cursor_impl.cpp
+++ b/src/mongo/s/query/cluster_client_cursor_impl.cpp
@@ -79,7 +79,9 @@ ClusterClientCursorImpl::ClusterClientCursorImpl(OperationContext* opCtx,
: _params(std::move(params)),
_root(buildMergerPlan(opCtx, executor, &_params)),
_lsid(lsid),
- _opCtx(opCtx) {
+ _opCtx(opCtx),
+ _createdDate(opCtx->getServiceContext()->getPreciseClockSource()->now()),
+ _lastUseDate(_createdDate) {
dassert(!_params.compareWholeSortKey ||
SimpleBSONObjComparator::kInstance.evaluate(
_params.sort == AsyncResultsMerger::kWholeSortKeySortPattern));
@@ -89,7 +91,12 @@ ClusterClientCursorImpl::ClusterClientCursorImpl(OperationContext* opCtx,
std::unique_ptr<RouterExecStage> root,
ClusterClientCursorParams&& params,
boost::optional<LogicalSessionId> lsid)
- : _params(std::move(params)), _root(std::move(root)), _lsid(lsid), _opCtx(opCtx) {
+ : _params(std::move(params)),
+ _root(std::move(root)),
+ _lsid(lsid),
+ _opCtx(opCtx),
+ _createdDate(opCtx->getServiceContext()->getPreciseClockSource()->now()),
+ _lastUseDate(_createdDate) {
dassert(!_params.compareWholeSortKey ||
SimpleBSONObjComparator::kInstance.evaluate(
_params.sort == AsyncResultsMerger::kWholeSortKeySortPattern));
@@ -181,6 +188,26 @@ boost::optional<TxnNumber> ClusterClientCursorImpl::getTxnNumber() const {
return _params.txnNumber;
}
+Date_t ClusterClientCursorImpl::getCreatedDate() const {
+ return _createdDate;
+}
+
+Date_t ClusterClientCursorImpl::getLastUseDate() const {
+ return _lastUseDate;
+}
+
+void ClusterClientCursorImpl::setLastUseDate(Date_t now) {
+ _lastUseDate = std::move(now);
+}
+
+std::uint64_t ClusterClientCursorImpl::getNBatches() const {
+ return _nBatchesReturned;
+}
+
+void ClusterClientCursorImpl::incNBatches() {
+ ++_nBatchesReturned;
+}
+
boost::optional<ReadPreferenceSetting> ClusterClientCursorImpl::getReadPreference() const {
return _params.readPreference;
}
diff --git a/src/mongo/s/query/cluster_client_cursor_impl.h b/src/mongo/s/query/cluster_client_cursor_impl.h
index 04e97cad3d9..b1d8908eea1 100644
--- a/src/mongo/s/query/cluster_client_cursor_impl.h
+++ b/src/mongo/s/query/cluster_client_cursor_impl.h
@@ -130,6 +130,16 @@ public:
boost::optional<ReadPreferenceSetting> getReadPreference() const final;
+ Date_t getCreatedDate() const final;
+
+ Date_t getLastUseDate() const final;
+
+ void setLastUseDate(Date_t now) final;
+
+ std::uint64_t getNBatches() const final;
+
+ void incNBatches() final;
+
public:
/**
* Constructs a CCC whose result set is generated by a mock execution stage.
@@ -172,6 +182,15 @@ private:
// The OperationContext that we're executing within. This can be updated if necessary by using
// detachFromOperationContext() and reattachToOperationContext().
OperationContext* _opCtx = nullptr;
+
+ // The time the cursor was created.
+ Date_t _createdDate;
+
+ // The time when the cursor was last unpinned, i.e. the end of the last getMore.
+ Date_t _lastUseDate;
+
+ // The number of batches returned by this cursor.
+ std::uint64_t _nBatchesReturned = 0;
};
} // namespace mongo
diff --git a/src/mongo/s/query/cluster_client_cursor_mock.cpp b/src/mongo/s/query/cluster_client_cursor_mock.cpp
index 616d48d275c..6649cee9494 100644
--- a/src/mongo/s/query/cluster_client_cursor_mock.cpp
+++ b/src/mongo/s/query/cluster_client_cursor_mock.cpp
@@ -77,6 +77,26 @@ long long ClusterClientCursorMock::getNumReturnedSoFar() const {
return _numReturnedSoFar;
}
+std::uint64_t ClusterClientCursorMock::getNBatches() const {
+ return _nBatchesReturned;
+}
+
+void ClusterClientCursorMock::incNBatches() {
+ ++_nBatchesReturned;
+}
+
+Date_t ClusterClientCursorMock::getCreatedDate() const {
+ return _createdDate;
+}
+
+Date_t ClusterClientCursorMock::getLastUseDate() const {
+ return _lastUseDate;
+}
+
+void ClusterClientCursorMock::setLastUseDate(Date_t now) {
+ _lastUseDate = std::move(now);
+}
+
void ClusterClientCursorMock::kill(OperationContext* opCtx) {
_killed = true;
if (_killCallback) {
diff --git a/src/mongo/s/query/cluster_client_cursor_mock.h b/src/mongo/s/query/cluster_client_cursor_mock.h
index f5b1464b94b..6c5806cc9c2 100644
--- a/src/mongo/s/query/cluster_client_cursor_mock.h
+++ b/src/mongo/s/query/cluster_client_cursor_mock.h
@@ -84,6 +84,16 @@ public:
boost::optional<ReadPreferenceSetting> getReadPreference() const final;
+ Date_t getCreatedDate() const final;
+
+ Date_t getLastUseDate() const final;
+
+ void setLastUseDate(Date_t now) final;
+
+ std::uint64_t getNBatches() const final;
+
+ void incNBatches() final;
+
/**
* Returns true unless marked as having non-exhausted remote cursors via
* markRemotesNotExhausted().
@@ -116,6 +126,12 @@ private:
boost::optional<TxnNumber> _txnNumber;
OperationContext* _opCtx = nullptr;
+
+ Date_t _createdDate;
+
+ Date_t _lastUseDate;
+
+ std::uint64_t _nBatchesReturned = 0;
};
} // namespace mongo
diff --git a/src/mongo/s/query/cluster_cursor_manager.cpp b/src/mongo/s/query/cluster_cursor_manager.cpp
index 4964991e8bb..37ed6216dd9 100644
--- a/src/mongo/s/query/cluster_cursor_manager.cpp
+++ b/src/mongo/s/query/cluster_cursor_manager.cpp
@@ -161,6 +161,29 @@ long long ClusterCursorManager::PinnedCursor::getNumReturnedSoFar() const {
return _cursor->getNumReturnedSoFar();
}
+Date_t ClusterCursorManager::PinnedCursor::getLastUseDate() const {
+ invariant(_cursor);
+ return _cursor->getLastUseDate();
+}
+
+void ClusterCursorManager::PinnedCursor::setLastUseDate(Date_t now) {
+ invariant(_cursor);
+ _cursor->setLastUseDate(now);
+}
+Date_t ClusterCursorManager::PinnedCursor::getCreatedDate() const {
+ invariant(_cursor);
+ return _cursor->getCreatedDate();
+}
+void ClusterCursorManager::PinnedCursor::incNBatches() {
+ invariant(_cursor);
+ return _cursor->incNBatches();
+}
+
+long long ClusterCursorManager::PinnedCursor::getNBatches() const {
+ invariant(_cursor);
+ return _cursor->getNBatches();
+}
+
void ClusterCursorManager::PinnedCursor::queueResult(const ClusterQueryResult& result) {
invariant(_cursor);
_cursor->queueResult(result);
@@ -180,6 +203,9 @@ GenericCursor ClusterCursorManager::PinnedCursor::toGenericCursor() const {
gc.setTailable(isTailable());
gc.setAwaitData(isTailableAndAwaitData());
gc.setOriginatingCommand(getOriginatingCommand());
+ gc.setLastAccessDate(getLastUseDate());
+ gc.setCreatedDate(getCreatedDate());
+ gc.setNBatchesReturned(getNBatches());
return gc;
}
@@ -342,7 +368,6 @@ StatusWith<ClusterCursorManager::PinnedCursor> ClusterCursorManager::checkOutCur
return vivifyCursorStatus;
}
}
-
cursor->reattachToOperationContext(opCtx);
return PinnedCursor(this, std::move(cursor), nss, cursorId);
}
@@ -359,6 +384,7 @@ void ClusterCursorManager::checkInCursor(std::unique_ptr<ClusterClientCursor> cu
OperationContext* opCtx = cursor->getCurrentOperationContext();
invariant(opCtx);
cursor->detachFromOperationContext();
+ cursor->setLastUseDate(now);
stdx::unique_lock<stdx::mutex> lk(_mutex);
@@ -590,12 +616,15 @@ GenericCursor ClusterCursorManager::CursorEntry::cursorToGenericCursor(
GenericCursor gc;
gc.setCursorId(cursorId);
gc.setNs(ns);
+ gc.setCreatedDate(_cursor->getCreatedDate());
+ gc.setLastAccessDate(_cursor->getLastUseDate());
gc.setLsid(_cursor->getLsid());
gc.setNDocsReturned(_cursor->getNumReturnedSoFar());
gc.setTailable(_cursor->isTailable());
gc.setAwaitData(_cursor->isTailableAndAwaitData());
gc.setOriginatingCommand(_cursor->getOriginatingCommand());
gc.setNoCursorTimeout(getLifetimeType() == CursorLifetime::Immortal);
+ gc.setNBatchesReturned(_cursor->getNBatches());
return gc;
}
diff --git a/src/mongo/s/query/cluster_cursor_manager.h b/src/mongo/s/query/cluster_cursor_manager.h
index 6c1b0d10c92..f74e8a4ba97 100644
--- a/src/mongo/s/query/cluster_cursor_manager.h
+++ b/src/mongo/s/query/cluster_cursor_manager.h
@@ -213,6 +213,31 @@ public:
long long getNumReturnedSoFar() const;
/**
+ * Returns the creation date of the cursor.
+ */
+ Date_t getCreatedDate() const;
+
+ /**
+ * Returns the time the cursor was last used.
+ */
+ Date_t getLastUseDate() const;
+
+ /**
+ * Set the cursor's lastUseDate to the given time.
+ */
+ void setLastUseDate(Date_t now);
+
+ /**
+ * Increment the number of batches returned by this cursor.
+ */
+ void incNBatches();
+
+ /**
+ * Get the number of batches returned by this cursor.
+ */
+ long long getNBatches() const;
+
+ /**
* Returns a GenericCursor version of the pinned cursor.
*/
GenericCursor toGenericCursor() const;
diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp
index a805ad35078..50f99690d84 100644
--- a/src/mongo/s/query/cluster_find.cpp
+++ b/src/mongo/s/query/cluster_find.cpp
@@ -361,6 +361,7 @@ CursorId runQueryWithoutRetrying(OperationContext* opCtx,
? ClusterCursorManager::CursorLifetime::Immortal
: ClusterCursorManager::CursorLifetime::Mortal;
auto authUsers = AuthorizationSession::get(opCtx->getClient())->getAuthenticatedUserNames();
+ ccc->incNBatches();
auto cursorId = uassertStatusOK(cursorManager->registerCursor(
opCtx, ccc.releaseCursor(), query.nss(), cursorType, cursorLifetime, authUsers));
@@ -646,6 +647,7 @@ StatusWith<CursorResponse> ClusterFind::runGetMore(OperationContext* opCtx,
}
pinnedCursor.getValue().setLeftoverMaxTimeMicros(opCtx->getRemainingMaxTimeMicros());
+ pinnedCursor.getValue().incNBatches();
// Upon successful completion, transfer ownership of the cursor back to the cursor manager. If
// the cursor has been exhausted, the cursor manager will clean it up for us.
pinnedCursor.getValue().returnCursor(cursorState);