Example #1
0
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();
}
Example #2
0
int main(int argc, char **argv)
{
  CmdLine clp;
  parse_cmd_line(argc, argv, clp);

  char buffer[1024];
  sprintf(buffer, "multi_write.%ld.log", clp.prefix_start);
  TBSYS_LOGGER.rotateLog(buffer);
  TBSYS_LOGGER.setFileName(buffer);
  TBSYS_LOGGER.setLogLevel(getenv("log_level")? getenv("log_level"): clp.log_level);
  clp.log_all();
  TBSYS_LOG(INFO, "cmdline: %s", my_str_join(argc, argv));
  TBSYS_LOG(INFO, "getpid()=%d", getpid());

  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.schema_addr, clp.schema_port, schema_mgr))
  {
    TBSYS_LOG(WARN, "fetch schema fail");
    exit(-1);
  }
  schema_mgr.print_info();

  ClientWrapper client;
  client.init(clp.write_addr, static_cast<int32_t>(clp.write_port));

  MutatorBuilder mb;
  mb.init4write(schema_mgr, clp.prefix_start,
                clp.read_addr, static_cast<int32_t>(clp.read_port),
                clp.table_start_version, clp.using_id,
                clp.suffix_length, clp.max_suffix, clp.prefix_end, clp.max_row, &client);

  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, clp.max_cell)))
    {
      TBSYS_LOG(WARN, "build_mutator fail ret=%d\n", ret);
      break;
    }
    while (true)
    {
      int64_t timeu = tbsys::CTimeUtil::getTime();
      ret = client.apply(mutator);
      TBSYS_LOG(DEBUG, "apply ret=%d timeu=%ld\n", ret, tbsys::CTimeUtil::getTime() - timeu);
      if (OB_SUCCESS == ret)
      {
        break;
      }
    }
  }
}