GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][broker] Log synchronous and asynchronous message expiry check f… · apache/pulsar@2ea058f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pulsar-broker/src
    • main/java/org/apache/pulsar/broker/service/persistent
      • PersistentTopic.java
    • test/java/org/apache/pulsar/broker/service/persistent
      • PersistentTopicMessageExpiryTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java‎

Copy file name to clipboardExpand all lines: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
+35-6Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,18 +2677,47 @@ public void checkMessageExpiry() {
26772677

26782678
@VisibleForTesting
26792679
void checkMessageExpiryWithoutSharedPosition(int messageTtlInSeconds) {
2680-
subscriptions.forEach((__, sub) -> {
2680+
subscriptions.forEach((subscriptionName, sub) -> {
26812681
// TTL must not advance non-durable reader cursors past unread retained messages.
26822682
if (sub.getCursor().isDurable() && !isCompactionSubscription(sub.getName())
26832683
&& (additionalSystemCursorNames.isEmpty()
26842684
|| !additionalSystemCursorNames.contains(sub.getName()))) {
2685-
sub.expireMessagesAsync(messageTtlInSeconds);
2685+
FutureUtil.supplySafely(() -> sub.expireMessagesAsync(messageTtlInSeconds))
2686+
.whenComplete((ignored, error) -> {
2687+
if (error != null) {
2688+
log.warn()
2689+
.attr("subscription", subscriptionName)
2690+
.attr("messageTTLInSeconds", messageTtlInSeconds)
2691+
.exception(error)
2692+
.log("Failed to start message expiry check");
2693+
}
2694+
});
26862695
}
26872696
});
2688-
replicators.forEach((__, replicator)
2689-
-> ((PersistentReplicator) replicator).expireMessagesAsync(messageTtlInSeconds));
2690-
shadowReplicators.forEach((__, replicator)
2691-
-> ((PersistentReplicator) replicator).expireMessagesAsync(messageTtlInSeconds));
2697+
replicators.forEach((remoteCluster, replicator)
2698+
-> FutureUtil.supplySafely(
2699+
() -> ((PersistentReplicator) replicator).expireMessagesAsync(messageTtlInSeconds))
2700+
.whenComplete((ignored, error) -> {
2701+
if (error != null) {
2702+
log.warn()
2703+
.attr("remoteCluster", remoteCluster)
2704+
.attr("messageTTLInSeconds", messageTtlInSeconds)
2705+
.exception(error)
2706+
.log("Failed to start message expiry check");
2707+
}
2708+
}));
2709+
shadowReplicators.forEach((shadowTopic, replicator)
2710+
-> FutureUtil.supplySafely(
2711+
() -> ((PersistentReplicator) replicator).expireMessagesAsync(messageTtlInSeconds))
2712+
.whenComplete((ignored, error) -> {
2713+
if (error != null) {
2714+
log.warn()
2715+
.attr("shadowTopic", shadowTopic)
2716+
.attr("messageTTLInSeconds", messageTtlInSeconds)
2717+
.exception(error)
2718+
.log("Failed to start message expiry check");
2719+
}
2720+
}));
26922721
}
26932722

26942723
private void checkMessageExpiryWithSharedPosition(ManagedLedgerImpl ml, int messageTtlInSeconds) {
Collapse file

‎pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicMessageExpiryTest.java‎

Copy file name to clipboard
+125Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.broker.service.persistent;
20+
21+
import static org.assertj.core.api.Assertions.assertThatCode;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.verify;
24+
import static org.mockito.Mockito.when;
25+
import java.util.concurrent.RejectedExecutionException;
26+
import org.apache.bookkeeper.mledger.ManagedCursor;
27+
import org.apache.bookkeeper.mledger.ManagedLedger;
28+
import org.apache.pulsar.broker.testcontext.PulsarTestContext;
29+
import org.testng.annotations.AfterMethod;
30+
import org.testng.annotations.BeforeMethod;
31+
import org.testng.annotations.Test;
32+
33+
@Test(groups = "broker")
34+
public class PersistentTopicMessageExpiryTest {
35+
36+
private static final int TTL_SECONDS = 60;
37+
38+
private PulsarTestContext context;
39+
private PersistentTopic topic;
40+
41+
@BeforeMethod(alwaysRun = true)
42+
public void setUp() throws Exception {
43+
context = PulsarTestContext.builderForNonStartableContext().build();
44+
topic = new PersistentTopic(
45+
"persistent://public/default/message-expiry",
46+
context.getBrokerService(),
47+
mock(ManagedLedger.class),
48+
mock(MessageDeduplication.class));
49+
}
50+
51+
@AfterMethod(alwaysRun = true)
52+
public void tearDown() throws Exception {
53+
if (context != null) {
54+
context.close();
55+
context = null;
56+
}
57+
}
58+
59+
@Test
60+
public void testSubscriptionFailureDoesNotStopOtherSubscriptions() {
61+
PersistentSubscription first = mockDurableSubscription("sub-1");
62+
PersistentSubscription second = mockDurableSubscription("sub-2");
63+
var failure = new RejectedExecutionException("Topic executor is shut down");
64+
65+
when(first.expireMessagesAsync(TTL_SECONDS)).thenThrow(failure);
66+
when(second.expireMessagesAsync(TTL_SECONDS)).thenThrow(failure);
67+
topic.getSubscriptions().put("sub-1", first);
68+
topic.getSubscriptions().put("sub-2", second);
69+
70+
assertThatCode(() -> topic.checkMessageExpiryWithoutSharedPosition(TTL_SECONDS))
71+
.as("Subscription failures should not escape the expiry check")
72+
.doesNotThrowAnyException();
73+
74+
verify(first).expireMessagesAsync(TTL_SECONDS);
75+
verify(second).expireMessagesAsync(TTL_SECONDS);
76+
}
77+
78+
@Test
79+
public void testReplicatorFailureDoesNotStopOtherReplicators() {
80+
PersistentReplicator first = mock(PersistentReplicator.class);
81+
PersistentReplicator second = mock(PersistentReplicator.class);
82+
var failure = new RejectedExecutionException("Topic executor is shut down");
83+
84+
when(first.expireMessagesAsync(TTL_SECONDS)).thenThrow(failure);
85+
when(second.expireMessagesAsync(TTL_SECONDS)).thenThrow(failure);
86+
topic.getReplicators().put("cluster-1", first);
87+
topic.getReplicators().put("cluster-2", second);
88+
89+
assertThatCode(() -> topic.checkMessageExpiryWithoutSharedPosition(TTL_SECONDS))
90+
.as("Replicator failures should not escape the expiry check")
91+
.doesNotThrowAnyException();
92+
93+
verify(first).expireMessagesAsync(TTL_SECONDS);
94+
verify(second).expireMessagesAsync(TTL_SECONDS);
95+
}
96+
97+
@Test
98+
public void testShadowReplicatorFailureDoesNotStopOtherShadowReplicators() {
99+
ShadowReplicator first = mock(ShadowReplicator.class);
100+
ShadowReplicator second = mock(ShadowReplicator.class);
101+
var failure = new RejectedExecutionException("Topic executor is shut down");
102+
103+
when(first.expireMessagesAsync(TTL_SECONDS)).thenThrow(failure);
104+
when(second.expireMessagesAsync(TTL_SECONDS)).thenThrow(failure);
105+
topic.getShadowReplicators().put("persistent://public/default/shadow-1", first);
106+
topic.getShadowReplicators().put("persistent://public/default/shadow-2", second);
107+
108+
assertThatCode(() -> topic.checkMessageExpiryWithoutSharedPosition(TTL_SECONDS))
109+
.as("Shadow replicator failures should not escape the expiry check")
110+
.doesNotThrowAnyException();
111+
112+
verify(first).expireMessagesAsync(TTL_SECONDS);
113+
verify(second).expireMessagesAsync(TTL_SECONDS);
114+
}
115+
116+
private PersistentSubscription mockDurableSubscription(String name) {
117+
ManagedCursor cursor = mock(ManagedCursor.class);
118+
when(cursor.isDurable()).thenReturn(true);
119+
120+
PersistentSubscription subscription = mock(PersistentSubscription.class);
121+
when(subscription.getName()).thenReturn(name);
122+
when(subscription.getCursor()).thenReturn(cursor);
123+
return subscription;
124+
}
125+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.