summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-09-21 06:27:27 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-21 10:58:14 +0000
commite97d622a0933cdc82fec6c1c565305c34153aebf (patch)
tree88431a007b74e88a51307a99bc2a573710246214
parent797ff5702922bc004ef251269281397d3d8e4d68 (diff)
downloadmongo-e97d622a0933cdc82fec6c1c565305c34153aebf.tar.gz
SERVER-60011 remove pipeline dependency from timeseries_update_delete_util
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp44
-rw-r--r--src/mongo/db/timeseries/SConscript1
-rw-r--r--src/mongo/db/timeseries/timeseries_update_delete_util.cpp15
-rw-r--r--src/mongo/db/timeseries/timeseries_update_delete_util.h11
-rw-r--r--src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp24
5 files changed, 56 insertions, 39 deletions
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index 277e037fe32..dcf660dbe53 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -60,6 +60,8 @@
#include "mongo/db/ops/write_ops_exec.h"
#include "mongo/db/ops/write_ops_gen.h"
#include "mongo/db/ops/write_ops_retryability.h"
+#include "mongo/db/pipeline/expression_context.h"
+#include "mongo/db/pipeline/pipeline.h"
#include "mongo/db/query/collection_query_info.h"
#include "mongo/db/query/get_executor.h"
#include "mongo/db/query/plan_summary_stats.h"
@@ -580,6 +582,24 @@ SingleWriteResult makeWriteResultForInsertOrDeleteRetry() {
res.setNModified(0);
return res;
}
+
+/**
+ * Returns true if the given query only modifies the time-series collection's given metaField, false
+ * otherwise.
+ */
+bool timeseriesQueryOnlyDependsOnMetaField(OperationContext* opCtx,
+ const NamespaceString& ns,
+ const BSONObj& query,
+ boost::optional<StringData> metaField,
+ const LegacyRuntimeConstants& runtimeConstants,
+ const boost::optional<BSONObj>& letParams) {
+ boost::intrusive_ptr<ExpressionContext> expCtx(
+ new ExpressionContext(opCtx, nullptr, ns, runtimeConstants, letParams));
+ std::vector<BSONObj> rawPipeline{BSON("$match" << query)};
+ DepsTracker dependencies = Pipeline::parse(rawPipeline, expCtx)->getDependencies({});
+ return timeseries::queryOnlyDependsOnMetaField(metaField, dependencies.fields);
+}
+
} // namespace
WriteResult performInserts(OperationContext* opCtx,
@@ -789,12 +809,12 @@ static SingleWriteResult performSingleUpdateOp(OperationContext* opCtx,
str::stream() << "Cannot perform an update on a time-series collection "
"when querying on a field that is not the metaField '"
<< *metaField << "'",
- timeseries::queryOnlyDependsOnMetaField(opCtx,
- ns,
- updateQuery,
- *metaField,
- *updateRequest->getLegacyRuntimeConstants(),
- updateRequest->getLetParameters()));
+ timeseriesQueryOnlyDependsOnMetaField(opCtx,
+ ns,
+ updateQuery,
+ *metaField,
+ *updateRequest->getLegacyRuntimeConstants(),
+ updateRequest->getLetParameters()));
// Get the original set of modifications to apply and check that they only
// modify the metaField.
@@ -1142,12 +1162,12 @@ static SingleWriteResult performSingleDeleteOp(OperationContext* opCtx,
str::stream() << "Cannot perform a delete on a time-series collection "
"when querying on a field that is not the metaField '"
<< timeseriesOptions->getMetaField() << "'",
- timeseries::queryOnlyDependsOnMetaField(opCtx,
- ns,
- request.getQuery(),
- timeseriesOptions->getMetaField(),
- runtimeConstants,
- letParams));
+ timeseriesQueryOnlyDependsOnMetaField(opCtx,
+ ns,
+ request.getQuery(),
+ timeseriesOptions->getMetaField(),
+ runtimeConstants,
+ letParams));
uassert(ErrorCodes::IllegalOperation,
"Cannot perform a non-multi delete on a time-series collection",
request.getMulti());
diff --git a/src/mongo/db/timeseries/SConscript b/src/mongo/db/timeseries/SConscript
index 8fa191f0248..3294f903b0f 100644
--- a/src/mongo/db/timeseries/SConscript
+++ b/src/mongo/db/timeseries/SConscript
@@ -106,7 +106,6 @@ env.Library(
'$BUILD_DIR/mongo/db/exec/bucket_unpacker',
'$BUILD_DIR/mongo/db/namespace_string',
'$BUILD_DIR/mongo/db/ops/write_ops_parsers',
- '$BUILD_DIR/mongo/db/pipeline/pipeline',
],
)
diff --git a/src/mongo/db/timeseries/timeseries_update_delete_util.cpp b/src/mongo/db/timeseries/timeseries_update_delete_util.cpp
index c90cc91612c..7c64e08bc0f 100644
--- a/src/mongo/db/timeseries/timeseries_update_delete_util.cpp
+++ b/src/mongo/db/timeseries/timeseries_update_delete_util.cpp
@@ -30,8 +30,6 @@
#include "mongo/db/timeseries/timeseries_update_delete_util.h"
#include "mongo/db/exec/bucket_unpacker.h"
-#include "mongo/db/pipeline/expression_context.h"
-#include "mongo/db/pipeline/pipeline.h"
#include "mongo/db/timeseries/timeseries_constants.h"
namespace mongo::timeseries {
@@ -137,19 +135,6 @@ void replaceQueryMetaFieldName(mutablebson::Element elem,
}
} // namespace
-bool queryOnlyDependsOnMetaField(OperationContext* opCtx,
- const NamespaceString& ns,
- const BSONObj& query,
- boost::optional<StringData> metaField,
- const LegacyRuntimeConstants& runtimeConstants,
- const boost::optional<BSONObj>& letParams) {
- boost::intrusive_ptr<ExpressionContext> expCtx(
- new ExpressionContext(opCtx, nullptr, ns, runtimeConstants, letParams));
- std::vector<BSONObj> rawPipeline{BSON("$match" << query)};
- DepsTracker dependencies = Pipeline::parse(rawPipeline, expCtx)->getDependencies({});
- return queryOnlyDependsOnMetaField(metaField, dependencies.fields);
-}
-
bool queryOnlyDependsOnMetaField(boost::optional<StringData> metaField,
const std::set<std::string>& dependencyFieldNames) {
return metaField
diff --git a/src/mongo/db/timeseries/timeseries_update_delete_util.h b/src/mongo/db/timeseries/timeseries_update_delete_util.h
index 44b877e33ce..0688cf8588a 100644
--- a/src/mongo/db/timeseries/timeseries_update_delete_util.h
+++ b/src/mongo/db/timeseries/timeseries_update_delete_util.h
@@ -38,17 +38,6 @@
namespace mongo::timeseries {
/**
- * Returns true if the given query only modifies the time-series collection's given metaField, false
- * otherwise.
- */
-bool queryOnlyDependsOnMetaField(OperationContext* opCtx,
- const NamespaceString& ns,
- const BSONObj& query,
- boost::optional<StringData> metaField,
- const LegacyRuntimeConstants& runtimeConstants,
- const boost::optional<BSONObj>& letParams);
-
-/**
* Returns true if the given query, represented by its dependent fields, only modifies the
* time-series collection's given metaField, false otherwise.
*/
diff --git a/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp b/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp
index ebf5edc1af1..fcee0825b8d 100644
--- a/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp
+++ b/src/mongo/db/timeseries/timeseries_update_delete_util_test.cpp
@@ -31,7 +31,9 @@
#include "mongo/base/error_codes.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/db/pipeline/document_source_merge_gen.h"
+#include "mongo/db/pipeline/expression_context.h"
#include "mongo/db/pipeline/legacy_runtime_constants_gen.h"
+#include "mongo/db/pipeline/pipeline.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/timeseries/timeseries_update_delete_util.h"
#include "mongo/unittest/death_test.h"
@@ -39,6 +41,28 @@
#include "mongo/util/assert_util.h"
namespace mongo {
+
+namespace timeseries {
+
+/**
+ * Returns true if the given query only modifies the time-series collection's given metaField, false
+ * otherwise.
+ */
+bool queryOnlyDependsOnMetaField(OperationContext* opCtx,
+ const NamespaceString& ns,
+ const BSONObj& query,
+ boost::optional<StringData> metaField,
+ const LegacyRuntimeConstants& runtimeConstants,
+ const boost::optional<BSONObj>& letParams) {
+ boost::intrusive_ptr<ExpressionContext> expCtx(
+ new ExpressionContext(opCtx, nullptr, ns, runtimeConstants, letParams));
+ std::vector<BSONObj> rawPipeline{BSON("$match" << query)};
+ DepsTracker dependencies = Pipeline::parse(rawPipeline, expCtx)->getDependencies({});
+ return queryOnlyDependsOnMetaField(metaField, dependencies.fields);
+}
+
+} // namespace timeseries
+
namespace {
class TimeseriesUpdateDeleteUtilTest : public ServiceContextMongoDTest {