Пример #1
0
int TaskFactory::init_scan_param(const char *table_name, const uint64_t table_id, uint64_t & max_len, ObScanParam & param)
{
  // init version range
  ObVersionRange version_range;
  //version_range.start_version_ = 0;
  version_range.border_flag_.set_min_value();
  version_range.end_version_ = memtable_version_;
  version_range.border_flag_.set_inclusive_end();
  //version_range.border_flag_.set_max_value();
  param.set_version_range(version_range);
  param.set_is_read_consistency(false);
  param.set_is_result_cached(false);
  param.set_is_read_consistency(false);
  int ret = get_max_len(table_id, max_len);
  if (ret != OB_SUCCESS)
  {
    TBSYS_LOG(ERROR, "get table max rowkey len failed:table[%lu], ret[%d]", table_id, ret);
  }
  else
  {
//    ret = add_all_columns(table_id, param);
    ret = add_columns(table_name, table_id, param);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "add all columns failed:table[%lu], ret[%d]", table_id, ret);
    }
  }
  return ret;
}
Пример #2
0
 void ObScanParamLoader::dump_param(ObScanParam &param)
 {
   TBSYS_LOG(INFO, "DUMP ObScanParam:");
   TBSYS_LOG(INFO, "table_name:[%.*s]", param.get_table_name().length(), param.get_table_name().ptr());
   TBSYS_LOG(INFO, "range:");
   param.get_range()->dump();
 }
Пример #3
0
int MockClientProxy::scan(const ObScanParam& scan_param,ObScanner& scanner)
{
  printf("%.*s\n", scan_param.get_range()->start_key_.length(), 
    scan_param.get_range()->start_key_.ptr());
  gen_scanner(scanner);
  this->scan_param_ = const_cast<ObScanParam*>(&scan_param);
  return OB_SUCCESS;
}
Пример #4
0
void TaskManager::setup_all_tasks_vesion(int64_t version)
{
  map<uint64_t, TaskInfo>::iterator it = wait_queue_.begin();
  while (it != wait_queue_.end())
  {
    ObScanParam *param = const_cast<ObScanParam *>(&it->second.get_param());
    ObVersionRange version_range;
    version_range.border_flag_.set_min_value();
    version_range.end_version_ = version;
    version_range.border_flag_.set_inclusive_end();
    param->set_version_range(version_range);
    it++;
  }
}
Пример #5
0
int ObUpsScan::get_next_scan_param(const ObRowkey &last_rowkey, ObScanParam &scan_param)
{
  int ret = OB_SUCCESS;

  ObNewRange next_range = *(scan_param.get_range());

  next_range.start_key_ = last_rowkey;
  next_range.border_flag_.unset_inclusive_start();

  if(OB_SUCCESS != (ret = scan_param.set_range(next_range)))
  {
    TBSYS_LOG(WARN, "scan param set range fail:ret[%d]", ret);
  }

  return ret;
}
Пример #6
0
int ObMetaTable3::MyIterator::add_scan_columns(ObScanParam &scan_param)
{
  int ret = OB_SUCCESS;
  if (OB_SUCCESS != (ret = get_table_schema()))
  {
    TBSYS_LOG(WARN, "failed to get table schema, err=%d", ret);
  }
  else
  {
    ObMetaTableColumnSchema col_schema(table_schema_);
    for (int64_t i = 0; i < col_schema.get_columns_num(); ++i)
    {
      uint64_t cid = col_schema.get_cid_by_idx(i);
      if (OB_INVALID_ID == cid)
      {
        TBSYS_LOG(ERROR, "failed to get column id, i=%ld", i);
      }
      else if (OB_SUCCESS != (ret = scan_param.add_column(cid)))
      {
        TBSYS_LOG(WARN, "failed to add column, err=%d", ret);
        break;
      }
    }
  }
  return ret;
}
int ObFakeSqlUpsRpcProxy2::gen_new_scanner(const ObScanParam & scan_param, ObNewScanner & new_scanner)
{
    int ret = OB_SUCCESS;
    const ObNewRange *const range = scan_param.get_range();
    int start = get_int(range->start_key_);
    int end = get_int(range->end_key_);

    new_scanner.clear();

    ObBorderFlag border_flag;
    border_flag = range->border_flag_;

    if (start+100 >= end)
    {
        if(OB_SUCCESS != (ret = gen_new_scanner(range->table_id_, start, end, border_flag, new_scanner, true)))
        {
            TBSYS_LOG(WARN, "gen new scanner fail:ret[%d]", ret);
        }
    }
    else
    {
        border_flag.set_inclusive_end();
        if(OB_SUCCESS != (ret = gen_new_scanner(range->table_id_, start, start+100, border_flag, new_scanner, false)))
        {
            TBSYS_LOG(WARN, "gen new scanner fail:ret[%d]", ret);
        }
    }
    return ret;
}
Пример #8
0
int ObRootServerRpcStub::scan(const ObServer & server, const int64_t timeout, 
                             const ObScanParam & param, ObScanner & result)
{
  ObDataBuffer data_buff;
  int ret = get_frame_buffer(data_buff);
  if (ret != OB_SUCCESS)
  {
    TBSYS_LOG(ERROR, "check get rpc buffer failed:ret[%d]", ret);
  }
  else
  {
    // step 1. serialize ObGetParam to the data_buff
    ret = param.serialize(data_buff.get_data(), data_buff.get_capacity(), 
        data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize get param failed:ret[%d]", ret);
    }
  }

  // step 2. send request for get data 
  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(server, OB_SCAN_REQUEST, DEFAULT_VERSION, 
        timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "get data failed from server:ret[%d]", ret);
    }
  }
  
  // step 3. deserialize the response result
  int64_t pos = 0;
  if (OB_SUCCESS == ret)
  {
    ObResultCode result_code;
    ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize result failed:pos[%ld], ret[%d]", pos, ret);
    }
    else if ((ret = result_code.result_code_) != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR,"scan failed,ret[%d]",ret);
    }
  }
  
  // step 4. deserialize the scanner 
  if (OB_SUCCESS == ret)
  {
    result.clear();
    ret = result.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize scanner from buff failed:pos[%ld], ret[%d]", pos, ret);
    }
  }
  return ret;
}
Пример #9
0
int MutatorBuilder::build_total_scan_param(ObScanParam &scan_param, PageArena<char> &allocer,
                                          const int64_t table_start_version,
                                          const bool using_id, const int64_t table_pos)
{
  int ret = OB_SUCCESS;
  const ObSchema &schema = schema_mgr_.begin()[table_pos];

  int64_t cur_rowkey_info = get_cur_rowkey_info_(schema, using_id, rb_array_[table_pos]->get_prefix_start());
  std::pair<ObString,ObString> key_range = rb_array_[table_pos]->get_rowkey4total_scan(cur_rowkey_info, allocer);
  ObRange range;
  range.start_key_ = key_range.first;
  range.end_key_ = key_range.second;

  const ObColumnSchema *iter = NULL;
  for (iter = schema.column_begin(); iter != schema.column_end(); iter++)
  {
    if (using_id)
    {
      scan_param.add_column(iter->get_id());
    }
    else
    {
      ObString column_name;
      column_name.assign_ptr(const_cast<char*>(iter->get_name()), static_cast<int32_t>(strlen(iter->get_name())));
      scan_param.add_column(column_name);
    }
  }

  if (using_id)
  {
    scan_param.set(schema.get_table_id(), ObString(), range);
  }
  else
  {
    ObString table_name;
    table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name())));
    scan_param.set(OB_INVALID_ID, table_name, range);
  }

  ObVersionRange version_range;
  version_range.start_version_ = table_start_version;
  version_range.border_flag_.set_max_value();
  version_range.border_flag_.set_inclusive_start();
  scan_param.set_version_range(version_range);
  return ret;
}
 bool is_finish_scan(const ObScanParam & param, const ObNewRange & result_range)
 {
   bool ret = false;
   if (ScanFlag::FORWARD == param.get_scan_direction())
   {
     if (result_range.compare_with_endkey2(*param.get_range()) >= 0)
     {
       ret = true;
     }
   }
   else
   {
     if (result_range.compare_with_startkey2(*param.get_range()) <= 0)
     {
       ret = true;
     }
   }
   return ret;
 }
Пример #11
0
void prepare_scan_param(ObScanParam &scan_param, const ObSchema &schema,
                        const int64_t table_start_version, const bool using_id)
{
  ObRange range;
  range.border_flag_.set_min_value();
  range.border_flag_.set_max_value();

  const ObColumnSchema *iter = NULL;
  for (iter = schema.column_begin(); iter != schema.column_end(); iter++)
  {
    if (using_id)
    {
      scan_param.add_column(iter->get_id());
    }
    else
    {
      ObString column_name;
      column_name.assign_ptr(const_cast<char*>(iter->get_name()), strlen(iter->get_name()));
      scan_param.add_column(column_name);
    }
  }

  if (using_id)
  {
    scan_param.set(schema.get_table_id(), ObString(), range);
  }
  else
  {
    ObString table_name;
    table_name.assign(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name()));
    scan_param.set(OB_INVALID_ID, table_name, range);
  }

  ObVersionRange version_range;
  version_range.start_version_ = table_start_version;
  version_range.border_flag_.set_max_value();
  version_range.border_flag_.set_inclusive_start();
  scan_param.set_version_range(version_range);
}
Пример #12
0
int ObMSScanCellStream::scan(const ObScanParam & param, const ObMergerTabletLocation & cs_addr)
{
  int ret = OB_SUCCESS;
  const ObRange * range = param.get_range();
  if (NULL == range)
  {
    TBSYS_LOG(ERROR, "%s", "check scan param failed");
    ret = OB_INPUT_PARAM_ERROR;
  }
  else
  {
    cs_addr_ = cs_addr;
    reset_inner_stat();
    scan_param_ = &param;
  }
  return ret;
}
Пример #13
0
int TaskFactory::add_all_columns(const uint64_t table_id, ObScanParam & param)
{
  int ret = OB_SUCCESS;
  int32_t count = 0;
  const ObColumnSchemaV2 * column_schema = schema_->get_table_schema(table_id, count);
  if ((NULL == column_schema) || (0 == count))
  {
    ret = OB_ERROR;
    TBSYS_LOG(ERROR, "check column schema or schema count failed:column[%p], count[%d]",
        column_schema, count);
  }
  else
  {
    ObString column;
    const char * column_name = NULL;
    for (int32_t i = 0; i < count; ++i)
    {
      column_name = column_schema->get_name();
      if (column_name != NULL)
      {
        TBSYS_LOG(DEBUG, "TableId:%ld, COLUMN=%s", table_id, column_name);

        column.assign(const_cast<char *>(column_name), (int32_t)strlen(column_name));
        ret = param.add_column(column);
        if (ret != OB_SUCCESS)
        {
          TBSYS_LOG(ERROR, "add column failed:table[%lu], column[%s], ret[%d]",
              table_id, column_name, ret);
          ret = OB_ERROR;
          break;
        }
      }
      else
      {
        ret = OB_ERROR;
        TBSYS_LOG(ERROR, "check column name failed:table[%lu], name[%s]", table_id, column_name);
        break;
      }
      ++column_schema;
    }
  }
  return ret;
}
Пример #14
0
 int ObScanParamLoader::decoded_scan_param(ObScanParam &org_param, ObScanParam &decoded_param)
 {
   int ret = OB_SUCCESS;
   ObSchemaManagerV2 schema_mgr;
   tbsys::CConfig config;
   /* read from Schema file */
   if (!schema_mgr.parse_from_file(OBSP_SCHEMA_FILE_NAME, config))
   {
     TBSYS_LOG(ERROR, "fail to load schema file [test_schema.ini]");        
     ret = OB_ERROR;
   }
   /* decode the SQL to scan param */
   if (OB_SUCCESS == ret)
   {
     dump_param(org_param);
     decoded_param.reset();
     ret = ob_decode_scan_param(org_param, schema_mgr, decoded_param);
   }
   return ret;
 }
Пример #15
0
 int ObScanCellStream::scan(const ObScanParam & param)
 {
   int ret = OB_SUCCESS;
   const ObRange * range = param.get_range();
   if (NULL == range)
   {
     TBSYS_LOG(WARN, "check scan param failed");
     ret = OB_INPUT_PARAM_ERROR;
   }
   else
   {
     reset_inner_stat();
     scan_param_ = &param;
     ret = scan_row_data();
     if (ret != OB_SUCCESS)
     {
       TBSYS_LOG(WARN, "scan server data failed:ret[%d]", ret);
     }
     else 
     {
       /**
        * ups return empty scanner, just return OB_ITER_END
        */
       if (cur_result_.is_empty() && !ObCellStream::first_rpc_)
       {
         // check already finish scan
         ret = check_finish_scan(cur_scan_param_);
         if (OB_SUCCESS != ret)
         {
           TBSYS_LOG(WARN, "check finish scan failed:ret[%d]", ret);
         }
         else if (finish_)
         {
           ret = OB_ITER_END;
         }
       }
     }
   }
   return ret;
 }
Пример #16
0
int TaskFactory::init_new_task(const ObString & table_name, const ObRowkey & start_key,
    const ObRowkey & end_key, ObScanParam & scan_param, TaskInfo & task) const
{
  int ret = OB_SUCCESS;
  if (!check_string(table_name))
  {
    TBSYS_LOG(WARN, "check table name or end key failed:name[%.*s]",
      table_name.length(), table_name.ptr());
    ret = OB_ERROR;
  }
  else
  {
    ObNewRange range;
    range.border_flag_.unset_inclusive_start();
    range.border_flag_.set_inclusive_end();
    if (NULL == start_key.ptr())
    {
      range.border_flag_.set_min_value();
    }
    else
    {
      range.start_key_ = start_key;
      range.border_flag_.unset_min_value();
    }
    range.border_flag_.unset_max_value();
    range.end_key_ = end_key;
    scan_param.set(OB_INVALID_ID, table_name, range);
    // deep copy the param to task info param
    ret = task.set_param(scan_param);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "set param failed:ret[%d]", ret);
    }
  }
  return ret;
}
Пример #17
0
int MockUpdateServer::handle_scan_table(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObScanParam param;
  if (OB_SUCCESS == ret)
  {
    ret = param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check 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;
    char temp[256] = "";
    ObString table_name;
    char * name = "update_test_table";
    table_name.assign(name, strlen(name));
    cell.table_name_ = table_name;
    for (uint64_t i = 0; i < 10; ++i)
    {
      snprintf(temp, 256, "update_%lu_scan_row_key:%lu", i, i);
      row_key.assign(temp, strlen(temp));
      cell.row_key_ = row_key;
      column_name.assign(temp, strlen(temp));
      cell.column_name_ = column_name;
      cell.value_.set_int(2234 + i);
      scanner.add_cell(cell);
    }

    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    //
    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;
}
Пример #18
0
int scan_test_case_common(
  BaseClient& client,
  const ObServer& server,
  const int64_t  table_id,
  const char* start_key_ptr,
  const char* end_key_ptr,
  const int64_t input_key_size,
  const bool is_hex
  )
{
  ObScanParam input;


  int64_t key_size = input_key_size;
  if (is_hex)
  {
    key_size = input_key_size / 2;
  }

  char start_key[input_key_size];
  char end_key[input_key_size];
  char range_str[OB_RANGE_STR_BUFSIZ];


  memset(start_key, 0, input_key_size);
  memset(end_key, 0, input_key_size);
  if (is_hex)
  {
    str_to_hex(start_key_ptr, static_cast<int32_t>(input_key_size), start_key, static_cast<int32_t>(key_size));
    str_to_hex(end_key_ptr, static_cast<int32_t>(input_key_size), end_key, static_cast<int32_t>(key_size));
  }
  else
  {
    memcpy(start_key, start_key_ptr, key_size);
    memcpy(end_key, end_key_ptr, key_size);
  }


  ObString ob_table_name(0, 0, NULL);

  ObRange range;
  range.table_id_= 0;
  range.start_key_.assign_ptr(start_key, static_cast<int32_t>(key_size));
  range.end_key_.assign_ptr(end_key, static_cast<int32_t>(key_size));
  range.border_flag_.set_inclusive_start();
  range.border_flag_.set_inclusive_end();

  range.to_string(range_str, OB_RANGE_STR_BUFSIZ);
  range.hex_dump();
  fprintf(stderr, "input scan range = %s\n", range_str);


  input.set(table_id, ob_table_name, range);
  input.set_scan_size(100000);
  input.add_column((uint64_t)0ull);


  ObScanner scanner;
  int64_t start = tbsys::CTimeUtil::getTime();
  int ret = rpc_cs_scan(client.client_, server, input, scanner);
  int64_t end = tbsys::CTimeUtil::getTime();
  fprintf(stderr,"rpc_cs_scan time consume:%ld\n", end - start);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"ret:%d\n", ret);
  }
  else
  {
    dump_scanner(scanner);
  }
  
  return ret;
}
Пример #19
0
int scan_test_case(
    BaseClient& client,
    const ObServer& server,
    const uint64_t table_id,
    const int64_t user_id,
  const int8_t item_type,
  const int32_t column_size
  )
{
  ObScanParam input;


  const int32_t key_size = 17;
  char start_key[key_size] ;
  char end_key[key_size] ;

  int64_t pos = 0;
  
  encode_i64(start_key, key_size, pos, user_id);
  if (item_type <= 1)
    encode_i8(start_key, key_size, pos, item_type);
  else
    encode_i8(start_key, key_size, pos, 0x0);
  memset(start_key + pos, 0x0, key_size - pos);

  pos = 0;
  encode_i64(end_key, key_size, pos, user_id);
  if ( item_type <= 1)
    encode_i8(end_key, key_size, pos, item_type);
  else
    encode_i8(end_key, key_size, pos, static_cast<int8_t>(0xFF));

  memset(end_key + pos, 0xFF, key_size - pos);

  hex_dump(start_key, key_size);
  hex_dump(end_key, key_size);


  ObString ob_table_name;
  ObRange range;
  range.table_id_= table_id;
  range.start_key_.assign_ptr(start_key, key_size);
  range.end_key_.assign_ptr(end_key, key_size);
  range.border_flag_.set_inclusive_start();
  range.border_flag_.set_inclusive_end();

  range.hex_dump();

  input.set(table_id, ob_table_name, range);
  input.set_scan_size(100000);

  for (int i = 0; i < column_size; ++i)
  {
    input.add_column(i + 2);
  }

  ObScanner scanner;
  int64_t start = tbsys::CTimeUtil::getTime();
  int ret = rpc_cs_scan(client.client_, server, input, scanner);
  int64_t end = tbsys::CTimeUtil::getTime();
  fprintf(stderr,"rpc_cs_scan time consume:%ld\n", end - start);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"ret:%d\n", ret);
  }
  else
  {
    dump_scanner(scanner);
  }
  
  return ret;
}
Пример #20
0
int rpc_cs_scan(ObClientManager& cp,
                const ObServer& cs,
                const ObScanParam& scan_param,
                ObScanner& scanner)
{
  int ret = OB_SUCCESS;
  int64_t start = 0, end = 0;
  const int32_t BUFFER_SIZE = 2*1024*1024;
  char* param_buffer = new char[BUFFER_SIZE];
  ObDataBuffer ob_inout_buffer;
  ObResultCode rc;
  int64_t return_start_pos = 0;

  if (NULL == param_buffer)
  {
    goto exit;
  }

  ob_inout_buffer.set_data(param_buffer, BUFFER_SIZE);
  ret = scan_param.serialize(ob_inout_buffer.get_data(),
                             ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position());
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"serialize scan_param into buffer failed\n");
    goto exit;
  }

  // send request;
  start = tbsys::CTimeUtil::getTime();
  ret = cp.send_request(cs, OB_SCAN_REQUEST, 1, 2000*2000, ob_inout_buffer);
  end = tbsys::CTimeUtil::getTime();
  fprintf(stderr,"time consume:%ld\n", end - start);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"rpc failed\n");
    goto exit;
  }


  ret = rc.deserialize(ob_inout_buffer.get_data(),
                       ob_inout_buffer.get_position(), return_start_pos);

  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"deserialize obscanner failed\n");
    goto exit;
  }

  fprintf(stderr,"return rc code:%d, msg:%s\n", rc.result_code_, rc.message_.ptr());

  if (OB_SUCCESS != rc.result_code_)
  {
    goto exit;
  }

  fprintf(stderr,"return_start_pos:%ld, %ld\n", return_start_pos, ob_inout_buffer.get_position());

  // deserialize output
  ret = scanner.deserialize(ob_inout_buffer.get_data(),
                            ob_inout_buffer.get_position(), return_start_pos);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"deserialize obscanner failed\n");
    goto exit;
  }
  fprintf(stderr,"return_start_pos:%ld, %ld\n", return_start_pos, ob_inout_buffer.get_position());

exit:
  if (param_buffer) delete []param_buffer;
  return ret;
}
Пример #21
0
    int ObServerRpc::scan(const ObServer& remote_server,
                          const ObScanParam& scan_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 (scan_param.get_scan_size() <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, scan_size=%ld", 
                  scan_param.get_scan_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);
      }

      // step 1. serialize scan param to data_buff
      if (OB_SUCCESS == ret)
      {
        ret = scan_param.serialize(data_buff.get_data(), 
                                   data_buff.get_capacity(), 
                                   data_buff.get_position());
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "serialize scan_param failed,ret=%d.", ret);
        }
      }
    
      // step 2. send request for scan
      if (OB_SUCCESS == ret)
      {
        ret = rpc_frame_->send_request(remote_server, 
                                       OB_SCAN_REQUEST, DEFAULT_VERSION, 
                                       timeout, data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "send request to remote server for scan 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 scannner
      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;
    }
TEST(ObSortedOperator, forward)
{
  const int32_t sharding_count = 5;
  const int32_t cell_count_each_sharding = 2;
  ObScanner *sharding_res_arr = new ObScanner[sharding_count];
  ObNewRange   *q_range_arr = new ObNewRange[sharding_count];
  ObStringBuf buf;
  char row_key_buf[32];
  int32_t row_key_len = 0;
  ObRowkey str;
  ObRowkey row_key;
  ObCellInfo cell;
  cell.table_id_ = 1;
  cell.column_id_ = 1;
  ObScanParam scan_param;
  EXPECT_EQ(scan_param.add_column(1),OB_SUCCESS);
  row_key_len = snprintf(row_key_buf, sizeof(row_key_buf),"%d",0);
  str = make_rowkey(row_key_buf,row_key_len, &allocator_);
  EXPECT_EQ(buf.write_string(str,&row_key),OB_SUCCESS);
  ObNewRange q_range;
  q_range.start_key_ = row_key;
  q_range.border_flag_.set_inclusive_start();
  q_range.end_key_.set_max_row();
  ObScanParam param;
  ObString table_name;
  EXPECT_EQ(param.set(1,table_name, q_range), OB_SUCCESS);

  ObMergerSortedOperator s_operator;
  EXPECT_EQ(s_operator.set_param(param), OB_SUCCESS);
  for (int32_t i = sharding_count * cell_count_each_sharding - 1; i >= 0; i -= 2)
  {
    int sharding_idx = (i-1)/2;
    /// prepare range
    if (i > 1)
    {
      row_key_len = snprintf(row_key_buf, sizeof(row_key_buf),"%d",i - 2);
    }
    else
    {
      row_key_len = snprintf(row_key_buf, sizeof(row_key_buf),"%d",0);
    }
    str = make_rowkey(row_key_buf,row_key_len, &allocator_);
    EXPECT_EQ(buf.write_string(str,&row_key),OB_SUCCESS);
    q_range_arr[sharding_idx].start_key_ = row_key;
    if (i > 1)
    {
      q_range_arr[sharding_idx].border_flag_.unset_inclusive_start();
    }
    else
    {
      q_range_arr[sharding_idx].border_flag_.set_inclusive_start();
    }
    q_range_arr[sharding_idx].border_flag_.set_max_value();

    /// first cell
    row_key_len = snprintf(row_key_buf, sizeof(row_key_buf),"%d",i - 1);
    str = make_rowkey(row_key_buf,row_key_len, &allocator_);
    EXPECT_EQ(buf.write_string(str,&row_key),OB_SUCCESS);
    cell.row_key_ = row_key;
    cell.value_.set_int(i - 1);
    EXPECT_EQ(sharding_res_arr[sharding_idx].add_cell(cell), OB_SUCCESS);

    /// second cell
    row_key_len = snprintf(row_key_buf, sizeof(row_key_buf),"%d",i);
    str = make_rowkey(row_key_buf,row_key_len, &allocator_);
    EXPECT_EQ(buf.write_string(str,&row_key),OB_SUCCESS);
    cell.row_key_ = row_key;
    cell.value_.set_int(i - 1);
    EXPECT_EQ(sharding_res_arr[sharding_idx].add_cell(cell), OB_SUCCESS);

    bool is_finish = true;
    EXPECT_EQ(s_operator.add_sharding_result(sharding_res_arr[sharding_idx], q_range_arr[sharding_idx],is_finish),false);
    if (sharding_idx == 0)
    {
      EXPECT_TRUE(is_finish);
    }
    else
    {
      EXPECT_FALSE(is_finish);
    }
  }
  EXPECT_EQ(s_operator.seal(),OB_SUCCESS);
  int32_t beg = 0;
  ObInnerCellInfo *cur_cell = NULL;
  int err = OB_SUCCESS;
  while ((err = s_operator.next_cell()) == OB_SUCCESS)
  {
    EXPECT_EQ(s_operator.get_cell(&cur_cell),OB_SUCCESS);
    row_key_len = snprintf(row_key_buf, sizeof(row_key_buf),"%d",beg);
    str = make_rowkey(row_key_buf,row_key_len, &allocator_);
    EXPECT_TRUE(cur_cell->row_key_ == str);
    beg ++;
  }
  EXPECT_EQ(OB_ITER_END, err);
  EXPECT_EQ(beg, sharding_count * cell_count_each_sharding);
  delete [] sharding_res_arr;
  delete [] q_range_arr;
}
Пример #23
0
    int ObGetScanProxy::cs_scan(const ObScanParam& scan_param, ObScanner& scanner, 
                                ObIterator* it_out[],int64_t& it_size)
    {
      int ret = OB_SUCCESS;
      int64_t it_num = 0;

      if ((NULL == it_out) || it_size <= 0)
      {
        ret = OB_INVALID_ARGUMENT;
      }

      if ((OB_SUCCESS == ret) && ((ret = tablet_manager_.scan(scan_param, scanner)) != OB_SUCCESS))
      {
        TBSYS_LOG(WARN, "failed to scan data from local chunk server, ret=%d", ret);        
      }

      if (OB_SUCCESS == ret)
      {
        ObSSTableScanner *sstable_scanner = 
          GET_TSI_MULT(ObSSTableScanner, TSI_CS_SSTABLE_SCANNER_1);
        if (NULL == sstable_scanner)
        {
          TBSYS_LOG(ERROR, "failed to get thread local sstable scanner, "
                           "sstable_scanner=%p", 
                    sstable_scanner);
          ret = OB_ALLOCATE_MEMORY_FAILED;
        }
        else
        {
          tablet_range_.reset();
          ret = scanner.get_range(tablet_range_);
          if (OB_SUCCESS == ret)
          {
            it_out[it_num++] = sstable_scanner;
          }
          else 
          {
            TBSYS_LOG(WARN, "failed to get tablet range from scanner, ret=%d", ret);
          }
        }
      }

      if (OB_SUCCESS == ret)
      {
        int64_t query_version = 0;
        const ObVersionRange version_range = scan_param.get_version_range();
        if (!version_range.border_flag_.is_max_value() && version_range.end_version_ != 0)
        {
          query_version = version_range.end_version_;
        }
        ObTablet*& scan_tablet            = tablet_manager_.get_cur_thread_scan_tablet();
        int32_t compactsstable_num        = scan_tablet->get_compactsstable_num();

        if (compactsstable_num > 0)
        {
          ObCompactSSTableMemNode* mem_node = scan_tablet->get_compactsstable_list();
          ObCompactMemIteratorArray *its    = GET_TSI_MULT(ObCompactMemIteratorArray,TSI_CS_COMPACTSSTABLE_ITERATOR_1);
          ColumnFilter* cf                  = GET_TSI_MULT(ColumnFilter,TSI_CS_COLUMNFILTER_1);          
          ObCompactSSTableMem* mem          = NULL;          
          int64_t major_version             = 0;
          int32_t i                         = 0;          

          if ((NULL == mem_node) || (NULL == cf) || (NULL == its))
          {
            TBSYS_LOG(WARN,"unexpect error,mem_node=%p,cf=%p,its=%p",mem_node,cf,its);
            ret = OB_ALLOCATE_MEMORY_FAILED;
          }
          else
          {
            cf->clear();
          }

          if ((OB_SUCCESS == ret) && (NULL == (cf = ColumnFilter::build_columnfilter(scan_param, cf))))
          {
            TBSYS_LOG(WARN,"build columnfilter failed");
            ret = OB_ERROR;
          }

          for(i=0; (mem_node != NULL) && (i < compactsstable_num) && (OB_SUCCESS == ret) && (it_num < it_size);++i)
          {
            mem = &mem_node->mem_;
            if (NULL == mem)
            {
              TBSYS_LOG(WARN,"unexpect error,compact mem is null");
              ret = OB_ERROR;
            }
            else
            {
              //query version just have major version
              major_version = mem->get_version_range().major_version_;
              if ((0 == query_version) || (query_version > 0 && major_version <= query_version))
              {
                if ((ret = its->iters_[i].init(mem)) != OB_SUCCESS)
                {
                  TBSYS_LOG(WARN,"init iterator of compact mem failed,ret=%d",ret);
                }
                else if ((ret = its->iters_[i].set_scan_param(*scan_param.get_range(),cf,
                                                              scan_param.get_scan_direction() == ScanFlag::BACKWARD))
                         != OB_SUCCESS)
                {
                  TBSYS_LOG(WARN,"set scan param failed,ret=%d",ret);
                }
                else
                {
                  it_out[it_num++] = &its->iters_[i];
                  //set data version to the last compact sstable version
                  scanner.set_data_version(mem->get_data_version());
                  FILL_TRACE_LOG("add compact iterator to merger,it_num:%ld,version:%ld",it_num,mem->get_data_version());
                }
              }
              else
              {
                break; //got enough data
              }
            }
            mem_node = mem_node->next_;
          } //end for
        } //end compactsstable_num > 0
      }

      if (OB_SUCCESS == ret)
      {
        it_size = it_num;
      }

      return ret;
    }
Пример #24
0
int MockChunkServer::handle_scan_table(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObScanParam param;
  if (OB_SUCCESS == ret)
  {
    ret = param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check 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
    ObNewScanner scanner;
    ObRow row_;
    ObRowDesc row_desc_;
    ObString row_key;
    ObString column_name;
    char temp[256] = "";
    ObObj obj_a, obj_b, obj_d;
    ObObj str_c;
    ObString var_str;
    row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0);
    //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1);
    //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2);
    //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3);
    obj_a.set_int(19);
    obj_b.set_int(2);
    var_str.assign("hello", 5);
    str_c.set_varchar(var_str);
    obj_d.set_int(3);
    row_.set_row_desc(row_desc_);
    row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0, obj_a);
    //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1, obj_b);
    //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2, str_c);
    //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3, obj_d);

    for (uint64_t i = 0; i < 10; ++i)
    {
      if (OB_SUCCESS != scanner.add_row(row_))
      {
        printf("handle table scan: fail! \n");
      }
      printf("handle table scan: add new row to scanner\n");
    }
    /* begin add by xiaochu */
    //Scanner Range must be set other wise the ms client will report error
    ObRange range;
    ObString start_key;
    ObString end_key;
    /*
    /// This will cause rowkey mismatch
    //char *start= "chunk_0_scan_row_key:0";
    //char *end  = "chunk_9_scan_row_key:9";
    */
    char *start= (char*)"row_100";
    char *end  = (char*)"row_200";
    start_key.assign(start, static_cast<int32_t>(strlen(start)));
    end_key.assign(end, static_cast<int32_t>(strlen(end)));
    range.start_key_ = start_key;
    range.end_key_ = end_key;
    range.table_id_ = test::ObFakeTable::TABLE_ID;
    scanner.set_range(range);
    scanner.set_is_req_fullfilled(true, 10);
    /* end add by xiaochu */

    int32_t channel_id = ob_packet->getChannelId();
    if (OB_SUCCESS != (ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position())))
    {
      TBSYS_LOG(WARN, "fail to serialize scanner");
    }
    else if (OB_SUCCESS != (ret = send_response(OB_SCAN_RESPONSE, 1, out_buffer, connection, channel_id)))
    {
      TBSYS_LOG(WARN, "fail to send scanner");
    }
    
  }
  TBSYS_LOG(INFO, "handle scan table result:ret[%d]", ret);
  return ret;
}
Пример #25
0
int ObRootServerRpcStub::get_tablet_info(const common::ObSchemaManagerV2& schema, 
    const uint64_t table_id, const ObRange& range, ObTabletLocation location [],int32_t& size)
{
  int ret = OB_SUCCESS;
  int32_t index = 0;
  const ObChunkServer& chunk_server = ObChunkServerMain::get_instance()->get_chunk_server();
  const int64_t timeout = chunk_server.get_param().get_network_time_out();
  if (OB_INVALID_ID == table_id || size <= 0)
  {
    TBSYS_LOG(ERROR,"invalid table id");
    ret = OB_ERROR;
  }
  
  ObScanParam param;
  ObScanner scanner;
  ObString table_name;
  
  const ObTableSchema *table = schema.get_table_schema(table_id);

  if (NULL == table)
  {
    TBSYS_LOG(ERROR,"can not find table %lu",table_id);
    ret = OB_ERROR;
  }
  else
  {
    table_name.assign_ptr(const_cast<char *>(table->get_table_name()),strlen(table->get_table_name()));
  }
  
  if (OB_SUCCESS == ret)
  {
    param.set(OB_INVALID_ID,table_name,range); //use table name
    param.set_is_read_consistency(false);
  }

  if ((OB_SUCCESS == ret) && ((ret = scan(root_server_,timeout,param,scanner)) != OB_SUCCESS) )
  {
    TBSYS_LOG(ERROR,"get tablet from rootserver failed:[%d]",ret);
  }
  
  ObServer server;
  char tmp_buf[32];
  ObString start_key;
  ObString end_key; 
  ObCellInfo * cell = NULL;
  ObScannerIterator iter; 
  bool row_change = false;
   
  if (OB_SUCCESS == ret) 
  { 
    int64_t ip = 0;
    int64_t port = 0;
    int64_t version = 0;
    iter = scanner.begin();
    ret = iter.get_cell(&cell, &row_change);
    row_change = false;

    while((OB_SUCCESS == ret) && index < size)
    {
      if (ret != OB_SUCCESS)
      {
        TBSYS_LOG(ERROR, "get cell from scanner iterator failed:ret[%d]", ret);
      }
      else if (row_change)
      {
        TBSYS_LOG(DEBUG,"row changed,ignore"); 
        hex_dump(cell->row_key_.ptr(),cell->row_key_.length(),false,TBSYS_LOG_LEVEL_INFO);
        break; //just get one row        
      } 
      else if (cell != NULL)
      {
        end_key.assign(cell->row_key_.ptr(), cell->row_key_.length());
        if ((cell->column_name_.compare("1_port") == 0) 
            || (cell->column_name_.compare("2_port") == 0) 
            || (cell->column_name_.compare("3_port") == 0))
        {
          ret = cell->value_.get_int(port);
          TBSYS_LOG(DEBUG,"port is %ld",port);
        }
        else if ((cell->column_name_.compare("1_ipv4") == 0)
            || (cell->column_name_.compare("2_ipv4") == 0)
            || (cell->column_name_.compare("3_ipv4") == 0))
        {
          ret = cell->value_.get_int(ip);
          TBSYS_LOG(DEBUG,"ip is %ld",ip);
        }
        else if (cell->column_name_.compare("1_tablet_version") == 0 ||
            cell->column_name_.compare("2_tablet_version") == 0 ||
            cell->column_name_.compare("3_tablet_version") == 0)
        {
          ret = cell->value_.get_int(version);
          hex_dump(cell->row_key_.ptr(),cell->row_key_.length(),false,TBSYS_LOG_LEVEL_INFO);
          TBSYS_LOG(DEBUG,"tablet_version is %d",version);
        }

        if (OB_SUCCESS == ret)
        {
          if (0 != port && 0 != ip && 0 != version)
          {
            server.set_ipv4_addr(ip, port);
            server.to_string(tmp_buf,sizeof(tmp_buf));
            TBSYS_LOG(INFO,"add tablet s:%s,%ld",tmp_buf,version);
            ObTabletLocation addr(version, server);
            location[index++] = addr;
            ip = port = version = 0;
          }
        }
        else 
        {
          TBSYS_LOG(ERROR, "check get value failed:ret[%d]", ret);
        }

        if (++iter == scanner.end())
          break;
        ret = iter.get_cell(&cell, &row_change);
      }
      else
      {
        //impossible
      }
    }
  }

  if (OB_SUCCESS == ret)
  {
    size = index;
    TBSYS_LOG(INFO,"get %d tablets from rootserver",size);
  }
  return ret;
}
Пример #26
0
    int ObScanParamLoader::get_org_scan_param(ObScanParam &param)
    {
      ObRange range;
      ObString column;
      ObString table_name;
      ObPostfixExpression comp;

      if (config_loaded_)
      {
        TBSYS_LOG(INFO, "creating org scan param");

        param.reset();

        range.reset();
        range.table_id_ = table_id_;
        range.start_key_ = range_start_;
        if (range_start_inclusive_) 
          range.border_flag_.set_inclusive_start();
        else 
          range.border_flag_.unset_inclusive_start();
        if (range_start_min_)
          range.border_flag_.set_min_value();

        range.end_key_ = range_end_;
        if (range_end_inclusive_) 
          range.border_flag_.set_inclusive_end();
        else 
          range.border_flag_.unset_inclusive_end();
        if (range_end_max_)
          range.border_flag_.set_max_value();
    
        param.set(table_id_, table_name_, range, true);
        param.set_scan_direction(scan_direction_==0?ObScanParam::FORWARD:ObScanParam::BACKWARD);
        param.set_limit_info(limit_offset_, limit_count_);

        int i = 0;
        for (i = 0; i < column_id_count_; i++)
        {
          param.add_column(column_id_[i], column_is_return_[i]);
        }

        for (i = 0; i < complex_column_id_count_; i++)
        {
          param.add_column(complex_column_id_[i],complex_column_id_[i], complex_column_is_return_[i]);
        }

        for (i = 0; i < orderby_column_id_count_; i++)
        {
          param.add_orderby_column(orderby_column_id_[i], 
              orderby_column_order_[i]==0?ObScanParam::ASC:ObScanParam::DESC);
        }

        if (where_cond_.length() > 0 &&  where_cond_.ptr() != NULL)
        {
          param.add_where_cond(where_cond_);
        }

        // groupby param
        for (i = 0; i < groupby_column_id_count_; i++)
        {
          param.get_group_by_param().add_groupby_column(groupby_column_id_[i], groupby_column_is_return_[i]);
        }
 
        for (i = 0; i < groupby_complex_column_id_count_; i++)
        {
          param.get_group_by_param().add_column(groupby_complex_column_id_[i], 
              groupby_complex_column_id_[i], 
              groupby_complex_column_is_return_[i]);
        }
 
        if (having_cond_.length() > 0 &&  having_cond_.ptr() != NULL)
        {        
          param.get_group_by_param().add_having_cond(having_cond_);
        }
        
        /// FIXME: SUM占位, 需要添加OP域
        for (i = 0; i < agg_column_id_count_; i++)
        {
          param.get_group_by_param().add_aggregate_column(agg_column_id_[i], 
              agg_column_as_name_[i], 
              (ObAggregateFuncType)agg_column_op_[i], 
              agg_column_is_return_[i]);
        }
      }
      return OB_SUCCESS;
    }
Пример #27
0
void read_scan_param(const char *fname, const char *section, PageArena<char> &allocer, ObScanParam &scan_param)
{
  TBSYS_CONFIG.load(fname);
  const char *str = NULL;
  int32_t len = 0;

  str = TBSYS_CONFIG.getString(section, SCAN_FROZEN_ONLY);
  if (0 == strcmp("YES", str))
  {
    //scan_param.set_is_read_frozen_only(true);
  }

  str = TBSYS_CONFIG.getString(section, SCAN_REVERSE);
  if (NULL == str
      || 0 != strcmp("YES", str))
  {
    scan_param.set_scan_direction(ObScanParam::FORWARD);
  }
  else
  {
    scan_param.set_scan_direction(ObScanParam::BACKWARD);
  }

  ObString table_name;
  sprintf(buffer, SCAN_TABLE_NAME);
  str = getAndCopySting_(allocer, section, buffer, len);
  table_name.assign_ptr(const_cast<char*>(str), len);

  uint64_t table_id = OB_INVALID_ID;
  if (NULL == str)
  {
    table_id = TBSYS_CONFIG.getInt(section, SCAN_TABLE_ID);
  }
  else
  {
    table_id = OB_INVALID_ID;
  }

  int32_t columns_num = TBSYS_CONFIG.getInt(section, SCAN_COLUMNS_NUM);
  for (int32_t i = 0; i < columns_num; i++)
  {
    ObString column_name;
    sprintf(buffer, SCAN_COLUMN_NAME_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    column_name.assign_ptr(const_cast<char*>(str), len);
    if (NULL != str)
    {
      scan_param.add_column(column_name);
    }
    else
    {
      sprintf(buffer, SCAN_COLUMN_ID_KEY_FORMAT, i);
      uint64_t column_id = TBSYS_CONFIG.getInt(section, buffer);
      scan_param.add_column(column_id);
    }
  }

  ObRange range;
  range.table_id_ = table_id;
  
  str = getAndCopySting_(allocer, section, SCAN_START_KEY, len);
  range.start_key_.assign_ptr(const_cast<char*>(str), len);
  if (0 == strcmp("MIN_KEY", str))
  {
    range.border_flag_.set_min_value();
  }
  if (0 == strcmp("MAX_KEY", str))
  {
    range.border_flag_.set_max_value();
  }
  
  str = getAndCopySting_(allocer, section, SCAN_END_KEY, len);
  range.end_key_.assign_ptr(const_cast<char*>(str), len);
  if (0 == strcmp("MIN_KEY", str))
  {
    range.border_flag_.set_min_value();
  }
  if (0 == strcmp("MAX_KEY", str))
  {
    range.border_flag_.set_max_value();
  }

  str = getAndCopySting_(allocer, section, SCAN_INCLUSIVE_START, len);
  if (0 == strcmp("YES", str))
  {
    range.border_flag_.set_inclusive_start();
  }
  str = getAndCopySting_(allocer, section, SCAN_INCLUSIVE_END, len);
  if (0 == strcmp("YES", str))
  {
    range.border_flag_.set_inclusive_end();
  }

  scan_param.set(table_id, table_name, range);
}
void init_decode_param(ObStringBuf &buf,  ObScanParam &org_scan_param)
{
  UNUSED(buf);
  const char *c_ptr;
  ObString str;
  ObNewRange q_range;
  q_range.set_whole_range();
  q_range.border_flag_.set_inclusive_start();
  q_range.border_flag_.set_inclusive_end();
  c_ptr = "collect_info";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  org_scan_param.reset();
  EXPECT_EQ(org_scan_param.set(OB_INVALID_ID, str,q_range), OB_SUCCESS);

  /// basic columns
  bool is_return = false;
  c_ptr = "item_collect_count";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.add_column(str,is_return), OB_SUCCESS );

  is_return = false;
  c_ptr = "item_category";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.add_column(str,is_return), OB_SUCCESS );

  is_return = true;
  c_ptr = "item_price";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.add_column(str,is_return), OB_SUCCESS );

  /// composite columns
  c_ptr = "`item_collect_count`*`item_price`";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.add_column(str,str, is_return), OB_SUCCESS );

  /// where condition
  c_ptr = "`item_price` > 10";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.add_where_cond(str), OB_SUCCESS );

  /// groupby::group by columns
  is_return = false;
  c_ptr = "item_category";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.get_group_by_param().add_groupby_column(str,is_return), OB_SUCCESS);

  /// aggregate columns
  is_return = true;
  c_ptr = "item_price";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.get_group_by_param().add_aggregate_column(str,str,  SUM, is_return), OB_SUCCESS);

  /// aggregate columns
  is_return = false;
  c_ptr = "item_collect_count";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.get_group_by_param().add_aggregate_column(str,str,  SUM, is_return), OB_SUCCESS);

  /// composite columns
  c_ptr = "`item_collect_count`*`item_price`";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.get_group_by_param().add_column(str, str,is_return), OB_SUCCESS );

  /// having condtion
  c_ptr = "`item_price` > 10";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.get_group_by_param().add_having_cond(str), OB_SUCCESS );

  /// orderby
  c_ptr = "item_price";
  str.assign((char*)c_ptr, static_cast<int32_t>(strlen(c_ptr)));
  EXPECT_EQ(org_scan_param.add_orderby_column(str),OB_SUCCESS);
}
Пример #29
0
int ObClientServerStub::cs_scan(const ObScanParam& scan_param, ObScanner& scanner)
{
  int ret = OB_SUCCESS;
  const int64_t timeout = 1000000;  // send_request timeout millionseconds
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

  // step 1. serialize timestamp to data_buff
  if (OB_SUCCESS == ret)
  {
    ret = scan_param.serialize(data_buff.get_data(), 
        data_buff.get_capacity(), data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize scan_param failed:ret[%d].", ret);
    }
  }

  // step 2. send request for fetch new schema
  if (OB_SUCCESS == ret)
  { 
    uint32_t pos = random() % merge_server_list_.size();
    ObServer &cur_server = merge_server_list_.at(pos);

    ret = rpc_frame_->send_request(cur_server, 
        OB_SCAN_REQUEST, DEFAULT_VERSION, timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to remote server for scan failed"
          " ret[%d].",  ret);
    }
  }


  // step 3. deserialize the response code
  int64_t pos = 0;
  if (OB_SUCCESS == ret)
  {
    ObResultCode result_code;
    ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize result_code failed:pos[%ld], ret[%d].", pos, ret);
    }
    else
    {
      ret = result_code.result_code_;
    }
  }
  // step 4. deserialize the table schema
  if (OB_SUCCESS == ret)
  {
    ret = scanner.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize scanner from buff failed"
          "pos[%ld], ret[%d].", pos, ret);
    }
  }

  return ret;
}
Пример #30
0
int MutatorBuilder::build_scan_param(ObScanParam &scan_param, PageArena<char> &allocer,
                                    const int64_t table_start_version, const bool using_id, int64_t &table_pos, int64_t &prefix)
{
  int ret = OB_SUCCESS;
  scan_param.reset();

  static int64_t row_info_array[OB_MAX_TABLE_NUMBER];
  static int64_t counter = 0;
  static const int64_t ROW_INFO_CACHE_FLUSH_PERIOD = 100;
  //static const int64_t ROW_INFO_CACHE_FLUSH_PERIOD = 1000000000;
  if (0 == (counter++ % ROW_INFO_CACHE_FLUSH_PERIOD))
  {
    memset(row_info_array, 0, sizeof(row_info_array));
  }

  int64_t rand = 0;
  lrand48_r(&table_rand_seed_, &rand);
  table_pos = range_rand(0, table_num_ - 1, rand);
  const ObSchema &schema = schema_mgr_.begin()[table_pos];

  if (0 == row_info_array[table_pos]
      && 0 == (row_info_array[table_pos] = get_cur_rowkey_info_(schema, using_id, rb_array_[table_pos]->get_prefix_start())))
  {
    ret = OB_ERROR;
  }
  else
  {
    ObRange range;
    std::pair<ObString, ObString> key_range = rb_array_[table_pos]->get_rowkey4scan(row_info_array[table_pos], allocer, prefix);
    range.start_key_ = key_range.first;
    range.end_key_ = key_range.second;

    if (using_id)
    {
      scan_param.add_column(SEED_COLUMN_ID);
    }
    else
    {
      ObString column_name;
      column_name.assign_ptr((char*)SEED_COLUMN_NAME, static_cast<int32_t>(strlen(SEED_COLUMN_NAME)));
      scan_param.add_column(column_name);
    }
    if (using_id)
    {
      scan_param.add_column(CELL_NUM_COLUMN_ID);
    }
    else
    {
      ObString column_name;
      column_name.assign_ptr((char*)CELL_NUM_COLUMN_NAME, static_cast<int32_t>(strlen(CELL_NUM_COLUMN_NAME)));
      scan_param.add_column(column_name);
    }

    lrand48_r(&table_rand_seed_, &rand);
    int64_t column_num = schema.column_end() - schema.column_begin();
    for (int64_t i = 0; i < column_num; i++)
    {
      lrand48_r(&table_rand_seed_, &rand);
      int64_t column_pos = range_rand(0, column_num - 1, rand);
      //int64_t column_pos = 0;
      const ObColumnSchema &column_schema = schema.column_begin()[column_pos];
      if (using_id)
      {
        scan_param.add_column(column_schema.get_id());
      }
      else
      {
        ObString column_name;
        column_name.assign_ptr(const_cast<char*>(column_schema.get_name()), static_cast<int32_t>(strlen(column_schema.get_name()))); 
        scan_param.add_column(column_name);
      }
    }

    if (using_id)
    {
      scan_param.set(schema.get_table_id(), ObString(), range);
    }
    else
    {
      ObString table_name;
      table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name())));
      scan_param.set(OB_INVALID_ID, table_name, range);
    }

    ObVersionRange version_range;
    version_range.start_version_ = table_start_version;
    version_range.border_flag_.set_max_value();
    version_range.border_flag_.set_inclusive_start();
    scan_param.set_version_range(version_range);
    char* is_read_consistency_cfg = getenv("is_read_consistency");
    bool is_read_consistency = (NULL != is_read_consistency_cfg && 0 == strcmp(is_read_consistency_cfg, "true"));
    scan_param.set_is_read_consistency(is_read_consistency);
  }
  return ret;
}