Skip to content

Commit

Permalink
chore: add table region key to delete in upgrade tool (#2214)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuiyisong authored Aug 21, 2023
1 parent c5f507c commit 9352649
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/cmd/src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,18 @@ impl MigrateTableMetadata {
);

while let Some((key, value)) = stream.try_next().await.context(error::IterStreamSnafu)? {
self.migrate_table_route_key(value).await?;
let table_id = self.migrate_table_route_key(value).await?;
keys.push(key);
keys.push(TableRegionKey::new(table_id).as_raw_key())
}

info!("Total migrated TableRouteKeys: {}", keys.len());
info!("Total migrated TableRouteKeys: {}", keys.len() / 2);
self.delete_migrated_keys(keys).await;

Ok(())
}

async fn migrate_table_route_key(&self, value: TableRouteValue) -> Result<()> {
async fn migrate_table_route_key(&self, value: TableRouteValue) -> Result<u32> {
let table_route = TableRoute::try_from_raw(
&value.peers,
value.table_route.expect("expected table_route"),
Expand All @@ -152,7 +153,8 @@ impl MigrateTableMetadata {

let new_table_value = NextTableRouteValue::new(table_route.region_routes);

let new_key = NextTableRouteKey::new(table_route.table.id as u32);
let table_id = table_route.table.id as u32;
let new_key = NextTableRouteKey::new(table_id);
info!("Creating '{new_key}'");

if self.dryrun {
Expand All @@ -168,7 +170,7 @@ impl MigrateTableMetadata {
.unwrap();
}

Ok(())
Ok(table_id)
}

async fn migrate_schema_keys(&self) -> Result<()> {
Expand Down Expand Up @@ -310,7 +312,7 @@ impl MigrateTableMetadata {

async fn delete_migrated_keys(&self, keys: Vec<Vec<u8>>) {
for keys in keys.chunks(PAGE_SIZE) {
info!("Deleting {} TableGlobalKeys", keys.len());
info!("Deleting {} keys", keys.len());
let req = BatchDeleteRequest {
keys: keys.to_vec(),
prev_kv: false,
Expand Down

0 comments on commit 9352649

Please sign in to comment.