Skip to content

Commit

Permalink
add the info command(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacketWoo committed Mar 24, 2016
1 parent 862dfce commit 7b1921f
Show file tree
Hide file tree
Showing 15 changed files with 470 additions and 78 deletions.
2 changes: 1 addition & 1 deletion conf/pika.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pika port
port : 9221
port : 8221
# Thread Number
thread_num : 1
# Slave Thread Number
Expand Down
40 changes: 38 additions & 2 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,48 @@ class ClientCmd : public Cmd {
ClientCmd() {
}
virtual void Do();
static std::string CLIENT_LIST_S;
static std::string CLIENT_KILL_S;
const static std::string CLIENT_LIST_S;
const static std::string CLIENT_KILL_S;
private:
std::string operation_, ip_port_;
virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo* const ptr_info);
};

class InfoCmd : public Cmd {
public:
enum InfoSection {
kInfoErr = 0x0,
kInfoServer,
kInfoClients,
kInfoStats,
kInfoReplication,
kInfoKeyspace,
kInfoAll
};

InfoCmd() : rescan_(false) {
}
virtual void Do();
private:
InfoSection info_section_;
bool rescan_; //whether to rescan the keyspace

const static std::string kServerSection;
const static std::string kClientsSection;
const static std::string kStatsSection;
const static std::string kReplicationSection;
const static std::string kKeyspaceSection;

virtual void DoInitial(PikaCmdArgsType &argvs, const CmdInfo* const ptr_info);
virtual void Clear() {
rescan_ = false;
}

void InfoServer(std::string &info);
void InfoClients(std::string &info);
void InfoStats(std::string &info);
void InfoReplication(std::string &info);
void InfoKeyspace(std::string &info);
};

class ShutdownCmd : public Cmd {
Expand Down
2 changes: 2 additions & 0 deletions include/pika_client_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PIKA_CLIENT_CONN_H_

#include <glog/logging.h>
#include <atomic>

#include "redis_conn.h"
#include "pink_thread.h"
Expand All @@ -15,6 +16,7 @@ class PikaClientConn: public pink::RedisConn {
PikaClientConn(int fd, std::string ip_port, pink::Thread *thread);
virtual ~PikaClientConn();
virtual int DealMessage();

private:
PikaWorkerThread* self_thread_;
std::string DoCmd(const std::string& opt);
Expand Down
1 change: 1 addition & 0 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const std::string kCmdNameFlushall = "flushall";
const std::string kCmdNameReadonly = "readonly";
const std::string kCmdNameClient = "client";
const std::string kCmdNameShutdown = "shutdown";
const std::string kCmdNameInfo = "info";

//Kv
const std::string kCmdNameSet = "set";
Expand Down
71 changes: 68 additions & 3 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class PikaServer
int port() {
return port_;
};

time_t start_time_s() {
return start_time_s_;
}
PikaWorkerThread** pika_worker_thread() {
return pika_worker_thread_;
};
Expand Down Expand Up @@ -67,6 +69,14 @@ class PikaServer
}


int role() {
slash::RWLock(&state_protector_, false);
return role_;
}
int repl_state() {
slash::RWLock(&state_protector_, false);
return repl_state_;
}
/*
* Master use
*/
Expand All @@ -79,6 +89,8 @@ class PikaServer

void DeleteSlave(int fd); // hb_fd
bool FindSlave(std::string& ip_port);
int32_t GetSlaveListString(std::string& slave_list_str);
Status GetSmallestValidLog(uint32_t* max);
void MayUpdateSlavesMap(int64_t sid, int32_t hb_fd);
void BecomeMaster();

Expand Down Expand Up @@ -137,6 +149,9 @@ class PikaServer
const BGSaveInfo& bgsave_info() const {
return bgsave_info_;
}
bool bgsaving() {
return bgsaving_;
}
void Bgsave();
bool Bgsaveoff();
bool RunBgsaveEngine();
Expand All @@ -160,21 +175,58 @@ class PikaServer
//flushall
bool FlushAll();
void PurgeDir(std::string& path);
bool GetPurgeWindow(uint32_t &max);

/*
*Keyscan used
*/
struct KeyScanInfo {
time_t start_time;
std::string s_start_time;
std::vector<uint64_t> key_nums_v; //the order is kv, hash, list, zset, set
bool key_scaning_;
KeyScanInfo() : start_time(0), key_nums_v({0, 0, 0, 0, 0}), key_scaning_(false) {
}
};
bool key_scaning() {
slash::MutexLock lm(&key_scan_protector_);
return key_scan_info_.key_scaning_;
}
KeyScanInfo key_scan_info() {
slash::MutexLock lm(&key_scan_protector_);
return key_scan_info_;
}
void KeyScan();
void RunKeyScan();


/*
* client related
*/
void ClientKillAll();
int ClientKill(const std::string &ip_port);
void ClientList(std::vector< std::pair<int, std::string> > &clients);
int64_t ClientList(std::vector< std::pair<int, std::string> > *clients = NULL);

/*
*for statistic
*/
uint64_t ServerQueryNum();
uint64_t ServerCurrentQps();
uint64_t accumulative_connections() {
return accumulative_connections_;
}
void incr_accumulative_connections() {
++accumulative_connections_;
}

private:
std::string host_;
int port_;
pthread_rwlock_t rwlock_;
std::shared_ptr<nemo::Nemo> db_;

time_t start_time_s_;

PikaWorkerThread* pika_worker_thread_[PIKA_MAX_WORKER_THREAD_NUM];
PikaDispatchThread* pika_dispatch_thread_;

Expand Down Expand Up @@ -216,12 +268,25 @@ class PikaServer
pink::BGThread purge_thread_;

static void DoPurgeLogs(void* arg);
bool GetPurgeWindow(uint32_t &max);

/*
* Flushall use
*/
static void DoPurgeDir(void* arg);
/*
* Keyscan use
*/
slash::Mutex key_scan_protector_;
pink::BGThread key_scan_thread_;
KeyScanInfo key_scan_info_;

/*
* for statistic
*/
std::atomic<uint64_t> accumulative_connections_;

static void DoKeyScan(void *arg);
void InitKeyScan();

PikaServer(PikaServer &ps);
void operator =(const PikaServer &ps);
Expand Down
2 changes: 1 addition & 1 deletion include/pika_worker_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PikaWorkerThread : public pink::WorkerThread<PikaClientConn>
virtual ~PikaWorkerThread();
virtual void CronHandle();

void ThreadClientList(std::vector< std::pair<int, std::string> > &clients);
int64_t ThreadClientList(std::vector< std::pair<int, std::string> > *clients = NULL);
bool ThreadClientKill(std::string ip_port = "");
int ThreadClientNum();

Expand Down
12 changes: 6 additions & 6 deletions pikatests/pikatest.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
rm -rf /home/songzhao/develop/pika_test/redis/log
rm -rf /home/songzhao/develop/pika_test/redis/db
cp /home/songzhao/develop/pika/output/bin/pika /home/songzhao/develop/pika_test/redis/src/redis-server
#cp /home/songzhao/develop/pika/output/conf/pika.conf /home/songzhao/develop/pika_test/redis/tests/assets/default.conf
rm -rf /home/wuxiaofei-xy/worplace/pika/pika_test/redis/log
rm -rf /home/wuxiaofei-xy/workplace/pika/pika_test/redis/db
cp /home/wuxiaofei-xy/workplace/pika/output/bin/pika /home/wuxiaofei-xy/workplace/pika/pikatests/redis/src/redis-server
cp /home/wuxiaofei-xy/workplace/pika/output/conf/pika.conf /home/wuxiaofei-xy/workplace/pika/pikatests/redis/tests/assets/default.conf

tclsh tests/test_helper.tcl --clients 1 --single unit/type/$1

rm -rf /home/songzhao/develop/pika_test/redis/log
rm -rf /home/songzhao/develop/pika_test/redis/db
rm -rf /home/wuxiaofei-xy/workplace/pika/pikatests/redis/log
rm -rf /home/wuxiaofei-xy/workplace/pika/pikatests/redis/db
32 changes: 24 additions & 8 deletions pikatests/tests/assets/default.conf
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
# Pika port
port : 9221
port : 8221
# Thread Number
thread_num : 16
thread_num : 1
# Slave Thread Number
slave_thread_num : 7
slave_thread_num : 1
# Pika log path
log_path : ./log
log_path : ./log/
# Pika glog level
log_level : 0
log_level : 1
# Pika db path
db_path : ./db/
# Pika write_buffer_size
write_buffer_size : 268435456
# Pika timeout
timeout : 60
# Requirepass
requirepass :
requirepass :
# Dump Prefix
dump_prefix :
# daemonize [yes | no]
#daemonize : yes
# Dump Path
dump_path : ./dump/
# pidfile Path
pidfile : ./pika.pid
# Max Connection
maxconnection : 20000
# the per file size of sst to compact, defalut is 2M
target_file_size_base : 20971520
# Expire_logs_days
expire_logs_days : 1
expire_logs_days : 7
# Expire_logs_nums
expire_logs_nums : 20
expire_logs_nums : 10
# Root_connection_num
root_connection_num : 2
# Slowlog_log_slower_than
slowlog_log_slower_than : 10000
# slave-read-only(yes/no, 1/0)
slave_read_only : 0

###################
## Critical Settings
###################
# binlog file size: default is 100M, limited in [1K, 2G]
binlog_file_size : 104857600
# Compression
compression : snappy
Binary file removed pikatests/tests/unit/type/.zset.tcl.swp
Binary file not shown.
Loading

0 comments on commit 7b1921f

Please sign in to comment.