int ObTransferSSTableQuery::get(const ObGetParam& get_param, 
                                    ObSSTableReader& reader,
                                    ObIterator* iterator)
    {
      int ret                         = OB_SUCCESS;
      int64_t cell_size               = get_param.get_cell_size();
      int64_t row_size                = get_param.get_row_size();
      ObSSTableGetter* sstable_getter = dynamic_cast<ObSSTableGetter*>(iterator);
      const ObGetParam::ObRowIndex* row_index = get_param.get_row_index();
      static __thread const ObSSTableReader* sstable_reader = NULL;

      if (!inited_)
      {
        TBSYS_LOG(WARN, "transfer sstable query has not inited");
        ret = OB_ERROR;
      }
      else if (cell_size <= 0 || NULL == row_index || row_size <= 0
               || row_size > OB_MAX_GET_ROW_NUMBER)
      {
        TBSYS_LOG(WARN, "invalid get param, cell_size=%ld, row_index=%p, row_size=%ld",
                  cell_size, row_index, row_size);
        ret = OB_INVALID_ARGUMENT;
      }
      else if (NULL == sstable_getter)
      {
        TBSYS_LOG(WARN, "get thread local instance of sstable getter failed");
        ret = OB_ERROR;
      }

      if (OB_SUCCESS == ret)
      {
        if (!reader.empty())
        {
          sstable_reader = &reader;
        }
        else
        {
          sstable_reader = NULL;
        }

        ret = sstable_getter->init(block_cache_, block_index_cache_, 
                                   get_param, &sstable_reader, 1, true,
                                   sstable_row_cache_);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "failed to init sstable getter, ret=%d", ret);
        }
        else
        {
          // do nothing
        }
      }

      return ret;
    }
Beispiel #2
0
    int ObServerRpc::get(const ObServer& remote_server,
                         const ObGetParam& get_param, 
                         ObScanner& scanner,
                         const int64_t timeout)
    {
      int ret     = OB_SUCCESS;
      int64_t pos = 0;
      ObResultCode result_code;
      ObDataBuffer data_buff;

      if (remote_server.get_ipv4() == 0 || remote_server.get_port() == 0
          || timeout <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, ip=%d, port=%d, timeout=%ld",
                  remote_server.get_ipv4(), remote_server.get_port(),
                  timeout);
        ret = OB_ERROR;
      }
      else if (get_param.get_cell_size() <= 0 || get_param.get_row_size() <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, cell_size=%ld, row_size=%ld", 
                  get_param.get_cell_size(), get_param.get_row_size());
        ret = OB_ERROR;
      }
      else if (NULL == rpc_frame_)
      {
        TBSYS_LOG(WARN, "server rpc doesn't init.");
        ret = OB_ERROR;
      }

      if (OB_SUCCESS == ret)
      {
        ret = get_frame_buffer(data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "get frame buffer failed, ret=%d.", ret);
        }
      }
      
      // step 1. serialize get param to data_buff
      if (OB_SUCCESS == ret)
      {
        ret = get_param.serialize(data_buff.get_data(), 
                                  data_buff.get_capacity(), 
                                  data_buff.get_position());
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "serialize get_param failed, ret=%d.", ret);
        }
      }
    
      // step 2. send request for get
      if (OB_SUCCESS == ret)
      {
        ret = rpc_frame_->send_request(remote_server, 
                                       OB_GET_REQUEST, DEFAULT_VERSION, 
                                       timeout, data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "send request to remote server for get failed, "
                          "ret=%d.", ret);
        }
      }
    
      // step 3. deserialize the response code
      if (OB_SUCCESS == ret)
      {
        ret = result_code.deserialize(data_buff.get_data(), 
                                      data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "deserialize result_code failed,pos=%ld, ret=%d.", 
                    pos, ret);
        }
        else
        {
          ret = result_code.result_code_;
          if (OB_SUCCESS != ret && OB_DATA_NOT_SERVE != ret)
          {
            TBSYS_LOG(WARN, "get response from remote server failed, "
                            "timeout=%ld, ret=%d.", timeout, ret);
          }
        }
      }

      // step 4. deserialize the scanner
      if (OB_SUCCESS == ret)
      {
        ret = scanner.deserialize(data_buff.get_data(), 
                                  data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "deserialize scanner from buff failed, "
                          "pos=%ld, ret=%d.", pos, ret);
        }
      }
    
      return ret;
    }
int ObFakeSqlUpsRpcProxy2::sql_ups_get(const ObGetParam & get_param, ObNewScanner & new_scanner, const int64_t timeout)
{
    UNUSED(timeout);

    int ret = OB_SUCCESS;
    ObUpsRow ups_row;
    ObRowDesc row_desc;

    new_scanner.clear();

    if( 0 == column_count_ )
    {
        ret = OB_INVALID_ARGUMENT;
    }

    for(int i=1; OB_SUCCESS == ret && i<=column_count_; i++)
    {
        if(OB_SUCCESS != (ret = row_desc.add_column_desc(TABLE_ID, i)))
        {
            TBSYS_LOG(WARN, "add column desc fail:ret[%d]", ret);
        }
    }
    if(OB_SUCCESS == ret)
    {
        ups_row.set_row_desc(row_desc);
    }

    if(OB_SUCCESS == ret)
    {
        if(get_param.get_cell_size() / column_count_ > MAX_ROW_COUNT)
        {
            if(OB_SUCCESS != (ret = new_scanner.set_is_req_fullfilled(false, MAX_ROW_COUNT)))
            {
                TBSYS_LOG(WARN, "set is req fullfilled fail:ret[%d]", ret);
            }
        }
        else
        {
            if(OB_SUCCESS != (ret = new_scanner.set_is_req_fullfilled(true, get_param.get_row_size())))
            {
                TBSYS_LOG(WARN, "set is req fullfilled fail:ret[%d]", ret);
            }
        }
    }

    int64_t row_count = 0;
    for(int64_t i=0; OB_SUCCESS == ret && i<get_param.get_cell_size(); i+=column_count_)
    {
        if( row_count >= MAX_ROW_COUNT )
        {
            break;
        }

        ObRowkey rowkey;

        for(int64_t j=0; OB_SUCCESS == ret && j<column_count_; j++)
        {
            ObCellInfo *cell = get_param[i + j];
            rowkey = cell->row_key_;
            if(OB_SUCCESS != (ret = ups_row.raw_set_cell(j, cell->value_)))
            {
                TBSYS_LOG(WARN, "set cell fail:ret[%d]", ret);
            }
        }

        if(OB_SUCCESS == ret)
        {
            row_count ++;
            if(OB_SUCCESS != (ret = new_scanner.add_row(rowkey, ups_row)))
            {
                TBSYS_LOG(WARN, "add row fail:ret[%d]", ret);
            }
        }
    }
    return ret;
}