You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2022/02/09 11:04:15 UTC
[pulsar] branch branch-2.8 updated: AbstractMetadataStore: invalidate childrenCache correctly when node created (#14177)
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.8 by this push:
new 7716894 AbstractMetadataStore: invalidate childrenCache correctly when node created (#14177)
7716894 is described below
commit 77168945d25c3c211600d09bb6da9605b873755d
Author: Michael Marshall <mm...@apache.org>
AuthorDate: Wed Feb 9 05:01:53 2022 -0600
AbstractMetadataStore: invalidate childrenCache correctly when node created (#14177)
---
.../MultiBrokerMetadataConsistencyTest.java | 97 ++++++++++++++++++++++
.../metadata/impl/AbstractMetadataStore.java | 1 +
2 files changed, 98 insertions(+)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/zookeeper/MultiBrokerMetadataConsistencyTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/zookeeper/MultiBrokerMetadataConsistencyTest.java
new file mode 100644
index 0000000..c116528
--- /dev/null
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/zookeeper/MultiBrokerMetadataConsistencyTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.broker.zookeeper;
+
+import static org.testng.Assert.assertTrue;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.MultiBrokerBaseTest;
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.metadata.TestZKServer;
+import org.apache.pulsar.metadata.api.MetadataStoreConfig;
+import org.apache.pulsar.metadata.api.MetadataStoreException;
+import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
+import org.apache.pulsar.zookeeper.ZooKeeperClientFactory;
+import org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl;
+import org.apache.zookeeper.ZooKeeper;
+import org.testng.annotations.Test;
+
+@Slf4j
+@Test(groups = "broker")
+public class MultiBrokerMetadataConsistencyTest extends MultiBrokerBaseTest {
+ @Override
+ protected int numberOfAdditionalBrokers() {
+ return 2;
+ }
+
+ TestZKServer testZKServer;
+
+ @Override
+ protected void doInitConf() throws Exception {
+ super.doInitConf();
+ testZKServer = new TestZKServer();
+ }
+
+ @Override
+ protected void onCleanup() {
+ super.onCleanup();
+ if (testZKServer != null) {
+ try {
+ testZKServer.close();
+ } catch (Exception e) {
+ log.error("Error in stopping ZK server", e);
+ }
+ }
+ }
+
+ @Override
+ protected ZooKeeperClientFactory createZooKeeperClientFactory() {
+ return new ZookeeperClientFactoryImpl() {
+ @Override
+ public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType,
+ int zkSessionTimeoutMillis) {
+ return super.create(testZKServer.getConnectionString(), sessionType, zkSessionTimeoutMillis);
+ }
+ };
+ }
+
+ @Override
+ protected MetadataStoreExtended createLocalMetadataStore() throws MetadataStoreException {
+ return MetadataStoreExtended.create(testZKServer.getConnectionString(), MetadataStoreConfig.builder().build());
+ }
+
+ @Override
+ protected MetadataStoreExtended createConfigurationMetadataStore() throws MetadataStoreException {
+ return MetadataStoreExtended.create(testZKServer.getConnectionString(), MetadataStoreConfig.builder().build());
+ }
+
+ @Test
+ public void newTopicShouldBeInTopicsList() throws PulsarAdminException {
+ List<PulsarAdmin> admins = getAllAdmins();
+ PulsarAdmin first = admins.get(0);
+ PulsarAdmin second = admins.get(1);
+ List<String> cacheMiss = second.topics().getList("public/default");
+ assertTrue(cacheMiss.isEmpty());
+ first.topics().createNonPartitionedTopic("persistent://public/default/my-topic");
+ List<String> topics = second.topics().getList("public/default");
+ assertTrue(topics.contains("persistent://public/default/my-topic"));
+ }
+}
diff --git a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/AbstractMetadataStore.java b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/AbstractMetadataStore.java
index f06b8b5..a0ba33b 100644
--- a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/AbstractMetadataStore.java
+++ b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/AbstractMetadataStore.java
@@ -166,6 +166,7 @@ public abstract class AbstractMetadataStore implements MetadataStoreExtended, Co
if (type == NotificationType.Created || type == NotificationType.Deleted) {
existsCache.synchronous().invalidate(path);
+ childrenCache.synchronous().invalidate(path);
String parent = parent(path);
if (parent != null) {
childrenCache.synchronous().invalidate(parent);