summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2023-04-11 23:54:17 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-12 04:52:53 +0000
commit3cd6a9bc6def4936c489f8f9dffeebc98390b6f5 (patch)
tree4d8e8b580e214f031c8054585a0b052a57c57606 /src/mongo/s/commands
parent7d08c1b07913e26982499e9ea6051e815d7cf7e6 (diff)
downloadmongo-3cd6a9bc6def4936c489f8f9dffeebc98390b6f5.tar.gz
SERVER-75928: Move common bulkWrite helpers between mongod and mongos into one place
Diffstat (limited to 'src/mongo/s/commands')
-rw-r--r--src/mongo/s/commands/SConscript1
-rw-r--r--src/mongo/s/commands/cluster_bulk_write_cmd.cpp19
2 files changed, 16 insertions, 4 deletions
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index ae3982f6d75..00894df10de 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -115,6 +115,7 @@ env.Library(
'$BUILD_DIR/mongo/db/auth/auth_checks',
'$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info',
'$BUILD_DIR/mongo/db/change_stream_options_manager',
+ '$BUILD_DIR/mongo/db/commands/bulk_write_common',
'$BUILD_DIR/mongo/db/commands/bulk_write_parser',
'$BUILD_DIR/mongo/db/commands/cluster_server_parameter_cmds_idl',
'$BUILD_DIR/mongo/db/commands/cluster_server_parameter_commands_invocation',
diff --git a/src/mongo/s/commands/cluster_bulk_write_cmd.cpp b/src/mongo/s/commands/cluster_bulk_write_cmd.cpp
index 7591ee50d63..324a49c6117 100644
--- a/src/mongo/s/commands/cluster_bulk_write_cmd.cpp
+++ b/src/mongo/s/commands/cluster_bulk_write_cmd.cpp
@@ -37,7 +37,9 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection_operation_source.h"
#include "mongo/db/commands.h"
+#include "mongo/db/commands/bulk_write_common.h"
#include "mongo/db/commands/bulk_write_gen.h"
+#include "mongo/db/not_primary_error_tracker.h"
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/server_feature_flags_gen.h"
#include "mongo/db/server_options.h"
@@ -94,15 +96,16 @@ public:
}
Reply typedRun(OperationContext* opCtx) final {
- uassert(ErrorCodes::CommandNotSupported,
- "BulkWrite on mongos is not currently supported.",
- false);
+ uasserted(ErrorCodes::CommandNotSupported,
+ "BulkWrite on mongos is not currently supported.");
uassert(
ErrorCodes::CommandNotSupported,
"BulkWrite may not be run without featureFlagBulkWriteCommand enabled",
gFeatureFlagBulkWriteCommand.isEnabled(serverGlobalParams.featureCompatibility));
+ bulk_write_common::validateRequest(request());
+
auto replyItems = cluster::bulkWrite(opCtx, request());
auto reply = Reply();
@@ -111,7 +114,15 @@ public:
return reply;
}
- void doCheckAuthorization(OperationContext* opCtx) const final {}
+ void doCheckAuthorization(OperationContext* opCtx) const final try {
+ uassert(ErrorCodes::Unauthorized,
+ "unauthorized",
+ AuthorizationSession::get(opCtx->getClient())
+ ->isAuthorizedForPrivileges(bulk_write_common::getPrivileges(request())));
+ } catch (const DBException& e) {
+ NotPrimaryErrorTracker::get(opCtx->getClient()).recordError(e.code());
+ throw;
+ }
};
} clusterBulkWriteCmd;