Skip to content
Snippets Groups Projects
Commit b348a5b1 authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

draft: refactor applying snapshot

parent 32a176af
No related branches found
No related tags found
1 merge request!643refactor applying snapshot
Pipeline #22366 passed
...@@ -1229,42 +1229,26 @@ impl NodeImpl { ...@@ -1229,42 +1229,26 @@ impl NodeImpl {
} }
); );
let v_local = local_schema_version().expect("storage souldn't fail");
let v_global = self
.storage
.properties
.global_schema_version()
.expect("storage shouldn't fail");
let v_snapshot = snapshot_data.schema_version; let v_snapshot = snapshot_data.schema_version;
assert!( loop {
v_global <= v_local, let v_local = local_schema_version().expect("storage souldn't fail");
"global schema version is only ever increased after local" let v_global = self
); .storage
assert!( .properties
v_global <= v_snapshot, .global_schema_version()
"global schema version updates are distributed via raft" .expect("storage shouldn't fail");
);
if v_local > v_snapshot { assert!(
tlog!( v_global <= v_local,
Warning, "global schema version is only ever increased after local"
"skipping stale snapshot: local schema version: {}, snapshot schema version: {}",
v_local,
snapshot_data.schema_version,
); );
return None;
}
loop { assert!(
if !self.is_readonly() { v_global <= v_snapshot,
break; "global schema version updates are distributed via raft"
} );
let v_local = local_schema_version().expect("storage error");
if v_local == v_snapshot {
break;
}
if v_local > v_snapshot { if v_local > v_snapshot {
tlog!( tlog!(
Warning, Warning,
...@@ -1275,11 +1259,22 @@ impl NodeImpl { ...@@ -1275,11 +1259,22 @@ impl NodeImpl {
return None; return None;
} }
if !self.is_readonly() {
// Replicaset leader applies the schema changes directly.
return Some(snapshot_data);
}
if v_local == v_snapshot {
// Replicaset follower has synced schema with the leader,
// now global space dumps should be handled.
return Some(snapshot_data);
}
// Replicaset follower needs to sync with leader via tarantool
// replication.
let timeout = MainLoop::TICK * 4; let timeout = MainLoop::TICK * 4;
fiber::sleep(timeout); fiber::sleep(timeout);
} }
Some(snapshot_data)
})(); })();
if let Some(snapshot_data) = snapshot_data { if let Some(snapshot_data) = snapshot_data {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment