Skip to content

Commit c437014

Browse files
committed
osd: Add extent_to_shard_extent interface to PGBackend.
This allows a backend to expose how an object offset/length translates to an offset/length on a particular shard. For Replica, this is trivial. For EC, this means looking up the start and end offsets, then translating this to shard address space. Signed-off-by: Alex Ainscow <[email protected]>
1 parent 332b547 commit c437014

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/osd/ECBackend.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,30 @@ int ECBackend::objects_read_sync(
10101010
return -EOPNOTSUPP;
10111011
}
10121012

1013+
std::pair<uint64_t, uint64_t> ECBackend::extent_to_shard_extent(uint64_t off, uint64_t len) {
1014+
// sync reads are supported for sub-chunk reads where no reconstruct is
1015+
// required.
1016+
uint64_t chunk_size = sinfo.get_chunk_size();
1017+
uint64_t start_chunk = off / chunk_size;
1018+
// This calculation is wrong for length = 0, but it doesn't matter if these reads get sent to the primary
1019+
uint64_t end_chunk = (off + len - 1) / chunk_size;
1020+
uint64_t shard_offset, shard_len;
1021+
shard_id_t shard = get_parent()->whoami_shard().shard;
1022+
raw_shard_id_t raw_shard = sinfo.get_raw_shard(shard);
1023+
1024+
if (end_chunk == start_chunk) {
1025+
shard_offset = sinfo.ro_offset_to_shard_offset(off, raw_shard);
1026+
shard_len = len;
1027+
} else {
1028+
ECUtil::shard_extent_set_t full_read(sinfo.get_k_plus_m());
1029+
sinfo.ro_range_to_shard_extent_set(off, len, full_read);
1030+
shard_offset = full_read[shard].range_start();
1031+
shard_len = full_read[shard].range_end() - shard_offset;
1032+
}
1033+
1034+
return std::pair(shard_offset, shard_len);
1035+
}
1036+
10131037
void ECBackend::objects_read_async(
10141038
const hobject_t &hoid,
10151039
uint64_t object_size,

src/osd/ECBackend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class ECBackend : public ECCommon {
138138
ceph::buffer::list *bl
139139
);
140140

141+
std::pair<uint64_t, uint64_t> extent_to_shard_extent(uint64_t off, uint64_t len);
142+
141143
/**
142144
* Async read mechanism
143145
*

src/osd/ECSwitch.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ class ECSwitch : public PGBackend
267267
return legacy.objects_read_sync(hoid, off, len, op_flags, bl);
268268
}
269269

270+
std::pair<uint64_t, uint64_t> extent_to_shard_extent(
271+
uint64_t off, uint64_t len) override {
272+
if (is_optimized()) {
273+
return optimized.extent_to_shard_extent(off, len);
274+
}
275+
ceph_abort_msg("Extent conversion not supported in legacy EC");
276+
}
277+
270278
void objects_read_async(
271279
const hobject_t &hoid,
272280
uint64_t object_size,

src/osd/PGBackend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ typedef std::shared_ptr<const OSDMap> OSDMapRef;
610610
return -EOPNOTSUPP;
611611
}
612612

613+
virtual std::pair<uint64_t, uint64_t> extent_to_shard_extent(
614+
uint64_t off, uint64_t len) {
615+
return std::pair(off, len);
616+
}
617+
613618
virtual void objects_read_async(
614619
const hobject_t &hoid,
615620
uint64_t object_size,

0 commit comments

Comments
 (0)