This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 89441b0cb0e27e332e7a806838c0fdac47f1de26 Author: yujun <[email protected]> AuthorDate: Sat Apr 20 23:02:54 2024 +0800 [fix](tablet invert index) fix tablet invert index leaky caused by auto partition (#33714) --- .../apache/doris/datasource/InternalCatalog.java | 18 +++---- .../apache/doris/alter/AddExistsPartitionTest.java | 56 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index ea33e30f861..16187bdc517 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -1416,7 +1416,9 @@ public class InternalCatalog implements CatalogIf<Database> { if (olapTable.checkPartitionNameExist(partitionName)) { if (singlePartitionDesc.isSetIfNotExists()) { LOG.info("add partition[{}] which already exists", partitionName); - return; + if (!DebugPointUtil.isEnable("InternalCatalog.addPartition.noCheckExists")) { + return; + } } else { ErrorReport.reportDdlException(ErrorCode.ERR_SAME_NAME_PARTITION, partitionName); } @@ -1573,6 +1575,7 @@ public class InternalCatalog implements CatalogIf<Database> { if (!Strings.isNullOrEmpty(dataProperty.getStoragePolicy())) { storagePolicy = dataProperty.getStoragePolicy(); } + boolean ignoreException = false; try { long partitionId = idGeneratorBuffer.getNextId(); Partition partition = createPartitionWithIndices(db.getId(), olapTable, @@ -1593,11 +1596,10 @@ public class InternalCatalog implements CatalogIf<Database> { // check partition name if (olapTable.checkPartitionNameExist(partitionName)) { if (singlePartitionDesc.isSetIfNotExists()) { - LOG.info("add partition[{}] which already exists", partitionName); - return; - } else { - ErrorReport.reportDdlException(ErrorCode.ERR_SAME_NAME_PARTITION, partitionName); + ignoreException = true; } + LOG.info("add partition[{}] which already exists", partitionName); + ErrorReport.reportDdlException(ErrorCode.ERR_SAME_NAME_PARTITION, partitionName); } // check if meta changed @@ -1642,8 +1644,6 @@ public class InternalCatalog implements CatalogIf<Database> { } } - - if (metaChanged) { throw new DdlException("Table[" + tableName + "]'s meta has been changed. try again."); } @@ -1688,7 +1688,9 @@ public class InternalCatalog implements CatalogIf<Database> { for (Long tabletId : tabletIdSet) { Env.getCurrentInvertedIndex().deleteTablet(tabletId); } - throw e; + if (!ignoreException) { + throw e; + } } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java b/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java new file mode 100644 index 00000000000..0d95ee30cde --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java @@ -0,0 +1,56 @@ +// 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. + +package org.apache.doris.alter; + +import org.apache.doris.catalog.Env; +import org.apache.doris.common.Config; +import org.apache.doris.common.util.DebugPointUtil; +import org.apache.doris.common.util.DebugPointUtil.DebugPoint; +import org.apache.doris.utframe.TestWithFeService; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +public class AddExistsPartitionTest extends TestWithFeService { + + @Override + protected void beforeCreatingConnectContext() throws Exception { + Config.enable_debug_points = true; + } + + @Test + public void testAddExistsPartition() throws Exception { + DebugPointUtil.addDebugPoint("InternalCatalog.addPartition.noCheckExists", new DebugPoint()); + createDatabase("test"); + createTable("CREATE TABLE test.tbl (k INT) DISTRIBUTED BY HASH(k) " + + " BUCKETS 5 PROPERTIES ( \"replication_num\" = \"" + backendNum() + "\" )"); + List<Long> backendIds = Env.getCurrentSystemInfo().getAllBackendIds(); + for (long backendId : backendIds) { + Assertions.assertEquals(5, Env.getCurrentInvertedIndex().getTabletIdsByBackendId(backendId).size()); + } + + String addPartitionSql = "ALTER TABLE test.tbl ADD PARTITION IF NOT EXISTS tbl" + + " DISTRIBUTED BY HASH(k) BUCKETS 5"; + Assertions.assertNotNull(getSqlStmtExecutor(addPartitionSql)); + for (long backendId : backendIds) { + Assertions.assertEquals(5, Env.getCurrentInvertedIndex().getTabletIdsByBackendId(backendId).size()); + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
