本文整理汇总了C++中Slave::start方法的典型用法代码示例。如果您正苦于以下问题:C++ Slave::start方法的具体用法?C++ Slave::start怎么用?C++ Slave::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slave
的用法示例。
在下文中一共展示了Slave::start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BackendDump
SSDBServer::SSDBServer(SSDB *ssdb, SSDB *meta, const Config &conf, NetworkServer *net){
this->ssdb = (SSDBImpl *)ssdb;
this->meta = meta;
net->data = this;
this->reg_procs(net);
int sync_speed = conf.get_num("replication.sync_speed");
backend_dump = new BackendDump(this->ssdb);
backend_sync = new BackendSync(this->ssdb, sync_speed);
expiration = new ExpirationHandler(this->ssdb);
cluster = new Cluster(this->ssdb);
if(cluster->init() == -1){
log_fatal("cluster init failed!");
exit(1);
}
{ // slaves
const Config *repl_conf = conf.get("replication");
if(repl_conf != NULL){
std::vector<Config *> children = repl_conf->children;
for(std::vector<Config *>::iterator it = children.begin(); it != children.end(); it++){
Config *c = *it;
if(c->key != "slaveof"){
continue;
}
std::string ip = c->get_str("ip");
int port = c->get_num("port");
if(ip == ""){
ip = c->get_str("host");
}
if(ip == "" || port <= 0 || port > 65535){
continue;
}
bool is_mirror = false;
std::string type = c->get_str("type");
if(type == "mirror"){
is_mirror = true;
}else{
type = "sync";
is_mirror = false;
}
std::string id = c->get_str("id");
log_info("slaveof: %s:%d, type: %s", ip.c_str(), port, type.c_str());
Slave *slave = new Slave(ssdb, meta, ip.c_str(), port, is_mirror);
if(!id.empty()){
slave->set_id(id);
}
slave->auth = c->get_str("auth");
slave->start();
slaves.push_back(slave);
}
}
}
// load kv_range
int ret = this->get_kv_range(&this->kv_range_s, &this->kv_range_e);
if(ret == -1){
log_fatal("load key_range failed!");
exit(1);
}
log_info("key_range.kv: \"%s\", \"%s\"",
str_escape(this->kv_range_s).c_str(),
str_escape(this->kv_range_e).c_str()
);
}
示例2: open
//.........这里部分代码省略.........
if(binlog_onoff != "no"){
binlog_onoff = "yes";
}
if(cache_size <= 0){
cache_size = 8;
}
if(write_buffer_size <= 0){
write_buffer_size = 4;
}
if(block_size <= 0){
block_size = 4;
}
log_info("main_db : %s", main_db_path.c_str());
log_info("meta_db : %s", meta_db_path.c_str());
log_info("cache_size : %d MB", cache_size);
log_info("block_size : %d KB", block_size);
log_info("write_buffer : %d MB", write_buffer_size);
log_info("compaction_speed : %d MB/s", compaction_speed);
log_info("compression : %s", compression.c_str());
log_info("binlog : %s", binlog_onoff.c_str());
SSDB *ssdb = new SSDB();
//
ssdb->options.create_if_missing = true;
ssdb->options.filter_policy = leveldb::NewBloomFilterPolicy(10);
ssdb->options.block_cache = leveldb::NewLRUCache(cache_size * 1048576);
ssdb->options.block_size = block_size * 1024;
ssdb->options.write_buffer_size = write_buffer_size * 1024 * 1024;
ssdb->options.compaction_speed = compaction_speed;
if(compression == "yes"){
ssdb->options.compression = leveldb::kSnappyCompression;
}else{
ssdb->options.compression = leveldb::kNoCompression;
}
leveldb::Status status;
{
leveldb::Options options;
options.create_if_missing = true;
status = leveldb::DB::Open(options, meta_db_path, &ssdb->meta_db);
if(!status.ok()){
goto err;
}
}
status = leveldb::DB::Open(ssdb->options, main_db_path, &ssdb->db);
if(!status.ok()){
log_error("open main_db failed");
goto err;
}
ssdb->binlogs = new BinlogQueue(ssdb->db);
if(binlog_onoff == "no"){
ssdb->binlogs->no_log();
}
{ // slaves
const Config *repl_conf = conf.get("replication");
if(repl_conf != NULL){
std::vector<Config *> children = repl_conf->children;
for(std::vector<Config *>::iterator it = children.begin(); it != children.end(); it++){
Config *c = *it;
if(c->key != "slaveof"){
continue;
}
std::string ip = c->get_str("ip");
int port = c->get_num("port");
if(ip == "" || port <= 0 || port > 65535){
continue;
}
bool is_mirror = false;
std::string type = c->get_str("type");
if(type == "mirror"){
is_mirror = true;
}else{
type = "sync";
is_mirror = false;
}
std::string id = c->get_str("id");
log_info("slaveof: %s:%d, type: %s", ip.c_str(), port, type.c_str());
Slave *slave = new Slave(ssdb, ssdb->meta_db, ip.c_str(), port, is_mirror);
if(!id.empty()){
slave->set_id(id);
}
slave->start();
ssdb->slaves.push_back(slave);
}
}
}
return ssdb;
err:
if(ssdb){
delete ssdb;
}
return NULL;
}