-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](catalog) safely publish Hadoop properties #66392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Gabriel39
merged 2 commits into
apache:branch-4.1
from
Gabriel39:fix/paimon-hadoop-properties-concurrency
Aug 4, 2026
+154
−7
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogPropertyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // 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.atomic.AtomicReference; | ||
|
|
||
| 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.newSingleThreadExecutor(); | ||
| AtomicReference<Map<String, String>> readerResult = new AtomicReference<>(); | ||
| Thread concurrentReader = new Thread( | ||
| () -> readerResult.set(new HashMap<>(catalogProperty.getHadoopProperties()))); | ||
| try { | ||
| Future<Map<String, String>> initializer = executor.submit(catalogProperty::getHadoopProperties); | ||
| Assert.assertTrue(iterationStarted.await(5, TimeUnit.SECONDS)); | ||
|
|
||
| concurrentReader.start(); | ||
| Assert.assertTrue(waitUntilBlockedOrTerminated(concurrentReader, 5, TimeUnit.SECONDS)); | ||
| Assert.assertEquals("The reader must block until initialization publishes the completed map", | ||
| Thread.State.BLOCKED, concurrentReader.getState()); | ||
|
|
||
| allowIteration.countDown(); | ||
| Assert.assertEquals("complete", initializer.get(5, TimeUnit.SECONDS).get("fs.test.property")); | ||
| concurrentReader.join(TimeUnit.SECONDS.toMillis(5)); | ||
| Assert.assertFalse(concurrentReader.isAlive()); | ||
| Assert.assertEquals("complete", readerResult.get().get("fs.test.property")); | ||
| } finally { | ||
| allowIteration.countDown(); | ||
| concurrentReader.interrupt(); | ||
| executor.shutdownNow(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testHadoopPropertiesCacheIsImmutable() { | ||
| Configuration configuration = new Configuration(false); | ||
| 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); | ||
| } | ||
| }; | ||
|
|
||
| Map<String, String> hadoopProperties = catalogProperty.getHadoopProperties(); | ||
| Assert.assertThrows(UnsupportedOperationException.class, | ||
| () -> hadoopProperties.put("fs.test.property", "modified")); | ||
| } | ||
|
|
||
| private static boolean waitUntilBlockedOrTerminated(Thread thread, long timeout, TimeUnit timeUnit) { | ||
| long deadline = System.nanoTime() + timeUnit.toNanos(timeout); | ||
| while (thread.isAlive() && thread.getState() != Thread.State.BLOCKED | ||
| && System.nanoTime() < deadline) { | ||
| Thread.yield(); | ||
| } | ||
| return !thread.isAlive() || thread.getState() == Thread.State.BLOCKED; | ||
| } | ||
|
|
||
| private static class BlockingConfiguration extends Configuration { | ||
| private final CountDownLatch iterationStarted; | ||
| private final CountDownLatch allowIteration; | ||
|
|
||
| BlockingConfiguration(CountDownLatch iterationStarted, CountDownLatch allowIteration) { | ||
| super(false); | ||
| this.iterationStarted = iterationStarted; | ||
| this.allowIteration = allowIteration; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<Map.Entry<String, String>> iterator() { | ||
| iterationStarted.countDown(); | ||
| try { | ||
| if (!allowIteration.await(5, TimeUnit.SECONDS)) { | ||
| throw new AssertionError("Timed out waiting to continue Hadoop configuration initialization"); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new AssertionError("Interrupted while initializing Hadoop configuration", e); | ||
| } | ||
| return super.iterator(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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 hadoopPropertiesis another volatile read: a concurrentaddProperty/modifyCatalogPropscan run after this method's first read, acquire this monitor, reset the field tonull, and make this call returnnull(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.