feat(mongodb): stream legacy agent exports via find cursors
This commit is contained in:
1 parent
9eafac706e
commit
7ab781ce19
26 files changed
+1942
-160
No files matched your search
@@ -68,6 +68,9 @@ public final class AgentProtocol {
|
|||||||
public static final String MONGO_METHOD_DROP_DATABASE = "drop_database";
|
public static final String MONGO_METHOD_DROP_DATABASE = "drop_database";
|
||||||
public static final String MONGO_METHOD_INSERT_DOCUMENT = "insert_document";
|
public static final String MONGO_METHOD_INSERT_DOCUMENT = "insert_document";
|
||||||
public static final String MONGO_METHOD_INSERT_DOCUMENTS = "insert_documents";
|
public static final String MONGO_METHOD_INSERT_DOCUMENTS = "insert_documents";
|
||||||
|
public static final String MONGO_METHOD_START_FIND_CURSOR = "start_find_cursor";
|
||||||
|
public static final String MONGO_METHOD_FETCH_FIND_CURSOR = "fetch_find_cursor";
|
||||||
|
public static final String MONGO_METHOD_CLOSE_FIND_CURSOR = "close_find_cursor";
|
||||||
public static final String MONGO_METHOD_UPDATE_DOCUMENT = "update_document";
|
public static final String MONGO_METHOD_UPDATE_DOCUMENT = "update_document";
|
||||||
public static final String MONGO_METHOD_UPDATE_DOCUMENTS = "update_documents";
|
public static final String MONGO_METHOD_UPDATE_DOCUMENTS = "update_documents";
|
||||||
public static final String MONGO_METHOD_REPLACE_DOCUMENT = "replace_document";
|
public static final String MONGO_METHOD_REPLACE_DOCUMENT = "replace_document";
|
||||||
@@ -129,6 +132,7 @@ public final class AgentProtocol {
|
|||||||
public static final String CAPABILITY_MONGO_RUN_COMMAND = "mongo_run_command";
|
public static final String CAPABILITY_MONGO_RUN_COMMAND = "mongo_run_command";
|
||||||
public static final String CAPABILITY_MONGO_INSERT_DOCUMENTS = "mongo_insert_documents";
|
public static final String CAPABILITY_MONGO_INSERT_DOCUMENTS = "mongo_insert_documents";
|
||||||
public static final String CAPABILITY_MONGO_REPLACE_DOCUMENT = "mongo_replace_document";
|
public static final String CAPABILITY_MONGO_REPLACE_DOCUMENT = "mongo_replace_document";
|
||||||
|
public static final String CAPABILITY_MONGO_FIND_CURSOR = "mongo_find_cursor";
|
||||||
public static final String CAPABILITY_MULTI_SESSION = "multi_session";
|
public static final String CAPABILITY_MULTI_SESSION = "multi_session";
|
||||||
public static final String CAPABILITY_STRUCTURED_ERROR_V1 = "structured_error_v1";
|
public static final String CAPABILITY_STRUCTURED_ERROR_V1 = "structured_error_v1";
|
||||||
|
|
||||||
@@ -165,7 +169,8 @@ public final class AgentProtocol {
|
|||||||
CAPABILITY_MONGO_CLONE_COLLECTION,
|
CAPABILITY_MONGO_CLONE_COLLECTION,
|
||||||
CAPABILITY_MONGO_RUN_COMMAND,
|
CAPABILITY_MONGO_RUN_COMMAND,
|
||||||
CAPABILITY_MONGO_INSERT_DOCUMENTS,
|
CAPABILITY_MONGO_INSERT_DOCUMENTS,
|
||||||
CAPABILITY_MONGO_REPLACE_DOCUMENT
|
CAPABILITY_MONGO_REPLACE_DOCUMENT,
|
||||||
|
CAPABILITY_MONGO_FIND_CURSOR
|
||||||
));
|
));
|
||||||
|
|
||||||
public static final List<String> MULTI_SESSION_CAPABILITIES;
|
public static final List<String> MULTI_SESSION_CAPABILITIES;
|
||||||
@@ -230,6 +235,7 @@ public final class AgentProtocol {
|
|||||||
mongoCapabilities.add(CAPABILITY_MONGO_RUN_COMMAND);
|
mongoCapabilities.add(CAPABILITY_MONGO_RUN_COMMAND);
|
||||||
mongoCapabilities.add(CAPABILITY_MONGO_INSERT_DOCUMENTS);
|
mongoCapabilities.add(CAPABILITY_MONGO_INSERT_DOCUMENTS);
|
||||||
mongoCapabilities.add(CAPABILITY_MONGO_REPLACE_DOCUMENT);
|
mongoCapabilities.add(CAPABILITY_MONGO_REPLACE_DOCUMENT);
|
||||||
|
mongoCapabilities.add(CAPABILITY_MONGO_FIND_CURSOR);
|
||||||
MONGO_LEGACY_CAPABILITIES = Collections.unmodifiableList(mongoCapabilities);
|
MONGO_LEGACY_CAPABILITIES = Collections.unmodifiableList(mongoCapabilities);
|
||||||
|
|
||||||
List<String> mongoMultiSessionCapabilities = new java.util.ArrayList<>(MULTI_SESSION_CAPABILITIES);
|
List<String> mongoMultiSessionCapabilities = new java.util.ArrayList<>(MULTI_SESSION_CAPABILITIES);
|
||||||
@@ -238,6 +244,7 @@ public final class AgentProtocol {
|
|||||||
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_RUN_COMMAND);
|
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_RUN_COMMAND);
|
||||||
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_INSERT_DOCUMENTS);
|
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_INSERT_DOCUMENTS);
|
||||||
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_REPLACE_DOCUMENT);
|
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_REPLACE_DOCUMENT);
|
||||||
|
mongoMultiSessionCapabilities.add(CAPABILITY_MONGO_FIND_CURSOR);
|
||||||
MONGO_LEGACY_MULTI_SESSION_CAPABILITIES = Collections.unmodifiableList(mongoMultiSessionCapabilities);
|
MONGO_LEGACY_MULTI_SESSION_CAPABILITIES = Collections.unmodifiableList(mongoMultiSessionCapabilities);
|
||||||
|
|
||||||
List<String> jdbcCapabilities = new java.util.ArrayList<>(MULTI_SESSION_CAPABILITIES);
|
List<String> jdbcCapabilities = new java.util.ArrayList<>(MULTI_SESSION_CAPABILITIES);
|
||||||
@@ -282,7 +289,10 @@ public final class AgentProtocol {
|
|||||||
MONGO_METHOD_REPLACE_DOCUMENT,
|
MONGO_METHOD_REPLACE_DOCUMENT,
|
||||||
MONGO_METHOD_DELETE_DOCUMENT,
|
MONGO_METHOD_DELETE_DOCUMENT,
|
||||||
MONGO_METHOD_DELETE_DOCUMENTS,
|
MONGO_METHOD_DELETE_DOCUMENTS,
|
||||||
MONGO_METHOD_RUN_COMMAND
|
MONGO_METHOD_RUN_COMMAND,
|
||||||
|
MONGO_METHOD_START_FIND_CURSOR,
|
||||||
|
MONGO_METHOD_FETCH_FIND_CURSOR,
|
||||||
|
MONGO_METHOD_CLOSE_FIND_CURSOR
|
||||||
));
|
));
|
||||||
|
|
||||||
public static final List<String> KV_METHODS = Collections.unmodifiableList(Arrays.asList(
|
public static final List<String> KV_METHODS = Collections.unmodifiableList(Arrays.asList(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"protocolVersion": 1,
|
"protocolVersion": 1,
|
||||||
"handshakeMethod": "handshake",
|
"handshakeMethod": "handshake",
|
||||||
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
||||||
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document"],
|
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document", "mongo_find_cursor"],
|
||||||
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
||||||
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
||||||
"commonMethods": [
|
"commonMethods": [
|
||||||
@@ -42,6 +42,6 @@
|
|||||||
"disconnect",
|
"disconnect",
|
||||||
"shutdown"
|
"shutdown"
|
||||||
],
|
],
|
||||||
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command"],
|
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command", "start_find_cursor", "fetch_find_cursor", "close_find_cursor"],
|
||||||
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"]
|
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"]
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"protocolVersion": 2,
|
"protocolVersion": 2,
|
||||||
"handshakeMethod": "handshake",
|
"handshakeMethod": "handshake",
|
||||||
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
||||||
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document", "multi_session", "structured_error_v1"],
|
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document", "mongo_find_cursor", "multi_session", "structured_error_v1"],
|
||||||
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session"],
|
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session"],
|
||||||
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session", "structured_error_v1"],
|
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session", "structured_error_v1"],
|
||||||
"commonMethods": [
|
"commonMethods": [
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"disconnect",
|
"disconnect",
|
||||||
"shutdown"
|
"shutdown"
|
||||||
],
|
],
|
||||||
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command"],
|
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command", "start_find_cursor", "fetch_find_cursor", "close_find_cursor"],
|
||||||
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"],
|
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"],
|
||||||
"sessionField": "agentSessionId",
|
"sessionField": "agentSessionId",
|
||||||
"cursorSessionField": "sessionId"
|
"cursorSessionField": "sessionId"
|
||||||
|
|||||||
@@ -10,10 +10,14 @@ import com.google.gson.JsonNull;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.mongodb.ConnectionString;
|
import com.mongodb.ConnectionString;
|
||||||
|
import com.mongodb.MongoBulkWriteException;
|
||||||
import com.mongodb.MongoCredential;
|
import com.mongodb.MongoCredential;
|
||||||
import com.mongodb.MongoClientSettings;
|
import com.mongodb.MongoClientSettings;
|
||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
|
import com.mongodb.bulk.BulkWriteError;
|
||||||
|
import com.mongodb.bulk.WriteConcernError;
|
||||||
import com.mongodb.client.AggregateIterable;
|
import com.mongodb.client.AggregateIterable;
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
import com.mongodb.client.MongoClient;
|
import com.mongodb.client.MongoClient;
|
||||||
import com.mongodb.client.MongoClients;
|
import com.mongodb.client.MongoClients;
|
||||||
import com.mongodb.client.MongoCollection;
|
import com.mongodb.client.MongoCollection;
|
||||||
@@ -58,6 +62,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -81,11 +86,22 @@ public final class MongoAgent {
|
|||||||
private static final JsonWriterSettings EXTENDED_JSON_SETTINGS = JsonWriterSettings.builder()
|
private static final JsonWriterSettings EXTENDED_JSON_SETTINGS = JsonWriterSettings.builder()
|
||||||
.outputMode(JsonMode.RELAXED)
|
.outputMode(JsonMode.RELAXED)
|
||||||
.build();
|
.build();
|
||||||
|
// Driver 3.x names the canonical Extended JSON v2 output "EXTENDED"; RELAXED is its lossy
|
||||||
|
// sibling (plain numbers, ISO dates), so exports must use this one to keep BSON types.
|
||||||
|
private static final JsonWriterSettings CANONICAL_JSON_SETTINGS = JsonWriterSettings.builder()
|
||||||
|
.outputMode(JsonMode.EXTENDED)
|
||||||
|
.build();
|
||||||
private static final String LEGACY_SESSION_ID = "__legacy__";
|
private static final String LEGACY_SESSION_ID = "__legacy__";
|
||||||
private static final String DEFAULT_ID_INDEX_NAME = "_id_";
|
private static final String DEFAULT_ID_INDEX_NAME = "_id_";
|
||||||
private static final int CLONE_INSERT_BATCH_SIZE = 1_000;
|
private static final int CLONE_INSERT_BATCH_SIZE = 1_000;
|
||||||
|
private static final int DEFAULT_FIND_CURSOR_BATCH_SIZE = 1_000;
|
||||||
|
private static final int MAX_FIND_CURSORS_PER_OWNER = 16;
|
||||||
|
private static final int MAX_FIND_CURSORS_TOTAL = 64;
|
||||||
private static final int MAX_SESSIONS = 256;
|
private static final int MAX_SESSIONS = 256;
|
||||||
private static final ThreadLocal<MongoClient> CURRENT_CLIENT = new ThreadLocal<>();
|
private static final ThreadLocal<MongoClient> CURRENT_CLIENT = new ThreadLocal<>();
|
||||||
|
private static final ThreadLocal<Set<String>> CURRENT_FIND_CURSOR_OWNER = new ThreadLocal<>();
|
||||||
|
private static final ConcurrentHashMap<String, MongoCursor<Document>> FIND_CURSORS = new ConcurrentHashMap<>();
|
||||||
|
private static final Set<String> LEGACY_FIND_CURSOR_IDS = ConcurrentHashMap.newKeySet();
|
||||||
private static MongoClient legacyClient;
|
private static MongoClient legacyClient;
|
||||||
|
|
||||||
private MongoAgent() {
|
private MongoAgent() {
|
||||||
@@ -1489,8 +1505,174 @@ public final class MongoAgent {
|
|||||||
MongoClient client = requireClient();
|
MongoClient client = requireClient();
|
||||||
String database = params.get("database").getAsString();
|
String database = params.get("database").getAsString();
|
||||||
String collection = params.get("collection").getAsString();
|
String collection = params.get("collection").getAsString();
|
||||||
client.getDatabase(database).getCollection(collection).insertMany(documents);
|
InsertManyOptions options = new InsertManyOptions();
|
||||||
return Collections.singletonMap("affected_rows", documents.size());
|
if (params.has("ordered") && !params.get("ordered").isJsonNull()) {
|
||||||
|
JsonElement ordered = params.get("ordered");
|
||||||
|
if (!ordered.isJsonPrimitive() || !ordered.getAsJsonPrimitive().isBoolean()) {
|
||||||
|
throw new IllegalArgumentException("ordered must be a boolean");
|
||||||
|
}
|
||||||
|
options.ordered(ordered.getAsBoolean());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
client.getDatabase(database).getCollection(collection).insertMany(documents, options);
|
||||||
|
return Collections.singletonMap("affected_rows", documents.size());
|
||||||
|
} catch (MongoBulkWriteException error) {
|
||||||
|
return bulkInsertResult(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, Object> bulkInsertResult(MongoBulkWriteException error) {
|
||||||
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
|
result.put("affected_rows", error.getWriteResult().getInsertedCount());
|
||||||
|
List<Map<String, Object>> errors = new ArrayList<>();
|
||||||
|
for (BulkWriteError writeError : error.getWriteErrors()) {
|
||||||
|
Map<String, Object> item = new LinkedHashMap<>();
|
||||||
|
item.put("index", writeError.getIndex());
|
||||||
|
item.put("code", writeError.getCode());
|
||||||
|
item.put("message", writeError.getMessage());
|
||||||
|
errors.add(item);
|
||||||
|
}
|
||||||
|
// The driver raises the same exception for write concern failures only (for example a
|
||||||
|
// wtimeout): there are no per-document errors then, but the batch must not look
|
||||||
|
// successful, so report the write concern error as a batch-wide rejection without index.
|
||||||
|
WriteConcernError writeConcernError = error.getWriteConcernError();
|
||||||
|
if (errors.isEmpty() && writeConcernError != null) {
|
||||||
|
Map<String, Object> item = new LinkedHashMap<>();
|
||||||
|
item.put("code", writeConcernError.getCode());
|
||||||
|
item.put("message", writeConcernError.getMessage());
|
||||||
|
errors.add(item);
|
||||||
|
}
|
||||||
|
result.put("errors", errors);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object startFindCursor(JsonObject params) {
|
||||||
|
Set<String> owner = CURRENT_FIND_CURSOR_OWNER.get();
|
||||||
|
if (owner != null && owner.size() >= MAX_FIND_CURSORS_PER_OWNER) {
|
||||||
|
throw new IllegalStateException("MongoDB find cursor limit reached: " + MAX_FIND_CURSORS_PER_OWNER);
|
||||||
|
}
|
||||||
|
// The per-owner budget keeps one session from starving the others; the process-wide cap
|
||||||
|
// only bounds how many server cursors this agent can hold in total.
|
||||||
|
if (FIND_CURSORS.size() >= MAX_FIND_CURSORS_TOTAL) {
|
||||||
|
throw new IllegalStateException("MongoDB find cursor limit reached: " + MAX_FIND_CURSORS_TOTAL);
|
||||||
|
}
|
||||||
|
MongoClient client = requireClient();
|
||||||
|
String database = params.get("database").getAsString();
|
||||||
|
String collection = params.get("collection").getAsString();
|
||||||
|
Document filterDoc = documentOrNull(params, "filter");
|
||||||
|
Document projectionDoc = documentOrNull(params, "projection");
|
||||||
|
Document sortDoc = documentOrNull(params, "sort");
|
||||||
|
Collation collation = collationOrNull(documentOrNull(params, "collation"));
|
||||||
|
int batchSize = findCursorBatchSize(params);
|
||||||
|
|
||||||
|
FindIterable<Document> iterable = client.getDatabase(database)
|
||||||
|
.getCollection(collection)
|
||||||
|
.find(filterDoc == null ? new Document() : filterDoc)
|
||||||
|
.batchSize(batchSize);
|
||||||
|
if (projectionDoc != null) {
|
||||||
|
iterable = iterable.projection(projectionDoc);
|
||||||
|
}
|
||||||
|
if (sortDoc != null) {
|
||||||
|
iterable = iterable.sort(sortDoc);
|
||||||
|
}
|
||||||
|
if (collation != null) {
|
||||||
|
iterable = iterable.collation(collation);
|
||||||
|
}
|
||||||
|
|
||||||
|
String cursorId = UUID.randomUUID().toString();
|
||||||
|
FIND_CURSORS.put(cursorId, iterable.iterator());
|
||||||
|
if (owner != null) {
|
||||||
|
owner.add(cursorId);
|
||||||
|
}
|
||||||
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
|
result.put("cursor_id", cursorId);
|
||||||
|
result.put("batch_size", batchSize);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object fetchFindCursor(JsonObject params) {
|
||||||
|
String cursorId = requiredCursorId(params);
|
||||||
|
MongoCursor<Document> cursor = FIND_CURSORS.get(cursorId);
|
||||||
|
if (cursor == null) {
|
||||||
|
throw new IllegalStateException("Find cursor not found");
|
||||||
|
}
|
||||||
|
int limit = params.has("limit") ? params.get("limit").getAsInt() : DEFAULT_FIND_CURSOR_BATCH_SIZE;
|
||||||
|
if (limit <= 0) {
|
||||||
|
throw new IllegalArgumentException("Find cursor limit must be a positive integer");
|
||||||
|
}
|
||||||
|
List<JsonObject> documents = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
while (documents.size() < limit && cursor.hasNext()) {
|
||||||
|
documents.add(bsonToCanonicalExtendedJson(cursor.next()));
|
||||||
|
}
|
||||||
|
} catch (RuntimeException error) {
|
||||||
|
// A cursor that fails mid-iteration (server-side idle timeout, lost connection) can
|
||||||
|
// never be resumed, so drop it instead of leaking a slot in the cursor budgets.
|
||||||
|
closeFindCursorById(cursorId);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
boolean exhausted = !cursor.hasNext();
|
||||||
|
if (exhausted) {
|
||||||
|
closeFindCursorById(cursorId);
|
||||||
|
}
|
||||||
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
|
result.put("documents", documents);
|
||||||
|
result.put("exhausted", exhausted);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object closeFindCursor(JsonObject params) {
|
||||||
|
closeFindCursorById(requiredCursorId(params));
|
||||||
|
return Collections.singletonMap("ok", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String requiredCursorId(JsonObject params) {
|
||||||
|
String cursorId = stringOrNull(params, "cursor_id");
|
||||||
|
if (cursorId == null || cursorId.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("cursor_id is required");
|
||||||
|
}
|
||||||
|
return cursorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int findCursorBatchSize(JsonObject params) {
|
||||||
|
if (!params.has("batch_size") || params.get("batch_size").isJsonNull()) {
|
||||||
|
return DEFAULT_FIND_CURSOR_BATCH_SIZE;
|
||||||
|
}
|
||||||
|
int batchSize = params.get("batch_size").getAsInt();
|
||||||
|
if (batchSize <= 0) {
|
||||||
|
throw new IllegalArgumentException("batch_size must be a positive integer");
|
||||||
|
}
|
||||||
|
return batchSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void closeFindCursorById(String cursorId) {
|
||||||
|
MongoCursor<Document> cursor = FIND_CURSORS.remove(cursorId);
|
||||||
|
if (cursor != null) {
|
||||||
|
try {
|
||||||
|
cursor.close();
|
||||||
|
} catch (RuntimeException ignored) {
|
||||||
|
// Closing a server cursor is best-effort; the client may already be gone.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Set<String> owner = CURRENT_FIND_CURSOR_OWNER.get();
|
||||||
|
if (owner != null) {
|
||||||
|
owner.remove(cursorId);
|
||||||
|
}
|
||||||
|
LEGACY_FIND_CURSOR_IDS.remove(cursorId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void closeFindCursors(Set<String> cursorIds) {
|
||||||
|
for (String cursorId : new ArrayList<>(cursorIds)) {
|
||||||
|
closeFindCursorById(cursorId);
|
||||||
|
}
|
||||||
|
cursorIds.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resetFindCursorsForTests() {
|
||||||
|
for (String cursorId : new ArrayList<>(FIND_CURSORS.keySet())) {
|
||||||
|
closeFindCursorById(cursorId);
|
||||||
|
}
|
||||||
|
LEGACY_FIND_CURSOR_IDS.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Object parseId(String id) {
|
static Object parseId(String id) {
|
||||||
@@ -1787,6 +1969,10 @@ public final class MongoAgent {
|
|||||||
return preserveUnsafeLongsForJsonClients(doc, relaxed).getAsJsonObject();
|
return preserveUnsafeLongsForJsonClients(doc, relaxed).getAsJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JsonObject bsonToCanonicalExtendedJson(Document doc) {
|
||||||
|
return JsonParser.parseString(doc.toJson(CANONICAL_JSON_SETTINGS)).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
private static JsonElement preserveUnsafeLongsForJsonClients(Object bsonValue, JsonElement relaxedValue) {
|
private static JsonElement preserveUnsafeLongsForJsonClients(Object bsonValue, JsonElement relaxedValue) {
|
||||||
if (
|
if (
|
||||||
bsonValue instanceof Long longValue &&
|
bsonValue instanceof Long longValue &&
|
||||||
@@ -1914,6 +2100,9 @@ public final class MongoAgent {
|
|||||||
case AgentProtocol.MONGO_METHOD_DROP_DATABASE -> dropDatabase(params);
|
case AgentProtocol.MONGO_METHOD_DROP_DATABASE -> dropDatabase(params);
|
||||||
case AgentProtocol.MONGO_METHOD_INSERT_DOCUMENT -> insertDocument(params);
|
case AgentProtocol.MONGO_METHOD_INSERT_DOCUMENT -> insertDocument(params);
|
||||||
case AgentProtocol.MONGO_METHOD_INSERT_DOCUMENTS -> insertDocuments(params);
|
case AgentProtocol.MONGO_METHOD_INSERT_DOCUMENTS -> insertDocuments(params);
|
||||||
|
case AgentProtocol.MONGO_METHOD_START_FIND_CURSOR -> startFindCursor(params);
|
||||||
|
case AgentProtocol.MONGO_METHOD_FETCH_FIND_CURSOR -> fetchFindCursor(params);
|
||||||
|
case AgentProtocol.MONGO_METHOD_CLOSE_FIND_CURSOR -> closeFindCursor(params);
|
||||||
case AgentProtocol.MONGO_METHOD_UPDATE_DOCUMENT -> updateDocument(params);
|
case AgentProtocol.MONGO_METHOD_UPDATE_DOCUMENT -> updateDocument(params);
|
||||||
case AgentProtocol.MONGO_METHOD_UPDATE_DOCUMENTS -> updateDocuments(params);
|
case AgentProtocol.MONGO_METHOD_UPDATE_DOCUMENTS -> updateDocuments(params);
|
||||||
case AgentProtocol.MONGO_METHOD_REPLACE_DOCUMENT -> replaceDocument(params);
|
case AgentProtocol.MONGO_METHOD_REPLACE_DOCUMENT -> replaceDocument(params);
|
||||||
@@ -1921,6 +2110,7 @@ public final class MongoAgent {
|
|||||||
case AgentProtocol.MONGO_METHOD_DELETE_DOCUMENTS -> deleteDocuments(params);
|
case AgentProtocol.MONGO_METHOD_DELETE_DOCUMENTS -> deleteDocuments(params);
|
||||||
case AgentProtocol.MONGO_METHOD_RUN_COMMAND -> runCommand(params);
|
case AgentProtocol.MONGO_METHOD_RUN_COMMAND -> runCommand(params);
|
||||||
case AgentProtocol.METHOD_DISCONNECT, AgentProtocol.METHOD_SHUTDOWN -> {
|
case AgentProtocol.METHOD_DISCONNECT, AgentProtocol.METHOD_SHUTDOWN -> {
|
||||||
|
closeFindCursors(LEGACY_FIND_CURSOR_IDS);
|
||||||
closeLegacyClient();
|
closeLegacyClient();
|
||||||
if (AgentProtocol.METHOD_SHUTDOWN.equals(method)) {
|
if (AgentProtocol.METHOD_SHUTDOWN.equals(method)) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@@ -1968,6 +2158,7 @@ public final class MongoAgent {
|
|||||||
static String handleRequest(String line, MongoClient client) {
|
static String handleRequest(String line, MongoClient client) {
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
CURRENT_CLIENT.set(client);
|
CURRENT_CLIENT.set(client);
|
||||||
|
CURRENT_FIND_CURSOR_OWNER.set(LEGACY_FIND_CURSOR_IDS);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
JsonObject req = JsonParser.parseString(line).getAsJsonObject();
|
JsonObject req = JsonParser.parseString(line).getAsJsonObject();
|
||||||
@@ -1995,6 +2186,7 @@ public final class MongoAgent {
|
|||||||
} finally {
|
} finally {
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
CURRENT_CLIENT.remove();
|
CURRENT_CLIENT.remove();
|
||||||
|
CURRENT_FIND_CURSOR_OWNER.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2120,6 +2312,7 @@ public final class MongoAgent {
|
|||||||
|
|
||||||
private static final class Session {
|
private static final class Session {
|
||||||
private final MongoClient client;
|
private final MongoClient client;
|
||||||
|
private final Set<String> findCursorIds = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
private Session(MongoClient client) {
|
private Session(MongoClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@@ -2127,10 +2320,12 @@ public final class MongoAgent {
|
|||||||
|
|
||||||
private synchronized Object handle(String method, JsonObject params) {
|
private synchronized Object handle(String method, JsonObject params) {
|
||||||
CURRENT_CLIENT.set(client);
|
CURRENT_CLIENT.set(client);
|
||||||
|
CURRENT_FIND_CURSOR_OWNER.set(findCursorIds);
|
||||||
try {
|
try {
|
||||||
return dispatch(method, params);
|
return dispatch(method, params);
|
||||||
} finally {
|
} finally {
|
||||||
CURRENT_CLIENT.remove();
|
CURRENT_CLIENT.remove();
|
||||||
|
CURRENT_FIND_CURSOR_OWNER.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2144,6 +2339,7 @@ public final class MongoAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void close() {
|
private synchronized void close() {
|
||||||
|
closeFindCursors(findCursorIds);
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.dbx.agent.mongodb;
|
package com.dbx.agent.mongodb;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
@@ -12,7 +13,12 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import com.mongodb.MongoBulkWriteException;
|
||||||
import com.mongodb.MongoClientSettings;
|
import com.mongodb.MongoClientSettings;
|
||||||
|
import com.mongodb.ServerAddress;
|
||||||
|
import com.mongodb.bulk.BulkWriteError;
|
||||||
|
import com.mongodb.bulk.BulkWriteResult;
|
||||||
|
import com.mongodb.bulk.WriteConcernError;
|
||||||
import com.mongodb.client.AggregateIterable;
|
import com.mongodb.client.AggregateIterable;
|
||||||
import com.mongodb.client.FindIterable;
|
import com.mongodb.client.FindIterable;
|
||||||
import com.mongodb.client.ListCollectionsIterable;
|
import com.mongodb.client.ListCollectionsIterable;
|
||||||
@@ -40,8 +46,12 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.bson.BsonDocument;
|
||||||
|
import org.bson.BsonRegularExpression;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.types.Binary;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
@@ -99,6 +109,11 @@ class MongoAgentTest {
|
|||||||
Files.writeString(clientKeyPath, pkcs8Pem);
|
Files.writeString(clientKeyPath, pkcs8Pem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void resetFindCursors() {
|
||||||
|
MongoAgent.resetFindCursorsForTests();
|
||||||
|
}
|
||||||
|
|
||||||
// ─── existing tests ───
|
// ─── existing tests ───
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -128,6 +143,7 @@ class MongoAgentTest {
|
|||||||
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_CLONE_COLLECTION));
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_CLONE_COLLECTION));
|
||||||
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_RUN_COMMAND));
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_RUN_COMMAND));
|
||||||
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_INSERT_DOCUMENTS));
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_INSERT_DOCUMENTS));
|
||||||
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_FIND_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -150,6 +166,7 @@ class MongoAgentTest {
|
|||||||
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_CLONE_COLLECTION));
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_CLONE_COLLECTION));
|
||||||
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_RUN_COMMAND));
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_RUN_COMMAND));
|
||||||
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_INSERT_DOCUMENTS));
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_INSERT_DOCUMENTS));
|
||||||
|
assertTrue(containsCapability(result.getAsJsonArray("capabilities"), AgentProtocol.CAPABILITY_MONGO_FIND_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -894,6 +911,10 @@ class MongoAgentTest {
|
|||||||
assertEquals("12", batches.get(0).get(1).getString("refid"));
|
assertEquals("12", batches.get(0).get(1).getString("refid"));
|
||||||
assertTrue(AgentProtocol.MONGO_LEGACY_METHODS.contains(AgentProtocol.MONGO_METHOD_INSERT_DOCUMENTS));
|
assertTrue(AgentProtocol.MONGO_LEGACY_METHODS.contains(AgentProtocol.MONGO_METHOD_INSERT_DOCUMENTS));
|
||||||
assertTrue(AgentProtocol.MONGO_LEGACY_CAPABILITIES.contains(AgentProtocol.CAPABILITY_MONGO_INSERT_DOCUMENTS));
|
assertTrue(AgentProtocol.MONGO_LEGACY_CAPABILITIES.contains(AgentProtocol.CAPABILITY_MONGO_INSERT_DOCUMENTS));
|
||||||
|
assertTrue(AgentProtocol.MONGO_LEGACY_CAPABILITIES.contains(AgentProtocol.CAPABILITY_MONGO_FIND_CURSOR));
|
||||||
|
assertTrue(AgentProtocol.MONGO_LEGACY_METHODS.contains(AgentProtocol.MONGO_METHOD_START_FIND_CURSOR));
|
||||||
|
assertTrue(AgentProtocol.MONGO_LEGACY_METHODS.contains(AgentProtocol.MONGO_METHOD_FETCH_FIND_CURSOR));
|
||||||
|
assertTrue(AgentProtocol.MONGO_LEGACY_METHODS.contains(AgentProtocol.MONGO_METHOD_CLOSE_FIND_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -939,6 +960,293 @@ class MongoAgentTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void documentForWritePreservesExtendedJsonBsonTypes() {
|
||||||
|
Document document = MongoAgent.documentForWrite(
|
||||||
|
"{\"_id\":{\"$oid\":\"507f1f77bcf86cd799439011\"},"
|
||||||
|
+ "\"count\":{\"$numberLong\":\"9007199254740993\"},"
|
||||||
|
+ "\"when\":{\"$date\":\"2020-01-02T03:04:05.000Z\"}}"
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(new ObjectId("507f1f77bcf86cd799439011"), document.getObjectId("_id"));
|
||||||
|
assertEquals(9007199254740993L, document.get("count"));
|
||||||
|
assertTrue(document.get("when") instanceof Date);
|
||||||
|
assertEquals(Date.from(java.time.Instant.parse("2020-01-02T03:04:05.000Z")), document.getDate("when"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertDocumentsRpcHonoursExplicitUnorderedInserts() {
|
||||||
|
List<List<Document>> batches = new ArrayList<>();
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
List<Boolean> ordered = new ArrayList<>();
|
||||||
|
MongoClient client = recordingInsertMongoClient(calls, batches, ordered);
|
||||||
|
|
||||||
|
JsonObject params = new JsonObject();
|
||||||
|
params.addProperty("database", "app");
|
||||||
|
params.addProperty("collection", "users");
|
||||||
|
params.addProperty("docs_json", "[{\"name\":\"Ada\"}]");
|
||||||
|
params.addProperty("ordered", false);
|
||||||
|
JsonObject request = new JsonObject();
|
||||||
|
request.addProperty("jsonrpc", "2.0");
|
||||||
|
request.addProperty("id", 44);
|
||||||
|
request.addProperty("method", "insert_documents");
|
||||||
|
request.add("params", params);
|
||||||
|
|
||||||
|
JsonObject response = JsonParser.parseString(MongoAgent.handleRequest(request.toString(), client)).getAsJsonObject();
|
||||||
|
|
||||||
|
assertFalse(response.has("error"), response.toString());
|
||||||
|
assertEquals(List.of(false), ordered);
|
||||||
|
assertEquals(1, response.getAsJsonObject("result").get("affected_rows").getAsInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertDocumentsRpcPreservesExtendedJsonTypesInTheInsertManyBatch() {
|
||||||
|
List<List<Document>> batches = new ArrayList<>();
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
MongoClient client = recordingInsertMongoClient(calls, batches);
|
||||||
|
String documents = "[{\"_id\":{\"$oid\":\"507f1f77bcf86cd799439011\"},"
|
||||||
|
+ "\"count\":{\"$numberLong\":\"9007199254740993\"}}]";
|
||||||
|
|
||||||
|
JsonObject response = insertDocumentsRpc(client, 45, "users", documents);
|
||||||
|
|
||||||
|
assertFalse(response.has("error"), response.toString());
|
||||||
|
assertEquals(1, batches.size());
|
||||||
|
Document written = batches.get(0).get(0);
|
||||||
|
assertEquals(new ObjectId("507f1f77bcf86cd799439011"), written.getObjectId("_id"));
|
||||||
|
assertEquals(9007199254740993L, written.get("count"));
|
||||||
|
assertTrue(written.get("count") instanceof Long);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertDocumentsRpcParsesCanonicalBinaryAndRegularExpression() {
|
||||||
|
List<List<Document>> batches = new ArrayList<>();
|
||||||
|
MongoClient client = recordingInsertMongoClient(new ArrayList<>(), batches);
|
||||||
|
String documents = "[{\"bin\":{\"$binary\":{\"base64\":\"AQID\",\"subType\":\"00\"}},"
|
||||||
|
+ "\"re\":{\"$regularExpression\":{\"pattern\":\"^test$\",\"options\":\"i\"}}}]";
|
||||||
|
|
||||||
|
JsonObject response = insertDocumentsRpc(client, 46, "users", documents);
|
||||||
|
|
||||||
|
assertFalse(response.has("error"), response.toString());
|
||||||
|
Document written = batches.get(0).get(0);
|
||||||
|
assertTrue(written.get("bin") instanceof Binary, String.valueOf(written.get("bin")));
|
||||||
|
Binary binary = (Binary) written.get("bin");
|
||||||
|
assertEquals(0, binary.getType());
|
||||||
|
assertArrayEquals(new byte[] {1, 2, 3}, binary.getData());
|
||||||
|
assertTrue(written.get("re") instanceof BsonRegularExpression, String.valueOf(written.get("re")));
|
||||||
|
BsonRegularExpression regex = (BsonRegularExpression) written.get("re");
|
||||||
|
assertEquals("^test$", regex.getPattern());
|
||||||
|
assertEquals("i", regex.getOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bulkInsertResultKeepsInsertedCountAndPerDocumentErrors() {
|
||||||
|
BulkWriteResult writeResult = BulkWriteResult.acknowledged(1, 0, 0, 0, List.of());
|
||||||
|
MongoBulkWriteException error = new MongoBulkWriteException(
|
||||||
|
writeResult,
|
||||||
|
List.of(new BulkWriteError(11000, "E11000 duplicate key", new BsonDocument(), 1)),
|
||||||
|
null,
|
||||||
|
new ServerAddress()
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, Object> result = MongoAgent.bulkInsertResult(error);
|
||||||
|
|
||||||
|
assertEquals(1, result.get("affected_rows"));
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Map<String, Object>> errors = (List<Map<String, Object>>) result.get("errors");
|
||||||
|
assertEquals(1, errors.size());
|
||||||
|
assertEquals(1, errors.get(0).get("index"));
|
||||||
|
assertEquals(11000, errors.get(0).get("code"));
|
||||||
|
assertEquals("E11000 duplicate key", errors.get(0).get("message"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bulkInsertResultReportsWriteConcernFailures() {
|
||||||
|
// The driver raises MongoBulkWriteException with no write errors when only the write
|
||||||
|
// concern failed, so the batch must not come back looking successful.
|
||||||
|
MongoBulkWriteException error = new MongoBulkWriteException(
|
||||||
|
BulkWriteResult.acknowledged(0, 0, 0, 0, List.of()),
|
||||||
|
List.of(),
|
||||||
|
new WriteConcernError(64, "WriteConcernFailed", "waiting for replication timed out", new BsonDocument()),
|
||||||
|
new ServerAddress()
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, Object> result = MongoAgent.bulkInsertResult(error);
|
||||||
|
|
||||||
|
assertEquals(0, result.get("affected_rows"));
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Map<String, Object>> errors = (List<Map<String, Object>>) result.get("errors");
|
||||||
|
assertEquals(1, errors.size());
|
||||||
|
assertEquals(64, errors.get(0).get("code"));
|
||||||
|
assertEquals("waiting for replication timed out", errors.get(0).get("message"));
|
||||||
|
assertFalse(errors.get(0).containsKey("index"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findCursorRpcPagesExtendedJsonDocumentsThenExhausts() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
List<Document> documents = List.of(
|
||||||
|
new Document("_id", new ObjectId("507f1f77bcf86cd799439011"))
|
||||||
|
.append("n", 1L)
|
||||||
|
.append("bin", new Binary((byte) 0, new byte[] {1, 2, 3}))
|
||||||
|
.append("re", new BsonRegularExpression("^test$", "i")),
|
||||||
|
new Document("_id", new ObjectId("507f1f77bcf86cd799439012")).append("n", 2L)
|
||||||
|
);
|
||||||
|
MongoClient client = recordingFindMongoClient(calls, documents);
|
||||||
|
|
||||||
|
JsonObject start = findCursorRpc(client, 50, "start_find_cursor", cursorParams("users", 1, null));
|
||||||
|
assertFalse(start.has("error"), start.toString());
|
||||||
|
String cursorId = start.getAsJsonObject("result").get("cursor_id").getAsString();
|
||||||
|
assertEquals(1, start.getAsJsonObject("result").get("batch_size").getAsInt());
|
||||||
|
|
||||||
|
JsonObject first = findCursorRpc(client, 51, "fetch_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
assertFalse(first.has("error"), first.toString());
|
||||||
|
assertEquals(1, first.getAsJsonObject("result").getAsJsonArray("documents").size());
|
||||||
|
assertFalse(first.getAsJsonObject("result").get("exhausted").getAsBoolean());
|
||||||
|
JsonObject firstDocument = first.getAsJsonObject("result").getAsJsonArray("documents").get(0).getAsJsonObject();
|
||||||
|
assertEquals(
|
||||||
|
"507f1f77bcf86cd799439011",
|
||||||
|
firstDocument.getAsJsonObject("_id").get("$oid").getAsString()
|
||||||
|
);
|
||||||
|
assertEquals("1", firstDocument.getAsJsonObject("n").get("$numberLong").getAsString());
|
||||||
|
JsonObject binary = firstDocument.getAsJsonObject("bin").getAsJsonObject("$binary");
|
||||||
|
assertEquals("AQID", binary.get("base64").getAsString(), firstDocument.toString());
|
||||||
|
assertEquals("00", binary.get("subType").getAsString(), firstDocument.toString());
|
||||||
|
JsonObject regex = firstDocument.getAsJsonObject("re").getAsJsonObject("$regularExpression");
|
||||||
|
assertEquals("^test$", regex.get("pattern").getAsString(), firstDocument.toString());
|
||||||
|
assertEquals("i", regex.get("options").getAsString(), firstDocument.toString());
|
||||||
|
|
||||||
|
JsonObject second = findCursorRpc(client, 52, "fetch_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
assertFalse(second.has("error"), second.toString());
|
||||||
|
assertEquals(1, second.getAsJsonObject("result").getAsJsonArray("documents").size());
|
||||||
|
assertTrue(second.getAsJsonObject("result").get("exhausted").getAsBoolean());
|
||||||
|
|
||||||
|
JsonObject missing = findCursorRpc(client, 53, "fetch_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
assertTrue(missing.has("error"), missing.toString());
|
||||||
|
assertEquals("Find cursor not found", missing.getAsJsonObject("error").get("message").getAsString());
|
||||||
|
assertTrue(calls.contains("find"));
|
||||||
|
assertTrue(calls.contains("batchSize:1"));
|
||||||
|
assertTrue(calls.contains("iterator"));
|
||||||
|
assertTrue(calls.contains("close"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void closeFindCursorRpcIsIdempotent() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
MongoClient client = recordingFindMongoClient(calls, List.of(new Document("n", 1)));
|
||||||
|
JsonObject start = findCursorRpc(client, 54, "start_find_cursor", cursorParams("users", 10, null));
|
||||||
|
String cursorId = start.getAsJsonObject("result").get("cursor_id").getAsString();
|
||||||
|
|
||||||
|
JsonObject closed = findCursorRpc(client, 55, "close_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
JsonObject again = findCursorRpc(client, 56, "close_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
|
||||||
|
assertFalse(closed.has("error"), closed.toString());
|
||||||
|
assertFalse(again.has("error"), again.toString());
|
||||||
|
assertEquals(1, calls.stream().filter("close"::equals).count());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bsonToCanonicalExtendedJsonKeepsInt64DistinctFromJsonNumber() {
|
||||||
|
JsonObject json = MongoAgent.bsonToCanonicalExtendedJson(
|
||||||
|
new Document("n", 5L)
|
||||||
|
.append("bin", new Binary((byte) 0, new byte[] {1, 2, 3}))
|
||||||
|
.append("re", new BsonRegularExpression("^test$", "i"))
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals("5", json.getAsJsonObject("n").get("$numberLong").getAsString());
|
||||||
|
assertFalse(json.get("n").isJsonPrimitive(), json.toString());
|
||||||
|
JsonObject binary = json.getAsJsonObject("bin").getAsJsonObject("$binary");
|
||||||
|
assertEquals("AQID", binary.get("base64").getAsString(), json.toString());
|
||||||
|
assertEquals("00", binary.get("subType").getAsString(), json.toString());
|
||||||
|
assertFalse(json.getAsJsonObject("bin").has("$type"), json.toString());
|
||||||
|
JsonObject regex = json.getAsJsonObject("re").getAsJsonObject("$regularExpression");
|
||||||
|
assertEquals("^test$", regex.get("pattern").getAsString(), json.toString());
|
||||||
|
assertEquals("i", regex.get("options").getAsString(), json.toString());
|
||||||
|
assertFalse(json.getAsJsonObject("re").has("$regex"), json.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void disconnectClosesOpenFindCursors() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
MongoClient client = recordingFindMongoClient(calls, List.of(new Document("n", 1L)));
|
||||||
|
JsonObject start = findCursorRpc(client, 57, "start_find_cursor", cursorParams("users", 10, null));
|
||||||
|
String cursorId = start.getAsJsonObject("result").get("cursor_id").getAsString();
|
||||||
|
|
||||||
|
JsonObject disconnect = JsonParser.parseString(MongoAgent.handleRequest(
|
||||||
|
"{\"jsonrpc\":\"2.0\",\"id\":58,\"method\":\"disconnect\",\"params\":{}}"
|
||||||
|
)).getAsJsonObject();
|
||||||
|
JsonObject fetch = findCursorRpc(client, 59, "fetch_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
|
||||||
|
assertFalse(disconnect.has("error"), disconnect.toString());
|
||||||
|
assertTrue(fetch.has("error"), fetch.toString());
|
||||||
|
assertEquals("Find cursor not found", fetch.getAsJsonObject("error").get("message").getAsString());
|
||||||
|
assertTrue(calls.contains("close"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fetchFailureReleasesTheCursorSlot() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
MongoCursor<Document> failing = new MongoCursor<>() {
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
calls.add("close");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
throw new IllegalStateException("cursor id 42 not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document next() {
|
||||||
|
throw new IllegalStateException("cursor id 42 not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document tryNext() {
|
||||||
|
throw new IllegalStateException("cursor id 42 not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerAddress getServerAddress() {
|
||||||
|
return new ServerAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public com.mongodb.ServerCursor getServerCursor() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MongoClient client = findMongoClientWithCursor(calls, failing);
|
||||||
|
|
||||||
|
JsonObject start = findCursorRpc(client, 60, "start_find_cursor", cursorParams("users", 10, null));
|
||||||
|
String cursorId = start.getAsJsonObject("result").get("cursor_id").getAsString();
|
||||||
|
JsonObject fetch = findCursorRpc(client, 61, "fetch_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
JsonObject again = findCursorRpc(client, 62, "fetch_find_cursor", cursorParams(null, 0, cursorId));
|
||||||
|
|
||||||
|
assertTrue(fetch.has("error"), fetch.toString());
|
||||||
|
assertTrue(calls.contains("close"));
|
||||||
|
// A dead cursor is dropped, so the slot is free again instead of being held until disconnect.
|
||||||
|
assertEquals("Find cursor not found", again.getAsJsonObject("error").get("message").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void startFindCursorEnforcesPerOwnerBudget() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
MongoClient client = recordingFindMongoClient(calls, List.of(new Document("n", 1)));
|
||||||
|
|
||||||
|
for (int index = 0; index < 16; index++) {
|
||||||
|
JsonObject started = findCursorRpc(client, 100 + index, "start_find_cursor", cursorParams("users", 100, null));
|
||||||
|
assertFalse(started.has("error"), started.toString());
|
||||||
|
}
|
||||||
|
JsonObject rejected = findCursorRpc(client, 200, "start_find_cursor", cursorParams("users", 100, null));
|
||||||
|
|
||||||
|
assertTrue(rejected.has("error"), rejected.toString());
|
||||||
|
assertEquals(
|
||||||
|
"MongoDB find cursor limit reached: 16",
|
||||||
|
rejected.getAsJsonObject("error").get("message").getAsString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateDocumentsRpcUsesDocumentOverloads() {
|
void updateDocumentsRpcUsesDocumentOverloads() {
|
||||||
List<String> calls = new ArrayList<>();
|
List<String> calls = new ArrayList<>();
|
||||||
@@ -1458,9 +1766,140 @@ class MongoAgentTest {
|
|||||||
return JsonParser.parseString(MongoAgent.handleRequest(request.toString(), client)).getAsJsonObject();
|
return JsonParser.parseString(MongoAgent.handleRequest(request.toString(), client)).getAsJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JsonObject cursorParams(String collection, int batchSize, String cursorId) {
|
||||||
|
JsonObject params = new JsonObject();
|
||||||
|
params.addProperty("database", "app");
|
||||||
|
if (collection != null) {
|
||||||
|
params.addProperty("collection", collection);
|
||||||
|
}
|
||||||
|
if (batchSize > 0) {
|
||||||
|
params.addProperty("batch_size", batchSize);
|
||||||
|
}
|
||||||
|
if (cursorId != null) {
|
||||||
|
params.addProperty("cursor_id", cursorId);
|
||||||
|
params.addProperty("limit", 1);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject findCursorRpc(MongoClient client, int id, String method, JsonObject params) {
|
||||||
|
JsonObject request = new JsonObject();
|
||||||
|
request.addProperty("jsonrpc", "2.0");
|
||||||
|
request.addProperty("id", id);
|
||||||
|
request.addProperty("method", method);
|
||||||
|
request.add("params", params);
|
||||||
|
return JsonParser.parseString(MongoAgent.handleRequest(request.toString(), client)).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static MongoClient recordingFindMongoClient(List<String> calls, List<Document> documents) {
|
||||||
|
MongoCursor<Document> cursor = new MongoCursor<>() {
|
||||||
|
private int index;
|
||||||
|
private boolean closed;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
closed = true;
|
||||||
|
calls.add("close");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return !closed && index < documents.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document next() {
|
||||||
|
return documents.get(index++);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document tryNext() {
|
||||||
|
return hasNext() ? next() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public com.mongodb.ServerAddress getServerAddress() {
|
||||||
|
return new com.mongodb.ServerAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public com.mongodb.ServerCursor getServerCursor() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return findMongoClientWithCursor(calls, cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Same proxy chain as [recordingFindMongoClient], for cursors that fail mid-iteration. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static MongoClient findMongoClientWithCursor(List<String> calls, MongoCursor<Document> cursor) {
|
||||||
|
FindIterable<Document> iterable = (FindIterable<Document>) Proxy.newProxyInstance(
|
||||||
|
FindIterable.class.getClassLoader(),
|
||||||
|
new Class<?>[] {FindIterable.class},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "batchSize" -> {
|
||||||
|
calls.add("batchSize:" + args[0]);
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
case "projection", "sort", "collation", "filter", "skip", "limit" -> {
|
||||||
|
calls.add(method.getName());
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
case "iterator" -> {
|
||||||
|
calls.add("iterator");
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
default -> throw new UnsupportedOperationException(method.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
MongoCollection<Document> collection = (MongoCollection<Document>) Proxy.newProxyInstance(
|
||||||
|
MongoCollection.class.getClassLoader(),
|
||||||
|
new Class<?>[] {MongoCollection.class},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
if ("find".equals(method.getName())) {
|
||||||
|
calls.add("find");
|
||||||
|
return iterable;
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException(method.getName());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
MongoDatabase database = (MongoDatabase) Proxy.newProxyInstance(
|
||||||
|
MongoDatabase.class.getClassLoader(),
|
||||||
|
new Class<?>[] {MongoDatabase.class},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
if ("getCollection".equals(method.getName())) {
|
||||||
|
calls.add("getCollection:" + args[0]);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException(method.getName());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return (MongoClient) Proxy.newProxyInstance(
|
||||||
|
MongoClient.class.getClassLoader(),
|
||||||
|
new Class<?>[] {MongoClient.class},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
if ("getDatabase".equals(method.getName())) {
|
||||||
|
calls.add("getDatabase:" + args[0]);
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException(method.getName());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static MongoClient recordingInsertMongoClient(
|
private static MongoClient recordingInsertMongoClient(
|
||||||
List<String> calls, List<List<Document>> batches
|
List<String> calls, List<List<Document>> batches
|
||||||
|
) {
|
||||||
|
return recordingInsertMongoClient(calls, batches, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static MongoClient recordingInsertMongoClient(
|
||||||
|
List<String> calls, List<List<Document>> batches, List<Boolean> ordered
|
||||||
) {
|
) {
|
||||||
MongoCollection<Document> collection = (MongoCollection<Document>) Proxy.newProxyInstance(
|
MongoCollection<Document> collection = (MongoCollection<Document>) Proxy.newProxyInstance(
|
||||||
MongoCollection.class.getClassLoader(),
|
MongoCollection.class.getClassLoader(),
|
||||||
@@ -1470,6 +1909,13 @@ class MongoAgentTest {
|
|||||||
List<Document> batch = ((List<Document>) args[0]).stream().map(Document::new).toList();
|
List<Document> batch = ((List<Document>) args[0]).stream().map(Document::new).toList();
|
||||||
batches.add(batch);
|
batches.add(batch);
|
||||||
calls.add("insertMany:" + batch.size());
|
calls.add("insertMany:" + batch.size());
|
||||||
|
if (ordered != null) {
|
||||||
|
boolean isOrdered = true;
|
||||||
|
if (args.length > 1 && args[1] instanceof InsertManyOptions options) {
|
||||||
|
isOrdered = options.isOrdered();
|
||||||
|
}
|
||||||
|
ordered.add(isOrdered);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException(method.getName());
|
throw new UnsupportedOperationException(method.getName());
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { executeWithProductionContextGuard } from "@/lib/database/productionExec
|
|||||||
import { TABLE_IMPORT_ENCODING_OPTIONS } from "@/lib/table/tableImport";
|
import { TABLE_IMPORT_ENCODING_OPTIONS } from "@/lib/table/tableImport";
|
||||||
import { importPreviewInput, importSourceDisplayName, importTextDelimiterForName, uploadedImportSourceFromPreview, type UploadedImportSource } from "@/lib/import/importSource";
|
import { importPreviewInput, importSourceDisplayName, importTextDelimiterForName, uploadedImportSourceFromPreview, type UploadedImportSource } from "@/lib/import/importSource";
|
||||||
import { useToast } from "@/composables/useToast";
|
import { useToast } from "@/composables/useToast";
|
||||||
|
import { translateBackendError } from "@/i18n/backend-errors";
|
||||||
import * as api from "@/lib/backend/api";
|
import * as api from "@/lib/backend/api";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
@@ -267,7 +268,7 @@ async function startImport() {
|
|||||||
running.value = false;
|
running.value = false;
|
||||||
open.value = false;
|
open.value = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorMessage.value = error instanceof Error ? error.message : String(error);
|
errorMessage.value = translateBackendError(t, error);
|
||||||
running.value = false;
|
running.value = false;
|
||||||
} finally {
|
} finally {
|
||||||
cancelling.value = false;
|
cancelling.value = false;
|
||||||
|
|||||||
@@ -101,6 +101,34 @@ const CASES: { name: string; message: string; key: string; params?: Record<strin
|
|||||||
message: "Streaming export needs a result-set session, but this driver returned no session_id.",
|
message: "Streaming export needs a result-set session, but this driver returned no session_id.",
|
||||||
key: "exportProgress.agentSessionMissing",
|
key: "exportProgress.agentSessionMissing",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "MongoDB Legacy insertMany unsupported",
|
||||||
|
message: "MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver",
|
||||||
|
key: "mongo.import.legacyInsertUnsupported",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// crates/dbx-core/src/mongodb_import_export.rs attributes a batch-level failure to a row.
|
||||||
|
name: "MongoDB Legacy insertMany unsupported on a located row",
|
||||||
|
message: "row 1: MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver",
|
||||||
|
key: "mongo.import.legacyInsertUnsupported",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "MongoDB Legacy partial insert",
|
||||||
|
message: "MongoDB Legacy Agent rejected 2 of 500 documents: E11000 duplicate key error collection: app.users",
|
||||||
|
key: "mongo.insert.partialFailure",
|
||||||
|
params: { failed: "2", total: "500", message: "E11000 duplicate key error collection: app.users" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "MongoDB Legacy export cursor invalid",
|
||||||
|
message: "MongoDB Legacy Agent returned an invalid find cursor",
|
||||||
|
key: "mongo.import.legacyCursorInvalid",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Agent-raised messages reach the frontend through the "Agent RPC error (<code>): " envelope.
|
||||||
|
name: "MongoDB Legacy export cursor expired",
|
||||||
|
message: "Agent RPC error (-1): Find cursor not found",
|
||||||
|
key: "mongo.import.legacyCursorInvalid",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "DuckDB draining",
|
name: "DuckDB draining",
|
||||||
message: "The previous DuckDB query is still stopping. Please try again shortly.",
|
message: "The previous DuckDB query is still stopping. Please try again shortly.",
|
||||||
@@ -401,6 +429,17 @@ describe("backend error translation", () => {
|
|||||||
expect(translateBackendError(t, error)).toBe(`${t("backendErrors.legacy")}\n\nlegacy backend failure`);
|
expect(translateBackendError(t, error)).toBe(`${t("backendErrors.legacy")}\n\nlegacy backend failure`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tauri wraps every backend rejection in a legacy envelope, so a message the catalog knows must
|
||||||
|
// still be phrased by the catalog rather than surfaced as raw English under a generic summary.
|
||||||
|
test("phrases a known message that arrived inside a legacy envelope", () => {
|
||||||
|
const t = translatorFor("zh-CN");
|
||||||
|
const wrap = (message: string) => new BackendErrorException(message);
|
||||||
|
|
||||||
|
expect(translateBackendError(t, wrap("row 1: MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver"))).toBe(t("mongo.import.legacyInsertUnsupported"));
|
||||||
|
expect(translateBackendError(t, wrap("Agent RPC error (-1): Find cursor not found"))).toBe(t("mongo.import.legacyCursorInvalid"));
|
||||||
|
expect(translateBackendError(t, wrap("MongoDB Legacy Agent rejected 2 of 500 documents: E11000 duplicate key"))).toBe(t("mongo.insert.partialFailure", { failed: "2", total: "500", message: "E11000 duplicate key" }));
|
||||||
|
});
|
||||||
|
|
||||||
test("keeps an explicit original detail when a structured legacy error omits detail", () => {
|
test("keeps an explicit original detail when a structured legacy error omits detail", () => {
|
||||||
const t = translatorFor("zh-CN");
|
const t = translatorFor("zh-CN");
|
||||||
const error = {
|
const error = {
|
||||||
@@ -529,6 +568,9 @@ describe("backend error wording is pinned to the Rust sources", () => {
|
|||||||
test.each([
|
test.each([
|
||||||
["crates/dbx-core/src/query_result_export.rs", "Streaming export is unsupported for this query. Simplify it or use a supported driver."],
|
["crates/dbx-core/src/query_result_export.rs", "Streaming export is unsupported for this query. Simplify it or use a supported driver."],
|
||||||
["crates/dbx-core/src/query_result_export.rs", "Streaming export needs a result-set session, but this driver returned no session_id."],
|
["crates/dbx-core/src/query_result_export.rs", "Streaming export needs a result-set session, but this driver returned no session_id."],
|
||||||
|
["crates/dbx-core/src/mongodb_import_export.rs", "MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver"],
|
||||||
|
["crates/dbx-core/src/mongodb_import_export.rs", "MongoDB Legacy Agent returned an invalid find cursor"],
|
||||||
|
["crates/dbx-core/src/mongo_ops.rs", "MongoDB Legacy Agent rejected "],
|
||||||
["crates/dbx-core/src/agent_service.rs", "Failed to remove the old JRE directory: "],
|
["crates/dbx-core/src/agent_service.rs", "Failed to remove the old JRE directory: "],
|
||||||
["crates/dbx-core/src/agent_service.rs", "is in use by drivers: "],
|
["crates/dbx-core/src/agent_service.rs", "is in use by drivers: "],
|
||||||
["crates/dbx-core/src/agent_service.rs", "agent-registry.json not found in the ZIP; not a valid offline driver package."],
|
["crates/dbx-core/src/agent_service.rs", "agent-registry.json not found in the ZIP; not a valid offline driver package."],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GENERIC_TRANSPORT_FAILURE_MESSAGE, normalizeBackendError, sanitizeBackendErrorMessage, type BackendError } from "@/lib/backend/errorUtils";
|
import { GENERIC_TRANSPORT_FAILURE_MESSAGE, LEGACY_BACKEND_ERROR_CODE, normalizeBackendError, sanitizeBackendErrorMessage, type BackendError } from "@/lib/backend/errorUtils";
|
||||||
import { PHOENIX_DRIVER_NOT_INSTALLED_ERROR, PHOENIX_JDBC_PLUGIN_NOT_INSTALLED_ERROR } from "@/lib/database/phoenixConnection";
|
import { PHOENIX_DRIVER_NOT_INSTALLED_ERROR, PHOENIX_JDBC_PLUGIN_NOT_INSTALLED_ERROR } from "@/lib/database/phoenixConnection";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +127,17 @@ const patterns: [RegExp, string][] = [
|
|||||||
|
|
||||||
// Query result export limits (crates/dbx-core/src/query_result_export.rs)
|
// Query result export limits (crates/dbx-core/src/query_result_export.rs)
|
||||||
[/^Streaming export is unsupported for this query\. Simplify it or use a supported driver\.$/, "exportProgress.streamingUnsupported"],
|
[/^Streaming export is unsupported for this query\. Simplify it or use a supported driver\.$/, "exportProgress.streamingUnsupported"],
|
||||||
|
// MongoDB Legacy agent failures: messages raised by the agent arrive wrapped in "Agent RPC
|
||||||
|
// error (<code>): ", and the import path prefixes the row a batch-level failure belongs to.
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver$/, "mongo.import.legacyInsertUnsupported"],
|
||||||
|
[/^(?:row \d+: )?MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver$/, "mongo.import.legacyInsertUnsupported"],
|
||||||
|
[/^MongoDB Legacy Agent rejected (\d+) of (\d+) documents: ([\s\S]+)$/, "mongo.insert.partialFailure"],
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?MongoDB Legacy Agent returned an invalid find cursor$/, "mongo.import.legacyCursorInvalid"],
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?MongoDB Legacy Agent returned an invalid find cursor page$/, "mongo.import.legacyCursorInvalid"],
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?Find cursor not found$/, "mongo.import.legacyCursorInvalid"],
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?MongoDB Legacy Agent does not support type-preserving export; upgrade or reinstall the MongoDB Legacy driver$/, "mongo.import.legacyExportUnsupported"],
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?MongoDB Legacy Agent returned the same export page twice; upgrade or reinstall the MongoDB Legacy driver$/, "mongo.import.legacyExportStalled"],
|
||||||
|
[/^(?:Agent RPC error \(-?\d+\): )?MongoDB Legacy Agent returned a document without _id$/, "mongo.import.legacyExportMissingId"],
|
||||||
[/^Streaming export needs a result-set session, but this driver returned no session_id\.$/, "exportProgress.agentSessionMissing"],
|
[/^Streaming export needs a result-set session, but this driver returned no session_id\.$/, "exportProgress.agentSessionMissing"],
|
||||||
|
|
||||||
// Legacy bundled DuckDB error kept for compatibility with older backends.
|
// Legacy bundled DuckDB error kept for compatibility with older backends.
|
||||||
@@ -157,6 +168,7 @@ const paramNames: Record<string, string | string[]> = {
|
|||||||
"connection.jreNotInstalled": "jre",
|
"connection.jreNotInstalled": "jre",
|
||||||
"ai.configNameExists": "name",
|
"ai.configNameExists": "name",
|
||||||
"nacos.nacosManagedNamespaceAccessDenied": "detail",
|
"nacos.nacosManagedNamespaceAccessDenied": "detail",
|
||||||
|
"mongo.insert.partialFailure": ["failed", "total", "message"],
|
||||||
"settings.tunnelsHttpTestSuccess": "code",
|
"settings.tunnelsHttpTestSuccess": "code",
|
||||||
"settings.tunnelsProxyTimedOut": "duration",
|
"settings.tunnelsProxyTimedOut": "duration",
|
||||||
"settings.tunnelsProxyConnectFailed": "error",
|
"settings.tunnelsProxyConnectFailed": "error",
|
||||||
@@ -188,27 +200,11 @@ function usableFallbackDetail(value: unknown): string | undefined {
|
|||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateStructuredBackendError(t: BackendErrorTranslate, error: BackendError, fallbackDetail?: unknown): string {
|
/**
|
||||||
const translated = t(error.messageKey, error.messageParams);
|
* Resolves a raw backend message through the known-message catalog, or `null` when the message is
|
||||||
const summary = translated !== error.messageKey ? translated : t("backendErrors.unknown");
|
* not one the UI knows how to phrase.
|
||||||
let detail = error.detail ? sanitizeBackendErrorMessage(error.detail).trim() : usableFallbackDetail(fallbackDetail);
|
*/
|
||||||
// Callers may pass an already-composited "summary\n\noriginal" cell as the
|
function translateKnownMessage(t: BackendErrorTranslate, message: string): string | null {
|
||||||
// fallback (query history re-translation of a failed result grid); strip the
|
|
||||||
// repeated summary so the message stays singular.
|
|
||||||
if (detail && detail.startsWith(`${summary}\n\n`)) {
|
|
||||||
detail = detail.slice(summary.length + 2).trim() || undefined;
|
|
||||||
}
|
|
||||||
const rawAdapterCode = error.diagnostics?.adapterCode;
|
|
||||||
const adapterCode = typeof rawAdapterCode === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/.test(rawAdapterCode) ? rawAdapterCode : undefined;
|
|
||||||
const diagnosticDetail = detail && adapterCode ? `[${adapterCode}] ${detail}` : (detail ?? adapterCode);
|
|
||||||
return diagnosticDetail && diagnosticDetail !== summary ? `${summary}\n\n${diagnosticDetail}` : summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function translateBackendError(t: BackendErrorTranslate, error: unknown, fallbackDetail?: unknown): string {
|
|
||||||
const structured = normalizeBackendError(error);
|
|
||||||
if (structured) return translateStructuredBackendError(t, structured, fallbackDetail);
|
|
||||||
|
|
||||||
const message = backendErrorMessage(error);
|
|
||||||
const exactKey = exactMessageKeys[message];
|
const exactKey = exactMessageKeys[message];
|
||||||
if (exactKey) return t(exactKey);
|
if (exactKey) return t(exactKey);
|
||||||
|
|
||||||
@@ -238,5 +234,35 @@ export function translateBackendError(t: BackendErrorTranslate, error: unknown,
|
|||||||
return t(key);
|
return t(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return message;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function translateStructuredBackendError(t: BackendErrorTranslate, error: BackendError, fallbackDetail?: unknown): string {
|
||||||
|
const translated = t(error.messageKey, error.messageParams);
|
||||||
|
const summary = translated !== error.messageKey ? translated : t("backendErrors.unknown");
|
||||||
|
let detail = error.detail ? sanitizeBackendErrorMessage(error.detail).trim() : usableFallbackDetail(fallbackDetail);
|
||||||
|
// Callers may pass an already-composited "summary\n\noriginal" cell as the
|
||||||
|
// fallback (query history re-translation of a failed result grid); strip the
|
||||||
|
// repeated summary so the message stays singular.
|
||||||
|
if (detail && detail.startsWith(`${summary}\n\n`)) {
|
||||||
|
detail = detail.slice(summary.length + 2).trim() || undefined;
|
||||||
|
}
|
||||||
|
// An unclassified message still goes through the same catalog the raw transports use, so a
|
||||||
|
// message DBX knows reads the same whether it arrived wrapped or bare.
|
||||||
|
if (error.code === LEGACY_BACKEND_ERROR_CODE && detail) {
|
||||||
|
const known = translateKnownMessage(t, detail);
|
||||||
|
if (known) return known;
|
||||||
|
}
|
||||||
|
const rawAdapterCode = error.diagnostics?.adapterCode;
|
||||||
|
const adapterCode = typeof rawAdapterCode === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/.test(rawAdapterCode) ? rawAdapterCode : undefined;
|
||||||
|
const diagnosticDetail = detail && adapterCode ? `[${adapterCode}] ${detail}` : (detail ?? adapterCode);
|
||||||
|
return diagnosticDetail && diagnosticDetail !== summary ? `${summary}\n\n${diagnosticDetail}` : summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function translateBackendError(t: BackendErrorTranslate, error: unknown, fallbackDetail?: unknown): string {
|
||||||
|
const structured = normalizeBackendError(error);
|
||||||
|
if (structured) return translateStructuredBackendError(t, structured, fallbackDetail);
|
||||||
|
|
||||||
|
const message = backendErrorMessage(error);
|
||||||
|
return translateKnownMessage(t, message) ?? message;
|
||||||
}
|
}
|
||||||
@@ -5406,6 +5406,11 @@ export default withEnglishFallback({
|
|||||||
start: "İdxal et",
|
start: "İdxal et",
|
||||||
success: "{count} sənəd idxal olundu",
|
success: "{count} sənəd idxal olundu",
|
||||||
stillRunning: "İdxal hələ işləyir. Yeni paketləri dayandırmaq üçün Ləğv et düyməsini istifadə edin.",
|
stillRunning: "İdxal hələ işləyir. Yeni paketləri dayandırmaq üçün Ləğv et düyməsini istifadə edin.",
|
||||||
|
legacyInsertUnsupported: "Bu MongoDB Legacy sürücüsü sənədləri toplu daxil edə bilmir. MongoDB Legacy sürücüsünü yeniləyin və ya yenidən quraşdırın.",
|
||||||
|
legacyCursorInvalid: "MongoDB Legacy ixrac kursoru artıq əlçatan deyil. İxracı yenidən cəhd edin.",
|
||||||
|
legacyExportUnsupported: "Bu MongoDB Legacy sürücüsü ixrac zamanı BSON tiplərini qorumağı dəstəkləmir. MongoDB Legacy sürücüsünü yeniləyin və ya yenidən quraşdırın.",
|
||||||
|
legacyExportStalled: "MongoDB Legacy sürücüsü eyni ixrac səhifəsini iki dəfə qaytardı. Sürücünü yeniləyin və ya yenidən quraşdırıb ixracı yenidən cəhd edin.",
|
||||||
|
legacyExportMissingId: "MongoDB Legacy sürücüsü _id olmayan sənəd qaytardı; ixrac təhlükəsiz şəkildə səhifələnə bilmir.",
|
||||||
rowsRead: "Oxunan sətirlər",
|
rowsRead: "Oxunan sətirlər",
|
||||||
rowsInserted: "Əlavə olunan sətirlər",
|
rowsInserted: "Əlavə olunan sətirlər",
|
||||||
rowsFailed: "Uğursuz sətirlər",
|
rowsFailed: "Uğursuz sətirlər",
|
||||||
@@ -5417,6 +5422,9 @@ export default withEnglishFallback({
|
|||||||
done: "Bitdi",
|
done: "Bitdi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "MongoDB Legacy drayveri {total} sənədin {failed} hissəsini rədd etdi: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementAz,
|
...meilisearchManagementAz,
|
||||||
|
|||||||
@@ -5558,6 +5558,11 @@ export default {
|
|||||||
start: "Import",
|
start: "Import",
|
||||||
success: "Imported {count} documents",
|
success: "Imported {count} documents",
|
||||||
stillRunning: "Import is still running. Use Cancel to stop new batches.",
|
stillRunning: "Import is still running. Use Cancel to stop new batches.",
|
||||||
|
legacyInsertUnsupported: "This MongoDB Legacy driver cannot insert documents in bulk. Upgrade or reinstall the MongoDB Legacy driver.",
|
||||||
|
legacyCursorInvalid: "The MongoDB Legacy export cursor is no longer available. Retry the export.",
|
||||||
|
legacyExportUnsupported: "This MongoDB Legacy driver cannot preserve BSON types during export. Upgrade or reinstall the MongoDB Legacy driver.",
|
||||||
|
legacyExportStalled: "The MongoDB Legacy driver returned the same export page twice. Upgrade or reinstall the MongoDB Legacy driver and retry the export.",
|
||||||
|
legacyExportMissingId: "The MongoDB Legacy driver returned a document without _id, so the export cannot page safely.",
|
||||||
rowsRead: "Rows read",
|
rowsRead: "Rows read",
|
||||||
rowsInserted: "Rows inserted",
|
rowsInserted: "Rows inserted",
|
||||||
rowsFailed: "Rows failed",
|
rowsFailed: "Rows failed",
|
||||||
@@ -5569,6 +5574,9 @@ export default {
|
|||||||
done: "Done",
|
done: "Done",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "The MongoDB Legacy driver rejected {failed} of {total} documents: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementEn,
|
...meilisearchManagementEn,
|
||||||
|
|||||||
@@ -5260,6 +5260,11 @@ export default withEnglishFallback({
|
|||||||
start: "Importar",
|
start: "Importar",
|
||||||
success: "Se importaron {count} documentos",
|
success: "Se importaron {count} documentos",
|
||||||
stillRunning: "La importación sigue en curso. Use Cancelar para detener nuevos lotes.",
|
stillRunning: "La importación sigue en curso. Use Cancelar para detener nuevos lotes.",
|
||||||
|
legacyInsertUnsupported: "Este controlador MongoDB Legacy no puede insertar documentos en lote. Actualice o reinstale el controlador MongoDB Legacy.",
|
||||||
|
legacyCursorInvalid: "El cursor de exportación de MongoDB Legacy ya no está disponible. Vuelva a intentar la exportación.",
|
||||||
|
legacyExportUnsupported: "Este controlador MongoDB Legacy no admite la preservación de tipos BSON al exportar. Actualice o reinstale el controlador MongoDB Legacy.",
|
||||||
|
legacyExportStalled: "El controlador MongoDB Legacy devolvió dos veces la misma página de exportación. Actualice o reinstale el controlador y vuelva a intentar la exportación.",
|
||||||
|
legacyExportMissingId: "El controlador MongoDB Legacy devolvió un documento sin _id, por lo que la exportación no puede paginar de forma segura.",
|
||||||
rowsRead: "Filas leídas",
|
rowsRead: "Filas leídas",
|
||||||
rowsInserted: "Filas insertadas",
|
rowsInserted: "Filas insertadas",
|
||||||
rowsFailed: "Filas fallidas",
|
rowsFailed: "Filas fallidas",
|
||||||
@@ -5271,6 +5276,9 @@ export default withEnglishFallback({
|
|||||||
done: "Hecho",
|
done: "Hecho",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "El controlador MongoDB Legacy rechazó {failed} de {total} documentos: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementEs,
|
...meilisearchManagementEs,
|
||||||
|
|||||||
@@ -5258,6 +5258,11 @@ export default withEnglishFallback({
|
|||||||
start: "Importa",
|
start: "Importa",
|
||||||
success: "Importati {count} documenti",
|
success: "Importati {count} documenti",
|
||||||
stillRunning: "L'importazione è ancora in esecuzione. Usa Annulla per fermare i nuovi batch.",
|
stillRunning: "L'importazione è ancora in esecuzione. Usa Annulla per fermare i nuovi batch.",
|
||||||
|
legacyInsertUnsupported: "Questo driver MongoDB Legacy non può inserire documenti in blocco. Aggiorna o reinstalla il driver MongoDB Legacy.",
|
||||||
|
legacyCursorInvalid: "Il cursore di esportazione MongoDB Legacy non è più disponibile. Riprova l'esportazione.",
|
||||||
|
legacyExportUnsupported: "Questo driver MongoDB Legacy non supporta la conservazione dei tipi BSON durante l'esportazione. Aggiorna o reinstalla il driver MongoDB Legacy.",
|
||||||
|
legacyExportStalled: "Il driver MongoDB Legacy ha restituito due volte la stessa pagina di esportazione. Aggiorna o reinstalla il driver e riprova l'esportazione.",
|
||||||
|
legacyExportMissingId: "Il driver MongoDB Legacy ha restituito un documento senza _id, quindi l'esportazione non può impaginare in modo sicuro.",
|
||||||
rowsRead: "Righe lette",
|
rowsRead: "Righe lette",
|
||||||
rowsInserted: "Righe inserite",
|
rowsInserted: "Righe inserite",
|
||||||
rowsFailed: "Righe non riuscite",
|
rowsFailed: "Righe non riuscite",
|
||||||
@@ -5269,6 +5274,9 @@ export default withEnglishFallback({
|
|||||||
done: "Completato",
|
done: "Completato",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "Il driver MongoDB Legacy ha rifiutato {failed} di {total} documenti: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementIt,
|
...meilisearchManagementIt,
|
||||||
|
|||||||
@@ -5287,6 +5287,11 @@ export default withEnglishFallback({
|
|||||||
start: "インポート",
|
start: "インポート",
|
||||||
success: "{count} 件のドキュメントをインポートしました",
|
success: "{count} 件のドキュメントをインポートしました",
|
||||||
stillRunning: "インポートは実行中です。以降のバッチを止めるにはキャンセルしてください。",
|
stillRunning: "インポートは実行中です。以降のバッチを止めるにはキャンセルしてください。",
|
||||||
|
legacyInsertUnsupported: "この MongoDB Legacy ドライバーは一括挿入に対応していません。ドライバーをアップグレードまたは再インストールしてください。",
|
||||||
|
legacyCursorInvalid: "MongoDB Legacy のエクスポートカーソルは利用できなくなりました。エクスポートを再試行してください。",
|
||||||
|
legacyExportUnsupported: "この MongoDB Legacy ドライバーはエクスポート時の BSON 型保持に対応していません。ドライバーをアップグレードまたは再インストールしてください。",
|
||||||
|
legacyExportStalled: "MongoDB Legacy ドライバーが同じエクスポートページを 2 回返しました。ドライバーをアップグレードまたは再インストールしてから、エクスポートを再試行してください。",
|
||||||
|
legacyExportMissingId: "MongoDB Legacy ドライバーが _id のないドキュメントを返したため、エクスポートを安全にページングできません。",
|
||||||
rowsRead: "読み取り行数",
|
rowsRead: "読み取り行数",
|
||||||
rowsInserted: "挿入行数",
|
rowsInserted: "挿入行数",
|
||||||
rowsFailed: "失敗行数",
|
rowsFailed: "失敗行数",
|
||||||
@@ -5298,6 +5303,9 @@ export default withEnglishFallback({
|
|||||||
done: "完了",
|
done: "完了",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "MongoDB Legacy ドライバーは {total} 件中 {failed} 件のドキュメントを拒否しました: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementJa,
|
...meilisearchManagementJa,
|
||||||
|
|||||||
@@ -4895,6 +4895,11 @@ export default withEnglishFallback({
|
|||||||
start: "가져오기",
|
start: "가져오기",
|
||||||
success: "{count}개 문서를 가져왔습니다",
|
success: "{count}개 문서를 가져왔습니다",
|
||||||
stillRunning: "가져오기가 계속 실행 중입니다. 이후 배치를 멈추려면 취소를 사용하세요.",
|
stillRunning: "가져오기가 계속 실행 중입니다. 이후 배치를 멈추려면 취소를 사용하세요.",
|
||||||
|
legacyInsertUnsupported: "이 MongoDB Legacy 드라이버는 문서 일괄 삽입을 지원하지 않습니다. MongoDB Legacy 드라이버를 업그레이드하거나 다시 설치하세요.",
|
||||||
|
legacyCursorInvalid: "MongoDB Legacy 내보내기 커서를 더 이상 사용할 수 없습니다. 내보내기를 다시 시도하세요.",
|
||||||
|
legacyExportUnsupported: "이 MongoDB Legacy 드라이버는 내보내기 시 BSON 타입 유지를 지원하지 않습니다. MongoDB Legacy 드라이버를 업그레이드하거나 다시 설치하세요.",
|
||||||
|
legacyExportStalled: "MongoDB Legacy 드라이버가 동일한 내보내기 페이지를 두 번 반환했습니다. 드라이버를 업그레이드하거나 다시 설치한 후 다시 시도하세요.",
|
||||||
|
legacyExportMissingId: "MongoDB Legacy 드라이버가 _id 없는 문서를 반환해 안전하게 페이지 매김할 수 없습니다.",
|
||||||
rowsRead: "읽은 행",
|
rowsRead: "읽은 행",
|
||||||
rowsInserted: "삽입된 행",
|
rowsInserted: "삽입된 행",
|
||||||
rowsFailed: "실패한 행",
|
rowsFailed: "실패한 행",
|
||||||
@@ -4906,6 +4911,9 @@ export default withEnglishFallback({
|
|||||||
done: "완료",
|
done: "완료",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "MongoDB Legacy 드라이버가 {total}개 문서 중 {failed}개를 거부했습니다: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementKo,
|
...meilisearchManagementKo,
|
||||||
|
|||||||
@@ -5260,6 +5260,11 @@ export default withEnglishFallback({
|
|||||||
start: "Importar",
|
start: "Importar",
|
||||||
success: "{count} documentos importados",
|
success: "{count} documentos importados",
|
||||||
stillRunning: "A importação ainda está em execução. Use Cancelar para interromper novos lotes.",
|
stillRunning: "A importação ainda está em execução. Use Cancelar para interromper novos lotes.",
|
||||||
|
legacyInsertUnsupported: "Este driver MongoDB Legacy não pode inserir documentos em lote. Atualize ou reinstale o driver MongoDB Legacy.",
|
||||||
|
legacyCursorInvalid: "O cursor de exportação do MongoDB Legacy não está mais disponível. Tente exportar novamente.",
|
||||||
|
legacyExportUnsupported: "Este driver MongoDB Legacy não é compatível com a preservação de tipos BSON na exportação. Atualize ou reinstale o driver MongoDB Legacy.",
|
||||||
|
legacyExportStalled: "O driver MongoDB Legacy retornou a mesma página de exportação duas vezes. Atualize ou reinstale o driver e tente exportar novamente.",
|
||||||
|
legacyExportMissingId: "O driver MongoDB Legacy retornou um documento sem _id, então a exportação não pode paginar com segurança.",
|
||||||
rowsRead: "Linhas lidas",
|
rowsRead: "Linhas lidas",
|
||||||
rowsInserted: "Linhas inseridas",
|
rowsInserted: "Linhas inseridas",
|
||||||
rowsFailed: "Linhas com falha",
|
rowsFailed: "Linhas com falha",
|
||||||
@@ -5271,6 +5276,9 @@ export default withEnglishFallback({
|
|||||||
done: "Concluído",
|
done: "Concluído",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "O driver MongoDB Legacy rejeitou {failed} de {total} documentos: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementPtBR,
|
...meilisearchManagementPtBR,
|
||||||
|
|||||||
@@ -5300,6 +5300,11 @@ export default withEnglishFallback({
|
|||||||
start: "İçe aktar",
|
start: "İçe aktar",
|
||||||
success: "{count} belge içe aktarıldı",
|
success: "{count} belge içe aktarıldı",
|
||||||
stillRunning: "İçe aktarma hâlâ çalışıyor. Yeni toplu işleri durdurmak için İptal’i kullanın.",
|
stillRunning: "İçe aktarma hâlâ çalışıyor. Yeni toplu işleri durdurmak için İptal’i kullanın.",
|
||||||
|
legacyInsertUnsupported: "Bu MongoDB Legacy sürücüsü belgeleri toplu ekleyemez. MongoDB Legacy sürücüsünü yükseltin veya yeniden yükleyin.",
|
||||||
|
legacyCursorInvalid: "MongoDB Legacy dışa aktarma imleci artık kullanılamıyor. Dışa aktarmayı yeniden deneyin.",
|
||||||
|
legacyExportUnsupported: "Bu MongoDB Legacy sürücüsü dışa aktarma sırasında BSON türlerini korumayı desteklemiyor. MongoDB Legacy sürücüsünü yükseltin veya yeniden yükleyin.",
|
||||||
|
legacyExportStalled: "MongoDB Legacy sürücüsü aynı dışa aktarma sayfasını iki kez döndürdü. Sürücüyü yükseltin veya yeniden yükleyin ve dışa aktarmayı yeniden deneyin.",
|
||||||
|
legacyExportMissingId: "MongoDB Legacy sürücüsü _id içermeyen bir belge döndürdü; dışa aktarma güvenli şekilde sayfalanamıyor.",
|
||||||
rowsRead: "Okunan satırlar",
|
rowsRead: "Okunan satırlar",
|
||||||
rowsInserted: "Eklenen satırlar",
|
rowsInserted: "Eklenen satırlar",
|
||||||
rowsFailed: "Başarısız satırlar",
|
rowsFailed: "Başarısız satırlar",
|
||||||
@@ -5311,6 +5316,9 @@ export default withEnglishFallback({
|
|||||||
done: "Bitti",
|
done: "Bitti",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "MongoDB Legacy sürücüsü {total} belgenin {failed} tanesini reddetti: {message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementTr,
|
...meilisearchManagementTr,
|
||||||
|
|||||||
@@ -5533,6 +5533,11 @@ export default withEnglishFallback({
|
|||||||
start: "开始导入",
|
start: "开始导入",
|
||||||
success: "已导入 {count} 个文档",
|
success: "已导入 {count} 个文档",
|
||||||
stillRunning: "导入仍在运行。如需停止后续批次,请点取消。",
|
stillRunning: "导入仍在运行。如需停止后续批次,请点取消。",
|
||||||
|
legacyInsertUnsupported: "当前 MongoDB Legacy 驱动不支持批量插入文档。请升级或重新安装 MongoDB Legacy 驱动。",
|
||||||
|
legacyCursorInvalid: "MongoDB Legacy 导出游标已失效,请重试导出。",
|
||||||
|
legacyExportUnsupported: "当前 MongoDB Legacy 驱动不支持导出时保留 BSON 类型。请升级或重新安装 MongoDB Legacy 驱动。",
|
||||||
|
legacyExportStalled: "MongoDB Legacy 驱动返回了重复的导出分页。请升级或重新安装 MongoDB Legacy 驱动后重试导出。",
|
||||||
|
legacyExportMissingId: "MongoDB Legacy 驱动返回了缺少 _id 的文档,导出无法安全分页。",
|
||||||
rowsRead: "已读取",
|
rowsRead: "已读取",
|
||||||
rowsInserted: "已插入",
|
rowsInserted: "已插入",
|
||||||
rowsFailed: "失败",
|
rowsFailed: "失败",
|
||||||
@@ -5544,6 +5549,9 @@ export default withEnglishFallback({
|
|||||||
done: "完成",
|
done: "完成",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
insert: {
|
||||||
|
partialFailure: "MongoDB Legacy 驱动拒绝了 {total} 个文档中的 {failed} 个:{message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementZhCN,
|
...meilisearchManagementZhCN,
|
||||||
|
|||||||
@@ -4575,6 +4575,11 @@ export default withEnglishFallback({
|
|||||||
start: "開始匯入",
|
start: "開始匯入",
|
||||||
success: "已匯入 {count} 個文件",
|
success: "已匯入 {count} 個文件",
|
||||||
stillRunning: "匯入仍在執行。如需停止後續批次,請點取消。",
|
stillRunning: "匯入仍在執行。如需停止後續批次,請點取消。",
|
||||||
|
legacyInsertUnsupported: "目前的 MongoDB Legacy 驅動程式不支援批次插入文件。請升級或重新安裝 MongoDB Legacy 驅動程式。",
|
||||||
|
legacyCursorInvalid: "MongoDB Legacy 匯出游標已失效,請重試匯出。",
|
||||||
|
legacyExportUnsupported: "目前的 MongoDB Legacy 驅動程式不支援匯出時保留 BSON 類型。請升級或重新安裝 MongoDB Legacy 驅動程式。",
|
||||||
|
legacyExportStalled: "MongoDB Legacy 驅動程式重複回傳了同一個匯出分頁。請升級或重新安裝 MongoDB Legacy 驅動程式後重試匯出。",
|
||||||
|
legacyExportMissingId: "MongoDB Legacy 驅動程式回傳了缺少 _id 的文件,匯出無法安全分頁。",
|
||||||
rowsRead: "已讀取",
|
rowsRead: "已讀取",
|
||||||
rowsInserted: "已插入",
|
rowsInserted: "已插入",
|
||||||
rowsFailed: "失敗",
|
rowsFailed: "失敗",
|
||||||
@@ -4591,6 +4596,9 @@ export default withEnglishFallback({
|
|||||||
nativeJsonHint: "BSON 值請使用 MongoDB Extended JSON,例如 $oid、$date、$numberLong。",
|
nativeJsonHint: "BSON 值請使用 MongoDB Extended JSON,例如 $oid、$date、$numberLong。",
|
||||||
invalidNativeJson: "原生 JSON 格式無效:{error}",
|
invalidNativeJson: "原生 JSON 格式無效:{error}",
|
||||||
nativeDocumentRequired: "原生 JSON 的最上層必須是文件物件。",
|
nativeDocumentRequired: "原生 JSON 的最上層必須是文件物件。",
|
||||||
|
insert: {
|
||||||
|
partialFailure: "MongoDB Legacy 驅動程式拒絕了 {total} 個文件中的 {failed} 個:{message}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
meilisearch: {
|
meilisearch: {
|
||||||
...meilisearchManagementZhTW,
|
...meilisearchManagementZhTW,
|
||||||
|
|||||||
@@ -182,6 +182,12 @@ function normalizeBackendErrorAtDepth(error: unknown, seen: WeakSet<object>, dep
|
|||||||
|
|
||||||
export const GENERIC_TRANSPORT_FAILURE_MESSAGE = "Backend request failed";
|
export const GENERIC_TRANSPORT_FAILURE_MESSAGE = "Backend request failed";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a backend message the UI could not classify, so it is carried as raw text inside a
|
||||||
|
* structured envelope. Callers may still match that text against the known-message catalog.
|
||||||
|
*/
|
||||||
|
export const LEGACY_BACKEND_ERROR_CODE = "DBX-LEGACY-0001";
|
||||||
|
|
||||||
export class BackendErrorException extends Error {
|
export class BackendErrorException extends Error {
|
||||||
readonly backendError: BackendError;
|
readonly backendError: BackendError;
|
||||||
|
|
||||||
@@ -193,7 +199,7 @@ export class BackendErrorException extends Error {
|
|||||||
this.name = "BackendErrorException";
|
this.name = "BackendErrorException";
|
||||||
this.backendError = backendError ?? {
|
this.backendError = backendError ?? {
|
||||||
version: 1,
|
version: 1,
|
||||||
code: "DBX-LEGACY-0001",
|
code: LEGACY_BACKEND_ERROR_CODE,
|
||||||
messageKey: "backendErrors.legacy",
|
messageKey: "backendErrors.legacy",
|
||||||
messageParams: {},
|
messageParams: {},
|
||||||
source: "legacyBackend",
|
source: "legacyBackend",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"protocolVersion": 1,
|
"protocolVersion": 1,
|
||||||
"handshakeMethod": "handshake",
|
"handshakeMethod": "handshake",
|
||||||
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
||||||
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document"],
|
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document", "mongo_find_cursor"],
|
||||||
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
||||||
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl"],
|
||||||
"commonMethods": [
|
"commonMethods": [
|
||||||
@@ -42,6 +42,6 @@
|
|||||||
"disconnect",
|
"disconnect",
|
||||||
"shutdown"
|
"shutdown"
|
||||||
],
|
],
|
||||||
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command"],
|
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command", "start_find_cursor", "fetch_find_cursor", "close_find_cursor"],
|
||||||
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"]
|
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"]
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"protocolVersion": 2,
|
"protocolVersion": 2,
|
||||||
"handshakeMethod": "handshake",
|
"handshakeMethod": "handshake",
|
||||||
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
"handshakeResponseFields": ["protocolVersion", "agentProtocolVersion", "capabilities"],
|
||||||
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document", "multi_session", "structured_error_v1"],
|
"allCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "kv", "kv_ttl", "kv_cas", "kv_list_values", "kv_status", "kv_history", "etcd_compaction", "etcd_defrag", "etcd_watch", "etcd_lease", "etcd_auth", "mongo_drop_database", "mongo_clone_collection", "mongo_run_command", "mongo_insert_documents", "mongo_replace_document", "mongo_find_cursor", "multi_session", "structured_error_v1"],
|
||||||
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session"],
|
"capabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session"],
|
||||||
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session", "structured_error_v1"],
|
"defaultSqlCapabilities": ["connect", "test_connection", "metadata", "query", "paged_query", "transaction", "ddl", "multi_session", "structured_error_v1"],
|
||||||
"commonMethods": [
|
"commonMethods": [
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"disconnect",
|
"disconnect",
|
||||||
"shutdown"
|
"shutdown"
|
||||||
],
|
],
|
||||||
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command"],
|
"mongoLegacyMethods": ["list_databases", "list_collections", "find_documents", "find_one", "explain_find", "aggregate_documents", "find_documents_extended_json", "count_documents", "server_version", "create_index", "create_user", "drop_indexes", "drop_collection", "clone_collection", "drop_database", "insert_document", "insert_documents", "update_document", "update_documents", "replace_document", "delete_document", "delete_documents", "run_command", "start_find_cursor", "fetch_find_cursor", "close_find_cursor"],
|
||||||
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"],
|
"kvMethods": ["kv_list_prefix", "kv_get", "kv_put", "kv_delete", "kv_rename", "kv_history", "kv_status", "etcd_compact", "etcd_defrag", "etcd_watch_start", "etcd_watch_poll", "etcd_watch_stop", "etcd_lease_list", "etcd_lease_get", "etcd_lease_grant", "etcd_lease_keepalive_once", "etcd_lease_revoke", "etcd_auth_user_list", "etcd_auth_user_get", "etcd_auth_user_add", "etcd_auth_user_delete", "etcd_auth_user_change_password", "etcd_auth_user_grant_role", "etcd_auth_user_revoke_role", "etcd_auth_role_list", "etcd_auth_role_get", "etcd_auth_role_add", "etcd_auth_role_delete", "etcd_auth_role_grant_permission", "etcd_auth_role_revoke_permission"],
|
||||||
"sessionField": "agentSessionId",
|
"sessionField": "agentSessionId",
|
||||||
"cursorSessionField": "sessionId"
|
"cursorSessionField": "sessionId"
|
||||||
|
|||||||
@@ -1042,6 +1042,7 @@ pub enum AgentCapability {
|
|||||||
MongoRunCommand,
|
MongoRunCommand,
|
||||||
MongoInsertDocuments,
|
MongoInsertDocuments,
|
||||||
MongoReplaceDocument,
|
MongoReplaceDocument,
|
||||||
|
MongoFindCursor,
|
||||||
MultiSession,
|
MultiSession,
|
||||||
StructuredErrorV1,
|
StructuredErrorV1,
|
||||||
}
|
}
|
||||||
@@ -1124,7 +1125,7 @@ fn parse_agent_rpc_error_header(header: &str) -> (Option<i64>, String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AgentCapability {
|
impl AgentCapability {
|
||||||
pub const ALL: [Self; 25] = [
|
pub const ALL: [Self; 26] = [
|
||||||
Self::Connect,
|
Self::Connect,
|
||||||
Self::TestConnection,
|
Self::TestConnection,
|
||||||
Self::Metadata,
|
Self::Metadata,
|
||||||
@@ -1148,6 +1149,7 @@ impl AgentCapability {
|
|||||||
Self::MongoRunCommand,
|
Self::MongoRunCommand,
|
||||||
Self::MongoInsertDocuments,
|
Self::MongoInsertDocuments,
|
||||||
Self::MongoReplaceDocument,
|
Self::MongoReplaceDocument,
|
||||||
|
Self::MongoFindCursor,
|
||||||
Self::MultiSession,
|
Self::MultiSession,
|
||||||
Self::StructuredErrorV1,
|
Self::StructuredErrorV1,
|
||||||
];
|
];
|
||||||
@@ -1177,6 +1179,7 @@ impl AgentCapability {
|
|||||||
Self::MongoRunCommand => "mongo_run_command",
|
Self::MongoRunCommand => "mongo_run_command",
|
||||||
Self::MongoInsertDocuments => "mongo_insert_documents",
|
Self::MongoInsertDocuments => "mongo_insert_documents",
|
||||||
Self::MongoReplaceDocument => "mongo_replace_document",
|
Self::MongoReplaceDocument => "mongo_replace_document",
|
||||||
|
Self::MongoFindCursor => "mongo_find_cursor",
|
||||||
Self::MultiSession => "multi_session",
|
Self::MultiSession => "multi_session",
|
||||||
Self::StructuredErrorV1 => "structured_error_v1",
|
Self::StructuredErrorV1 => "structured_error_v1",
|
||||||
}
|
}
|
||||||
@@ -1383,10 +1386,13 @@ pub enum MongoAgentMethod {
|
|||||||
DeleteDocument,
|
DeleteDocument,
|
||||||
DeleteDocuments,
|
DeleteDocuments,
|
||||||
RunCommand,
|
RunCommand,
|
||||||
|
StartFindCursor,
|
||||||
|
FetchFindCursor,
|
||||||
|
CloseFindCursor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MongoAgentMethod {
|
impl MongoAgentMethod {
|
||||||
pub const ALL: [Self; 23] = [
|
pub const ALL: [Self; 26] = [
|
||||||
Self::ListDatabases,
|
Self::ListDatabases,
|
||||||
Self::ListCollections,
|
Self::ListCollections,
|
||||||
Self::FindDocuments,
|
Self::FindDocuments,
|
||||||
@@ -1410,6 +1416,9 @@ impl MongoAgentMethod {
|
|||||||
Self::DeleteDocument,
|
Self::DeleteDocument,
|
||||||
Self::DeleteDocuments,
|
Self::DeleteDocuments,
|
||||||
Self::RunCommand,
|
Self::RunCommand,
|
||||||
|
Self::StartFindCursor,
|
||||||
|
Self::FetchFindCursor,
|
||||||
|
Self::CloseFindCursor,
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn as_str(self) -> &'static str {
|
pub fn as_str(self) -> &'static str {
|
||||||
@@ -1437,6 +1446,9 @@ impl MongoAgentMethod {
|
|||||||
Self::DeleteDocument => "delete_document",
|
Self::DeleteDocument => "delete_document",
|
||||||
Self::DeleteDocuments => "delete_documents",
|
Self::DeleteDocuments => "delete_documents",
|
||||||
Self::RunCommand => "run_command",
|
Self::RunCommand => "run_command",
|
||||||
|
Self::StartFindCursor => "start_find_cursor",
|
||||||
|
Self::FetchFindCursor => "fetch_find_cursor",
|
||||||
|
Self::CloseFindCursor => "close_find_cursor",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2795,6 +2807,27 @@ impl AgentDriverClient {
|
|||||||
self.call_mongo_method(MongoAgentMethod::InsertDocuments, params).await
|
self.call_mongo_method(MongoAgentMethod::InsertDocuments, params).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn mongo_start_find_cursor<T: DeserializeOwned + Send + 'static>(
|
||||||
|
&mut self,
|
||||||
|
params: Value,
|
||||||
|
) -> Result<T, String> {
|
||||||
|
self.call_mongo_method(MongoAgentMethod::StartFindCursor, params).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn mongo_fetch_find_cursor<T: DeserializeOwned + Send + 'static>(
|
||||||
|
&mut self,
|
||||||
|
params: Value,
|
||||||
|
) -> Result<T, String> {
|
||||||
|
self.call_mongo_method(MongoAgentMethod::FetchFindCursor, params).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn mongo_close_find_cursor<T: DeserializeOwned + Send + 'static>(
|
||||||
|
&mut self,
|
||||||
|
params: Value,
|
||||||
|
) -> Result<T, String> {
|
||||||
|
self.call_mongo_method(MongoAgentMethod::CloseFindCursor, params).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn mongo_update_document<T: DeserializeOwned + Send + 'static>(
|
pub async fn mongo_update_document<T: DeserializeOwned + Send + 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
params: Value,
|
params: Value,
|
||||||
@@ -2972,6 +3005,7 @@ pub fn agent_supports_capability(handshake: Option<&AgentHandshake>, capability:
|
|||||||
| AgentCapability::MongoRunCommand
|
| AgentCapability::MongoRunCommand
|
||||||
| AgentCapability::MongoInsertDocuments
|
| AgentCapability::MongoInsertDocuments
|
||||||
| AgentCapability::MongoReplaceDocument
|
| AgentCapability::MongoReplaceDocument
|
||||||
|
| AgentCapability::MongoFindCursor
|
||||||
) {
|
) {
|
||||||
return handshake.map(|value| value.supports(capability)).unwrap_or(false);
|
return handshake.map(|value| value.supports(capability)).unwrap_or(false);
|
||||||
}
|
}
|
||||||
@@ -5006,9 +5040,10 @@ for line in sys.stdin:
|
|||||||
assert_eq!(AgentCapability::MongoRunCommand.as_str(), "mongo_run_command");
|
assert_eq!(AgentCapability::MongoRunCommand.as_str(), "mongo_run_command");
|
||||||
assert_eq!(AgentCapability::MongoInsertDocuments.as_str(), "mongo_insert_documents");
|
assert_eq!(AgentCapability::MongoInsertDocuments.as_str(), "mongo_insert_documents");
|
||||||
assert_eq!(AgentCapability::MongoReplaceDocument.as_str(), "mongo_replace_document");
|
assert_eq!(AgentCapability::MongoReplaceDocument.as_str(), "mongo_replace_document");
|
||||||
|
assert_eq!(AgentCapability::MongoFindCursor.as_str(), "mongo_find_cursor");
|
||||||
assert_eq!(AgentCapability::MultiSession.as_str(), "multi_session");
|
assert_eq!(AgentCapability::MultiSession.as_str(), "multi_session");
|
||||||
assert_eq!(AgentCapability::StructuredErrorV1.as_str(), "structured_error_v1");
|
assert_eq!(AgentCapability::StructuredErrorV1.as_str(), "structured_error_v1");
|
||||||
assert_eq!(AgentCapability::ALL.len(), 25);
|
assert_eq!(AgentCapability::ALL.len(), 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -5073,6 +5108,9 @@ for line in sys.stdin:
|
|||||||
assert_eq!(MongoAgentMethod::ReplaceDocument.as_str(), "replace_document");
|
assert_eq!(MongoAgentMethod::ReplaceDocument.as_str(), "replace_document");
|
||||||
assert_eq!(MongoAgentMethod::DeleteDocument.as_str(), "delete_document");
|
assert_eq!(MongoAgentMethod::DeleteDocument.as_str(), "delete_document");
|
||||||
assert_eq!(MongoAgentMethod::DeleteDocuments.as_str(), "delete_documents");
|
assert_eq!(MongoAgentMethod::DeleteDocuments.as_str(), "delete_documents");
|
||||||
|
assert_eq!(MongoAgentMethod::StartFindCursor.as_str(), "start_find_cursor");
|
||||||
|
assert_eq!(MongoAgentMethod::FetchFindCursor.as_str(), "fetch_find_cursor");
|
||||||
|
assert_eq!(MongoAgentMethod::CloseFindCursor.as_str(), "close_find_cursor");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -5138,6 +5176,9 @@ for line in sys.stdin:
|
|||||||
let _mongo_clone_collection = AgentDriverClient::mongo_clone_collection::<serde_json::Value>;
|
let _mongo_clone_collection = AgentDriverClient::mongo_clone_collection::<serde_json::Value>;
|
||||||
let _mongo_drop_database = AgentDriverClient::mongo_drop_database::<serde_json::Value>;
|
let _mongo_drop_database = AgentDriverClient::mongo_drop_database::<serde_json::Value>;
|
||||||
let _mongo_insert_document = AgentDriverClient::mongo_insert_document::<serde_json::Value>;
|
let _mongo_insert_document = AgentDriverClient::mongo_insert_document::<serde_json::Value>;
|
||||||
|
let _mongo_start_find_cursor = AgentDriverClient::mongo_start_find_cursor::<serde_json::Value>;
|
||||||
|
let _mongo_fetch_find_cursor = AgentDriverClient::mongo_fetch_find_cursor::<serde_json::Value>;
|
||||||
|
let _mongo_close_find_cursor = AgentDriverClient::mongo_close_find_cursor::<serde_json::Value>;
|
||||||
let _mongo_update_document = AgentDriverClient::mongo_update_document::<serde_json::Value>;
|
let _mongo_update_document = AgentDriverClient::mongo_update_document::<serde_json::Value>;
|
||||||
let _mongo_update_documents = AgentDriverClient::mongo_update_documents::<serde_json::Value>;
|
let _mongo_update_documents = AgentDriverClient::mongo_update_documents::<serde_json::Value>;
|
||||||
let _mongo_delete_document = AgentDriverClient::mongo_delete_document::<serde_json::Value>;
|
let _mongo_delete_document = AgentDriverClient::mongo_delete_document::<serde_json::Value>;
|
||||||
@@ -5389,6 +5430,8 @@ for line in sys.stdin:
|
|||||||
assert!(!agent_supports_capability(Some(&handshake), AgentCapability::MongoRunCommand));
|
assert!(!agent_supports_capability(Some(&handshake), AgentCapability::MongoRunCommand));
|
||||||
assert!(!agent_supports_capability(None, AgentCapability::MongoInsertDocuments));
|
assert!(!agent_supports_capability(None, AgentCapability::MongoInsertDocuments));
|
||||||
assert!(!agent_supports_capability(Some(&handshake), AgentCapability::MongoInsertDocuments));
|
assert!(!agent_supports_capability(Some(&handshake), AgentCapability::MongoInsertDocuments));
|
||||||
|
assert!(!agent_supports_capability(None, AgentCapability::MongoFindCursor));
|
||||||
|
assert!(!agent_supports_capability(Some(&handshake), AgentCapability::MongoFindCursor));
|
||||||
|
|
||||||
let mongo_handshake =
|
let mongo_handshake =
|
||||||
AgentHandshake { capabilities: vec![AgentCapability::MongoDropDatabase.as_str().to_string()], ..handshake };
|
AgentHandshake { capabilities: vec![AgentCapability::MongoDropDatabase.as_str().to_string()], ..handshake };
|
||||||
@@ -5414,6 +5457,12 @@ for line in sys.stdin:
|
|||||||
Some(&mongo_insert_documents_handshake),
|
Some(&mongo_insert_documents_handshake),
|
||||||
AgentCapability::MongoInsertDocuments
|
AgentCapability::MongoInsertDocuments
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let mongo_find_cursor_handshake = AgentHandshake {
|
||||||
|
capabilities: vec![AgentCapability::MongoFindCursor.as_str().to_string()],
|
||||||
|
..mongo_insert_documents_handshake
|
||||||
|
};
|
||||||
|
assert!(agent_supports_capability(Some(&mongo_find_cursor_handshake), AgentCapability::MongoFindCursor));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -2649,6 +2649,41 @@ fn is_retryable_mongo_write_code(code: i32) -> bool {
|
|||||||
!matches!(code, 11000 | 11001 | 12582)
|
!matches!(code, 11000 | 11001 | 12582)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reads the `insert_documents` result of a MongoDB legacy agent. The agent reports a partly
|
||||||
|
/// applied batch as a success carrying one entry per rejected document, so callers must inspect
|
||||||
|
/// [`MongoInsertOutcome::errors`] instead of trusting a bare affected-row count.
|
||||||
|
pub fn agent_insert_outcome(result: &serde_json::Value) -> Result<MongoInsertOutcome, String> {
|
||||||
|
let inserted = result
|
||||||
|
.get("affected_rows")
|
||||||
|
.and_then(serde_json::Value::as_u64)
|
||||||
|
.ok_or_else(|| "MongoDB Legacy Agent returned an invalid insertMany result".to_string())?;
|
||||||
|
let errors = result
|
||||||
|
.get("errors")
|
||||||
|
.and_then(serde_json::Value::as_array)
|
||||||
|
.map(|errors| errors.iter().map(agent_insert_error).collect())
|
||||||
|
.unwrap_or_default();
|
||||||
|
Ok(MongoInsertOutcome { inserted, errors })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One rejected document, or a batch-wide rejection the agent could not attribute to a document
|
||||||
|
/// (a write concern failure) — those carry no index and keep [`MongoBulkWriteError::index`] `None`.
|
||||||
|
fn agent_insert_error(value: &serde_json::Value) -> MongoBulkWriteError {
|
||||||
|
// A rejection is never dropped for lack of a message: dropping it would make a document the
|
||||||
|
// server refused look like a successful insert.
|
||||||
|
let message = value
|
||||||
|
.get("message")
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.unwrap_or("MongoDB Legacy Agent rejected a document without a message")
|
||||||
|
.to_string();
|
||||||
|
let code = value.get("code").and_then(serde_json::Value::as_i64).map(|code| code as i32);
|
||||||
|
MongoBulkWriteError {
|
||||||
|
message,
|
||||||
|
index: value.get("index").and_then(serde_json::Value::as_u64).map(|index| index as usize),
|
||||||
|
code,
|
||||||
|
retryable: code.is_some_and(is_retryable_mongo_write_code),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn for_each_find_document(
|
pub async fn for_each_find_document(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
|
|||||||
@@ -439,11 +439,18 @@ pub async fn mongo_find_documents_extended_json_core(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_unknown_agent_method_error(error: &str, method: &str) -> bool {
|
pub(crate) fn is_unknown_agent_method_error(error: &str, method: &str) -> bool {
|
||||||
let lower = error.to_ascii_lowercase();
|
let lower = error.to_ascii_lowercase();
|
||||||
lower.contains(method) && (lower.contains("unknown method") || lower.contains("method not found"))
|
lower.contains(method) && (lower.contains("unknown method") || lower.contains("method not found"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True only when a legacy agent refused a bulk write because it has no `insertMany` at all, which
|
||||||
|
/// is the one failure a document-by-document retry can still get through. It must stay precise:
|
||||||
|
/// every other legacy-agent failure, a rejected document included, has to surface as-is.
|
||||||
|
pub(crate) fn is_legacy_agent_insert_many_unsupported(error: &str) -> bool {
|
||||||
|
error.contains("does not support insertMany") || error.contains("does not support bulk insertMany")
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn mongo_aggregate_documents_core(
|
pub async fn mongo_aggregate_documents_core(
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
connection_id: &str,
|
connection_id: &str,
|
||||||
@@ -730,10 +737,18 @@ pub async fn mongo_insert_documents_core(
|
|||||||
"docs_json": docs_json,
|
"docs_json": docs_json,
|
||||||
}))
|
}))
|
||||||
.await?;
|
.await?;
|
||||||
result
|
let outcome = mongo_driver::agent_insert_outcome(&result)?;
|
||||||
.get("affected_rows")
|
// The agent reports a partly applied batch as a success, so a rejected document has to
|
||||||
.and_then(serde_json::Value::as_u64)
|
// fail the call here exactly like the native driver's insert_many does.
|
||||||
.ok_or_else(|| "MongoDB Legacy Agent returned an invalid insertMany result".to_string())
|
if let Some(first) = outcome.errors.first() {
|
||||||
|
return Err(format!(
|
||||||
|
"MongoDB Legacy Agent rejected {} of {} documents: {}",
|
||||||
|
outcome.errors.len(),
|
||||||
|
documents.len(),
|
||||||
|
first.message
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(outcome.inserted)
|
||||||
}
|
}
|
||||||
_ => Err("Not a MongoDB connection".to_string()),
|
_ => Err("Not a MongoDB connection".to_string()),
|
||||||
}
|
}
|
||||||
@@ -1758,6 +1773,46 @@ for line in sys.stdin:
|
|||||||
assert_eq!(affected, 2);
|
assert_eq!(affected, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn mongo_insert_many_fails_when_the_legacy_agent_rejects_a_document() {
|
||||||
|
let documents = r#"[{"_id":1},{"_id":1}]"#;
|
||||||
|
let (state, _directory) = legacy_mongo_state_with_capabilities(
|
||||||
|
"insert_documents",
|
||||||
|
serde_json::json!({
|
||||||
|
"database": "app",
|
||||||
|
"collection": "users",
|
||||||
|
"docs_json": documents,
|
||||||
|
}),
|
||||||
|
serde_json::json!({
|
||||||
|
"affected_rows": 1,
|
||||||
|
"errors": [{ "index": 1, "code": 11000, "message": "E11000 duplicate key" }],
|
||||||
|
}),
|
||||||
|
&["mongo_insert_documents"],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let error = mongo_insert_documents_core(&state, "legacy", "app", "users", documents).await.unwrap_err();
|
||||||
|
|
||||||
|
// The agent reports a partly applied batch as a success, so a rejected document has to
|
||||||
|
// fail the call here rather than being rounded up to "inserted".
|
||||||
|
assert_eq!(error, "MongoDB Legacy Agent rejected 1 of 2 documents: E11000 duplicate key");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn legacy_insert_many_heuristic_covers_only_the_missing_capability() {
|
||||||
|
assert!(is_legacy_agent_insert_many_unsupported(
|
||||||
|
"MongoDB Legacy Agent does not support insertMany; upgrade or reinstall the MongoDB Legacy driver"
|
||||||
|
));
|
||||||
|
assert!(is_legacy_agent_insert_many_unsupported(
|
||||||
|
"MongoDB legacy agent does not support bulk insertMany/insertOne writes"
|
||||||
|
));
|
||||||
|
// A rejected document must not be retried one by one: the rest of the batch is written.
|
||||||
|
assert!(!is_legacy_agent_insert_many_unsupported(
|
||||||
|
"MongoDB Legacy Agent rejected 1 of 2 documents: E11000 duplicate key"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn mongo_insert_many_requires_an_explicit_legacy_agent_capability() {
|
async fn mongo_insert_many_requires_an_explicit_legacy_agent_capability() {
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -5421,7 +5421,7 @@ async fn insert_mongo_documents_for_transfer(
|
|||||||
let docs_json = serde_json::to_string(documents).map_err(|e| format!("Failed to encode MongoDB documents: {e}"))?;
|
let docs_json = serde_json::to_string(documents).map_err(|e| format!("Failed to encode MongoDB documents: {e}"))?;
|
||||||
match crate::mongo_ops::mongo_insert_documents_core(state, connection_id, database, collection, &docs_json).await {
|
match crate::mongo_ops::mongo_insert_documents_core(state, connection_id, database, collection, &docs_json).await {
|
||||||
Ok(count) => Ok(count),
|
Ok(count) => Ok(count),
|
||||||
Err(error) if error.to_ascii_lowercase().contains("legacy agent") => {
|
Err(error) if crate::mongo_ops::is_legacy_agent_insert_many_unsupported(&error) => {
|
||||||
let mut inserted = 0;
|
let mut inserted = 0;
|
||||||
for document in documents {
|
for document in documents {
|
||||||
let doc_json =
|
let doc_json =
|
||||||
@@ -5457,7 +5457,7 @@ async fn insert_mongo_documents_extended_json_for_transfer(
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(count) => Ok(count),
|
Ok(count) => Ok(count),
|
||||||
Err(error) if error.to_ascii_lowercase().contains("legacy agent") => {
|
Err(error) if crate::mongo_ops::is_legacy_agent_insert_many_unsupported(&error) => {
|
||||||
insert_mongo_documents_for_transfer(state, connection_id, database, collection, documents).await
|
insert_mongo_documents_for_transfer(state, connection_id, database, collection, documents).await
|
||||||
}
|
}
|
||||||
Err(error) => Err(error),
|
Err(error) => Err(error),
|
||||||
|
|||||||
Reference in new issue
Block a user