You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2026/10/13 06:04:21 UTC
(pulsar) 02/08: [fix][meta] Avoid duplicate sync listener registration in OxiaMetadataStore (#26856)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 31c59d8b1f30ecf437cd524d6d4d4ccdd175a14e
Author: Dream95 <86...@qq.com>
AuthorDate: Mon Oct 12 12:55:19 2026 +0800
[fix][meta] Avoid duplicate sync listener registration in OxiaMetadataStore (#26856)
Signed-off-by: Dream95 <zh...@163.com>
(cherry picked from commit 4e3bd9637e8d18111efb132d2f55bdc816f71df0)
---
.../metadata/impl/oxia/OxiaMetadataStore.java | 9 +++-
.../oxia/OxiaMetadataStoreSynchronizerTest.java | 55 ++++++++++++++++++++++
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStore.java b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStore.java
index fbf5b75e7068..be7c234ecc7b 100644
--- a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStore.java
+++ b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStore.java
@@ -18,6 +18,7 @@
*/
package org.apache.pulsar.metadata.impl.oxia;
+import com.google.common.annotations.VisibleForTesting;
import io.opentelemetry.api.OpenTelemetry;
import io.oxia.client.api.AsyncOxiaClient;
import io.oxia.client.api.Notification;
@@ -64,10 +65,15 @@ public class OxiaMetadataStore extends AbstractMetadataStore {
private Optional<MetadataEventSynchronizer> synchronizer;
public OxiaMetadataStore(AsyncOxiaClient oxia, String identity) {
+ this(oxia, identity, null);
+ }
+
+ @VisibleForTesting
+ OxiaMetadataStore(AsyncOxiaClient oxia, String identity, MetadataEventSynchronizer synchronizer) {
super("oxia-metadata", OpenTelemetry.noop(), null, 1);
this.client = oxia;
this.identity = identity;
- this.synchronizer = Optional.empty();
+ this.synchronizer = Optional.ofNullable(synchronizer);
init();
}
@@ -99,7 +105,6 @@ public class OxiaMetadataStore extends AbstractMetadataStore {
updateMetadataEventSynchronizer(synchronizer.orElse(null));
client.notifications(this::notificationCallback);
- super.registerSyncListener(synchronizer);
}
private void notificationCallback(Notification notification) {
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStoreSynchronizerTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStoreSynchronizerTest.java
new file mode 100644
index 000000000000..9e2a326b9f63
--- /dev/null
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/impl/oxia/OxiaMetadataStoreSynchronizerTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.pulsar.metadata.impl.oxia;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+import io.oxia.client.api.AsyncOxiaClient;
+import org.apache.pulsar.metadata.api.MetadataEventSynchronizer;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+public class OxiaMetadataStoreSynchronizerTest {
+
+ private OxiaMetadataStore store;
+
+ @AfterMethod(alwaysRun = true)
+ public void teardown() throws Exception {
+ if (store != null) {
+ store.close();
+ store = null;
+ }
+ }
+
+ @Test
+ public void constructionRegistersSyncListenerExactlyOnce() {
+ AsyncOxiaClient client = mock(AsyncOxiaClient.class);
+ MetadataEventSynchronizer synchronizer = mock(MetadataEventSynchronizer.class);
+
+ store = new OxiaMetadataStore(client, "test-identity", synchronizer);
+
+ verify(synchronizer, times(1)).registerSyncListener(any());
+ assertTrue(store.getMetadataEventSynchronizer().isPresent());
+ assertSame(store.getMetadataEventSynchronizer().get(), synchronizer);
+ }
+}