当前位置: 首页>>代码示例>>C++>>正文


C++ Binlog类代码示例

本文整理汇总了C++中Binlog的典型用法代码示例。如果您正苦于以下问题:C++ Binlog类的具体用法?C++ Binlog怎么用?C++ Binlog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Binlog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: log_info

BinlogQueue::BinlogQueue(leveldb::DB *db, bool enabled, int capacity){
	this->db = db;
	this->min_seq = 0;
	this->last_seq = 0;
	this->tran_seq = 0;
	this->capacity = capacity;
	this->enabled = enabled;
	
	Binlog log;
	if(this->find_last(&log) == 1){
		this->last_seq = log.seq();
	}
	if(this->find_next(0, &log) == 1){
		this->min_seq = log.seq();
	}
	if(this->enabled){
		log_info("binlogs capacity: %d, min: %" PRIu64 ", max: %" PRIu64 ",",
			this->capacity, this->min_seq, this->last_seq);
	}

	// start cleaning thread
	if(this->enabled){
		thread_quit = false;
		pthread_t tid;
		int err = pthread_create(&tid, NULL, &BinlogQueue::log_clean_thread_func, this);
		if(err != 0){
			log_fatal("can't create thread: %s", strerror(err));
			exit(0);
		}
	}
}
开发者ID:Mumujane,项目名称:ssdb,代码行数:31,代码来源:binlog.cpp

示例2: switch

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;
}
开发者ID:ddling1216,项目名称:ssdb,代码行数:28,代码来源:slave.cpp

示例3: switch

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;
}
开发者ID:sunxiaojun2014,项目名称:qssdb,代码行数:31,代码来源:slave.cpp

示例4: log_trace

// TESTING, slow, so not used
void BinlogQueue::merge(){
	std::map<std::string, uint64_t> key_map;
	uint64_t start = min_seq;
	uint64_t end = last_seq;
	int reduce_count = 0;
	int total = 0;
	total = end - start + 1;
	(void)total; // suppresses warning
	log_trace("merge begin");
	for(; start <= end; start++){
		Binlog log;
		if(this->get(start, &log) == 1){
			if(log.type() == BinlogType::NOOP){
				continue;
			}
			std::string key = log.key().String();
			std::map<std::string, uint64_t>::iterator it = key_map.find(key);
			if(it != key_map.end()){
				uint64_t seq = it->second;
				this->update(seq, BinlogType::NOOP, BinlogCommand::NONE, "");
				//log_trace("merge update %" PRIu64 " to NOOP", seq);
				reduce_count ++;
			}
			key_map[key] = log.seq();
		}
	}
	log_trace("merge reduce %d of %d binlogs", reduce_count, total);
}
开发者ID:Mumujane,项目名称:ssdb,代码行数:29,代码来源:binlog.cpp

示例5: log_info

BinlogQueue::BinlogQueue(leveldb::DB *db){
	this->db = db;
	this->min_seq = 0;
	this->last_seq = 0;
	this->tran_seq = 0;
	this->capacity = LOG_QUEUE_SIZE;
	this->no_log_ = false;
	
	Binlog log;
	if(this->find_last(&log) == 1){
		this->last_seq = log.seq();
	}
	if(this->last_seq > LOG_QUEUE_SIZE){
		this->min_seq = this->last_seq - LOG_QUEUE_SIZE;
	}else{
		this->min_seq = 0;
	}
	// TODO: use binary search to find out min_seq
	if(this->find_next(this->min_seq, &log) == 1){
		this->min_seq = log.seq();
	}
	log_info("binlogs capacity: %d, min: %" PRIu64 ", max: %" PRIu64 ",", capacity, min_seq, last_seq);

	//this->merge();
		/*
	int noops = 0;
	int total = 0;
	uint64_t seq = this->min_seq;
	while(this->find_next(seq, &log) == 1){
		total ++;
		seq = log.seq() + 1;
		if(log.type() != BinlogType::NOOP){
			std::string s = log.dumps();
			//log_trace("%s", s.c_str());
			noops ++;
		}
	}
	log_debug("capacity: %d, min: %" PRIu64 ", max: %" PRIu64 ", noops: %d, total: %d",
		capacity, min_seq, last_seq, noops, total);
		*/

	// start cleaning thread
	thread_quit = false;
	pthread_t tid;
	int err = pthread_create(&tid, NULL, &BinlogQueue::log_clean_thread_func, this);
	if(err != 0){
		log_fatal("can't create thread: %s", strerror(err));
		exit(0);
	}
}
开发者ID:jcai,项目名称:ssdb,代码行数:50,代码来源:binlog.cpp

示例6: switch

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;
}
开发者ID:1514louluo,项目名称:ssdb,代码行数:17,代码来源:slave.cpp

示例7: proc_noop

int Slave::proc_noop(const Binlog &log, const std::vector<Bytes> &req){
	uint64_t seq = log.seq();
	if(this->last_seq != seq){
		log_debug("noop last_seq: %" PRIu64 ", seq: %" PRIu64 "", this->last_seq, seq);
		this->last_seq = seq;
		this->save_status();
	}
	return 0;
}
开发者ID:sunxiaojun2014,项目名称:qssdb,代码行数:9,代码来源:slave.cpp

示例8: log_info

BinlogQueue::BinlogQueue(leveldb::DB *db, bool enabled, int capacity){
	this->db = db;
	this->min_seq = 0;
	this->last_seq = 0;
	this->tran_seq = 0;
	this->capacity = capacity;
	this->enabled = enabled;
	
	Binlog log;
	if(this->find_last(&log) == 1){
		this->last_seq = log.seq();
	}
	// 下面这段代码是可能性能非常差!
	//if(this->find_next(0, &log) == 1){
	//	this->min_seq = log.seq();
	//}
	if(this->last_seq > this->capacity){
		this->min_seq = this->last_seq - this->capacity;
	}else{
		this->min_seq = 0;
	}
	if(this->find_next(this->min_seq, &log) == 1){
		this->min_seq = log.seq();
	}
	if(this->enabled){
		log_info("binlogs capacity: %d, min: %" PRIu64 ", max: %" PRIu64 ",",
			this->capacity, this->min_seq, this->last_seq);
		// 这个方法有性能问题
		// 但是, 如果不执行清理, 如果将 capacity 修改大, 可能会导致主从同步问题
		//this->clean_obsolete_binlogs();
	}

	// start cleaning thread
	if(this->enabled){
		thread_quit = false;
		pthread_t tid;
		int err = pthread_create(&tid, NULL, &BinlogQueue::log_clean_thread_func, this);
		if(err != 0){
			log_fatal("can't create thread: %s", strerror(err));
			exit(0);
		}
	}
}
开发者ID:Amano-Ginji,项目名称:ssdb,代码行数:43,代码来源:binlog.cpp

示例9: log_info

// 创建一个操作日志队列
BinlogQueue::BinlogQueue(leveldb::DB *db, bool enabled){
	this->db = db;
	this->min_seq = 0;
	this->last_seq = 0;
	this->tran_seq = 0;
	// 队列空间
	this->capacity = LOG_QUEUE_SIZE;
	this->enabled = enabled;
	
	Binlog log;
	// 从leveldb中查找之前最大的序列号
	if(this->find_last(&log) == 1){
		this->last_seq = log.seq();
	}
	// 超过了队列长度,最小应该是减去队列长度的序列号
	if(this->last_seq > LOG_QUEUE_SIZE){
		this->min_seq = this->last_seq - LOG_QUEUE_SIZE;
	}else{
	    // 否则,最小序列号是0
		this->min_seq = 0;
	}
	// TODO: use binary search to find out min_seq
	// 通过leveldb中记录的操作日志更新最小序列号
	if(this->find_next(this->min_seq, &log) == 1){
		this->min_seq = log.seq();
	}
	if(this->enabled){
		log_info("binlogs capacity: %d, min: %" PRIu64 ", max: %" PRIu64 ",", capacity, min_seq, last_seq);
	}

	// start cleaning thread
	// 启动线程进行操作日志的清理
	if(this->enabled){
		thread_quit = false;
		pthread_t tid;
		int err = pthread_create(&tid, NULL, &BinlogQueue::log_clean_thread_func, this);
		if(err != 0){
			log_fatal("can't create thread: %s", strerror(err));
			exit(0);
		}
	}
}
开发者ID:qwang2505,项目名称:ssdb-source-comments,代码行数:43,代码来源:binlog.cpp

示例10: log_error

int Slave::proc(const std::vector<Bytes> &req){
	Binlog log;
	if(log.load_format_key(req[0]) == -1){
		log_error("invalid binlog!");
		return 0;
	}
	const char *sync_type = this->is_mirror? "mirror" : "sync";
	switch(log.type()){
		case BinlogType::NOOP:
			return this->proc_noop(log, req);
			break;
		case BinlogType::COPY:{
			status = COPY;
			if(++copy_count % 1000 == 1){
				log_info("copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
					copy_count, this->last_seq, log.seq());
			}
			if(req.size() >= 2){
				log_debug("[%s] %s [%d]", sync_type, log.dumps().c_str(), req[1].size());
			}else{
				log_debug("[%s] %s", sync_type, log.dumps().c_str());
			}
			this->proc_copy(log, req);
			break;
		}
		case BinlogType::SYNC:
		case BinlogType::MIRROR:{
			status = SYNC;
			if(++sync_count % 1000 == 1){
				log_info("sync_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
					sync_count, this->last_seq, log.seq());
			}
			if(req.size() >= 2){
				log_debug("[%s] %s [%d]", sync_type, log.dumps().c_str(), req[1].size());
			}else{
				log_debug("[%s] %s", sync_type, log.dumps().c_str());
			}
			this->proc_sync(log, req);
			break;
		}
		default:
			break;
	}
	return 0;
}
开发者ID:sunxiaojun2014,项目名称:qssdb,代码行数:45,代码来源:slave.cpp

示例11: log_error

int Slave::proc(const std::vector<Bytes> &req){
	Binlog log;
	if(log.load(req[0].Slice()) == -1){
		log_error("invalid binlog!");
		return 0;
	}
	if(log.type() != BinlogType::NOOP){
		if(this->is_mirror){
			log_debug("[mirror] %s", log.dumps().c_str());
		}else{
			log_debug("[sync] %s", log.dumps().c_str());
		}
	}
	switch(log.type()){
		case BinlogType::NOOP:
			return this->proc_noop(log, req);
			break;
		case BinlogType::COPY:
			return this->proc_copy(log, req);
			break;
		case BinlogType::SYNC:
		case BinlogType::MIRROR:
			return this->proc_sync(log, req);
			break;
		default:
			break;
	}
	return 0;
}
开发者ID:chenld,项目名称:ssdb,代码行数:29,代码来源:slave.cpp

示例12: log_error

int Slave::proc(const std::vector<Bytes> &req){
	Binlog log;
	if(log.load(req[0].Slice()) == -1){
		log_error("invalid binlog!");
		return 0;
	}
	switch(log.type()){
		case BinlogType::NOOP:
			return this->proc_noop(log, req);
			break;
		case BinlogType::COPY:{
			if(++copy_count % 1000 == 1){
				log_info("copy_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
					copy_count, this->last_seq, log.seq());
			}
			if(this->is_mirror){
				log_trace("[mirror] %s", log.dumps().c_str());
			}else{
				log_trace("[sync] %s", log.dumps().c_str());
			}
			return this->proc_copy(log, req);
			break;
		}
		case BinlogType::SYNC:
		case BinlogType::MIRROR:{
			if(++sync_count % 1000 == 1){
				log_info("sync_count: %" PRIu64 ", last_seq: %" PRIu64 ", seq: %" PRIu64 "",
					sync_count, this->last_seq, log.seq());
			}
			if(this->is_mirror){
				log_debug("[mirror] %s", log.dumps().c_str());
			}else{
				log_debug("[sync] %s", log.dumps().c_str());
			}
			return this->proc_sync(log, req);
			break;
		}
		default:
			break;
	}
	return 0;
}
开发者ID:29n,项目名称:ssdb,代码行数:42,代码来源:slave.cpp

示例13: switch

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;
}
开发者ID:chenld,项目名称:ssdb,代码行数:16,代码来源:slave.cpp

示例14: 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;
}
开发者ID:Mumujane,项目名称:ssdb,代码行数:87,代码来源:backend_sync.cpp

示例15: 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;
		}
		// 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;
}
开发者ID:preillyme,项目名称:ssdb,代码行数:78,代码来源:backend_sync.cpp


注:本文中的Binlog类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。