MCPcopy Create free account
hub / github.com/ceph/ceph / encode_decode

Method encode_decode

src/test/erasure-code/TestErasureCodeIsa.cc:50–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50void IsaErasureCodeTest::encode_decode(unsigned object_size)
51{
52 ErasureCodeIsaDefault Isa(tcache, "reed_sol_van");
53
54 ErasureCodeProfile profile;
55 profile["k"] = "2";
56 profile["m"] = "2";
57 Isa.init(profile, &cerr);
58
59 string payload(object_size, 'X');
60 bufferlist in;
61 // may be multiple bufferptr if object_size is larger than CEPH_PAGE_SIZE
62 in.append(payload.c_str(), payload.length());
63 int want_to_encode[] = {0, 1, 2, 3};
64 shard_id_map<bufferlist> encoded(Isa.get_chunk_count());
65 EXPECT_EQ(0, Isa.encode(shard_id_set(want_to_encode, want_to_encode + 4),
66 in,
67 &encoded));
68 EXPECT_EQ(4u, encoded.size());
69 unsigned chunk_size = encoded[shard_id_t(0)].length();
70 EXPECT_EQ(chunk_size, Isa.get_chunk_size(object_size));
71 compare_chunks(in, encoded);
72
73 // all chunks are available
74 {
75 int want_to_decode[] = {0, 1};
76 shard_id_map<bufferlist> decoded(Isa.get_chunk_count());
77 EXPECT_EQ(0, Isa._decode(shard_id_set(want_to_decode, want_to_decode + 2),
78 encoded,
79 &decoded));
80 EXPECT_EQ(2u, decoded.size());
81 EXPECT_EQ(chunk_size, decoded[shard_id_t(0)].length());
82 compare_chunks(in, decoded);
83 }
84
85 // one data chunk is missing
86 {
87 shard_id_map<bufferlist> degraded = encoded;
88
89 string enc1(encoded[shard_id_t(1)].c_str(), chunk_size);
90
91 degraded.erase(shard_id_t(1));
92 EXPECT_EQ(3u, degraded.size());
93 int want_to_decode[] = {1};
94 shard_id_map<bufferlist> decoded(Isa.get_chunk_count());
95 EXPECT_EQ(0, Isa._decode(shard_id_set(want_to_decode, want_to_decode + 1),
96 degraded,
97 &decoded));
98 // always decode all, regardless of want_to_decode
99 EXPECT_EQ(4u, decoded.size());
100 EXPECT_EQ(chunk_size, decoded[shard_id_t(1)].length());
101 EXPECT_EQ(0, memcmp(decoded[shard_id_t(1)].c_str(), enc1.c_str(), chunk_size));
102 }
103
104 // non-xor coding chunk is missing
105 {
106 shard_id_map<bufferlist> degraded = encoded;
107

Callers

nothing calls this directly

Calls 11

shard_id_tClass · 0.50
initMethod · 0.45
appendMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45
get_chunk_countMethod · 0.45
encodeMethod · 0.45
sizeMethod · 0.45
get_chunk_sizeMethod · 0.45
_decodeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected