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 2024/12/16 12:14:11 UTC
(pulsar) branch branch-4.0 updated (e88fc71d0a5 -> c49a2e59466)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a change to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
from e88fc71d0a5 [fix][broker] Fix the retry mechanism in `MetadataCache#readModifyUpdateOrCreate` (#23686)
new 8f9d7962ae2 [improve][client] Print consumer stats log if prefetched messages are not zero (#23698)
new f06661365bc [fix] [broker] fix NPE when calculating a topic's backlogQuota (#23720)
new 4201f990224 [fix][client] Fix wrong start message id when it's a chunked message id (#23713)
new 84d3b2b2a93 [fix][doc] Refine ClientBuilder#memoryLimit and ConsumerBuilder#autoScaledReceiverQueueSizeEnabled javadoc (#23687)
new 18cd2732353 [improve] [test] Add more test for the case that client receives a SendError, which relates to the PR #23038 (#23721)
new 5ce558b91f9 [fix][broker] Avoid block markDeletePosition forward when skip lost entries (#21210)
new c49a2e59466 [fix][sec] Upgrade async-http-client to 2.12.4 to address CVE-2024-53990 (#23732)
The 7 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:
distribution/server/src/assemble/LICENSE.bin.txt | 6 +-
distribution/shell/src/assemble/LICENSE.bin.txt | 6 +-
.../bookkeeper/mledger/impl/ManagedCursorImpl.java | 48 +++++++++
.../bookkeeper/mledger/impl/OpReadEntry.java | 2 +
.../bookkeeper/mledger/impl/ManagedCursorTest.java | 47 +++++++++
pom.xml | 9 +-
pulsar-broker/pom.xml | 2 +-
.../broker/service/persistent/PersistentTopic.java | 6 +-
.../PersistentTopicProtectedMethodsTest.java | 114 +++++++++++++++++++++
.../apache/pulsar/client/impl/ClientCnxTest.java | 59 ++++++++++-
.../pulsar/client/impl/MessageChunkingTest.java | 25 +++--
pulsar-client-admin-shaded/pom.xml | 2 +-
pulsar-client-admin/pom.xml | 2 +-
pulsar-client-all/pom.xml | 2 +-
.../apache/pulsar/client/api/ClientBuilder.java | 5 +-
.../apache/pulsar/client/api/ConsumerBuilder.java | 9 +-
pulsar-client-shaded/pom.xml | 2 +-
.../apache/pulsar/client/impl/ConsumerImpl.java | 8 +-
.../client/impl/ConsumerStatsRecorderImpl.java | 5 +-
pulsar-proxy/pom.xml | 2 +-
tiered-storage/jcloud/pom.xml | 2 +-
21 files changed, 320 insertions(+), 43 deletions(-)
create mode 100644 pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicProtectedMethodsTest.java
(pulsar) 06/07: [fix][broker] Avoid block markDeletePosition forward when skip lost entries (#21210)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 5ce558b91f98d4eedc9e6ff731a187b71200287c
Author: hanmz <gu...@tencent.com>
AuthorDate: Mon Dec 16 19:22:28 2024 +0800
[fix][broker] Avoid block markDeletePosition forward when skip lost entries (#21210)
Co-authored-by: Lari Hotari <lh...@users.noreply.github.com>
Co-authored-by: Lari Hotari <lh...@apache.org>
(cherry picked from commit 3761dc482cf0566ad012b06a908422938bc3f391)
---
.../bookkeeper/mledger/impl/ManagedCursorImpl.java | 48 ++++++++++++++++++++++
.../bookkeeper/mledger/impl/OpReadEntry.java | 2 +
.../bookkeeper/mledger/impl/ManagedCursorTest.java | 47 +++++++++++++++++++++
3 files changed, 97 insertions(+)
diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
index 478c6a1b379..022cecf8d57 100644
--- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
+++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
@@ -2890,6 +2890,54 @@ public class ManagedCursorImpl implements ManagedCursor {
}, null);
}
+ /**
+ * Manually acknowledge all entries from startPosition to endPosition.
+ * - Since this is an uncommon event, we focus on maintainability. So we do not modify
+ * {@link #individualDeletedMessages} and {@link #batchDeletedIndexes}, but call
+ * {@link #asyncDelete(Position, AsyncCallbacks.DeleteCallback, Object)}.
+ * - This method is valid regardless of the consumer ACK type.
+ * - If there is a consumer ack request after this event, it will also work.
+ */
+ public void skipNonRecoverableEntries(Position startPosition, Position endPosition){
+ long ledgerId = startPosition.getLedgerId();
+ LedgerInfo ledgerInfo = ledger.getLedgersInfo().get(ledgerId);
+ if (ledgerInfo == null) {
+ return;
+ }
+
+ long startEntryId = Math.max(0, startPosition.getEntryId());
+ long endEntryId = ledgerId != endPosition.getLedgerId() ? ledgerInfo.getEntries() : endPosition.getEntryId();
+ if (startEntryId >= endEntryId) {
+ return;
+ }
+
+ lock.writeLock().lock();
+ log.warn("[{}] [{}] Since these entry for ledger [{}] is lost and the autoSkipNonRecoverableData is true, "
+ + "these entries [{}:{}) will be auto acknowledge in subscription",
+ ledger.getName(), name, ledgerId, startEntryId, endEntryId);
+ try {
+ for (long i = startEntryId; i < endEntryId; i++) {
+ if (!individualDeletedMessages.contains(ledgerId, i)) {
+ asyncDelete(PositionFactory.create(ledgerId, i), new AsyncCallbacks.DeleteCallback() {
+ @Override
+ public void deleteComplete(Object ctx) {
+ // ignore.
+ }
+
+ @Override
+ public void deleteFailed(ManagedLedgerException ex, Object ctx) {
+ // The method internalMarkDelete already handled the failure operation. We only need to
+ // make sure the memory state is updated.
+ // If the broker crashed, the non-recoverable ledger will be detected again.
+ }
+ }, null);
+ }
+ }
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
// //////////////////////////////////////////////////
void startCreatingNewMetadataLedger() {
diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java
index 3fd7e36c433..a4928b44bd9 100644
--- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java
+++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java
@@ -137,6 +137,8 @@ class OpReadEntry implements ReadEntriesCallback {
updateReadPosition(nexReadPosition);
if (lostLedger != null) {
cursor.getManagedLedger().skipNonRecoverableLedger(lostLedger);
+ } else {
+ cursor.skipNonRecoverableEntries(readPosition, nexReadPosition);
}
checkReadCompletion();
} else {
diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
index b4ab673facb..69b74fcf8f5 100644
--- a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
+++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
@@ -4766,6 +4766,53 @@ public class ManagedCursorTest extends MockedBookKeeperTestCase {
&& cursorReadPosition.getEntryId() == expectReadPosition.getEntryId());
}
+ @Test
+ public void testSkipNonRecoverableEntries() throws ManagedLedgerException, InterruptedException {
+ ManagedLedgerConfig managedLedgerConfig = new ManagedLedgerConfig();
+ int maxMessagePerLedger = 10;
+ managedLedgerConfig.setMaxEntriesPerLedger(maxMessagePerLedger);
+ ManagedLedger ledger = factory.open("testSkipNonRecoverableEntries", managedLedgerConfig);
+ ManagedCursorImpl cursor = (ManagedCursorImpl) ledger.openCursor("my-cursor");
+
+ Position lacPosition = ledger.getLastConfirmedEntry();
+ long ledgerId = lacPosition.getLedgerId();
+ assertEquals(PositionFactory.create(ledgerId, -1), cursor.getMarkDeletedPosition());
+
+ // Mock add 10 entry
+ for (int i = 0; i < 10; i++) {
+ ledger.addEntry(String.valueOf(i).getBytes());
+ }
+
+ // read 2 entry and delete these entries, MarkDeletedPosition move forward
+ List<Entry> entries = cursor.readEntries(2);
+ for (Entry entry : entries) {
+ cursor.delete(entry.getPosition());
+ }
+ assertEquals(PositionFactory.create(ledgerId, 1), cursor.getMarkDeletedPosition());
+
+ // read the next 6 entry and not delete, MarkDeletedPosition not move forward
+ entries = cursor.readEntries(6);
+ assertEquals(PositionFactory.create(ledgerId, 1), cursor.getMarkDeletedPosition());
+
+ // delete last read entry, MarkDeletedPosition not move forward
+ Entry lastEntry = entries.get(entries.size() - 1);
+ cursor.delete(lastEntry.getPosition());
+ assertEquals(PositionFactory.create(ledgerId, 1), cursor.getMarkDeletedPosition());
+
+ // call skip entries, MarkDeletedPosition move forward
+ cursor.skipNonRecoverableEntries(cursor.getMarkDeletedPosition(),
+ PositionFactory.create(ledgerId, lastEntry.getEntryId()));
+ assertEquals(PositionFactory.create(ledgerId, lastEntry.getEntryId()), cursor.getMarkDeletedPosition());
+
+ // repeat call skip entries, MarkDeletedPosition not change
+ cursor.skipNonRecoverableEntries(cursor.getMarkDeletedPosition(),
+ PositionFactory.create(ledgerId, lastEntry.getEntryId()));
+ assertEquals(PositionFactory.create(ledgerId, lastEntry.getEntryId()), cursor.getMarkDeletedPosition());
+
+ cursor.close();
+ ledger.close();
+ }
+
@Test
public void testRecoverCursorWithTerminateManagedLedger() throws Exception {
String mlName = "my_test_ledger";
(pulsar) 02/07: [fix] [broker] fix NPE when calculating a topic's backlogQuota (#23720)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit f06661365bc34ed17ad898b85e075c4c8753e571
Author: fengyubiao <yu...@streamnative.io>
AuthorDate: Fri Dec 13 11:36:09 2024 +0800
[fix] [broker] fix NPE when calculating a topic's backlogQuota (#23720)
(cherry picked from commit 8e80f88cd46ad041b87773d49c5ce4420df95b9a)
---
.../broker/service/persistent/PersistentTopic.java | 6 +-
.../PersistentTopicProtectedMethodsTest.java | 114 +++++++++++++++++++++
2 files changed, 118 insertions(+), 2 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
index 0b2c9d8c7bc..056fad2a005 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
@@ -3631,7 +3631,8 @@ public class PersistentTopic extends AbstractTopic implements Topic, AddEntryCal
});
}
- private EstimateTimeBasedBacklogQuotaCheckResult estimatedTimeBasedBacklogQuotaCheck(
+ @VisibleForTesting
+ EstimateTimeBasedBacklogQuotaCheckResult estimatedTimeBasedBacklogQuotaCheck(
Position markDeletePosition)
throws ExecutionException, InterruptedException {
int backlogQuotaLimitInSecond = getBacklogQuota(BacklogQuotaType.message_age).getLimitTime();
@@ -3650,7 +3651,8 @@ public class PersistentTopic extends AbstractTopic implements Topic, AddEntryCal
// if the mark-delete position is the last entry it means all entries for
// that ledger are acknowledged
- if (markDeletePosition.getEntryId() == markDeletePositionLedgerInfo.getEntries() - 1) {
+ if (markDeletePositionLedgerInfo != null
+ && (markDeletePosition.getEntryId() == markDeletePositionLedgerInfo.getEntries() - 1)) {
Position positionToCheck = ledger.getNextValidPosition(markDeletePosition);
positionToCheckLedgerInfo = ledger.getLedgerInfo(positionToCheck.getLedgerId()).get();
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicProtectedMethodsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicProtectedMethodsTest.java
new file mode 100644
index 00000000000..1d841483ed7
--- /dev/null
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicProtectedMethodsTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.service.persistent;
+
+import static org.testng.Assert.assertEquals;
+import java.util.concurrent.CompletableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl;
+import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
+import org.apache.pulsar.broker.BrokerTestUtil;
+import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.ProducerConsumerBase;
+import org.awaitility.Awaitility;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Slf4j
+@Test(groups = "broker")
+public class PersistentTopicProtectedMethodsTest extends ProducerConsumerBase {
+
+ @BeforeClass(alwaysRun = true)
+ @Override
+ protected void setup() throws Exception {
+ super.internalSetup();
+ super.producerBaseSetup();
+ }
+
+ @AfterClass(alwaysRun = true)
+ @Override
+ protected void cleanup() throws Exception {
+ super.internalCleanup();
+ }
+
+ protected void doInitConf() throws Exception {
+ this.conf.setPreciseTimeBasedBacklogQuotaCheck(true);
+ this.conf.setManagedLedgerMaxEntriesPerLedger(2);
+ this.conf.setManagedLedgerMaxLedgerRolloverTimeMinutes(10);
+ this.conf.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
+ }
+
+ /***
+ * Background: the steps for checking backlog metadata are as follows.
+ * - Get the oldest cursor.
+ * - Return the result if the oldest `cursor.md` equals LAC.
+ * - Else, calculate the estimated backlog quota.
+ *
+ * What case been covered by this test.
+ * - The method `PersistentTopic.estimatedTimeBasedBacklogQuotaCheck` may get an NPE when the
+ * `@param position(cursor.markDeletedPositon)` equals LAC and the latest ledger has been removed by a
+ * `ML.trimLedgers`, which was introduced by https://github.com/apache/pulsar/pull/21816.
+ * - Q: The broker checked whether the oldest `cursor.md` equals LAC at step 2 above, why does it still call
+ * `PersistentTopic.estimatedTimeBasedBacklogQuotaCheck` with a param that equals `LAC`?
+ * - A: There may be some `acknowledgments` and `ML.trimLedgers` that happened between `step2 above and step 3`.
+ */
+ @Test
+ public void testEstimatedTimeBasedBacklogQuotaCheckWhenNoBacklog() throws Exception {
+ final String tp = BrokerTestUtil.newUniqueName("public/default/tp");
+ admin.topics().createNonPartitionedTopic(tp);
+ PersistentTopic persistentTopic = (PersistentTopic) pulsar.getBrokerService().getTopic(tp, false).join().get();
+ ManagedLedgerImpl ml = (ManagedLedgerImpl) persistentTopic.getManagedLedger();
+ Consumer c1 = pulsarClient.newConsumer().topic(tp).subscriptionName("s1").subscribe();
+ ManagedCursorImpl cursor = (ManagedCursorImpl) ml.getCursors().get("s1");
+
+ // Generated multi ledgers.
+ Producer<byte[]> p1 = pulsarClient.newProducer().topic(tp).create();
+ byte[] content = new byte[]{1};
+ for (int i = 0; i < 10; i++) {
+ p1.send(content);
+ }
+
+ // Consume all messages.
+ // Trim ledgers, then the LAC relates to a ledger who has been deleted.
+ admin.topics().skipAllMessages(tp, "s1");
+ Awaitility.await().untilAsserted(() -> {
+ assertEquals(cursor.getNumberOfEntriesInBacklog(true), 0);
+ assertEquals(cursor.getMarkDeletedPosition(), ml.getLastConfirmedEntry());
+ });
+ CompletableFuture completableFuture = new CompletableFuture();
+ ml.trimConsumedLedgersInBackground(completableFuture);
+ completableFuture.join();
+ Awaitility.await().untilAsserted(() -> {
+ assertEquals(ml.getLedgersInfo().size(), 1);
+ assertEquals(cursor.getNumberOfEntriesInBacklog(true), 0);
+ assertEquals(cursor.getMarkDeletedPosition(), ml.getLastConfirmedEntry());
+ });
+
+ // Verify: "persistentTopic.estimatedTimeBasedBacklogQuotaCheck" will not get a NullPointerException.
+ Position oldestPosition = ml.getCursors().getCursorWithOldestPosition().getPosition();
+ persistentTopic.estimatedTimeBasedBacklogQuotaCheck(oldestPosition);
+
+ p1.close();
+ c1.close();
+ admin.topics().delete(tp, false);
+ }
+}
(pulsar) 01/07: [improve][client] Print consumer stats log if prefetched messages are not zero (#23698)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 8f9d7962ae25aff78e931a394f544d9f4b1052ea
Author: Penghui Li <pe...@apache.org>
AuthorDate: Thu Dec 12 21:32:20 2024 +0800
[improve][client] Print consumer stats log if prefetched messages are not zero (#23698)
(cherry picked from commit c52af1d5c733ec05b40fc72e63a202f20d25603b)
---
.../org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java
index 8dfc0af8e1d..5cbbcc44298 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java
@@ -146,15 +146,16 @@ public class ConsumerStatsRecorderImpl implements ConsumerStatsRecorder {
receivedMsgsRate = currentNumMsgsReceived / elapsed;
receivedBytesRate = currentNumBytesReceived / elapsed;
+ int prefetchQueueSize = consumerImpl.incomingMessages.size();
if ((currentNumMsgsReceived | currentNumBytesReceived | currentNumReceiveFailed | currentNumAcksSent
- | currentNumAcksFailed) != 0) {
+ | currentNumAcksFailed | prefetchQueueSize) != 0) {
log.info(
"[{}] [{}] [{}] Prefetched messages: {} --- "
+ "Consume throughput received: {} msgs/s --- {} Mbit/s --- "
+ "Ack sent rate: {} ack/s --- " + "Failed messages: {} --- batch messages: {} ---"
+ "Failed acks: {}",
consumerImpl.getTopic(), consumerImpl.getSubscription(), consumerImpl.consumerName,
- consumerImpl.incomingMessages.size(), THROUGHPUT_FORMAT.format(receivedMsgsRate),
+ prefetchQueueSize, THROUGHPUT_FORMAT.format(receivedMsgsRate),
THROUGHPUT_FORMAT.format(receivedBytesRate * 8 / 1024 / 1024),
THROUGHPUT_FORMAT.format(currentNumAcksSent / elapsed), currentNumReceiveFailed,
currentNumBatchReceiveFailed, currentNumAcksFailed);
(pulsar) 05/07: [improve] [test] Add more test for the case that client receives a SendError, which relates to the PR #23038 (#23721)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 18cd273235314f09cffe8494b17839bd44f1b759
Author: fengyubiao <yu...@streamnative.io>
AuthorDate: Mon Dec 16 10:11:58 2024 +0800
[improve] [test] Add more test for the case that client receives a SendError, which relates to the PR #23038 (#23721)
(cherry picked from commit 1113153bd33a59b5997a1473514cc63f34d54991)
---
.../apache/pulsar/client/impl/ClientCnxTest.java | 59 +++++++++++++++++++++-
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
index e25212e0108..35b89ad988c 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
@@ -26,10 +26,14 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.PulsarVersion;
import org.apache.pulsar.broker.BrokerTestUtil;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
+import org.apache.pulsar.broker.service.ServerCnx;
import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.MessageIdAdv;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.Schema;
@@ -44,6 +48,7 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+@Slf4j
@Test(groups = "broker-impl")
public class ClientCnxTest extends MockedPulsarServiceBaseTest {
@@ -137,6 +142,7 @@ public class ClientCnxTest extends MockedPulsarServiceBaseTest {
public void testCnxReceiveSendError() throws Exception {
final String topicOne = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-one";
final String topicTwo = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-two";
+ final String topicThree = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-three";
PulsarClient client = PulsarClient.builder().serviceUrl(lookupUrl.toString()).connectionsPerBroker(1).build();
Producer<String> producerOne = client.newProducer(Schema.STRING)
@@ -145,22 +151,31 @@ public class ClientCnxTest extends MockedPulsarServiceBaseTest {
Producer<String> producerTwo = client.newProducer(Schema.STRING)
.topic(topicTwo)
.create();
+ Producer<String> producerThree = client.newProducer(Schema.STRING)
+ .topic(topicThree).producerName("three")
+ .create();
ClientCnx cnxOne = ((ProducerImpl<?>) producerOne).getClientCnx();
ClientCnx cnxTwo = ((ProducerImpl<?>) producerTwo).getClientCnx();
+ ClientCnx cnxThree = ((ProducerImpl<?>) producerTwo).getClientCnx();
// simulate a sending error
cnxOne.handleSendError(Commands.newSendErrorCommand(((ProducerImpl<?>) producerOne).producerId,
- 10, ServerError.PersistenceError, "persistent error").getSendError());
+ 10, ServerError.PersistenceError, "persistent error 1").getSendError());
+ cnxThree.handleSendError(Commands.newSendErrorCommand(((ProducerImpl<?>) producerOne).producerId,
+ 10, ServerError.PersistenceError, "persistent error 3").getSendError());
// two producer use the same cnx
Assert.assertEquals(cnxOne, cnxTwo);
+ Assert.assertEquals(cnxThree, cnxTwo);
// the cnx will not change
try {
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() ->
(((ProducerImpl<?>) producerOne).getClientCnx() != null
&& !cnxOne.equals(((ProducerImpl<?>) producerOne).getClientCnx()))
- || !cnxTwo.equals(((ProducerImpl<?>) producerTwo).getClientCnx()));
+ || (((ProducerImpl<?>) producerThree).getClientCnx() != null
+ && !cnxThree.equals(((ProducerImpl<?>) producerThree).getClientCnx()))
+ || !cnxTwo.equals(((ProducerImpl<?>) producerTwo).getClientCnx()));
Assert.fail();
} catch (Throwable e) {
Assert.assertTrue(e instanceof ConditionTimeoutException);
@@ -173,11 +188,51 @@ public class ClientCnxTest extends MockedPulsarServiceBaseTest {
// producer also can send message
producerOne.send("test");
producerTwo.send("test");
+ producerThree.send("test");
producerTwo.close();
producerOne.close();
+ producerThree.close();
client.close();
}
+ @Test
+ public void testCnxReceiveSendErrorWithMultiConnectionsPerBroker() throws Exception {
+ PulsarClient client = PulsarClient.builder().serviceUrl(lookupUrl.toString())
+ .connectionsPerBroker(1000).build();
+
+ // Create a producer with customized name.
+ final String tp = BrokerTestUtil.newUniqueName(NAMESPACE + "/tp");
+ admin.topics().createNonPartitionedTopic(tp);
+ ProducerImpl<String> p =
+ (ProducerImpl<String>) client.newProducer(Schema.STRING).producerName("p1").topic(tp).create();
+
+ // Inject a persistence error.
+ org.apache.pulsar.broker.service.Producer serverProducer = pulsar.getBrokerService().getTopic(tp, false)
+ .join().get().getProducers().values().iterator().next();
+ ServerCnx serverCnx = (ServerCnx) serverProducer.getCnx();
+ serverCnx.getCommandSender().sendSendError(serverProducer.getProducerId(), 1/* sequenceId */,
+ ServerError.PersistenceError, "mocked error");
+
+ // Wait for the client receives the error.
+ // If the client confirmed two Pings, it means the client has handled the PersistenceError we sent.
+ serverCnx.checkConnectionLiveness().join();
+ serverCnx.checkConnectionLiveness().join();
+
+ try {
+ // Verify: the next publish will finish.
+ MessageId messageId = p.sendAsync("1").get(10, TimeUnit.SECONDS);
+ MessageIdAdv messageIdAdv = (MessageIdAdv) messageId;
+ log.info("sent {}:{}", messageIdAdv.getLedgerId(), messageIdAdv.getEntryId());
+ } finally {
+ // cleanup orphan producers.
+ serverCnx.ctx().close();
+ // cleanup
+ client.close();
+ p.close();
+ admin.topics().delete(tp);
+ }
+ }
+
public void testSupportsGetPartitionedMetadataWithoutAutoCreation() throws Exception {
final String topic = BrokerTestUtil.newUniqueName( "persistent://" + NAMESPACE + "/tp");
admin.topics().createNonPartitionedTopic(topic);
(pulsar) 07/07: [fix][sec] Upgrade async-http-client to 2.12.4 to address CVE-2024-53990 (#23732)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit c49a2e594660de1929f8e3774ce171f2422369c3
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Mon Dec 16 13:51:28 2024 +0200
[fix][sec] Upgrade async-http-client to 2.12.4 to address CVE-2024-53990 (#23732)
(cherry picked from commit 9a7269a9cf98bd63f45cc48db85b70fb191fb054)
---
distribution/server/src/assemble/LICENSE.bin.txt | 6 +++---
distribution/shell/src/assemble/LICENSE.bin.txt | 6 +++---
pom.xml | 9 +--------
pulsar-broker/pom.xml | 2 +-
pulsar-client-admin-shaded/pom.xml | 2 +-
pulsar-client-admin/pom.xml | 2 +-
pulsar-client-all/pom.xml | 2 +-
pulsar-client-shaded/pom.xml | 2 +-
pulsar-proxy/pom.xml | 2 +-
tiered-storage/jcloud/pom.xml | 2 +-
10 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/distribution/server/src/assemble/LICENSE.bin.txt b/distribution/server/src/assemble/LICENSE.bin.txt
index ae7ffaa7fc9..faea3fee824 100644
--- a/distribution/server/src/assemble/LICENSE.bin.txt
+++ b/distribution/server/src/assemble/LICENSE.bin.txt
@@ -389,8 +389,8 @@ The Apache Software License, Version 2.0
* AirCompressor
- io.airlift-aircompressor-0.27.jar
* AsyncHttpClient
- - org.asynchttpclient-async-http-client-2.12.1.jar
- - org.asynchttpclient-async-http-client-netty-utils-2.12.1.jar
+ - org.asynchttpclient-async-http-client-2.12.4.jar
+ - org.asynchttpclient-async-http-client-netty-utils-2.12.4.jar
* Jetty
- org.eclipse.jetty-jetty-client-9.4.56.v20240826.jar
- org.eclipse.jetty-jetty-continuation-9.4.56.v20240826.jar
@@ -570,7 +570,7 @@ Protocol Buffers License
CDDL-1.1 -- ../licenses/LICENSE-CDDL-1.1.txt
* Java Annotations API
- - com.sun.activation-javax.activation-1.2.0.jar
+ - com.sun.activation-jakarta.activation-1.2.2.jar
* Java Servlet API -- javax.servlet-javax.servlet-api-3.1.0.jar
* WebSocket Server API -- javax.websocket-javax.websocket-client-api-1.0.jar
* HK2 - Dependency Injection Kernel
diff --git a/distribution/shell/src/assemble/LICENSE.bin.txt b/distribution/shell/src/assemble/LICENSE.bin.txt
index 0b3809431df..e4d3771185b 100644
--- a/distribution/shell/src/assemble/LICENSE.bin.txt
+++ b/distribution/shell/src/assemble/LICENSE.bin.txt
@@ -399,8 +399,8 @@ The Apache Software License, Version 2.0
* AirCompressor
- aircompressor-0.27.jar
* AsyncHttpClient
- - async-http-client-2.12.1.jar
- - async-http-client-netty-utils-2.12.1.jar
+ - async-http-client-2.12.4.jar
+ - async-http-client-netty-utils-2.12.4.jar
* Jetty
- jetty-client-9.4.56.v20240826.jar
- jetty-http-9.4.56.v20240826.jar
@@ -431,7 +431,7 @@ MIT License
CDDL-1.1 -- ../licenses/LICENSE-CDDL-1.1.txt
* Java Annotations API
- - javax.activation-1.2.0.jar
+ - jakarta.activation-1.2.2.jar
* WebSocket Server API -- javax.websocket-client-api-1.0.jar
* HK2 - Dependency Injection Kernel
- hk2-api-2.6.1.jar
diff --git a/pom.xml b/pom.xml
index 5c5727bff4e..228bd43d272 100644
--- a/pom.xml
+++ b/pom.xml
@@ -215,7 +215,7 @@ flexible messaging model and an intuitive client API.</description>
<prometheus-jmx.version>0.16.1</prometheus-jmx.version>
<confluent.version>6.2.8</confluent.version>
<aircompressor.version>0.27</aircompressor.version>
- <asynchttpclient.version>2.12.1</asynchttpclient.version>
+ <asynchttpclient.version>2.12.4</asynchttpclient.version>
<commons-lang3.version>3.11</commons-lang3.version>
<commons-configuration.version>1.10</commons-configuration.version>
<commons-io.version>2.18.0</commons-io.version>
@@ -233,7 +233,6 @@ flexible messaging model and an intuitive client API.</description>
<lombok.version>1.18.32</lombok.version>
<jakarta.annotation-api.version>1.3.5</jakarta.annotation-api.version>
<jaxb-api>2.3.1</jaxb-api>
- <javax.activation.version>1.2.0</javax.activation.version>
<jakarta.activation.version>1.2.2</jakarta.activation.version>
<jakarta.xml.bind.version>2.3.3</jakarta.xml.bind.version>
<jakarta.validation.version>2.0.2</jakarta.validation.version>
@@ -1441,12 +1440,6 @@ flexible messaging model and an intuitive client API.</description>
<version>${jakarta.xml.bind.version}</version>
</dependency>
- <dependency>
- <groupId>com.sun.activation</groupId>
- <artifactId>javax.activation</artifactId>
- <version>${javax.activation.version}</version>
- </dependency>
-
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
diff --git a/pulsar-broker/pom.xml b/pulsar-broker/pom.xml
index 5a6d44b99ab..1a9ef465ee8 100644
--- a/pulsar-broker/pom.xml
+++ b/pulsar-broker/pom.xml
@@ -458,7 +458,7 @@
<dependency>
<groupId>com.sun.activation</groupId>
- <artifactId>javax.activation</artifactId>
+ <artifactId>jakarta.activation</artifactId>
</dependency>
<dependency>
diff --git a/pulsar-client-admin-shaded/pom.xml b/pulsar-client-admin-shaded/pom.xml
index a17c973dfad..8c8ce60439d 100644
--- a/pulsar-client-admin-shaded/pom.xml
+++ b/pulsar-client-admin-shaded/pom.xml
@@ -111,7 +111,7 @@
<include>com.google.re2j:re2j</include>
<include>com.spotify:completable-futures</include>
<include>com.squareup.*:*</include>
- <include>com.sun.activation:javax.activation</include>
+ <include>com.sun.activation:jakarta.activation</include>
<include>com.typesafe.netty:netty-reactive-streams</include>
<include>com.yahoo.datasketches:*</include>
<include>com.yahoo.datasketches:sketches-core</include>
diff --git a/pulsar-client-admin/pom.xml b/pulsar-client-admin/pom.xml
index 2b2d1ac1055..02004be12db 100644
--- a/pulsar-client-admin/pom.xml
+++ b/pulsar-client-admin/pom.xml
@@ -87,7 +87,7 @@
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
- <artifactId>javax.activation</artifactId>
+ <artifactId>jakarta.activation</artifactId>
<scope>runtime</scope>
</dependency>
diff --git a/pulsar-client-all/pom.xml b/pulsar-client-all/pom.xml
index 73a7819e607..6fe363d41c5 100644
--- a/pulsar-client-all/pom.xml
+++ b/pulsar-client-all/pom.xml
@@ -152,7 +152,7 @@
<include>com.google.re2j:re2j</include>
<include>com.spotify:completable-futures</include>
<include>com.squareup.*:*</include>
- <include>com.sun.activation:javax.activation</include>
+ <include>com.sun.activation:jakarta.activation</include>
<!-- Avro transitive dependencies -->
<include>com.thoughtworks.paranamer:paranamer</include>
<include>com.typesafe.netty:netty-reactive-streams</include>
diff --git a/pulsar-client-shaded/pom.xml b/pulsar-client-shaded/pom.xml
index 9d93439bd6b..d680a3ae5a9 100644
--- a/pulsar-client-shaded/pom.xml
+++ b/pulsar-client-shaded/pom.xml
@@ -126,7 +126,7 @@
<include>com.google.j2objc:*</include>
<include>com.google.re2j:re2j</include>
<include>com.spotify:completable-futures</include>
- <include>com.sun.activation:javax.activation</include>
+ <include>com.sun.activation:jakarta.activation</include>
<!-- Avro transitive dependencies -->
<include>com.thoughtworks.paranamer:paranamer</include>
<include>com.typesafe.netty:netty-reactive-streams</include>
diff --git a/pulsar-proxy/pom.xml b/pulsar-proxy/pom.xml
index 2268194526c..0fdee383b8d 100644
--- a/pulsar-proxy/pom.xml
+++ b/pulsar-proxy/pom.xml
@@ -140,7 +140,7 @@
<dependency>
<groupId>com.sun.activation</groupId>
- <artifactId>javax.activation</artifactId>
+ <artifactId>jakarta.activation</artifactId>
</dependency>
<dependency>
diff --git a/tiered-storage/jcloud/pom.xml b/tiered-storage/jcloud/pom.xml
index 47ba6b406bb..b71b21abfdd 100644
--- a/tiered-storage/jcloud/pom.xml
+++ b/tiered-storage/jcloud/pom.xml
@@ -117,7 +117,7 @@
<dependency>
<groupId>com.sun.activation</groupId>
- <artifactId>javax.activation</artifactId>
+ <artifactId>jakarta.activation</artifactId>
<scope>runtime</scope>
</dependency>
(pulsar) 03/07: [fix][client] Fix wrong start message id when it's a chunked message id (#23713)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 4201f990224b8d1d9652cfd6ccb81c27d36984f2
Author: Yunze Xu <xy...@163.com>
AuthorDate: Fri Dec 13 14:38:03 2024 +0800
[fix][client] Fix wrong start message id when it's a chunked message id (#23713)
(cherry picked from commit 4606385f4e30392119b813326d493245a3504aac)
---
.../pulsar/client/impl/MessageChunkingTest.java | 25 ++++++++++++++--------
.../apache/pulsar/client/impl/ConsumerImpl.java | 8 ++++++-
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageChunkingTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageChunkingTest.java
index 8df5a38bb46..18ba6a5ab5b 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageChunkingTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessageChunkingTest.java
@@ -561,8 +561,12 @@ public class MessageChunkingTest extends ProducerConsumerBase {
clientBuilder.memoryLimit(10000L, SizeUnit.BYTES);
}
+ interface ThrowingBiConsumer<T, U> {
+ void accept(T t, U u) throws Exception;
+ }
+
@Test
- public void testSeekChunkMessages() throws PulsarClientException {
+ public void testSeekChunkMessages() throws Exception {
log.info("-- Starting {} test --", methodName);
this.conf.setMaxMessageSize(50);
final int totalMessages = 5;
@@ -612,14 +616,17 @@ public class MessageChunkingTest extends ProducerConsumerBase {
assertEquals(msgIds.get(i), msgAfterSeek.getMessageId());
}
- Reader<byte[]> reader = pulsarClient.newReader()
- .topic(topicName)
- .startMessageIdInclusive()
- .startMessageId(msgIds.get(1))
- .create();
-
- Message<byte[]> readMsg = reader.readNext(5, TimeUnit.SECONDS);
- assertEquals(msgIds.get(1), readMsg.getMessageId());
+ ThrowingBiConsumer<Boolean, MessageId> assertStartMessageId = (inclusive, expectedFirstMsgId) -> {
+ final var builder = pulsarClient.newReader().topic(topicName).startMessageId(msgIds.get(1));
+ if (inclusive) {
+ builder.startMessageIdInclusive();
+ }
+ @Cleanup final var reader = builder.create();
+ final var readMsg = reader.readNext(5, TimeUnit.SECONDS);
+ assertEquals(expectedFirstMsgId, readMsg.getMessageId());
+ };
+ assertStartMessageId.accept(true, msgIds.get(1));
+ assertStartMessageId.accept(false, msgIds.get(2));
consumer1.close();
consumer2.close();
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
index d2753856264..e01c6d4643b 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
@@ -298,7 +298,13 @@ public class ConsumerImpl<T> extends ConsumerBase<T> implements ConnectionHandle
this.subscriptionMode = conf.getSubscriptionMode();
if (startMessageId != null) {
MessageIdAdv firstChunkMessageId = ((MessageIdAdv) startMessageId).getFirstChunkMessageId();
- this.startMessageId = (firstChunkMessageId == null) ? (MessageIdAdv) startMessageId : firstChunkMessageId;
+ if (conf.isResetIncludeHead() && firstChunkMessageId != null) {
+ // The chunk message id's ledger id and entry id are the last chunk's ledger id and entry id, when
+ // startMessageIdInclusive() is enabled, we need to start from the first chunk's message id
+ this.startMessageId = firstChunkMessageId;
+ } else {
+ this.startMessageId = (MessageIdAdv) startMessageId;
+ }
}
this.initialStartMessageId = this.startMessageId;
this.startMessageRollbackDurationInSec = startMessageRollbackDurationInSec;
(pulsar) 04/07: [fix][doc] Refine ClientBuilder#memoryLimit and ConsumerBuilder#autoScaledReceiverQueueSizeEnabled javadoc (#23687)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 84d3b2b2a9364a6091d36118d4b830081be70503
Author: Yike Xiao <km...@live.com>
AuthorDate: Sat Dec 14 02:14:15 2024 +0800
[fix][doc] Refine ClientBuilder#memoryLimit and ConsumerBuilder#autoScaledReceiverQueueSizeEnabled javadoc (#23687)
(cherry picked from commit 0845c2163d3a2a118cc9ae3bc80ad97d5eec8a39)
---
.../main/java/org/apache/pulsar/client/api/ClientBuilder.java | 5 ++---
.../main/java/org/apache/pulsar/client/api/ConsumerBuilder.java | 9 ++++++---
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ClientBuilder.java b/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ClientBuilder.java
index 73ad555165c..74b7c084d5a 100644
--- a/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ClientBuilder.java
+++ b/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ClientBuilder.java
@@ -439,9 +439,8 @@ public interface ClientBuilder extends Serializable, Cloneable {
ClientBuilder tlsProtocols(Set<String> tlsProtocols);
/**
- * Configure a limit on the amount of direct memory that will be allocated by this client instance.
- * <p>
- * <b>Note: at this moment this is only limiting the memory for producers.</b>
+ * Configure a limit on the amount of direct memory that will be allocated by this client instance
+ * <i>(default: 64 MB)</i>.
* <p>
* Setting this to 0 will disable the limit.
*
diff --git a/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ConsumerBuilder.java b/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ConsumerBuilder.java
index 4c37b1da927..3ce12b7741a 100644
--- a/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ConsumerBuilder.java
+++ b/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ConsumerBuilder.java
@@ -884,13 +884,16 @@ public interface ConsumerBuilder<T> extends Cloneable {
/**
* If this is enabled, the consumer receiver queue size is initialized as a very small value, 1 by default,
- * and will double itself until it reaches the value set by {@link #receiverQueueSize(int)}, if and only if:
+ * and will double itself until it reaches either the value set by {@link #receiverQueueSize(int)} or the client
+ * memory limit set by {@link ClientBuilder#memoryLimit(long, SizeUnit)}.
+ *
+ * <p>The consumer receiver queue size will double if and only if:
* <p>1) User calls receive() and there are no messages in receiver queue.
* <p>2) The last message we put in the receiver queue took the last space available in receiver queue.
*
- * This is disabled by default and currentReceiverQueueSize is initialized as maxReceiverQueueSize.
+ * <p>This is disabled by default and currentReceiverQueueSize is initialized as maxReceiverQueueSize.
*
- * The feature should be able to reduce client memory usage.
+ * <p>The feature should be able to reduce client memory usage.
*
* @param enabled whether to enable AutoScaledReceiverQueueSize.
*/