mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
Merge vector-metadata-index-worker into vector-metadata-index-admin
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ef6cda9ab6
3 files changed
+75
-18
No files matched your search
@@ -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,11 +369,24 @@ 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -930,7 +930,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 {
|
||||
@@ -983,7 +984,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 {}))
|
||||
}
|
||||
|
||||
@@ -995,6 +996,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,
|
||||
|
||||
Reference in new issue
Block a user