summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Banala <arun.banala@mongodb.com>2021-09-09 17:56:39 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-21 17:02:44 +0000
commit536cd38e7ab615181f5586519f60728c52e47108 (patch)
tree28257014602d0c4f4623e0cfbea0420a7c13046b
parented2e91304a83771f20e3df874222984c61a3e884 (diff)
downloadmongo-536cd38e7ab615181f5586519f60728c52e47108.tar.gz
SERVER-57567 Update sharded passthrough suite to handle time series collections
-rw-r--r--buildscripts/resmokelib/testing/testcases/jstest.py1
-rw-r--r--jstests/core/timeseries/clustered_index_options.js1
-rw-r--r--jstests/core/timeseries/clustered_index_types.js1
-rw-r--r--jstests/core/timeseries/timeseries_collation.js1
-rw-r--r--jstests/core/timeseries/timeseries_create_collection.js1
-rw-r--r--jstests/core/timeseries/timeseries_expire.js1
-rw-r--r--jstests/core/timeseries/timeseries_expire_collmod.js1
-rw-r--r--jstests/core/timeseries/timeseries_id_index.js1
-rw-r--r--jstests/core/timeseries/timeseries_id_range.js7
-rw-r--r--jstests/core/timeseries/timeseries_index.js3
-rw-r--r--jstests/core/timeseries/timeseries_index_collation.js3
-rw-r--r--jstests/core/timeseries/timeseries_index_skipped_record_tracker.js1
-rw-r--r--jstests/core/timeseries/timeseries_index_stats.js1
-rw-r--r--jstests/core/timeseries/timeseries_index_use.js3
-rw-r--r--jstests/core/timeseries/timeseries_insert.js6
-rw-r--r--jstests/core/timeseries/timeseries_insert_after_delete.js2
-rw-r--r--jstests/core/timeseries/timeseries_insert_after_update.js2
-rw-r--r--jstests/core/timeseries/timeseries_internal_bucket_geo_within.js5
-rw-r--r--jstests/core/timeseries/timeseries_list_collections.js1
-rw-r--r--jstests/core/timeseries/timeseries_list_collections_filter_name.js1
-rw-r--r--jstests/core/timeseries/timeseries_list_collections_invalid_view.js1
-rw-r--r--jstests/core/timeseries/timeseries_list_collections_missing_view.js1
-rw-r--r--jstests/core/timeseries/timeseries_lookup.js10
-rw-r--r--jstests/core/timeseries/timeseries_out_of_order.js1
-rw-r--r--jstests/core/timeseries/timeseries_resume_after.js1
-rw-r--r--jstests/core/timeseries/timeseries_show_record_id.js1
-rw-r--r--jstests/core/timeseries/timeseries_simple.js1
-rw-r--r--jstests/core/timeseries/timeseries_sparse.js1
-rw-r--r--jstests/core/timeseries/timeseries_special_indexes_metadata.js3
-rw-r--r--jstests/core/timeseries/timeseries_update.js2
-rw-r--r--jstests/core/timeseries/timeseries_update_concurrent.js2
-rw-r--r--jstests/core/timeseries/timeseries_update_hint.js2
-rw-r--r--jstests/libs/override_methods/implicitly_shard_accessed_collections.js50
-rw-r--r--src/mongo/s/write_ops/batch_write_op.cpp3
34 files changed, 82 insertions, 40 deletions
diff --git a/buildscripts/resmokelib/testing/testcases/jstest.py b/buildscripts/resmokelib/testing/testcases/jstest.py
index f6ae1033e94..86255838414 100644
--- a/buildscripts/resmokelib/testing/testcases/jstest.py
+++ b/buildscripts/resmokelib/testing/testcases/jstest.py
@@ -62,6 +62,7 @@ class _SingleJSTestCase(interface.ProcessTestCase):
test_data["peerPids"] = self.fixture.pids()
test_data["alwaysUseLogFiles"] = config.ALWAYS_USE_LOG_FILES
test_data["failIfUnterminatedProcesses"] = True
+ test_data["implicitlyShardOnCreateCollectionOnly"] = "/timeseries/" in self.js_filename
global_vars["TestData"] = test_data
self.shell_options["global_vars"] = global_vars
diff --git a/jstests/core/timeseries/clustered_index_options.js b/jstests/core/timeseries/clustered_index_options.js
index f741e780065..d923b03508d 100644
--- a/jstests/core/timeseries/clustered_index_options.js
+++ b/jstests/core/timeseries/clustered_index_options.js
@@ -5,7 +5,6 @@
*
* @tags: [
* assumes_against_mongod_not_mongos,
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* ]
*/
diff --git a/jstests/core/timeseries/clustered_index_types.js b/jstests/core/timeseries/clustered_index_types.js
index 158f516b387..9819d3df896 100644
--- a/jstests/core/timeseries/clustered_index_types.js
+++ b/jstests/core/timeseries/clustered_index_types.js
@@ -3,7 +3,6 @@
*
* @tags: [
* assumes_against_mongod_not_mongos,
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* requires_fcv_51,
* # TODO: (SERVER-59199) Support appending large RecordIds to KeyStrings
diff --git a/jstests/core/timeseries/timeseries_collation.js b/jstests/core/timeseries/timeseries_collation.js
index 0c523011742..c6bb3c1fd14 100644
--- a/jstests/core/timeseries/timeseries_collation.js
+++ b/jstests/core/timeseries/timeseries_collation.js
@@ -2,7 +2,6 @@
* Tests that time-series collections respect collations for metadata and min/max.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_create_collection.js b/jstests/core/timeseries/timeseries_create_collection.js
index 907a06d6be2..feb2f443d26 100644
--- a/jstests/core/timeseries/timeseries_create_collection.js
+++ b/jstests/core/timeseries/timeseries_create_collection.js
@@ -4,7 +4,6 @@
* in that case.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_transactions,
* requires_getmore,
* ]
diff --git a/jstests/core/timeseries/timeseries_expire.js b/jstests/core/timeseries/timeseries_expire.js
index 8291faf71f6..02f3020a6ed 100644
--- a/jstests/core/timeseries/timeseries_expire.js
+++ b/jstests/core/timeseries/timeseries_expire.js
@@ -2,7 +2,6 @@
* Tests that a time-series collection created with the 'expireAfterSeconds' option will remove
* buckets older than 'expireAfterSeconds' based on the bucket creation time.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_expire_collmod.js b/jstests/core/timeseries/timeseries_expire_collmod.js
index e06cc09d732..3ba770dfeb9 100644
--- a/jstests/core/timeseries/timeseries_expire_collmod.js
+++ b/jstests/core/timeseries/timeseries_expire_collmod.js
@@ -3,7 +3,6 @@
* the underlying bucket collection.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* ]
diff --git a/jstests/core/timeseries/timeseries_id_index.js b/jstests/core/timeseries/timeseries_id_index.js
index a0f9d7901fb..f20cceef768 100644
--- a/jstests/core/timeseries/timeseries_id_index.js
+++ b/jstests/core/timeseries/timeseries_id_index.js
@@ -2,7 +2,6 @@
* Verifies that the _id index cannot be created on a time-series collection.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_id_range.js b/jstests/core/timeseries/timeseries_id_range.js
index 452a9a6089a..77388f1dee4 100644
--- a/jstests/core/timeseries/timeseries_id_range.js
+++ b/jstests/core/timeseries/timeseries_id_range.js
@@ -3,7 +3,9 @@
* range scan using a combination of minRecord and maxRecord.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * # The test assumes no index exists on the time field. shardCollection implicitly creates an
+ * # index.
+ * assumes_unsharded_collection,
* does_not_support_transactions,
* requires_getmore,
* ]
@@ -61,7 +63,8 @@ TimeseriesTest.run((insert) => {
assert.eq(0, res.length);
let expl = coll.explain("executionStats").aggregate(pipeline);
- assert(getAggPlanStage(expl, "COLLSCAN").hasOwnProperty("maxRecord"));
+ assert(getAggPlanStage(expl, "COLLSCAN"), expl);
+ assert(getAggPlanStage(expl, "COLLSCAN").hasOwnProperty("maxRecord"), expl);
assert.eq(0, expl.stages[0].$cursor.executionStats.executionStages.nReturned);
for (let i = 0; i < 10; i++) {
diff --git a/jstests/core/timeseries/timeseries_index.js b/jstests/core/timeseries/timeseries_index.js
index a92d7cdcb1e..3c2b34eb123 100644
--- a/jstests/core/timeseries/timeseries_index.js
+++ b/jstests/core/timeseries/timeseries_index.js
@@ -2,7 +2,8 @@
* Tests index creation, index drops, list indexes, hide/unhide index on a time-series collection.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * # The shardCollection implicitly creates an index on time field.
+ * assumes_unsharded_collection,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_fcv_51,
diff --git a/jstests/core/timeseries/timeseries_index_collation.js b/jstests/core/timeseries/timeseries_index_collation.js
index 35033c58be6..70aef3b95f4 100644
--- a/jstests/core/timeseries/timeseries_index_collation.js
+++ b/jstests/core/timeseries/timeseries_index_collation.js
@@ -2,7 +2,8 @@
* Tests collation with time-series collections.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * # The shardCollection implicitly creates an index on time field.
+ * assumes_unsharded_collection,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_index_skipped_record_tracker.js b/jstests/core/timeseries/timeseries_index_skipped_record_tracker.js
index bf7d001a2a7..4142fc268c3 100644
--- a/jstests/core/timeseries/timeseries_index_skipped_record_tracker.js
+++ b/jstests/core/timeseries/timeseries_index_skipped_record_tracker.js
@@ -3,7 +3,6 @@
* for time-series collections.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_index_stats.js b/jstests/core/timeseries/timeseries_index_stats.js
index e8d19fbe053..9bf3144ed2d 100644
--- a/jstests/core/timeseries/timeseries_index_stats.js
+++ b/jstests/core/timeseries/timeseries_index_stats.js
@@ -2,7 +2,6 @@
* Tests $indexStats on a time-series collection.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* # This test attempts to perform write operations and get index usage statistics using the
* # $indexStats stage. The former operation must be routed to the primary in a replica set,
* # whereas the latter may be routed to a secondary.
diff --git a/jstests/core/timeseries/timeseries_index_use.js b/jstests/core/timeseries/timeseries_index_use.js
index a49d5a01610..f4a4202f06e 100644
--- a/jstests/core/timeseries/timeseries_index_use.js
+++ b/jstests/core/timeseries/timeseries_index_use.js
@@ -2,7 +2,8 @@
* Tests index usage on meta and time fields for timeseries collections.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * # The shardCollection implicitly creates an index on time field.
+ * assumes_unsharded_collection,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_fcv_51,
diff --git a/jstests/core/timeseries/timeseries_insert.js b/jstests/core/timeseries/timeseries_insert.js
index 435add76780..65e8f2e5ef0 100644
--- a/jstests/core/timeseries/timeseries_insert.js
+++ b/jstests/core/timeseries/timeseries_insert.js
@@ -1,5 +1,8 @@
/**
* Inserts time-series data based on the TSBS document-per-event format.
+ * * @tags: [
+ * does_not_support_transactions,
+ * ]
*/
(function() {
"use strict";
@@ -9,6 +12,9 @@ load("jstests/core/timeseries/libs/timeseries.js");
const coll = db.timeseries_insert;
coll.drop();
+assert.commandWorked(db.createCollection(
+ coll.getName(), {timeseries: {timeField: "time", metaField: "measurement"}}));
+
Random.setRandomSeed();
const numHosts = 10;
diff --git a/jstests/core/timeseries/timeseries_insert_after_delete.js b/jstests/core/timeseries/timeseries_insert_after_delete.js
index 49ed2be198b..4a033f391c1 100644
--- a/jstests/core/timeseries/timeseries_insert_after_delete.js
+++ b/jstests/core/timeseries/timeseries_insert_after_delete.js
@@ -1,7 +1,7 @@
/**
* Tests running the delete command on a time-series collection closes the in-memory bucket.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * assumes_unsharded_collection, # TODO SERVER-59180: Remove this tag.
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_insert_after_update.js b/jstests/core/timeseries/timeseries_insert_after_update.js
index 733a30d423c..37e1df137a3 100644
--- a/jstests/core/timeseries/timeseries_insert_after_update.js
+++ b/jstests/core/timeseries/timeseries_insert_after_update.js
@@ -3,7 +3,7 @@
* were updated.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * assumes_unsharded_collection, # TODO SERVER-59180: Remove this tag.
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js b/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js
index 05dd4314715..d411f8d37c4 100644
--- a/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js
+++ b/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js
@@ -3,12 +3,12 @@
* $_internalUnpackBucket when used on a non-metadata field on a time-series collection.
*
* @tags: [
+ * assumes_unsharded_collection,
* requires_fcv_51,
* requires_pipeline_optimization,
* requires_timeseries,
* does_not_support_stepdowns,
* does_not_support_transactions,
- * assumes_no_implicit_collection_creation_after_drop,
* ]
*/
@@ -50,7 +50,8 @@ for (let collScanStage of collScanStages) {
"field": "loc"
}
},
- collScanStage.filter);
+ collScanStage.filter,
+ collScanStages);
}
// Test that $geoWithin still gives the correct result, when the events are in the same bucket.
diff --git a/jstests/core/timeseries/timeseries_list_collections.js b/jstests/core/timeseries/timeseries_list_collections.js
index d6770e1c8cb..2b2ce211761 100644
--- a/jstests/core/timeseries/timeseries_list_collections.js
+++ b/jstests/core/timeseries/timeseries_list_collections.js
@@ -2,7 +2,6 @@
* Tests the result of running listCollections when there are time-series collections present.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_transactions,
* requires_getmore,
* ]
diff --git a/jstests/core/timeseries/timeseries_list_collections_filter_name.js b/jstests/core/timeseries/timeseries_list_collections_filter_name.js
index 3414f3b5294..673fb40a99e 100644
--- a/jstests/core/timeseries/timeseries_list_collections_filter_name.js
+++ b/jstests/core/timeseries/timeseries_list_collections_filter_name.js
@@ -3,7 +3,6 @@
* name.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_transactions,
* requires_getmore,
* ]
diff --git a/jstests/core/timeseries/timeseries_list_collections_invalid_view.js b/jstests/core/timeseries/timeseries_list_collections_invalid_view.js
index 1ad58d5caf4..dda533041d4 100644
--- a/jstests/core/timeseries/timeseries_list_collections_invalid_view.js
+++ b/jstests/core/timeseries/timeseries_list_collections_invalid_view.js
@@ -4,7 +4,6 @@
*
* @tags: [
* assumes_against_mongod_not_mongos,
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_transactions,
* requires_getmore,
* ]
diff --git a/jstests/core/timeseries/timeseries_list_collections_missing_view.js b/jstests/core/timeseries/timeseries_list_collections_missing_view.js
index 12fd1ef2297..356739a9818 100644
--- a/jstests/core/timeseries/timeseries_list_collections_missing_view.js
+++ b/jstests/core/timeseries/timeseries_list_collections_missing_view.js
@@ -3,7 +3,6 @@
* time-series view is missing.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_transactions,
* requires_getmore,
* ]
diff --git a/jstests/core/timeseries/timeseries_lookup.js b/jstests/core/timeseries/timeseries_lookup.js
index b0496e918df..849e99f5fea 100644
--- a/jstests/core/timeseries/timeseries_lookup.js
+++ b/jstests/core/timeseries/timeseries_lookup.js
@@ -2,7 +2,7 @@
* Test that time-series bucket collections work as expected with $lookup.
*
* @tags: [
- * # Timeseries collections cannot be sharded.
+ * # Cannot run lookup with sharded foreign collection.
* assumes_unsharded_collection,
* does_not_support_transactions,
* requires_timeseries,
@@ -32,7 +32,13 @@ TimeseriesTest.run((insert) => {
collA.drop();
collB.drop();
assert.commandWorked(testDB.createCollection(collA.getName(), collAOption));
- assert.commandWorked(testDB.createCollection(collB.getName(), collBOption));
+
+ // Currently, we do not support $lookup on sharded foreign collections. Certain test suites
+ // override createCollection() shell helper to implicitly shard the collection. To avoid
+ // this behaviour, we issue create command directly.
+ assert.commandWorked(
+ testDB.runCommand(Object.assign({create: collB.getName()}, collBOption)));
+
let entryCountPerHost = new Array(numHosts).fill(0);
// Insert into collA, one entry per host.
diff --git a/jstests/core/timeseries/timeseries_out_of_order.js b/jstests/core/timeseries/timeseries_out_of_order.js
index ec0a1d05a76..db1b6798f81 100644
--- a/jstests/core/timeseries/timeseries_out_of_order.js
+++ b/jstests/core/timeseries/timeseries_out_of_order.js
@@ -3,7 +3,6 @@
* they are within the time range, regardless of the order in which they are inserted.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_resume_after.js b/jstests/core/timeseries/timeseries_resume_after.js
index 3aa87d05779..beee2f19a4c 100644
--- a/jstests/core/timeseries/timeseries_resume_after.js
+++ b/jstests/core/timeseries/timeseries_resume_after.js
@@ -4,7 +4,6 @@
*
* @tags: [
* assumes_against_mongod_not_mongos,
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_show_record_id.js b/jstests/core/timeseries/timeseries_show_record_id.js
index 641c70840fb..fe8e25dad12 100644
--- a/jstests/core/timeseries/timeseries_show_record_id.js
+++ b/jstests/core/timeseries/timeseries_show_record_id.js
@@ -2,7 +2,6 @@
* Verifies that showRecordId() returns the ObjectId type for time-series collections.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_simple.js b/jstests/core/timeseries/timeseries_simple.js
index 6ca14e72ee7..ab20a90d096 100644
--- a/jstests/core/timeseries/timeseries_simple.js
+++ b/jstests/core/timeseries/timeseries_simple.js
@@ -2,7 +2,6 @@
* Tests inserting sample data into the time-series buckets collection.
* This test is for the simple case of only one measurement per bucket.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_sparse.js b/jstests/core/timeseries/timeseries_sparse.js
index a5ddb4a1fc8..6fa18856fa2 100644
--- a/jstests/core/timeseries/timeseries_sparse.js
+++ b/jstests/core/timeseries/timeseries_sparse.js
@@ -2,7 +2,6 @@
* Typically, time-series collections use measurements that always contain data for every field.
* This test provides coverage for when this is not the case.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_special_indexes_metadata.js b/jstests/core/timeseries/timeseries_special_indexes_metadata.js
index 725e2eef43f..9e5ef2f5c0d 100644
--- a/jstests/core/timeseries/timeseries_special_indexes_metadata.js
+++ b/jstests/core/timeseries/timeseries_special_indexes_metadata.js
@@ -4,7 +4,8 @@
* Tests index creation, index drops, list indexes, hide/unhide index on a time-series collection.
*
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * # The shardCollection implicitly creates an index on time field.
+ * assumes_unsharded_collection,
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_fcv_51,
diff --git a/jstests/core/timeseries/timeseries_update.js b/jstests/core/timeseries/timeseries_update.js
index 13ebe199e8c..57eb7ec1958 100644
--- a/jstests/core/timeseries/timeseries_update.js
+++ b/jstests/core/timeseries/timeseries_update.js
@@ -1,7 +1,7 @@
/**
* Tests running the update command on a time-series collection.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * assumes_unsharded_collection, # TODO SERVER-59180: Remove this tag.
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_getmore,
diff --git a/jstests/core/timeseries/timeseries_update_concurrent.js b/jstests/core/timeseries/timeseries_update_concurrent.js
index 00a48d94f0b..fdea47f4683 100644
--- a/jstests/core/timeseries/timeseries_update_concurrent.js
+++ b/jstests/core/timeseries/timeseries_update_concurrent.js
@@ -2,7 +2,7 @@
* Tests running the update command on a time-series collection with concurrent modifications to the
* collection.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * assumes_unsharded_collection, # TODO SERVER-59180: Remove this tag.
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_fcv_51,
diff --git a/jstests/core/timeseries/timeseries_update_hint.js b/jstests/core/timeseries/timeseries_update_hint.js
index b878f2b2290..b658bd13539 100644
--- a/jstests/core/timeseries/timeseries_update_hint.js
+++ b/jstests/core/timeseries/timeseries_update_hint.js
@@ -1,7 +1,7 @@
/**
* Tests passing a hint to the update command on a time-series collection.
* @tags: [
- * assumes_no_implicit_collection_creation_after_drop,
+ * assumes_unsharded_collection, # TODO SERVER-59180: Remove this tag.
* does_not_support_stepdowns,
* does_not_support_transactions,
* requires_fcv_51,
diff --git a/jstests/libs/override_methods/implicitly_shard_accessed_collections.js b/jstests/libs/override_methods/implicitly_shard_accessed_collections.js
index 6e279a5332d..07355dc7126 100644
--- a/jstests/libs/override_methods/implicitly_shard_accessed_collections.js
+++ b/jstests/libs/override_methods/implicitly_shard_accessed_collections.js
@@ -41,6 +41,7 @@ load("jstests/libs/override_methods/override_helpers.js"); // For 'OverrideHelp
// Save a reference to the original methods in the IIFE's scope.
// This scoping allows the original methods to be called by the overrides below.
var originalGetCollection = DB.prototype.getCollection;
+var originalCreateCollection = DB.prototype.createCollection;
var originalDBCollectionDrop = DBCollection.prototype.drop;
var originalStartParallelShell = startParallelShell;
var originalRunCommand = Mongo.prototype.runCommand;
@@ -58,9 +59,13 @@ var denylistedNamespaces = [
const kZoneName = 'moveToHereForMigrationPassthrough';
function shardCollection(collection) {
- var db = collection.getDB();
+ return shardCollectionWithSpec(
+ {db: collection.getDB(), collName: collection.getName(), shardKey: {_id: 'hashed'}});
+}
+
+function shardCollectionWithSpec({db, collName, shardKey, timeseriesSpec}) {
var dbName = db.getName();
- var fullName = collection.getFullName();
+ var fullName = dbName + "." + collName;
for (var ns of denylistedNamespaces) {
if (fullName.match(ns)) {
@@ -75,8 +80,11 @@ function shardCollection(collection) {
assert.commandWorked(res, "enabling sharding on the '" + dbName + "' db failed");
}
- res = db.adminCommand(
- {shardCollection: fullName, key: {_id: 'hashed'}, collation: {locale: "simple"}});
+ let shardCollCmd = {shardCollection: fullName, key: shardKey, collation: {locale: "simple"}};
+ if (timeseriesSpec) {
+ shardCollCmd["timeseries"] = timeseriesSpec;
+ }
+ res = db.adminCommand(shardCollCmd);
let checkResult = function(res, opDescription) {
if (res.ok === 0 && testMayRunDropInParallel) {
@@ -119,6 +127,32 @@ function shardCollection(collection) {
}
}
+DB.prototype.createCollection = function() {
+ const createCollResult = originalCreateCollection.apply(this, arguments);
+
+ if (!createCollResult.ok || arguments.length < 2 || arguments[1] == null ||
+ !isObject(arguments[1]) || !arguments[1].timeseries || !arguments[1].timeseries.timeField) {
+ return createCollResult;
+ }
+
+ const parameterResult = this.adminCommand({getParameter: 1, featureFlagShardedTimeSeries: 1});
+ const isTimeseriesShardingEnabled =
+ parameterResult.ok && parameterResult.featureFlagShardedTimeSeries.value;
+ if (!isTimeseriesShardingEnabled) {
+ return createCollResult;
+ }
+
+ const timeField = arguments[1]["timeseries"]["timeField"];
+ shardCollectionWithSpec({
+ db: this,
+ collName: arguments[0],
+ shardKey: {[timeField]: 1},
+ timeseriesSpec: arguments[1]["timeseries"]
+ });
+
+ return createCollResult;
+};
+
DB.prototype.getCollection = function() {
var collection = originalGetCollection.apply(this, arguments);
@@ -147,7 +181,9 @@ DB.prototype.getCollection = function() {
}
// Attempt to enable sharding on database and collection if not already done.
- shardCollection(collection);
+ if (!TestData.implicitlyShardOnCreateCollectionOnly) {
+ shardCollection(collection);
+ }
return collection;
};
@@ -156,7 +192,9 @@ DBCollection.prototype.drop = function() {
var dropResult = originalDBCollectionDrop.apply(this, arguments);
// Attempt to enable sharding on database and collection if not already done.
- shardCollection(this);
+ if (!TestData.implicitlyShardOnCreateCollectionOnly) {
+ shardCollection(this);
+ }
return dropResult;
};
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp
index db2f1623d26..533bac1f1f3 100644
--- a/src/mongo/s/write_ops/batch_write_op.cpp
+++ b/src/mongo/s/write_ops/batch_write_op.cpp
@@ -546,7 +546,8 @@ BatchedCommandRequest BatchWriteOp::buildBatchRequest(const TargetedWriteBatch&
_clientRequest.getWriteCommandRequestBase().getBypassDocumentValidation());
wcb.setOrdered(_clientRequest.getWriteCommandRequestBase().getOrdered());
- if (targeter.isShardedTimeSeriesBucketsNamespace()) {
+ if (targeter.isShardedTimeSeriesBucketsNamespace() &&
+ !_clientRequest.getNS().isTimeseriesBucketsCollection()) {
wcb.setIsTimeseriesNamespace(true);
}