Ejemplo n.º 1
0
TEST(ObMultiVersionTabletImage, test_service)
{
  FileInfoCache fic;
  ObMultiVersionTabletImage image(fic);

  fic.init(100);
  CharArena allocator;
  ObRange r1,r2,r3;
  create_range(allocator, r1, 1, ObBorderFlag::INCLUSIVE_START|ObBorderFlag::INCLUSIVE_END, "aoo", "foo");
  create_range(allocator, r2, 1, ObBorderFlag::INCLUSIVE_END, "foo", "mj");
  create_range(allocator, r3, 1, ObBorderFlag::INCLUSIVE_END, "mj", "oi");

  int ret = 0;
  ObTablet* tablet = NULL;
  ObSSTableId id;
  id.sstable_file_id_ = 1;
  id.sstable_file_offset_ = 0;

  ret = image.alloc_tablet_object(r1, VERSION_1, tablet);
  ASSERT_EQ(0, ret);
  tablet->set_disk_no(1);
  ret = tablet->add_sstable_by_id(id);
  ASSERT_EQ(0, ret);
  ret = image.add_tablet(tablet, false);
  ASSERT_EQ(0, ret);

  //image.initialize_service_index();

  /*
  ret = image.alloc_tablet_object(r1, VERSION_2, tablet);
  ASSERT_EQ(0, ret);
  tablet->set_disk_no(1);
  ret = tablet->add_sstable_by_id(id);
  ASSERT_EQ(0, ret);
  ret = image.add_tablet(tablet, false);
  ASSERT_EQ(0, ret);

  ret = image.alloc_tablet_object(r2, VERSION_2, tablet);
  ASSERT_EQ(0, ret);
  id.sstable_file_id_ = 2;
  id.sstable_file_offset_ = 0;
  tablet->set_disk_no(2);
  tablet->add_sstable_by_id(id);
  ret = image.add_tablet(tablet, false);
  ASSERT_EQ(0, ret);

  ret = image.alloc_tablet_object(r3, VERSION_2, tablet);
  ASSERT_EQ(0, ret);
  id.sstable_file_id_ = 3;
  id.sstable_file_offset_ = 0;
  tablet->set_disk_no(3);
  tablet->add_sstable_by_id(id);
  ret = image.add_tablet(tablet, false);
  ASSERT_EQ(0, ret);

  ret = write_all(image);
  ASSERT_EQ(0, ret);
  */
  fic.destroy();
}
Ejemplo n.º 2
0
TEST(ObMultiVersionTabletImage, test_write_null)
{
  FileInfoCache fic;
  ObMultiVersionTabletImage image(fic);

  fic.init(100);
  CharArena allocator;
  ObRange r1;

  ObBorderFlag flag; 
  flag.set_min_value();
  flag.set_max_value();

  create_range(allocator, r1, 1, flag.get_data(), "", "");

  int ret = 0;
  ObTablet* tablet = NULL;
  ObSSTableId id;
  id.sstable_file_id_ = 1;
  id.sstable_file_offset_ = 0;

  ret = image.alloc_tablet_object(r1, VERSION_1, tablet);
  ASSERT_EQ(0, ret);
  tablet->set_disk_no(1);
  ret = tablet->add_sstable_by_id(id);
  ASSERT_EQ(0, ret);
  ret = image.add_tablet(tablet, false);
  ASSERT_EQ(0, ret);

  image.write(VERSION_1, 1);

  fic.destroy();
}
Ejemplo n.º 3
0
TEST(ObMultiVersionTabletImage, test_scan)
{
  FileInfoCache fic;
  ObMultiVersionTabletImage null_image(fic);
  int ret = null_image.begin_scan_tablets();
  ASSERT_EQ(OB_ITER_END, ret);

  ObMultiVersionTabletImage image(fic);
  CharArena allocator;
  ObRange r1,r2,r3;
  create_range(allocator, r1, 1, ObBorderFlag::INCLUSIVE_START|ObBorderFlag::INCLUSIVE_END, "aoo", "foo");
  create_range(allocator, r2, 1, ObBorderFlag::INCLUSIVE_END, "foo", "mj");
  create_range(allocator, r3, 1, ObBorderFlag::INCLUSIVE_END, "mj", "oi");

  ret = read_all(image);
  ASSERT_EQ(0, ret);

  ret = image.begin_scan_tablets();
  ObTablet* tablet = NULL;
  while (OB_SUCCESS == ret)
  {
    ret = image.get_next_tablet(tablet);
    if (OB_SUCCESS == ret) tablet->dump();
    if (NULL != tablet) image.release_tablet(tablet);
  }
  image.end_scan_tablets();


}
Ejemplo n.º 4
0
int TabletManagerIniter::create_tablet(const ObNewRange& range,
                                       const ObSSTableId& sst_id, bool serving,
                                       bool add_sst_id,
                                       const int64_t version)
{
  int ret = OB_SUCCESS;
  UNUSED(serving);

  if (range.empty())
  {
    TBSYS_LOG(ERROR, "create_tablet error, input range is empty.");
    ret = OB_INVALID_ARGUMENT;
  }

  if (OB_SUCCESS == ret)
  {
    ObTablet* tablet = NULL;
    // find tablet if exist?
    ObMultiVersionTabletImage &image = tablet_mgr_.get_serving_tablet_image();
    ret = image.acquire_tablet(range, ObMultiVersionTabletImage::SCAN_FORWARD, version, tablet);
    if (OB_SUCCESS == ret)
    {
      TBSYS_LOG(ERROR, "tablet already exists! dump input and exist:");
      range.hex_dump(TBSYS_LOG_LEVEL_ERROR);
      tablet->get_range().hex_dump(TBSYS_LOG_LEVEL_ERROR);
      ret = OB_ERROR;
      tablet = NULL;
      image.release_tablet(tablet);
    }
    else
    {
      ret = image.alloc_tablet_object(range, version, tablet);
      if (OB_SUCCESS == ret && add_sst_id)
      {
        ret = tablet->add_sstable_by_id(sst_id);
      }
      if (OB_SUCCESS == ret)
      {
        tablet->set_disk_no(sst_id.sstable_file_id_ & DISK_NO_MASK);
        ret = image.add_tablet(tablet, true, true);
      }
    }
  }

  return ret;
}
Ejemplo n.º 5
0
TEST(ObMultiVersionTabletImage, test_query_min_max)
{
  FileInfoCache fic;
  ObMultiVersionTabletImage image(fic);

  fic.init(100);
  CharArena allocator;
  ObRange r1,r2,r3;
  create_range(allocator, r1, 1, ObBorderFlag::INCLUSIVE_START|ObBorderFlag::INCLUSIVE_END, "aoo", "foo");
  create_range(allocator, r2, 1, ObBorderFlag::INCLUSIVE_END, "foo", "mj");
  create_range(allocator, r3, 1, ObBorderFlag::INCLUSIVE_END, "mj", "oi");

  ObRange rall;
  ObBorderFlag flag; 
  flag.set_min_value();
  flag.set_max_value();
  create_range(allocator, rall, 1, flag.get_data(), "aoo", "zoo");

  int ret = 0;
  ObTablet* tablet = NULL;
  ObSSTableId id;
  id.sstable_file_id_ = 1;
  id.sstable_file_offset_ = 0;

  ret = image.alloc_tablet_object(rall, VERSION_1, tablet);
  ASSERT_EQ(0, ret);
  tablet->set_disk_no(1);
  ret = tablet->add_sstable_by_id(id);
  ASSERT_EQ(0, ret);
  ret = image.add_tablet(tablet, false, true);
  ASSERT_EQ(0, ret);

  image.dump();

  ret = image.acquire_tablet(r1, ObMultiVersionTabletImage::SCAN_FORWARD, 0, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(VERSION_1, tablet->get_data_version());
  image.release_tablet(tablet);

  ret = image.acquire_tablet(rall, ObMultiVersionTabletImage::SCAN_FORWARD, 0, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(VERSION_1, tablet->get_data_version());
  tablet->get_range().hex_dump();
  image.release_tablet(tablet);

  fic.destroy();
}
Ejemplo n.º 6
0
TEST(ObMultiVersionTabletImage, test_query)
{
  FileInfoCache fic;
  ObMultiVersionTabletImage image(fic);
  fic.init(100);

  CharArena allocator;
  ObRange r1,r2,r3;
  create_range(allocator, r1, 1, ObBorderFlag::INCLUSIVE_START|ObBorderFlag::INCLUSIVE_END, "aoo", "foo");
  create_range(allocator, r2, 1, ObBorderFlag::INCLUSIVE_END, "foo", "mj");
  create_range(allocator, r3, 1, ObBorderFlag::INCLUSIVE_END, "mj", "oi");

  int ret = read_all(image);
  ASSERT_EQ(0, ret);
  image.dump();


  ObTablet *tablet = NULL;
  ret = image.acquire_tablet(r2, ObMultiVersionTabletImage::SCAN_FORWARD, 0, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r2));
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(VERSION_2, tablet->get_data_version());

  ret = image.acquire_tablet(r1, ObMultiVersionTabletImage::SCAN_FORWARD, 0, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r1));
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(VERSION_1, tablet->get_data_version());

  ret = image.acquire_tablet(r1, ObMultiVersionTabletImage::SCAN_FORWARD, VERSION_1, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r1));
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(VERSION_1, tablet->get_data_version());

  ObRange query_whole_range;
  query_whole_range.table_id_ = 1;
  query_whole_range.border_flag_.set_min_value();
  query_whole_range.border_flag_.set_max_value();
  ret = image.acquire_tablet(query_whole_range,  ObMultiVersionTabletImage::SCAN_FORWARD, VERSION_1, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r1));
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(VERSION_1, tablet->get_data_version());

  ret = image.acquire_tablet_all_version(query_whole_range, ObMultiVersionTabletImage::SCAN_BACKWARD, 
      ObMultiVersionTabletImage::FROM_NEWEST_INDEX, VERSION_2, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r3));
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);

  ret = image.acquire_tablet(query_whole_range, ObMultiVersionTabletImage::SCAN_BACKWARD, VERSION_1, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r1));
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);

  ObRange r4;
  create_range(allocator, r4, 1, ObBorderFlag::INCLUSIVE_START|ObBorderFlag::INCLUSIVE_END, "foo", "koo");
  ret = image.acquire_tablet_all_version(r4, ObMultiVersionTabletImage::SCAN_FORWARD, 
      ObMultiVersionTabletImage::FROM_NEWEST_INDEX, 0, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r1));
  ASSERT_EQ(VERSION_2, tablet->get_data_version());
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);

  create_range(allocator, r4, 1, ObBorderFlag::INCLUSIVE_START|ObBorderFlag::INCLUSIVE_END, "foz", "noo");
  ret = image.acquire_tablet(r4,  ObMultiVersionTabletImage::SCAN_FORWARD,0, tablet);
  ASSERT_EQ(0, ret);
  ASSERT_EQ(true, tablet->get_range().equal(r2));
  ASSERT_EQ(VERSION_2, tablet->get_data_version());
  ret = image.release_tablet(tablet);
  ASSERT_EQ(0, ret);

  fic.destroy();
}
Ejemplo n.º 7
0
    int ObGetScanProxy::get_compact_row(ObTablet& tablet,ObRowkey& rowkey,const int64_t compactsstable_version,
                                        const ColumnFilter *cf,
                                        ObScanner& compact_scanner)
    {

      int32_t compactsstable_num        = tablet.get_compactsstable_num();
      ObCompactSSTableMemNode* mem_node = tablet.get_compactsstable_list();
      ObCompactMemIteratorArray *its    = GET_TSI_MULT(ObCompactMemIteratorArray,TSI_CS_COMPACTSSTABLE_ITERATOR_1);
      ObCompactSSTableMem* mem          = NULL;
      int ret                           = OB_SUCCESS;
      int32_t m                         = 0;
      uint64_t table_id                 = OB_INVALID_ID;
      bool add_row_not_exist            = false;
      ObMerger merger;

      for(m=0; (OB_SUCCESS == ret) &&
            (mem_node != NULL) && (m < compactsstable_num); )
      {
        mem = &mem_node->mem_;
        if (NULL == mem)
        {
          TBSYS_LOG(WARN,"unexpect error,compactsstable is null");
          ret = OB_ERROR;
        }
        else if (ObVersion::compare(mem->get_data_version(),compactsstable_version) <= 0)
        {
          if (OB_INVALID_ID == table_id)
          {
            table_id = mem->get_table_id();
          }
          if (!mem->is_row_exist(rowkey))
          {
            //row not exists,do nothing            
            TBSYS_LOG(DEBUG,"row not exist,%s", to_cstring(rowkey));
            add_row_not_exist = true;
          }
          else if ((ret = its->iters_[m].init(mem)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN,"init iterator failed,ret=%d",ret);
          }
          else if ((ret = its->iters_[m].set_get_param(rowkey,cf)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN,"set get param failed,ret=%d",ret);
          }
          else if ((ret = merger.add_iterator(&(its->iters_[m]))) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN,"add iterator to merger failed,ret=%d",ret);
          }          
          else
          {
            ++m;
            //success
          }
        }
        else
        {
          break; //got enough data
        }
        mem_node = mem_node->next_;
      }

      if ((m > 0) && (OB_SUCCESS == ret))
      {
        if ((ret = fill_compact_data(merger,compact_scanner)) != OB_SUCCESS)
        {
          TBSYS_LOG(WARN,"fill compact data failed,ret=%d",ret);
        }
      }
      else if ((OB_SUCCESS == ret) && add_row_not_exist)
      {
        //not exist
        ObCellInfo cell;
        cell.table_id_ = table_id;
        cell.column_id_ = OB_INVALID_ID;
        cell.value_.set_ext(ObActionFlag::OP_ROW_DOES_NOT_EXIST);
        cell.row_key_ = rowkey;
        if ((ret = compact_scanner.add_cell(cell,false,true)) != OB_SUCCESS)
        {
          TBSYS_LOG(WARN,"add not exist cell failed,ret=%d",ret);
        }
      }
      return ret;
    }