ObRowCompaction::ObRowCompaction() : NODES_NUM_(65536), nodes_(NULL), list_(NULL), tail_(NULL), cur_version_(0), iter_(NULL), is_row_changed_(false), row_del_node_(), row_nop_node_(), row_not_exist_node_(), prev_cell_(NULL), cur_cell_() { if (NULL == (nodes_ = (ObjNode*)ob_malloc(sizeof(ObjNode) * NODES_NUM_, ObModIds::OB_ROW_COMPACTION))) { TBSYS_LOG(ERROR, "new obj_nodes array fail"); } else { memset(nodes_, 0, sizeof(ObjNode) * NODES_NUM_); row_del_node_.version = 0; row_del_node_.column_id = OB_INVALID_ID; row_del_node_.value.set_ext(ObActionFlag::OP_DEL_ROW); row_del_node_.next = NULL; row_nop_node_.version = 0; row_nop_node_.column_id = OB_INVALID_ID; row_nop_node_.value.set_ext(ObActionFlag::OP_NOP); row_nop_node_.next = NULL; row_not_exist_node_.version = 0; row_not_exist_node_.column_id = OB_INVALID_ID; row_not_exist_node_.value.set_ext(ObActionFlag::OP_ROW_DOES_NOT_EXIST); row_not_exist_node_.next = NULL; } }
int ObStringBuf :: alloc_mem_(const int64_t size, void*& ptr) { int err = OB_SUCCESS; if (size <= 0) { TBSYS_LOG(WARN, "invalid param, size=%ld", size); err = OB_INVALID_ARGUMENT; } else { ptr = ob_malloc(size, mod_id_); if (NULL == ptr) { TBSYS_LOG(WARN, "failed to alloc mem, size=%ld", size); err = OB_ERROR; } else { total_virt_ += size; } } return err; }
FIFOAllocator::Page *FIFOAllocator::alloc_page_() { Page *ret = NULL; if (total_limit_ >= ATOMIC_ADD(&allocated_size_, page_size_)) { free_list_.pop(ret); if (NULL == ret) { ret = (Page*)ob_malloc(page_size_ + sizeof(Page), mod_id_); if (NULL == ret) { TBSYS_LOG(WARN, "alloc from system fail size=%ld", page_size_ + sizeof(Page)); } } if (NULL != ret) { ret->ref_cnt = 0; ret->pos = 0; } else { ATOMIC_ADD(&allocated_size_, -page_size_); } } else { ATOMIC_ADD(&allocated_size_, -page_size_); } return ret; }
ObSchemaManagerWrapper::ObSchemaManagerWrapper() : schema_mgr_buffer_(NULL), schema_mgr_impl_(NULL) { void *schema_mgr_buffer_ = ob_malloc(sizeof(ObSchemaManager)); schema_mgr_impl_ = new(schema_mgr_buffer_) ObSchemaManager(); if (NULL == schema_mgr_impl_) { TBSYS_LOG(WARN, "new schema mgr fail"); } }
ObSSTableSchema* create_sstable_schema() { char* schema_buf = static_cast<char*>(ob_malloc(sizeof(ObSSTableSchema))); EXPECT_TRUE(NULL != schema_buf); ObSSTableSchema* schema = new (schema_buf) ObSSTableSchema(); EXPECT_TRUE(NULL != schema); return schema; }
int ObPermInfoKey::build_get_param(ObGetParam & get_param) { int ret = OB_SUCCESS; ObCellInfo cell_info; ObRowkey rowkey; ObObj rowkey_obj; ObVersionRange ver_range; int64_t pos = 0; if (NULL == buffer_) { buffer_ = reinterpret_cast<char*>(ob_malloc(BUF_SIZE, ObModIds::OB_PERM_INFO)); } if (NULL != buffer_) { int64_t encode_pos = pos; ret = serialization::encode_i64(buffer_, BUF_SIZE, encode_pos, table_id_); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "encode failed table_id=%ld", table_id_); } else { memcpy(buffer_ + encode_pos, user_name_, length_); encode_pos += length_; rowkey_obj.set_varchar( ObString(0, static_cast<int32_t>(encode_pos - pos), buffer_ + pos)); rowkey.assign(&rowkey_obj, 1); get_param.set_is_result_cached(true); cell_info.table_id_ = PERM_TABLE_ID; cell_info.row_key_ = rowkey; cell_info.column_id_ = PERM_COL_ID; ret = get_param.add_cell(cell_info); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "Get param add cell failed table_id[%lu]", cell_info.table_id_); } else { ver_range.start_version_ = 0; ver_range.end_version_ = INT64_MAX - 1; ver_range.border_flag_.set_inclusive_start(); ver_range.border_flag_.set_inclusive_end(); get_param.set_version_range(ver_range); } } } else { TBSYS_LOG(ERROR, "malloc key buffer failed"); ret = OB_ERROR; } return ret; }
int ObSKeyInfoKey::build_get_param(ObGetParam& get_param) { int ret = OB_SUCCESS; ObCellInfo cell_info; ObRowkey rowkey; ObObj rowkey_obj; ObVersionRange ver_range; int64_t pos = 0; if (NULL == buffer_) { buffer_ = reinterpret_cast<char*>(ob_malloc(BUF_SIZE, ObModIds::OB_SKEY_INFO_KEY)); } ret = serialization::encode_i64(buffer_, BUF_SIZE, pos, skey_version_); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "encode failed pkey_version=%ld", skey_version_); } else { rowkey_obj.set_varchar(ObString(0, static_cast<int32_t>(pos), buffer_)); rowkey.assign(&rowkey_obj, 1); get_param.reset(); get_param.set_is_result_cached(true); cell_info.table_id_ = SKEY_TABLE_ID; cell_info.row_key_ = rowkey; cell_info.column_id_ = SKEY_COL_ID; ret = get_param.add_cell(cell_info); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "Get param add cell failed table_id[%lu]", cell_info.table_id_); } else { ver_range.start_version_ = 0; ver_range.end_version_ = INT64_MAX - 1; ver_range.border_flag_.set_inclusive_start(); ver_range.border_flag_.set_inclusive_end(); get_param.set_version_range(ver_range); } } return ret; }
ThreadSpecificBuffer::Buffer* ThreadSpecificBuffer::get_buffer() const { Buffer * buffer = NULL; if (INVALID_THREAD_KEY != key_ && size_ > 0) { void* ptr = pthread_getspecific(key_); if (NULL == ptr) { ptr = ob_malloc(size_ + sizeof(Buffer), ObModIds::OB_THREAD_BUFFER); if (NULL != ptr) { int ret = pthread_setspecific(key_, ptr); if (0 != ret) { TBSYS_LOG(ERROR, "pthread_setspecific failed:%d", ret); ob_free(ptr); ptr = NULL; } else { buffer = new (ptr) Buffer(static_cast<char*>(ptr) + sizeof(Buffer), size_); } } else { // malloc failed; TBSYS_LOG(ERROR, "malloc thread specific memeory failed."); } } else { // got exist ptr; buffer = reinterpret_cast<Buffer*>(ptr); } } else { TBSYS_LOG(ERROR, "thread key must be initialized " "and size must great than zero, key:%u,size:%d", key_, size_); } return buffer; }
int ObUserInfoKey:: build_get_param(ObGetParam& get_param) { int ret = OB_SUCCESS; ObCellInfo cell_info; ObString rowkey; ObVersionRange ver_range; if (NULL == buffer_) { buffer_ = reinterpret_cast<char*>(ob_malloc(BUF_SIZE)); } if (NULL != buffer_) { memcpy(buffer_, user_name_, length_); rowkey.assign(buffer_, static_cast<int32_t>(length_)); get_param.set_is_result_cached(true); cell_info.table_id_ = USER_TABLE_ID; cell_info.row_key_ = rowkey; cell_info.column_id_ = USER_COL_ID; ret = get_param.add_cell(cell_info); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "Get param add cell failed table_id[%lu]", cell_info.table_id_); } else { ver_range.start_version_ = 0; ver_range.end_version_ = INT64_MAX - 1; ver_range.border_flag_.set_inclusive_start(); ver_range.border_flag_.set_inclusive_end(); get_param.set_version_range(ver_range); } } else { TBSYS_LOG(ERROR, "malloc key buffer failed"); ret = OB_ERROR; } return ret; }
int ObTicketQueue::init(int64_t queue_len) { int err = OB_SUCCESS; if (queue_len <= 0) { err = OB_INVALID_ARGUMENT; } else if (NULL != items_) { err = OB_INIT_TWICE; } else if (NULL == (items_ = (Item*)ob_malloc(sizeof(Item) * queue_len, ObModIds::TICKET_QUEUE))) { err = OB_MEM_OVERFLOW; TBSYS_LOG(ERROR, "ob_malloc(%ld): fail", sizeof(Item)*queue_len); } else { memset(items_, 0, sizeof(Item) * queue_len); queue_len_ = queue_len; } return err; }
bool ObRegex::init(const char* pattern, int flags) { bool bret = false; if (init_) { TBSYS_LOG(WARN, "this=%p already inited", this); } else if (NULL == pattern) { TBSYS_LOG(WARN, "invalid param pattern=%p", pattern); } else { int tmp_ret = regcomp(®_, pattern, flags); if (0 != tmp_ret) { TBSYS_LOG(WARN, "regcomp fail ret=%d", tmp_ret); } else { nmatch_ = reg_.re_nsub + 1; match_ = (regmatch_t*)ob_malloc(sizeof(regmatch_t) * nmatch_, ObModIds::OB_REGEX); if (NULL == match_) { TBSYS_LOG(WARN, "create the regmatch object fail"); regfree(®_); } else { init_ = true; bret = true; } } } return bret; }