Skip to content

Commit

Permalink
fix(meta): fix order when restoring metadata (#19791)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1e24ca4)
  • Loading branch information
zwang28 committed Dec 17, 2024
1 parent 23ac7db commit 6ed985c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/meta/src/backup_restore/restore_impl/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::cmp;

use itertools::Itertools;
use risingwave_backup::error::{BackupError, BackupResult};
use risingwave_backup::meta_snapshot::MetaSnapshot;
Expand Down Expand Up @@ -108,8 +110,21 @@ impl Writer<MetadataV2> for WriterModelV2ToMetaStoreV2 {
insert_models(metadata.worker_properties.clone(), db).await?;
insert_models(metadata.users.clone(), db).await?;
// The sort is required to pass table's foreign key check.
use risingwave_meta_model::object::ObjectType;
insert_models(
metadata.objects.iter().sorted_by_key(|o| o.oid).cloned(),
metadata
.objects
.iter()
.sorted_by(|a, b| match (a.obj_type, b.obj_type) {
(ObjectType::Database, ObjectType::Database) => a.oid.cmp(&b.oid),
(ObjectType::Database, _) => cmp::Ordering::Less,
(_, ObjectType::Database) => cmp::Ordering::Greater,
(ObjectType::Schema, ObjectType::Schema) => a.oid.cmp(&b.oid),
(ObjectType::Schema, _) => cmp::Ordering::Less,
(_, ObjectType::Schema) => cmp::Ordering::Greater,
(_, _) => a.oid.cmp(&b.oid),
})
.cloned(),
db,
)
.await?;
Expand Down

0 comments on commit 6ed985c

Please sign in to comment.