Skip to content

Commit c2177aa

Browse files
pierlauroMongoDB Bot
authored andcommitted
SERVER-106887 Support rename with viewless timeseries (#39878)
GitOrigin-RevId: 677a3806de73f66f197197f000181b15e2ae99e2
1 parent ea36f51 commit c2177aa

9 files changed

+207
-101
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
132132
/buildscripts/resmokeconfig/matrix_suites/overrides/**/multiplan_single_solutions.yml @10gen/query-optimization @svc-auto-approve-bot
133133
/buildscripts/resmokeconfig/matrix_suites/overrides/**/networking.yml @10gen/server-networking-and-observability @svc-auto-approve-bot
134134
/buildscripts/resmokeconfig/matrix_suites/overrides/**/query_settings.yml @10gen/query-execution-query-settings @svc-auto-approve-bot
135-
/buildscripts/resmokeconfig/matrix_suites/overrides/**/query_shape_hash_stability.yml @10gen/query-execution-query-settings @svc-auto-approve-bot
135+
/buildscripts/resmokeconfig/matrix_suites/overrides/**/*query_shape_hash_stability* @10gen/query-execution-query-settings @svc-auto-approve-bot
136136
/buildscripts/resmokeconfig/matrix_suites/overrides/**/repeat_queries.yml @10gen/query-optimization @svc-auto-approve-bot
137137
/buildscripts/resmokeconfig/matrix_suites/overrides/**/*viewless_timeseries.yml @10gen/server-catalog-and-routing @svc-auto-approve-bot
138138
/buildscripts/resmokeconfig/matrix_suites/overrides/**/stepdown_primary_change_streams.yml @10gen/query-execution-change-streams @svc-auto-approve-bot

buildscripts/resmokeconfig/matrix_suites/generated_suites/replica_sets_recordids_replicated_jscore_passthrough.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ selector:
5656
- jstests/core/catalog/agg_list_cluster_catalog_with_match.js
5757
- jstests/core/write/bulk/bulk_write_timeseries_basic.js
5858
- jstests/core/ddl/convert_to_capped.js
59-
- jstests/core/timeseries/ddl/rename_system_buckets_collections.js
59+
- jstests/core/timeseries/ddl/rename_timeseries.js
6060
- jstests/core/query/index_correctness_pbt.js
6161
- jstests/core/query/plan_cache/cache_correctness_pbt.js
6262
- jstests/core/query/run_all_plans_pbt.js

buildscripts/resmokeconfig/matrix_suites/generated_suites/sharded_collections_query_shape_hash_stability_last_continuous_new_old.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ selector:
104104
- jstests/core/index/express.js
105105
- jstests/core/query/idhack.js
106106
- jstests/core/query/explain/explain_all_plans_execution_stats.js
107-
- jstests/core/timeseries/ddl/rename_system_buckets_collections.js
107+
- jstests/core/timeseries/ddl/rename_timeseries.js
108108
- jstests/core/timeseries/write/timeseries_delete_with_meta.js
109109
- jstests/core/timeseries/ddl/timeseries_collection_uuid.js
110110
exclude_with_any_tags:

buildscripts/resmokeconfig/matrix_suites/generated_suites/sharded_collections_query_shape_hash_stability_last_lts_new_old.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ selector:
104104
- jstests/core/index/express.js
105105
- jstests/core/query/idhack.js
106106
- jstests/core/query/explain/explain_all_plans_execution_stats.js
107-
- jstests/core/timeseries/ddl/rename_system_buckets_collections.js
107+
- jstests/core/timeseries/ddl/rename_timeseries.js
108108
- jstests/core/timeseries/write/timeseries_delete_with_meta.js
109109
- jstests/core/timeseries/ddl/timeseries_collection_uuid.js
110110
exclude_with_any_tags:

buildscripts/resmokeconfig/matrix_suites/overrides/OWNERS.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ filters:
1818
- "query_settings.yml":
1919
approvers:
2020
- 10gen/query-execution-query-settings
21-
- "query_shape_hash_stability.yml":
21+
- "*query_shape_hash_stability*":
2222
approvers:
2323
- 10gen/query-execution-query-settings
2424
- "repeat_queries.yml":

buildscripts/resmokeconfig/matrix_suites/overrides/query_shape_hash_stability.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
- jstests/core/index/express.js
132132
- jstests/core/query/idhack.js
133133
- jstests/core/query/explain/explain_all_plans_execution_stats.js
134-
- jstests/core/timeseries/ddl/rename_system_buckets_collections.js
134+
- jstests/core/timeseries/ddl/rename_timeseries.js
135135
- jstests/core/timeseries/write/timeseries_delete_with_meta.js
136136
# UUID mismatch on second cluster.
137137
- jstests/core/timeseries/ddl/timeseries_collection_uuid.js

buildscripts/resmokeconfig/matrix_suites/overrides/recordids_replicated.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- jstests/core/catalog/agg_list_cluster_catalog_with_match.js
1717
- jstests/core/write/bulk/bulk_write_timeseries_basic.js
1818
- jstests/core/ddl/convert_to_capped.js
19-
- jstests/core/timeseries/ddl/rename_system_buckets_collections.js
19+
- jstests/core/timeseries/ddl/rename_timeseries.js
2020
- jstests/core/query/index_correctness_pbt.js
2121
- jstests/core/query/plan_cache/cache_correctness_pbt.js
2222
- jstests/core/query/run_all_plans_pbt.js

jstests/core/timeseries/ddl/rename_system_buckets_collections.js

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
* Tests valid/invalid rename operations over timeseries collections
3+
*
4+
* @tags: [
5+
* uses_rename,
6+
* requires_timeseries,
7+
* # the rename command is not idempotent
8+
* requires_non_retryable_commands,
9+
* # rename only works across databases with same primary shard
10+
* # TODO SERVER-90096: change this tag with a more specific one
11+
* assumes_balancer_off,
12+
* ]
13+
*/
14+
15+
import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js";
16+
import {FixtureHelpers} from "jstests/libs/fixture_helpers.js";
17+
18+
const dbName = db.getName();
19+
const otherDbName = `${dbName}_other`;
20+
const collName = `coll_${jsTestName()}`;
21+
const bucketsCollName = `system.buckets.${collName}`;
22+
const timeseriesOpts = {
23+
timeseries: {timeField: "time"}
24+
};
25+
26+
// TODO SERVER-101595 get rid of all the code protected behind this flag
27+
const viewlessTimeseriesEnabled =
28+
FeatureFlagUtil.isPresentAndEnabled(db, "CreateViewlessTimeseriesCollections");
29+
30+
function setupEnv() {
31+
db.dropDatabase();
32+
db.getSiblingDB(otherDbName).dropDatabase();
33+
34+
// TODO SERVER-89086 remove the following workaround once the underlying problem is fixed.
35+
if (FixtureHelpers.isMongos(db) || TestData.testingReplicaSetEndpoint) {
36+
// On sharded cluster rename throw NamespaceNotFound if the target database does not exists
37+
// yet. Thus we need to manually pre-create it.
38+
// Additionally rename only works across database with the same primary shard. Thus create
39+
// second database on the same primary shard.
40+
assert.commandWorked(db.adminCommand({enableSharding: dbName}));
41+
assert.commandWorked(db.adminCommand({
42+
enableSharding: otherDbName,
43+
primaryShard: db.getSiblingDB(dbName).getDatabasePrimaryShardId()
44+
}));
45+
}
46+
}
47+
48+
// Insert measurements -> rename -> check measurements/buckets have not changed
49+
function checkSuccessfullRename(fromDb, fromColl, toDb, toColl) {
50+
const srcNss = fromDb + (viewlessTimeseriesEnabled ? '.' : '.system.buckets.') + fromColl;
51+
const srcColl = db.getSiblingDB(fromDb)[fromColl];
52+
const dstNss = toDb + (viewlessTimeseriesEnabled ? '.' : '.system.buckets.') + toColl;
53+
const dstColl = db.getSiblingDB(toDb)[toColl];
54+
55+
// 4 measurements falling into 3 different buckets
56+
const measurements = [
57+
{time: ISODate("2019-01-30T07:30:10.957Z"), meta: 0},
58+
{time: ISODate("2019-01-30T07:30:11.957Z"), meta: 1},
59+
{time: ISODate("2020-01-30T07:30:11.957Z"), meta: 2},
60+
{time: ISODate("2021-01-30T07:30:11.957Z"), meta: 3}
61+
];
62+
63+
for (let i = 0; i < measurements.length; i++) {
64+
assert.commandWorked(srcColl.insert(measurements[i]));
65+
}
66+
67+
const beforeBuckets =
68+
viewlessTimeseriesEnabled ? srcColl.find().rawData().toArray() : srcColl.find().toArray();
69+
70+
assert.commandWorked(db.adminCommand({renameCollection: srcNss, to: dstNss}));
71+
72+
if (!viewlessTimeseriesEnabled) {
73+
// Fix view definitions following rename
74+
assert.commandWorked(db.getSiblingDB(fromDb).runCommand({drop: fromColl}));
75+
assert.commandWorked(db.getSiblingDB(toDb).createCollection(toColl, timeseriesOpts));
76+
}
77+
78+
const afterBuckets =
79+
viewlessTimeseriesEnabled ? dstColl.find().rawData().toArray() : dstColl.find().toArray();
80+
assert.eq(beforeBuckets, afterBuckets);
81+
82+
const afterMeasurements = dstColl.find({}, {_id: 0}).sort({time: 1}).toArray();
83+
assert.eq(afterMeasurements, measurements);
84+
}
85+
86+
function runSystemBucketsTests(targetDbName) {
87+
{
88+
jsTest.log("Renaming a timeseries collection using the main namespace is not supported");
89+
90+
setupEnv();
91+
assert.commandWorked(db.createCollection(collName, timeseriesOpts));
92+
assert.commandFailedWithCode(
93+
db.adminCommand(
94+
{renameCollection: `${dbName}.${collName}`, to: `${targetDbName}.newColl`}),
95+
// TODO SERVER-89100 unify error code between sharded clusters and replicaset
96+
[ErrorCodes.IllegalOperation, ErrorCodes.CommandNotSupportedOnView]);
97+
}
98+
{
99+
jsTest.log(
100+
"Renaming a simple collection to a bucket collection without timeseries options fails");
101+
setupEnv();
102+
assert.commandWorked(db.createCollection(collName));
103+
const res = db.adminCommand({
104+
renameCollection: `${dbName}.${collName}`,
105+
to: `${targetDbName}.system.buckets.newColl`
106+
});
107+
assert.commandFailedWithCode(res, [ErrorCodes.IllegalOperation]);
108+
}
109+
{
110+
jsTest.log(
111+
"Renaming a timeseries collection using the main namespace with a target bucket collection fail");
112+
setupEnv();
113+
assert.commandWorked(db.createCollection(collName, timeseriesOpts));
114+
assert.commandFailedWithCode(
115+
db.adminCommand({
116+
renameCollection: `${dbName}.${collName}`,
117+
to: `${dbName}.system.buckets.newColl`
118+
}),
119+
// TODO SERVER-89100 unify error code between sharded clusters and replicaset
120+
[ErrorCodes.IllegalOperation, ErrorCodes.CommandNotSupportedOnView]);
121+
}
122+
{
123+
jsTest.log("Renaming a timeseries bucket collection to a normal collection fail");
124+
setupEnv();
125+
assert.commandWorked(db.createCollection(collName, timeseriesOpts));
126+
assert.commandFailedWithCode(
127+
db.adminCommand(
128+
{renameCollection: `${dbName}.${bucketsCollName}`, to: `${targetDbName}.newColl`}),
129+
ErrorCodes.IllegalOperation);
130+
}
131+
132+
{
133+
setupEnv();
134+
assert.commandWorked(db.createCollection(collName, timeseriesOpts));
135+
const isUnsharded =
136+
db.getSiblingDB('config').collections.countDocuments(
137+
{_id: `${dbName}.${bucketsCollName}`, unsplittable: {$ne: true}}) == 0;
138+
// Rename across db is not supported for sharded collections
139+
if (dbName == targetDbName || isUnsharded) {
140+
jsTest.log(
141+
"Renaming a timeseries bucket collection to another bucket collection works");
142+
checkSuccessfullRename(dbName, collName, targetDbName, 'newColl');
143+
} else {
144+
jsTest.log("Renaming a sharded timeseries bucket collection to a different db fails");
145+
146+
assert.commandFailedWithCode(db.adminCommand({
147+
renameCollection: `${dbName}.${bucketsCollName}`,
148+
to: `${targetDbName}.system.buckets.newColl`
149+
}),
150+
ErrorCodes.CommandFailed);
151+
}
152+
}
153+
}
154+
155+
function runViewLessTimeseriesTests(targetDbName) {
156+
{
157+
setupEnv();
158+
assert.commandWorked(db.createCollection(collName, timeseriesOpts));
159+
const isUnsharded = db.getSiblingDB('config').collections.countDocuments(
160+
{_id: `${dbName}.${collName}`, unsplittable: {$ne: true}}) == 0;
161+
162+
// Rename across db is not supported for sharded collections
163+
if (dbName == targetDbName || isUnsharded) {
164+
jsTest.log("Renaming a viewless timeseries collection works");
165+
checkSuccessfullRename(dbName, collName, targetDbName, 'newColl');
166+
} else {
167+
jsTest.log("Renaming a sharded viewless timeseries collection to a different db fails");
168+
assert.commandFailedWithCode(db.adminCommand({
169+
renameCollection: `${dbName}.${bucketsCollName}`,
170+
to: `${targetDbName}.newColl`
171+
}),
172+
ErrorCodes.IllegalOperation);
173+
}
174+
}
175+
176+
{
177+
jsTest.log("Renaming a viewless timeseries collection to a target bucket collection fails");
178+
setupEnv();
179+
assert.commandWorked(db.createCollection(collName));
180+
const res = db.adminCommand({
181+
renameCollection: `${dbName}.${collName}`,
182+
to: `${targetDbName}.system.buckets.newColl`
183+
});
184+
assert.commandFailedWithCode(res, [ErrorCodes.IllegalOperation]);
185+
}
186+
}
187+
188+
jsTest.log("Run test cases with rename within same database");
189+
if (viewlessTimeseriesEnabled) {
190+
runViewLessTimeseriesTests(dbName);
191+
} else {
192+
runSystemBucketsTests(dbName);
193+
}
194+
195+
jsTest.log("Run test cases with rename across different databases");
196+
if (viewlessTimeseriesEnabled) {
197+
runViewLessTimeseriesTests(otherDbName);
198+
} else {
199+
runSystemBucketsTests(otherDbName);
200+
}

0 commit comments

Comments
 (0)