Skip to content

Commit

Permalink
core: log parents[0] / node_id mismatch (#9241)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
spolu authored Dec 10, 2024
1 parent f726c72 commit 41a906b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
55 changes: 55 additions & 0 deletions core/bin/core_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,17 @@ async fn data_sources_documents_update_parents(
) -> (StatusCode, Json<APIResponse>) {
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2068,6 +2090,17 @@ async fn tables_upsert(
) -> (StatusCode, Json<APIResponse>) {
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(
Expand Down Expand Up @@ -2305,6 +2338,17 @@ async fn tables_update_parents(
) -> (StatusCode, Json<APIResponse>) {
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)
Expand Down Expand Up @@ -2690,6 +2734,17 @@ async fn folders_upsert(
) -> (StatusCode, Json<APIResponse>) {
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(
Expand Down
18 changes: 1 addition & 17 deletions core/src/data_sources/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 41a906b

Please sign in to comment.