diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index 10fd947e5..624685d16 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -430,6 +430,17 @@ void Binlog::flush() { } need_flush_since_ = 0; LOG_IF(FATAL, fd_.need_flush_write()) << "Failed to flush binlog"; + + if (state_ == State::Run && Time::now() > next_buffer_flush_time_) { + LOG(DEBUG) << "Flush write buffer"; + buffer_writer_ = ChainBufferWriter(); + buffer_reader_ = buffer_writer_.extract_reader(); + if (encryption_type_ == EncryptionType::AesCtr) { + aes_ctr_state_ = aes_xcode_byte_flow_.move_aes_ctr_state(); + } + update_write_encryption(); + next_buffer_flush_time_ = Time::now() + 1.0; + } } void Binlog::lazy_flush() { diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index 8cae93f18..055c84e18 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -161,6 +161,7 @@ class Binlog { bool in_flush_events_buffer_{false}; uint64 last_event_id_{0}; double need_flush_since_ = 0; + double next_buffer_flush_time_ = 0; bool need_sync_{false}; enum class State { Empty, Load, Reindex, Run } state_{State::Empty};