mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-06 04:26:02 +08:00
test(release): include startup expansion fix in main replay
Signed-off-by: overtrue <anzhengchao@gmail.com>
This commit is contained in:
@@ -10021,11 +10021,13 @@ impl PoolMeta {
|
||||
.and_then(|cmd_line| new_pool_indices.get(cmd_line).copied())
|
||||
};
|
||||
|
||||
let promoted_pool = prev_meta.single_pool_cmd_line_promotion(pools);
|
||||
for (idx, pool) in pools.iter().enumerate() {
|
||||
let Some(current_pool) = prev_meta
|
||||
.pools
|
||||
.iter()
|
||||
.find(|current_pool| current_pool.cmd_line == pool.endpoints.cmd_line)
|
||||
.or_else(|| promoted_pool.filter(|_| idx == 0))
|
||||
else {
|
||||
new_meta.pools.push(PoolStatus {
|
||||
cmd_line: pool.endpoints.cmd_line.clone(),
|
||||
@@ -10037,6 +10039,9 @@ impl PoolMeta {
|
||||
};
|
||||
|
||||
let mut retained_pool = current_pool.clone();
|
||||
if retained_pool.cmd_line != pool.endpoints.cmd_line {
|
||||
retained_pool.cmd_line.clone_from(&pool.endpoints.cmd_line);
|
||||
}
|
||||
if let Some(info) = retained_pool.decommission.as_mut() {
|
||||
for entry in &mut info.unresolved_entries {
|
||||
if remap_pool_index(entry.pool_index) != Some(idx) {
|
||||
@@ -11470,6 +11475,18 @@ impl PoolMeta {
|
||||
.is_some())
|
||||
}
|
||||
|
||||
fn single_pool_cmd_line_promotion(&self, pools: &[Arc<Sets>]) -> Option<&PoolStatus> {
|
||||
let ([old_pool], Some(first)) = (self.pools.as_slice(), pools.first()) else {
|
||||
return None;
|
||||
};
|
||||
// A single pool can change to ellipses when it remains pool 0.
|
||||
(old_pool.decommission.is_none()
|
||||
&& (pools.len() > 1 || !old_pool.cmd_line.contains("://"))
|
||||
&& pools.iter().all(|pool| pool.endpoints.cmd_line != old_pool.cmd_line)
|
||||
&& matches_single_pool_cmd_line_promotion(&old_pool.cmd_line, &first.endpoints))
|
||||
.then_some(old_pool)
|
||||
}
|
||||
|
||||
pub fn validate(&self, pools: Vec<Arc<Sets>>) -> Result<bool> {
|
||||
struct PoolInfo {
|
||||
position: usize,
|
||||
@@ -11512,19 +11529,7 @@ impl PoolMeta {
|
||||
// even when its command line still matches the current topology.
|
||||
let mut update = !self.pool_ids_are_indexed();
|
||||
|
||||
// Allow single-pool canonical cmd_line promotion (e.g. `/data/rustfs1` ->
|
||||
// `/data/rustfs{1...1}` or `http://node1:9000/data/rustfs{1...1}`,
|
||||
// `/data/rustfs{1...4}` -> `http://node1:9000/data/rustfs{1...4}`, or
|
||||
// legacy space-joined `/data1 /data2` -> `http://node1:9000/data{1...2}`)
|
||||
// when pool 0 stays on a single host with identical expanded file paths
|
||||
// in exact order.
|
||||
let single_pool_path_promotion = self.pools.len() == 1
|
||||
&& !self.pools[0].cmd_line.contains("://")
|
||||
&& self.pools[0].decommission.is_none()
|
||||
&& !specified_pools.contains_key(&self.pools[0].cmd_line)
|
||||
&& pools
|
||||
.first()
|
||||
.is_some_and(|p0| matches_single_pool_path_promotion(&self.pools[0].cmd_line, &p0.endpoints));
|
||||
let single_pool_cmd_line_promotion = self.single_pool_cmd_line_promotion(&pools).is_some();
|
||||
|
||||
let mut added_indices = Vec::new();
|
||||
let mut retained_old_positions = Vec::new();
|
||||
@@ -11535,7 +11540,7 @@ impl PoolMeta {
|
||||
if let Some(pi) = remembered_pools.get(cmd) {
|
||||
ensure_pool_not_left_in_cmdline_after_decommission(pi.position, cmd, pi.completed)?;
|
||||
retained_old_positions.push((pi.position, idx, cmd.as_str()));
|
||||
} else if single_pool_path_promotion && idx == 0 {
|
||||
} else if single_pool_cmd_line_promotion && idx == 0 {
|
||||
retained_old_positions.push((0, 0, cmd.as_str()));
|
||||
update = true;
|
||||
} else {
|
||||
@@ -11545,7 +11550,7 @@ impl PoolMeta {
|
||||
}
|
||||
|
||||
for (idx, pool) in self.pools.iter().enumerate() {
|
||||
if !specified_pools.contains_key(&pool.cmd_line) && !(single_pool_path_promotion && idx == 0) {
|
||||
if !specified_pools.contains_key(&pool.cmd_line) && !(single_pool_cmd_line_promotion && idx == 0) {
|
||||
removed_remembered.push((idx, pool.cmd_line.as_str()));
|
||||
update = true;
|
||||
}
|
||||
@@ -12068,6 +12073,29 @@ fn invalidate_decommission_fast_capacity_grants_for_target(store_id: uuid::Uuid,
|
||||
}
|
||||
}
|
||||
|
||||
fn matches_single_pool_cmd_line_promotion(old_cmd: &str, p0: &crate::layout::endpoints::PoolEndpoints) -> bool {
|
||||
if !old_cmd.contains("://") {
|
||||
return matches_single_pool_path_promotion(old_cmd, p0);
|
||||
}
|
||||
if p0.legacy || !p0.endpoints.as_ref().iter().all(|ep| ep.url.has_host()) {
|
||||
return false;
|
||||
}
|
||||
let Ok(layout) =
|
||||
crate::layout::disks_layout::DisksLayout::from_volumes_with_set_drive_count(&[&p0.cmd_line], p0.drives_per_set)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// The legacy command stores explicit arguments joined with a space. An
|
||||
// endpoint whose port is absent after URL parsing used the listen port,
|
||||
// which is not available from the persisted command on its own.
|
||||
let old_arguments = old_cmd.split(' ');
|
||||
old_arguments
|
||||
.clone()
|
||||
.all(|raw| url::Url::parse(raw).is_ok_and(|url| url.port().is_some()))
|
||||
&& old_arguments.eq(layout.pools.iter().flat_map(|pool| pool.iter().flatten().map(String::as_str)))
|
||||
}
|
||||
|
||||
fn matches_single_pool_path_promotion(old_cmd: &str, p0: &crate::layout::endpoints::PoolEndpoints) -> bool {
|
||||
if old_cmd.contains("://") || old_cmd.is_empty() {
|
||||
return false;
|
||||
@@ -32503,6 +32531,138 @@ mod pools_tests {
|
||||
Arc::new(|_| Box::pin(async {}))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn pool_meta_preserves_explicit_url_pool_when_expanding_on_startup() {
|
||||
use crate::layout::endpoints::SetupType;
|
||||
|
||||
let old_endpoints: Vec<_> = (0..4)
|
||||
.map(|disk| format!("http://127.0.0.1:9000/pool-expansion-test/node0/drive{disk}"))
|
||||
.collect();
|
||||
let (initial, initial_setup) =
|
||||
EndpointServerPools::from_volumes_with_set_drive_count("127.0.0.1:9000", old_endpoints.clone(), Some(4))
|
||||
.await
|
||||
.expect("explicit URL pool should configure");
|
||||
assert_eq!(initial_setup, SetupType::Erasure);
|
||||
|
||||
let expanded_cmds: Vec<_> = (0..3)
|
||||
.map(|node| format!("http://127.0.0.1:{}/pool-expansion-test/node{node}/drive{{0...3}}", 9000 + node))
|
||||
.collect();
|
||||
let (expanded, expanded_setup) =
|
||||
EndpointServerPools::from_volumes_with_set_drive_count("127.0.0.1:9000", expanded_cmds.clone(), Some(4))
|
||||
.await
|
||||
.expect("appended URL pools should configure");
|
||||
assert_eq!(expanded_setup, SetupType::DistErasure);
|
||||
|
||||
let ctx = Arc::new(InstanceContext::new());
|
||||
let mut fixtures = Vec::new();
|
||||
let mut pools = Vec::new();
|
||||
for (pool_idx, endpoints) in expanded.0.into_iter().enumerate() {
|
||||
let (dirs, mut pool) = make_local_two_set_sets_for_pool_with_ctx(Arc::clone(&ctx), pool_idx).await;
|
||||
Arc::get_mut(&mut pool).unwrap().endpoints = endpoints;
|
||||
fixtures.push(dirs);
|
||||
pools.push(pool);
|
||||
}
|
||||
let [first, second, third] = pools.as_slice() else {
|
||||
panic!("expected three configured pools");
|
||||
};
|
||||
let both = [Arc::clone(first), Arc::clone(second)];
|
||||
let last_update = OffsetDateTime::UNIX_EPOCH;
|
||||
let old_meta = PoolMeta {
|
||||
version: super::POOL_META_GENERATION_VERSION,
|
||||
pools: vec![PoolStatus {
|
||||
id: 0,
|
||||
cmd_line: initial.0[0].cmd_line.clone(),
|
||||
last_update,
|
||||
decommission: None,
|
||||
}],
|
||||
dont_save: false,
|
||||
};
|
||||
let revision = super::PoolMetaRevision {
|
||||
version: old_meta.version,
|
||||
cluster_id: Some(uuid::Uuid::new_v4()),
|
||||
epoch: 1,
|
||||
generation: 1,
|
||||
transaction_id: Some(uuid::Uuid::new_v4()),
|
||||
};
|
||||
let round_trip_committed_meta = |meta: &PoolMeta, revision| {
|
||||
let bytes = super::encode_pool_meta_v3_envelope(meta, revision, true, None).expect("encode committed metadata");
|
||||
let mut round_trip = PoolMeta::default();
|
||||
round_trip.load_from_config_data(bytes).expect("decode committed metadata");
|
||||
round_trip
|
||||
};
|
||||
|
||||
let persisted_old = round_trip_committed_meta(&old_meta, revision);
|
||||
assert!(persisted_old.validate(both.to_vec()).expect("the first pool is retained"));
|
||||
let rebuilt = PoolMeta::new(&both, &persisted_old).expect("rebuild startup metadata");
|
||||
let mut restored = round_trip_committed_meta(
|
||||
&rebuilt,
|
||||
super::PoolMetaRevision {
|
||||
generation: 2,
|
||||
transaction_id: Some(uuid::Uuid::new_v4()),
|
||||
..revision
|
||||
},
|
||||
);
|
||||
assert_eq!(restored.pools[0].cmd_line, expanded_cmds[0]);
|
||||
assert_eq!(restored.pools[0].last_update, last_update);
|
||||
assert_eq!(restored.pools[1].cmd_line, expanded_cmds[1]);
|
||||
assert!(restored.pool_ids_are_indexed());
|
||||
assert!(
|
||||
!restored
|
||||
.validate(both.to_vec())
|
||||
.expect("restart should keep committed metadata")
|
||||
);
|
||||
assert!(restored.validate(pools.clone()).expect("a later append should remain valid"));
|
||||
|
||||
let reject_add_remove = |meta: &PoolMeta, config| {
|
||||
let error = meta
|
||||
.validate(config)
|
||||
.expect_err("must reject simultaneous addition and removal");
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("cannot simultaneously add new pools and remove existing pools")
|
||||
);
|
||||
};
|
||||
let mut reversed = old_endpoints.clone();
|
||||
reversed.reverse();
|
||||
for changed_cmd in [
|
||||
reversed.join(" "),
|
||||
persisted_old.pools[0].cmd_line.replace("drive2", "other2"),
|
||||
persisted_old.pools[0].cmd_line.replace("127.0.0.1", "127.0.0.2"),
|
||||
persisted_old.pools[0].cmd_line.replace(":9000", ":9003"),
|
||||
persisted_old.pools[0].cmd_line.replace("http:", "https:"),
|
||||
] {
|
||||
let mut changed = persisted_old.clone();
|
||||
changed.pools[0].cmd_line = changed_cmd;
|
||||
reject_add_remove(&changed, both.to_vec());
|
||||
}
|
||||
for unresolved_port in ["", ":80"] {
|
||||
let mut first_endpoints = first.endpoints.clone();
|
||||
first_endpoints.cmd_line = first_endpoints.cmd_line.replace(":9000", unresolved_port);
|
||||
let old_cmd = persisted_old.pools[0].cmd_line.replace(":9000", unresolved_port);
|
||||
assert!(!super::matches_single_pool_cmd_line_promotion(&old_cmd, &first_endpoints));
|
||||
}
|
||||
reject_add_remove(&persisted_old, vec![Arc::clone(first)]);
|
||||
reject_add_remove(&persisted_old, vec![Arc::clone(second), Arc::clone(first)]);
|
||||
let mut decommissioning = persisted_old;
|
||||
decommissioning.pools[0].decommission = Some(PoolDecommissionInfo::default());
|
||||
reject_add_remove(&decommissioning, both.to_vec());
|
||||
assert!(
|
||||
restored
|
||||
.validate(vec![Arc::clone(second), Arc::clone(first)])
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("pool order drift")
|
||||
);
|
||||
restored.pools[1].decommission = Some(PoolDecommissionInfo {
|
||||
complete: true,
|
||||
..Default::default()
|
||||
});
|
||||
reject_add_remove(&restored, vec![Arc::clone(first), Arc::clone(third)]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
async fn pool_meta_reindexes_ids_after_pool_removal_and_expansion() {
|
||||
|
||||
Reference in New Issue
Block a user