]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: implement example create_ruleset
authorLoic Dachary <loic@dachary.org>
Wed, 29 Jan 2014 14:06:41 +0000 (15:06 +0100)
committerLoic Dachary <loic@dachary.org>
Tue, 4 Feb 2014 07:06:25 +0000 (08:06 +0100)
And the associated unit tests.

Reviewed-By: Christophe Courtaut <christophe.courtaut@gmail.com>
Signed-off-by: Loic Dachary <loic@dachary.org>
src/test/Makefile.am
src/test/osd/ErasureCodeExample.h
src/test/osd/TestErasureCodeExample.cc

index 83b83f4676ef1d30f47e7f51535a1a6b7213985c..84c9ef93874c7fa537333a83743e84ac8f4d3c66 100644 (file)
@@ -364,7 +364,7 @@ check_PROGRAMS += unittest_ceph_compatset
 libec_example_la_SOURCES = test/osd/ErasureCodePluginExample.cc
 libec_example_la_CFLAGS = ${AM_CFLAGS}
 libec_example_la_CXXFLAGS= ${AM_CXXFLAGS}
-libec_example_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS)
+libec_example_la_LIBADD = $(LIBCRUSH) $(PTHREAD_LIBS) $(EXTRALIBS)
 libec_example_la_LDFLAGS = ${AM_LDFLAGS} -export-symbols-regex '.*__erasure_code_.*'
 erasure_codelib_LTLIBRARIES += libec_example.la
 
index ab2bcf02909dff3ad11906df9308fb3793a05022..bd36b1d73c43a01a7c6101613dabb934051963d0 100644 (file)
@@ -21,6 +21,9 @@
 #include <errno.h>
 #include <algorithm>
 #include <sstream>
+
+#include "crush/CrushWrapper.h"
+#include "osd/osd_types.h"
 #include "osd/ErasureCodeInterface.h"
 
 #define FIRST_DATA_CHUNK 0
 class ErasureCodeExample : public ErasureCodeInterface {
 public:
   virtual ~ErasureCodeExample() {}
+
+  virtual int create_ruleset(const string &name,
+                            CrushWrapper &crush,
+                            ostream *ss) const {
+    return crush.add_simple_ruleset(name, "default", "host",
+                                   "indep", pg_pool_t::TYPE_ERASURE, ss);
+  }
   
   virtual int minimum_to_decode(const set<int> &want_to_read,
                                 const set<int> &available_chunks,
index faa863ec2acca00f221af22e4749a6489b163879..4df0762419b567c0a2552064cb4b0567ee929eb1 100644 (file)
@@ -14,6 +14,7 @@
  * 
  */
 
+#include "include/stringify.h"
 #include "global/global_init.h"
 #include "ErasureCodeExample.h"
 #include "common/ceph_argparse.h"
@@ -201,6 +202,37 @@ TEST(ErasureCodeExample, decode)
   EXPECT_EQ(-ERANGE, example.decode_concat(degraded, &out));
 }
 
+TEST(ErasureCodeExample, create_ruleset)
+{
+  CrushWrapper *c = new CrushWrapper;
+  c->create();
+  c->set_type_name(2, "root");
+  c->set_type_name(1, "host");
+  c->set_type_name(0, "osd");
+
+  int rootno;
+  c->add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_RJENKINS1,
+               5, 0, NULL, NULL, &rootno);
+  c->set_item_name(rootno, "default");
+
+  map<string,string> loc;
+  loc["root"] = "default";
+
+  int num_host = 2;
+  int num_osd = 5;
+  int osd = 0;
+  for (int h=0; h<num_host; ++h) {
+    loc["host"] = string("host-") + stringify(h);
+    for (int o=0; o<num_osd; ++o, ++osd) {
+      c->insert_item(g_ceph_context, osd, 1.0, string("osd.") + stringify(osd), loc);
+    }
+  }
+
+  stringstream ss;
+  ErasureCodeExample example;
+  EXPECT_EQ(0, example.create_ruleset("myrule", *c, &ss));
+}
+
 int main(int argc, char **argv) {
   vector<const char*> args;
   argv_to_vec(argc, (const char **)argv, args);