Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #137]🚀Define the rust version of Messagestore based on the Java version of MessageStore #138

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rocketmq-common/src/common/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

mod message_batch;
mod message_id;
mod message_queue;
mod message_single;
pub mod message_batch;
pub mod message_id;
pub mod message_queue;
pub mod message_single;

use std::collections::HashMap;

Expand Down
2 changes: 2 additions & 0 deletions rocketmq-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ description.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocketmq-common = {version = "0.2.0", path = "../rocketmq-common"}

lazy_static.workspace = true

#tools
Expand Down
20 changes: 20 additions & 0 deletions rocketmq-store/src/base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pub mod message_result;
pub mod message_status_enum;
pub mod select_result;
82 changes: 82 additions & 0 deletions rocketmq-store/src/base/message_result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use std::{cell::RefCell, rc::Rc};

use crate::base::{
message_status_enum::{AppendMessageStatus, GetMessageStatus, PutMessageStatus},
select_result::SelectMappedBufferResult,
};

/// Represents the result of an append message operation.
pub struct AppendMessageResult {
/// Return code.
pub status: AppendMessageStatus,
/// Where to start writing.
pub wrote_offset: i64,
/// Write Bytes.
pub wrote_bytes: i32,
/// Message ID.
pub msg_id: String,
/// Message ID supplier.
pub msg_id_supplier: Option<Rc<RefCell<dyn Fn() -> String>>>,
/// Message storage timestamp.
pub store_timestamp: i64,
/// Consume queue's offset (step by one).
pub logics_offset: i64,
/// Page cache RT.
pub page_cache_rt: i64,
/// Message number.
pub msg_num: i32,
}

pub struct PutMessageResult {
pub put_message_status: PutMessageStatus,
pub append_message_result: AppendMessageResult,
pub remote_put: bool,
}

/// Represents the result of getting a message.
pub struct GetMessageResult {
/// The list of mapped buffer results.
pub message_mapped_list: Vec<SelectMappedBufferResult>,
/// The list of message buffers.
pub message_buffer_list: Vec<Vec<u8>>, /* Using Vec<u8> as a simplified representation of
* ByteBuffer in Rust */
/// The list of message queue offsets.
pub message_queue_offset: Vec<i64>,
/// The status of getting the message.
pub status: GetMessageStatus,
/// The next begin offset.
pub next_begin_offset: i64,
/// The minimum offset.
pub min_offset: i64,
/// The maximum offset.
pub max_offset: i64,
/// The total size of buffers.
pub buffer_total_size: i32,
/// The count of messages.
pub message_count: i32,
/// Indicates whether pulling from a slave is suggested.
pub suggest_pulling_from_slave: bool,
/// The count of messages for commercial purposes.
pub msg_count4_commercial: i32,
/// The size per message for commercial purposes.
pub commercial_size_per_msg: i32,
/// The sum of cold data.
pub cold_data_sum: i64,
}
70 changes: 70 additions & 0 deletions rocketmq-store/src/base/message_status_enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
pub enum AppendMessageStatus {
PutOk,
EndOfFile,
MessageSizeExceeded,
PropertiesSizeExceeded,
UnknownError,
}

#[derive(Debug)]
pub enum PutMessageStatus {
PutOk,
FlushDiskTimeout,
FlushSlaveTimeout,
SlaveNotAvailable,
ServiceNotAvailable,
CreateMappedFileFailed,
MessageIllegal,
PropertiesSizeExceeded,
OsPageCacheBusy,
UnknownError,
InSyncReplicasNotEnough,
PutToRemoteBrokerFail,
LmqConsumeQueueNumExceeded,
WheelTimerFlowControl,
WheelTimerMsgIllegal,
WheelTimerNotEnable,
}

impl std::fmt::Display for PutMessageStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#[derive(Debug)]
pub enum GetMessageStatus {
Found,
NoMatchedMessage,
MessageWasRemoving,
OffsetFoundNull,
OffsetOverflowBadly,
OffsetOverflowOne,
OffsetTooSmall,
NoMatchedLogicQueue,
NoMessageInQueue,
OffsetReset,
}

impl std::fmt::Display for GetMessageStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
34 changes: 34 additions & 0 deletions rocketmq-store/src/base/select_result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use std::{cell::RefCell, sync::Arc};

use crate::log_file::mapped_file::MappedFile;

/// Represents the result of selecting a mapped buffer.
pub struct SelectMappedBufferResult {
/// The start offset.
pub start_offset: i64,
/// The ByteBuffer.
pub byte_buffer: Vec<u8>, // Using Vec<u8> as a simplified representation of ByteBuffer in Rust
/// The size.
pub size: i32,
/// The mapped file.
pub mapped_file: Option<Arc<RefCell<dyn MappedFile>>>,
/// Indicates whether the buffer is in the cache.
pub is_in_cache: bool,
}
18 changes: 18 additions & 0 deletions rocketmq-store/src/consume_queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pub(crate) mod consume_queue_ext;
18 changes: 18 additions & 0 deletions rocketmq-store/src/consume_queue/consume_queue_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pub struct ConsumeQueueExtCqExtUnit {}
41 changes: 41 additions & 0 deletions rocketmq-store/src/filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use std::collections::HashMap;

use crate::consume_queue::consume_queue_ext::ConsumeQueueExtCqExtUnit;

/// Represents a message filter.
pub trait MessageFilter {
/// Matches by tags code or filter bit map which is calculated when the message is received
/// and stored in consume queue ext.
fn is_matched_by_consume_queue(
&self,
tags_code: Option<i64>,
cq_ext_unit: Option<&ConsumeQueueExtCqExtUnit>,
) -> bool;

/// Matches by message content which is stored in the commit log.
///
/// `msg_buffer`: Message buffer in the commit log, may be `None` if not invoked in store.
/// `properties`: Message properties, should be decoded from the buffer if `None`.
fn is_matched_by_commit_log(
&self,
msg_buffer: Option<&Vec<u8>>,
properties: Option<&HashMap<String, String>>,
) -> bool;
}
4 changes: 4 additions & 0 deletions rocketmq-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
*/
#![allow(dead_code)]

mod base;
mod config;
mod consume_queue;
mod filter;
mod log_file;
Loading
Loading