本文整理汇总了C++中data_entry类的典型用法代码示例。如果您正苦于以下问题:C++ data_entry类的具体用法?C++ data_entry怎么用?C++ data_entry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了data_entry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get
int tair_manager::get(int area, data_entry &key, data_entry &value)
{
if (status != STATUS_CAN_WORK) {
return TAIR_RETURN_SERVER_CAN_NOT_WORK;
}
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
data_entry mkey = key;
mkey.merge_area(area);
int bucket_number = get_bucket_number(key);
log_debug("get request will server in bucket: %d", bucket_number);
PROFILER_BEGIN("get from storage engine");
int rc = storage_mgr->get(bucket_number, mkey, value);
PROFILER_END();
key.data_meta = mkey.data_meta;
TAIR_STAT.stat_get(area, rc);
return rc;
}
示例2: __get_items
int item_manager::__get_items(tair_manager *tair_mgr,int area,data_entry& key,data_entry& value,vector<any>& items,int type /*ELEMENT_TYPE_INVALID*/)
{
int ret = TAIR_RETURN_FAILED;
if( (ret = tair_mgr->get(area,key,value)) != TAIR_RETURN_SUCCESS ){
return ret;
}
if (!tair_mgr->get_storage_manager()->test_flag(value.data_meta.flag, TAIR_ITEM_FLAG_ITEM)) {
log_debug("is not items type,flag:%d",value.data_meta.flag);
return TAIR_RETURN_TYPE_NOT_MATCH;
}
if(type != ELEMENT_TYPE_INVALID){ //need check type
uint32_t attr = get_attribute(value);
log_debug("__get_items:type:%d,attr:%u",type,VAL_TYPE(attr));
if(static_cast<uint32_t>(type) != VAL_TYPE(attr)){
return TAIR_RETURN_TYPE_NOT_MATCH;
}
}
if( !parse_array(get_items_addr(value),value.get_data()+value.get_size(),items)){
log_debug("parse_array failed");
return TAIR_RETURN_SERIALIZE_ERROR;
}
if(items.size() == 0){ //empty
return TAIR_RETURN_ITEM_EMPTY;
}
return 0;
}
示例3: log
void update_log::log(sn_operation_type operation_type, data_entry &key, data_entry &value, uint16_t db_id)
{
uint key_size = key.get_size();
if (key.data_meta.keysize == 0){
key.data_meta.keysize = key_size;
}
log_debug("key length: %d, value length:%d", key_size, value.get_size());
uint value_size = 0;
uint header_size = sizeof(item_meta_info);
int total_size = header_size + key_size + 3 ;
if (operation_type == SN_PUT) {
value_size = value.get_size();
if (key.data_meta.valsize == 0){
key.data_meta.valsize = value_size;
}
total_size += value_size;
}
char *log_str = (char *)malloc(total_size);
memcpy(log_str, &(key.data_meta), header_size);
char *ptr = log_str + header_size;
*((int8_t *)ptr) = (int8_t)operation_type;
*((uint16_t *)(ptr + 1)) = (uint16_t)db_id;
memcpy(ptr + 3, key.get_data(), key_size);
if (operation_type == SN_PUT) {
memcpy(ptr + 3 + key_size, value.get_data(), value_size);
}
PROFILER_BEGIN("write migrate log");
writer->write(log_str, total_size);
PROFILER_END();
free(log_str);
}
示例4: put
int tair_manager::put(int area, data_entry &key, data_entry &value, int expire_time)
{
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (value.get_size() >= TAIR_MAX_DATA_SIZE || value.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
data_entry mkey = key; // key merged with area
mkey.merge_area(area);
int bucket_number = get_bucket_number(key);
log_debug("put request will server in bucket: %d key =%s ", bucket_number, key.get_data());
key.data_meta.log_self();
int op_flag = get_op_flag(bucket_number, key.server_flag);
int rc = TAIR_RETURN_SERVER_CAN_NOT_WORK;
PROFILER_BEGIN("should write local?");
if (should_write_local(bucket_number, key.server_flag, op_flag, rc) == false) {
PROFILER_END();
return rc;
}
PROFILER_END();
// save into the storage engine
bool version_care = op_flag & TAIR_OPERATION_VERSION;
PROFILER_BEGIN("put into storage");
rc = storage_mgr->put(bucket_number, mkey, value, version_care, expire_time);
PROFILER_END();
if (rc == TAIR_RETURN_SUCCESS ) {
key.data_meta = mkey.data_meta;
if (op_flag & TAIR_OPERATION_DUPLICATE) {
vector<uint64_t> slaves;
get_slaves(key.server_flag, bucket_number, slaves);
if (slaves.empty() == false) {
PROFILER_BEGIN("do duplicate");
duplicator->duplicate_data(area, &key, &value, bucket_number, slaves);
PROFILER_END();
}
}
if (migrate_log != NULL && need_do_migrate_log(bucket_number)) {
PROFILER_BEGIN("do migrate log");
migrate_log->log(SN_PUT, mkey, value, bucket_number);
PROFILER_END();
}
}
TAIR_STAT.stat_put(area);
return rc;
}
示例5: dump_key
void RequestProcessor::dump_key(const data_entry &key, const char *msg) {
if (msg == NULL) {
msg = "error";
}
char *d_str = util::string_util::bin2ascii(key.get_data(), key.get_size(), NULL, 0);
log_error("%s, key: %s", msg, d_str);
free(d_str);
}
示例6: remove
int tair_manager::remove(int area, data_entry &key)
{
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
data_entry mkey = key;
mkey.merge_area(area);
int bucket_number = get_bucket_number(key);
int op_flag = get_op_flag(bucket_number, key.server_flag);
int rc = TAIR_RETURN_SERVER_CAN_NOT_WORK;
PROFILER_BEGIN("should write local?");
if (should_write_local(bucket_number, key.server_flag, op_flag, rc) == false) {
PROFILER_END();
return rc;
}
PROFILER_END();
bool version_care = op_flag & TAIR_OPERATION_VERSION;
PROFILER_BEGIN("remove from storage engine");
rc = storage_mgr->remove(bucket_number, mkey, version_care);
PROFILER_END();
if (rc == TAIR_RETURN_SUCCESS || rc == TAIR_RETURN_DATA_NOT_EXIST) {
if (op_flag & TAIR_OPERATION_DUPLICATE) {
vector<uint64_t> slaves;
get_slaves(key.server_flag, bucket_number, slaves);
if (slaves.empty() == false) {
PROFILER_BEGIN("do duplicate");
duplicator->duplicate_data(area, &key, NULL, bucket_number, slaves);
PROFILER_END();
}
}
if (migrate_log != NULL && need_do_migrate_log(bucket_number)) {
PROFILER_BEGIN("do migrate log");
migrate_log->log(SN_REMOVE, mkey, mkey, bucket_number);
PROFILER_END();
}
}
TAIR_STAT.stat_remove(area);
return rc;
}
示例7: get_item_count
int tair_manager::get_item_count(int area, data_entry& key)
{
if (status != STATUS_CAN_WORK) {
return TAIR_RETURN_SERVER_CAN_NOT_WORK;
}
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
return json::item_manager::get_item_count(this,area,key);
}
示例8: guard
int tair_manager::add_count(int area, data_entry &key, int count, int init_value, int *result_value, int expire_time)
{
if (status != STATUS_CAN_WORK) {
return TAIR_RETURN_SERVER_CAN_NOT_WORK;
}
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
tbsys::CThreadGuard guard(&counter_mutex[get_mutex_index(key)]);
// get from storage engine
data_entry old_value;
PROFILER_BEGIN("get from storage");
int rc = get(area, key, old_value);
PROFILER_END();
log_debug("get result: %d, flag: %d", rc, key.data_meta.flag);
key.data_meta.log_self();
if (rc == TAIR_RETURN_SUCCESS && IS_ADDCOUNT_TYPE(key.data_meta.flag)) {
// old value exist
int32_t *v = (int32_t *)(old_value.get_data() + ITEM_HEAD_LENGTH);
log_debug("old count: %d, new count: %d, init value: %d", (*v), count, init_value);
*v += count;
*result_value = *v;
} else if(rc == TAIR_RETURN_SUCCESS){
//exist,but is not add_count,return error;
log_debug("cann't override old value");
return TAIR_RETURN_CANNOT_OVERRIDE;
}else {
// old value not exist
char fv[6]; // 2 + sizeof(int)
*((short *)fv) = 0x1600; // for java header
*result_value = init_value + count;
*((int32_t *)(fv + 2)) = *result_value;
old_value.set_data(fv, 6);
}
old_value.data_meta.flag |= TAIR_ITEM_FLAG_ADDCOUNT;
log_debug("before put flag: %d", old_value.data_meta.flag);
PROFILER_BEGIN("save count into storage");
int result = put(area, key, old_value, expire_time);
PROFILER_END();
return result;
}
示例9: get_from_local_cluster
int get_from_local_cluster(ClusterHandler& handler, data_entry& key, data_entry*& value, bool& skip)
{
int ret = handler.client()->get_hidden(key.get_area(), key, value);
if (ret == TAIR_RETURN_DATA_NOT_EXIST || ret == TAIR_RETURN_DATA_EXPIRED)
{
log_warn("key not exist local");
skip = true;
ret = TAIR_RETURN_SUCCESS;
}
else if (ret != TAIR_RETURN_SUCCESS && ret != TAIR_RETURN_HIDDEN)
{
log_error("get local fail, ret: %d", ret);
}
else
{
key.data_meta.cdate = value->data_meta.cdate;
key.data_meta.edate = value->data_meta.edate;
key.data_meta.mdate = value->data_meta.mdate;
key.data_meta.version = value->data_meta.version;
key.data_meta.keysize = value->data_meta.keysize;
key.data_meta.valsize = value->data_meta.valsize;
ret = TAIR_RETURN_SUCCESS;
}
return ret;
}
示例10: get_items
int tair_manager::get_items(int area,
data_entry& key,
int offset, int count, data_entry& value /*out*/,
int type /*=ELEMENT_TYPE_INVALID*/)
{
if (status != STATUS_CAN_WORK) {
return TAIR_RETURN_SERVER_CAN_NOT_WORK;
}
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
return json::item_manager::get_items(this,area,key,offset,count,value,type);
}
示例11: remove_items
int tair_manager::remove_items(int area,
data_entry& key, int offset, int count)
{
if (status != STATUS_CAN_WORK) {
return TAIR_RETURN_SERVER_CAN_NOT_WORK;
}
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
//tbsys::CThreadGuard guard(&removeItemsMutex[getMutexIndex(key)]);
tbsys::CThreadGuard guard(&item_mutex[get_mutex_index(key)]);
return json::item_manager::remove_items(this,area,key,offset,count);
}
示例12: get_and_remove
int tair_manager::get_and_remove(int area,
data_entry& key,
int offset, int count, data_entry& value /*out*/,
int type /*=ELEMENT_TYPE_INVALID*/)
{
if (status != STATUS_CAN_WORK) {
return TAIR_RETURN_SERVER_CAN_NOT_WORK;
}
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (area < 0 || area >= TAIR_MAX_AREA_COUNT) {
return TAIR_RETURN_INVALID_ARGUMENT;
}
//tbsys::CThreadGuard guard(&getAndRemoveItemsMutex[getMutexIndex(key)]);
tbsys::CThreadGuard guard(&item_mutex[get_mutex_index(key)]);
return json::item_manager::get_and_remove(this,area,key,offset,count,value,type);
}
示例13: add_del_key
//add del key
bool add_del_key(const data_entry& key)
{
uint temp = len + key.get_size() + 1;
if (temp > MAX_MUPDATE_PACKET_SIZE){
return false;
}
if (key_and_values == NULL) {
key_and_values = new tair_operc_vector();
}
operation_record *oprec = new operation_record();
oprec->key = new data_entry();
oprec->key->clone(key);
//log_debug("addkeyis %d", oprec->key->m_isMerged);
oprec->operation_type = 2;
oprec->value = NULL;
key_and_values->push_back(oprec);
count++;
len += key.get_size() + 1;
return true;
}
示例14: direct_remove
int tair_manager::direct_remove(data_entry &key)
{
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
data_entry akey = key;
akey.decode_area();
int bucket_number = get_bucket_number(akey);
int rc = storage_mgr->remove(bucket_number, key, false);
if (rc == TAIR_RETURN_DATA_NOT_EXIST) {
// for migrate, return SUCCESS
rc = TAIR_RETURN_SUCCESS;
}
TAIR_STAT.stat_remove(akey.area);
return rc;
}
示例15: direct_put
int tair_manager::direct_put(data_entry &key, data_entry &value)
{
if (key.get_size() >= TAIR_MAX_KEY_SIZE || key.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
if (value.get_size() >= TAIR_MAX_DATA_SIZE || value.get_size() < 1) {
return TAIR_RETURN_ITEMSIZE_ERROR;
}
data_entry akey = key;
int area = akey.decode_area();
key.area = area;
int bucket_number = get_bucket_number(akey);
int rc = storage_mgr->put(bucket_number, key, value, false, 0);
TAIR_STAT.stat_put(area);
return rc;
}