fix when the disk is full cause pika crash
MODIFY
include/pika_server.h
include/pika_server.h
@@ -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();
@@ -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_;

MODIFY
src/pika_binlog.cc
src/pika_binlog.cc
@@ -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();

MODIFY
src/pika_client_conn.cc
src/pika_client_conn.cc
@@ -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";
}
@@ -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";
+ }
}
}

MODIFY
src/pika_server.cc
src/pika_server.cc
@@ -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),

fix when the disk is full cause pika crash (#190)