Skip to content

vector: Fix building vector index on DeltaVS may lead to delta compact failure#10311

Merged
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
JaySon-Huang:vec_delta_compact_fail
Aug 18, 2025
Merged

vector: Fix building vector index on DeltaVS may lead to delta compact failure#10311
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
JaySon-Huang:vec_delta_compact_fail

Conversation

@JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Jul 14, 2025

What problem does this PR solve?

Issue Number: close #10310, ref #9600

Problem Summary: Introduced by #9546 in the vector update workload

In DeltaMergeStore::segmentEnsureDeltaLocalIndex, the function will update the persisted ColumnFiles in DeltaVS.

// Update the column files in the delta with the new column files.
for (auto & column_file : delta_persisted_column_files)
{
const auto * tiny_file = column_file->tryToTinyFile();
if (!tiny_file)
continue;
if (auto iter = new_column_files_map.find(tiny_file->getDataPageId()); iter != new_column_files_map.end())
column_file = iter->second;
}
delta_persisted_file_set->updatePersistedColumnFilesAfterAddingIndex(delta_persisted_column_files, wbs);

In ColumnFilePersistedSet::installCompactionResults it will check whether the persisted ColumnFiles are changed during the minor compaction. If the persisted ColumnFiles not matched, it will throw an exception as the issue describe.
auto old_persisted_files_iter = persisted_files.begin();
for (const auto & task : compaction->getTasks())
{
for (const auto & file : task.to_compact)
{
if (unlikely(
old_persisted_files_iter == persisted_files.end()
|| (file->getId() != (*old_persisted_files_iter)->getId())
|| (file->getRows() != (*old_persisted_files_iter)->getRows())))
{
throw Exception(
ErrorCodes::LOGICAL_ERROR,
"Compaction algorithm broken, "
"compaction={{{}}} persisted_files={} "
"old_persisted_files_iter.is_end={} "
"file->getId={} old_persist_files->getId={} file->getRows={} old_persist_files->getRows={}",
compaction->info(),
detailInfo(),
old_persisted_files_iter == persisted_files.end(),
file->getId(),
old_persisted_files_iter == persisted_files.end() ? -1 : (*old_persisted_files_iter)->getId(),
file->getRows(),
old_persisted_files_iter == persisted_files.end() ? -1 : (*old_persisted_files_iter)->getRows());
}
old_persisted_files_iter++;
}
}

So the issue is cause by local index on the DeltaVS changed the persisted ColumnFiles between Minor Compaction.

What is changed and how it works?

* In `DeltaMergeStore::segmentEnsureDeltaLocalIndexAsync` and `DeltaMergeStore::segmentWaitDeltaLocalIndexReady` if we detect that `segment->getDelta()->isUpdating()`, it means the segment is running an update task (SegmentMergeDelta/SegmentMerge/SegmentSplit), just skip the local index build job
* `ColumnFilePersistedSet::installCompactionResults` if we detect the column file set is changed during minor compaction, then log an error and rollback the minor compaction
* `WriteBatches::rollbackWrittenLogAndData` will also remove the pending `removed_log` and `removed_data`

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Signed-off-by: JaySon-Huang <tshent@qq.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 14, 2025
Signed-off-by: JaySon-Huang <tshent@qq.com>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/needs-triage-completed labels Jul 14, 2025
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang JaySon-Huang force-pushed the vec_delta_compact_fail branch from e1b6111 to 13f464b Compare July 15, 2025 05:32
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang JaySon-Huang changed the title [WIP] Add test case for delta compact failure vector: Add test case for delta compact failure Jul 15, 2025
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2025
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang JaySon-Huang changed the title vector: Add test case for delta compact failure vector: Fix building vector index on DeltaVS may lead to delta compact failure Aug 16, 2025
@JaySon-Huang JaySon-Huang requested a review from CalvinNeo August 16, 2025 14:52
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Aug 18, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Aug 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JinheLin, Lloyd-Pottiger

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JinheLin,Lloyd-Pottiger]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 18, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Aug 18, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-08-18 02:24:05.722709873 +0000 UTC m=+233853.665885379: ☑️ agreed by Lloyd-Pottiger.
  • 2025-08-18 13:40:47.527121486 +0000 UTC m=+274455.470297012: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit 76a4ec4 into pingcap:master Aug 18, 2025
7 checks passed
@JaySon-Huang JaySon-Huang deleted the vec_delta_compact_fail branch August 18, 2025 14:44
@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Aug 20, 2025
ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Aug 20, 2025
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #10353.
But this PR has conflicts, please resolve them!

ti-chi-bot bot pushed a commit that referenced this pull request Sep 1, 2025
…t failure (#10311) (#10353)

ref #9600, close #10310

* In `DeltaMergeStore::segmentEnsureDeltaLocalIndexAsync` and `DeltaMergeStore::segmentWaitDeltaLocalIndexReady` if we detect that `segment->getDelta()->isUpdating()`, it means the segment is running an update task (SegmentMergeDelta/SegmentMerge/SegmentSplit), just skip the local index build job
* `ColumnFilePersistedSet::installCompactionResults` if we detect the column file set is changed during minor compaction, then log an error and rollback the minor compaction
* `WriteBatches::rollbackWrittenLogAndData` will also remove the pending `removed_log` and `removed_data`

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: JaySon-Huang <tshent@qq.com>

Co-authored-by: JaySon <tshent@qq.com>
Co-authored-by: JaySon-Huang <tshent@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Compaction algorithm broken" is reported when running vector search workload

4 participants