示例#1
0
void MigrateTestEnv::setup()
{
  // 1. init
  ObRootServer2* rs = worker_.get_root_server();
  ASSERT_TRUE(rs->init("./root_server.conf", 100, &worker_));

  rs->start_threads();
  sleep(1);
  
  // 2. cs register
  int status;
  ASSERT_EQ(OB_SUCCESS, rs->regist_server(cs1_, false, status));
  ASSERT_EQ(OB_SUCCESS, rs->regist_server(cs2_, false, status));

  // 3. cs1 report tablets replicas
  ObTabletReportInfoList report_list1;
  ObTabletReportInfoList report_list2;
  ObTabletReportInfo report_info;
  ObTabletLocation location;
  location.tablet_version_ = tablet_version_;
  info1_.range_.table_id_ = 10001;
  info1_.range_.border_flag_.set_inclusive_end();
  info1_.range_.border_flag_.unset_inclusive_start();
  info1_.range_.border_flag_.set_min_value();
  info1_.range_.border_flag_.unset_max_value();

  info1_.range_.start_key_.assign_buffer(buf1[0], 30);
  info1_.range_.end_key_.assign_buffer(buf2[0], 30);
  info1_.range_.start_key_.write("aa1", 3);
  info1_.range_.end_key_.write("ba1", 3);

  location.chunkserver_ = cs1_;

  report_info.tablet_info_ = info1_;
  report_info.tablet_location_ = location;
  report_list1.add_tablet(report_info);

  info1_.range_.border_flag_.unset_min_value();
  info1_.range_.border_flag_.set_max_value();
  info1_.range_.start_key_.assign_buffer(buf1[1], 30);
  info1_.range_.end_key_.assign_buffer(buf2[1], 30);
  info1_.range_.start_key_.write("ba1", 3);
  info1_.range_.end_key_.write("ca1", 3);

  report_info.tablet_info_ = info1_;
  report_info.tablet_location_ = location;
  report_list1.add_tablet(report_info);

  int64_t now = tbsys::CTimeUtil::getTime();
  ASSERT_EQ(OB_SUCCESS, rs->report_tablets(cs1_, report_list1, now));
  ASSERT_EQ(OB_SUCCESS, rs->report_tablets(cs2_, report_list2, now));

  // wait init finish
  sleep(5);
}
示例#2
0
// 每个tablet两个复本,每个CS上均匀分布
void ObBalanceTest::report_tablets_2replicas(BalanceTestParams &params)
{
  ObTabletReportInfoList* report_lists = new (std::nothrow) ObTabletReportInfoList[params.cs_num_];
  ASSERT_TRUE(NULL != report_lists);
  int64_t *tablets_per_cs = new(std::nothrow) int64_t[params.cs_num_];
  ASSERT_TRUE(NULL != tablets_per_cs);
  ObTabletReportInfo tablet;
  for (int i = 0; i < params.table_num_; ++i)
  {
    int32_t sstables_count = params.sstables_per_table_[i];
    TBSYS_LOG(INFO, "table_id=%lu sstables=%d\n", get_table_id(i), sstables_count);
    for (int j = 0; j < params.cs_num_; ++j)
    {
      TBSYS_LOG(INFO, "sstables dist per cs, %d", params.sstables_dist[i][j]);
      reset_report_info_list(report_lists[j]);
      tablets_per_cs[j] = 0;
    }
    int k = 0;
    for (int j = 0; j < sstables_count; ++j)
    {
      int replicas = 0;
      while (replicas < 2)
      {
        if (0 < params.sstables_dist[i][k])
        {
          get_report_tablet(tablet, sstables_count, i, j, k, params.sstable_size_);
          int ret2 = report_lists[k].add_tablet(tablet);
          if (OB_ARRAY_OUT_OF_RANGE == ret2)
          {
            // report
            int ret = server_->report_tablets(get_addr(k), report_lists[k], 1);
            ASSERT_EQ(OB_SUCCESS, ret);
            TBSYS_LOG(INFO, "report tablets, cs=%d count=%ld", k, report_lists[k].get_tablet_size());
            reset_report_info_list(report_lists[k]);
            ret2 = report_lists[k].add_tablet(tablet);
          }
          ASSERT_EQ(OB_SUCCESS, ret2);
          tablets_per_cs[k]++;
          ++replicas;
        }
        k++;
        if (k >= params.cs_num_)
        {
          k = 0;
        }
      }
    }
    for (int k = 0; k < params.cs_num_; ++k)
    {
      if (0 < report_lists[k].get_tablet_size())
      {
        int ret = server_->report_tablets(get_addr(k), report_lists[k], 1);
        ASSERT_EQ(OB_SUCCESS, ret);
        TBSYS_LOG(INFO, "report tablets, cs=%d count=%ld", k, report_lists[k].get_tablet_size());
      }
    }
    for (int k = 0; k < params.cs_num_; ++k)
    {
      TBSYS_LOG(INFO, "reported tablets, table=%lu cs_idx=%d tablets=%ld", 
                get_table_id(i), k, tablets_per_cs[k]);
    }
  } // end for each table
  
  if (NULL != tablets_per_cs)
  {
    delete [] tablets_per_cs;
    tablets_per_cs = NULL;
  }
  if (NULL != report_lists)
  {
    delete [] report_lists;
  }
}