diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2021-02-03 17:42:39 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-05 05:48:02 +0000 |
commit | 03954159a4260ec6132669b2e94c9d9cfd5628c0 (patch) | |
tree | 682dfeec10fdf61af3a832e7941e3b555bfc6ced /src/mongo | |
parent | 709dca02b250194115e5a79fa6c6a4daa9b296a0 (diff) | |
download | mongo-03954159a4260ec6132669b2e94c9d9cfd5628c0.tar.gz |
SERVER-53963 Improve error message for unsupported operations on time-series collections
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/create_collection.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/catalog_raii.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/commands/run_aggregate.cpp | 15 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index 87366fe6b46..81df2b85d43 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -159,7 +159,11 @@ Status _createTimeseries(OperationContext* opCtx, } auto db = autoColl.ensureDbExists(); - if (ViewCatalog::get(db)->lookup(opCtx, ns.ns())) { + if (auto view = ViewCatalog::get(db)->lookup(opCtx, ns.ns())) { + if (view->timeseries()) { + return {ErrorCodes::NamespaceExists, + str::stream() << "A timeseries collection already exists. NS: " << ns}; + } return {ErrorCodes::NamespaceExists, str::stream() << "A view already exists. NS: " << ns}; } @@ -307,7 +311,12 @@ Status _createCollection(OperationContext* opCtx, return Status(ErrorCodes::NamespaceExists, str::stream() << "Collection already exists. NS: " << nss); } - if (ViewCatalog::get(autoDb.getDb())->lookup(opCtx, nss.ns())) { + if (auto view = ViewCatalog::get(autoDb.getDb())->lookup(opCtx, nss.ns()); view) { + if (view->timeseries()) { + return Status(ErrorCodes::NamespaceExists, + str::stream() + << "A timeseries collection already exists. NS: " << nss); + } return Status(ErrorCodes::NamespaceExists, str::stream() << "A view already exists. NS: " << nss); } diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp index e5c2043b152..1c3ddcdeee3 100644 --- a/src/mongo/db/catalog_raii.cpp +++ b/src/mongo/db/catalog_raii.cpp @@ -172,6 +172,10 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx, _view = ViewCatalog::get(db)->lookup(opCtx, _resolvedNss.ns()); uassert(ErrorCodes::CommandNotSupportedOnView, + str::stream() << "Namespace " << _resolvedNss.ns() << " is a timeseries collection", + !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted || + !_view->timeseries()); + uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Namespace " << _resolvedNss.ns() << " is a view, not a collection", !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted); } @@ -280,6 +284,10 @@ AutoGetCollectionLockFree::AutoGetCollectionLockFree(OperationContext* opCtx, _view = viewCatalog->lookup(opCtx, _resolvedNss.ns()); uassert(ErrorCodes::CommandNotSupportedOnView, + str::stream() << "Namespace " << _resolvedNss.ns() << " is a timeseries collection", + !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted || + !_view->timeseries()); + uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Namespace " << _resolvedNss.ns() << " is a view, not a collection", !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted); } diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index 28d6abd0c63..dd796ef3a2c 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -572,10 +572,17 @@ Status runAggregate(OperationContext* opCtx, // a stream on an entire db or across the cluster. if (!origNss.isCollectionlessAggregateNS()) { auto viewCatalog = DatabaseHolder::get(opCtx)->getViewCatalog(opCtx, origNss.db()); - uassert(ErrorCodes::CommandNotSupportedOnView, - str::stream() - << "Namespace " << origNss.ns() << " is a view, not a collection", - !viewCatalog || !viewCatalog->lookup(opCtx, origNss.ns())); + if (viewCatalog) { + auto view = viewCatalog->lookup(opCtx, origNss.ns()); + uassert(ErrorCodes::CommandNotSupportedOnView, + str::stream() + << "Namespace " << origNss.ns() << " is a timeseries collection", + !view || !view->timeseries()); + uassert(ErrorCodes::CommandNotSupportedOnView, + str::stream() + << "Namespace " << origNss.ns() << " is a view, not a collection", + !view); + } } // If the user specified an explicit collation, adopt it; otherwise, use the simple |