]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: refactor the example to use chunk size helpers
authorLoic Dachary <loic@dachary.org>
Wed, 18 Dec 2013 09:00:30 +0000 (10:00 +0100)
committerLoic Dachary <loic@dachary.org>
Fri, 10 Jan 2014 18:24:55 +0000 (19:24 +0100)
The get_chunk_size and get_chunk_count methods are implemented using the
code found in the encode() method. The encode method is modified to use
the chunk size helpers.

The unit tests are modified to use the helpers.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/test/osd/ErasureCodeExample.h
src/test/osd/TestErasureCodeExample.cc

index 0710189cba4eeb7295b5a2a9f436c9447e2e44ee..ab2bcf02909dff3ad11906df9308fb3793a05022 100644 (file)
@@ -81,6 +81,18 @@ public:
     return minimum_to_decode(want_to_read, available_chunks, minimum);
   }
 
+  virtual unsigned int get_chunk_count() const {
+    return DATA_CHUNKS + CODING_CHUNKS;
+  }
+
+  virtual unsigned int get_data_chunk_count() const {
+    return DATA_CHUNKS;
+  }
+
+  virtual unsigned int get_chunk_size(unsigned int object_size) const {
+    return ( object_size / DATA_CHUNKS ) + 1;
+  }
+
   virtual int encode(const set<int> &want_to_encode,
                      const bufferlist &in,
                      map<int, bufferlist> *encoded) {
@@ -88,11 +100,11 @@ public:
     // make sure all data chunks have the same length, allocating
     // padding if necessary.
     //
-    unsigned chunk_length = ( in.length() / DATA_CHUNKS ) + 1;
-    unsigned length = chunk_length * ( DATA_CHUNKS + CODING_CHUNKS );
+    unsigned int chunk_length = get_chunk_size(in.length());
     bufferlist out(in);
-    bufferptr pad(length - in.length());
-    pad.zero(0, DATA_CHUNKS);
+    unsigned int width = get_chunk_count() * get_chunk_size(in.length());
+    bufferptr pad(width - in.length());
+    pad.zero(0, get_data_chunk_count());
     out.push_back(pad);
     //
     // compute the coding chunk with first chunk ^ second chunk
index f12e80c8cd043a132f58f912333d52f0e291729a..17e77a0bdaac63a92f0fc628b82342e07b3a9e92 100644 (file)
 #include "global/global_context.h"
 #include "gtest/gtest.h"
 
+TEST(ErasureCodeExample, chunk_size)
+{
+  ErasureCodeExample example;
+  EXPECT_EQ(3u, example.get_chunk_count());
+  EXPECT_EQ(11u, example.get_chunk_size(20));
+}
+
 TEST(ErasureCodeExample, minimum_to_decode)
 {
   ErasureCodeExample example;
@@ -105,13 +112,13 @@ TEST(ErasureCodeExample, encode_decode)
 
   bufferlist in;
   in.append("ABCDE");
-  int want_to_encode[] = { 0, 1, 2 };
+  set<int> want_to_encode;
+  for(unsigned int i = 0; i < example.get_chunk_count(); i++)
+    want_to_encode.insert(i);
   map<int, bufferlist> encoded;
-  EXPECT_EQ(0, example.encode(set<int>(want_to_encode, want_to_encode+3),
-                              in,
-                              &encoded));
-  EXPECT_EQ(3u, encoded.size());
-  EXPECT_EQ(3u, encoded[0].length());
+  EXPECT_EQ(0, example.encode(want_to_encode, in, &encoded));
+  EXPECT_EQ(example.get_chunk_count(), encoded.size());
+  EXPECT_EQ(example.get_chunk_size(in.length()), encoded[0].length());
   EXPECT_EQ('A', encoded[0][0]);
   EXPECT_EQ('B', encoded[0][1]);
   EXPECT_EQ('C', encoded[0][2]);