diff options
author | Jason Carey <jcarey@argv.me> | 2017-08-29 15:34:20 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2017-08-31 16:10:18 -0400 |
commit | c351caa6815218c5b4a9801342ccbb1b050f6aea (patch) | |
tree | ac65b981a61218ff9384a0f68a89d9b3141ea4bb /src/mongo/db/sessions_collection_sharded.cpp | |
parent | ed619087e8dc51eb13578f5ebdd60f8ffee750aa (diff) | |
download | mongo-c351caa6815218c5b4a9801342ccbb1b050f6aea.tar.gz |
SERVER-30805 add LSC::findRemovedSessions()
Implements a findRemovedSessions method for the logical session
collection and impls for the various backends.
Diffstat (limited to 'src/mongo/db/sessions_collection_sharded.cpp')
-rw-r--r-- | src/mongo/db/sessions_collection_sharded.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/mongo/db/sessions_collection_sharded.cpp b/src/mongo/db/sessions_collection_sharded.cpp index 46ad4ce5a21..6c35d317b26 100644 --- a/src/mongo/db/sessions_collection_sharded.cpp +++ b/src/mongo/db/sessions_collection_sharded.cpp @@ -30,8 +30,12 @@ #include "mongo/db/sessions_collection_sharded.h" +#include "mongo/db/matcher/extensions_callback_noop.h" #include "mongo/db/operation_context.h" +#include "mongo/db/query/canonical_query.h" +#include "mongo/db/query/query_request.h" #include "mongo/s/commands/cluster_write.h" +#include "mongo/s/query/cluster_find.h" #include "mongo/s/write_ops/batch_write_exec.h" #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" @@ -93,5 +97,50 @@ Status SessionsCollectionSharded::removeRecords(OperationContext* opCtx, return doRemove(sessions, send); } +StatusWith<LogicalSessionIdSet> SessionsCollectionSharded::findRemovedSessions( + OperationContext* opCtx, const LogicalSessionIdSet& sessions) { + + auto send = [&](BSONObj toSend) -> StatusWith<BSONObj> { + const NamespaceString nss(SessionsCollection::kSessionsFullNS); + + auto qr = QueryRequest::makeFromFindCommand(nss, toSend, false); + if (!qr.isOK()) { + return qr.getStatus(); + } + + const boost::intrusive_ptr<ExpressionContext> expCtx; + auto cq = CanonicalQuery::canonicalize(opCtx, + std::move(qr.getValue()), + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::kAllowAllSpecialFeatures & + ~MatchExpressionParser::AllowedFeatures::kExpr); + if (!cq.isOK()) { + return cq.getStatus(); + } + + // Do the work to generate the first batch of results. This blocks waiting to get responses + // from the shard(s). + std::vector<BSONObj> batch; + BSONObj viewDefinition; + auto cursorId = ClusterFind::runQuery( + opCtx, *cq.getValue(), ReadPreferenceSetting::get(opCtx), &batch, &viewDefinition); + + if (!cursorId.isOK()) { + return cursorId.getStatus(); + } + + BSONObjBuilder result; + CursorResponseBuilder firstBatch(/*firstBatch*/ true, &result); + for (const auto& obj : batch) { + firstBatch.append(obj); + } + firstBatch.done(cursorId.getValue(), nss.ns()); + + return result.obj(); + }; + + return doFetch(sessions, send); +} } // namespace mongo |