Skip to content

Commit

Permalink
fix when the disk is full cause pika crash (OpenAtomFoundation#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leviathan1995 authored and KernelMaker committed Oct 10, 2017
1 parent af134e6 commit 083438b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ class PikaServer {
void Exit() {
exit_ = true;
}

void SetBinlogIoError(bool error) {
binlog_io_error_ = error;
}

bool BinlogIoError() {
return binlog_io_error_;
}

void DoTimingTask();
void Cleanup();

Expand Down Expand Up @@ -334,6 +343,7 @@ class PikaServer {

private:
std::atomic<bool> exit_;
std::atomic<bool> binlog_io_error_;
std::string host_;
int port_;
pthread_rwlock_t rwlock_;
Expand Down
5 changes: 4 additions & 1 deletion src/pika_binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ Status Binlog::Produce(const Slice &item, int *temp_pro_offset) {
assert(leftover >= 0);
if (static_cast<size_t>(leftover) < kHeaderSize) {
if (leftover > 0) {
queue_->Append(Slice("\x00\x00\x00\x00\x00\x00\x00", leftover));
s = queue_->Append(Slice("\x00\x00\x00\x00\x00\x00\x00", leftover));
if (!s.ok()) {
return s;
}
//version_->rise_pro_offset(leftover);
*temp_pro_offset += leftover;
//version_->StableSave();
Expand Down
11 changes: 10 additions & 1 deletion src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ std::string PikaClientConn::DoCmd(const std::string& opt) {

std::string raw_args;
if (cinfo_ptr->is_write()) {
if (g_pika_server->BinlogIoError()) {
return "-ERR Writing binlog failed, maybe no space left on device\r\n";
}
if (g_pika_conf->readonly()) {
return "-ERR Server in read-only\r\n";
}
Expand All @@ -111,8 +114,14 @@ std::string PikaClientConn::DoCmd(const std::string& opt) {
if (cinfo_ptr->is_write()) {
if (c_ptr->res().ok()) {
g_pika_server->logger_->Lock();
g_pika_server->logger_->Put(raw_args);
slash::Status s = g_pika_server->logger_->Put(raw_args);
g_pika_server->logger_->Unlock();
if (!s.ok()) {
LOG(INFO) << "Writing binlog failed, maybe no space left on device";
g_pika_server->SetBinlogIoError(true);
g_pika_conf->SetReadonly(true);
return "-ERR Writing binlog failed, maybe no space left on device\r\n";
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern PikaConf *g_pika_conf;
PikaServer::PikaServer() :
ping_thread_(NULL),
exit_(false),
binlog_io_error_(false),
have_scheduled_crontask_(false),
last_check_compact_time_({0, 0}),
sid_(0),
Expand Down

0 comments on commit 083438b

Please sign in to comment.