From 41a906b0ca13c17689568eac1b6d7037dd87d234 Mon Sep 17 00:00:00 2001 From: Stanislas Polu Date: Tue, 10 Dec 2024 12:02:50 +0100 Subject: [PATCH] core: log parents[0] / node_id mismatch (#9241) * core: log parents that are not self * KWSearch invariant log * remove unused * fix log * more compact log * remove old log * clean-up imports * better logging --- core/bin/core_api.rs | 55 ++++++++++++++++++++++++++++ core/src/data_sources/data_source.rs | 18 +-------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/core/bin/core_api.rs b/core/bin/core_api.rs index 081e9c8eeb29..7881b73de5dd 100644 --- a/core/bin/core_api.rs +++ b/core/bin/core_api.rs @@ -1478,6 +1478,17 @@ async fn data_sources_documents_update_parents( ) -> (StatusCode, Json) { let project = project::Project::new_from_id(project_id); + if payload.parents.get(0) != Some(&document_id) { + info!( + data_source_id = data_source_id, + node_id = document_id, + parents = ?payload.parents, + node_type = "document", + operation = "update_parents", + "[KWSEARCH] invariant_first_parent_self" + ); + } + match state .store .load_data_source(&project, &data_source_id) @@ -1625,6 +1636,17 @@ async fn data_sources_documents_upsert( None => false, }; + if payload.parents.get(0) != Some(&payload.document_id) { + info!( + data_source_id = data_source_id, + node_id = payload.document_id, + parents = ?payload.parents, + node_type = "document", + operation = "upsert", + "[KWSEARCH] invariant_first_parent_self" + ); + } + match state .store .load_data_source(&project, &data_source_id) @@ -2068,6 +2090,17 @@ async fn tables_upsert( ) -> (StatusCode, Json) { let project = project::Project::new_from_id(project_id); + if payload.parents.get(0) != Some(&payload.table_id) { + info!( + data_source_id = data_source_id, + node_id = payload.table_id, + parents = ?payload.parents, + node_type = "table", + operation = "upsert", + "[KWSEARCH] invariant_first_parent_self" + ); + } + match state .store .upsert_data_source_table( @@ -2305,6 +2338,17 @@ async fn tables_update_parents( ) -> (StatusCode, Json) { let project = project::Project::new_from_id(project_id); + if payload.parents.get(0) != Some(&table_id) { + info!( + data_source_id = data_source_id, + node_id = table_id, + parents = ?payload.parents, + node_type = "table", + operation = "update_parents", + "[KWSEARCH] invariant_first_parent_self" + ); + } + match state .store .load_data_source_table(&project, &data_source_id, &table_id) @@ -2690,6 +2734,17 @@ async fn folders_upsert( ) -> (StatusCode, Json) { let project = project::Project::new_from_id(project_id); + if payload.parents.get(0) != Some(&payload.folder_id) { + info!( + data_source_id = data_source_id, + node_id = payload.folder_id, + parents = ?payload.parents, + node_type = "folder", + operation = "upsert", + "[KWSEARCH] invariant_first_parent_self" + ); + } + match state .store .upsert_data_source_folder( diff --git a/core/src/data_sources/data_source.rs b/core/src/data_sources/data_source.rs index 9ed0beb832fa..747c45f74fc0 100644 --- a/core/src/data_sources/data_source.rs +++ b/core/src/data_sources/data_source.rs @@ -26,7 +26,7 @@ use std::collections::HashMap; use std::fmt; use std::str::FromStr; use tokio_stream::{self as stream}; -use tracing::{error, info, warn}; +use tracing::{error, info}; use uuid::Uuid; /// Section is used to represent the structure of document to be taken into account during chunking. @@ -627,22 +627,6 @@ impl DataSource { ))?; } - if parents.is_empty() { - warn!( - document_id = document_id, - timestamp = ?timestamp, - parents = ?parents, - "Upserting a document without any parent" - ); - } else if parents[0] != document_id { - warn!( - document_id = document_id, - timestamp = ?timestamp, - parents = ?parents, - "Upserting a document that is not self-referenced as its parent" - ); - } - let store = store.clone(); let current_system_tags = if preserve_system_tags {