예제 #1
0
int main(int argc, char **argv)
{
  if (argc < 5)
  {
    usage(argv[0]);
    return 1;
  }

  gstreamer.set_packet_factory(&gfactory);
  NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  const char *root_ipport = argv[1];
  const char *local_ipport = argv[2];
  char *stat_time = argv[3];
  ExpireTaskType type = static_cast<ExpireTaskType>(atoi(argv[4]));

  uint64_t root_id = Func::get_host_ip(root_ipport);
  uint64_t local_id = Func::get_host_ip(local_ipport);
  int32_t spec_time = tbsys::CTimeUtil::strToTime(stat_time);

  printf("root_id: %"PRI64_PREFIX"d, es_id: %"PRI64_PREFIX"d, spec_time: %d, type: %d\n", root_id, local_id, spec_time, type);

  int32_t percent = 0;
  ReqQueryProgressMessage req_qp_msg;
  req_qp_msg.set_es_id(local_id);
  req_qp_msg.set_es_num(0);
  req_qp_msg.set_task_time(spec_time);
  req_qp_msg.set_hash_bucket_id(0);
  req_qp_msg.set_expire_task_type(type);

  tbnet::Packet *rsp = NULL;
  NewClient *client = NewClientManager::get_instance().create_client();
  int ret = send_msg_to_server(root_id, client, &req_qp_msg, rsp, ClientConfig::wait_timeout_);

  if (TFS_SUCCESS != ret)
  {
    printf("call query progress fail, ret: %d\n", ret);
    ret = EXIT_NETWORK_ERROR;
  }
  else if (RSP_QUERY_PROGRESS_MESSAGE == rsp->getPCode())
  {
    RspQueryProgressMessage *rsp_qp_msg = dynamic_cast<RspQueryProgressMessage*>(rsp);
    percent = rsp_qp_msg->get_current_percent();
    printf("query progress success, current percent: %d\%%\n", percent);
  }
예제 #2
0
int main(int argc, char *argv[])
{
  gstreamer.set_packet_factory(&gfactory);

  tfs::common::NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  int i;

  std::string old_server;
  std::string new_server;
  std::string log_file_name;
  std::string input_file_name;
  while ((i = getopt(argc, argv, "i:o:n:l:")) != EOF)
  {
    switch (i)
    {
      case 'i':
        input_file_name = optarg;
        break;
      case 'o':
        old_server = optarg;
        break;
      case 'n':
        new_server = optarg;
        break;
      case 'l':
        log_file_name = optarg;
        break;
      default:
        usage(argv[0]);
        return TFS_ERROR;
    }
  }
  cout << input_file_name  << "  -" << old_server << "  -" << new_server << "  -" << log_file_name << endl;
  if (input_file_name.empty() || log_file_name.empty())
  {
    usage(argv[0]);
    return TFS_ERROR;
  }
  TBSYS_LOGGER.setFileName(log_file_name.c_str());
  TBSYS_LOGGER.setLogLevel("info");
  signal(SIGINT, sign_handler);

  NameMetaClientImpl old_client;
  if( TFS_SUCCESS != old_client.initialize( old_server.c_str() ) )
  {
    return TFS_ERROR;
  }
  TBSYS_LOG(DEBUG, "old_client initialize SUCCESS");

  old_server_id = Func::get_host_ip(old_server.c_str());
  new_server_id = Func::get_host_ip(new_server.c_str());
  string tfs_name = "/";
  int32_t ret = TFS_SUCCESS;
  FILE *s_fd = NULL;
  s_fd = fopen(input_file_name.c_str(), "r");
  if (NULL == s_fd)
  {
    printf(" open file %s for read error\n", input_file_name.c_str());
    ret =  TFS_ERROR;
  }
  char buff[128];
  while(TFS_SUCCESS == ret && 1 != stop)
  {
    if (NULL == fgets(buff, 128, s_fd))
    {
      break;
    }
    buff[127] = 0;
    char *p = NULL;
    const char DLIMER = ',';
    p = strchr(buff, DLIMER);
    if (NULL == p)
    {
      TBSYS_LOG(ERROR, "err input line %s", buff);
      continue;
    }
    app_id = -1;
    uid = -1;
    *p = '\0';
    app_id = strtoll(buff, NULL, 10);
    uid = strtoll(p + 1, NULL, 10);
    if (app_id <= 0 || uid <= 0)
    {
      *p = DLIMER;
      TBSYS_LOG(ERROR, "err input line %s", buff);
      continue;
    }
    TBSYS_LOG(INFO, "check app_id %ld uid %ld", app_id, uid);
    ret = check(old_client, tfs_name);
  }
  fclose(s_fd);
  s_fd = NULL;
  return 0;
}
예제 #3
0
파일: tfstool.cpp 프로젝트: LinxiaHu/tfs
int main(int argc, char* argv[])
{
    int32_t i;
    int ret = TFS_SUCCESS;
    bool directly = false;
    bool set_log_level = false;

    // analyze arguments
    while ((i = getopt(argc, argv, "s:r:nih")) != EOF)
    {
        switch (i)
        {
        case 'n':
            set_log_level = true;
            break;
        case 's':
            nsip = optarg;
            break;
        case 'r':
            rc_addr = optarg;
            break;
        case 'i':
            directly = true;
            break;
        case 'h':
        default:
            usage(argv[0]);
            return TFS_ERROR;
        }
    }

    if (set_log_level)
    {
        TBSYS_LOGGER.setLogLevel("ERROR");
    }

    if (NULL == nsip && NULL == rc_addr)
    {
        usage(argv[0]);
        return TFS_ERROR;
    }

    gstreamer.set_packet_factory(&gfactory);
    NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

    if (nsip != NULL)
    {
        g_tfs_client = TfsClientImpl::Instance();
        ret = g_tfs_client->initialize(nsip, DEFAULT_BLOCK_CACHE_TIME, 1000, false);
        if (ret != TFS_SUCCESS)
        {
            fprintf(stderr, "init tfs client fail, ret: %d\n", ret);
            return ret;
        }
        g_use_meta = false;
    }
    else if (rc_addr != NULL)
    {
        strcpy(app_key, default_app_key);
        g_use_meta = true;
    }


    init();

    if (optind >= argc)
    {
        signal(SIGINT, sign_handler);
        signal(SIGTERM, sign_handler);
        main_loop();
    }
    else // has other params
    {
        int32_t i = 0;
        if (directly)
        {
            for (i = optind; i < argc; i++)
            {
                do_cmd(argv[i]);
            }
        }
        else
        {
            VSTRING param;
            for (i = optind; i < argc; i++)
            {
                param.clear();
                param.push_back(argv[i]);
                cmd_batch_file(param);
            }
        }
    }
    if (g_tfs_client != NULL)
    {
        g_tfs_client->destroy();
    }
    return TFS_SUCCESS;
}
예제 #4
0
파일: txt2newmeta.cpp 프로젝트: alimy/tfs
int main(int argc, char *argv[])
{
  gstreamer.set_packet_factory(&gfactory);

  tfs::common::NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  int i;
  std::string s3_server;
  std::string log_file_name;
  std::string date_time;
  uint32_t thread_num;
  while ((i = getopt(argc, argv, "f:d:t:l:p:a:u:")) != EOF)
  {
    switch (i)
    {
      case 'f':
        source_file_name = optarg;
        break;
      case 'd':
        s3_server = optarg;
        break;
      case 't':
        date_time = optarg;
        break;
      case 'l':
        log_file_name = optarg;
        break;
      case 'p':
        thread_num = atoi(optarg);
        break;
      case 'a':
        last_appid = atol(optarg);
        break;
      case 'u':
        last_uid = atol(optarg);
        break;
      default:
        usage(argv[0]);
        return TFS_ERROR;
    }
  }
  if (source_file_name.empty() || log_file_name.empty())
  {
    usage(argv[0]);
    return TFS_ERROR;
  }
  time_point = tbsys::CTimeUtil::strToTime(const_cast<char*>(date_time.c_str()));
  server_id = Func::get_host_ip(s3_server.c_str());
  TBSYS_LOGGER.setFileName(log_file_name.c_str());
  TBSYS_LOGGER.setLogLevel("info");
  signal(SIGINT, sign_handler);
  TBSYS_LOG(INFO, "date %s num_time %ld",date_time.c_str(), time_point);

  pthread_t* tid = (pthread_t*) malloc(thread_num * sizeof(pthread_t));
  arg_type* p_arg = (arg_type*) malloc(thread_num * sizeof(arg_type));
  for (uint32_t i = 0 ; i < thread_num ; ++i)
  {
     p_arg[i].tnum = i;
     p_arg[i].ttotal = thread_num;
     TBSYS_LOG(INFO,"i is %d tum is %d, ttotal is %d\n",i, p_arg[i].tnum, p_arg[i].ttotal);
  }

  thread_create(tid, p_arg, thread_num);

  thread_wait(tid, thread_num);



  //transfer(source_file_name, s3_server);
  free(p_arg);
  free(tid);
  return 0;
}
예제 #5
0
파일: main.cpp 프로젝트: alimy/tfs
int main(int argc,char** argv)
{
  //TODO readline
  int32_t i;
  string ns_ip_port_1;
  string ns_ip_port_2;
  bool directly = false;
  while ((i = getopt(argc, argv, "s:m:ihv")) != EOF)
  {
    switch (i)
    {
      case 's':
        ns_ip_port_2 = optarg;
        break;
      case 'm':
        ns_ip_port_1 = optarg;
        g_need_cmp = true;
        break;
      case 'i':
        directly = true;
        break;
      case 'v':
        version(argv[0]);
        break;
      case 'h':
      default:
        usage(argv[0]);
    }
  }

  if (ns_ip_port_2.empty() || (g_need_cmp && ns_ip_port_1.empty()))
  {
    fprintf(stderr, "please input nameserver ip and port.\n");
    usage(argv[0]);
  }

  TBSYS_LOGGER.setLogLevel("error");

  init();

  gstreamer.set_packet_factory(&gfactory);
  NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  if (!g_need_cmp)
  {
    g_show_info.set_ns_ip(ns_ip_port_2);
  }
  else
  {
    g_cmp_info.set_ns_ip(ns_ip_port_1, ns_ip_port_2);
  }

  signal(SIGINT, sign_handler);
  signal(SIGTERM, sign_handler);
  if (optind >= argc)
  {
    main_loop();
  }
  else
  {
    if (directly) // ssm ... -i "cmd"
    {
      for (i = optind; i < argc; i++)
      {
        do_cmd(argv[i]);
      }
      g_show_info.clean_last_file();
    }
    else// exec filename
    {
      VSTRING param;
      for (i = optind; i < argc; i++)
      {
        param.clear();
        param.push_back(argv[i]);
        cmd_batch(param);
      }
    }
  }
  NewClientManager::get_instance().destroy();
}
예제 #6
0
int main(int argc, char* argv[])
{
  int32_t i;
  bool directly = false;
  bool set_log_level = false;

  // analyze arguments
  while ((i = getopt(argc, argv, "s:k:ih")) != EOF)
  {
    switch (i)
    {
      case 'n':
        set_log_level = true;
        break;
      case 'k':
        krs_addr = optarg;
        break;
      case 'i':
        directly = true;
        break;
      case 'h':
      default:
        usage(argv[0]);
        return TFS_ERROR;
    }
  }

  if (set_log_level)
  {
    TBSYS_LOGGER.setLogLevel("ERROR");
  }

  if (NULL == krs_addr)
  {
    usage(argv[0]);
    return TFS_ERROR;
  }

  gstreamer.set_packet_factory(&gfactory);
  NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  if (krs_addr != NULL)
  {
    new_server_id = Func::get_host_ip(krs_addr);
  }

  init();

  if (optind >= argc)
  {
    signal(SIGINT, sign_handler);
    signal(SIGTERM, sign_handler);
    main_loop();
  }
  else // has other params
  {
    int32_t i = 0;
    if (directly)
    {
      for (i = optind; i < argc; i++)
      {
        do_cmd(argv[i]);
      }
    }
    else
    {
      VSTRING param;
      for (i = optind; i < argc; i++)
      {
        param.clear();
        param.push_back(argv[i]);
        cmd_batch_file(param);
      }
    }
  }
  return TFS_SUCCESS;
}
예제 #7
0
파일: stat_main.cpp 프로젝트: alimy/tfs
int main(int argc,char** argv)
{
  int32_t i;
  string ns_addr;
  string log_file("stat_log");
  int32_t top_num = 0;
  bool is_debug = true;
  while ((i = getopt(argc, argv, "s:f:m:nhv")) != EOF)
  {
    switch (i)
    {
      case 's':
        ns_addr = optarg;
        break;
      case 'f':
        log_file = optarg;
        break;
      case 'm':
        top_num = atoi(optarg);
        break;
      case 'n':
        is_debug = false;
        break;
      case 'v':
        version(argv[0]);
        break;
      case 'h':
      default:
        usage(argv[0]);
    }
  }

  if (ns_addr.empty())
  {
    fprintf(stderr, "please input nameserver ip and port.\n");
    usage(argv[0]);
  }
  uint64_t ns_id = get_addr(ns_addr);
  FILE* fp = fopen(log_file.c_str(), "w");
  if (fp == NULL)
  {
    TBSYS_LOG(ERROR, "open log file failed. file: %s", log_file.c_str());
    return TFS_ERROR;
  }

  if (! is_debug)
  {
    TBSYS_LOGGER.setLogLevel("warn");
  }

  gstreamer.set_packet_factory(&gfactory);
  int ret = NewClientManager::get_instance().initialize(&gfactory, &gstreamer);
  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(ERROR, "initialize NewClientManager fail, ret: %d", ret);
    return ret;
  }

  StatInfo stat_info;
  V_BLOCK_SIZE_RANGE v_block_size_range;
  V_DEL_BLOCK_RANGE v_del_block_range;
  set<BlockSize> s_big_block;
  set<BlockSize> s_topn_block;
  map<uint64_t, int32_t> family_map;

  // initialize
  int32_t row = 0;
  while (RANGE_ARR[row][0] != -1)
  {
    v_block_size_range.push_back(BlockSizeRange(RANGE_ARR[row][0], RANGE_ARR[row][1]));
    row++;
  }
  row = 0;
  while (DEL_RANGE_ARR[row][0] != -1)
  {
    v_del_block_range.push_back(DelBlockRange(DEL_RANGE_ARR[row][0], DEL_RANGE_ARR[row][1]));
    row++;
  }

  // do stat
  ret = family_process(ns_id, family_map);
  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(ERROR, "scan all families from ns fail, ret: %d", ret);
    return ret;
  }
  ret = block_process(ns_id, family_map, stat_info, v_block_size_range, v_del_block_range, s_big_block, top_num, s_topn_block);
  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(ERROR, "scan all blocks from ns fail, ret: %d", ret);
    return ret;
  }

  // print info to log file
  fprintf(fp, "--------------------------block file info-------------------------------\n");
  stat_info.dump(fp);
  fprintf(fp, "--------------------------block size range-------------------------------\n");
  V_BLOCK_SIZE_RANGE_ITER siter = v_block_size_range.begin();
  for (; siter != v_block_size_range.end(); siter++)
  {
    siter->dump(fp);
  }
  fprintf(fp, "--------------------------del block range-------------------------------\n");
  V_DEL_BLOCK_RANGE_ITER diter = v_del_block_range.begin();
  for (; diter != v_del_block_range.end(); diter++)
  {
    diter->dump(fp);
  }
  if (top_num > 0)
  {
    fprintf(fp, "--------------------------block list whose size bigger is than %d. num: %zd -------------------------------\n", THRESHOLD, s_big_block.size());
    set<BlockSize>::reverse_iterator rbiter = s_big_block.rbegin();
    for (; rbiter != s_big_block.rend(); rbiter++)
    {
      fprintf(fp, "block_id: %"PRI64_PREFIX"u, size: %d\n", rbiter->block_id_, rbiter->file_size_);
    }
    fprintf(fp, "--------------------------top %d block list-------------------------------\n", top_num);
    set<BlockSize>::reverse_iterator rtiter = s_topn_block.rbegin();
    for (; rtiter != s_topn_block.rend(); rtiter++)
    {
      fprintf(fp, "block_id: %"PRI64_PREFIX"u, size: %d\n", rtiter->block_id_, rtiter->file_size_);
    }
  }
  fclose(fp);
}
예제 #8
0
파일: rcstat.cpp 프로젝트: keoyeop/tfs
 RcStat::RcStat()
   :app_id_(0), oper_type_(0), order_by_(0), is_json_(false)
 {
   gstreamer.set_packet_factory(&gfactory);
   NewClientManager::get_instance().initialize(&gfactory, &gstreamer);
 }
예제 #9
0
파일: ds_client.cpp 프로젝트: 0huah0/tfs
int main(int argc, char* argv[])
{
  int i = 0;
  int iex = 0;

  // input option
  if (argc == 1)
  {
    usage(argv[0]);
    return TFS_ERROR;
  }
  while ((i = getopt(argc, argv, "d:i::")) != -1)
  {
    switch (i)
    {
    case 'i':
      iex = 1;
      break;
    case 'd':
      ds_ip = Func::get_host_ip(optarg);
      if (ds_ip == 0)
      {
        printf("ip or port is invalid, please try again.\n");
        return TFS_ERROR;
      }
      break;
    case ':':
      printf("missing -d");
      usage(argv[0]);
      break;
    default:
      usage(argv[0]);
      return TFS_ERROR;
    }
  }
  static tfs::message::MessageFactory factory;
  static tfs::common::BasePacketStreamer streamer;
  streamer.set_packet_factory(&factory);
  NewClientManager::get_instance().initialize(&factory, &streamer);

  init();

  if (optind >= argc)
  {
    signal(SIGINT, signal_handler);
    main_loop();
  }
  else
  {
    VSTRING param;
    int i = optind;
    if (iex)
    {
      printf("with i\n");
      for (i = optind; i < argc; i++)
      {
        param.clear();
        int cmd = parse_cmd(argv[i], param);
        switch_cmd(cmd, param);
      }
    }
    else
    {
      printf("without i\n");
      for (i = optind; i < argc; i++)
      {
        param.clear();
        param.push_back(argv[i]);
      }
    }
  }
  return TFS_SUCCESS;
}