本文整理汇总了C++中Slave::save_status方法的典型用法代码示例。如果您正苦于以下问题:C++ Slave::save_status方法的具体用法?C++ Slave::save_status怎么用?C++ Slave::save_status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slave
的用法示例。
在下文中一共展示了Slave::save_status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _run_thread
void* Slave::_run_thread(void *arg){
Slave *slave = (Slave *)arg;
const SSDB *ssdb = slave->ssdb;
const char *ip = slave->master_ip.c_str();
int port = slave->master_port;
Link *link = NULL;
int retry = 0;
const std::vector<Bytes> *req;
while(true){
if(link == NULL){
if(retry){
int t = retry > 15? 15 : retry;
usleep(t * 1000 * 1000);
log_info("[%d] connecting to master at %s:%d...", retry, ip, port);
}
link = connect(ip, port, slave->next_seq, slave->last_key);
if(link == NULL){
retry ++;
continue;
}else{
retry = 0;
}
}
req = link->recv();
if(req == NULL){
retry = 1;
delete link;
link = NULL;
log_info("recv error, reconnecting to master...");
continue;
}else if(req->empty()){
if(link->read() <= 0){
retry = 1;
delete link;
link = NULL;
log_info("network error, reconnecting to master...");
}
continue;
}
Bytes cmd = req->at(0);
if(cmd == "sync_set"){
log_trace("recv sync: %s", serialize_req(*req).c_str());
if(req->size() != 4){
log_warn("invalid set params!");
break;
}
uint64_t seq = req->at(1).Uint64();
Bytes key = req->at(2);
Bytes val = req->at(3);
if(seq == 0){
// dump
slave->last_key = key.String();
}else{
// sync
slave->next_seq = seq + 1;
}
int ret = ssdb->raw_set(key, val);
if(ret == -1){
log_error("ssdb.raw_set error!");
}
slave->save_status();
}else if(cmd == "sync_del"){
log_trace("recv sync: %s", serialize_req(*req).c_str());
if(req->size() != 3){
log_warn("invalid del params!");
break;
}
uint64_t seq = req->at(1).Uint64();
Bytes key = req->at(2);
if(seq == 0){
// dump
slave->last_key = key.String();
}else{
// sync
slave->next_seq = seq + 1;
}
int ret = ssdb->raw_del(key);
if(ret == -1){
log_error("ssdb.raw_del error!");
}
slave->save_status();
}else if(cmd == "dump_end"){
log_info("dump end, step in sync");
slave->last_key = "";
}else if(cmd == "noop"){
//
}else{
log_warn("unknow sync command: %s", serialize_req(*req).c_str());
}
} // end while
if(link){
delete link;
//.........这里部分代码省略.........