hello-stephen commented on code in PR #71358: URL: https://github.com/apache/doris/pull/71358#discussion_r4784290877
########## regression-test/suites/inverted_index_p0/test_multi_inverted_index_clone.groovy: ########## @@ -0,0 +1,185 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import java.util.concurrent.TimeUnit +import org.awaitility.Awaitility + +suite("test_multi_inverted_index_clone", "p0") { + if (isCloudMode()) { + return + } + + def aliveBackends = sql_return_maparray("SHOW BACKENDS").findAll { it.Alive.toString() == "true" } + if (aliveBackends.size() < 2) { + logger.info("Skip test_multi_inverted_index_clone because alive backend num is ${aliveBackends.size()}") + return + } + int replicaNum = Math.min(aliveBackends.size(), 3) + + sql """ DROP TABLE IF EXISTS test_multi_inverted_index_clone """ + sql """ + CREATE INVERTED INDEX CHAR_FILTER IF NOT EXISTS cf_71271_nfkc + PROPERTIES ('type' = 'icu_normalizer', 'name' = 'nfkc_cf') + """ + sql """ + CREATE INVERTED INDEX ANALYZER IF NOT EXISTS analyzer_71271_icu + PROPERTIES ('char_filter' = 'cf_71271_nfkc', 'tokenizer' = 'icu', 'token_filter' = 'lowercase') + """ + sql """ + CREATE INVERTED INDEX TOKENIZER IF NOT EXISTS bigram_tok + PROPERTIES ('type' = 'ngram', 'min_gram' = '2', 'max_gram' = '2', 'token_chars' = 'letter,digit') + """ + sql """ + CREATE INVERTED INDEX ANALYZER IF NOT EXISTS analyzer_71271_bigram + PROPERTIES ('tokenizer' = 'bigram_tok', 'token_filter' = 'lowercase') + """ + + sql """ + CREATE TABLE test_multi_inverted_index_clone ( + k1 BIGINT NOT NULL, + k2 BIGINT NOT NULL, + txt TEXT, + updated_at DATETIME NOT NULL, + INDEX idx_icu (txt) USING INVERTED PROPERTIES("analyzer" = "analyzer_71271_icu", "support_phrase" = "true"), + INDEX idx_bigram (txt) USING INVERTED PROPERTIES("analyzer" = "analyzer_71271_bigram", "support_phrase" = "true") + ) + UNIQUE KEY(k1, k2) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES ( + "replication_num" = "${replicaNum}", + "min_load_replica_num" = "1", + "enable_unique_key_merge_on_write" = "true", + "light_schema_change" = "true", + "inverted_index_storage_format" = "V3", + "function_column.sequence_col" = "updated_at", + "disable_auto_compaction" = "true" + ) + """ + + // Analyzer policies are pushed to BEs via heartbeat; wait until all replicas accept the first load. + Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until { + try { + sql """ + INSERT INTO test_multi_inverted_index_clone + SELECT number % 10, number, concat('営業職を募集 Sales engineer ', number), '2026-01-01 00:00:00' + FROM numbers("number" = "20") + """ + return true + } catch (Exception e) { + logger.info("Waiting for analyzer policy sync to all BEs: ${e.message}") + return false + } + } + sql """ + INSERT INTO test_multi_inverted_index_clone + SELECT number % 10, 20 + number, concat('営業職を募集 Marketing lead ', number), '2026-01-01 00:01:00' + FROM numbers("number" = "20") + """ + + def replicas = sql_return_maparray("SHOW TABLETS FROM test_multi_inverted_index_clone") + .sort { a, b -> (a.ReplicaId as long) <=> (b.ReplicaId as long) } + assertEquals(replicaNum, replicas.size()) + def targetReplica = replicas.last() + String tabletId = targetReplica.TabletId + String targetBeId = targetReplica.BackendId + int targetReplicaIdx = replicas.size() - 1 + long baseVersion = targetReplica.Version as long + + // Mark the target replica bad so subsequent loads skip it on disk, then restore status to ok + // with last_failed_version set so TabletScheduler repairs it via incremental clone. + sql """ + ADMIN SET REPLICA STATUS PROPERTIES( + "tablet_id" = "${tabletId}", + "backend_id" = "${targetBeId}", + "status" = "bad" Review Comment: [P2] Keep the target replica in place while creating the version gap. On the two- and three-BE layouts this test targets, all live BEs hold a replica. If the tablet checker runs during these inserts, `Tablet.getHealth` classifies the BAD replica as `FORCE_REDUNDANT` and the scheduler can delete it immediately. Setting it back to OK can fail, or the test can accept a replacement on the same backend and miss the incremental-clone path. Isolate the failed load or publish from scheduler actions and verify the original `ReplicaId` and the missing rowset versions before repair. ########## regression-test/suites/inverted_index_p0/test_multi_inverted_index_clone.groovy: ########## @@ -0,0 +1,185 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import java.util.concurrent.TimeUnit +import org.awaitility.Awaitility + +suite("test_multi_inverted_index_clone", "p0") { + if (isCloudMode()) { + return + } + + def aliveBackends = sql_return_maparray("SHOW BACKENDS").findAll { it.Alive.toString() == "true" } + if (aliveBackends.size() < 2) { + logger.info("Skip test_multi_inverted_index_clone because alive backend num is ${aliveBackends.size()}") + return + } + int replicaNum = Math.min(aliveBackends.size(), 3) + + sql """ DROP TABLE IF EXISTS test_multi_inverted_index_clone """ + sql """ + CREATE INVERTED INDEX CHAR_FILTER IF NOT EXISTS cf_71271_nfkc + PROPERTIES ('type' = 'icu_normalizer', 'name' = 'nfkc_cf') + """ + sql """ + CREATE INVERTED INDEX ANALYZER IF NOT EXISTS analyzer_71271_icu + PROPERTIES ('char_filter' = 'cf_71271_nfkc', 'tokenizer' = 'icu', 'token_filter' = 'lowercase') + """ + sql """ + CREATE INVERTED INDEX TOKENIZER IF NOT EXISTS bigram_tok + PROPERTIES ('type' = 'ngram', 'min_gram' = '2', 'max_gram' = '2', 'token_chars' = 'letter,digit') + """ + sql """ + CREATE INVERTED INDEX ANALYZER IF NOT EXISTS analyzer_71271_bigram + PROPERTIES ('tokenizer' = 'bigram_tok', 'token_filter' = 'lowercase') + """ + + sql """ + CREATE TABLE test_multi_inverted_index_clone ( + k1 BIGINT NOT NULL, + k2 BIGINT NOT NULL, + txt TEXT, + updated_at DATETIME NOT NULL, + INDEX idx_icu (txt) USING INVERTED PROPERTIES("analyzer" = "analyzer_71271_icu", "support_phrase" = "true"), + INDEX idx_bigram (txt) USING INVERTED PROPERTIES("analyzer" = "analyzer_71271_bigram", "support_phrase" = "true") + ) + UNIQUE KEY(k1, k2) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES ( + "replication_num" = "${replicaNum}", + "min_load_replica_num" = "1", + "enable_unique_key_merge_on_write" = "true", + "light_schema_change" = "true", + "inverted_index_storage_format" = "V3", + "function_column.sequence_col" = "updated_at", + "disable_auto_compaction" = "true" + ) + """ + + // Analyzer policies are pushed to BEs via heartbeat; wait until all replicas accept the first load. + Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until { + try { + sql """ + INSERT INTO test_multi_inverted_index_clone + SELECT number % 10, number, concat('営業職を募集 Sales engineer ', number), '2026-01-01 00:00:00' + FROM numbers("number" = "20") + """ + return true + } catch (Exception e) { + logger.info("Waiting for analyzer policy sync to all BEs: ${e.message}") + return false + } + } + sql """ + INSERT INTO test_multi_inverted_index_clone + SELECT number % 10, 20 + number, concat('営業職を募集 Marketing lead ', number), '2026-01-01 00:01:00' + FROM numbers("number" = "20") + """ + + def replicas = sql_return_maparray("SHOW TABLETS FROM test_multi_inverted_index_clone") + .sort { a, b -> (a.ReplicaId as long) <=> (b.ReplicaId as long) } + assertEquals(replicaNum, replicas.size()) + def targetReplica = replicas.last() + String tabletId = targetReplica.TabletId + String targetBeId = targetReplica.BackendId + int targetReplicaIdx = replicas.size() - 1 + long baseVersion = targetReplica.Version as long + + // Mark the target replica bad so subsequent loads skip it on disk, then restore status to ok + // with last_failed_version set so TabletScheduler repairs it via incremental clone. + sql """ + ADMIN SET REPLICA STATUS PROPERTIES( + "tablet_id" = "${tabletId}", + "backend_id" = "${targetBeId}", + "status" = "bad" + ) + """ + + sql """ + INSERT INTO test_multi_inverted_index_clone + SELECT number % 10, 40 + number, concat('営業職を募集 Sales engineer ', 40 + number), '2026-01-01 00:02:00' + FROM numbers("number" = "20") + """ + sql """ + INSERT INTO test_multi_inverted_index_clone + SELECT number % 10, 60 + number, concat('開発職を募集 Backend developer ', 60 + number), '2026-01-01 00:03:00' + FROM numbers("number" = "20") + """ + + long expectedVersion = baseVersion + 2 + sql """ + ADMIN SET REPLICA STATUS PROPERTIES( + "tablet_id" = "${tabletId}", + "backend_id" = "${targetBeId}", + "status" = "ok" + ) + """ + sql """ + ADMIN SET REPLICA VERSION PROPERTIES( + "tablet_id" = "${tabletId}", + "backend_id" = "${targetBeId}", + "version" = "${baseVersion}", + "last_failed_version" = "${expectedVersion}" + ) + """ + sql """ ADMIN REPAIR TABLE test_multi_inverted_index_clone """ + + Awaitility.await().atMost(60, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until { + def curReplicas = sql_return_maparray("SHOW TABLETS FROM test_multi_inverted_index_clone") + curReplicas.size() == replicaNum && curReplicas.every { + (it.Version as long) == expectedVersion && it.LstFailedVersion.toString() == "-1" + } + } + + def repairedReplica = sql_return_maparray("SHOW TABLETS FROM test_multi_inverted_index_clone") + .find { it.BackendId.toString() == targetBeId } + assertNotNull(repairedReplica) + def (code, out, err) = curl("GET", repairedReplica.MetaUrl) + assertEquals(0, code) + def jsonMeta = parseJson(out.trim()) + def topIndexIds = jsonMeta.schema.index.collect { it.index_id as long } as Set + assertEquals(2, topIndexIds.size()) + for (def rsMeta : jsonMeta.rs_metas) { + if (rsMeta.tablet_schema?.index != null && rsMeta.tablet_schema.index.size() > 0) { + def rsIndexIds = rsMeta.tablet_schema.index.collect { it.index_id as long } as Set + assertEquals(topIndexIds, rsIndexIds) + } + } + + sql """ SET use_fix_replica = ${targetReplicaIdx} """ + order_qt_icu """ + SELECT k1, k2 FROM test_multi_inverted_index_clone + WHERE txt MATCH_PHRASE '営業職' USING ANALYZER analyzer_71271_icu + ORDER BY k1, k2 LIMIT 10 + """ + order_qt_bigram """ + SELECT k1, k2 FROM test_multi_inverted_index_clone + WHERE txt MATCH_PHRASE 'Sales' USING ANALYZER analyzer_71271_bigram + ORDER BY k1, k2 LIMIT 10 + """ + + trigger_and_wait_compaction("test_multi_inverted_index_clone", "cumulative") Review Comment: [P3] Assert the repaired replica actually compacted. Four tiny single-segment loads can fall below the default cumulative compaction thresholds of five deltas and 64 MiB. `trigger_and_wait_compaction` accepts the no-suitable-version result, so the two checks below can pass on the original rowsets. Supply enough eligible rowsets and assert that the repaired replica has a new merged version range covering the cloned versions. ########## be/src/storage/snapshot/snapshot_manager.cpp: ########## @@ -250,11 +243,6 @@ Result<std::vector<PendingRowsetGuard>> SnapshotManager::convert_rowset_ids( rowset_meta->set_partition_id(partition_id); } - if (rowset_meta->has_tablet_schema() && rowset_meta->tablet_schema().index_size() > 0) { - RETURN_IF_ERROR_RESULT( - _rename_index_ids(*rowset_meta->mutable_tablet_schema(), target_tablet_schema)); Review Comment: [P2] Keep partition-scoped DROP INDEX working after restore into an existing table. `OlapTable.getSignature` accepts a logically identical index with a different ID. After restoring a missing partition, the copied rowsets now keep source ID A while the destination catalog still has ID B. `DROP INDEX ... PARTITION` sends B, so `Tablet::pick_candidate_rowsets_to_build_inverted_index` skips the restored rowsets and the job reports success without dropping the index. The old conversion selected the rowsets for a single V2 index, and last-index removal could discard the compound file. Preserve a mapping the drop can use, or reject this restore before installing the partition. ########## be/src/cloud/cloud_snapshot_mgr.cpp: ########## @@ -158,19 +155,10 @@ Status CloudSnapshotMgr::convert_rowsets( RETURN_IF_ERROR(_create_rowset_meta(new_rowset_meta_pb, rowset_meta_pb, tablet_id, target_tablet, storage_resource, tablet_schema, file_mapping, rowset_id_mapping)); - if (new_rowset_meta_pb->has_tablet_schema() && - new_rowset_meta_pb->tablet_schema().index_size() > 0) { - RETURN_IF_ERROR(_rename_index_ids(*new_rowset_meta_pb->mutable_tablet_schema(), Review Comment: [P2] Handle different secondary IDs before Cloud restore commits the schema. Restore a missing partition into a same-schema Cloud table whose index has a different allocated ID. `OlapTable.getSignature` allows that, and `CloudRestoreJob.createReplicas` writes the destination schema. When the versions match, `commit_restore_job` writes the source schema under the same destination key. `put_schema_kv` DCHECKs on the ID difference in debug and ASAN builds. This regresses even a single `NGRAM_BF` index, whose bloom data lives in the segment. In release, the old schema wins, so a restored inverted index can resolve an ID absent from the copied file. Reconcile the schemas and physical IDs before this commit or reject the incompatible restore. -- 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]
