16
16
*/
17
17
use std:: { collections:: HashMap , sync:: Arc } ;
18
18
19
- use bytes:: { Bytes , BytesMut } ;
19
+ use bytes:: { BufMut , Bytes , BytesMut } ;
20
20
use rocketmq_common:: {
21
21
common:: {
22
22
attribute:: cq_type:: CQType ,
@@ -36,7 +36,7 @@ use crate::{
36
36
} ,
37
37
config:: message_store_config:: MessageStoreConfig ,
38
38
log_file:: {
39
- commit_log:: { CommitLog , CRC32_RESERVED_LEN } ,
39
+ commit_log:: { CommitLog , BLANK_MAGIC_CODE , CRC32_RESERVED_LEN } ,
40
40
mapped_file:: MappedFile ,
41
41
} ,
42
42
} ;
@@ -101,7 +101,7 @@ pub trait AppendMessageCallback {
101
101
const END_FILE_MIN_BLANK_LENGTH : i32 = 4 + 4 ;
102
102
103
103
pub ( crate ) struct DefaultAppendMessageCallback {
104
- msg_store_item_memory : bytes:: BytesMut ,
104
+ // msg_store_item_memory: bytes::BytesMut,
105
105
crc32_reserved_length : i32 ,
106
106
message_store_config : Arc < MessageStoreConfig > ,
107
107
topic_config_table : Arc < parking_lot:: Mutex < HashMap < String , TopicConfig > > > ,
@@ -113,9 +113,9 @@ impl DefaultAppendMessageCallback {
113
113
topic_config_table : Arc < parking_lot:: Mutex < HashMap < String , TopicConfig > > > ,
114
114
) -> Self {
115
115
Self {
116
- msg_store_item_memory : bytes:: BytesMut :: with_capacity (
116
+ /* msg_store_item_memory: bytes::BytesMut::with_capacity(
117
117
END_FILE_MIN_BLANK_LENGTH as usize,
118
- ) ,
118
+ ),*/
119
119
crc32_reserved_length : CRC32_RESERVED_LEN ,
120
120
message_store_config,
121
121
topic_config_table,
@@ -178,42 +178,38 @@ impl AppendMessageCallback for DefaultAppendMessageCallback {
178
178
match MessageSysFlag :: get_transaction_value ( msg_inner. sys_flag ( ) ) {
179
179
MessageSysFlag :: TRANSACTION_PREPARED_TYPE
180
180
| MessageSysFlag :: TRANSACTION_ROLLBACK_TYPE => queue_offset = 0 ,
181
- // MessageSysFlag::TRANSACTION_NOT_TYPE | MessageSysFlag::TRANSACTION_COMMIT_TYPE | _ =>
182
- // {}
183
181
_ => { }
184
182
}
185
183
186
184
if ( msg_len + END_FILE_MIN_BLANK_LENGTH ) > max_blank {
187
- /*self.msg_store_item_memory.borrow_mut().clear();
188
- self.msg_store_item_memory.borrow_mut().put_i32(max_blank);
189
- self.msg_store_item_memory
190
- .borrow_mut()
191
- .put_i32(BLANK_MAGIC_CODE);
192
- let bytes = self.msg_store_item_memory.borrow_mut().split().freeze();
193
- mapped_file.append_message_bytes(&bytes);*/
185
+ let mut bytes = BytesMut :: with_capacity ( END_FILE_MIN_BLANK_LENGTH as usize ) ;
186
+ bytes. put_i32 ( max_blank) ;
187
+ bytes. put_i32 ( BLANK_MAGIC_CODE ) ;
188
+ mapped_file. append_message_bytes ( & bytes. freeze ( ) ) ;
194
189
return AppendMessageResult {
195
190
status : AppendMessageStatus :: EndOfFile ,
196
191
wrote_offset,
197
192
wrote_bytes : max_blank,
198
193
msg_id,
199
194
store_timestamp : msg_inner. store_timestamp ( ) ,
200
195
logics_offset : queue_offset,
196
+ msg_num : message_num as i32 ,
201
197
..Default :: default ( )
202
198
} ;
203
199
}
204
200
205
201
let mut pos = 4 + 4 + 4 + 4 + 4 ;
206
- pre_encode_buffer[ pos..( pos + 8 ) ] . copy_from_slice ( & queue_offset. to_le_bytes ( ) ) ;
202
+ pre_encode_buffer[ pos..( pos + 8 ) ] . copy_from_slice ( & queue_offset. to_be_bytes ( ) ) ;
207
203
pos += 8 ;
208
- pre_encode_buffer[ pos..( pos + 8 ) ] . copy_from_slice ( & wrote_offset. to_le_bytes ( ) ) ;
204
+ pre_encode_buffer[ pos..( pos + 8 ) ] . copy_from_slice ( & wrote_offset. to_be_bytes ( ) ) ;
209
205
let ip_len = if msg_inner. sys_flag ( ) & MessageSysFlag :: BORNHOST_V6_FLAG == 0 {
210
206
4 + 4
211
207
} else {
212
208
16 + 4
213
209
} ;
214
210
pos += 8 + 4 + 8 + ip_len;
215
211
pre_encode_buffer[ pos..( pos + 8 ) ]
216
- . copy_from_slice ( & msg_inner. store_timestamp ( ) . to_le_bytes ( ) ) ;
212
+ . copy_from_slice ( & msg_inner. store_timestamp ( ) . to_be_bytes ( ) ) ;
217
213
218
214
// msg_inner.encoded_buff = pre_encode_buffer;
219
215
let bytes = Bytes :: from ( pre_encode_buffer) ;
@@ -225,6 +221,7 @@ impl AppendMessageCallback for DefaultAppendMessageCallback {
225
221
msg_id,
226
222
store_timestamp : msg_inner. store_timestamp ( ) ,
227
223
logics_offset : queue_offset,
224
+ msg_num : message_num as i32 ,
228
225
..Default :: default ( )
229
226
}
230
227
}
0 commit comments