Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker]Support setting autoSkipNonRecoverableData dynamically in expiryMon… #21991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.pulsar.broker.service.persistent;

import com.google.common.annotations.VisibleForTesting;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
Expand Down Expand Up @@ -48,7 +49,6 @@ public class PersistentMessageExpiryMonitor implements FindEntryCallback, Messag
private final String topicName;
private final Rate msgExpired;
private final LongAdder totalMsgExpired;
private final boolean autoSkipNonRecoverableData;
private final PersistentSubscription subscription;

private static final int FALSE = 0;
Expand All @@ -68,8 +68,12 @@ public PersistentMessageExpiryMonitor(PersistentTopic topic, String subscription
this.subscription = subscription;
this.msgExpired = new Rate();
this.totalMsgExpired = new LongAdder();
}

@VisibleForTesting
public boolean isAutoSkipNonRecoverableData() {
// check to avoid test failures
this.autoSkipNonRecoverableData = this.cursor.getManagedLedger() != null
return this.cursor.getManagedLedger() != null
&& this.cursor.getManagedLedger().getConfig().isAutoSkipNonRecoverableData();
}

Expand Down Expand Up @@ -196,7 +200,7 @@ public void findEntryFailed(ManagedLedgerException exception, Optional<Position>
if (log.isDebugEnabled()) {
log.debug("[{}][{}] Finding expired entry operation failed", topicName, subName, exception);
}
if (autoSkipNonRecoverableData && failedReadPosition.isPresent()
if (isAutoSkipNonRecoverableData() && failedReadPosition.isPresent()
&& (exception instanceof NonRecoverableLedgerException)) {
log.warn("[{}][{}] read failed from ledger at position:{} : {}", topicName, subName, failedReadPosition,
exception.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,30 @@ public void testCheckPersistencePolicies() throws Exception {
assertEquals(persistentTopic.getManagedLedger().getConfig().getRetentionSizeInMB(), 1L);
assertEquals(persistentTopic.getManagedLedger().getConfig().getRetentionTimeMillis(), TimeUnit.MINUTES.toMillis(1));
}

@Test
public void testDynamicConfigurationAutoSkipNonRecoverableData() throws Exception {
pulsar.getConfiguration().setAutoSkipNonRecoverableData(false);
final String topicName = "persistent://prop/ns-abc/testAutoSkipNonRecoverableData";
final String subName = "test_sub";

Consumer<byte[]> subscribe = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscribe();
PersistentTopic persistentTopic =
(PersistentTopic) pulsar.getBrokerService().getTopic(topicName, false).join().get();
PersistentSubscription subscription = persistentTopic.getSubscription(subName);

assertFalse(persistentTopic.ledger.getConfig().isAutoSkipNonRecoverableData());
assertFalse(subscription.getExpiryMonitor().isAutoSkipNonRecoverableData());

String key = "autoSkipNonRecoverableData";
admin.brokers().updateDynamicConfiguration(key, "true");
Awaitility.await()
.untilAsserted(() -> assertEquals(admin.brokers().getAllDynamicConfigurations().get(key), "true"));

assertTrue(persistentTopic.ledger.getConfig().isAutoSkipNonRecoverableData());
assertTrue(subscription.getExpiryMonitor().isAutoSkipNonRecoverableData());

subscribe.close();
admin.topics().delete(topicName);
}
}
Loading