Exemple #1
0
int CellinfoBuilder::get_mutator(const ObString &row_key, const ObSchema &schema, int64_t &cur_seed,
                                ObMutator &mutator, PageArena<char> &allocer)
{
  int ret = OB_SUCCESS;
  
  int64_t sign = ob_crc64(row_key.ptr(), row_key.length());
  uint64_t table_id = schema.get_table_id();
  sign = ob_crc64(sign, &table_id, sizeof(uint64_t));

  struct drand48_data rand_data;
  cur_seed += 1;
  srand48_r(sign + cur_seed, &rand_data);

  int64_t rand = 0;
  lrand48_r(&rand_data, &rand);
  
  int64_t op_num = range_rand(1, max_op_num_, rand);
  for (int64_t i = 0; i < op_num; i++)
  {
    ret = build_operator_(rand_data, row_key, schema, mutator, allocer);
    if (OB_SUCCESS != ret)
    {
      break;
    }
  }
  ObString table_name;
  table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name()));
  ObString column_name;
  column_name.assign_ptr(SEED_COLUMN_NAME, strlen(SEED_COLUMN_NAME));
  ObObj obj;
  obj.set_int(cur_seed);
  mutator.update(table_name, row_key, column_name, obj);

  return ret;
}
Exemple #2
0
bool get_check_row(const ObSchema &schema, const ObString &row_key, CellinfoBuilder &cb,
                  MockClient &client, const int64_t table_start_version, const bool using_id)
{
  bool bret = false;

  ObGetParam get_param;
  const ObColumnSchema *iter = NULL;
  for (iter = schema.column_begin(); iter != schema.column_end(); iter++)
  {
    ObCellInfo ci;
    ci.row_key_ = row_key;
    if (using_id) 
    {
      ci.table_id_ = schema.get_table_id();
      ci.column_id_ = iter->get_id();
    }
    else
    {
      ci.table_name_.assign_ptr(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name()));
      ci.column_name_.assign_ptr(const_cast<char*>(iter->get_name()), strlen(iter->get_name()));
    }
    get_param.add_cell(ci);
  }
  ObVersionRange version_range;
  version_range.start_version_ = table_start_version;
  version_range.border_flag_.set_max_value();
  version_range.border_flag_.set_inclusive_start();
  get_param.set_version_range(version_range);

  ObScanner scanner;
  int ret = client.ups_get(get_param, scanner, TIMEOUT_MS);
  if (OB_SUCCESS == ret)
  {
    RowChecker rc;
    while (OB_SUCCESS == scanner.next_cell())
    {
      ObCellInfo *ci = NULL;
      if (OB_SUCCESS == scanner.get_cell(&ci))
      {
        if (!using_id)
        {
          trans_name2id(*ci, schema);
        }
        rc.add_cell(ci);
      }
    }
    bret = rc.check_row(cb, schema);
  }
  else
  {
    TBSYS_LOG(WARN, "get ret=%d", ret);
  }
  return bret;
  return true;
}
Exemple #3
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);
}
Exemple #4
0
int CellinfoBuilder::build_operator_(struct drand48_data &rand_data, const ObString &row_key, const ObSchema &schema,
                                    ObMutator &mutator, PageArena<char> &allocer)
{
  int ret = OB_SUCCESS;

  int op_type = 0;
  int64_t column_pos = 0;
  ObObj obj;
  build_cell_(rand_data, row_key, schema,
              obj, column_pos, op_type,
              allocer);
  const ObColumnSchema *column_schema = schema.column_begin();

  ObString table_name;
  ObString column_name;
  table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name()));
  column_name.assign_ptr(const_cast<char*>(column_schema[column_pos].get_name()),
                        strlen(column_schema[column_pos].get_name()));
  switch (op_type)
  {
    case DEL_CELL:
    case UPDATE:
    case ADD:
      mutator.update(table_name, row_key, column_name, obj);
      break;
    case INSERT:
      mutator.insert(table_name, row_key, column_name, obj);
      break;
    case DEL_ROW:
      ret = mutator.del_row(table_name, row_key);
      break;
    default:
      break;
  }

  return ret;
}
Exemple #5
0
int MutatorBuilder::write_prefix_meta_(ClientWrapper &client, const ObSchema &schema, const int64_t prefix_start,
                                      const int64_t param, const char *column_name)
{
  int ret = OB_SUCCESS;
  ObMutator mutator;
  ObString table_name;
  table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name())));
  ObString meta_column_name;
  meta_column_name.assign_ptr(const_cast<char*>(column_name), static_cast<int32_t>(strlen(column_name)));
  ObString rowkey_info_rowkey;
  char rowkey_info_buffer[1024];
  sprintf(rowkey_info_buffer, "%s%020ld", ROWKEY_INFO_ROWKEY, prefix_start);
  rowkey_info_rowkey.assign_ptr(rowkey_info_buffer, static_cast<int32_t>(strlen(rowkey_info_buffer)));
  ObObj meta_obj;
  meta_obj.set_int(param);
  if (OB_SUCCESS == (ret = mutator.update(table_name, rowkey_info_rowkey, meta_column_name, meta_obj)))
  {
    ret = client.apply(mutator);
  }
  return ret;
}
Exemple #6
0
int64_t MutatorBuilder::get_cur_seed_(const seed_map_t &seed_map, const ObSchema &schema, const ObString &row_key, const bool using_id)
{
  int64_t cur_seed = 0;
  
  TEKey te_key;
  te_key.table_id = schema.get_table_id();
  te_key.row_key = row_key;

  int hash_ret = 0;
  if (HASH_EXIST != (hash_ret = seed_map.get(te_key, cur_seed)))
  {
    ObGetParam get_param;
    ObScanner scanner;
    ObCellInfo cell_info;
    cell_info.row_key_ = row_key;
    if (using_id)
    {
      cell_info.table_id_ = schema.get_table_id();
      cell_info.column_id_ = SEED_COLUMN_ID;
    }
    else
    {
      cell_info.table_name_.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name())));
      cell_info.column_name_.assign_ptr((char*)SEED_COLUMN_NAME, static_cast<int32_t>(strlen(SEED_COLUMN_NAME)));
    }
    get_param.add_cell(cell_info);
    ObVersionRange version_range;
    version_range.start_version_ = table_start_version_;
    version_range.border_flag_.set_max_value();
    version_range.border_flag_.set_inclusive_start();
    get_param.set_version_range(version_range);
    if (OB_SUCCESS == client_.get(get_param, scanner))
    {
      CellinfoBuilder::result_set_t result_set;
      MemTank mem_tank;
      while (OB_SUCCESS == scanner.next_cell())
      {
        ObCellInfo *ci = NULL;
        if (OB_SUCCESS != scanner.get_cell(&ci))
        {
          break;
        }
        if (!using_id)
        {
          ::trans_name2id(*ci, schema);
        }
        ObCellInfo *new_ci = copy_cell(mem_tank, ci);
        CellinfoBuilder::merge_obj(new_ci, result_set);
      }
      if (0 != result_set.size())
      {
        ObCellInfo *ret_ci = NULL;
        result_set.get(SEED_COLUMN_ID, ret_ci);
        if (NULL != ret_ci)
        {
          ret_ci->value_.get_int(cur_seed);
        }
        TBSYS_LOG(DEBUG, "seed get from oceanbase %s", print_cellinfo(ret_ci));
      }
    }
    else
    {
      abort();
    }
  }
  if (0 == cur_seed)
  {
    cur_seed = SEED_START;
    TBSYS_LOG(DEBUG, "first seed from cur_seed=%ld row_key=[%.*s]", cur_seed, row_key.length(), row_key.ptr());
  }
  else
  {
    cur_seed += 1;
  }
  TBSYS_LOG(DEBUG, "get cur_seed=%ld hash_ret=%d row_key=[%.*s]", cur_seed, hash_ret, row_key.length(), row_key.ptr());
  return cur_seed;
}
Exemple #7
0
int64_t MutatorBuilder::query_prefix_meta_(const ObSchema &schema, const bool using_id, const int64_t prefix_start, const char *column_name)
{
  int64_t ret = 0;

  ObGetParam get_param;
  ObScanner scanner;
  ObCellInfo cell_info;
  if (using_id)
  {
    cell_info.table_id_ = schema.get_table_id();
    cell_info.column_id_ = schema.find_column_info(column_name)->get_id();
  }
  else
  {
    cell_info.table_name_.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name())));
    cell_info.column_name_.assign_ptr(const_cast<char*>(column_name), static_cast<int32_t>(strlen(column_name)));
  }
  char rowkey_info_buffer[1024];
  sprintf(rowkey_info_buffer, "%s%020ld", ROWKEY_INFO_ROWKEY, prefix_start);
  cell_info.row_key_.assign_ptr(rowkey_info_buffer, static_cast<int32_t>(strlen(rowkey_info_buffer)));
  get_param.add_cell(cell_info);
  ObVersionRange version_range;
  version_range.start_version_ = table_start_version_;
  version_range.border_flag_.set_max_value();
  version_range.border_flag_.set_inclusive_start();
  get_param.set_version_range(version_range);

  if (OB_SUCCESS == (ret = client_.get(get_param, scanner)))
  {
    CellinfoBuilder::result_set_t result_set;
    ::MemTank mem_tank;
    while (OB_SUCCESS == scanner.next_cell())
    {
      ObCellInfo *ci = NULL;
      if (OB_SUCCESS != scanner.get_cell(&ci))
      {
        break;
      }
      if (!using_id)
      {
        ::trans_name2id(*ci, schema);
      }
      ObCellInfo *new_ci = copy_cell(mem_tank, ci);
      CellinfoBuilder::merge_obj(new_ci, result_set);
    }
    if (0 != result_set.size())
    {
      ObCellInfo *ret_ci = NULL;
      result_set.get(schema.find_column_info(column_name)->get_id(), ret_ci);
      if (NULL != ret_ci)
      {
        ret_ci->value_.get_int(ret);
      }
    }
  }
  else
  {
    abort();
  }

  return ret;
}