Skip to content

Commit

Permalink
add timer_task_thread_
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyuecai committed Jul 3, 2024
1 parent b7d5e0f commit 8a986a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions include/pika_binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "pstd/include/pstd_status.h"
#include "pstd/include/noncopyable.h"
#include "include/pika_define.h"
#include "net/src/dispatch_thread.h"

std::string NewFileName(const std::string& name, uint32_t current);

Expand Down Expand Up @@ -78,6 +79,7 @@ class Binlog : public pstd::noncopyable {
}

void Close();
void FlushBufferedFile();

private:
pstd::Status Put(const char* item, int len);
Expand Down Expand Up @@ -110,6 +112,8 @@ class Binlog : public pstd::noncopyable {
std::string filename_;

std::atomic<bool> binlog_io_error_;

net::TimerTaskThread timer_task_thread_;
};

#endif
16 changes: 15 additions & 1 deletion src/pika_binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,29 @@ Binlog::Binlog(std::string binlog_path, const int file_size)
uint64_t filesize = queue_->Filesize();
DLOG(INFO) << "Binlog: filesize is " << filesize;
}

InitLogFile();

timer_task_thread_.AddTimerTask("flush_binlog_task", 500, true,
[this] { this->FlushBufferedFile(); });
timer_task_thread_.StartThread();
}

Binlog::~Binlog() {
std::lock_guard l(mutex_);
timer_task_thread_.StopThread();
Close();
}

void Binlog::FlushBufferedFile() {
std::lock_guard l(mutex_);
if (!opened_.load()) {
return;
}
if (queue_) {
queue_->Flush();
}
}

void Binlog::Close() {
if (!opened_.load()) {
return;
Expand Down
4 changes: 0 additions & 4 deletions src/pstd/src/env.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#include "pstd/include/env.h"

#include <dirent.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <cassert>

#include <cstdio>
#include <fstream>
#include <sstream>
#include <utility>
#include <thread>
Expand Down

0 comments on commit 8a986a5

Please sign in to comment.