airborne12 commented on code in PR #70352:
URL: https://github.com/apache/doris/pull/70352#discussion_r4702626916
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -3440,25 +3501,86 @@ public void buildOrDeleteTableInvertedIndices(Database
db, OlapTable olapTable,
}
}
+ // Inverted index supports light schema change in both cloud and local
mode.
+ // NGRAM_BF supports it only in cloud mode.
+ private static boolean isLightDropIndexSupported(Index index, boolean
enableAddIndexForNewData) {
+ if (Config.isCloudMode()) {
+ return enableAddIndexForNewData
+ && (index.getIndexType() == IndexType.NGRAM_BF
+ || index.getIndexType() == IndexType.INVERTED);
+ }
+ return index.getIndexType() == IndexType.INVERTED ||
index.getIndexType() == IndexType.ANN;
+ }
+
+ // Reject conflicting jobs and mixed add/drop operations before publishing
index metadata.
+ private void checkLightDropIndexPreconditions(Database db, OlapTable
olapTable, List<AlterClause> alterClauses,
+ boolean enableAddIndexForNewData) throws UserException {
+ if (!Config.enable_light_index_change) {
+ return;
+ }
+ List<Index> droppedIndexes = new ArrayList<>();
+ for (AlterClause alterClause : alterClauses) {
+ if (!(alterClause instanceof DropIndexClause)
+ || ((DropIndexClause) alterClause).hasPartitionSpec()) {
+ continue;
+ }
+ String indexName = ((DropIndexClause) alterClause).getIndexName();
+ olapTable.getIndexes().stream()
+ .filter(index ->
index.getIndexName().equalsIgnoreCase(indexName))
+ .filter(index -> isLightDropIndexSupported(index,
enableAddIndexForNewData))
+ .findFirst()
+ .ifPresent(droppedIndexes::add);
+ }
+ if (droppedIndexes.isEmpty()) {
+ return;
+ }
+ if (alterClauses.stream().anyMatch(alterClause -> alterClause
instanceof CreateIndexClause
+ && ((CreateIndexClause)
alterClause).getIndex().isLightAddIndexSupported(enableAddIndexForNewData))) {
+ throw new DdlException("Can not add and drop indexes in one ALTER
statement,"
+ + " please run them in separate statements.");
+ }
+ getCloudClusterName();
+ checkNoIndexChangeJobOnPartitions(db, olapTable, droppedIndexes,
olapTable.getPartitionNames());
+ }
+
+ // Throws if any of the partitions still has an unfinished index change
job on the base index.
+ private void checkNoIndexChangeJobOnPartitions(Database db, OlapTable
olapTable, List<Index> alterIndexes,
+ Set<String> partitionNames) throws DdlException {
+ // Scan the retained job history once instead of once per partition,
the table write lock is held here.
+ for (IndexChangeJob indexChangeJob :
ImmutableList.copyOf(indexChangeJobs.values())) {
+ // Cheap partition check first, the predicate compares index lists.
+ if (partitionNames.contains(indexChangeJob.getPartitionName())
Review Comment:
Confirmed and fixed. Both checks compared the partition name captured when
the job was created, and `RENAME PARTITION` only requires the table to be
NORMAL, so a renamed partition escaped the conflict check. c663db50d57 picks
#71043, which matches jobs by partition ID in `hasIndexChangeJobOnPartition`
and `checkNoIndexChangeJobOnPartitions`, including this branch's partition DROP
pre-check.
`SchemaChangeHandlerTest#testIndexChangeConflictFollowsRenamedPartition`
registers an unfinished BUILD on p1, renames p1 to p1_renamed, and checks that
both `DROP INDEX idx_v1 PARTITION (p1_renamed)` and `DROP INDEX idx_v1` are
rejected; it fails on master without the fix and passes with it.
--
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]