From 25e6cd1332341a57fa7d2ba948f18c7f01e71f84 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 2 Nov 2018 18:08:40 -0700 Subject: [PATCH] ircd::db: Add compression string option to column descriptor. --- include/ircd/db/descriptor.h | 5 +++++ ircd/db.cc | 26 ++++++++++++++++++++++++-- ircd/db.h | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/ircd/db/descriptor.h b/include/ircd/db/descriptor.h index e6b301b0e..b54f2ea9d 100644 --- a/include/ircd/db/descriptor.h +++ b/include/ircd/db/descriptor.h @@ -75,6 +75,11 @@ struct ircd::db::descriptor /// the cache. size_t meta_block_size { 512 }; + /// Compression algorithm for this column. Empty string is equal to + /// kNoCompression. List is semicolon separated to allow fallbacks in + /// case the first algorithms are not supported. + std::string compression {"kSnappyCompression;kLZ4Compression"}; + /// User given compaction callback surface. db::compactor compactor {}; }; diff --git a/ircd/db.cc b/ircd/db.cc index 2ce85de03..5dd7860c9 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -1627,8 +1627,7 @@ ircd::db::database::column::column(database &d, this->options.optimize_filters_for_hits = this->descriptor->expect_queries_hit; // Compression - //TODO: descriptor / conf / detect etc... - this->options.compression = rocksdb::kSnappyCompression; + this->options.compression = find_supported_compression(this->descriptor->compression); //this->options.compression = rocksdb::kNoCompression; //TODO: descriptor / conf @@ -9603,6 +9602,29 @@ const // Misc // +rocksdb::CompressionType +ircd::db::find_supported_compression(const std::string &list) +{ + rocksdb::CompressionType ret + { + rocksdb::kNoCompression + }; + + tokens(list, ';', [&ret] + (const string_view &name) + { + for(size_t i(0); i < db::compressions.size(); ++i) + if(!db::compressions.at(i).empty()) + if(name == db::compressions.at(i)) + { + ret = rocksdb::CompressionType(i); + break; + } + }); + + return ret; +} + rocksdb::DBOptions ircd::db::make_dbopts(std::string optstr, std::string *const &out, diff --git a/ircd/db.h b/ircd/db.h index 8108cdacd..b7e645fe7 100644 --- a/ircd/db.h +++ b/ircd/db.h @@ -76,6 +76,7 @@ namespace ircd::db // Database options creator bool optstr_find_and_remove(std::string &optstr, const std::string &what); rocksdb::DBOptions make_dbopts(std::string optstr, std::string *const &out = nullptr, bool *read_only = nullptr, bool *fsck = nullptr); + rocksdb::CompressionType find_supported_compression(const std::string &); // Validation functors bool valid(const rocksdb::Iterator &);