]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
compressor: add support for type=random for teuthology testing
authorCasey Bodley <cbodley@redhat.com>
Wed, 9 Nov 2016 19:02:38 +0000 (14:02 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 11 Nov 2016 19:06:47 +0000 (14:06 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/compressor/Compressor.cc

index 46fddd9670c1f77fd717226d6bd2fe36a53112c1..8da051cf6d4226637f9b62ac8435d9ec6c1232d5 100644 (file)
@@ -59,6 +59,24 @@ boost::optional<Compressor::CompressionMode> Compressor::get_comp_mode_type(cons
 
 CompressorRef Compressor::create(CephContext *cct, const std::string &type)
 {
+  // support "random" for teuthology testing
+  if (type == "random") {
+    static std::random_device seed;
+    static std::default_random_engine engine(seed());
+    static Spinlock mutex;
+
+    int alg = COMP_ALG_NONE;
+    std::uniform_int_distribution<> dist(0, COMP_ALG_LAST - 1);
+    {
+      std::lock_guard<Spinlock> lock(mutex);
+      alg = dist(engine);
+    }
+    if (alg == COMP_ALG_NONE) {
+      return nullptr;
+    }
+    return create(cct, alg);
+  }
+
   CompressorRef cs_impl = NULL;
   std::stringstream ss;
   PluginRegistry *reg = cct->get_plugin_registry();