From 6ac6f398aff1a2afaa30601a1bc020d6d15a147c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 20 Nov 2026 09:26:17 -0800 Subject: [PATCH 1/4] vector: test a late query of a dropped table after the next table's first one Co-Authored-By: Claude Opus 5.5 --- seaweed-vector/crates/server/src/filter_stats.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/seaweed-vector/crates/server/src/filter_stats.rs b/seaweed-vector/crates/server/src/filter_stats.rs index 5cc5ccfd5f..3f3c6fa2ec 100644 --- a/seaweed-vector/crates/server/src/filter_stats.rs +++ b/seaweed-vector/crates/server/src/filter_stats.rs @@ -359,4 +359,17 @@ mod tests { stats.record_table_at("b/i", "t4", &author, Duration::ZERO, t0); assert_eq!(count(&stats), 1); } + + #[test] + fn a_late_query_after_a_drop_is_not_counted_on_the_new_table() { + let stats = FilterStats::new(); + let t0 = stats.start; + let author = keys(&[("author", operand::STRING)]); + stats.record_table_at("b/i", "t1", &author, Duration::ZERO, t0); + stats.forget("b/i"); + stats.record_table_at("b/i", "t2", &author, Duration::ZERO, t0); + stats.record_table_at("b/i", "t2", &author, Duration::ZERO, t0); + stats.record_table_at("b/i", "t1", &author, Duration::ZERO, t0); + assert_eq!(stats.snapshot_at("b/i", t0).keys[0].queries, 2); + } } From 9f170a08a4b2d172ea2ca52754863de7ca0ba08f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 20 Nov 2026 09:26:17 -0800 Subject: [PATCH 2/4] vector: test PutVectors at a version from before a key's column add Co-Authored-By: Claude Opus 5.5 --- .../crates/server/src/indexed_keys_tests.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/seaweed-vector/crates/server/src/indexed_keys_tests.rs b/seaweed-vector/crates/server/src/indexed_keys_tests.rs index 7fdb9e2664..e1e2581253 100644 --- a/seaweed-vector/crates/server/src/indexed_keys_tests.rs +++ b/seaweed-vector/crates/server/src/indexed_keys_tests.rs @@ -579,6 +579,29 @@ async fn a_write_that_raced_the_column_add_fills_the_column() { assert_eq!(fixture.flat(latest, filter, 400, &v).await.len(), 4); } +/// A write names no version: one at a version from before a key's column +/// add would commit rows without the column. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_write_at_an_older_version_is_refused() { + let fixture = Fixture::new().await; + fixture + .put((0..10).map(|i| row(i, author(i))).collect()) + .await; + let before = fixture.dataset(0).await.version().version; + fixture.index_author().await; + let mut table = fixture.table.clone(); + table.version = before; + let refused = fixture + .server + .put_vectors(Request::new(pb::PutVectorsRequest { + table: Some(table), + vectors: (10..20).map(|i| row(i, author(i))).collect(), + })) + .await + .unwrap_err(); + assert_eq!(refused.code(), tonic::Code::InvalidArgument); +} + /// Two writes updating the same keys raced the column add, and the first /// one's fill commits last: each write's rows get the values of its own /// metadata, not the ones derived before it or from the other write. From 178de8bf080338d2d419faf5161578ece396c89e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 20 Nov 2026 09:26:50 -0800 Subject: [PATCH 3/4] vector: keep a dropped table retired when its index's stats are forgotten Dropping or creating an index removed its stats entry, and the retired tables with it, so a late query of the dropped table that came after the new table's first one reset the new table's stats. Co-Authored-By: Claude Opus 5.5 --- .../crates/server/src/filter_stats.rs | 51 ++++++++++++------- seaweed-vector/crates/server/src/service.rs | 5 +- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/seaweed-vector/crates/server/src/filter_stats.rs b/seaweed-vector/crates/server/src/filter_stats.rs index 3f3c6fa2ec..a3bce33267 100644 --- a/seaweed-vector/crates/server/src/filter_stats.rs +++ b/seaweed-vector/crates/server/src/filter_stats.rs @@ -46,6 +46,25 @@ struct IndexStats { last: u64, } +impl IndexStats { + /// Starts counting on `table`, retiring the table counted on before. + fn replace(&mut self, table: &str) { + let mut retired = std::mem::take(&mut self.retired); + if !self.table.is_empty() { + retired.push(std::mem::take(&mut self.table)); + if retired.len() > MAX_RETIRED_TABLES { + retired.remove(0); + } + } + *self = IndexStats { + table: table.to_string(), + retired, + last: self.last, + ..Default::default() + }; + } +} + /// Whether bucket `at` is still in the window of bucket `now`. fn live(at: u64, now: u64) -> bool { at + BUCKETS as u64 > now @@ -74,9 +93,15 @@ impl FilterStats { (now.duration_since(self.start).as_secs() / BUCKET.as_secs()) + 1 } - /// Drops the stats of `index`, whose table was created or dropped. - pub fn forget(&self, index: &str) { - self.indexes.lock().unwrap().remove(index); + /// Drops the stats of `index`, which now holds `table` ("" once + /// dropped): late queries of the table it held before are not counted. + pub fn forget(&self, index: &str, table: &str) { + let mut indexes = self.indexes.lock().unwrap(); + if let Some(stats) = indexes.get_mut(index) + && (table.is_empty() || stats.table != table) + { + stats.replace(table); + } } /// One query of `index`, whose table is `table`, that took `elapsed` and @@ -119,19 +144,11 @@ impl FilterStats { if stats.retired.iter().any(|t| t == table) { return; } - if !stats.table.is_empty() { - let mut retired = std::mem::take(&mut stats.retired); - retired.push(std::mem::take(&mut stats.table)); - if retired.len() > MAX_RETIRED_TABLES { - retired.remove(0); - } - *stats = IndexStats { - retired, - last: stats.last, - ..Default::default() - }; + if stats.table.is_empty() { + stats.table = table.to_string(); + } else { + stats.replace(table); } - stats.table = table.to_string(); } stats.last = stats.last.max(at); for (key, kinds) in keys { @@ -352,7 +369,7 @@ mod tests { // A late query of the old table is not counted on the new one. stats.record_table_at("b/i", "t1", &author, Duration::ZERO, t0); assert_eq!(count(&stats), 1); - stats.forget("b/i"); + stats.forget("b/i", ""); assert_eq!(count(&stats), 0); // A first query records its table: a later table starts over. stats.record_table_at("b/i", "t3", &author, Duration::ZERO, t0); @@ -366,7 +383,7 @@ mod tests { let t0 = stats.start; let author = keys(&[("author", operand::STRING)]); stats.record_table_at("b/i", "t1", &author, Duration::ZERO, t0); - stats.forget("b/i"); + stats.forget("b/i", ""); stats.record_table_at("b/i", "t2", &author, Duration::ZERO, t0); stats.record_table_at("b/i", "t2", &author, Duration::ZERO, t0); stats.record_table_at("b/i", "t1", &author, Duration::ZERO, t0); diff --git a/seaweed-vector/crates/server/src/service.rs b/seaweed-vector/crates/server/src/service.rs index 5e725a10a1..9f90c5e7f2 100644 --- a/seaweed-vector/crates/server/src/service.rs +++ b/seaweed-vector/crates/server/src/service.rs @@ -920,7 +920,8 @@ impl VectorService for VectorServer { .await; let dataset = match dataset { Ok(dataset) => { - self.filter_stats.forget(&table.id.join("/")); + self.filter_stats + .forget(&table.id.join("/"), table_id(&dataset)); dataset } Err(error) => match self.open(&table).await { @@ -973,7 +974,7 @@ impl VectorService for VectorServer { store.remove_dir_all(path).await.map_err(internal)?; } } - self.filter_stats.forget(&table.id.join("/")); + self.filter_stats.forget(&table.id.join("/"), ""); Ok(Response::new(pb::DropIndexResponse {})) } From a76bc41b9c89a3e967915fe0e2b1117d6a464820 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 20 Nov 2026 09:26:51 -0800 Subject: [PATCH 4/4] vector: refuse PutVectors at a table version Table.version pins reads. A write opened at a version from before a key's column add would commit rows without the column after the key went ready, past the write deadline and the grace pass. Co-Authored-By: Claude Opus 5.5 --- seaweed-vector/crates/server/src/service.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/seaweed-vector/crates/server/src/service.rs b/seaweed-vector/crates/server/src/service.rs index 9f90c5e7f2..e43cb36bff 100644 --- a/seaweed-vector/crates/server/src/service.rs +++ b/seaweed-vector/crates/server/src/service.rs @@ -986,6 +986,9 @@ impl VectorService for VectorServer { let table = req .table .ok_or_else(|| Status::invalid_argument("missing table"))?; + if table.version != 0 { + return Err(Status::invalid_argument("a write takes no table version")); + } // A write commits within its deadline of opening the table or not // at all: a key's column add waits longer than that before the key // is ready, so a write that opened before the add has committed,