github-actions[bot] commented on code in PR #65476:
URL: https://github.com/apache/doris/pull/65476#discussion_r3561778451
##########
fe/fe-core/src/main/java/org/apache/doris/dictionary/DictionaryManager.java:
##########
@@ -464,8 +491,7 @@ public void dataLoad(ConnectContext ctx, Dictionary
dictionary, boolean adaptive
lockRead();
boolean unlocked = false;
try {
- if (!dictionaryIds.containsKey(dictionary.getDbName())
- ||
!dictionaryIds.get(dictionary.getDbName()).containsKey(dictionary.getName())) {
+ if (!isCurrentDictionaryWithoutLock(dictionary)) {
Review Comment:
This identity check is still too early for the failure path below. After
this block releases the dictionary-manager read lock, a concurrent `DROP
DICTIONARY`/`DROP DATABASE` can remove this same dictionary and log
`OP_DROP_DICTIONARY`; if `commitNowVersion()` then returns false, lines 527-528
still call `logDictionaryDecVersion(dictionary)` for an object that is no
longer current. On replay the drop removes the dictionary, and
`replayDecreaseVersion()` calls `getDictionary(dbName, dictName)`, so the later
decrement entry cannot be applied. Please recheck/hold the dictionary identity
before logging the decrement, and skip the rollback journal entry once the
dictionary has already been dropped.
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertTargetDropRaceTest.java:
##########
@@ -0,0 +1,182 @@
+// 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.nereids.trees.plans.commands.insert;
+
+import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.util.DebugPointUtil;
+import org.apache.doris.dictionary.Dictionary;
+import org.apache.doris.dictionary.Dictionary.DictionaryStatus;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.OriginStatement;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BooleanSupplier;
+
+class InsertTargetDropRaceTest extends TestWithFeService {
+ private static final String DICTIONARY_BLOCK_POINT =
"DictionaryManager.dataLoad.blockBeforePlan";
+ private boolean debugPointsEnabled;
+
+ @BeforeEach
+ void saveDebugPointConfig() {
+ debugPointsEnabled = Config.enable_debug_points;
+ }
+
+ @AfterEach
+ void clearDebugPoints() {
+ DebugPointUtil.clearDebugPoints();
+ Config.enable_debug_points = debugPointsEnabled;
+ }
+
+ @Test
+ void
normalInsertReturnsAnalysisErrorWhenDatabaseIsDroppedAfterTargetResolution()
throws Exception {
+ String dbName = "normal_insert_drop_race";
+ createDatabaseAndUse(dbName);
+ createTable("CREATE TABLE target_table (id INT) DISTRIBUTED BY
HASH(id) BUCKETS 1 "
+ + "PROPERTIES ('replication_num' = '1')");
+
+ String sql = "INSERT INTO " + dbName + ".target_table VALUES (1)";
+ InsertIntoTableCommand baseCommand = (InsertIntoTableCommand) new
NereidsParser().parseSingle(sql);
+ CountDownLatch targetResolved = new CountDownLatch(1);
+ CountDownLatch resumeInsert = new CountDownLatch(1);
+ AtomicBoolean blockOnce = new AtomicBoolean(true);
+ InsertIntoTableCommand command = new
InsertIntoTableCommand(baseCommand,
+ PlanType.INSERT_INTO_TABLE_COMMAND) {
+ @Override
+ protected InsertTarget getTarget(ConnectContext ctx, List<String>
qualifiedTargetTableName) {
+ InsertTarget target = super.getTarget(ctx,
qualifiedTargetTableName);
+ if (blockOnce.compareAndSet(true, false)) {
+ targetResolved.countDown();
+ await(resumeInsert);
+ }
+ return target;
+ }
+ };
+
+ ExecutorService executorService = Executors.newSingleThreadExecutor();
+ try {
+ Future<Throwable> result = executorService.submit(() ->
runInitPlan(command, sql, dbName));
+ Assertions.assertTrue(targetResolved.await(10, TimeUnit.SECONDS));
+ Env.getCurrentInternalCatalog().dropDb(dbName, false, true);
+ resumeInsert.countDown();
+
+ Throwable failure = result.get(10, TimeUnit.SECONDS);
+ Assertions.assertNotNull(failure);
+ Assertions.assertTrue(hasCause(failure,
org.apache.doris.nereids.exceptions.AnalysisException.class),
+ failure.toString());
+ Assertions.assertFalse(hasCause(failure,
NullPointerException.class), failure.toString());
+ } finally {
+ resumeInsert.countDown();
+ executorService.shutdownNow();
+ }
+ }
+
+ @Test
+ void dictionaryLoadStopsCleanlyWhenDatabaseIsDroppedBeforePlanning()
throws Exception {
+ Config.enable_debug_points = true;
+ DebugPointUtil.addDebugPoint(DICTIONARY_BLOCK_POINT);
+
+ String dbName = "dictionary_insert_drop_race";
+ createDatabaseAndUse(dbName);
+ createTable("CREATE TABLE source_table (id INT NOT NULL, city
VARCHAR(32) NOT NULL) "
+ + "DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES
('replication_num' = '1')");
+ executeNereidsSql("CREATE DICTIONARY dic1 USING source_table (city
KEY, id VALUE) "
+ + "LAYOUT(HASH_MAP) PROPERTIES ('data_lifetime' = '600')");
+
+ Dictionary dictionary =
Env.getCurrentEnv().getDictionaryManager().getDictionary(dbName, "dic1");
+ try {
+ await(() -> dictionary.getStatus() == DictionaryStatus.LOADING);
Review Comment:
Waiting for `LOADING` does not guarantee the load thread has reached
`DictionaryManager.dataLoad.blockBeforePlan`. `dataLoad()` sets `LOADING`
before it resolves/checks the database and before it enters the debug-point
loop, so this test can drop the database early and still pass through the new
`database == null || !isCurrentDictionary(...)` branch without exercising the
stale captured-database/planning path. Please synchronize on a point reached
after the debug point is entered, or make the debug point signal the test, so
this race test fails if the planning path regresses.
--
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]