예제 #1
0
int main(int argc, char* argv[])
{
  ObServer cs;
  cs.set_ipv4_addr("localhost", 3500);

  BaseClient client;
  client.initialize();
  
  ObServer root;
  root.set_ipv4_addr("10.232.35.40", 2500);

  ThreadSpecificBuffer buffer;
  ObRootServerRpcStub server;
  
  do
  {
    int ret = server.init(root, client.get_rpc());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "init failed");
      break;
    } 

    int64_t timeout = 2000;
    int64_t timestamp = 0;
    // heartbeat 
    ret = server.renew_heartbeat(timeout, cs, timestamp); 
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "renew heartbeat failed:ret[%d]", ret);
      break;
    }
    else
    {
      printf("get new lease time[%ld]\n", timestamp);
    }

    sleep(1);
    
    // fetch schema
    timestamp = 1282900503726484;
    ObSchemaManager schema;
    ret = server.fetch_schema(timeout, timestamp, schema);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "fetch schema failed:ret[%d]", ret);
      break;
    }
    else
    {
      printf("fetch schema succ:appname[%s]\n", schema.get_app_name());
      schema.print_info();
    }
  } while(0);
  client.destory();
  return 0;
}
예제 #2
0
int CellinfoBuilder::check_schema_mgr(const ObSchemaManager &schema_mgr)
{
  int ret = OB_SUCCESS;
  const ObSchema *schema = NULL;
  for (schema = schema_mgr.begin(); schema != schema_mgr.end(); ++schema)
  {
    if (NULL == schema->find_column_info(SEED_COLUMN_NAME)
        || NULL == schema->find_column_info(ROWKEY_INFO_COLUMN_NAME)
        || SEED_COLUMN_ID != schema->find_column_info(SEED_COLUMN_NAME)->get_id()
        || ROWKEY_INFO_COLUMN_ID != schema->find_column_info(ROWKEY_INFO_COLUMN_NAME)->get_id())
    {
      TBSYS_LOG(WARN, "no seed or rowkey_info column in the schema");
      ret = OB_ERROR;
      break;
    }
  }
  return ret;
}
예제 #3
0
int MutatorBuilder::init4write(const ObSchemaManager &schema_mgr,
                              const int64_t prefix_start,
                              const char *serv_addr,
                              const int serv_port,
                              const int64_t table_start_version,
                              const bool using_id,
                              const int64_t suffix_length,
                              const int64_t suffix_num,
                              const int64_t prefix_end,
                              const int64_t max_rownum_per_mutator,
                              ClientWrapper *client4write)
{
  int ret = OB_SUCCESS;
  if (OB_SUCCESS != (ret = CellinfoBuilder::check_schema_mgr(schema_mgr)))
  {
    TBSYS_LOG(WARN, "schema cannot pass check");
  }
  else
  {
    client_.init(serv_addr, serv_port);

    table_num_ = schema_mgr.end() - schema_mgr.begin();
    srand48_r(time(NULL), &table_rand_seed_);
    schema_mgr_ = schema_mgr;
    max_rownum_per_mutator_ = max_rownum_per_mutator;
    table_start_version_ = table_start_version;
    //seed_map_.create(2000000);
    const ObSchema *schema_array = schema_mgr_.begin();
    for (int64_t i = 0; i < table_num_; i++)
    {
      int64_t tmp_suffix_length = get_suffix_length_(schema_array[i], using_id, prefix_start);
      tmp_suffix_length = (0 == tmp_suffix_length) ? suffix_length : tmp_suffix_length;
      int64_t tmp_suffix_num = get_suffix_num_(schema_array[i], using_id, prefix_start);
      tmp_suffix_num = (0 == tmp_suffix_num) ? suffix_num : tmp_suffix_num;
      int64_t tmp_prefix_end = get_prefix_end_(schema_array[i], using_id, prefix_start);
      tmp_prefix_end = std::max(prefix_end, tmp_prefix_end);
      if (0 == tmp_suffix_length
          || 0 == tmp_suffix_num
          || 0 == tmp_prefix_end)
      {
        TBSYS_LOG(WARN, "suffix_length=%ld suffix_num=%ld prefix_end=%ld",
                  tmp_suffix_length, tmp_suffix_num, tmp_prefix_end);
        ret = OB_ERROR;
        break;
      }
      if (NULL == (cb_array_[i] = new(std::nothrow) CellinfoBuilder())
          || NULL == (rb_array_[i] = new(std::nothrow) RowkeyBuilder(prefix_start, tmp_suffix_num, tmp_suffix_length)))
      {
        ret = OB_ERROR;
        break;
      }
      prefix_end_array_[i] = tmp_prefix_end;
      if (NULL == client4write)
      {
        continue;
      }
      if (OB_SUCCESS != (ret = put_suffix_length_(*client4write, schema_array[i], prefix_start, tmp_suffix_length)))
      {
        break;
      }
      if (OB_SUCCESS != (ret = put_suffix_num_(*client4write, schema_array[i], prefix_start, tmp_suffix_num)))
      {
        break;
      }
      if (OB_SUCCESS != (ret = put_prefix_end_(*client4write, schema_array[i], prefix_start, tmp_prefix_end)))
      {
        break;
      }
    }
  }
  assert(OB_SUCCESS == ret);
  return ret;
}
예제 #4
0
int ObFinalResult::apply_join(ObSchemaManager &schema_mgr,
                              oceanbase::common::ObCellInfo& left_cell, 
                              const oceanbase::common::ObJoinInfo &join_info)
{
  int err = OB_SUCCESS; 
  ObCellInfo get_cell;
  const ObSchema *right_schema = NULL;
  uint64_t right_table_id = OB_INVALID_ID;
  uint64_t right_column_id = OB_INVALID_ID;
  int32_t right_key_start_pos = 0;
  int32_t right_key_end_pos = 0;
  ObScanner right_scanner;
  ObGetParam get_param;
  get_param.reset();
  join_info.get_rowkey_join_range(right_key_start_pos, right_key_end_pos);
  if (-1 == right_key_start_pos && -1 == right_key_end_pos)
  {
    right_key_start_pos = 0;
    right_key_end_pos = left_cell.row_key_.length();
  }
  else
  {
    right_key_end_pos += 1;
  }
  get_cell.row_key_.assign(left_cell.row_key_.ptr() + right_key_start_pos, 
                           right_key_end_pos - right_key_start_pos);
  right_table_id  =  join_info.get_table_id_joined();
  right_column_id =  join_info.find_right_column_id(left_cell.column_id_);
  right_schema = schema_mgr.get_table_schema(right_table_id);
  if (NULL == right_schema)
  {
    TBSYS_LOG(WARN,"unexpected error, fail to get right table schema");
    err = OB_ERR_UNEXPECTED;
  }
  if (OB_SUCCESS == err)
  {
    const ObColumnSchema * column_info = NULL;
    get_cell.table_name_.assign(const_cast<char*>(right_schema->get_table_name()),
                                strlen(right_schema->get_table_name())); 
    column_info = right_schema->find_column_info(right_column_id);
    if (NULL == column_info)
    {
      TBSYS_LOG(WARN,"unexpected error, fail to get right column schema");
      err = OB_ERR_UNEXPECTED;
    }
    if (OB_SUCCESS == err)
    {
      get_cell.column_name_.assign(const_cast<char*>(column_info->get_name()), 
                                   strlen(column_info->get_name()));
      err = get_param.add_cell(get_cell);
    }
  }
  if (OB_SUCCESS == err)
  {
    err = get(get_param,right_scanner,false);
  }
  while (OB_SUCCESS == err)
  {
    ObCellInfo *cur_cell = NULL;
    err = right_scanner.next_cell();
    if (OB_SUCCESS == err)
    {
      err = right_scanner.get_cell(&cur_cell);
    }
    if (OB_SUCCESS == err)
    {
      TBSYS_LOG(DEBUG, "apply one cell");
      err = left_cell.value_.apply(cur_cell->value_);
    }
  }
  if (OB_ITER_END == err)
  {
    err = OB_SUCCESS;
  }
  return err;
}