Skip to content

Commit

Permalink
fix(meta): ensure order when restoring metadata (#19763) (#19769)
Browse files Browse the repository at this point in the history
Co-authored-by: zwang28 <[email protected]>
  • Loading branch information
github-actions[bot] and zwang28 authored Dec 12, 2024
1 parent b901388 commit a310d4b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/meta/src/backup_restore/restore_impl/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use itertools::Itertools;
use risingwave_backup::error::{BackupError, BackupResult};
use risingwave_backup::meta_snapshot::MetaSnapshot;
use risingwave_backup::meta_snapshot_v2::{MetaSnapshotV2, MetadataV2};
Expand Down Expand Up @@ -106,8 +107,21 @@ impl Writer<MetadataV2> for WriterModelV2ToMetaStoreV2 {
insert_models(metadata.workers.clone(), db).await?;
insert_models(metadata.worker_properties.clone(), db).await?;
insert_models(metadata.users.clone(), db).await?;
insert_models(metadata.objects.clone(), db).await?;
insert_models(metadata.user_privileges.clone(), db).await?;
// The sort is required to pass table's foreign key check.
insert_models(
metadata.objects.iter().sorted_by_key(|o| o.oid).cloned(),
db,
)
.await?;
insert_models(
metadata
.user_privileges
.iter()
.sorted_by_key(|u| u.id)
.cloned(),
db,
)
.await?;
insert_models(metadata.object_dependencies.clone(), db).await?;
insert_models(metadata.databases.clone(), db).await?;
insert_models(metadata.schemas.clone(), db).await?;
Expand Down Expand Up @@ -153,7 +167,7 @@ macro_rules! for_all_auto_increment {
};
}

macro_rules! reset_mysql_sequence {
macro_rules! reset_sql_sequence {
($metadata:ident, $db:ident, $( {$table:expr, $model:ident, $id_field:ident} ),*) => {
$(
match $db.get_database_backend() {
Expand Down Expand Up @@ -186,7 +200,7 @@ async fn update_auto_inc(
metadata: &MetadataV2,
db: &impl sea_orm::ConnectionTrait,
) -> BackupResult<()> {
for_all_auto_increment!(metadata, db, reset_mysql_sequence);
for_all_auto_increment!(metadata, db, reset_sql_sequence);
Ok(())
}

Expand Down

0 comments on commit a310d4b

Please sign in to comment.