summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/parsed_delete.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-12-02 20:10:01 -0500
committerDavid Storch <david.storch@10gen.com>2014-12-04 17:41:11 -0500
commit367810995073e01ee58159deb1bb5b878882632f (patch)
tree3074960c42a7b63e4e3be337e44f33a036a6679f /src/mongo/db/ops/parsed_delete.cpp
parent5080932a79ce0152535169ec3b42edde2951bdcd (diff)
downloadmongo-367810995073e01ee58159deb1bb5b878882632f.tar.gz
SERVER-16101 replace DeleteExecutor with ParsedDelete
Diffstat (limited to 'src/mongo/db/ops/parsed_delete.cpp')
-rw-r--r--src/mongo/db/ops/parsed_delete.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/mongo/db/ops/parsed_delete.cpp b/src/mongo/db/ops/parsed_delete.cpp
new file mode 100644
index 00000000000..da1b2c77a25
--- /dev/null
+++ b/src/mongo/db/ops/parsed_delete.cpp
@@ -0,0 +1,104 @@
+/**
+ * Copyright (C) 2014 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.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kWrite
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/ops/parsed_delete.h"
+
+#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/database.h"
+#include "mongo/db/exec/delete.h"
+#include "mongo/db/ops/delete_request.h"
+#include "mongo/db/query/canonical_query.h"
+#include "mongo/db/query/get_executor.h"
+#include "mongo/db/query/query_planner_common.h"
+#include "mongo/db/repl/repl_coordinator_global.h"
+#include "mongo/util/assert_util.h"
+#include "mongo/util/log.h"
+#include "mongo/util/mongoutils/str.h"
+
+namespace mongo {
+
+ ParsedDelete::ParsedDelete(OperationContext* txn, const DeleteRequest* request) :
+ _txn(txn),
+ _request(request) { }
+
+ Status ParsedDelete::parseRequest() {
+ dassert(!_canonicalQuery.get());
+
+ if (CanonicalQuery::isSimpleIdQuery(_request->getQuery())) {
+ return Status::OK();
+ }
+
+ return parseQueryToCQ();
+ }
+
+ Status ParsedDelete::parseQueryToCQ() {
+ dassert(!_canonicalQuery.get());
+
+ CanonicalQuery* cqRaw;
+ const WhereCallbackReal whereCallback(_txn, _request->getNamespaceString().db());
+
+ Status status = CanonicalQuery::canonicalize(_request->getNamespaceString().ns(),
+ _request->getQuery(),
+ _request->isExplain(),
+ &cqRaw,
+ whereCallback);
+
+ if (status.isOK()) {
+ cqRaw->setIsForWrite(true);
+ _canonicalQuery.reset(cqRaw);
+ }
+
+ return status;
+ }
+
+ const DeleteRequest* ParsedDelete::getRequest() const {
+ return _request;
+ }
+
+ bool ParsedDelete::canYield() const {
+ return !_request->isGod() &&
+ PlanExecutor::YIELD_AUTO == _request->getYieldPolicy() && (
+ _canonicalQuery.get() ?
+ !QueryPlannerCommon::hasNode(_canonicalQuery->root(), MatchExpression::ATOMIC) :
+ !LiteParsedQuery::isQueryIsolated(_request->getQuery()));
+ }
+
+ bool ParsedDelete::hasParsedQuery() const {
+ return _canonicalQuery.get() != NULL;
+ }
+
+ CanonicalQuery* ParsedDelete::releaseParsedQuery() {
+ invariant(_canonicalQuery.get() != NULL);
+ return _canonicalQuery.release();
+ }
+
+} // namespace mongo