15
15
* limitations under the License.
16
16
*/
17
17
18
- use std:: { cell:: Cell , collections:: HashMap , mem, sync:: Arc } ;
18
+ use std:: {
19
+ cell:: Cell ,
20
+ collections:: HashMap ,
21
+ mem,
22
+ sync:: { atomic:: AtomicU64 , Arc } ,
23
+ } ;
19
24
20
25
use bytes:: { Buf , Bytes , BytesMut } ;
21
26
use rocketmq_common:: {
@@ -167,6 +172,7 @@ pub struct CommitLog {
167
172
consume_queue_store : ConsumeQueueStore ,
168
173
flush_manager : Arc < tokio:: sync:: Mutex < DefaultFlushManager > > ,
169
174
//flush_manager: Arc<parking_lot::Mutex<DefaultFlushManager>>,
175
+ begin_time_in_lock : Arc < AtomicU64 > ,
170
176
}
171
177
172
178
impl CommitLog {
@@ -203,11 +209,7 @@ impl CommitLog {
203
209
mapped_file_queue,
204
210
store_checkpoint,
205
211
) ) ) ,
206
- /*flush_manager: Arc::new(parking_lot::Mutex::new(DefaultFlushManager::new(
207
- message_store_config,
208
- mapped_file_queue,
209
- store_checkpoint,
210
- ))),*/
212
+ begin_time_in_lock : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
211
213
}
212
214
}
213
215
}
@@ -319,6 +321,10 @@ impl CommitLog {
319
321
msg. encoded_buff = Some ( encoded_buff) ;
320
322
let put_message_context = PutMessageContext :: new ( topic_queue_key) ;
321
323
let lock = self . put_message_lock . lock ( ) . await ;
324
+ self . begin_time_in_lock . store (
325
+ time_utils:: get_current_millis ( ) ,
326
+ std:: sync:: atomic:: Ordering :: Release ,
327
+ ) ;
322
328
let start_time = Instant :: now ( ) ;
323
329
// Here settings are stored timestamp, in order to ensure an orderly global
324
330
if !self . message_store_config . duplication_enable {
@@ -333,6 +339,13 @@ impl CommitLog {
333
339
334
340
if mapped_file. is_none ( ) {
335
341
drop ( lock) ;
342
+ error ! (
343
+ "create mapped file error, topic: {} clientAddr: {}" ,
344
+ msg. topic( ) ,
345
+ msg. born_host( )
346
+ ) ;
347
+ self . begin_time_in_lock
348
+ . store ( 0 , std:: sync:: atomic:: Ordering :: Release ) ;
336
349
return PutMessageResult :: new_default ( PutMessageStatus :: CreateMappedFileFailed ) ;
337
350
}
338
351
@@ -353,6 +366,8 @@ impl CommitLog {
353
366
. mapped_file_queue
354
367
. get_last_mapped_file_mut_start_offset ( 0 , true ) ;
355
368
if mapped_file. is_none ( ) {
369
+ self . begin_time_in_lock
370
+ . store ( 0 , std:: sync:: atomic:: Ordering :: Release ) ;
356
371
error ! (
357
372
"create mapped file error, topic: {} clientAddr: {}" ,
358
373
msg. topic( ) ,
@@ -379,15 +394,21 @@ impl CommitLog {
379
394
}
380
395
AppendMessageStatus :: MessageSizeExceeded
381
396
| AppendMessageStatus :: PropertiesSizeExceeded => {
397
+ self . begin_time_in_lock
398
+ . store ( 0 , std:: sync:: atomic:: Ordering :: Release ) ;
382
399
PutMessageResult :: new_append_result ( PutMessageStatus :: MessageIllegal , Some ( result) )
383
400
}
384
401
AppendMessageStatus :: UnknownError => {
402
+ self . begin_time_in_lock
403
+ . store ( 0 , std:: sync:: atomic:: Ordering :: Release ) ;
385
404
PutMessageResult :: new_append_result ( PutMessageStatus :: UnknownError , Some ( result) )
386
405
}
387
406
} ;
388
407
let elapsed_time_in_lock = start_time. elapsed ( ) . as_millis ( ) as u64 ;
389
408
drop ( lock) ;
390
- if elapsed_time_in_lock > 100 {
409
+ self . begin_time_in_lock
410
+ . store ( 0 , std:: sync:: atomic:: Ordering :: Release ) ;
411
+ if elapsed_time_in_lock > 500 {
391
412
warn ! (
392
413
"[NOTIFYME]putMessage in lock cost time(ms)={}, bodyLength={} \
393
414
AppendMessageResult={:?}",
@@ -873,6 +894,10 @@ impl CommitLog {
873
894
pub fn check_self ( & self ) {
874
895
self . mapped_file_queue . check_self ( ) ;
875
896
}
897
+
898
+ pub fn begin_time_in_lock ( & self ) -> & Arc < AtomicU64 > {
899
+ & self . begin_time_in_lock
900
+ }
876
901
}
877
902
878
903
pub fn check_message_and_return_size (
0 commit comments