]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: change algorithm of compression header from string to int 10137/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 6 Jul 2016 02:06:40 +0000 (10:06 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Fri, 8 Jul 2016 11:39:17 +0000 (19:39 +0800)
The literal description of compression algorithm can vary from
various compression types and thus increases the complexity of
en/decoding, which as a result can cause chaos. Also it can be
more efficient by translating it into a fixed-length type.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/os/bluestore/BlueStore.cc
src/os/bluestore/bluestore_types.cc
src/os/bluestore/bluestore_types.h

index 09a13f328d45fef0c6f54e44307e7339448593ba..2847e27329f0c5ad559947a5f536136ec95c5ec3 100644 (file)
@@ -3689,7 +3689,8 @@ int BlueStore::_decompress(bufferlist& source, bufferlist* result)
   bufferlist::iterator i = source.begin();
   bluestore_compression_header_t chdr;
   ::decode(chdr, i);
-  CompressorRef compressor = Compressor::create(cct, chdr.type);
+  string name = bluestore_blob_t::get_comp_alg_name(chdr.type);
+  CompressorRef compressor = Compressor::create(cct, name);
   if (!compressor.get()) {
     // if compressor isn't available - error, because cannot return
     // decompressed data?
@@ -5952,7 +5953,7 @@ int BlueStore::_do_alloc_write(
       assert(b_off == 0);
       assert(wi.blob_length == l->length());
       bluestore_compression_header_t chdr;
-      chdr.type = c->get_type();
+      chdr.type = bluestore_blob_t::get_comp_alg_type(c->get_type());
       // FIXME: memory alignment here is bad
       bufferlist t;
       c->compress(*l, t);
index 61f0d9e683a3c54b19ea5202acc50f06bc19995c..e50cabc8a2f5b834cef6d0fb1c58ac5e03f69902 100644 (file)
@@ -1054,7 +1054,7 @@ void bluestore_compression_header_t::decode(bufferlist::iterator& p)
 
 void bluestore_compression_header_t::dump(Formatter *f) const
 {
-  f->dump_string("type", type);
+  f->dump_unsigned("type", type);
   f->dump_unsigned("length", length);
 }
 
@@ -1062,6 +1062,6 @@ void bluestore_compression_header_t::generate_test_instances(
   list<bluestore_compression_header_t*>& o)
 {
   o.push_back(new bluestore_compression_header_t);
-  o.push_back(new bluestore_compression_header_t("some_header"));
+  o.push_back(new bluestore_compression_header_t(1));
   o.back()->length = 1234;
 }
index 44e0e8b5d27594e65ed6c6157d28db4c10db8db9..e95faea09efbb9ea7ee8e129f18119a45c50b581 100644 (file)
@@ -194,6 +194,33 @@ struct bluestore_blob_t {
     return -EINVAL;
   }
 
+  enum CompressionAlgorithm {
+    COMP_ALG_NONE = 0,
+    COMP_ALG_SNAPPY = 1,
+    COMP_ALG_ZLIB = 2,
+  };
+
+  static const char * get_comp_alg_name(int a) {
+    switch (a) {
+    case COMP_ALG_NONE: return "none";
+    case COMP_ALG_SNAPPY: return "snappy";
+    case COMP_ALG_ZLIB: return "zlib";
+    default: return "???";
+    }
+  }
+
+  static int get_comp_alg_type(const std::string &s) {
+    if (s == "none")
+      return COMP_ALG_NONE;
+    if (s == "snappy")
+      return COMP_ALG_SNAPPY;
+    if (s == "zlib")
+      return COMP_ALG_ZLIB;
+
+    assert(0 == "invalid compression algorithm");
+    return COMP_ALG_NONE;
+  }
+
   vector<bluestore_pextent_t> extents;///< raw data position on device
   uint32_t compressed_length = 0;     ///< compressed length if any
   uint32_t flags = 0;                 ///< FLAG_*
@@ -621,11 +648,11 @@ struct bluestore_wal_transaction_t {
 WRITE_CLASS_ENCODER(bluestore_wal_transaction_t)
 
 struct bluestore_compression_header_t {
-  std::string type;
+  uint8_t type = bluestore_blob_t::COMP_ALG_NONE;
   uint32_t length = 0;
 
   bluestore_compression_header_t() {}
-  bluestore_compression_header_t(const std::string& _type)
+  bluestore_compression_header_t(uint8_t _type)
     : type(_type) {}
 
   void encode(bufferlist& bl) const;