|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.rocketmq.broker.pop.orderly; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | +import java.util.concurrent.CompletableFuture; |
| 21 | +import org.apache.rocketmq.common.OrderedConsumptionLevel; |
| 22 | +import org.apache.rocketmq.store.GetMessageResult; |
| 23 | + |
| 24 | +/** |
| 25 | + * |
| 26 | + * Ordered Consumption Controller Interface |
| 27 | + * This is the top-level interface that encapsulates complete ordered consumption management functionality, |
| 28 | + * supporting different concurrency strategy implementations |
| 29 | + * <p> |
| 30 | + * Design Goals: |
| 31 | + * 1. Support queue-level ordered consumption (existing implementation) |
| 32 | + * 2. Support message group-level ordered consumption (improve concurrency) |
| 33 | + * 3. Support custom ordered consumption strategies |
| 34 | + * </p> |
| 35 | + */ |
| 36 | +public interface ConsumerOrderInfoManager { |
| 37 | + |
| 38 | + /** |
| 39 | + * Update the reception status of message list |
| 40 | + * Called by handleGetMessageResult when consumer POPs messages, used to record message status and build consumption information |
| 41 | + * |
| 42 | + * @param attemptId Distinguish different pop requests |
| 43 | + * @param isRetry Whether it is a retry topic |
| 44 | + * @param topic Topic name |
| 45 | + * @param group Consumer group name |
| 46 | + * @param queueId Queue ID |
| 47 | + * @param popTime Time when messages are popped |
| 48 | + * @param invisibleTime Message invisible time |
| 49 | + * @param msgQueueOffsetList List of message queue offsets |
| 50 | + * @param orderInfoBuilder String builder for constructing order information |
| 51 | + * @param getMessageResult Return new result |
| 52 | + */ |
| 53 | + void update(String attemptId, boolean isRetry, String topic, String group, int queueId, |
| 54 | + long popTime, long invisibleTime, List<Long> msgQueueOffsetList, |
| 55 | + StringBuilder orderInfoBuilder, GetMessageResult getMessageResult); |
| 56 | + |
| 57 | + /** |
| 58 | + * Check whether the current POP request needs to be blocked |
| 59 | + * Used to ensure ordered consumption of ordered messages |
| 60 | + * Called when consumer POPs messages |
| 61 | + * |
| 62 | + * @param attemptId Attempt ID |
| 63 | + * @param topic Topic name |
| 64 | + * @param group Consumer group name |
| 65 | + * @param queueId Queue ID |
| 66 | + * @param invisibleTime Invisible time |
| 67 | + * @return true indicates blocking is needed, false indicates can proceed |
| 68 | + */ |
| 69 | + boolean checkBlock(String attemptId, String topic, String group, int queueId, long invisibleTime); |
| 70 | + |
| 71 | + /** |
| 72 | + * Commit message and calculate next consumption offset |
| 73 | + * Called when consumer ACKs messages |
| 74 | + * |
| 75 | + * @param topic Topic name |
| 76 | + * @param group Consumer group name |
| 77 | + * @param queueId Queue ID |
| 78 | + * @param queueOffset Message queue offset |
| 79 | + * @param popTime Pop time, used for validation |
| 80 | + * @return -1: invalid, -2: no need to commit, >=0: offset that needs to be committed (indicates messages below this offset have been consumed) |
| 81 | + */ |
| 82 | + long commitAndNext(String topic, String group, int queueId, long queueOffset, long popTime); |
| 83 | + |
| 84 | + /** |
| 85 | + * Update the next visible time of message |
| 86 | + * Used for delayed message re-consumption |
| 87 | + * |
| 88 | + * @param topic Topic name |
| 89 | + * @param group Consumer group name |
| 90 | + * @param queueId Queue ID |
| 91 | + * @param queueOffset Message offset |
| 92 | + * @param popTime Pop time, used for validation |
| 93 | + * @param nextVisibleTime Next visible time |
| 94 | + */ |
| 95 | + void updateNextVisibleTime(String topic, String group, int queueId, long queueOffset, |
| 96 | + long popTime, long nextVisibleTime); |
| 97 | + |
| 98 | + /** |
| 99 | + * Clear the blocking status of specified queue |
| 100 | + * Usually called during consumer rebalancing or queue reassignment |
| 101 | + * |
| 102 | + * @param topic Topic name |
| 103 | + * @param group Consumer group name |
| 104 | + * @param queueId Queue ID |
| 105 | + */ |
| 106 | + void clearBlock(String topic, String group, int queueId); |
| 107 | + |
| 108 | + /** |
| 109 | + * Get ordered consumption level |
| 110 | + * Used to distinguish different implementation strategies |
| 111 | + * |
| 112 | + * @return Ordered consumption level, such as: QUEUE, MESSAGE_GROUP, etc. |
| 113 | + */ |
| 114 | + OrderedConsumptionLevel getOrderedConsumptionLevel(); |
| 115 | + |
| 116 | + /** |
| 117 | + * Start the controller |
| 118 | + * Initialize necessary resources, such as timers, thread pools, etc. |
| 119 | + */ |
| 120 | + void start(); |
| 121 | + |
| 122 | + /** |
| 123 | + * Shutdown the controller |
| 124 | + * Release resources, clean up scheduled tasks, etc. |
| 125 | + */ |
| 126 | + void shutdown(); |
| 127 | + |
| 128 | + /** |
| 129 | + * Persist the controller |
| 130 | + * Persist the controller's data |
| 131 | + */ |
| 132 | + void persist(); |
| 133 | + |
| 134 | + boolean load(); |
| 135 | + |
| 136 | + /** |
| 137 | + * Get available message result |
| 138 | + * Used to retrieve messages from cache |
| 139 | + */ |
| 140 | + CompletableFuture<GetMessageResult> getAvailableMessageResult(String attemptId, long popTime, long invisibleTime, String groupId, |
| 141 | + String topicId, int queueId, int batchSize, StringBuilder orderCountInfoBuilder); |
| 142 | +} |
0 commit comments