diff options
author | Jason Rassi <rassi@10gen.com> | 2015-07-16 14:49:44 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-07-16 18:26:08 -0400 |
commit | e4256fb22e7093496859e614ac499e0558e77130 (patch) | |
tree | fdd0284227a483eb5d6c834e719b228970ddbea1 | |
parent | 17816e5251cd9765cca2a30caf60a1aff0fe2538 (diff) | |
download | mongo-e4256fb22e7093496859e614ac499e0558e77130.tar.gz |
SERVER-18766 Convert ClusterClientCursor to an interface
-rw-r--r-- | src/mongo/s/query/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/s/query/async_cluster_client_cursor_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor.h | 29 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor_impl.cpp (renamed from src/mongo/s/query/cluster_client_cursor.cpp) | 14 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_client_cursor_impl.h | 64 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_find.cpp | 4 |
6 files changed, 82 insertions, 33 deletions
diff --git a/src/mongo/s/query/SConscript b/src/mongo/s/query/SConscript index b8c091e9a2a..89ab61a04f3 100644 --- a/src/mongo/s/query/SConscript +++ b/src/mongo/s/query/SConscript @@ -15,7 +15,7 @@ env.Library( env.Library( target="cluster_client_cursor", source=[ - "cluster_client_cursor.cpp", + "cluster_client_cursor_impl.cpp", "async_cluster_client_cursor.cpp", ], LIBDEPS=[ diff --git a/src/mongo/s/query/async_cluster_client_cursor_test.cpp b/src/mongo/s/query/async_cluster_client_cursor_test.cpp index f6b412aacb4..b70480d999c 100644 --- a/src/mongo/s/query/async_cluster_client_cursor_test.cpp +++ b/src/mongo/s/query/async_cluster_client_cursor_test.cpp @@ -28,7 +28,7 @@ #include "mongo/platform/basic.h" -#include "mongo/s/query/cluster_client_cursor.h" +#include "mongo/s/query/async_cluster_client_cursor.h" #include "mongo/db/json.h" #include "mongo/db/query/getmore_response.h" diff --git a/src/mongo/s/query/cluster_client_cursor.h b/src/mongo/s/query/cluster_client_cursor.h index e2ea3a72e59..a0e0db58621 100644 --- a/src/mongo/s/query/cluster_client_cursor.h +++ b/src/mongo/s/query/cluster_client_cursor.h @@ -30,14 +30,13 @@ #include <boost/optional.hpp> -#include "mongo/base/status_with.h" -#include "mongo/executor/task_executor.h" -#include "mongo/s/query/cluster_client_cursor_params.h" -#include "mongo/s/query/async_cluster_client_cursor.h" -#include "mongo/util/net/hostandport.h" +#include "mongo/db/jsobj.h" namespace mongo { +template <typename T> +class StatusWith; + /** * ClusterClientCursor is used to generate results from cursor-generating commands on one or * more remote hosts. A cursor-generating command (e.g. the find command) is one that @@ -52,12 +51,7 @@ namespace mongo { */ class ClusterClientCursor { public: - /** - * Constructs a cluster client cursor. - */ - ClusterClientCursor(executor::TaskExecutor* executor, - const ClusterClientCursorParams& params, - const std::vector<HostAndPort>& remotes); + virtual ~ClusterClientCursor(){}; /** * Returns the next available result document (along with an ok status). May block waiting @@ -68,7 +62,7 @@ public: * * A non-ok status is returned in case of any error. */ - StatusWith<boost::optional<BSONObj>> next(); + virtual StatusWith<boost::optional<BSONObj>> next() = 0; /** * Must be called before destruction to abandon a not-yet-exhausted cursor. If next() has @@ -76,16 +70,7 @@ public: * * May block waiting for responses from remote hosts. */ - void kill(); - -private: - // Not owned here. - executor::TaskExecutor* _executor; - - const ClusterClientCursorParams _params; - - // Does work of scheduling remote work and merging results. - AsyncClusterClientCursor _accc; + virtual void kill() = 0; }; } // namespace mongo diff --git a/src/mongo/s/query/cluster_client_cursor.cpp b/src/mongo/s/query/cluster_client_cursor_impl.cpp index ff0558473b7..c8db908a0e5 100644 --- a/src/mongo/s/query/cluster_client_cursor.cpp +++ b/src/mongo/s/query/cluster_client_cursor_impl.cpp @@ -30,20 +30,20 @@ #include "mongo/platform/basic.h" -#include "mongo/s/query/cluster_client_cursor.h" +#include "mongo/s/query/cluster_client_cursor_impl.h" #include "mongo/util/scopeguard.h" namespace mongo { -ClusterClientCursor::ClusterClientCursor(executor::TaskExecutor* executor, - const ClusterClientCursorParams& params, - const std::vector<HostAndPort>& remotes) +ClusterClientCursorImpl::ClusterClientCursorImpl(executor::TaskExecutor* executor, + const ClusterClientCursorParams& params, + const std::vector<HostAndPort>& remotes) : _executor(executor), _params(params), _accc(executor, params, remotes) {} -StatusWith<boost::optional<BSONObj>> ClusterClientCursor::next() { +StatusWith<boost::optional<BSONObj>> ClusterClientCursorImpl::next() { // On error, kill the underlying ACCC. - ScopeGuard cursorKiller = MakeGuard(&ClusterClientCursor::kill, this); + ScopeGuard cursorKiller = MakeGuard(&ClusterClientCursorImpl::kill, this); while (!_accc.ready()) { auto nextEventStatus = _accc.nextEvent(); @@ -63,7 +63,7 @@ StatusWith<boost::optional<BSONObj>> ClusterClientCursor::next() { return statusWithNext; } -void ClusterClientCursor::kill() { +void ClusterClientCursorImpl::kill() { auto killEvent = _accc.kill(); _executor->waitForEvent(killEvent); } diff --git a/src/mongo/s/query/cluster_client_cursor_impl.h b/src/mongo/s/query/cluster_client_cursor_impl.h new file mode 100644 index 00000000000..ad162e9db2d --- /dev/null +++ b/src/mongo/s/query/cluster_client_cursor_impl.h @@ -0,0 +1,64 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/executor/task_executor.h" +#include "mongo/s/query/async_cluster_client_cursor.h" +#include "mongo/s/query/cluster_client_cursor.h" +#include "mongo/s/query/cluster_client_cursor_params.h" +#include "mongo/util/net/hostandport.h" + +namespace mongo { + +class ClusterClientCursorImpl final : public ClusterClientCursor { + MONGO_DISALLOW_COPYING(ClusterClientCursorImpl); + +public: + /** + * Constructs a cluster client cursor. + */ + ClusterClientCursorImpl(executor::TaskExecutor* executor, + const ClusterClientCursorParams& params, + const std::vector<HostAndPort>& remotes); + + StatusWith<boost::optional<BSONObj>> next() final; + + void kill() final; + +private: + // Not owned here. + executor::TaskExecutor* _executor; + + const ClusterClientCursorParams _params; + + // Does work of scheduling remote work and merging results. + AsyncClusterClientCursor _accc; +}; + +} // namespace mongo diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp index 7e0ceb2e5ea..871ac58f395 100644 --- a/src/mongo/s/query/cluster_find.cpp +++ b/src/mongo/s/query/cluster_find.cpp @@ -43,7 +43,7 @@ #include "mongo/s/client/shard_registry.h" #include "mongo/s/config.h" #include "mongo/s/grid.h" -#include "mongo/s/query/cluster_client_cursor.h" +#include "mongo/s/query/cluster_client_cursor_impl.h" namespace mongo { @@ -94,7 +94,7 @@ StatusWith<CursorId> ClusterFind::runQuery(OperationContext* txn, params.cmdObj = query.getParsed().asFindCommand(); params.sort = query.getParsed().getSort(); - ClusterClientCursor ccc(shardRegistry->getExecutor(), params, remotes); + ClusterClientCursorImpl ccc(shardRegistry->getExecutor(), params, remotes); // TODO: this should implement the batching logic rather than fully exhausting the cursor. It // should allocate a cursor id and save the ClusterClientCursor rather than always returning a |