use rocketmq_common::common::sys_flag::message_sys_flag::MessageSysFlag;
use crate::base::commit_log_dispatcher::CommitLogDispatcher;
use crate::base::dispatch_request::DispatchRequest;
use crate::queue::consume_queue_store::ConsumeQueueStoreInterface;
use crate::queue::local_file_consume_queue_store::ConsumeQueueStore;
pub struct CommitLogDispatcherBuildConsumeQueue {
consume_queue_store: ConsumeQueueStore,
}
impl CommitLogDispatcherBuildConsumeQueue {
pub fn new(consume_queue_store: ConsumeQueueStore) -> Self {
Self { consume_queue_store }
}
}
impl CommitLogDispatcher for CommitLogDispatcherBuildConsumeQueue {
fn dispatch(&self, dispatch_request: &mut DispatchRequest) {
let tran_type = MessageSysFlag::get_transaction_value(dispatch_request.sys_flag);
match tran_type {
MessageSysFlag::TRANSACTION_NOT_TYPE | MessageSysFlag::TRANSACTION_COMMIT_TYPE => {
self.consume_queue_store
.put_message_position_info_wrapper(dispatch_request);
}
_ => {}
}
}
fn dispatch_progress_offset(&self, _commit_log_min_offset: i64) -> Option<i64> {
let offset = self.consume_queue_store.get_max_phy_offset_in_consume_queue_global();
(offset >= 0).then_some(offset)
}
}