66 {
67 if (is_writing_) {
68
69 while (1) {
70 {
71 std::unique_lock<std::mutex> flush_lock(flush_mutex_);
72 if (chunk_flush_->empty()) {
73 break;
74 }
75 }
76 std::this_thread::sleep_for(std::chrono::milliseconds(100));
77 }
78
79
80 {
81 std::unique_lock<std::mutex> flush_lock(flush_mutex_);
82 chunk_flush_.swap(chunk_active_);
83 flush_cv_.notify_one();
84 }
85
86
87 while (1) {
88 {
89 std::unique_lock<std::mutex> flush_lock(flush_mutex_);
90 if (chunk_flush_->empty()) {
91 break;
92 }
93 }
94 std::this_thread::sleep_for(std::chrono::milliseconds(100));
95 }
96
97 is_writing_ = false;
98 flush_cv_.notify_all();
99 if (flush_thread_ && flush_thread_->joinable()) {
100 flush_thread_->join();
101 flush_thread_ = nullptr;
102 }
103
104 if (!WriteIndex()) {
105 AERROR <<
"Write index section failed, file: " <<
path_;
106 }
107
110 AERROR <<
"Overwrite header section failed, file: " <<
path_;
111 }
112
113 if (close(
fd_) < 0) {
115 << ", errno: " << errno;
116 }
117 }
118}
bool WriteHeader(const proto::Header &header)