diff options
author | Antonio Fuschetto <antonio.fuschetto@mongodb.com> | 2022-03-28 16:24:56 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-28 19:32:40 +0000 |
commit | 6d6945cab4a3e00e3d95b505c260f1531d650e34 (patch) | |
tree | 918ab5c4fed143c5d21078bc876ca09dca97fea1 /src/mongo/db/commands/write_commands.cpp | |
parent | 6b17b79fafd363ffe7b899f10943f76941c0bb52 (diff) | |
download | mongo-6d6945cab4a3e00e3d95b505c260f1531d650e34.tar.gz |
SERVER-64975 Time series insertion takes a lock on the bucket collection without checking the shard version
Diffstat (limited to 'src/mongo/db/commands/write_commands.cpp')
-rw-r--r-- | src/mongo/db/commands/write_commands.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/mongo/db/commands/write_commands.cpp b/src/mongo/db/commands/write_commands.cpp index e0b6516d46e..2a6279e6388 100644 --- a/src/mongo/db/commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands.cpp @@ -66,6 +66,7 @@ #include "mongo/db/repl/tenant_migration_decoration.h" #include "mongo/db/retryable_writes_stats.h" #include "mongo/db/s/collection_sharding_state.h" +#include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/stats/counters.h" #include "mongo/db/storage/duplicate_key_error_info.h" #include "mongo/db/storage/storage_parameters_gen.h" @@ -982,7 +983,21 @@ public: bucketsColl->getTimeseriesOptions()); auto timeSeriesOptions = *bucketsColl->getTimeseriesOptions(); - _rebuildOptionsWithGranularityFromConfigServer(opCtx, timeSeriesOptions, bucketsNs); + + boost::optional<Status> rebuildOptionsError; + try { + _rebuildOptionsWithGranularityFromConfigServer(opCtx, timeSeriesOptions, bucketsNs); + } catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) { + // This could occur when the shard version attached to the request is for the time + // series namespace (unsharded), which is compared to the shard version of the + // bucket namespace. Consequently, every single entry fails but the whole operation + // succeeds. + + rebuildOptionsError = ex.toStatus(); + + auto& oss{OperationShardingState::get(opCtx)}; + oss.setShardingOperationFailedStatus(ex.toStatus()); + } TimeseriesBatches batches; TimeseriesStmtIds stmtIds; @@ -991,6 +1006,13 @@ public: auto insert = [&](size_t index) { invariant(start + index < request().getDocuments().size()); + if (rebuildOptionsError) { + const auto error{ + generateError(opCtx, *rebuildOptionsError, start + index, errors->size())}; + errors->emplace_back(std::move(*error)); + return false; + } + auto stmtId = request().getStmtIds() ? request().getStmtIds()->at(start + index) : request().getStmtId().value_or(0) + start + index; |