1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: BUSL-1.1
//! Data Plane handler for `MetaOp::RenameCollection`.
//!
//! Called after `MoveTenantCutover` applies so that physical data is
//! accessible under the new database context. Re-keys all documents and
//! secondary indexes in the sparse engine (document / strict-document engines)
//! and the KV engine from the old db-qualified collection name to the new one.
use crate::bridge::envelope::{ErrorCode, Response};
use crate::data::executor::core_loop::CoreLoop;
use crate::data::executor::task::ExecutionTask;
/// Parameters for [`CoreLoop::execute_rename_collection`].
pub(in crate::data::executor) struct RenameCollectionParams<'a> {
pub tenant_id: u64,
pub old_database_id: u64,
pub new_database_id: u64,
pub old_collection: &'a str,
pub new_collection: &'a str,
}
impl CoreLoop {
/// Handle `MetaOp::RenameCollection`: re-key all documents and secondary
/// indexes from `old_collection` to `new_collection` for `tenant_id` in
/// every engine that uses db-qualified collection names for keying.
pub(in crate::data::executor) fn execute_rename_collection(
&mut self,
task: &ExecutionTask,
params: RenameCollectionParams<'_>,
) -> Response {
let RenameCollectionParams {
tenant_id,
old_database_id,
new_database_id,
old_collection,
new_collection,
} = params;
// Sparse engine (document schemaless + document strict).
if let Err(e) = self.sparse.rename_collection(
old_database_id,
new_database_id,
tenant_id,
old_collection,
new_collection,
) {
return self.response_error(
task,
ErrorCode::Internal {
detail: format!(
"rename_collection sparse ({old_collection} -> {new_collection}): {e}"
),
},
);
}
// KV engine.
self.kv_engine
.rename_collection(crate::engine::kv::RenameCollectionParams {
old_database_id,
new_database_id,
tenant_id,
old_collection,
new_collection,
});
self.response_ok(task)
}
}