From cd3c768b9b88c92b9a221ec783368c9acbe26a1f Mon Sep 17 00:00:00 2001 From: Emma Forman Ling Date: Tue, 10 Sep 2024 11:06:10 -0700 Subject: [PATCH] skip usage for orphaned table namespaces (#29724) This PR removed calls to `must_component_path` which will return an error for table namespaced orphaned from incomplete pushes (`start_push` adds them, and `finish_push` might never get called to commit them). These are user tables that should be empty anyway, so we can just skip reporting usage on them and throw an error if they are unexpectedly not empty. GitOrigin-RevId: 2a022edf556906ea3e55298dfcd99d1e1f200b25 --- crates/database/src/database.rs | 36 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/database/src/database.rs b/crates/database/src/database.rs index 2d8150d6..8234e0c7 100644 --- a/crates/database/src/database.rs +++ b/crates/database/src/database.rs @@ -1913,13 +1913,22 @@ impl Database { let tablet_id = *value.name.table(); let table_namespace = table_mapping.tablet_namespace(tablet_id)?; let component_id = ComponentId::from(table_namespace); - let component_path = components_model.must_component_path(component_id)?; let table_name = table_mapping.tablet_name(tablet_id)?; let size = value.config.estimate_pricing_size_bytes()?; - vector_index_storage - .entry((component_path, table_name)) - .and_modify(|sum| *sum += size) - .or_insert(size); + if let Some(component_path) = components_model.get_component_path(component_id) { + vector_index_storage + .entry((component_path, table_name)) + .and_modify(|sum| *sum += size) + .or_insert(size); + } else { + // If there is no component path for this table namespace, this must be an empty + // user table left over from incomplete components push + anyhow::ensure!( + size == 0, + "Table {table_name} is in an orphaned TableNamespace without a component, but \ + has non-zero vector index size {size}", + ); + } } Ok(vector_index_storage) } @@ -1933,9 +1942,20 @@ impl Database { let snapshot = self.snapshot_manager.lock().snapshot(ts)?; let mut document_counts = vec![]; for ((table_namespace, table_name), summary) in snapshot.iter_user_table_summaries() { - let component_path = - components_model.must_component_path(ComponentId::from(table_namespace))?; - document_counts.push((component_path, table_name, summary.num_values() as u64)); + let count = summary.num_values() as u64; + if let Some(component_path) = + components_model.get_component_path(ComponentId::from(table_namespace)) + { + document_counts.push((component_path, table_name, count)); + } else { + // If there is no component path for this table namespace, this must be an empty + // user table left over from incomplete components push + anyhow::ensure!( + count == 0, + "Table {table_name} is in an orphaned TableNamespace without a component, but \ + has document count {count}", + ); + } } Ok(document_counts) }