Skip to content

Commit 13b64bd

Browse files
committed
erasure-code/consistency: Allow consistency checker to be able to deal with non-4k aligned buffers
A parity returned to the client will be the size of shard 0, which may not be 4k aligned in optimised erasure coding. A parity returned through the encode function will always be 4k aligned. This change makes it so we truncate the encoded data down to the size of the client write before comparing them together in the consistency check so we know we are comparing them like-for-like Signed-off-by: Jon Bailey <[email protected]>
1 parent 30670d3 commit 13b64bd

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

src/erasure-code/consistency/ConsistencyChecker.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ECReader.h"
66
#include "ECEncoder.h"
77
#include "ECEncoderSwitch.h"
8+
#include "osd/ECUtil.h"
89

910
using ConsistencyChecker = ceph::consistency::ConsistencyChecker;
1011

@@ -115,6 +116,30 @@ bool ConsistencyChecker::check_object_consistency(const std::string& oid,
115116
return false;
116117
}
117118

119+
// Encode always returns 4k aligned data
120+
// A client read will always return parity with the same size as shard 0
121+
// We confirm the encoded data is the same or larger than the client read
122+
ceph_assert(outbl->length() >= data_and_parity.second.length());
123+
// We check the difference is not larger than the page size multipled by the
124+
// number of parities
125+
ceph_assert(outbl->length() - data_and_parity.second.length()
126+
<= (encoder.get_m() * encoder.get_chunk_size()) - encoder.get_m());
127+
// We truncate the encoded parity to the size of the client read for comparison
128+
if (outbl->length() != data_and_parity.second.length())
129+
{
130+
const int aligned_shard_length = outbl->length() / encoder.get_m();
131+
const int shard_data_length = data_and_parity.second.length()
132+
/ encoder.get_m();
133+
ceph::bufferlist newdata;
134+
for (int i = 0; i < encoder.get_m(); i++)
135+
{
136+
ceph::bufferlist bl;
137+
bl.substr_of(*outbl, i * aligned_shard_length, shard_data_length);
138+
newdata.append(bl);
139+
}
140+
outbl = std::move(newdata);
141+
}
142+
118143
return buffers_match(outbl.value(), data_and_parity.second);
119144
}
120145

src/erasure-code/consistency/ECEncoder.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ int ECEncoder<SInfo>::get_m()
198198
{
199199
return stripe_info->get_m();
200200
}
201+
202+
/**
203+
* Return chunksize for the stripe
204+
*
205+
* @returns int Chunksize for the stripe
206+
*/
207+
template <typename SInfo>
208+
int ECEncoder<SInfo>::get_chunk_size()
209+
{
210+
return stripe_info->get_chunk_size();
211+
}
201212
}
202213
}
203214

src/erasure-code/consistency/ECEncoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ECEncoder {
2929
std::optional<ceph::bufferlist> do_encode(ceph::bufferlist inbl);
3030
int get_k(void);
3131
int get_m(void);
32+
int get_chunk_size(void);
3233
};
3334
}
3435
}

src/erasure-code/consistency/ECEncoderSwitch.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ int ECEncoderSwitch::get_m()
5757
return encoder_legacy.get_m();
5858
}
5959
}
60+
61+
/**
62+
* Return chunksize for the stripe from the correct version of the encoder
63+
*
64+
* @returns int Chunksize for stripe
65+
*/
66+
int ECEncoderSwitch::get_chunk_size()
67+
{
68+
if (optimizations_enabled) {
69+
return encoder_optimized.get_chunk_size();
70+
} else {
71+
return encoder_legacy.get_chunk_size();
72+
}
73+
}

src/erasure-code/consistency/ECEncoderSwitch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ECEncoderSwitch {
2626
std::optional<ceph::bufferlist> do_encode(ceph::bufferlist inbl);
2727
int get_k(void);
2828
int get_m(void);
29+
int get_chunk_size(void);
2930
};
3031
}
3132
}

0 commit comments

Comments
 (0)