예제 #1
0
void Slave::load_status(){
	std::string key;
	std::string seq;
	meta->hget(status_key(), "last_key", &key);
	meta->hget(status_key(), "last_seq", &seq);
	if(!key.empty()){
		this->last_key = key;
	}
	if(!seq.empty()){
		this->last_seq = str_to_uint64(seq);
	}
}
예제 #2
0
파일: slave.cpp 프로젝트: airowner/ssdb
void Slave::save_status(){
	std::string key = status_key();
	std::string status;
	status.append((char *)&this->next_seq, sizeof(uint64_t));
	status.append(this->last_key);
	meta_db->Put(leveldb::WriteOptions(), key, status);
}
예제 #3
0
파일: socket99.c 프로젝트: dgsb/socket99
/* Print an error message based on the status contained in *RES. */
void socket99_fprintf(FILE *f, socket99_result *res) {
    if (f == NULL || res == NULL) { return; }
    fprintf(f, "%s: %s\n", status_key(res->status),
        (res->status == SOCKET99_ERROR_GETADDRINFO
            ? gai_strerror(res->getaddrinfo_error)
            : strerror(res->saved_errno)));
}
예제 #4
0
파일: socket99.c 프로젝트: dgsb/socket99
/* Construct an error message in BUF, based on the status codes
 * in *RES. This has the same return value and general behavior
 * as snprintf -- if the return value is >= buf_size, the string
 * has been truncated. Returns -1 if either BUF or RES are NULL. */
int socket99_snprintf(char *buf, size_t buf_size, socket99_result *res) {
    if (buf == NULL || res == NULL) { return 0; }
    return snprintf(buf, buf_size, "%s: %s",
        status_key(res->status),
        (res->status == SOCKET99_ERROR_GETADDRINFO
            ? gai_strerror(res->getaddrinfo_error)
            : strerror(res->saved_errno)));
}
예제 #5
0
void Slave::start(){
	migrate_old_status();
	load_status();
	log_debug("status_key: %s last_seq: %" PRIu64 ", last_key: %s",
		status_key().c_str(),last_seq, hexmem(last_key.data(), last_key.size()).c_str());

	thread_quit = false;
	int err = pthread_create(&run_thread_tid, NULL, &Slave::_run_thread, this);
	if(err != 0){
		log_error("can't create thread: %s", strerror(err));
	}
}
예제 #6
0
파일: slave.cpp 프로젝트: chenld/ssdb
void Slave::load_status(){
	std::string key = status_key();
	std::string val;
	leveldb::Status s = meta_db->Get(leveldb::ReadOptions(), key, &val);
	if(s.ok()){
		if(val.size() < sizeof(uint64_t)){
			log_error("invalid format of status");
		}else{
			last_seq = *((uint64_t *)(val.data()));
			last_key.assign(val.data() + sizeof(uint64_t), val.size() - sizeof(uint64_t));
		}
	}
}
예제 #7
0
파일: slave.cpp 프로젝트: airowner/ssdb
void Slave::load_status(){
	std::string key = status_key();
	std::string status;
	leveldb::Status s;
	s = meta_db->Get(leveldb::ReadOptions(), key, &status);
	if(s.IsNotFound()){
		return;
	}
	if(s.ok()){
		if(status.size() < sizeof(uint64_t)){
			log_error("invlid format of status");
		}else{
			next_seq = *((uint64_t *)(status.data()));
			last_key = std::string(status.data() + sizeof(uint64_t), status.size() - sizeof(uint64_t));
			log_debug("load_status seq: %llu, key: %s",
				next_seq,
				hexmem(last_key.data(), last_key.size()).c_str());
		}
	}
}
예제 #8
0
void Slave::save_status(){
	std::string seq = str(this->last_seq);
	meta->hset(status_key(), "last_key", this->last_key);
	meta->hset(status_key(), "last_seq", seq);
}