You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bo...@apache.org on 2022/12/07 03:45:51 UTC

[pulsar] branch branch-2.9 updated (3a5c1d1ac9c -> 8036bd070f6)

This is an automated email from the ASF dual-hosted git repository.

bogong pushed a change to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git


    from 3a5c1d1ac9c [fix][storage]fix OpAddEntry release error when exception in ManagedLedgerInterceptor (#17929)
     new 2ec6471ac42 [fix][broker] Extract additional servlets to the default directory by… (#17477)
     new 8036bd070f6 [fix][cpp] Use weak ptr avoid circular references. (#17481)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../web/plugin/servlet/AdditionalServlets.java     |  4 +-
 .../web/plugin/servlet/AdditionalServletsTest.java | 92 ++++++++++++++++++++++
 pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc   |  7 +-
 3 files changed, 99 insertions(+), 4 deletions(-)
 create mode 100644 pulsar-broker-common/src/test/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServletsTest.java


[pulsar] 02/02: [fix][cpp] Use weak ptr avoid circular references. (#17481)

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bogong pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 8036bd070f67e13da9ff8fbfef4d452c74d75479
Author: Baodi Shi <wu...@icloud.com>
AuthorDate: Thu Sep 22 15:49:12 2022 +0800

    [fix][cpp] Use weak ptr avoid circular references. (#17481)
    
    ### Motivation
    
    Capturing shared ptr in the timer function will cause a circular reference.
    
    ### Modifications
    
    - Use weak ptr instead shared ptr.
    
    (cherry picked from commit 141981b902ae4727d6220055d9292d41c9f61b2e)
---
 pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
index 5fe9446b186..c35d84b6db6 100644
--- a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
+++ b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
@@ -734,11 +734,12 @@ uint64_t MultiTopicsConsumerImpl::getNumberOfConnectedConsumer() {
 }
 void MultiTopicsConsumerImpl::runPartitionUpdateTask() {
     partitionsUpdateTimer_->expires_from_now(partitionsUpdateInterval_);
-    auto self = shared_from_this();
-    partitionsUpdateTimer_->async_wait([self](const boost::system::error_code& ec) {
+    std::weak_ptr<MultiTopicsConsumerImpl> weakSelf{shared_from_this()};
+    partitionsUpdateTimer_->async_wait([weakSelf](const boost::system::error_code& ec) {
         // If two requests call runPartitionUpdateTask at the same time, the timer will fail, and it
         // cannot continue at this time, and the request needs to be ignored.
-        if (!ec) {
+        auto self = weakSelf.lock();
+        if (self && !ec) {
             self->topicPartitionUpdate();
         }
     });


[pulsar] 01/02: [fix][broker] Extract additional servlets to the default directory by… (#17477)

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bogong pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 2ec6471ac428720990da560f2f59fc5977bef0ef
Author: Andras Beni <an...@streamnative.io>
AuthorDate: Thu Sep 22 13:27:09 2022 +0200

    [fix][broker] Extract additional servlets to the default directory by… (#17477)
    
    (cherry picked from commit 3d47ee8ab6a2d39017413b21160a21067cf7439b)
---
 .../web/plugin/servlet/AdditionalServlets.java     |  4 +-
 .../web/plugin/servlet/AdditionalServletsTest.java | 92 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServlets.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServlets.java
index 080e1c75096..a0c0bf98f0a 100644
--- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServlets.java
+++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServlets.java
@@ -25,6 +25,7 @@ import java.util.Map;
 
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.pulsar.common.configuration.PulsarConfiguration;
 import org.apache.pulsar.common.nar.NarClassLoader;
 
@@ -72,7 +73,8 @@ public class AdditionalServlets implements AutoCloseable {
         }
 
         String narExtractionDirectory = conf.getProperties().getProperty(NAR_EXTRACTION_DIRECTORY);
-        if(narExtractionDirectory == null) {
+
+        if (StringUtils.isBlank(narExtractionDirectory)) {
             narExtractionDirectory = NarClassLoader.DEFAULT_NAR_EXTRACTION_DIR;
         }
 
diff --git a/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServletsTest.java b/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServletsTest.java
new file mode 100644
index 00000000000..d8cd8798fb3
--- /dev/null
+++ b/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/web/plugin/servlet/AdditionalServletsTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.web.plugin.servlet;
+
+import static org.mockito.Mockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import org.apache.pulsar.common.configuration.PulsarConfiguration;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.testng.PowerMockTestCase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.Properties;
+
+@PrepareForTest({
+        AdditionalServletUtils.class
+})
+@PowerMockIgnore({"org.apache.logging.log4j.*", "javax.xml.*", "com.sun.org.apache.xerces.*"})
+public class AdditionalServletsTest extends PowerMockTestCase {
+
+
+    @Test
+    public void testEmptyStringAsExtractionDirectory() throws IOException {
+        Properties p = new Properties();
+        p.put("narExtractionDirectory", "");
+        p.put("additionalServlets", "AS1,AS2");
+        p.put("additionalServletDirectory", "/additionalServletDirectory");
+
+        PulsarConfiguration config = mock(PulsarConfiguration.class);
+        Mockito.when(config.getProperties()).thenReturn(p);
+
+        AdditionalServletMetadata asm1 = additionalServletMetadata(1);
+        AdditionalServletMetadata asm2 = additionalServletMetadata(2);
+
+        AdditionalServletDefinitions definitions = new AdditionalServletDefinitions();
+        definitions.servlets().put("AS1", asm1);
+        definitions.servlets().put("AS2", asm2);
+
+        AdditionalServletWithClassLoader as1 = mock(AdditionalServletWithClassLoader.class);
+        AdditionalServletWithClassLoader as2 = mock(AdditionalServletWithClassLoader.class);
+
+        String originalTmpDirectory = System.getProperty("java.io.tmpdir");
+
+        try {
+            PowerMockito.mockStatic(AdditionalServletUtils.class);
+            String tmpDirectory = "/my/tmp/directory";
+            System.setProperty("java.io.tmpdir", tmpDirectory);
+            when(AdditionalServletUtils.searchForServlets(
+                    "/additionalServletDirectory", tmpDirectory)).thenReturn(definitions);
+            when(AdditionalServletUtils.load(asm1, tmpDirectory)).thenReturn(as1);
+            when(AdditionalServletUtils.load(asm2, tmpDirectory)).thenReturn(as2);
+
+            AdditionalServlets servlets = AdditionalServlets.load(config);
+
+            Assert.assertEquals(servlets.getServlets().get("AS1"), as1);
+            Assert.assertEquals(servlets.getServlets().get("AS2"), as2);
+        } finally {
+            System.setProperty("java.io.tmpdir", originalTmpDirectory);
+        }
+    }
+
+    private AdditionalServletMetadata additionalServletMetadata(int index) {
+        AdditionalServletMetadata as = new AdditionalServletMetadata();
+        as.setArchivePath(Paths.get("/additionalServletDirectory/" + index));
+        as.setDefinition(new AdditionalServletDefinition());
+        as.getDefinition().setName("as" + index);
+        as.getDefinition().setAdditionalServletClass("com.example.AS" + index);
+        as.getDefinition().setDescription("Additional Servlet " +index);
+        return as;
+    }
+}