LeBW commented on a change in pull request #12523:
URL: https://github.com/apache/pulsar/pull/12523#discussion_r743604270
##########
File path:
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -1141,6 +1144,53 @@ public long getEstimatedBacklogSize() {
}
}
+ @Override
+ public long getEarliestMessagePublishTimeInBacklog() {
+ PositionImpl pos = getMarkDeletePositionOfSlowestConsumer();
+
+ return getEarliestMessagePublishTimeOfPos(pos);
+ }
+
+ public long getEarliestMessagePublishTimeOfPos(PositionImpl pos) {
+ if (pos == null) {
+ return 0L;
+ }
+ PositionImpl nextPos = getNextValidPosition(pos);
+
+ CompletableFuture<Long> future = new CompletableFuture<>();
+ asyncReadEntry(nextPos, new ReadEntryCallback() {
+ @Override
+ public void readEntryComplete(Entry entry, Object ctx) {
+ ByteBuf metadataAndPayload = entry.getDataBuffer();
+ BrokerEntryMetadata brokerEntryMetadata =
Commands.parseBrokerEntryMetadataIfExist(metadataAndPayload);
+ if (brokerEntryMetadata != null &&
brokerEntryMetadata.hasBrokerTimestamp()) {
+ future.complete(brokerEntryMetadata.getBrokerTimestamp());
+ } else {
+ MessageMetadata messageMetadata =
Commands.parseMessageMetadata(metadataAndPayload);
+ if (messageMetadata.hasPublishTime()) {
+ future.complete(messageMetadata.getPublishTime());
+ } else {
+ future.complete(0L);
+ }
+ }
+ }
+
+ @Override
+ public void readEntryFailed(ManagedLedgerException exception,
Object ctx) {
+ future.completeExceptionally(exception);
+ }
+ }, null);
+
+ long result;
+ try {
+ result = future.get();
Review comment:
Even if we return a `Future` here, maybe we still need to wait the entry
read somewhere else (which will also block the request thread) ?
##########
File path:
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
##########
@@ -563,10 +563,14 @@ void run() throws PulsarAdminException {
+ ", locking required.")
private boolean subscriptionBacklogSize = false;
+ @Parameter(names = { "-etb",
+ "--get-earliest-time-in-backlog" }, description = "Set true to
get earliest time in backlog")
Review comment:
Can `--get-backlog-in-mills` reflect that it will get a timestamp? Maybe
it's a little confusing as it looks like getting the backlog itself. (It's just
my question and I can still change it to `--get-backlog-in-mills`)
##########
File path:
pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/Topics.java
##########
@@ -856,8 +858,13 @@ default void delete(String topic, boolean force) throws
PulsarAdminException {
* @throws PulsarAdminException
* Unexpected error
*/
- TopicStats getStats(String topic, boolean getPreciseBacklog,
- boolean subscriptionBacklogSize) throws
PulsarAdminException;
+ TopicStats getStats(String topic, boolean getPreciseBacklog, boolean
subscriptionBacklogSize,
Review comment:
Maybe the method below (Line 864 - 866) can resolve the compatibility
issue because it's the original API with the `getEarliestTimeInBacklog` default
to be `false`?
##########
File path:
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -1141,6 +1144,53 @@ public long getEstimatedBacklogSize() {
}
}
+ @Override
+ public long getEarliestMessagePublishTimeInBacklog() {
+ PositionImpl pos = getMarkDeletePositionOfSlowestConsumer();
+
+ return getEarliestMessagePublishTimeOfPos(pos);
+ }
+
+ public long getEarliestMessagePublishTimeOfPos(PositionImpl pos) {
+ if (pos == null) {
+ return 0L;
+ }
+ PositionImpl nextPos = getNextValidPosition(pos);
+
+ CompletableFuture<Long> future = new CompletableFuture<>();
+ asyncReadEntry(nextPos, new ReadEntryCallback() {
+ @Override
+ public void readEntryComplete(Entry entry, Object ctx) {
+ ByteBuf metadataAndPayload = entry.getDataBuffer();
+ BrokerEntryMetadata brokerEntryMetadata =
Commands.parseBrokerEntryMetadataIfExist(metadataAndPayload);
+ if (brokerEntryMetadata != null &&
brokerEntryMetadata.hasBrokerTimestamp()) {
+ future.complete(brokerEntryMetadata.getBrokerTimestamp());
+ } else {
+ MessageMetadata messageMetadata =
Commands.parseMessageMetadata(metadataAndPayload);
+ if (messageMetadata.hasPublishTime()) {
+ future.complete(messageMetadata.getPublishTime());
+ } else {
+ future.complete(0L);
+ }
+ }
+ }
+
+ @Override
+ public void readEntryFailed(ManagedLedgerException exception,
Object ctx) {
+ future.completeExceptionally(exception);
+ }
+ }, null);
+
+ long result;
+ try {
+ result = future.get();
Review comment:
Even if we return a `Future` here, maybe we still need to wait the entry
read somewhere else (which will also block the request thread) ?
##########
File path:
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
##########
@@ -563,10 +563,14 @@ void run() throws PulsarAdminException {
+ ", locking required.")
private boolean subscriptionBacklogSize = false;
+ @Parameter(names = { "-etb",
+ "--get-earliest-time-in-backlog" }, description = "Set true to
get earliest time in backlog")
Review comment:
Can `--get-backlog-in-mills` reflect that it will get a timestamp? Maybe
it's a little confusing as it looks like getting the backlog itself. (It's just
my question and I can still change it to `--get-backlog-in-mills`)
##########
File path:
pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/Topics.java
##########
@@ -856,8 +858,13 @@ default void delete(String topic, boolean force) throws
PulsarAdminException {
* @throws PulsarAdminException
* Unexpected error
*/
- TopicStats getStats(String topic, boolean getPreciseBacklog,
- boolean subscriptionBacklogSize) throws
PulsarAdminException;
+ TopicStats getStats(String topic, boolean getPreciseBacklog, boolean
subscriptionBacklogSize,
Review comment:
Maybe the method below (Line 864 - 866) can resolve the compatibility
issue because it's the original API with the `getEarliestTimeInBacklog` default
to be `false`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]