本文整理汇总了C++中Binlog::cmd方法的典型用法代码示例。如果您正苦于以下问题:C++ Binlog::cmd方法的具体用法?C++ Binlog::cmd怎么用?C++ Binlog::cmd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binlog
的用法示例。
在下文中一共展示了Binlog::cmd方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proc_copy
int Slave::proc_copy(const Binlog &log, const std::vector<Bytes> &req){
switch(log.cmd()){
case BinlogCommand::BEGIN:
log_info("copy begin");
break;
case BinlogCommand::END:
log_info("copy end, copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64,
copy_count, this->last_seq, log.seq());
if (!this->is_mirror && this->last_seq > 0) { // no master
ssdb->get_binlogs()->update(this->last_seq, BinlogType::NOOP, BinlogCommand::NONE, "", "");
ssdb->get_binlogs()->set_last_seq(this->last_seq);
}
this->last_key = "";
this->save_status();
status = SYNC;
break;
default:
if (this->is_mirror) {
// if master, don't set no_log
return proc_sync(log, req);
} else {
// unable to support multi replications
bool enabled = ssdb->get_binlogs()->is_enabled();
ssdb->get_binlogs()->set_enabled(false); // disabled binlog
int result = proc_sync(log, req);
ssdb->get_binlogs()->set_enabled(enabled);
return result;
}
}
return 0;
}
示例2: proc_copy
int Slave::proc_copy(const Binlog &log, const std::vector<Bytes> &req){
switch(log.cmd()){
case BinlogCommand::BEGIN:
log_info("copy begin");
log_info("start flushdb...");
this->last_seq = 0;
this->last_key = "";
this->save_status();
ssdb->flushdb();
log_info("end flushdb.");
break;
case BinlogCommand::END:
log_info("copy end, copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64,
copy_count, this->last_seq, log.seq());
this->status = SYNC;
this->last_key = "";
this->save_status();
break;
default:
if(++copy_count % 1000 == 1){
log_info("copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
copy_count, this->last_seq, log.seq());
}
return proc_sync(log, req);
break;
}
return 0;
}
示例3: proc_copy
int Slave::proc_copy(const Binlog &log, const std::vector<Bytes> &req){
switch(log.cmd()){
case BinlogCommand::BEGIN:
log_info("copy begin");
break;
case BinlogCommand::END:
log_info("copy end, step in sync");
this->last_key = "";
this->save_status();
break;
default:
return proc_sync(log, req);
break;
}
return 0;
}
示例4: proc_copy
int Slave::proc_copy(const Binlog &log, const std::vector<Bytes> &req){
switch(log.cmd()){
case BinlogCommand::BEGIN:
log_info("copy begin");
break;
case BinlogCommand::END:
log_info("copy end, copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64,
copy_count, this->last_seq, log.seq());
this->last_key = "";
this->save_status();
break;
default:
return proc_sync(log, req);
break;
}
return 0;
}
示例5: while
int BackendSync::Client::sync(BinlogQueue *logs) {
Binlog log;
while(1) {
int ret = 0;
uint64_t expect_seq = this->last_seq + 1;
if(this->status == Client::COPY && this->last_seq == 0) {
ret = logs->find_last(&log);
} else {
ret = logs->find_next(expect_seq, &log);
}
if(ret == 0) {
return 0;
}
if(this->status == Client::COPY && log.key() > this->last_key) {
log_debug("fd: %d, last_key: '%s', drop: %s",
link->fd(),
hexmem(this->last_key.data(), this->last_key.size()).c_str(),
log.dumps().c_str());
this->last_seq = log.seq();
// WARN: When there are writes behind last_key, we MUST create
// a new iterator, because iterator will not know this key.
// Because iterator ONLY iterates throught keys written before
// iterator is created.
if(this->iter) {
delete this->iter;
this->iter = NULL;
}
continue;
}
if(this->last_seq != 0 && log.seq() != expect_seq) {
log_warn("%s:%d fd: %d, OUT_OF_SYNC! log.seq: %" PRIu64 ", expect_seq: %" PRIu64 "",
link->remote_ip, link->remote_port,
link->fd(),
log.seq(),
expect_seq
);
this->status = Client::OUT_OF_SYNC;
return 1;
}
// update last_seq
this->last_seq = log.seq();
char type = log.type();
if(type == BinlogType::MIRROR && this->is_mirror) {
if(this->last_seq - this->last_noop_seq >= 1000) {
this->noop();
return 1;
} else {
continue;
}
}
break;
}
int ret = 0;
std::string val;
switch(log.cmd()) {
case BinlogCommand::KSET:
case BinlogCommand::HSET:
case BinlogCommand::ZSET:
case BinlogCommand::QSET:
case BinlogCommand::QPUSH_BACK:
case BinlogCommand::QPUSH_FRONT:
ret = backend->ssdb->raw_get(log.key(), &val);
if(ret == -1) {
log_error("fd: %d, raw_get error!", link->fd());
} else if(ret == 0) {
//log_debug("%s", hexmem(log.key().data(), log.key().size()).c_str());
log_trace("fd: %d, skip not found: %s", link->fd(), log.dumps().c_str());
} else {
log_trace("fd: %d, %s", link->fd(), log.dumps().c_str());
link->send(log.repr(), val);
}
break;
case BinlogCommand::KDEL:
case BinlogCommand::HDEL:
case BinlogCommand::ZDEL:
case BinlogCommand::QPOP_BACK:
case BinlogCommand::QPOP_FRONT:
log_trace("fd: %d, %s", link->fd(), log.dumps().c_str());
link->send(log.repr());
break;
}
return 1;
}
示例6: proc_sync
int Slave::proc_sync(const Binlog &log, const std::vector<Bytes> &req){
switch(log.cmd()){
case BinlogCommand::KSET:
{
if(req.size() != 2){
break;
}
std::string key;
if(decode_kv_key(log.key(), &key) == -1){
break;
}
log_trace("set %s", hexmem(key.data(), key.size()).c_str());
if(ssdb->set(key, req[1], log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::KDEL:
{
std::string key;
if(decode_kv_key(log.key(), &key) == -1){
break;
}
log_trace("del %s", hexmem(key.data(), key.size()).c_str());
if(ssdb->del(key, log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::HSET:
{
if(req.size() != 2){
break;
}
std::string name, key;
if(decode_hash_key(log.key(), &name, &key) == -1){
break;
}
log_trace("hset %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->hset(name, key, req[1], log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::HDEL:
{
std::string name, key;
if(decode_hash_key(log.key(), &name, &key) == -1){
break;
}
log_trace("hdel %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->hdel(name, key, log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::ZSET:
{
if(req.size() != 2){
break;
}
std::string name, key;
if(decode_zset_key(log.key(), &name, &key) == -1){
break;
}
log_trace("zset %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->zset(name, key, req[1], log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::ZDEL:
{
std::string name, key;
if(decode_zset_key(log.key(), &name, &key) == -1){
break;
}
log_trace("zdel %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->zdel(name, key, log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::QSET:
case BinlogCommand::QPUSH_BACK:
case BinlogCommand::QPUSH_FRONT:
{
if(req.size() != 2){
break;
}
std::string name;
uint64_t seq;
//.........这里部分代码省略.........
示例7: proc_sync
int Slave::proc_sync(const Binlog &log, const std::vector<Bytes> &req){
switch(log.cmd()){
case BinlogCommand::KSET:
{
if(req.size() != 2){
break;
}
std::string key;
if(decode_kv_key(log.key(), &key) == -1){
break;
}
log_trace("set %s", hexmem(key.data(), key.size()).c_str());
if(ssdb->set(key, req[1], log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::KDEL:
{
std::string key;
if(decode_kv_key(log.key(), &key) == -1){
break;
}
log_trace("del %s", hexmem(key.data(), key.size()).c_str());
if(ssdb->del(key, log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::HSET:
{
if(req.size() != 2){
break;
}
std::string name, key;
if(decode_hash_key(log.key(), &name, &key) == -1){
break;
}
log_trace("hset %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->hset(name, key, req[1], log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::HDEL:
{
std::string name, key;
if(decode_hash_key(log.key(), &name, &key) == -1){
break;
}
log_trace("hdel %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->hdel(name, key, log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::ZSET:
{
if(req.size() != 2){
break;
}
std::string name, key;
if(decode_zset_key(log.key(), &name, &key) == -1){
break;
}
log_trace("zset %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->zset(name, key, req[1], log_type) == -1){
return -1;
}
}
break;
case BinlogCommand::ZDEL:
{
std::string name, key;
if(decode_zset_key(log.key(), &name, &key) == -1){
break;
}
log_trace("zdel %s %s",
hexmem(name.data(), name.size()).c_str(),
hexmem(key.data(), key.size()).c_str());
if(ssdb->zdel(name, key, log_type) == -1){
return -1;
}
}
break;
default:
log_error("unknown binlog, type=%d, cmd=%d", log.type(), log.cmd());
break;
}
this->last_seq = log.seq();
if(log.type() == BinlogType::COPY){
this->last_key = log.key().String();
}
this->save_status();
//.........这里部分代码省略.........
示例8: if
int BackendSync::Client::sync(BinlogQueue *logs){
Binlog log;
while(1){
int ret = 0;
uint64_t expect_seq = this->last_seq + 1;
if(this->status == Client::COPY && this->last_seq == 0){
ret = logs->find_last(&log);
}else{
ret = logs->find_next(expect_seq, &log);
}
if(ret == 0){
return 0;
}
// writes that are out of copied range will be discarded.
if(this->status == Client::COPY && log.key() > this->last_key){
log_trace("fd: %d, last_key: '%s', drop: %s",
link->fd(),
hexmem(this->last_key.data(), this->last_key.size()).c_str(),
log.dumps().c_str());
this->last_seq = log.seq();
//if(this->iter){
// delete this->iter;
// this->iter = NULL;
//}
continue;
}
if(this->last_seq != 0 && log.seq() != expect_seq){
log_warn("fd: %d, OUT_OF_SYNC! log.seq: %" PRIu64", expect_seq: %" PRIu64"",
link->fd(),
log.seq(),
expect_seq
);
this->status = Client::OUT_OF_SYNC;
return 1;
}
// update last_seq
this->last_seq = log.seq();
char type = log.type();
if(type == BinlogType::MIRROR && this->is_mirror){
if(this->last_seq - this->last_noop_seq >= 1000){
this->noop();
return 1;
}else{
continue;
}
}
break;
}
int ret = 0;
std::string val;
switch(log.cmd()){
case BinlogCommand::KSET:
case BinlogCommand::HSET:
case BinlogCommand::ZSET:
ret = backend->ssdb->raw_get(log.key(), &val);
if(ret == -1){
log_error("fd: %d, raw_get error!", link->fd());
}else if(ret == 0){
//log_debug("%s", hexmem(log.key().data(), log.key().size()).c_str());
log_trace("fd: %d, skip not found: %s", link->fd(), log.dumps().c_str());
}else{
log_trace("fd: %d, %s", link->fd(), log.dumps().c_str());
link->send(log.repr(), val);
}
break;
case BinlogCommand::KDEL:
case BinlogCommand::HDEL:
case BinlogCommand::ZDEL:
log_trace("fd: %d, %s", link->fd(), log.dumps().c_str());
link->send(log.repr());
break;
}
return 1;
}