Esempio n. 1
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;
}
Esempio n. 2
0
int CellinfoBuilder::get_result(const ObString &row_key, const ObSchema &schema,
                                const int64_t begin_seed, const int64_t end_seed,
                                result_set_t &result, PageArena<char> &allocer)
{
  int ret = OB_SUCCESS;
  for (int64_t seed = begin_seed; seed <= end_seed; seed++)
  {
    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;
    srand48_r(sign + 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++)
    {
      int op_type = 0;
      int64_t column_pos = 0;
      ObCellInfo *cell_info = (ObCellInfo*)allocer.alloc(sizeof(ObCellInfo));
      cell_info->reset();
      const ObColumnSchema *column_schema = schema.column_begin();

      build_cell_(rand_data, row_key, schema,
                  cell_info->value_, column_pos, op_type,
                  allocer);
      cell_info->table_id_ = table_id;
      cell_info->row_key_ = row_key;
      if (DEL_ROW == op_type)
      {
        cell_info->column_id_ = OB_INVALID_ID;
      }
      else
      {
        cell_info->column_id_ = column_schema[column_pos].get_id();
      }

      merge_obj(op_type, cell_info, result);
    }
  }
  return ret;
}
Esempio n. 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);
}
Esempio n. 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;
}
Esempio n. 5
0
void CellinfoBuilder::build_cell_(struct drand48_data &rand_data, const ObString &row_key, const ObSchema &schema,
                                  ObObj &obj, int64_t &column_pos, int &op_type,
                                  PageArena<char> &allocer)
{
  const ObColumnSchema *column_schema = schema.column_begin();
  int64_t column_num = schema.column_end() - schema.column_begin();
  int64_t rand = 0;

  lrand48_r(&rand_data, &rand);
  op_type = calc_op_type_(rand);
  //while (true)
  //{
  //  lrand48_r(&rand_data, &rand);
  //  column_pos = range_rand(0, column_num - 3, rand);
  //  if (ObIntType <= column_schema[column_pos].get_type()
  //      && ObVarcharType >= column_schema[column_pos].get_type())
  //  {
  //    break;
  //  }
  //}
  column_pos=0;

  lrand48_r(&rand_data, &rand);
  switch (column_schema[column_pos].get_type())
  {
    case ObIntType:
      {
        int64_t tmp = rand;
        obj.set_int(tmp, ADD == op_type);
        break;
      }
    case ObFloatType:
      {
        float tmp = static_cast<float>(rand);
        obj.set_float(tmp, ADD == op_type);
        break;
      }
    case ObDoubleType:
      {
        double tmp = static_cast<double>(rand);
        obj.set_double(tmp, ADD == op_type);
        break;
      }
    case ObDateTimeType:
      {
        ObDateTime tmp = static_cast<ObDateTime>(rand);
        obj.set_datetime(tmp, ADD == op_type);
        break;
      }
    case ObPreciseDateTimeType:
      {
        ObPreciseDateTime tmp = static_cast<ObPreciseDateTime>(rand);
        obj.set_precise_datetime(tmp, ADD == op_type);
        break;
      }
    case ObVarcharType:
      {
        int64_t length = range_rand(1, column_schema[column_pos].get_size(), rand);
        char *ptr = allocer.alloc(length);
        build_string(ptr, length, rand);
        ObString str;
        str.assign_ptr(ptr, length);
        if (ADD == op_type)
        {
          op_type = UPDATE;
        }
        obj.set_varchar(str);
        break;
      }
    default:
      break;
  }
  if (DEL_CELL == op_type)
  {
    obj.set_null();
  }
  else if (DEL_ROW == op_type)
  {
    obj.set_ext(ObActionFlag::OP_DEL_ROW);
  }
}