コード例 #1
0
ファイル: multi_write.cpp プロジェクト: CCoder123/pproj
int main(int argc, char **argv)
{
  CmdLine clp;
  parse_cmd_line(argc, argv, clp);

  TBSYS_LOGGER.rotateLog("multi_write.log");
  TBSYS_LOGGER.setFileName("multi_write.log");
  TBSYS_LOGGER.setLogLevel("info");
  clp.log_all();

  ob_init_memory_pool();

  ObSchemaManager schema_mgr;
  if (NULL != clp.schema_file)
  {
    tbsys::CConfig config;
    if (!schema_mgr.parse_from_file(clp.schema_file, config))
    {
      TBSYS_LOG(WARN, "parse schema fail");
      exit(-1);
    }
  }
  else if (OB_SUCCESS != fetch_schema(clp.root_addr, clp.root_port, schema_mgr))
  {
    TBSYS_LOG(WARN, "fetch schema fail");
    exit(-1);
  }
  schema_mgr.print_info();

  MutatorBuilder mb;
  mb.init(schema_mgr,
          clp.prefix_start, clp.suffix_length,
          clp.merge_addr, clp.merge_port, clp.table_start_version,
          clp.max_cell, clp.max_row, clp.max_suffix);
  if (OB_SUCCESS != mb.init_prefix_end(clp.prefix_end))
  {
    TBSYS_LOG(WARN, "init prerfix end fail");
    exit(-1);
  }

  ObServer dst_host;
  dst_host.set_ipv4_addr(clp.serv_addr, clp.serv_port);
  MockClient client;
  client.init(dst_host);
  for (int64_t i = 0; i < clp.mutator_num; i++)
  {
    ObMutator mutator;
    PageArena<char> allocer;
    int ret = OB_SUCCESS;
    if (OB_SUCCESS != (ret = mb.build_mutator(mutator, allocer, clp.using_id)))
    {
      TBSYS_LOG(WARN, "build_mutator fail ret=%d\n", ret);
      break;
    }
    int64_t timeu = tbsys::CTimeUtil::getTime();
    ret = client.ups_apply(mutator, TIMEOUT_MS);
    TBSYS_LOG(INFO, "apply ret=%d timeu=%ld\n", ret, tbsys::CTimeUtil::getTime() - timeu);
  }
  client.destroy();
}
コード例 #2
0
ファイル: ups_admin.cpp プロジェクト: mrunix/oceanbase
void apply(const char *fname, PageArena<char> &allocer, MockClient &client)
{
  ObMutator mutator;
  ObMutator result;
  read_cell_infos(fname, CELL_INFOS_SECTION, allocer, mutator, result);
  int err = client.ups_apply(mutator, timeout);
  fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err);
}
コード例 #3
0
ファイル: test_ups_client.cpp プロジェクト: CCoder123/pproj
int apply(CParam &param, MockClient &client)
{
  int err = OB_SUCCESS;
  ObString table_name;
  table_name.assign(param.table_name_, strlen(param.table_name_));
  uint64_t table_id = param.schema_mgr_->get_table_id(table_name);
  if (table_id == 0)
  {
    TBSYS_LOG(ERROR, "fail to find table id:name[%s]", param.table_name_);
    err = OB_ERROR;
  }
  else
  {
    const ObSchema * schema = param.schema_mgr_->get_table_schema(table_id);
    if (NULL == schema)
    {
      TBSYS_LOG(ERROR, "check schema failed:id[%lu]", table_id);
      err = OB_ERROR;
    }
    else
    {
      ObString rowkey_str;
      ObString column_str;
      ObMutator mutator;
      ObObj value_obj;
      int64_t column_id = 0;
      char buffer[128];
      const ObColumnSchema * column_info = NULL;
      for (int64_t i = param.start_key_; i <= param.end_key_; ++i)
      {
        int64_t pos = 0;
        serialization::encode_i64(buffer, sizeof(buffer), pos, i);
        rowkey_str.assign(buffer, pos); 
        for (column_info = schema->column_begin(); column_info != schema->column_end(); ++column_info)
        {
          mutator.reset();
          if (NULL == column_info)
          {
            TBSYS_LOG(ERROR, "check column info failed:table[%lu], rowkey[%lu]", table_id, i);
            err = OB_ERROR;
            break;
          }
          column_id = column_info->get_id();
          column_str.assign(const_cast<char *>(column_info->get_name()), strlen(column_info->get_name()));
          if (column_info->get_type() == ObIntType)
          {
            //value_obj.set_int(1, true);
            value_obj.set_int(((i << 24) | (column_id << 16)) | (param.count_ + 1));
            err = mutator.update(table_name, rowkey_str, column_str, value_obj);
            if (OB_SUCCESS == err)
            {
              err = client.ups_apply(mutator, TIMEOUT);
              TBSYS_LOG(DEBUG, "update table:%.*s rowkey:%ld column:%.*s err:%d", 
                  table_name.length(), table_name.ptr(), i,
                  column_str.length(), column_str.ptr(), err);
            }
            else
            {
              TBSYS_LOG(ERROR, "update table:%.*s rowkey:%ld column:%.*s err:%d", 
                  table_name.length(), table_name.ptr(), i,
                  column_str.length(), column_str.ptr(), err);
              break;
            }
          }
          /*
          else
          {
            TBSYS_LOG(WARN, "check column type failed:table:%.*s rowkey:%.*s column:%.*s type:%lu",
                table_name.length(), table_name.ptr(), 
                rowkey_str.length(), rowkey_str.ptr(), column_str.length(), column_str.ptr(), column_info->get_type());
          }
          */
        }
        //
        if (err != OB_SUCCESS)
        {
          break;
        }
      }
    }
  }
  return err;     
}