};
using TestBlockRef = TCachedExtentRef<TestBlock>;
+struct TestBlockPhysical : crimson::os::seastore::CachedExtent{
+ constexpr static segment_off_t SIZE = 4<<10;
+ using Ref = TCachedExtentRef<TestBlockPhysical>;
+
+ std::vector<test_block_delta_t> delta = {};
+
+ TestBlockPhysical(ceph::bufferptr &&ptr)
+ : CachedExtent(std::move(ptr)) {}
+ TestBlockPhysical(const TestBlock &other)
+ : CachedExtent(other) {}
+
+ CachedExtentRef duplicate_for_write() final {
+ return CachedExtentRef(new TestBlockPhysical(*this));
+ };
+
+ static constexpr extent_types_t TYPE = extent_types_t::TEST_BLOCK_PHYSICAL;
+ extent_types_t get_type() const final {
+ return TYPE;
+ }
+
+ void set_contents(char c, uint16_t offset, uint16_t len) {
+ ::memset(get_bptr().c_str() + offset, c, len);
+ }
+
+ void set_contents(char c) {
+ set_contents(c, 0, get_length());
+ }
+
+ ceph::bufferlist get_delta() final { return ceph::bufferlist(); }
+
+ int checksum() { return 0; }
+
+ void apply_delta_and_adjust_crc(paddr_t, const ceph::bufferlist &bl) final {}
+};
+using TestBlockPhysicalRef = TCachedExtentRef<TestBlockPhysical>;
+
struct test_block_mutator_t {
std::uniform_int_distribution<int8_t>
contents_distribution = std::uniform_int_distribution<int8_t>(
int csum = 0;
{
auto t = get_transaction();
- auto extent = cache.alloc_new_extent<TestBlock>(
+ auto extent = cache.alloc_new_extent<TestBlockPhysical>(
*t,
- TestBlock::SIZE);
+ TestBlockPhysical::SIZE);
extent->set_contents('c');
csum = extent->checksum();
auto ret = submit_transaction(std::move(t)).get0();
}
{
auto t = get_transaction();
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
ASSERT_EQ(extent->get_paddr(), addr);
ASSERT_EQ(extent->checksum(), csum);
}
{
// write out initial test block
auto t = get_transaction();
- auto extent = cache.alloc_new_extent<TestBlock>(
+ auto extent = cache.alloc_new_extent<TestBlockPhysical>(
*t,
- TestBlock::SIZE);
+ TestBlockPhysical::SIZE);
extent->set_contents('c');
csum = extent->checksum();
auto reladdr = extent->get_paddr();
{
// test that read with same transaction sees new block though
// uncommitted
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t,
reladdr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
ASSERT_TRUE(extent->is_clean());
ASSERT_TRUE(extent->is_pending());
ASSERT_TRUE(extent->get_paddr().is_relative());
{
// test that consecutive reads on the same extent get the same ref
auto t = get_transaction();
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
auto t2 = get_transaction();
- auto extent2 = cache.get_extent<TestBlock>(
+ auto extent2 = cache.get_extent<TestBlockPhysical>(
*t2,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
ASSERT_EQ(&*extent, &*extent2);
}
{
// read back test block
auto t = get_transaction();
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
// duplicate and reset contents
- extent = cache.duplicate_for_write(*t, extent)->cast<TestBlock>();
+ extent = cache.duplicate_for_write(*t, extent)->cast<TestBlockPhysical>();
extent->set_contents('c');
csum2 = extent->checksum();
ASSERT_EQ(extent->get_paddr(), addr);
// test that concurrent read with fresh transaction sees old
// block
auto t2 = get_transaction();
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t2,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
ASSERT_TRUE(extent->is_clean());
ASSERT_FALSE(extent->is_pending());
ASSERT_EQ(addr, extent->get_paddr());
}
{
// test that read with same transaction sees new block
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
ASSERT_TRUE(extent->is_dirty());
ASSERT_TRUE(extent->is_pending());
ASSERT_EQ(addr, extent->get_paddr());
{
// test that fresh transaction now sees newly dirty block
auto t = get_transaction();
- auto extent = cache.get_extent<TestBlock>(
+ auto extent = cache.get_extent<TestBlockPhysical>(
*t,
addr,
- TestBlock::SIZE).unsafe_get0();
+ TestBlockPhysical::SIZE).unsafe_get0();
ASSERT_TRUE(extent->is_dirty());
ASSERT_EQ(addr, extent->get_paddr());
ASSERT_EQ(extent->get_version(), 1);