github-actions[bot] commented on code in PR #66392:
URL: https://github.com/apache/doris/pull/66392#discussion_r3705007495
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogProperty.java:
##########
@@ -284,7 +284,9 @@ public Map<String, String> getHadoopProperties() {
if (hadoopProperties == null) {
synchronized (this) {
if (hadoopProperties == null) {
- hadoopProperties = new HashMap<>();
+ // Publish the volatile cache only after construction
because readers skip this
+ // lock once it is non-null and must never observe a map
still being mutated.
+ Map<String, String> result = new HashMap<>();
Review Comment:
**[P1] Return a retained snapshot across invalidation**
Please use the local-snapshot form for the whole double-checked getter and
return that snapshot. The final `return hadoopProperties` is another volatile
read: a concurrent `addProperty`/`modifyCatalogProps` can run after this
method's first read, acquire this monitor, reset the field to `null`, and make
this call return `null` (the same window exists just after initialization
releases the monitor). Current consumers immediately iterate or copy the
result, so that becomes an intermittent NPE during catalog updates.
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogProperty.java:
##########
@@ -294,12 +296,13 @@ public Map<String, String> getHadoopProperties() {
String key = entry.getKey();
String value = entry.getValue();
if (value != null) {
- hadoopProperties.put(key, value);
+ result.put(key, value);
}
});
}
}
- StorageProperties.setCombinedFsCacheKey(hadoopProperties,
storageMap.values());
+ StorageProperties.setCombinedFsCacheKey(result,
storageMap.values());
+ hadoopProperties = result;
Review Comment:
**[P1] Keep the published cache immutable**
The construction itself is safely published now, but this still exposes the
same mutable `HashMap` after publication. `PaimonTableValuedFunction` keeps
this exact map (`PaimonTableValuedFunction.java:89-90`) and appends Kerberos
entries in `appendHMSKerberosProps`, while `ExternalCatalog.buildConf` iterates
it and `PaimonWriteBinding` copies it. Those paths can still race into partial
Kerberos state or `ConcurrentModificationException`, and the TVF-specific
entries also leak into the catalog cache. Please keep the cached snapshot
encapsulated or immutable and copy it before caller-specific augmentation.
##########
fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogPropertyTest.java:
##########
@@ -0,0 +1,109 @@
+// 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.property.storage.StorageProperties;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+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 CatalogPropertyTest {
+
+ @Test
+ public void testHadoopPropertiesArePublishedAfterInitialization() throws
Exception {
+ CountDownLatch iterationStarted = new CountDownLatch(1);
+ CountDownLatch allowIteration = new CountDownLatch(1);
+ Configuration configuration = new
BlockingConfiguration(iterationStarted, allowIteration);
+ configuration.set("fs.test.property", "complete");
+
+ StorageProperties storageProperties =
Mockito.mock(StorageProperties.class);
+
Mockito.when(storageProperties.getHadoopStorageConfig()).thenReturn(configuration);
+
Mockito.when(storageProperties.getFsCacheFingerprint()).thenReturn("test-fingerprint");
+
+ CatalogProperty catalogProperty = new CatalogProperty(null,
Collections.emptyMap()) {
+ @Override
+ public Map<StorageProperties.Type, StorageProperties>
getStoragePropertiesMap() {
+ return Collections.singletonMap(StorageProperties.Type.HDFS,
storageProperties);
+ }
+ };
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+ CountDownLatch readerStarted = new CountDownLatch(1);
+ try {
+ Future<Map<String, String>> initializer =
executor.submit(catalogProperty::getHadoopProperties);
+ Assert.assertTrue(iterationStarted.await(5, TimeUnit.SECONDS));
+
+ Future<Map<String, String>> concurrentReader = executor.submit(()
-> {
+ readerStarted.countDown();
Review Comment:
**[P2] Make the old-code failure handshake deterministic**
`readerStarted` only proves that the task began, not that it reached
`getHadoopProperties()`: the worker can be descheduled immediately after this
countdown. In that schedule the 200 ms `get` times out even on the old
early-publication code; after `allowIteration` is released both futures return
the complete map and the regression passes falsely. Please use a bounded
handshake that observes the reader complete on the old path or actually become
blocked at the getter or monitor before releasing the initializer.
--
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]