]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: add store/pool compression option selector.
authorIgor Fedotov <ifedotov@mirantis.com>
Sat, 10 Sep 2016 10:34:47 +0000 (13:34 +0300)
committerIgor Fedotov <ifedotov@mirantis.com>
Wed, 19 Oct 2016 14:33:29 +0000 (14:33 +0000)
Signed-off-by: Igor Fedotov <ifedotov@mirantis.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 439163effc81b2f4f30dc64ae1e1c046e2ac4714..40e1e50c35c596e0e8126fafe9a3a98d6041faf5 100644 (file)
@@ -7570,6 +7570,7 @@ void BlueStore::_do_write_big(
 
 int BlueStore::_do_alloc_write(
   TransContext *txc,
+  CollectionRef coll,
   WriteContext *wctx)
 {
   dout(20) << __func__ << " txc " << txc
@@ -7588,7 +7589,24 @@ int BlueStore::_do_alloc_write(
   }
 
   uint64_t hint = 0;
-  CompressorRef c = compressor;
+  CompressorRef c;
+  if (wctx->compress) {
+    c = select_option(
+    "compression_algorithm",
+    compressor,
+    [&]() {
+      string val;
+      if (coll->pool_opts.get(pool_opts_t::COMPRESSION_ALGORITHM, &val)) {
+        CompressorRef cp = compressor;
+        if (!cp || cp->get_type_name() != val) {
+          cp = Compressor::create(cct, val);
+        }
+        return boost::optional<CompressorRef>(cp);
+      }
+      return boost::optional<CompressorRef>();
+    });
+  }
+
   for (auto& wi : wctx->writes) {
     BlobRef b = wi.b;
     bluestore_blob_t& dblob = b->dirty_blob();
@@ -7599,7 +7617,7 @@ int BlueStore::_do_alloc_write(
     unsigned csum_order = block_size_order;
     bufferlist compressed_bl;
     bool compressed = false;
-    if (c && wctx->compress && wi.blob_length > min_alloc_size) {
+    if(c && wi.blob_length > min_alloc_size) {
 
       utime_t start = ceph_clock_now(g_ceph_context);
 
@@ -7619,8 +7637,19 @@ int BlueStore::_do_alloc_write(
       compressed_bl.claim_append(t);
       uint64_t rawlen = compressed_bl.length();
       uint64_t newlen = P2ROUNDUP(rawlen, min_alloc_size);
-      uint64_t want_len_raw = final_length *
-        g_conf->bluestore_compression_required_ratio;
+
+      auto crr = select_option(
+       "compression_required_ratio",
+       g_conf->bluestore_compression_required_ratio,
+       [&]() {
+         double val;
+         if(coll->pool_opts.get(pool_opts_t::COMPRESSION_REQUIRED_RATIO, &val)) {
+           return boost::optional<double>(val);
+         }
+         return boost::optional<double>();
+       }
+      );
+      uint64_t want_len_raw = final_length * crr;
       uint64_t want_len = P2ROUNDUP(want_len_raw, min_alloc_size);
       if (newlen <= want_len && newlen < final_length) {
         // Cool. We compressed at least as much as we were hoping to.
@@ -7685,13 +7714,26 @@ int BlueStore::_do_alloc_write(
       dblob.extents.push_back(e);
     }
 
+    // checksum
+    int csum = csum_type.load();
+    csum = select_option(
+      "csum_type",
+      csum, 
+      [&]() {
+        int val;
+        if(coll->pool_opts.get(pool_opts_t::CSUM_TYPE, &val)) {
+         return  boost::optional<int>(val);
+        }
+        return boost::optional<int>();
+      }
+    );
+
     dout(20) << __func__ << " blob " << *b
+            << " csum_type " << Checksummer::get_csum_type_string(csum)
             << " csum_order " << csum_order
             << " csum_length 0x" << std::hex << csum_length << std::dec
             << dendl;
 
-    // checksum
-    int csum = csum_type.load();
     if (csum) {
       dblob.init_csum(csum, csum_order, csum_length);
       dblob.calc_csum(b_off, *l);
@@ -7874,12 +7916,22 @@ int BlueStore::_do_write(
 
   // compression parameters
   unsigned alloc_hints = o->onode.alloc_hint_flags;
-  int comp = comp_mode.load();
+  auto cm = select_option(
+    "compression_mode",
+    comp_mode.load(), 
+    [&]() {
+      string val;
+      if(c->pool_opts.get(pool_opts_t::COMPRESSION_MODE, &val)) {
+       return  boost::optional<Compressor::CompressionMode>(Compressor::get_comp_mode_type(val));
+      }
+      return boost::optional<Compressor::CompressionMode>();
+    }
+  );
   wctx.compress =
-    (comp == Compressor::COMP_FORCE) ||
-    (comp == Compressor::COMP_AGGRESSIVE &&
+    (cm == Compressor::COMP_FORCE) ||
+    (cm == Compressor::COMP_AGGRESSIVE &&
      (alloc_hints & CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE) == 0) ||
-    (comp == Compressor::COMP_PASSIVE &&
+    (cm == Compressor::COMP_PASSIVE &&
      (alloc_hints & CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE));
 
   if ((alloc_hints & CEPH_OSD_ALLOC_HINT_FLAG_SEQUENTIAL_READ) &&
@@ -7890,11 +7942,31 @@ int BlueStore::_do_write(
     dout(20) << __func__ << " will prefer large blob and csum sizes" << dendl;
     wctx.csum_order = min_alloc_size_order;
     if (wctx.compress) {
-      wctx.target_blob_size = comp_max_blob_size.load();
+      wctx.target_blob_size = select_option(
+        "compression_max_blob_size",
+        comp_max_blob_size.load(), 
+        [&]() {
+          uint64_t val;
+          if(c->pool_opts.get(pool_opts_t::COMPRESSION_MAX_BLOB_SIZE, &val)) {
+           return boost::optional<uint64_t>(val);
+          }
+          return boost::optional<uint64_t>();
+        }
+      );
     }
   } else {
     if (wctx.compress) {
-      wctx.target_blob_size = comp_min_blob_size.load();
+      wctx.target_blob_size = select_option(
+        "compression_min_blob_size",
+        comp_min_blob_size.load(), 
+        [&]() {
+          uint64_t val;
+          if(c->pool_opts.get(pool_opts_t::COMPRESSION_MIN_BLOB_SIZE, &val)) {
+           return boost::optional<uint64_t>(val);
+          }
+          return boost::optional<uint64_t>();
+        }
+      );
     }
   }
   if (wctx.target_blob_size == 0 ||
@@ -7959,7 +8031,7 @@ int BlueStore::_do_write(
   o->extent_map.fault_range(db, offset, length);
   _do_write_data(txc, c, o, offset, length, bl, &wctx);
 
-  r = _do_alloc_write(txc, &wctx);
+  r = _do_alloc_write(txc, c, &wctx);
   if (r < 0) {
     derr << __func__ << " _do_alloc_write failed with " << cpp_strerror(r)
         << dendl;
index 5d780fb4ba1a2b590e832f1759a1de53d6fc2832..25f502a665336262f66c658a20e7bf7997cf5de0 100644 (file)
@@ -1582,7 +1582,15 @@ private:
   int _collection_list(Collection *c, ghobject_t start, ghobject_t end,
     bool sort_bitwise, int max, vector<ghobject_t> *ls, ghobject_t *next);
 
-
+  template <typename T, typename F>
+  T select_option(const std::string& opt_name, T val1, F f) {
+    //NB: opt_name reserved for future use
+    boost::optional<T> val2 = f();
+    if (val2) {
+      return *val2;
+    }
+    return val1;
+  }
 public:
   BlueStore(CephContext *cct, const string& path);
   ~BlueStore();
@@ -1876,6 +1884,7 @@ private:
     WriteContext *wctx);
   int _do_alloc_write(
     TransContext *txc,
+    CollectionRef c,
     WriteContext *wctx);
   void _wctx_finish(
     TransContext *txc,