From ec463fc2fe67f217d7178af498e5a5bf56a2718c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADcio=20Bracht?= Date: Tue, 19 May 2026 12:22:28 -0700 Subject: [PATCH 1/3] remove dead clear_partition for broadcast catalog stores --- .../src/cluster/db/constraint_store.rs | 35 ------------------- .../src/cluster/db/schema_store.rs | 28 --------------- .../src/cluster/store_manager/partition_io.rs | 20 ----------- 3 files changed, 83 deletions(-) diff --git a/crates/mqdb-cluster/src/cluster/db/constraint_store.rs b/crates/mqdb-cluster/src/cluster/db/constraint_store.rs index bf28581..b9a0a04 100644 --- a/crates/mqdb-cluster/src/cluster/db/constraint_store.rs +++ b/crates/mqdb-cluster/src/cluster/db/constraint_store.rs @@ -533,15 +533,6 @@ impl ConstraintStore { Ok(imported) } - - /// # Panics - /// Panics if the internal lock is poisoned. - pub fn clear_partition(&self, partition: PartitionId) -> usize { - let mut constraints = self.constraints.write().unwrap(); - let before = constraints.len(); - constraints.retain(|_, c| c.partition() != partition); - before - constraints.len() - } } impl std::fmt::Debug for ConstraintStore { @@ -978,32 +969,6 @@ mod tests { } } - #[test] - fn clear_partition_removes_only_target() { - let store = ConstraintStore::new(node(1)); - let entities = ["alpha", "beta", "gamma", "delta"]; - for entity in &entities { - store - .add(ClusterConstraint::unique( - entity, - &format!("uniq_{entity}"), - "email", - )) - .unwrap(); - } - - let target = store.get("alpha", "uniq_alpha").unwrap().partition(); - let removed = store.clear_partition(target); - assert!(removed >= 1); - - for entity in &entities { - let c = store.get(entity, &format!("uniq_{entity}")); - if let Some(c) = c { - assert_ne!(c.partition(), target); - } - } - } - #[test] fn export_all_carries_every_constraint_regardless_of_partition() { let src = ConstraintStore::new(node(1)); diff --git a/crates/mqdb-cluster/src/cluster/db/schema_store.rs b/crates/mqdb-cluster/src/cluster/db/schema_store.rs index 7e7e927..aaa9d45 100644 --- a/crates/mqdb-cluster/src/cluster/db/schema_store.rs +++ b/crates/mqdb-cluster/src/cluster/db/schema_store.rs @@ -341,15 +341,6 @@ impl SchemaStore { Ok(imported) } - - /// # Panics - /// Panics if the internal lock is poisoned. - pub fn clear_partition(&self, partition: PartitionId) -> usize { - let mut schemas = self.schemas.write().unwrap(); - let before = schemas.len(); - schemas.retain(|_, s| s.partition() != partition); - before - schemas.len() - } } impl std::fmt::Debug for SchemaStore { @@ -499,25 +490,6 @@ mod tests { } } - #[test] - fn clear_partition_removes_only_target() { - let store = SchemaStore::new(node(1)); - store.register("alpha", b"{}").unwrap(); - store.register("beta", b"{}").unwrap(); - store.register("gamma", b"{}").unwrap(); - - let target = store.get("alpha").unwrap().partition(); - let removed = store.clear_partition(target); - - assert!(removed >= 1); - assert!(store.get("alpha").is_none()); - for entity in ["beta", "gamma"] { - if let Some(s) = store.get(entity) { - assert_ne!(s.partition(), target); - } - } - } - #[test] fn export_all_carries_every_schema_regardless_of_partition() { let src = SchemaStore::new(node(1)); diff --git a/crates/mqdb-cluster/src/cluster/store_manager/partition_io.rs b/crates/mqdb-cluster/src/cluster/store_manager/partition_io.rs index a7664cc..1c2b01e 100644 --- a/crates/mqdb-cluster/src/cluster/store_manager/partition_io.rs +++ b/crates/mqdb-cluster/src/cluster/store_manager/partition_io.rs @@ -196,26 +196,6 @@ impl StoreManager { } } } - - pub fn clear_partition(&self, partition: PartitionId) -> usize { - let mut total_cleared = 0; - total_cleared += self.sessions.clear_partition(partition); - total_cleared += self.qos2.clear_partition(partition); - total_cleared += self.subscriptions.clear_partition(partition); - total_cleared += self.retained.clear_partition(partition); - total_cleared += self.topics.clear_partition(partition); - total_cleared += self.wildcards.clear_partition(partition); - total_cleared += self.inflight.clear_partition(partition); - total_cleared += self.offsets.clear_partition(partition); - total_cleared += self.idempotency.clear_partition(partition); - total_cleared += self.db_data.clear_partition(partition); - total_cleared += self.db_schema.clear_partition(partition); - total_cleared += self.db_index.clear_partition(partition); - total_cleared += self.db_unique.clear_partition(partition); - total_cleared += self.db_fk.clear_partition(partition); - total_cleared += self.db_constraints.clear_partition(partition); - total_cleared - } } #[cfg(test)] From dea25d34f8131958598bed359befa2df4642f3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADcio=20Bracht?= Date: Tue, 19 May 2026 14:30:31 -0700 Subject: [PATCH 2/3] document broadcast catalog invariant on schema and constraint stores --- crates/mqdb-cluster/src/cluster/db/constraint_store.rs | 6 ++++++ crates/mqdb-cluster/src/cluster/db/schema_store.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/crates/mqdb-cluster/src/cluster/db/constraint_store.rs b/crates/mqdb-cluster/src/cluster/db/constraint_store.rs index b9a0a04..e62eee6 100644 --- a/crates/mqdb-cluster/src/cluster/db/constraint_store.rs +++ b/crates/mqdb-cluster/src/cluster/db/constraint_store.rs @@ -205,6 +205,12 @@ impl std::fmt::Display for ConstraintStoreError { impl std::error::Error for ConstraintStoreError {} +/// Cluster-wide constraint catalog (unique + foreign-key definitions). +/// +/// Constraints are broadcast state: every node holds the full catalog and +/// every partition snapshot ships all entries. There is intentionally no +/// per-partition clearing API — a partition wipe must not drop catalog +/// entries that every node is supposed to hold. pub struct ConstraintStore { node_id: NodeId, constraints: RwLock>, diff --git a/crates/mqdb-cluster/src/cluster/db/schema_store.rs b/crates/mqdb-cluster/src/cluster/db/schema_store.rs index aaa9d45..d6b7aa1 100644 --- a/crates/mqdb-cluster/src/cluster/db/schema_store.rs +++ b/crates/mqdb-cluster/src/cluster/db/schema_store.rs @@ -94,6 +94,12 @@ impl std::fmt::Display for SchemaStoreError { impl std::error::Error for SchemaStoreError {} +/// Cluster-wide schema catalog. +/// +/// Schemas are broadcast state: every node holds the full catalog and every +/// partition snapshot ships all entries. There is intentionally no +/// per-partition clearing API — a partition wipe must not drop catalog +/// entries that every node is supposed to hold. pub struct SchemaStore { node_id: NodeId, schemas: RwLock>, From 518d4f86edfbd3aa15776fa83419e8511e32d685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADcio=20Bracht?= Date: Tue, 19 May 2026 14:41:31 -0700 Subject: [PATCH 3/3] bump mqdb-cluster to 0.3.5 and add changelog entry --- CHANGELOG.md | 17 +++++++++++++++++ Cargo.lock | 2 +- crates/mqdb-cluster/Cargo.toml | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 320f4b6..49a2d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. Each entry lists the date and the crate versions that were released. +## 2026-05-19 — mqdb-cluster 0.3.5 + +### Removed + +- `StoreManager::clear_partition` (the 15-line aggregator at `partition_io.rs:206`). It had **no callers anywhere in the codebase** — production, tests, or otherwise — and aggregated per-partition wipes across stores that included the broadcast catalog (schemas, constraints). With schemas and constraints now treated as broadcast state on the export side (every partition snapshot ships the full catalog, per the 0.3.2 / 0.3.4 work), the aggregator was wrong-by-construction: a partition wipe must not drop catalog entries that every node is supposed to hold. +- `SchemaStore::clear_partition` and its `clear_partition_removes_only_target` unit test. The method was referenced only by its own test; nothing in the migration, rebalance, or snapshot paths called it. +- `ConstraintStore::clear_partition` and its `clear_partition_removes_only_target` unit test. Same dead-code-with-self-test status as above. +- Per-partition `clear_partition` on `DbDataStore`, `IndexStore`, `UniqueStore`, `FkValidationStore`, and the MQTT-side stores (sessions, retained, topics, wildcards, inflight, offsets, idempotency, qos2) is intentionally preserved — those stores are genuinely partition-scoped. + +### Changed + +- Added struct-level doc comments on `SchemaStore` and `ConstraintStore` documenting the broadcast-catalog invariant: every node holds the full catalog, every partition snapshot ships all entries, and there is intentionally no per-partition clearing API. Makes the invariant explicit at the point where a future contributor would otherwise consider adding a clearing method. + +### Notes + +- Follow-up to the broadcast-catalog model established by PR #61 (the export-side counterpart). 83 deletions across `partition_io.rs`, `schema_store.rs`, and `constraint_store.rs`; 12 lines of documentation added. + ## 2026-05-06 — mqdb-cli 0.7.6 ### Fixed diff --git a/Cargo.lock b/Cargo.lock index f5610ba..1af7689 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1411,7 +1411,7 @@ dependencies = [ [[package]] name = "mqdb-cluster" -version = "0.3.4" +version = "0.3.5" dependencies = [ "arc-swap", "bebytes", diff --git a/crates/mqdb-cluster/Cargo.toml b/crates/mqdb-cluster/Cargo.toml index 3d9ac80..9c7f375 100644 --- a/crates/mqdb-cluster/Cargo.toml +++ b/crates/mqdb-cluster/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mqdb-cluster" -version = "0.3.4" +version = "0.3.5" publish = false edition.workspace = true license = "AGPL-3.0-only"