File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -487,14 +487,16 @@ namespace bq {
487487 merged_log_level_bitmap_ = tmp;
488488 }
489489
490- void log_imp::process (bool is_force_flush)
490+ bool log_imp::process (bool is_force_flush)
491491 {
492492 constexpr uint64_t flush_io_min_interval_ms = 100 ;
493493 uint64_t current_epoch_ms = 0 ;
494+ bool did_work = false ;
494495 while (true ) {
495496 auto read_chunk = buffer_->read_chunk ();
496497 scoped_log_buffer_handle<log_buffer> scoped_read_chunk (*buffer_, read_chunk);
497498 if (read_chunk.result == enum_buffer_result_code::success) {
499+ did_work = true ;
498500 bq::log_entry_handle log_item (read_chunk.data_addr , read_chunk.data_size );
499501 current_epoch_ms = log_item.get_log_head ().timestamp_epoch ;
500502 process_log_chunk (log_item);
@@ -514,6 +516,7 @@ namespace bq {
514516 last_flush_io_epoch_ms_ = current_epoch_ms;
515517 }
516518 }
519+ return did_work;
517520 }
518521
519522 void log_imp::sync_process (bool is_force_flush)
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ namespace bq {
7878
7979 bq::string& get_config ();
8080
81- void process (bool is_force_flush);
81+ bool process (bool is_force_flush);
8282
8383 void sync_process (bool is_force_flush);
8484
Original file line number Diff line number Diff line change @@ -160,22 +160,24 @@ namespace bq {
160160 return false ;
161161 }
162162
163- void log_manager::process_by_worker (log_imp* target_log, bool is_force_flush)
163+ bool log_manager::process_by_worker (log_imp* target_log, bool is_force_flush)
164164 {
165165 bq::platform::scoped_spin_lock_read_crazy scoped_lock (logs_lock_);
166166 if (phase::working != phase_.load (bq::platform::memory_order::relaxed)) {
167- return ;
167+ return false ;
168168 }
169+ bool did_work = false ;
169170 if (target_log) {
170- target_log->process (is_force_flush);
171+ did_work = target_log->process (is_force_flush);
171172 } else {
172173 for (decltype (log_imp_list_)::size_type i = 0 ; i < log_imp_list_.size (); ++i) {
173174 auto & log_impl = log_imp_list_[i];
174175 if (log_impl->get_thread_mode () == log_thread_mode::async) {
175- log_imp_list_[i]->process (is_force_flush);
176+ did_work = log_imp_list_[i]->process (is_force_flush) || did_work ;
176177 }
177178 }
178179 }
180+ return did_work;
179181 }
180182
181183 void log_manager::force_flush_all ()
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ namespace bq {
3636
3737 bool reset_config (const bq::string& log_name, const bq::string& config_content);
3838
39- void process_by_worker (log_imp* target_log, bool is_force_flush);
39+ bool process_by_worker (log_imp* target_log, bool is_force_flush);
4040
4141 uint32_t get_logs_count () const ;
4242
Original file line number Diff line number Diff line change @@ -99,7 +99,13 @@ namespace bq {
9999 }
100100 // normal process
101101 else {
102- manager_->process_by_worker ((thread_mode_ == log_thread_mode::async) ? nullptr : log_target_, false );
102+ bool did_work = manager_->process_by_worker ((thread_mode_ == log_thread_mode::async) ? nullptr : log_target_, false );
103+ if (did_work) {
104+ if (is_cancelled ()) {
105+ break ;
106+ }
107+ continue ;
108+ }
103109 }
104110 if (is_cancelled ()) {
105111 break ;
Original file line number Diff line number Diff line change @@ -211,6 +211,11 @@ namespace bq {
211211 handle.data_addr = new_block.chunk_head .data ;
212212 used_blocks_count += need_block_count;
213213 handle.low_space_flag = ((used_blocks_count << 1 ) >= aligned_blocks_count_);
214+ if (handle.low_space_flag ) {
215+ read_cursor_ref = cursors_.read_cursor_ .load_acquire ();
216+ used_blocks_count = static_cast <uint32_t >(current_write_cursor + need_block_count - read_cursor_ref);
217+ handle.low_space_flag = ((used_blocks_count << 1 ) >= aligned_blocks_count_);
218+ }
214219#if defined(BQ_LOG_BUFFER_DEBUG)
215220 ++result_code_statistics_[(int32_t )enum_buffer_result_code::success];
216221#endif
Original file line number Diff line number Diff line change @@ -119,6 +119,11 @@ namespace bq {
119119 new_block.to_chunk_head ().data_size = size;
120120
121121 handle.low_space_flag = ((aligned_blocks_count_ - left_space) << 1 ) >= aligned_blocks_count_;
122+ if (handle.low_space_flag ) {
123+ head_->wt_reading_cursor_cache_ = head_->reading_cursor ().load_acquire ();
124+ left_space = static_cast <uint32_t >(head_->wt_reading_cursor_cache_ + aligned_blocks_count_ - head_->wt_writing_cursor_cache_ );
125+ handle.low_space_flag = ((aligned_blocks_count_ - left_space) << 1 ) >= aligned_blocks_count_;
126+ }
122127 handle.result = enum_buffer_result_code::success;
123128#if defined(BQ_LOG_BUFFER_DEBUG)
124129 ++result_code_statistics_[(int32_t )enum_buffer_result_code::success];
You can’t perform that action at this time.
0 commit comments