Skip to content
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 @@ -1240,6 +1240,10 @@ public CompletableFuture<Long> getEarliestMessagePublishTimeOfPos(PositionImpl p
}
PositionImpl nextPos = getNextValidPosition(pos);

if (nextPos.compareTo(lastConfirmedEntry) > 0) {
return CompletableFuture.completedFuture(-1L);
}

asyncReadEntry(nextPos, new ReadEntryCallback() {
@Override
public void readEntryComplete(Entry entry, Object ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,16 +1160,20 @@ public SubscriptionStatsImpl getStats(Boolean getPreciseBacklog, boolean subscri
} else {
subStats.backlogSize = -1;
}
if (getEarliestTimeInBacklog && subStats.msgBacklog > 0) {
ManagedLedgerImpl managedLedger = ((ManagedLedgerImpl) cursor.getManagedLedger());
PositionImpl markDeletedPosition = (PositionImpl) cursor.getMarkDeletedPosition();
long result = 0;
try {
result = managedLedger.getEarliestMessagePublishTimeOfPos(markDeletedPosition).get();
} catch (InterruptedException | ExecutionException e) {
result = -1;
if (getEarliestTimeInBacklog) {
if (subStats.msgBacklog > 0) {
ManagedLedgerImpl managedLedger = ((ManagedLedgerImpl) cursor.getManagedLedger());
PositionImpl markDeletedPosition = (PositionImpl) cursor.getMarkDeletedPosition();
long result = 0;
try {
result = managedLedger.getEarliestMessagePublishTimeOfPos(markDeletedPosition).get();
} catch (InterruptedException | ExecutionException e) {
result = -1;
}
subStats.earliestMsgPublishTimeInBacklog = result;
} else {
subStats.earliestMsgPublishTimeInBacklog = -1;
}
subStats.earliestMsgPublishTimeInBacklog = result;
}
subStats.msgBacklogNoDelayed = subStats.msgBacklog - subStats.msgDelayed;
subStats.msgRateExpired = expiryMonitor.getMessageExpiryRate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl;
import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.pulsar.broker.BrokerTestUtil;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.admin.AdminApiTest.MockedPulsarService;
Expand Down Expand Up @@ -3191,6 +3192,32 @@ public void testFailedUpdatePartitionedTopic() throws Exception {
assertEquals(admin.topics().getPartitionedTopicMetadata(partitionedTopicName).partitions, newPartitions);
}

/**
* Validate retring failed partitioned topic should succeed.
* @throws Exception
*/
@Test
public void testTopicStatsWithEarliestTimeInBacklogIfNoBacklog() throws Exception {
final String topicName = BrokerTestUtil.newUniqueName("persistent://" + defaultNamespace + "/tp_");
final String subscriptionName = "s1";
admin.topics().createNonPartitionedTopic(topicName);
admin.topics().createSubscription(topicName, subscriptionName, MessageId.earliest);

// Send one message.
Producer<String> producer = pulsarClient.newProducer(Schema.STRING).topic(topicName).enableBatching(false)
.create();
MessageIdImpl messageId = (MessageIdImpl) producer.send("123");
// Catch up.
admin.topics().skipAllMessages(topicName, subscriptionName);
// Get topic stats with earliestTimeInBacklog
TopicStats topicStats = admin.topics().getStats(topicName, false, false, true);
assertEquals(topicStats.getSubscriptions().get(subscriptionName).getEarliestMsgPublishTimeInBacklog(), -1L);

// cleanup.
producer.close();
admin.topics().delete(topicName);
}

@Test(dataProvider = "topicType")
public void testPartitionedStatsAggregationByProducerName(String topicType) throws Exception {
restartClusterIfReused();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ public void testGetStats() throws Exception {
TopicStats topicStats = admin.topics().getStats(topic, false, false, true);

assertEquals(topicStats.getEarliestMsgPublishTimeInBacklogs(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog(), -1);
assertEquals(topicStats.getSubscriptions().get(subName).getBacklogSize(), -1);

// publish several messages
Expand All @@ -1309,7 +1309,7 @@ public void testGetStats() throws Exception {

topicStats = admin.topics().getStats(topic, false, true, true);
assertEquals(topicStats.getEarliestMsgPublishTimeInBacklogs(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog(), 0);
assertEquals(topicStats.getSubscriptions().get(subName).getEarliestMsgPublishTimeInBacklog(), -1);
assertEquals(topicStats.getSubscriptions().get(subName).getBacklogSize(), 0);
}

Expand Down