From 0615103c56fff3e43df910c103975c8242079584 Mon Sep 17 00:00:00 2001 From: overtrue Date: Sun, 6 Dec 2026 01:51:21 +0800 Subject: [PATCH 1/3] fix(ecstore): retain explicit URL pools during startup expansion Signed-off-by: overtrue --- crates/ecstore/src/core/pools.rs | 188 ++++++++++++++++++++++++++++--- 1 file changed, 173 insertions(+), 15 deletions(-) diff --git a/crates/ecstore/src/core/pools.rs b/crates/ecstore/src/core/pools.rs index 647f522618..4223623ddc 100644 --- a/crates/ecstore/src/core/pools.rs +++ b/crates/ecstore/src/core/pools.rs @@ -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,17 @@ impl PoolMeta { .is_some()) } + fn single_pool_cmd_line_promotion(&self, pools: &[Arc]) -> 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.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>) -> Result { struct PoolInfo { position: usize, @@ -11512,19 +11528,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 +11539,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 +11549,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 +12072,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; @@ -32474,6 +32501,137 @@ 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(second), Arc::clone(first)]); + let mut decommissioning = persisted_old.clone(); + 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() { From 4c5d27c58a55fd69b37f09cdd5375db2b1c2081b Mon Sep 17 00:00:00 2001 From: overtrue Date: Sun, 6 Dec 2026 01:54:15 +0800 Subject: [PATCH 2/3] fix(ecstore): require an appended pool for URL promotion Signed-off-by: overtrue --- crates/ecstore/src/core/pools.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ecstore/src/core/pools.rs b/crates/ecstore/src/core/pools.rs index 4223623ddc..a6c391f83d 100644 --- a/crates/ecstore/src/core/pools.rs +++ b/crates/ecstore/src/core/pools.rs @@ -11481,6 +11481,7 @@ impl PoolMeta { }; // 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) @@ -32614,6 +32615,7 @@ mod pools_tests { 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.clone(); decommissioning.pools[0].decommission = Some(PoolDecommissionInfo::default()); From e29611920a229238946e441966a8413ae1df885f Mon Sep 17 00:00:00 2001 From: overtrue Date: Sun, 6 Dec 2026 02:12:34 +0800 Subject: [PATCH 3/3] test(ecstore): move pool metadata in startup regression Signed-off-by: overtrue --- crates/ecstore/src/core/pools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ecstore/src/core/pools.rs b/crates/ecstore/src/core/pools.rs index a6c391f83d..5f7c18c2f1 100644 --- a/crates/ecstore/src/core/pools.rs +++ b/crates/ecstore/src/core/pools.rs @@ -32617,7 +32617,7 @@ mod pools_tests { } 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.clone(); + let mut decommissioning = persisted_old; decommissioning.pools[0].decommission = Some(PoolDecommissionInfo::default()); reject_add_remove(&decommissioning, both.to_vec()); assert!(