Skip to content

Commit

Permalink
import: fix upgrade bug for import_file (tikv#10903)
Browse files Browse the repository at this point in the history
* fix upgrade bug

Signed-off-by: Little-Wallace <[email protected]>

* fix lint

Signed-off-by: Little-Wallace <[email protected]>

* add comment

Signed-off-by: Little-Wallace <[email protected]>
  • Loading branch information
Little-Wallace authored Sep 6, 2021
1 parent b9426ea commit a284376
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions components/sst_importer/src/import_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub fn path_to_sst_meta<P: AsRef<Path>>(path: P) -> Result<SstMeta> {
return Err(Error::InvalidSSTPath(path.to_owned()));
}
let elems: Vec<_> = file_name.trim_end_matches(SST_SUFFIX).split('_').collect();
if elems.len() != 5 {
if elems.len() < 4 {
return Err(Error::InvalidSSTPath(path.to_owned()));
}

Expand All @@ -366,7 +366,11 @@ pub fn path_to_sst_meta<P: AsRef<Path>>(path: P) -> Result<SstMeta> {
meta.set_region_id(elems[1].parse()?);
meta.mut_region_epoch().set_conf_ver(elems[2].parse()?);
meta.mut_region_epoch().set_version(elems[3].parse()?);
meta.set_cf_name(elems[4].to_owned());
if elems.len() > 4 {
// If we upgrade TiKV from 3.0.x to 4.0.x and higher version, we can not read cf_name from
// the file path, because TiKV 3.0.x does not encode cf_name to path.
meta.set_cf_name(elems[4].to_owned());
}
Ok(meta)
}

Expand All @@ -392,4 +396,24 @@ mod test {
let new_meta = path_to_sst_meta(path).unwrap();
assert_eq!(meta, new_meta);
}

#[test]
fn test_path_to_sst_meta() {
let uuid = Uuid::new_v4();
let mut meta = SstMeta::default();
meta.set_uuid(uuid.as_bytes().to_vec());
meta.set_region_id(1);
meta.mut_region_epoch().set_conf_ver(222);
meta.mut_region_epoch().set_version(333);
let path = PathBuf::from(format!(
"{}_{}_{}_{}{}",
UuidBuilder::from_slice(meta.get_uuid()).unwrap().build(),
meta.get_region_id(),
meta.get_region_epoch().get_conf_ver(),
meta.get_region_epoch().get_version(),
SST_SUFFIX,
));
let new_meta = path_to_sst_meta(&path).unwrap();
assert_eq!(meta, new_meta);
}
}

0 comments on commit a284376

Please sign in to comment.