|
62 | 62 | public class TieredMessageStore extends AbstractPluginMessageStore { |
63 | 63 |
|
64 | 64 | protected static final Logger log = LoggerFactory.getLogger(MessageStoreUtil.TIERED_STORE_LOGGER_NAME); |
| 65 | + protected static final long MIN_STORE_TIME = -1L; |
65 | 66 |
|
66 | 67 | protected final String brokerName; |
67 | 68 | protected final MessageStore defaultStore; |
@@ -310,24 +311,21 @@ public long getEarliestMessageTime(String topic, int queueId) { |
310 | 311 | return getEarliestMessageTimeAsync(topic, queueId).join(); |
311 | 312 | } |
312 | 313 |
|
| 314 | + /** |
| 315 | + * In the original design, getting the earliest time of the first message |
| 316 | + * would generate two RPC requests. However, using the timestamp stored in the metadata |
| 317 | + * avoids these requests, although this approach might introduce some level of inaccuracy. |
| 318 | + */ |
313 | 319 | @Override |
314 | 320 | public CompletableFuture<Long> getEarliestMessageTimeAsync(String topic, int queueId) { |
315 | | - long nextEarliestMessageTime = next.getEarliestMessageTime(topic, queueId); |
316 | | - long finalNextEarliestMessageTime = nextEarliestMessageTime > 0 ? nextEarliestMessageTime : Long.MAX_VALUE; |
317 | | - Stopwatch stopwatch = Stopwatch.createStarted(); |
| 321 | + long localMinTime = next.getEarliestMessageTime(topic, queueId); |
318 | 322 | return fetcher.getEarliestMessageTimeAsync(topic, queueId) |
319 | | - .thenApply(time -> { |
320 | | - Attributes latencyAttributes = TieredStoreMetricsManager.newAttributesBuilder() |
321 | | - .put(TieredStoreMetricsConstant.LABEL_OPERATION, TieredStoreMetricsConstant.OPERATION_API_GET_EARLIEST_MESSAGE_TIME) |
322 | | - .put(TieredStoreMetricsConstant.LABEL_TOPIC, topic) |
323 | | - .build(); |
324 | | - TieredStoreMetricsManager.apiLatency.record(stopwatch.elapsed(TimeUnit.MILLISECONDS), latencyAttributes); |
325 | | - if (time < 0) { |
326 | | - log.debug("GetEarliestMessageTimeAsync failed, try to get earliest message time from next store: topic: {}, queue: {}", |
327 | | - topic, queueId); |
328 | | - return finalNextEarliestMessageTime != Long.MAX_VALUE ? finalNextEarliestMessageTime : -1; |
| 323 | + .thenApply(remoteMinTime -> { |
| 324 | + if (localMinTime > MIN_STORE_TIME && remoteMinTime > MIN_STORE_TIME) { |
| 325 | + return Math.min(localMinTime, remoteMinTime); |
329 | 326 | } |
330 | | - return Math.min(finalNextEarliestMessageTime, time); |
| 327 | + return localMinTime > MIN_STORE_TIME ? localMinTime : |
| 328 | + (remoteMinTime > MIN_STORE_TIME ? remoteMinTime : MIN_STORE_TIME); |
331 | 329 | }); |
332 | 330 | } |
333 | 331 |
|
|
0 commit comments