From: Casey Bodley Date: Wed, 9 Nov 2016 19:02:38 +0000 (-0500) Subject: compressor: add support for type=random for teuthology testing X-Git-Tag: v11.1.0~220^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e1de56791ece78fb88d3e2d8b76b67f36ec25253;p=ceph.git compressor: add support for type=random for teuthology testing Signed-off-by: Casey Bodley --- diff --git a/src/compressor/Compressor.cc b/src/compressor/Compressor.cc index 46fddd9670c..8da051cf6d4 100644 --- a/src/compressor/Compressor.cc +++ b/src/compressor/Compressor.cc @@ -59,6 +59,24 @@ boost::optional 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 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();