Ejemplo n.º 1
0
int ObMergerTabletLocationCache::update(const uint64_t table_id, const ObString & rowkey,
    const ObMergerTabletLocationList & location)
{
  int ret = OB_SUCCESS;
  if (!init_)
  {
    TBSYS_LOG(ERROR, "%s", "check init failed");
    ret = OB_INNER_STAT_ERROR;
  }
  else if ((0 == rowkey.length()) || (NULL == rowkey.ptr()))
  {
    TBSYS_LOG(ERROR, "%s", "check rowkey length failed");
    ret = OB_INPUT_PARAM_ERROR;
  }
  else
  {
    char * temp = (char *)ob_malloc(sizeof(table_id) + rowkey.length(),ObModIds::OB_MS_LOCATION_CACHE);
    if (NULL == temp)
    {
      TBSYS_LOG(ERROR, "check ob malloc failed:size[%lu], pointer[%p]", 
          sizeof(table_id) + rowkey.length(), temp);
      ret = OB_ALLOCATE_MEMORY_FAILED;
    }
    else
    {
      ObRange range;
      ObString CacheKey;
      // encode table_id + rowkey as CacheKey
      *((uint64_t *) temp) = table_id;
      memcpy(temp + sizeof(uint64_t), rowkey.ptr(), rowkey.length());
      CacheKey.assign(temp, static_cast<int32_t>(sizeof(table_id) + rowkey.length()));
      // get the pair according to the key
      ObCachePair pair;
      ret = tablet_cache_.get(CacheKey, pair);
      if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(DEBUG, "find tablet from cache failed:table_id[%lu], length[%d]",
            table_id, rowkey.length());
      }
      else
      {
        int64_t pos = 0;
        // TODO double check pair.key whether as equal with CacheKey
        ret = range.deserialize(pair.get_key().ptr(), pair.get_key().length(), pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "deserialize tablet range failed:table_id[%lu], ret[%d]",
              table_id, ret);
        }
        else
        {
          ret = set(range, location);
        }
      }
      // destory the temp buffer
      ob_free(temp);
    }
  }
  return ret;
}
Ejemplo n.º 2
0
int MockUpdateServer::handle_mock_scan(ObPacket *ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObScanParam scan_param;
  if (OB_SUCCESS == ret)
  {
    ret = scan_param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check scan_param failed");
    }
  }

  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake cell
    ObCellInfo cell;
    ObScanner scanner;
    ObString row_key;
    ObString column_name;
    cell.table_id_ = scan_param.get_table_id();
    if (mock::join_table_id == cell.table_id_)
    {
      for (int32_t i = 0; i < scan_param.get_column_id_size(); i++)
      {
        if (mock::join_column1_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (mock::join_column2_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column2_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column2_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column2_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_,
                    scan_param.get_column_id()[i]);
          ret = OB_ERR_UNEXPECTED;
        }
      }
    }
    else if (mock::table_id == cell.table_id_)
    {
      for (int32_t i = 0; i < scan_param.get_column_id_size(); i++)
      {
        if (mock::column1_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::rowkey,strlen(mock::rowkey));
          cell.column_id_ = mock::column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (mock::column2_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::rowkey,strlen(mock::rowkey));
          cell.column_id_ = mock::column2_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::column2_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::column2_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_,
                    scan_param.get_column_id()[i]);
          ret = OB_ERR_UNEXPECTED;
        }
      }
    }
    else
    {
      TBSYS_LOG(ERROR, "unexpected table id [tableid:%lu]", cell.table_id_);
      ret = OB_ERR_UNEXPECTED;
    }

    if (OB_SUCCESS == ret)
    {
      ret = scanner.set_is_req_fullfilled(true,1);
      // scanner.set_timestamp(mock::schema_timestamp);
    }
    int64_t pos = 0;
    char range_buf[512];
    ObString range_str;
    if (OB_SUCCESS == ret)
    {
      ObRange range;
      range.border_flag_.set_min_value();
      range.border_flag_.set_max_value();
      ret = range.serialize(range_buf,sizeof(range_buf),pos);
      if (OB_SUCCESS == ret)
      {
        range_str.assign(range_buf,pos);
        // ret = scanner.set_ext_info(range_str);
      }
      pos = 0;
      TBSYS_LOG(INFO, "pos:%ld,ret:%d",pos, 
                range.deserialize(range_str.ptr(),range_str.length(),pos));
    }
    int32_t channel_id = ob_packet->getChannelId();
    if (OB_SUCCESS == ret)
    {
      ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    }
    if (OB_SUCCESS == ret)
    {
      ret = send_response(OB_GET_RESPONSE, 1, out_buffer, connection, channel_id);
    }
  }
  TBSYS_LOG(INFO, "handle scan root table result:ret[%d]", ret);
  return ret;
}