This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new e81621be517 branch-4.2: [fix](fe) Close BDB JE group administrators
after use #70210 (#71376)
e81621be517 is described below
commit e81621be517b89e2acc087608e6539c089e65815
Author: Gavin Chou <[email protected]>
AuthorDate: Fri Dec 4 09:28:06 2026 +0800
branch-4.2: [fix](fe) Close BDB JE group administrators after use #70210
(#71376)
### What problem does this PR solve?
Cherry-pick #70210 to `branch-4.2`.
Close all seven per-operation BDB JE group administrators in `finally`
blocks so SSL-backed administrators release their certificate-monitor
executors. Preserve existing return values and exception handling,
including
nested conflict-node removal. `branch-4.2` already uses JE
`18.3.18-doris-SNAPSHOT`, which provides `close()`.
The Java implementation, 18 test cases and PKCS#8 certificate fixture
are
unchanged from the original PR. The only conflict is in
`.gitleaks.toml`:
retain the existing 4.2 configuration and add the exact-path private-key
allowlist needed by the fixture, without importing unrelated master
entries.
### Release note
Release BDB JE group administrators after frontend metadata and HA
operations, preventing certificate-monitor thread retention when using
an SSL-backed administrator.
### Check List (For Author)
- Test:
- [x] `git diff --check`.
- [x] Both changed Java files pass Checkstyle 9.3 using plugin 3.1.2 and
unchanged `branch-4.2` rules (isolated POM; no application compilation).
- [x] Both Java files and the new fixture are byte identical to #70210.
- [x] OpenSSL confirms the original key, PKCS#8 key and client
certificate
have identical public keys.
- [ ] Rerun unit tests and build validation for this backport in CI.
- Behavior changed: Yes, release administrator-owned resources after
use.
- Does this need documentation: No.
---
.gitleaks.toml | 7 +
.../src/main/java/org/apache/doris/ha/BDBHA.java | 70 ++++---
.../test/java/org/apache/doris/ha/BdbHaTest.java | 225 +++++++++++++++++++++
.../ssl_default_certificate/client-key-pkcs8.pem | 28 +++
4 files changed, 306 insertions(+), 24 deletions(-)
diff --git a/.gitleaks.toml b/.gitleaks.toml
index 6f6031c7cfc..63007a9c369 100644
--- a/.gitleaks.toml
+++ b/.gitleaks.toml
@@ -34,3 +34,10 @@ condition = "AND"
regexTarget = "line"
paths =
['''^fe/fe-core/src/test/java/org/apache/doris/datasource/DelegatedCredentialTest\.java$''']
regexes = ['''"eyJhbGciOiJub25lIn0\.eyJleHAiOjE3MDAwMDAwMDB9\."''']
+
+[[rules]]
+id = "private-key"
+
+[[rules.allowlists]]
+description = "Ignore the PKCS#8 form of the existing regression client TLS
test key"
+paths = ['''^regression-test/ssl_default_certificate/client-key-pkcs8\.pem$''']
diff --git a/fe/fe-core/src/main/java/org/apache/doris/ha/BDBHA.java
b/fe/fe-core/src/main/java/org/apache/doris/ha/BDBHA.java
index 5270bf19c54..a1b5f84313f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/ha/BDBHA.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/ha/BDBHA.java
@@ -119,6 +119,8 @@ public class BDBHA implements HAProtocol {
} catch (UnknownMasterException e) {
LOG.warn("Catch UnknownMasterException when calling
getObserverNodes.", e);
return Lists.newArrayList();
+ } finally {
+ replicationGroupAdmin.close();
}
return ret;
}
@@ -146,6 +148,8 @@ public class BDBHA implements HAProtocol {
} catch (UnknownMasterException e) {
LOG.warn("Catch UnknownMasterException when calling
getElectableNodes.", e);
return Lists.newArrayList();
+ } finally {
+ replicationGroupAdmin.close();
}
return ret;
}
@@ -153,10 +157,16 @@ public class BDBHA implements HAProtocol {
@Override
public InetSocketAddress getLeader() {
ReplicationGroupAdmin replicationGroupAdmin =
environment.getReplicationGroupAdmin();
- String leaderName = replicationGroupAdmin.getMasterNodeName();
- ReplicationGroup rg = replicationGroupAdmin.getGroup();
- ReplicationNode rn = rg.getMember(leaderName);
- return rn.getSocketAddress();
+ try {
+ String leaderName = replicationGroupAdmin.getMasterNodeName();
+ ReplicationGroup rg = replicationGroupAdmin.getGroup();
+ ReplicationNode rn = rg.getMember(leaderName);
+ return rn.getSocketAddress();
+ } finally {
+ if (replicationGroupAdmin != null) {
+ replicationGroupAdmin.close();
+ }
+ }
}
@Override
@@ -174,6 +184,8 @@ public class BDBHA implements HAProtocol {
} catch (Exception e) {
LOG.error("remove electable node {} meeting unkown exception:",
nodeName, e);
System.exit(-1);
+ } finally {
+ replicationGroupAdmin.close();
}
return true;
}
@@ -192,6 +204,8 @@ public class BDBHA implements HAProtocol {
} catch (MasterStateException e) {
LOG.error("the updating electable node is master {}", nodeName, e);
return false;
+ } finally {
+ replicationGroupAdmin.close();
}
return true;
}
@@ -202,16 +216,20 @@ public class BDBHA implements HAProtocol {
return;
}
- List<String> conflictNodes = Lists.newArrayList();
- Set<ReplicationNode> replicationNodes =
replicationGroupAdmin.getGroup().getElectableNodes();
- for (ReplicationNode replicationNode : replicationNodes) {
- if (replicationNode.getHostName().equals(host) &&
replicationNode.getPort() == port) {
- conflictNodes.add(replicationNode.getName());
+ try {
+ List<String> conflictNodes = Lists.newArrayList();
+ Set<ReplicationNode> replicationNodes =
replicationGroupAdmin.getGroup().getElectableNodes();
+ for (ReplicationNode replicationNode : replicationNodes) {
+ if (replicationNode.getHostName().equals(host) &&
replicationNode.getPort() == port) {
+ conflictNodes.add(replicationNode.getName());
+ }
}
- }
- for (String conflictNode : conflictNodes) {
- removeElectableNode(conflictNode);
+ for (String conflictNode : conflictNodes) {
+ removeElectableNode(conflictNode);
+ }
+ } finally {
+ replicationGroupAdmin.close();
}
}
@@ -253,20 +271,24 @@ public class BDBHA implements HAProtocol {
if (replicationGroupAdmin == null) {
return;
}
- Set<ReplicationNode> replicationNodes =
replicationGroupAdmin.getGroup().getElectableNodes();
- LOG.debug("removedFrontends:{}", removedFrontends);
- for (ReplicationNode replicationNode : replicationNodes) {
- LOG.debug("node:{}", replicationNode.toString());
- if (removedFrontends.contains(replicationNode.getName())) {
- try {
-
replicationGroupAdmin.removeMember(replicationNode.getName());
- } catch (MemberNotFoundException e) {
- LOG.warn("the electable node is not found {}",
replicationNode.getName());
- } catch (Exception e) {
- LOG.error("remove electable node {} meeting unknown
exception:", replicationNode.getName(), e);
- System.exit(-1);
+ try {
+ Set<ReplicationNode> replicationNodes =
replicationGroupAdmin.getGroup().getElectableNodes();
+ LOG.debug("removedFrontends:{}", removedFrontends);
+ for (ReplicationNode replicationNode : replicationNodes) {
+ LOG.debug("node:{}", replicationNode.toString());
+ if (removedFrontends.contains(replicationNode.getName())) {
+ try {
+
replicationGroupAdmin.removeMember(replicationNode.getName());
+ } catch (MemberNotFoundException e) {
+ LOG.warn("the electable node is not found {}",
replicationNode.getName());
+ } catch (Exception e) {
+ LOG.error("remove electable node {} meeting unknown
exception:", replicationNode.getName(), e);
+ System.exit(-1);
+ }
}
}
+ } finally {
+ replicationGroupAdmin.close();
}
}
}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/ha/BdbHaTest.java
b/fe/fe-core/src/test/java/org/apache/doris/ha/BdbHaTest.java
new file mode 100644
index 00000000000..d0bfb21b0fe
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/ha/BdbHaTest.java
@@ -0,0 +1,225 @@
+// 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.ha;
+
+import org.apache.doris.common.jmockit.Deencapsulation;
+import org.apache.doris.journal.bdbje.BDBEnvironment;
+
+import com.sleepycat.je.rep.MemberNotFoundException;
+import com.sleepycat.je.rep.ReplicationGroup;
+import com.sleepycat.je.rep.ReplicationNode;
+import com.sleepycat.je.rep.ReplicationSSLConfig;
+import com.sleepycat.je.rep.UnknownMasterException;
+import com.sleepycat.je.rep.util.ReplicationGroupAdmin;
+import com.sleepycat.je.rep.utilint.net.SSLChannelFactory;
+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 org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.mockito.Mockito;
+
+import java.net.InetSocketAddress;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ScheduledExecutorService;
+
+public class BdbHaTest {
+ private static final String MASTER = "test-master";
+ private static final InetSocketAddress ADDRESS = new
InetSocketAddress("127.0.0.1", 9010);
+
+ private final List<ReplicationGroupAdmin> admins = new ArrayList<>();
+ private final List<ScheduledExecutorService> monitors = new ArrayList<>();
+ private BDBHA ha;
+ private boolean fail;
+ private String keyStore;
+
+ enum Operation {
+ GET_OBSERVER_NODES,
+ GET_ELECTABLE_NODES,
+ GET_ELECTABLE_NODES_WITHOUT_LEADER,
+ GET_LEADER,
+ REMOVE_ELECTABLE_NODE,
+ UPDATE_NODE_ADDRESS,
+ REMOVE_CONFLICT_NODE,
+ REMOVE_DROPPED_MEMBER
+ }
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ keyStore = System.getProperty("javax.net.ssl.keyStore");
+ System.clearProperty("javax.net.ssl.keyStore");
+ Path certificates =
Paths.get(System.getenv().getOrDefault("DORIS_HOME", "../.."),
+ "regression-test", "ssl_default_certificate");
+ ReplicationSSLConfig config = new ReplicationSSLConfig();
+ config.setSSLPemCaCertFile(certificates.resolve("ca.pem").toString());
+
config.setSSLPemCertFile(certificates.resolve("client-cert.pem").toString());
+ // PKCS#8 form of the existing regression-test client key, as required
by JE.
+
config.setSSLPemKeyFile(certificates.resolve("client-key-pkcs8.pem").toString());
+ config.setSSLCertRefreshIntervalSeconds(3600);
+
+ ReplicationNode node = Mockito.mock(ReplicationNode.class);
+ Mockito.when(node.getName()).thenReturn(MASTER);
+ Mockito.when(node.getHostName()).thenReturn(ADDRESS.getHostString());
+ Mockito.when(node.getPort()).thenReturn(ADDRESS.getPort());
+ Mockito.when(node.getSocketAddress()).thenReturn(ADDRESS);
+ ReplicationGroup group = Mockito.mock(ReplicationGroup.class);
+ Mockito.when(group.getMember(MASTER)).thenReturn(node);
+
Mockito.when(group.getElectableNodes()).thenReturn(Collections.singleton(node));
+
Mockito.when(group.getSecondaryNodes()).thenReturn(Collections.singleton(node));
+
+ BDBEnvironment environment = Mockito.mock(BDBEnvironment.class);
+
Mockito.when(environment.getReplicationGroupAdmin()).thenAnswer(invocation -> {
+ // Keep real JE construction, SSL factories, schedulers and
close().
+ // Only replace RPCs, so these tests need no running replication
group.
+ ReplicationGroupAdmin admin = Mockito.spy(new
ReplicationGroupAdmin("test-group",
+ Collections.singleton(ADDRESS), config));
+ Mockito.doAnswer(call -> {
+ if (fail) {
+ throw new UnknownMasterException("test failure");
+ }
+ return group;
+ }).when(admin).getGroup();
+ Mockito.doReturn(MASTER).when(admin).getMasterNodeName();
+ Mockito.doAnswer(call -> {
+ if (fail) {
+ throw new MemberNotFoundException("test failure");
+ }
+ return null;
+ }).when(admin).removeMember(Mockito.anyString());
+ Mockito.doAnswer(call -> {
+ if (fail) {
+ throw new MemberNotFoundException("test failure");
+ }
+ return null;
+ }).when(admin).updateAddress(Mockito.anyString(),
Mockito.anyString(), Mockito.anyInt());
+ admins.add(admin);
+ SSLChannelFactory factory = Deencapsulation.getField(admin,
"channelFactory");
+ ScheduledExecutorService monitor =
Deencapsulation.getField(factory, "certificateCheckExecutor");
+ Assertions.assertNotNull(monitor, "The test must enable real PEM
certificate monitoring");
+ monitors.add(monitor);
+ return admin;
+ });
+ ha = new BDBHA(environment, MASTER);
+ }
+
+ @AfterEach
+ public void tearDown() {
+ // Also clean up when run against the unfixed implementation.
+ for (ReplicationGroupAdmin admin : admins) {
+ admin.close();
+ }
+ if (keyStore == null) {
+ System.clearProperty("javax.net.ssl.keyStore");
+ } else {
+ System.setProperty("javax.net.ssl.keyStore", keyStore);
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(Operation.class)
+ public void testReleasesCertificateMonitor(Operation operation) {
+ invoke(operation);
+ assertMonitorsReleased();
+ }
+
+ @ParameterizedTest
+ @EnumSource(Operation.class)
+ public void testReleasesCertificateMonitorOnFailure(Operation operation) {
+ fail = true;
+ switch (operation) {
+ case GET_LEADER:
+ case REMOVE_CONFLICT_NODE:
+ case REMOVE_DROPPED_MEMBER:
+ Assertions.assertThrows(UnknownMasterException.class, () ->
invoke(operation));
+ break;
+ default:
+ invoke(operation);
+ }
+ assertMonitorsReleased();
+ }
+
+ @Test
+ public void testRepeatedFrontendQueriesDoNotAccumulateMonitors() {
+ for (int i = 0; i < 40; i++) {
+ ha.getLeader();
+ ha.getElectableNodes(true);
+ ha.getObserverNodes();
+ }
+ Assertions.assertEquals(120, monitors.size());
+ assertMonitorsReleased();
+ }
+
+ @Test
+ public void testNoAvailableAdmin() {
+ BDBHA empty = new BDBHA(Mockito.mock(BDBEnvironment.class), MASTER);
+ Assertions.assertTrue(empty.getObserverNodes().isEmpty());
+ Assertions.assertTrue(empty.getElectableNodes(true).isEmpty());
+ Assertions.assertThrows(NullPointerException.class, empty::getLeader);
+ Assertions.assertFalse(empty.removeElectableNode(MASTER));
+ Assertions.assertFalse(empty.updateNodeAddress(MASTER, "127.0.0.2",
9010));
+ empty.removeConflictNodeIfExist(ADDRESS.getHostString(),
ADDRESS.getPort());
+ empty.removeDroppedMember(new ConcurrentLinkedQueue<>());
+ Assertions.assertTrue(admins.isEmpty());
+ }
+
+ private void assertMonitorsReleased() {
+ Assertions.assertFalse(monitors.isEmpty());
+ for (ScheduledExecutorService monitor : monitors) {
+ Assertions.assertTrue(monitor.isTerminated(), "BDB SSL certificate
monitor was not released");
+ }
+ }
+
+ private void invoke(Operation operation) {
+ switch (operation) {
+ case GET_OBSERVER_NODES:
+ Assertions.assertEquals(fail ? Collections.emptyList() :
Collections.singletonList(ADDRESS),
+ ha.getObserverNodes());
+ break;
+ case GET_ELECTABLE_NODES:
+ Assertions.assertEquals(fail ? Collections.emptyList() :
Collections.singletonList(ADDRESS),
+ ha.getElectableNodes(true));
+ break;
+ case GET_ELECTABLE_NODES_WITHOUT_LEADER:
+ Assertions.assertTrue(ha.getElectableNodes(false).isEmpty());
+ break;
+ case GET_LEADER:
+ Assertions.assertEquals(ADDRESS, ha.getLeader());
+ break;
+ case REMOVE_ELECTABLE_NODE:
+ Assertions.assertEquals(!fail, ha.removeElectableNode(MASTER));
+ break;
+ case UPDATE_NODE_ADDRESS:
+ Assertions.assertEquals(!fail, ha.updateNodeAddress(MASTER,
"127.0.0.2", 9010));
+ break;
+ case REMOVE_CONFLICT_NODE:
+ ha.removeConflictNodeIfExist(ADDRESS.getHostString(),
ADDRESS.getPort());
+ break;
+ case REMOVE_DROPPED_MEMBER:
+ ha.removeDroppedMember(new
ConcurrentLinkedQueue<>(Collections.singleton(MASTER)));
+ break;
+ default:
+ throw new AssertionError(operation);
+ }
+ }
+}
diff --git a/regression-test/ssl_default_certificate/client-key-pkcs8.pem
b/regression-test/ssl_default_certificate/client-key-pkcs8.pem
new file mode 100644
index 00000000000..4dad2d1b2e0
--- /dev/null
+++ b/regression-test/ssl_default_certificate/client-key-pkcs8.pem
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCtZmgvKcVuRNNe
+vLetGg5PTIj5VYTxCz9x0qyFPx5w2taCSgxsG0YSg9qG0L4G4x/Iex01LHojLLGB
+57Z/jUyqF+9z2yxkVur3c08Tuttvy/4uhmSJunkSszi+0OYpwGnhkSxYxHFq5diK
+nK93IYJuzAMz8d3Q88W5ukSiqD/yqMjP9NtAhdsnYViQoW/xndFi/LQY/llWlObj
+NxgHpEDOvrP6psDcuL/RSNRVJ2HOygNafmU59foOnvIC6KhxIykyTrk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/E3iAcXpD3qNQ3LZiPLhd8VE0zWxIPmm6kbsVdE84U9/P
+70rd6fxaXL4Jmkt0tJAqQ7rIjsHnch95kNjAFEMD2QKBgCfN4ib5zxqFDoc1Z1G2
+4x094//awfIlX22/9lOyLZACB93iuqYYSEzbR4mnhFDMHrzAgMxlyhI/zGkAJlBj
+AflFm9DzOjndJeuBaBvpdiejyVFzRzGHmgsgu2AIDG3/bQ9ykXHkiCHThMg6xhjY
+qynnpxskvq7u7IGcrDBrhekK
+-----END PRIVATE KEY-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]