Skip to content

Commit 3d93c17

Browse files
authored
refactor(metactl-import): when importing, also write the data version (#18080)
Before this commit, when importing, the data version (such as `V004`) is not written to disk, and the data version is assumed to be the oldest compatible version, and the on-disk data then will be upgraded to the latest version. For example, when `databend-metactl` imports `V004` data, the data on disk is left as `V002`, and then the data is upgraded from `V002` to `V003` and finally to `V004`. This is an unnecessary burden, and the upgrading process invokes the legacy `sled-db` based storage, which leads to problems on NFS (`device busy` error when deleting sled from disk after closing it). This commit refines this behavior by directly writing the data version such as `V004` to disk after importing. Thus there won't be an unnecessary burden of upgrading the data, and it gets rid of the necessity to access sled DB, which is a workaround for running on NFS.
1 parent 1ec2e8b commit 3d93c17

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/meta/control/src/import_v004.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use std::sync::Mutex;
1919
use databend_common_meta_raft_store::config::RaftConfig;
2020
use databend_common_meta_raft_store::key_spaces::RaftStoreEntry;
2121
use databend_common_meta_raft_store::key_spaces::SMEntry;
22+
use databend_common_meta_raft_store::ondisk::DataVersion;
23+
use databend_common_meta_raft_store::ondisk::Header;
2224
use databend_common_meta_raft_store::ondisk::OnDisk;
2325
use databend_common_meta_raft_store::raft_log_v004;
2426
use databend_common_meta_raft_store::raft_log_v004::RaftLogV004;
@@ -38,6 +40,8 @@ pub async fn import_v004(
3840
raft_config: RaftConfig,
3941
lines: impl IntoIterator<Item = Result<String, io::Error>>,
4042
) -> anyhow::Result<Option<LogId>> {
43+
let data_version = DataVersion::V004;
44+
4145
OnDisk::ensure_dirs(&raft_config.raft_dir)?;
4246

4347
let mut n = 0;
@@ -50,7 +54,7 @@ pub async fn import_v004(
5054
raft_log_v004::Importer::new(raft_log)
5155
};
5256

53-
let snapshot_store = SnapshotStoreV004::new(raft_config);
57+
let snapshot_store = SnapshotStoreV004::new(raft_config.clone());
5458
let writer = snapshot_store.new_writer()?;
5559
let (tx, join_handle) = writer.spawn_writer_thread("import_v004");
5660

@@ -104,11 +108,24 @@ pub async fn import_v004(
104108
let db = temp_snapshot_data.move_to_final_path(snapshot_id.to_string())?;
105109

106110
eprintln!(
107-
"Imported {} records, snapshot: {}; snapshot_path: {}; snapshot_stat: {}",
111+
"{data_version}: Imported {} records, snapshot: {}; snapshot_path: {}; snapshot_stat: {}",
108112
n,
109113
snapshot_id,
110114
db.path(),
111115
db.stat()
112116
);
117+
118+
let on_disk = OnDisk::new(
119+
Header {
120+
version: DataVersion::V004,
121+
upgrading: None,
122+
cleaning: false,
123+
},
124+
&raft_config,
125+
);
126+
127+
on_disk.write_header(&on_disk.header)?;
128+
eprintln!("{data_version}: written on-disk header: {}", on_disk.header);
129+
113130
Ok(max_log_id)
114131
}

src/meta/raft-store/src/ondisk/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl OnDisk {
121121
Ok(OnDisk::new(header, config))
122122
}
123123

124-
fn new(header: Header, config: &RaftConfig) -> Self {
124+
pub fn new(header: Header, config: &RaftConfig) -> Self {
125125
let min_compatible = DATA_VERSION.min_compatible_data_version();
126126

127127
if header.version < min_compatible {
@@ -358,7 +358,7 @@ impl OnDisk {
358358
Ok(())
359359
}
360360

361-
fn write_header(&self, header: &Header) -> Result<(), MetaStorageError> {
361+
pub fn write_header(&self, header: &Header) -> Result<(), MetaStorageError> {
362362
Self::write_header_to_fs(&self.config, header)?;
363363
Ok(())
364364
}

0 commit comments

Comments
 (0)