Repository navigation
fix: stop three recurring errors on doc delete (#17685) - #17686
yuzhichang merged 12 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughInfinity document metadata now uses tenant-scoped tables. List filters support JSON and legacy Varchar columns. Deletion-marker writes upgrade existing tables when possible and include the new ChangesInfinity compatibility changes
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant DatasetStructureMerger
participant InfinityConnection
participant InfinityTable
DatasetStructureMerger->>InfinityConnection: ensure_columns(index, knowledgebase_id, deleted_doc_id)
InfinityConnection->>InfinityTable: inspect columns and add missing column
DatasetStructureMerger->>InfinityConnection: insert deletion metadata
InfinityConnection->>InfinityTable: insert marker row
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rag/utils/ob_conn.py (1)
102-146: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winAdd
column_deleted_doc_idtoEXTRA_COLUMNS.
EXTRA_COLUMNSis consumed byOBConnection.create_idxto add columns on existing OceanBase chunk tables.column_deleted_doc_idis only incolumn_definitions, so existing tables will keep missing it and can still fail whenrecord_doc_deletioninserts deletion markers.🛠️ Proposed fix
EXTRA_COLUMNS: list[Column] = [ column_order_id, column_group_id, column_mom_id, column_chunk_data, column_raptor_kwd, column_raptor_layer_int, column_n_hop_with_weight, + column_deleted_doc_id, ]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag/utils/ob_conn.py` around lines 102 - 146, Add column_deleted_doc_id to the EXTRA_COLUMNS list used by OBConnection.create_idx, alongside the other migration columns, so existing OceanBase chunk tables receive this column during migration.
🧹 Nitpick comments (2)
rag/svr/task_executor_refactor/dataset_structure_merger.py (2)
184-194: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConsider caching the column-upgrade check to avoid a round trip on every deletion.
ensure_columnsruns an extraget_table+show_columnsround trip on every call torecord_doc_deletion, even long after the column has already been confirmed present on that table. Since the upgrade is idempotent and only ever needs to happen once per table, cache the set of already-verified(tenant, kb)pairs in this module (or insideensure_columnsitself) and skip the call once a table is known to be up to date.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag/svr/task_executor_refactor/dataset_structure_merger.py` around lines 184 - 194, Cache successfully verified (tenant, kb) pairs for the table upgrade performed in record_doc_deletion, and skip ensure_columns for pairs already confirmed. Add appropriate handling so a pair is cached only after ensure_columns succeeds, preserving retries if the upgrade fails while leaving the existing upgrade definition unchanged.
188-194: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAlign the
deleted_doc_idschema used byensure_columns.
record_doc_deletionupgrades existing Infinity chunk tables with{"deleted_doc_id": {"type": "varchar", "default": ""}}, whileconf/infinity_mapping.jsondeclares the same column with"analyzer": "whitespace-#". Upgrades can leavedeleted_doc_idas a non-analyzed varchar, so source this column definition from a single mapping to avoid schema drift.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag/svr/task_executor_refactor/dataset_structure_merger.py` around lines 188 - 194, Update the ensure_columns call in record_doc_deletion to reuse the shared deleted_doc_id definition from conf/infinity_mapping.json or its existing mapping symbol, including the whitespace-# analyzer, instead of constructing a separate varchar/default schema. Preserve the current index and kb_id upgrade flow while eliminating duplicate column definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@common/doc_store/infinity_conn_base.py`:
- Around line 326-354: In the schema-dependent filtering loop around
is_json_col, col_present, and list_conditions, add debug logging once per field
indicating whether the JSON path, legacy Varchar path, or skipped path was
selected. Keep values out of log messages, and avoid logging once per item or
changing the existing predicates.
- Around line 326-347: Restrict the legacy branch in the value-condition loop to
columns whose detected type is Varchar, using the existing col_type value
alongside the string-item check. Keep JSON handling unchanged, skip unknown or
other known column types, and emit filter_fulltext only for Varchar columns.
---
Outside diff comments:
In `@rag/utils/ob_conn.py`:
- Around line 102-146: Add column_deleted_doc_id to the EXTRA_COLUMNS list used
by OBConnection.create_idx, alongside the other migration columns, so existing
OceanBase chunk tables receive this column during migration.
---
Nitpick comments:
In `@rag/svr/task_executor_refactor/dataset_structure_merger.py`:
- Around line 184-194: Cache successfully verified (tenant, kb) pairs for the
table upgrade performed in record_doc_deletion, and skip ensure_columns for
pairs already confirmed. Add appropriate handling so a pair is cached only after
ensure_columns succeeds, preserving retries if the upgrade fails while leaving
the existing upgrade definition unchanged.
- Around line 188-194: Update the ensure_columns call in record_doc_deletion to
reuse the shared deleted_doc_id definition from conf/infinity_mapping.json or
its existing mapping symbol, including the whitespace-# analyzer, instead of
constructing a separate varchar/default schema. Preserve the current index and
kb_id upgrade flow while eliminating duplicate column definitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d0c92842-efa4-4756-a298-ac41190501e3
📒 Files selected for processing (10)
api/db/services/doc_metadata_service.pycommon/doc_store/infinity_conn_base.pyconf/infinity_mapping.jsonrag/svr/task_executor_refactor/dataset_structure_merger.pyrag/utils/infinity_conn.pyrag/utils/ob_conn.pytest/unit_test/api/db/services/test_doc_metadata_service.pytest/unit_test/common/test_infinity_condition.pytest/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.pytest/unit_test/rag/utils/test_infinity_conn_helpers.py
|
Thank you for the review! All feedback items have been addressed in commit
|
|
Tip For best results, initiate chat on the files or code changes.
The OceanBase migration now upgrades existing chunk tables. The Infinity column definition now matches the mapping. The cache avoids repeated table-upgrade operations. The legacy filter fallback is limited to character columns. The updated tests cover the new behavior. 🐇 ✅ ✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
common/doc_store/infinity_conn_base.py (1)
354-360: 🗄️ Data Integrity & Integration | 🔴 Critical | 🏗️ Heavy liftDo not drop unsupported filters before destructive operations.
When a legacy item is not a string, Line [345] skips it. If all items are skipped, Lines [354-360] add no condition. The helper then returns
"1=1"at Line [410].delete()passes that filter totable_instance.delete()at Lines [721-724]. The Infinity delete API applies the filter to selected rows. (infiniflow.org)A condition such as
{"source_doc_ids": [123]}can therefore delete every row instead of failing. The same risk exists when the column is missing from table metadata.Return an explicit unsupported-condition result or raise an error. Ensure destructive callers abort before executing the delete. Add a regression test that verifies
table_instance.delete()is not called.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@common/doc_store/infinity_conn_base.py` around lines 354 - 360, Update the filter-building helper around list_conditions so unsupported or skipped filter values never produce an empty predicate or fall through to the "1=1" result; instead return an explicit unsupported-condition result or raise an error. Ensure delete() detects that result and aborts before calling table_instance.delete(), including when column metadata is missing, and add a regression test asserting the delete method is not invoked.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@test/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.py`:
- Around line 72-77: Update the test around record_doc_deletion to exercise two
different knowledge-base IDs and verify caching remains scoped per knowledge
base. Assert mock_conn.insert received two records whose deleted_doc_id values
are distinct and match the requested document IDs, while preserving the
ensure_columns call-count checks.
- Around line 75-76: Update the caching flow used by record_doc_deletion so a
table is added to _UPGRADED_TABLES only after the deletion-marker insert
succeeds, or after ensure_columns explicitly reports a successful upgrade.
Preserve the existing single-call caching behavior for successful operations,
and add a test covering a swallowed upgrade failure followed by a second
deletion that retries ensure_columns.
---
Outside diff comments:
In `@common/doc_store/infinity_conn_base.py`:
- Around line 354-360: Update the filter-building helper around list_conditions
so unsupported or skipped filter values never produce an empty predicate or fall
through to the "1=1" result; instead return an explicit unsupported-condition
result or raise an error. Ensure delete() detects that result and aborts before
calling table_instance.delete(), including when column metadata is missing, and
add a regression test asserting the delete method is not invoked.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 76da1cff-153f-4bc3-8a17-f0fccd12dfb7
📒 Files selected for processing (4)
common/doc_store/infinity_conn_base.pyrag/svr/task_executor_refactor/dataset_structure_merger.pyrag/utils/ob_conn.pytest/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.py
🚧 Files skipped from review as they are similar to previous changes (2)
- rag/utils/ob_conn.py
- rag/svr/task_executor_refactor/dataset_structure_merger.py
|
Thank you for catching the unconstrained filter delete risk! Addressed in commit
|
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✅ You are interacting with an AI system. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@common/doc_store/infinity_conn_base.py`:
- Around line 722-724: Update the warning in the delete flow around the
condition/filter guard in the relevant method to stop interpolating the raw
condition or filter values. Keep the warning limited to stating that a non-empty
condition produced an unconstrained filter and include only the table name,
preserving the existing early return.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 84f86f4f-8692-47dd-b643-93447fc717d3
📒 Files selected for processing (2)
common/doc_store/infinity_conn_base.pytest/unit_test/common/test_infinity_condition.py
|
Updated the warning format in commit self.logger.warning(
"INFINITY delete aborted: non-empty condition produced an unconstrained filter on table %s.",
table_name,
) |
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✅ You are interacting with an AI system. |
|
All review feedback items have been fully addressed and verified:
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
impl="rag/svr/task_executor_refactor/dataset_structure_merger.py"
test_file="test/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.py"
ast-grep outline "$impl" --items all --match 'record_doc_deletion|_UPGRADED_TABLES' --view expanded || true
ast-grep outline "$test_file" --items all --match 'test_record_doc_deletion_caches_upgraded_tables_per_kb|test_record_doc_deletion_retries_ensure_columns_on_insert_failure' --view expanded || true
printf '\n--- relevant implementation occurrences ---\n'
rg -n -C 12 '_UPGRADED_TABLES|record_doc_deletion|docStoreConn\.insert' "$impl"
printf '\n--- relevant test occurrences ---\n'
rg -n -C 10 'test_record_doc_deletion_caches_upgraded_tables_per_kb|test_record_doc_deletion_retries_ensure_columns_on_insert_failure|_UPGRADED_TABLES' "$test_file"Length of output: 11835
The new tests verify cache scope per knowledge base and retry behavior after an insertion failure. Static inspection confirms the reported behavior. Test execution was not performed in this verification. 🐇 ✅ ✏️ Learnings added
You are interacting with an AI system. |
|
@yuzhichang please review |
There was a problem hiding this comment.
Pull request overview
This PR addresses three recurring Infinity-related errors/warnings during document deletion by making the runtime tolerant of older deployed schemas (missing columns and legacy Varchar-encoded “JSON list” fields) while also updating the “new table” mappings so freshly created tables are correct.
Changes:
- Adds
deleted_doc_idto Infinity and OceanBase chunk-table schemas and introduces a best-effortensure_columns()helper to upgrade existing Infinity tables in place before first use. - Makes Infinity condition translation choose
json_containsvsfilter_fulltextbased on the table’s actual column types, avoidingjson_contains(Varchar, Varchar)failures on legacy tables. - Fixes doc-meta
get()routing forragflow_doc_meta_*tables and updates metadata service callers to pass emptyknowledgebase_idsfor per-tenant metadata indices; adds targeted unit tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
rag/utils/infinity_conn.py |
Special-cases doc-meta get() and adds ensure_columns() for best-effort schema upgrades on existing Infinity tables. |
common/doc_store/infinity_conn_base.py |
Routes JSON-list predicates based on observed column type (Json vs Varchar) and adds a safety guard to abort deletes that would become unconstrained. |
rag/svr/task_executor_refactor/dataset_structure_merger.py |
Ensures deleted_doc_id column exists (via ensure_columns) before writing deletion markers; caches upgraded (index,kb) pairs. |
conf/infinity_mapping.json |
Adds deleted_doc_id to the Infinity mapping so newly created chunk tables include the column. |
rag/utils/ob_conn.py |
Adds deleted_doc_id column to OceanBase chunk-table column definitions for schema parity. |
api/db/services/doc_metadata_service.py |
Passes [] for knowledgebase_ids when using per-tenant doc-meta indexes to avoid incorrect <index>_<kb> table naming under Infinity. |
test/unit_test/common/test_infinity_condition.py |
Adds unit coverage for json_contains vs filter_fulltext routing for JSON-list fields across Json/Varchar/unknown schema cases. |
test/unit_test/rag/utils/test_infinity_conn_helpers.py |
Adds unit tests for doc-meta get() routing and ensure_columns() behavior (idempotency, missing-table, failure swallow). |
test/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.py |
Adds unit tests verifying record_doc_deletion() invokes ensure_columns() and retries upgrade after insert failure. |
test/unit_test/api/db/services/test_doc_metadata_service.py |
Adds unit tests ensuring metadata service uses empty knowledgebase_ids for doc-meta get() calls. |
|
@coderabbitai @Copilot All review feedback items have been fully addressed, verified with unit tests, and resolved:
|
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✅ ✏️ Learnings added
You are interacting with an AI system. |
|
Tip For best results, initiate chat on the files or code changes.
For other The new test covers this error path. Thank you for the fix. 🐇 ✅ You are interacting with an AI system. |
|
Added Go Infinity engine parity in commit
|
|
Added Elasticsearch Go engine parity in commit
|
Follow-up to infiniflow#17526 ("Refactor: merge dataset scope graph"), which introduced two code paths that touch Infinity columns the deployed schema does not declare. This PR makes the runtime robust against the old schema while also adding the new column to the new schema so freshly created tables are correct. 1) (ERROR 3013) "Column deleted_doc_id not found in table …" 'record_doc_deletion' writes a 'doc_deleted' marker row with a 'deleted_doc_id' column, but conf/infinity_mapping.json and rag/utils/ob_conn.py's chunk column list never declared it. • conf/infinity_mapping.json: add 'deleted_doc_id' so new tables pick it up. • rag/utils/ob_conn.py: add 'column_deleted_doc_id' so new OB chunk tables pick it up. • rag/utils/infinity_conn.py: add 'ensure_columns', a best-effort helper that calls Infinity 'add_columns' for any columns missing on an existing chunk table (idempotent for already-present ones). • rag/svr/task_executor_refactor/dataset_structure_merger.py: 'record_doc_deletion' now invokes 'ensure_columns' before 'insert' so pre-existing chunk tables get the column in place during the first delete after upgrade. 2) (WARNING 3030) "json_contains(Varchar, Varchar) not found" The migrated JSON-list columns (source_doc_ids, source_chunk_ids, …) emit 'json_contains(col, "<json-literal>")'. On pre-infiniflow#17288 chunk tables those columns are still Varchar (whitespace analyzer, '###'-joined encoding) and Infinity rejects the call. • common/doc_store/infinity_conn_base.py: 'equivalent_condition_to_str' now reads the actual column type from 'table_instance.show_columns()' and falls back to 'filter_fulltext(col, <bare value>)' when the column is Varchar. New JSON tables keep the 'json_contains' path. Unknown-type columns are skipped (better than emitting a query Infinity would reject). 3) (WARNING) "INFINITY get has only blank knowledgebase_ids for index ragflow_doc_meta_<tenant>" 'DocMetadataService.delete_document_metadata' passed ['"] as the 'knowledgebase_ids' for a per-tenant meta table; the connector then built an empty 'f"<index>_<kb>"' list and logged a misleading warning. Two other call sites passed '[kb_id]' for a per-tenant meta table, which under the old code queried a non-existent '<index>_<kb>' table. • rag/utils/infinity_conn.py: 'get' now special-cases 'ragflow_doc_meta_' (like 'index_exist' / 'insert' / 'delete' already do): the meta table is queried by index name only. The empty-list check is hoisted above the connection acquisition so the blank-list case no longer burns a connection from the pool. • api/db/services/doc_metadata_service.py: the three meta-table 'get' call sites now pass '[]' with a comment explaining why. Tests test/unit_test/common/test_infinity_condition.py — 29 cases for the json_contains/filter_fulltext routing in 'equivalent_condition_to_str', including the Varchar and Json paths for every JSON-list column, apostrophe escaping, numeric handling on Json, and the unknown-type skip. test/unit_test/rag/utils/test_infinity_conn_helpers.py — 9 cases for 'InfinityConnection.get' (meta-table routing) and 'InfinityConnection.ensure_columns' (idempotent column upgrade). test/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.py — 3 cases for 'record_doc_deletion' invoking 'ensure_columns' and 'insert'. test/unit_test/api/db/services/test_doc_metadata_service.py — 2 cases for 'DocMetadataService' metadata get/delete passing empty knowledgebase_ids list.
…alignment, table caching, and type checks
51fc7f2 to
e376ca7
Compare
|
@yuzhichang please review |
wangq8
left a comment
There was a problem hiding this comment.
Excellent, well-structured fix. Here is my detailed review:
Overall: ✅ Approve
This is a high-quality PR — comprehensive, well-tested, and carefully defensive. 43 unit tests across 4 new test files covering all three error paths. The PR description is thorough and the commit is well-scoped.
Fix 1: deleted_doc_id column (ERROR 3013)
conf/infinity_mapping.json and rag/utils/ob_conn.py: ✅ Adding deleted_doc_id to the schema is correct. New tables will pick it up automatically.
rag/utils/infinity_conn.py — ensure_columns: ✅ Good pattern. Idempotent, best-effort, skips non-existent tables, swallows failures gracefully. The _UPGRADED_TABLES module-level cache is a reasonable optimization, though it will reset on process restart — harmless since ensure_columns is idempotent.
dataset_structure_merger.py — record_doc_deletion: ✅ The retry-on-failure behavior (not marking as upgraded until insert succeeds) is the right move. Clean docstring improvements too.
Fix 2: json_contains on Varchar columns (WARNING 3030)
common/doc_store/infinity_conn_base.py: ✅ The column-type-aware routing (json_contains for JSON, filter_fulltext for Varchar) is correct. The edge cases are well handled:
- Numeric values on legacy Varchar: skipped (old encoding couldn't represent them searchably)
- Unknown/missing columns: skipped rather than fabricating a query
- Apostrophe escaping: correct in both paths
The extra show_columns() call was already happening when table_instance was passed — no new RTT overhead.
test/unit_test/common/test_infinity_condition.py: ✅ 29 cases covering the full matrix: JSON/Varchar × all 8 columns × string/numeric × apostrophe × unknown-type × no-table-metadata × other-condition-branches × delete-safety. Excellent.
Fix 3: Meta-table knowledgebase_ids (blank-list WARNING)
rag/utils/infinity_conn.py — get: ✅ Special-casing ragflow_doc_meta_ to query by index name only is consistent with how index_exist/insert/delete already handle meta tables. Moving the empty-list check before connection acquisition is a nice optimization — avoids burning pool connections on a programmer error.
api/db/services/doc_metadata_service.py: ✅ All three call sites now pass [] with clear comments explaining why. The comments reference _get_doc_meta_index_name for discoverability.
Go-side guards: ✅
The unconstrained-filter safety checks in internal/engine/infinity/chunk.go, internal/engine/infinity/metadata.go, and internal/engine/elasticsearch/chunk.go are a good defense-in-depth addition. If a non-empty condition map produces an empty or 1=1 filter, the delete is aborted rather than accidentally truncating a table.
Minor observation (non-blocking):
In dataset_structure_merger.py, the _UPGRADED_TABLES set is module-level and lives only for the process lifetime. After a restart, tables that were already upgraded will be retried. This is harmless (idempotent) but worth noting for future readers. A comment might help, though the existing code is self-documenting enough.
This is ready to merge. Nice work.
Lynn-Inf
left a comment
There was a problem hiding this comment.
Overall this PR reduces doc-meta residual data (the meta-table delete was previously always skipped), but the new delete safety guard introduces a silent residual-data path. Suggestions:
- Don't silently return 0 in the delete guard. When condition is non-empty but equivalent_condition_to_str degrades to 1=1 (e.g. column type unknown / JSON-list column skipped), the delete now returns 0 as if successful. Callers can't distinguish
"0 rows = nothing matched" from "0 rows = predicate skipped". For a delete operation, raising an error is safer than silently no-op-ing. - record_doc_deletion marker write should surface failures. ensure_columns and the outer insert are both swallowed via except Exception: logging.exception(...). If add_columns/insert fails (concurrent DDL, Infinity hiccup), the
deleted_doc_id marker is lost and orphaned dataset-level entity rows won't be cleaned in the next structure merge — leaving permanent ghost entities. The failure should be observable (re-raise or explicit alert), not just logged. - Differentiate skip behavior between query vs delete in equivalent_condition_to_str. Skipping an unknown-type predicate is acceptable for reads, but for deletes it should not be silently dropped — otherwise chunks/metadata can be left behind
without notice. - Add an integration test for the "legacy varchar chunk table + delete by source_doc_ids" scenario asserting deleted_rows > 0 (not aborted), to prevent regressions of silent partial deletes.
…nd marker propagation
|
@Lynn-Inf Thanks for the thorough review and insightful suggestions! All 4 points have been addressed in commit
All 49 Python unit tests and Go package tests for |
|
Please fix lint - lefthook - ruff. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17686 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
all checks passes, please merge, thank you! |
Summary
Fixes #17685.
Follow-up to #17526 ("Refactor: merge dataset scope graph"), which introduced two code paths that touch Infinity columns the deployed schema does not declare. This PR makes the runtime robust against the old schema while also adding the new column to the new schema so freshly created tables are correct.
1) (ERROR 3013) "Column deleted_doc_id not found in table …"
record_doc_deletionwrites adoc_deletedmarker row with adeleted_doc_idcolumn, butconf/infinity_mapping.jsonandrag/utils/ob_conn.py's chunk column list never declared it.•
conf/infinity_mapping.json: adddeleted_doc_idso new tables pick it up.•
rag/utils/ob_conn.py: addcolumn_deleted_doc_idso new OceanBase chunk tables pick it up.•
rag/utils/infinity_conn.py: addensure_columns, a best-effort helper that calls Infinityadd_columnsfor any columns missing on an existing chunk table (idempotent for already-present ones).•
rag/svr/task_executor_refactor/dataset_structure_merger.py:record_doc_deletionnow invokesensure_columnsbeforeinsertso pre-existing chunk tables get the column in place during the first delete after upgrade.2) (WARNING 3030) "json_contains(Varchar, Varchar) not found"
The migrated JSON-list columns (
source_doc_ids,source_chunk_ids, …) emitjson_contains(col, "<json-literal>"). On pre-#17288 chunk tables those columns are still Varchar (whitespace-#analyzer,###-joined encoding) and Infinity rejects the call.•
common/doc_store/infinity_conn_base.py:equivalent_condition_to_strnow reads the actual column type fromtable_instance.show_columns()and falls back tofilter_fulltext(col, <bare value>)when the column is Varchar. New JSON tables keep thejson_containspath. Unknown-type columns are skipped.3) (WARNING) "INFINITY get has only blank knowledgebase_ids for index ragflow_doc_meta_"
DocMetadataService.delete_document_metadatapassed[""]as theknowledgebase_idsfor a per-tenant meta table; the connector then built an emptyf"<index>_<kb>"list and logged a misleading warning. Two other call sites passed[kb_id]for a per-tenant meta table, which under the old code queried a non-existent<index>_<kb>table.•
rag/utils/infinity_conn.py:getnow special-casesragflow_doc_meta_(likeindex_exist/insert/deletealready do): the meta table is queried by index name only. The empty-list check is hoisted above the connection acquisition so the blank-list case no longer burns a connection from the pool.•
api/db/services/doc_metadata_service.py: the three meta-tablegetcall sites now pass[]with a comment explaining why.Test Coverage
test/unit_test/common/test_infinity_condition.py— 29 cases for thejson_contains/filter_fulltextrouting inequivalent_condition_to_str, including Varchar and Json paths for every JSON-list column, apostrophe escaping, numeric handling on Json, and unknown-type skips.test/unit_test/rag/utils/test_infinity_conn_helpers.py— 9 cases forInfinityConnection.get(meta-table routing) andInfinityConnection.ensure_columns(idempotent column upgrade).test/unit_test/rag/svr/task_executor_refactor/test_dataset_structure_merger.py— 3 cases forrecord_doc_deletioninvokingensure_columnsandinsert.test/unit_test/api/db/services/test_doc_metadata_service.py— 2 cases forDocMetadataServicemetadata get/delete passing emptyknowledgebase_idslist.Total: 43 unit tests passing.