From e97d622a0933cdc82fec6c1c565305c34153aebf Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Tue, 21 Sep 2021 06:27:27 -0400 Subject: SERVER-60011 remove pipeline dependency from timeseries_update_delete_util --- src/mongo/db/ops/write_ops_exec.cpp | 44 ++++++++++++++++------ src/mongo/db/timeseries/SConscript | 1 - .../timeseries/timeseries_update_delete_util.cpp | 15 -------- .../db/timeseries/timeseries_update_delete_util.h | 11 ------ .../timeseries_update_delete_util_test.cpp | 24 ++++++++++++ 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 metaField, + const LegacyRuntimeConstants& runtimeConstants, + const boost::optional& letParams) { + boost::intrusive_ptr expCtx( + new ExpressionContext(opCtx, nullptr, ns, runtimeConstants, letParams)); + std::vector 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 metaField, - const LegacyRuntimeConstants& runtimeConstants, - const boost::optional& letParams) { - boost::intrusive_ptr expCtx( - new ExpressionContext(opCtx, nullptr, ns, runtimeConstants, letParams)); - std::vector rawPipeline{BSON("$match" << query)}; - DepsTracker dependencies = Pipeline::parse(rawPipeline, expCtx)->getDependencies({}); - return queryOnlyDependsOnMetaField(metaField, dependencies.fields); -} - bool queryOnlyDependsOnMetaField(boost::optional metaField, const std::set& 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 @@ -37,17 +37,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 metaField, - const LegacyRuntimeConstants& runtimeConstants, - const boost::optional& 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 metaField, + const LegacyRuntimeConstants& runtimeConstants, + const boost::optional& letParams) { + boost::intrusive_ptr expCtx( + new ExpressionContext(opCtx, nullptr, ns, runtimeConstants, letParams)); + std::vector rawPipeline{BSON("$match" << query)}; + DepsTracker dependencies = Pipeline::parse(rawPipeline, expCtx)->getDependencies({}); + return queryOnlyDependsOnMetaField(metaField, dependencies.fields); +} + +} // namespace timeseries + namespace { class TimeseriesUpdateDeleteUtilTest : public ServiceContextMongoDTest { -- cgit v1.2.1