Merge pull request #10137 from xiexingguo/xxg-wip-bluestore-2016-07-05-02

os/bluestore: change algorithm of compression header from string to int

Reviewed-by: Igor Fedotov <ifedotov@mirantis.com>
This commit is contained in:
Igor Fedotov 2016-07-08 13:43:33 +02:00 committed by GitHub
commit 5c2a1bbb1f
3 changed files with 34 additions and 6 deletions

View File

@ -3707,7 +3707,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?
@ -5971,7 +5972,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);

View 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;
}

View 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;