airborne12 commented on code in PR #70352:
URL: https://github.com/apache/doris/pull/70352#discussion_r4698160620
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -2179,37 +2201,65 @@ public int getAsInt() {
buildIndexChange = true;
lightSchemaChange = false;
} else if (alterClause instanceof DropIndexClause) {
- if (processDropIndex((DropIndexClause) alterClause,
olapTable, newIndexes)) {
- return;
- }
- lightSchemaChange = false;
-
DropIndexClause dropIndexClause = (DropIndexClause)
alterClause;
- List<Index> existedIndexes = olapTable.getIndexes();
- Index found = null;
- for (Index existedIdx : existedIndexes) {
- if
(existedIdx.getIndexName().equalsIgnoreCase(dropIndexClause.getIndexName())) {
- found = existedIdx;
- break;
+
+ if (dropIndexClause.hasPartitionSpec()) {
+ // Delete the physical index files and keep the
table-level index definition.
+ List<Index> existedIndexes = olapTable.getIndexes();
+ Index found = null;
+ for (Index existedIdx : existedIndexes) {
+ if
(existedIdx.getIndexName().equalsIgnoreCase(dropIndexClause.getIndexName())) {
+ found = existedIdx;
+ break;
+ }
}
- }
- // for inverted index, light schema change is supported in
both cloud and local mode;
- // for ngram index, light schema change is supported only
in cloud mode;
- boolean supportLightIndexChange = false;
- if (Config.isCloudMode()) {
- if (enableAddIndexForNewData) {
- supportLightIndexChange = (
- found.getIndexType() == IndexType.NGRAM_BF
- || found.getIndexType() ==
IndexDef.IndexType.INVERTED);
+ if (found == null) {
+ if (dropIndexClause.isSetIfExists()) {
+ LOG.info("drop index[{}] which does not exist
on table[{}]",
+ dropIndexClause.getIndexName(),
olapTable.getName());
+ return;
+ }
+ throw new DdlException("index " +
dropIndexClause.getIndexName() + " does not exist");
}
- } else {
- supportLightIndexChange = found.getIndexType() ==
IndexDef.IndexType.INVERTED
- || found.getIndexType() ==
IndexDef.IndexType.ANN;
- }
- if (found != null && supportLightIndexChange) {
+ if (found.getIndexType() != IndexType.INVERTED) {
+ throw new DdlException(
+ "Only inverted index supports DROP INDEX
ON PARTITION");
+ }
+ if (!olapTable.isPartitionedTable()) {
+ throw new DdlException("table " +
olapTable.getName()
+ + " is not partitioned, cannot drop index
with partitions");
+ }
+ Set<String> specifiedPartitions = new
HashSet<>(dropIndexClause.getPartitionNames());
+ for (String partName : specifiedPartitions) {
+ if (olapTable.getPartition(partName) == null) {
+ throw new DdlException("partition " + partName
+ " does not exist");
+ }
+ }
+
alterIndexes.add(found);
+ indexOnPartitions.put(found.getIndexId(),
specifiedPartitions);
Review Comment:
Confirmed. A BE unit test that sends the request FE builds for a partition
drop (`is_drop_op=true`, the unchanged schema version, the full index list)
showed `EngineCloudIndexChangeTask` returning OK without starting a rewrite,
and on a cloud cluster the job reached FINISHED while queries on the partition
still used the index. A real cloud drop would need a rowset schema that differs
from the table schema at the same schema version, which the meta-service schema
store does not allow, so the statement is now rejected: 2eeb49f6cc0 picks
#71041, which makes `DropIndexOp.validate` fail `DROP INDEX ... ON PARTITION`
and `ALTER TABLE ... DROP INDEX ... PARTITION` in cloud mode.
`IndexChangeJobTest#testDropIndexOnPartitionRejectedInCloudMode` fails without
the check and passes with it, and the cloud branch of
`test_drop_index_on_partition` asserts the error.
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -2179,37 +2201,65 @@ public int getAsInt() {
buildIndexChange = true;
lightSchemaChange = false;
} else if (alterClause instanceof DropIndexClause) {
- if (processDropIndex((DropIndexClause) alterClause,
olapTable, newIndexes)) {
- return;
- }
- lightSchemaChange = false;
-
DropIndexClause dropIndexClause = (DropIndexClause)
alterClause;
- List<Index> existedIndexes = olapTable.getIndexes();
- Index found = null;
- for (Index existedIdx : existedIndexes) {
- if
(existedIdx.getIndexName().equalsIgnoreCase(dropIndexClause.getIndexName())) {
- found = existedIdx;
- break;
+
+ if (dropIndexClause.hasPartitionSpec()) {
+ // Delete the physical index files and keep the
table-level index definition.
+ List<Index> existedIndexes = olapTable.getIndexes();
+ Index found = null;
+ for (Index existedIdx : existedIndexes) {
+ if
(existedIdx.getIndexName().equalsIgnoreCase(dropIndexClause.getIndexName())) {
+ found = existedIdx;
+ break;
+ }
}
- }
- // for inverted index, light schema change is supported in
both cloud and local mode;
- // for ngram index, light schema change is supported only
in cloud mode;
- boolean supportLightIndexChange = false;
- if (Config.isCloudMode()) {
- if (enableAddIndexForNewData) {
- supportLightIndexChange = (
- found.getIndexType() == IndexType.NGRAM_BF
- || found.getIndexType() ==
IndexDef.IndexType.INVERTED);
+ if (found == null) {
+ if (dropIndexClause.isSetIfExists()) {
+ LOG.info("drop index[{}] which does not exist
on table[{}]",
+ dropIndexClause.getIndexName(),
olapTable.getName());
+ return;
+ }
+ throw new DdlException("index " +
dropIndexClause.getIndexName() + " does not exist");
}
- } else {
- supportLightIndexChange = found.getIndexType() ==
IndexDef.IndexType.INVERTED
- || found.getIndexType() ==
IndexDef.IndexType.ANN;
- }
- if (found != null && supportLightIndexChange) {
+ if (found.getIndexType() != IndexType.INVERTED) {
+ throw new DdlException(
+ "Only inverted index supports DROP INDEX
ON PARTITION");
+ }
+ if (!olapTable.isPartitionedTable()) {
+ throw new DdlException("table " +
olapTable.getName()
+ + " is not partitioned, cannot drop index
with partitions");
+ }
+ Set<String> specifiedPartitions = new
HashSet<>(dropIndexClause.getPartitionNames());
+ for (String partName : specifiedPartitions) {
+ if (olapTable.getPartition(partName) == null) {
+ throw new DdlException("partition " + partName
+ " does not exist");
+ }
+ }
+
alterIndexes.add(found);
+ indexOnPartitions.put(found.getIndexId(),
specifiedPartitions);
isDropIndex = true;
- lightIndexChange = true;
+ buildIndexChange = true;
Review Comment:
Fixed in b09ac4cb955: with `enable_light_index_change=false` the partition
branch now throws `DROP INDEX ON PARTITION requires
enable_light_index_change=true` before any job is created.
`SchemaChangeHandlerTest#testPartitionDropRequiresLightIndexChanges` covers it.
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -3438,25 +3492,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()) {
Review Comment:
Fixed in b09ac4cb955: the partition branch calls
`checkNoIndexChangeJobOnPartitions` for the whole selected partition set while
it validates the clause, so a conflict on any listed partition fails the
statement before any job is registered or logged.
`SchemaChangeHandlerTest#testPartitionDropChecksAllConflictsBeforePublishingJobs`
covers it.
##########
regression-test/suites/inverted_index_p0/index_change/test_drop_index_on_partition.groovy:
##########
@@ -0,0 +1,278 @@
+// 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.
+
+
+suite("test_drop_index_on_partition", "inverted_index") {
+ def timeout = 300000
+ def delta_time = 1000
+
+ def get_build_index_job_count = { table_name ->
+ def res = sql """SHOW BUILD INDEX WHERE TableName = "${table_name}";"""
+ return res.size()
+ }
+
+ def wait_for_build_index_on_partition_finish = { table_name,
expected_job_count, OpTimeout ->
+ def useTime = 0
+ for (int t = delta_time; t <= OpTimeout; t += delta_time) {
+ def alter_res = sql """SHOW BUILD INDEX WHERE TableName =
"${table_name}";"""
+ if (alter_res.size() < expected_job_count) {
+ useTime = t
+ sleep(delta_time)
+ continue
+ }
+ def finished_num = 0
+ for (int i = 0; i < alter_res.size(); i++) {
+ logger.info(table_name + " build index job state: " +
alter_res[i][7] + " idx: " + i)
+ if (alter_res[i][7] == "FINISHED") {
+ ++finished_num
+ }
+ }
+ if (finished_num == alter_res.size()) {
+ logger.info(table_name + " all build index jobs finished,
detail: " + alter_res)
+ break
+ }
+ useTime = t
+ sleep(delta_time)
+ }
+ assertTrue(useTime <= OpTimeout,
"wait_for_build_index_on_partition_finish timeout")
Review Comment:
Fixed in b09ac4cb955: the helper now asserts that jobs were created, fails
as soon as any job is CANCELLED, and asserts after the loop that every job
reached FINISHED, so a cancelled or stuck DROP job fails the suite instead of
passing after the timeout.
--
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]