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(); }
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; }
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(); }