Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Qihoo360/pika
Browse files Browse the repository at this point in the history
  • Loading branch information
wenduo committed Jun 3, 2016
2 parents 7f7ce0c + 7c74bb6 commit 9f1d039
Show file tree
Hide file tree
Showing 27 changed files with 1,798 additions and 117 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Pika is a persistent huge storage service , compatible with the vast majority o
~~~
a. sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
b. yum install --nogpgcheck devtoolset-1.1
c. scl enable devetoolset-1.1 bash
c. scl enable devtoolset-1.1 bash
~~~
4.Fetch the source code:

Expand Down Expand Up @@ -64,6 +64,19 @@ The PIKA_SOURCE stands for pika source code's root directory;
The __VERSION represents the OS's version, such as 6.2, 5.4...
The RPATH is defined in pika's Makefile

## Quickstart and Try
You can try to use our pre-build binary versions. For now, only Centos5 and Centos6 are supported. The binary ones can be found at [the release page](https://github.com/Qihoo360/pika/releases) which are called pikaX.Y.Z_centosK_bin.tar.gz.

```
# 1. unzip file
tar zxf pikaX.Y.Z_centosK_bin.tar.gz
# 2. change working directory to output
# note: we should in this directory, caz the RPATH is ./lib;
cd output
# 3. run pika:
./bin/pika -c conf/pika.conf
```

##Performance

```
Expand Down
15 changes: 14 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Pika是一个可持久化的大容量redis存储服务,兼容string、hash、l
```
a. sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
b. yum install --nogpgcheck devtoolset-1.1
c. scl enable devetoolset-1.1 bash
c. scl enable devtoolset-1.1 bash
```
4.获取源代码

Expand Down Expand Up @@ -61,6 +61,19 @@ PIKA_SOURCE表示的pika的源代码根目录;
_VERSION表示的是编译机的CenOS版本,如6.2, 5.4...
RPATH在Makefile定义,表示的是程序运行的库预先加载路径

## 快速试用
如果想快速试用pika,目前提供了Centos5,Centos6的binary版本,可以在[release页面](https://github.com/Qihoo360/pika/releases)看到,具体文件是pikaX.Y.Z_centosK_bin.tar.gz。

```
# 1. unzip file
tar zxf pikaX.Y.Z_centosK_bin.tar.gz
# 2. change working directory to output
# note: we should in this directory, caz the RPATH is ./lib;
cd output
# 3. run pika:
./bin/pika -c conf/pika.conf
```

## 性能
```
服务端配置:
Expand Down
13 changes: 13 additions & 0 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class InfoCmd : public Cmd {
kInfoStats,
kInfoReplication,
kInfoKeyspace,
kInfoBgstats,
kInfoLog,
kInfoData,
kInfoAll
};

Expand All @@ -160,6 +163,9 @@ class InfoCmd : public Cmd {
const static std::string kStatsSection;
const static std::string kReplicationSection;
const static std::string kKeyspaceSection;
const static std::string kBgstatsSection;
const static std::string kLogSection;
const static std::string kDataSection;

virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo* const ptr_info);
virtual void Clear() {
Expand All @@ -171,6 +177,13 @@ class InfoCmd : public Cmd {
void InfoStats(std::string &info);
void InfoReplication(std::string &info);
void InfoKeyspace(std::string &info);
void InfoBgstats(std::string &info);
void InfoLog(std::string &info);
void InfoData(std::string &info);

void GetBgstats(std::stringstream &s);
void GetLog(std::stringstream &s);
void GetData(std::stringstream &s);
};

class ShutdownCmd : public Cmd {
Expand Down
2 changes: 1 addition & 1 deletion include/pika_kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ExistsCmd : public Cmd {
ExistsCmd() {}
virtual void Do();
private:
std::string key_;
std::vector<std::string> keys_;
virtual void DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info);
};

Expand Down
12 changes: 5 additions & 7 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,11 @@ class PikaServer
slash::MutexLock l(&bgsave_protector_);
return bgsave_info_.bgsaving;
}
slash::Mutex* bgsave_protector() {
return &bgsave_protector_;
}
void Bgsave();
bool Bgsaveoff();
bool RunBgsaveEngine(const std::string path);
// need bgsave_protector protect
void ClearBgsave() {
bgsave_info_.Clear();
}
void FinishBgsave() {
slash::MutexLock l(&bgsave_protector_);
bgsave_info_.bgsaving = false;
}

Expand Down Expand Up @@ -320,6 +314,10 @@ void SignalNextBinlogBGSerial();
static void DoBgsave(void* arg);
bool InitBgsaveEnv();
bool InitBgsaveEngine();
void ClearBgsave() {
slash::MutexLock l(&bgsave_protector_);
bgsave_info_.Clear();
}


/*
Expand Down
11 changes: 11 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Used for Release only.

TAG="2.0.4"

make clean && make RPATH=./lib __REL=1

#cp LOOKME output/
#tar -czf $RELEASE_FILE output
tar -czf pika${TAG}_bin.tar.gz output
167 changes: 119 additions & 48 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ const std::string InfoCmd::kClientsSection = "clients";
const std::string InfoCmd::kStatsSection = "stats";
const std::string InfoCmd::kReplicationSection = "replication";
const std::string InfoCmd::kKeyspaceSection = "keyspace";
const std::string InfoCmd::kBgstatsSection = "bgstats";
const std::string InfoCmd::kLogSection = "log";
const std::string InfoCmd::kDataSection = "data";

void InfoCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info) {
(void)ptr_info;
Expand Down Expand Up @@ -402,7 +405,13 @@ void InfoCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info) {
res_.SetRes(CmdRes::kSyntaxErr);
}
return;
} else {
} else if (argv[1] == kBgstatsSection) {
info_section_ = kInfoBgstats;
} else if (argv[1] == kLogSection) {
info_section_ = kInfoLog;
} else if (argv[1] == kDataSection) {
info_section_ = kInfoData;
}else {
info_section_ = kInfoErr;
}
if (argc != 2) {
Expand All @@ -412,35 +421,90 @@ void InfoCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info) {

void InfoCmd::Do() {
std::string info;
if (info_section_ == kInfoAll) {
InfoServer(info);
info.append("\r\n");
InfoClients(info);
info.append("\r\n");
InfoStats(info);
info.append("\r\n");
InfoReplication(info);
info.append("\r\n");
InfoKeyspace(info);
} else if (info_section_ == kInfoServer) {
InfoServer(info);
} else if (info_section_ == kInfoClients) {
InfoClients(info);
} else if (info_section_ == kInfoStats) {
InfoStats(info);
} else if (info_section_ == kInfoReplication) {
InfoReplication(info);
} else if (info_section_ == kInfoKeyspace) {
InfoKeyspace(info);
} else {
//kInfoErr is nothing
switch (info_section_) {
case kInfoAll:
InfoServer(info);
info.append("\r\n");
InfoClients(info);
info.append("\r\n");
InfoStats(info);
info.append("\r\n");
InfoReplication(info);
info.append("\r\n");
InfoKeyspace(info);
break;
case kInfoServer:
InfoServer(info);
break;
case kInfoClients:
InfoClients(info);
break;
case kInfoStats:
InfoServer(info);
break;
case kInfoReplication:
InfoReplication(info);
break;
case kInfoKeyspace:
InfoKeyspace(info);
break;
case kInfoBgstats:
InfoBgstats(info);
break;
case kInfoLog:
InfoLog(info);
break;
case kInfoData:
InfoData(info);
break;
default:
//kInfoErr is nothing
break;
}


res_.AppendStringLen(info.size());
res_.AppendContent(info);
return;
}

void InfoCmd::GetBgstats(std::stringstream &s) {
PikaServer::BGSaveInfo bgsave_info = g_pika_server->bgsave_info();
bool is_bgsaving = g_pika_server->bgsaving();
time_t current_time_s = time(NULL);
s << "is_bgsaving:" << (is_bgsaving ? "Yes, " : "No, ") << bgsave_info.s_start_time << ", "
<< (is_bgsaving ? (current_time_s - bgsave_info.start_time) : 0) << "\r\n";
PikaServer::KeyScanInfo key_scan_info = g_pika_server->key_scan_info();
bool is_scaning = g_pika_server->key_scaning();
s << "is_scaning_keyspace:" << (is_scaning ? ("Yes, " + key_scan_info.s_start_time) + "," : "No");
if (is_scaning) {
s << current_time_s - key_scan_info.start_time;
}
s << "\r\n";
s << "is_compact:" << g_pika_server->db()->GetCurrentTaskType() << "\r\n";
return;
}

void InfoCmd::GetLog(std::stringstream &s) {
uint32_t purge_max;
s << "log_size:" << (slash::Du(g_pika_conf->log_path()) >> 20) << "M\r\n";
s << "safety_purge:" << (g_pika_server->GetPurgeWindow(purge_max) ?
kBinlogPrefix + std::to_string(static_cast<int32_t>(purge_max)) : "none") << "\r\n";
s << "expire_logs_days:" << g_pika_conf->expire_logs_days() << "\r\n";
s << "expire_logs_nums:" << g_pika_conf->expire_logs_nums() << "\r\n";
uint32_t filenum;
uint64_t offset;
g_pika_server->logger_->GetProducerStatus(&filenum, &offset);
s << "write2file:" << filenum << "\r\n";
return;
}

void InfoCmd::GetData(std::stringstream &s) {
s << "db_size:" << (slash::Du(g_pika_conf->db_path()) >> 20) << "M\r\n";
s << "compression:" << g_pika_conf->compression() << "\r\n";
return;
}

void InfoCmd::InfoServer(std::string &info) {
static struct utsname host_info;
static bool host_info_valid = false;
Expand All @@ -451,7 +515,6 @@ void InfoCmd::InfoServer(std::string &info) {

time_t current_time_s = time(NULL);
std::stringstream tmp_stream;
uint32_t purge_max;
tmp_stream << "# Server\r\n";
tmp_stream << "pika_version:" << kPikaVersion << "\r\n";
tmp_stream << "os:" << host_info.sysname << " " << host_info.release << " " << host_info.machine << "\r\n";
Expand All @@ -463,26 +526,10 @@ void InfoCmd::InfoServer(std::string &info) {
tmp_stream << "uptime_in_seconds:" << (current_time_s - g_pika_server->start_time_s()) << "\r\n";
tmp_stream << "uptime_in_days:" << (current_time_s / (24*3600) - g_pika_server->start_time_s() / (24*3600) + 1) << "\r\n";
tmp_stream << "config_file:" << g_pika_conf->conf_path() << "\r\n";
PikaServer::BGSaveInfo bgsave_info = g_pika_server->bgsave_info();
bool is_bgsaving = g_pika_server->bgsaving();
tmp_stream << "is_bgsaving:" << (is_bgsaving ? "Yes, " : "No, ") << bgsave_info.s_start_time << ", "
<< (is_bgsaving ? (current_time_s - bgsave_info.start_time) : 0) << "\r\n";
PikaServer::KeyScanInfo key_scan_info = g_pika_server->key_scan_info();
bool is_scaning = g_pika_server->key_scaning();
tmp_stream << "is_scaning_keyspace:" << (is_scaning ? ("Yes, " + key_scan_info.s_start_time) + "," : "No");
if (is_scaning) {
tmp_stream << current_time_s - key_scan_info.start_time;
}
tmp_stream << "\r\n";
tmp_stream << "is_compact:" << g_pika_server->db()->GetCurrentTaskType() << "\r\n";
tmp_stream << "db_size:" << (slash::Du(g_pika_conf->db_path()) >> 20) << "M\r\n";
tmp_stream << "log_size:" << (slash::Du(g_pika_conf->log_path()) >> 20) << "M\r\n";
tmp_stream << "compression:" << g_pika_conf->compression() << "\r\n";
tmp_stream << "safety_purge:" << (g_pika_server->GetPurgeWindow(purge_max) ?
kBinlogPrefix + std::to_string(static_cast<int32_t>(purge_max)) : "none") << "\r\n";
tmp_stream << "expire_logs_days:" << g_pika_conf->expire_logs_days() << "\r\n";
tmp_stream << "expire_logs_nums:" << g_pika_conf->expire_logs_nums() << "\r\n";

GetBgstats(tmp_stream);
GetData(tmp_stream);
GetLog(tmp_stream);

info.append(tmp_stream.str());
}

Expand All @@ -500,7 +547,7 @@ void InfoCmd::InfoStats(std::string &info) {

tmp_stream << "total_connections_received:" << g_pika_server->accumulative_connections() << "\r\n";
tmp_stream << "instantaneous_ops_per_sec:" << g_pika_server->ServerCurrentQps() << "\r\n";
tmp_stream << "accumulative_query_nums:" << g_pika_server->ServerQueryNum() << "\r\n";
tmp_stream << "total_commands_processed:" << g_pika_server->ServerQueryNum() << "\r\n";

info.append(tmp_stream.str());
}
Expand All @@ -524,13 +571,13 @@ void InfoCmd::InfoReplication(std::string &info) {
tmp_stream << "master_host:" << g_pika_server->master_ip() << "\r\n";
tmp_stream << "master_port:" << g_pika_server->master_port() << "\r\n";
tmp_stream << "master_link_status:" << (g_pika_server->repl_state() == PIKA_REPL_CONNECTED ? "up" : "down") << "\r\n";
tmp_stream << "slave-read-only:" << g_pika_conf->readonly() << "\r\n";
tmp_stream << "slave_read_only:" << g_pika_conf->readonly() << "\r\n";
break;
case PIKA_ROLE_MASTER | PIKA_ROLE_SLAVE :
tmp_stream << "master_host:" << g_pika_server->master_ip() << "\r\n";
tmp_stream << "master_port:" << g_pika_server->master_port() << "\r\n";
tmp_stream << "master_link_status:" << (g_pika_server->repl_state() == PIKA_REPL_CONNECTED ? "connected" : "down") << "\r\n";
tmp_stream << "slave-read-only:" << g_pika_conf->readonly() << "\r\n";
tmp_stream << "master_link_status:" << (g_pika_server->repl_state() == PIKA_REPL_CONNECTED ? "up" : "down") << "\r\n";
tmp_stream << "slave_read_only:" << g_pika_conf->readonly() << "\r\n";
case PIKA_ROLE_SINGLE :
case PIKA_ROLE_MASTER :
tmp_stream << "connected_slaves:" << g_pika_server->GetSlaveListString(slaves_list_str) << "\r\n" << slaves_list_str;
Expand Down Expand Up @@ -562,6 +609,30 @@ void InfoCmd::InfoKeyspace(std::string &info) {
return;
}

void InfoCmd::InfoBgstats(std::string &info) {
std::stringstream tmp_stream;
tmp_stream << "# Bgstats" << "\r\n";
GetBgstats(tmp_stream);
info.append(tmp_stream.str());
return;
}

void InfoCmd::InfoLog(std::string &info) {
std::stringstream tmp_stream;
tmp_stream << "# Log" << "\r\n";
GetLog(tmp_stream);
info.append(tmp_stream.str());
return;
}

void InfoCmd::InfoData(std::string &info) {
std::stringstream tmp_stream;
tmp_stream << "# Data" << "\r\n";
GetData(tmp_stream);
info.append(tmp_stream.str());
return;
}

void ConfigCmd::DoInitial(PikaCmdArgsType &argv, const CmdInfo* const ptr_info) {
if (!ptr_info->CheckArg(argv.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void InitCmdInfoTable() {
CmdInfo* strlenptr = new CmdInfo(kCmdNameStrlen, 2, kCmdFlagsRead | kCmdFlagsKv);
cmd_infos.insert(std::pair<std::string, CmdInfo*>(kCmdNameStrlen, strlenptr));
////Exists
CmdInfo* existsptr = new CmdInfo(kCmdNameExists, 2, kCmdFlagsRead | kCmdFlagsKv);
CmdInfo* existsptr = new CmdInfo(kCmdNameExists, -2, kCmdFlagsRead | kCmdFlagsKv);
cmd_infos.insert(std::pair<std::string, CmdInfo*>(kCmdNameExists, existsptr));
////Expire
CmdInfo* expireptr = new CmdInfo(kCmdNameExpire, 3, kCmdFlagsWrite | kCmdFlagsKv);
Expand Down
Loading

0 comments on commit 9f1d039

Please sign in to comment.