airborne12 opened a new pull request, #71334:
URL: https://github.com/apache/doris/pull/71334
### Background
Each secondary index has an id that FE assigns per table and that all
replicas of a tablet share. A rowset carries the schema it was written with,
and its index data is stored under these ids: in the file name for V1 inverted
indexes, and as the directory key inside the index file for V2 and later. Clone
and storage migration copy the rowset files of the same tablet. Then
`SnapshotManager::convert_rowset_ids` rewrites the copied metadata. Restore
uses the same function for a snapshot of another table.
### What problem does this PR solve?
Issue Number: close #71271
Related PR: #57074 (introduced the bug), #58660 (same change on branch-4.0),
#70585 (alternative fix, open)
PR Type: Bugfix
Problem Summary:
Since #57074, `convert_rowset_ids` replaces the index ids in every copied
rowset schema with those of the local tablet schema, matched by (column, index
type, suffix). Two inverted indexes on one column share that key, so after a
clone into an existing tablet, or a disk migration, both get the same id.
Queries and compaction on that replica then fail, and the replica does not
recover by itself. Clone and migration now keep the ids. Restore is unchanged.
```sql
CREATE TABLE t (k INT, txt STRING,
INDEX idx_std (txt) USING INVERTED PROPERTIES("analyzer" = "std"),
INDEX idx_kw (txt) USING INVERTED PROPERTIES("analyzer" = "kw"))
DUPLICATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1;
-- one replica misses some loads, then FE repairs it by incremental clone
SET use_fix_replica = <the cloned replica>;
SELECT k FROM t WHERE txt MATCH 'alice' USING ANALYZER std ORDER BY k;
-- before: [E-6001]Duplicate inverted index id 1796272036896 in one field
-- after: 1, 2, 4 (same as the other replicas)
```
### Details
- **Change map:** production code +18 -15 (a flag and its three call sites);
tests +234 -5 (BE unit tests and a docker regression suite); generated `.out`
+55.
- **Frequency:** Always, when a column has several indexes of the same type
and suffix (for example, inverted indexes with different analyzers) and a
replica gets an incremental clone, a full clone into an existing tablet, or a
disk migration. Reported in #71271 on 4.1.5.
- **Root cause:** `_rename_index_ids` in `convert_rowset_ids` picks the
target index with `TabletSchema::get_index(column, type, suffix)`, which
returns the first match. Two indexes on one column get one id, while their
files keep two ids.
- **Why existing tests missed it:**
`SnapshotManagerTest.TestConvertRowsetIdsNormal` covers only restore with one
bitmap index. In regression, `clone_p0/test_clone_missing_version` has no
indexes, and the multi-analyzer suites in `inverted_index_p0` use one replica
and never clone.
- **Fix:** `convert_rowset_ids` takes `refresh_index_ids`. Restore passes
true. Clone and migration pass false and do not read the local schema, as
before #57074. Only the caller knows whether the snapshot comes from the same
tablet. A better matching key would still fail for clone when the local schema
lags behind the source, for example after an ADD INDEX that the replica has not
loaded yet.
- **Other paths and branches:**
- Local restore and cloud restore (`CloudSnapshotMgr`) still match by
(column, type, suffix). That is the restore remapping problem, tracked in
#70583, and this PR does not change it. Cloud has no BE clone or disk migration.
- CCR: full sync uses restore. Incremental binlog ingestion does not call
`convert_rowset_ids`.
- Branches: branch-4.0 from 4.0.2 on (#58660), branch-4.1 and branch-4.2
have the bug. branch-3.1 does not rewrite index ids on clone.
### Testing
- BE UT `SnapshotManagerTest.CloneKeepsIdsOfInvertedIndexesOnOneColumn`
(new): clones a snapshot with two inverted indexes on one column into a local
tablet that has both indexes, and into one that has only the first. Before the
fix, `idx_bigram` 3002 becomes 3001 in the tablet schema and in the visible and
stale rowset schemas. With the fix, all six `SnapshotManagerTest` cases pass
(local, ASAN).
- Docker regression `clone_p0/test_clone_multi_analyzer_index_ids` (new, 3
BE): one BE misses two loads and is repaired by incremental clone. Then each
replica is queried with both analyzers, before and after compaction. On master
(7dd131e514c), the cloned replica fails with `Duplicate inverted index id`.
With the fix, the suite passes (local). PR pipelines skip docker suites, so the
UT is the CI guard.
### Notes for Reviewers
- #70585 also changes this code, but:
- It treats a snapshot as a clone when its tablet_id equals the local one.
A restore into an existing partition of the same table also has equal tablet
ids.
- It makes restore match by full index definition. In the #57074 log,
`idx_ngrambf` has `lower_case` only in the backup schema. With that rule, the
index would not match, and the cloud meta-service schema check that #57074
fixed would fail again.
- Replicas already broken are not repaired here. `ADMIN SET REPLICA STATUS
... "status" = "drop"` rebuilds them. The steps are in #71271.
### Release note
Fix replica clone and disk migration giving several inverted indexes on one
column the same index id, which made queries and compaction on that replica
fail with "Duplicate inverted index id ... in one field".
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: analysis, code, tests, this description
- Human review: not stated
- Prompts: Analyze #71271 and check whether master already fixes it;
re-derive the root cause from first principles; treat the restore/CCR index id
remapping as a separate problem; fix the clone case first, checking side
effects on cloud mode and other paths; then reply to the issue.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]