int ObTabletJoin::fetch_ups_row(ObGetParam *get_param) { int ret = OB_SUCCESS; const ObUpsRow *ups_row = NULL; ObString compact_row; //用于存储ObRow的紧缩格式,内存已经分配好 const ObString *rowkey = NULL; ThreadSpecificBuffer::Buffer *buffer = NULL; if(NULL == get_param) { ret = OB_INVALID_ARGUMENT; TBSYS_LOG(WARN, "get param is null"); } if(OB_SUCCESS == ret) { buffer = thread_buffer_.get_buffer(); if(NULL == buffer) { ret = OB_ALLOCATE_MEMORY_FAILED; TBSYS_LOG(WARN, "get thread specific buffer fail:ret[%d]", ret); } else { buffer->reset(); } } if(OB_SUCCESS == ret && get_param->get_cell_size() > 0) { ups_multi_get_->reset(); ups_multi_get_->set_get_param(*get_param); ups_multi_get_->set_row_desc(ups_row_desc_); if(OB_SUCCESS != (ret = ups_multi_get_->open())) { TBSYS_LOG(WARN, "open ups multi get fail:ret[%d]", ret); } while(OB_SUCCESS == ret) { const ObRow *tmp_row_ptr = NULL; ret = ups_multi_get_->get_next_row(rowkey, tmp_row_ptr); if(OB_ITER_END == ret) { ret = OB_SUCCESS; break; } else if(OB_SUCCESS != ret) { TBSYS_LOG(WARN, "ups multi get next row fail:ret[%d]", ret); } else { ups_row = dynamic_cast<const ObUpsRow *>(tmp_row_ptr); if(NULL == ups_row) { ret = OB_ERR_UNEXPECTED; TBSYS_LOG(WARN, "shoud be ObUpsRow"); } } if(OB_SUCCESS == ret) { compact_row.assign_buffer(buffer->current(), buffer->remain()); if(OB_SUCCESS != (ret = ObUpsRowUtil::convert(*ups_row, compact_row))) { TBSYS_LOG(WARN, "convert ups row to compact row fail:ret[%d]", ret); } else if(OB_SUCCESS != (ret = ups_row_cache_.put(*rowkey, compact_row))) { TBSYS_LOG(WARN, "join cache put fail:ret[%d]", ret); } } } if(OB_SUCCESS == ret && NULL != ups_multi_get_) { if(OB_SUCCESS != (ret = ups_multi_get_->close())) { TBSYS_LOG(WARN, "close ups multi get fail:ret[%d]", ret); } } } return ret; }
int ObPacketQueue::pop_packets(tbnet::Packet** packet_arr, const int64_t ary_size, int64_t& ret_size) { int err = OB_SUCCESS; ThreadSpecificBuffer::Buffer* tb = NULL; ret_size = 0; if (NULL == packet_arr || ary_size <= 0) { TBSYS_LOG(WARN, "invalid param, packet_arr=%p, arr_size=%ld", packet_arr, ary_size); err = OB_ERROR; } else { tb = thread_buffer_->get_buffer(); if (tb == NULL) { TBSYS_LOG(ERROR, "get packet thread buffer failed, return NULL"); err = OB_ERROR; } else { tb->reset(); } } while (OB_SUCCESS == err && ret_size < ary_size) { if (head_ == NULL) { break; } else { ObPacket* packet = head_; int64_t total_size = sizeof(ObPacket) + packet->get_packet_buffer()->get_capacity(); if (tb->remain() < total_size) { if (0 == ret_size) { TBSYS_LOG(ERROR, "the thread buffer is too small, packet_size=%ld, buffer_size=%ld", total_size, tb->remain()); // discard packet ring_buffer_.pop_task(head_); head_ = (ObPacket*) head_->_next; if (head_ == NULL) { tail_ = NULL; } size_ --; err = OB_ERROR; } break; } else { char* buf = tb->current(); memcpy(buf, packet, total_size); packet_arr[ret_size] = (ObPacket*) buf; buf += sizeof(ObPacket); ((ObPacket*) packet_arr[ret_size])->set_packet_buffer(buf, packet->get_packet_buffer()->get_capacity()); // pop from queue head_ = (ObPacket*) head_->_next; if (head_ == NULL) { tail_ = NULL; } size_ --; // pop from ring buffer err = ring_buffer_.pop_task(packet); if (OB_SUCCESS != err) { TBSYS_LOG(ERROR, "failed to pop task, err=%d", err); } tb->advance(total_size); ++ret_size; } } } return err; }