924060929 commented on code in PR #66913:
URL: https://github.com/apache/doris/pull/66913#discussion_r4056308032
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalMetaCache.java:
##########
@@ -110,7 +118,14 @@ public IcebergExternalMetaCache(ExecutorService
refreshExecutor, ExternalMetaCac
this::loadTableCacheValue, defaultEntryCacheSpec(),
MetaCacheEntryInvalidation.forNameMapping(nameMapping ->
nameMapping))
.withSizeEstimator(this::prepareTableForCachePublication)
- .withReplacementListener(this::retireTableGeneration));
+ .withReplacementListener(this::retireTableGeneration)
+ .withUnpublishedValueRetirer(IcebergTableCacheValue::retire)
+ .withRemovalListener(value -> value, (key, value) -> {
Review Comment:
Fixed on the current head. Iceberg table removal now retires the full table
graph synchronously in the removal listener and returns only a compact Boolean
token to the asynchronous follow-up queue, so retired table/FileIO graphs no
longer escape the cache budget.
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/source/IcebergScanNode.java:
##########
@@ -1709,7 +1723,109 @@ public void doStartSplit() throws UserException {
}
}
}
- }, Env.getCurrentEnv().getExtMetaCacheMgr().getScheduleExecutor());
+ });
+ splitAssignment.addCloseable(planningTask);
+ planningTask.submit();
+ }
+
+ /** Owns the planner generation until the worker actually exits, including
cancellation races. */
+ @VisibleForTesting
+ static final class AsyncPlanningTask implements Runnable, Closeable {
+ private final ExecutorService executor;
+ private final SplitAssignment splitAssignment;
+ private final Closeable generationLease;
+ private final Runnable planning;
+ private boolean submitted;
+ private boolean started;
+ private boolean closeRequested;
+ private boolean finished;
+ private Thread runner;
+
+ AsyncPlanningTask(ExecutorService executor, SplitAssignment
splitAssignment,
+ Closeable generationLease, Runnable planning) {
+ this.executor = Objects.requireNonNull(executor, "executor is
null");
+ this.splitAssignment = Objects.requireNonNull(splitAssignment,
"splitAssignment is null");
+ this.generationLease = Objects.requireNonNull(generationLease,
"generationLease is null");
+ this.planning = Objects.requireNonNull(planning, "planning is
null");
+ }
+
+ void submit() {
+ try {
+ synchronized (this) {
+ if (finished) {
+ return;
+ }
+ submitted = true;
+ }
+ executor.execute(this);
Review Comment:
Fixed in b6f05bedd3d. Async planning now submits a FutureTask wrapper and
cancels/removes that same wrapper before start, so BlockedPolicy observes
cancellation even in the submitted-before-enqueue gap. A real single-worker,
one-slot bounded-executor regression covers the full-queue race;
IcebergScanNodeTest passes 100/100.
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalCatalog.java:
##########
@@ -73,8 +86,39 @@ public class HMSExternalCatalog extends ExternalCatalog {
//for "type" = "hms" , but is iceberg table.
private IcebergMetadataOps icebergMetadataOps;
+ private IcebergCatalogResourceTracker icebergResourceTracker = new
IcebergCatalogResourceTracker();
private volatile AbstractHiveProperties hmsProperties;
+ private AtomicLong runtimeGeneration = new AtomicLong();
+
+ public synchronized long getRuntimeGeneration() {
Review Comment:
Fixed on the current head. HMSExternalCatalog.getRuntimeGeneration() is now
a lock-free AtomicLong.get(); per-split generation checks no longer take the
catalog monitor.
##########
fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalCatalogRuntimeStateTest.java:
##########
@@ -0,0 +1,120 @@
+// 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.datasource;
+
+import org.apache.doris.datasource.hive.HMSExternalCatalog;
+import org.apache.doris.datasource.iceberg.IcebergCatalogResourceTracker;
+import org.apache.doris.datasource.iceberg.IcebergExternalCatalog;
+import org.apache.doris.datasource.iceberg.IcebergRestExternalCatalog;
+import org.apache.doris.persist.gson.GsonUtils;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+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.TimeoutException;
+
+public class ExternalCatalogRuntimeStateTest {
+
+ @Test
+ public void testIcebergRuntimeStateRestoredAfterGsonReplay() throws
Exception {
+ IcebergExternalCatalog restored = roundTrip(
+ new IcebergRestExternalCatalog(1L, "iceberg", null,
Collections.emptyMap(), ""),
+ IcebergExternalCatalog.class);
+
+ assertTrackerCanRetainAndRelease(restored,
IcebergExternalCatalog.class, "resourceTracker");
+ }
+
+ @Test
+ public void testHmsRuntimeStateRestoredAfterGsonReplay() throws Exception {
+ HMSExternalCatalog restored = roundTrip(
+ new HMSExternalCatalog(2L, "hms", null,
Collections.emptyMap(), ""),
+ HMSExternalCatalog.class);
+
+ Assertions.assertEquals(0L, restored.getRuntimeGeneration());
+ assertTrackerCanRetainAndRelease(restored, HMSExternalCatalog.class,
"icebergResourceTracker");
+ }
+
+ @Test
+ public void testHmsRuntimeGenerationCannotObservePropertyCommitMidReset()
throws Exception {
+ CountDownLatch resetEntered = new CountDownLatch(1);
+ CountDownLatch allowResetToFinish = new CountDownLatch(1);
+ HMSExternalCatalog catalog = new HMSExternalCatalog(
+ 3L, "hms", null,
+ new HashMap<>(Collections.singletonMap("s3.access_key",
"old")), "") {
+ @Override
+ public synchronized void
notifyPropertiesUpdated(java.util.Map<String, String> updatedProps) {
+ resetEntered.countDown();
+ try {
+ Assertions.assertTrue(allowResetToFinish.await(5,
TimeUnit.SECONDS));
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+ try {
+ Future<?> modifier = executor.submit(() ->
+
catalog.modifyCatalogProps(Collections.singletonMap("s3.access_key", "new")));
+ Assertions.assertTrue(resetEntered.await(5, TimeUnit.SECONDS));
+ Assertions.assertEquals("new",
catalog.getProperties().get("s3.access_key"));
+
+ CountDownLatch readerStarted = new CountDownLatch(1);
+ Future<Long> reader = executor.submit(() -> {
+ readerStarted.countDown();
+ return catalog.getRuntimeGeneration();
+ });
+ Assertions.assertTrue(readerStarted.await(5, TimeUnit.SECONDS));
+ Assertions.assertThrows(TimeoutException.class, () ->
reader.get(200, TimeUnit.MILLISECONDS));
Review Comment:
Fixed on the current head. The runtime-state test now asserts that the
lock-free reader immediately observes generation 1 while reset completion is
still paused; the stale TimeoutException oracle has been removed.
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/hudi/HudiExternalMetaCache.java:
##########
@@ -93,8 +96,10 @@ public HudiExternalMetaCache(ExecutorService
refreshExecutor, ExternalMetaCacheB
TablePartitionValues.class,
this::loadPartitionValuesCacheValue, defaultEntryCacheSpec(),
MetaCacheEntryInvalidation.forNameMapping(HudiPartitionCacheKey::getNameMapping)));
fsViewEntry = registerEntry(MetaCacheEntryDef.of(ENTRY_FS_VIEW,
HudiFsViewCacheKey.class,
- HoodieTableFileSystemView.class, this::createFsView,
defaultEntryCacheSpec(),
-
MetaCacheEntryInvalidation.forNameMapping(HudiFsViewCacheKey::getNameMapping)));
+ HudiFsViewCacheValue.class, this::createFsView,
defaultEntryCacheSpec(),
+ false,
MetaCacheEntryInvalidation.forNameMapping(HudiFsViewCacheKey::getNameMapping))
+ .withRemovalListener(value -> value,
this::releaseFsViewCacheReference)
Review Comment:
Fixed on the current head. Hudi filesystem-view removal synchronously calls
value.retire() and queues only a Boolean cleanup token, so the full
view/timeline graph is not retained by the unbounded cleanup queue.
--
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]