Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backup): ensure correct delta log order #12371

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/meta/src/backup_restore/meta_snapshot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::future::Future;

use anyhow::anyhow;
Expand Down Expand Up @@ -65,18 +65,22 @@ impl<S: MetaStore> MetaSnapshotBuilder<S> {
// hummock_version and version_stats is guaranteed to exist in a initialized cluster.
let hummock_version = {
let mut redo_state = hummock_version;
let hummock_version_deltas =
HummockVersionDelta::list_at_snapshot::<S>(&meta_store_snapshot).await?;
for version_delta in &hummock_version_deltas {
let hummock_version_deltas: BTreeMap<_, _> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some comments of this fix ?

HummockVersionDelta::list_at_snapshot::<S>(&meta_store_snapshot)
.await?
.into_iter()
.map(|d| (d.id, d))
.collect();
for version_delta in hummock_version_deltas.values() {
if version_delta.prev_id == redo_state.id {
redo_state.apply_version_delta(version_delta);
}
}
if let Some(log) = hummock_version_deltas.iter().next_back() {
if log.id != redo_state.id {
if let Some((max_log_id, _)) = hummock_version_deltas.last_key_value() {
if *max_log_id != redo_state.id {
return Err(BackupError::Other(anyhow::anyhow!(format!(
"inconsistent hummock version: expected {}, actual {}",
log.id, redo_state.id
max_log_id, redo_state.id
))));
}
}
Expand Down
Loading