use std::collections::HashMap;
use std::error::Error;
use std::sync::Arc;
use cheetah_string::CheetahString;
use parking_lot::RwLock;
use rocketmq_common::common::message::message_batch::MessageExtBatch;
use rocketmq_common::common::message::message_ext::MessageExt;
use rocketmq_common::common::message::message_ext_broker_inner::MessageExtBrokerInner;
use rocketmq_common::TimeUtils::get_current_millis;
use crate::base::dispatch_request::DispatchRequest;
use crate::base::get_message_result::GetMessageResult;
use crate::base::message_result::PutMessageResult;
use crate::base::query_message_result::QueryMessageResult;
use crate::base::select_result::SelectMappedBufferResult;
use crate::config::message_store_config::MessageStoreConfig;
use crate::filter::MessageFilter;
use crate::hook::put_message_hook::BoxedPutMessageHook;
use crate::queue::ArcConsumeQueue;
use crate::stats::broker_stats_manager::BrokerStatsManager;
use crate::store::running_flags::RunningFlags;
use crate::timer::timer_message_store::TimerMessageStore;
pub(crate) mod cold_data_check_service;
pub mod commit_log;
pub mod flush_manager_impl;
pub mod mapped_file;
pub const MAX_PULL_MSG_SIZE: i32 = 128 * 1024 * 1024;
#[trait_variant::make(MessageStore: Send)]
pub trait RocketMQMessageStore: Sync + 'static {
async fn load(&mut self) -> bool;
fn start(&mut self) -> Result<(), Box<dyn Error>>;
fn shutdown(&mut self);
fn set_confirm_offset(&mut self, phy_offset: i64);
fn get_max_phy_offset(&self) -> i64;
fn set_broker_init_max_offset(&mut self, broker_init_max_offset: i64);
#[inline]
fn now(&self) -> u64 {
get_current_millis()
}
fn get_state_machine_version(&self) -> i64;
async fn put_message(&mut self, msg: MessageExtBrokerInner) -> PutMessageResult;
async fn put_messages(&mut self, msg_batch: MessageExtBatch) -> PutMessageResult;
fn truncate_files(&mut self, offset_to_truncate: i64) -> bool;
fn is_os_page_cache_busy(&self) -> bool {
false
}
fn get_running_flags(&self) -> &RunningFlags;
fn is_shutdown(&self) -> bool;
fn get_put_message_hook_list(&self) -> Arc<RwLock<Vec<BoxedPutMessageHook>>>;
fn set_put_message_hook(&self, put_message_hook: BoxedPutMessageHook);
fn get_broker_stats_manager(&self) -> Option<Arc<BrokerStatsManager>>;
fn dispatch_behind_bytes(&self) -> i64;
fn get_min_offset_in_queue(&self, topic: &CheetahString, queue_id: i32) -> i64;
fn get_max_offset_in_queue(&self, topic: &CheetahString, queue_id: i32) -> i64;
fn get_max_offset_in_queue_committed(
&self,
topic: &CheetahString,
queue_id: i32,
committed: bool,
) -> i64;
async fn get_message(
&self,
group: &CheetahString,
topic: &CheetahString,
queue_id: i32,
offset: i64,
max_msg_nums: i32,
message_filter: Option<Arc<Box<dyn MessageFilter>>>,
) -> Option<GetMessageResult>;
async fn get_message_with_total_size(
&self,
group: &CheetahString,
topic: &CheetahString,
queue_id: i32,
offset: i64,
max_msg_nums: i32,
max_total_msg_size: i32,
message_filter: Option<Arc<Box<dyn MessageFilter>>>,
) -> Option<GetMessageResult>;
fn check_in_mem_by_consume_offset(
&self,
topic: &CheetahString,
queue_id: i32,
consume_offset: i64,
batch_size: i32,
) -> bool;
fn notify_message_arrive_if_necessary(&self, dispatch_request: &mut DispatchRequest);
fn find_consume_queue(&self, topic: &CheetahString, queue_id: i32) -> Option<ArcConsumeQueue>;
fn delete_topics(&mut self, delete_topics: Vec<&CheetahString>) -> i32;
async fn query_message(
&self,
topic: &CheetahString,
key: &CheetahString,
max_num: i32,
begin_timestamp: i64,
end_timestamp: i64,
) -> Option<QueryMessageResult>;
async fn select_one_message_by_offset(
&self,
commit_log_offset: i64,
) -> Option<SelectMappedBufferResult>;
async fn select_one_message_by_offset_with_size(
&self,
commit_log_offset: i64,
size: i32,
) -> Option<SelectMappedBufferResult>;
fn look_message_by_offset(&self, commit_log_offset: i64) -> Option<MessageExt>;
fn look_message_by_offset_with_size(
&self,
commit_log_offset: i64,
size: i32,
) -> Option<MessageExt>;
fn get_message_store_timestamp(
&self,
topic: &CheetahString,
queue_id: i32,
consume_queue_offset: i64,
) -> i64;
fn get_runtime_info(&self) -> HashMap<String, String>;
fn lock_time_mills(&self) -> i64;
fn get_earliest_message_time(&self) -> i64;
fn get_timer_message_store(&self) -> Arc<TimerMessageStore>;
fn set_timer_message_store(&mut self, timer_message_store: Arc<TimerMessageStore>);
fn remain_transient_store_buffer_nums(&self) -> i32;
fn remain_how_many_data_to_commit(&self) -> i64;
fn remain_how_many_data_to_flush(&self) -> i64;
fn get_message_store_config(&self) -> &MessageStoreConfig;
}