当前位置: 首页>>代码示例>>C++>>正文


C++ TaskInfo::set_index方法代码示例

本文整理汇总了C++中TaskInfo::set_index方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskInfo::set_index方法的具体用法?C++ TaskInfo::set_index怎么用?C++ TaskInfo::set_index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TaskInfo的用法示例。


在下文中一共展示了TaskInfo::set_index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fetch_task

int TaskManager::fetch_task(TaskCounter & counter, TaskInfo & task)
{
  int ret = OB_SUCCESS;
  int64_t task_count = 0;
  bool find_task = false;
  map<uint64_t, TaskInfo>::iterator it;
  tbsys::CThreadGuard lock(&lock_);
  // step 1. check waiting task
  for (it = wait_queue_.begin(); it != wait_queue_.end(); ++it)
  {
    for (int64_t i = 0; i < it->second.get_location().size(); ++i)
    {

      if (it->second.get_location()[i].tablet_version_ != tablet_version_ &&
          it->second.get_location()[i].tablet_version_ != (tablet_version_ + 1))
      {
#if 1
        it->second.get_location()[i].dump(it->second.get_location()[i]);
        TBSYS_LOG(DEBUG, "skip task[%ld], due to version compatiablility", it->first);
#endif
        continue;
      }

      TBSYS_LOG(DEBUG, "server:%ld is selected, task_count = %ld", 
                it->second.get_location()[i].chunkserver_.get_ipv4(),
                task_count);

      task_count = get_server_task_count(it->second.get_location()[i].chunkserver_);
      if (task_count >= max_count_)
      {
        continue;
      }
      else
      {
        task = it->second;
        task.set_index(i);
        find_task = true;
        task.set_timestamp(tbsys::CTimeUtil::getTime());
        // remove this item to doing_queue_
        wait_queue_.erase(it);
        doing_queue_.insert(pair<uint64_t, TaskInfo>(task.get_id(), task));
        break;
      }
    }
    if (find_task)
    {
      break;
    }
  }
  
  // step 2. check doing timeout task
  if ((false == find_task) && (total_finish_count_ != 0))
  {
    int64_t timestamp = tbsys::CTimeUtil::getTime();
    int64_t avg_finish_time = total_finish_time_/total_finish_count_;
    for (it = doing_queue_.begin(); it != doing_queue_.end(); ++it)
    {
      if ((timestamp - it->second.get_timestamp()) > (avg_times_ * avg_finish_time))
      {
        int64_t last_index = task.get_index();  /* last used mergeserver index */

        // timeout so reset the visit count 
        for (int64_t i = 0; i < it->second.get_location().size(); ++i)
        {
          if (i == last_index) {
            continue;                           /* do not allocate same task to same server */
          }

          task_count = get_server_task_count(it->second.get_location()[i].chunkserver_);
          // must > not include equal with
          if (task_count > max_count_)
          {
            continue;
          }
          else
          {
            TBSYS_LOG(INFO, "check task timeout:task[%lu], avg_time[%ld], timeout_times[%ld], "
                "total_time[%ld], total_finish[%ld], finish[%ld], now[%ld], add_time[%ld], old_idx=%lu, new_idx=%lu",
                it->second.get_id(), avg_finish_time, avg_times_, total_finish_time_, total_finish_count_,
                complete_queue_.size(), timestamp, it->second.get_timestamp(),
                last_index, i);
            // update timestamp
            it->second.set_timestamp(timestamp);
            task = it->second;
            task.set_index(i);
            find_task = true;
            break;
          }
        }

        if (find_task)
        {
          break;
        }
      }
    }
  }
  
  // set task start timestamp
  task.set_timestamp(tbsys::CTimeUtil::getTime());
//.........这里部分代码省略.........
开发者ID:Abioy,项目名称:oceanbase,代码行数:101,代码来源:task_manager.cpp


注:本文中的TaskInfo::set_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。