Skip to content

Commit

Permalink
Expose compression algorithms via MOSDBoot. Implements 22420.
Browse files Browse the repository at this point in the history
Modifies Compressor to expose a set of strings (already hardcoded)
that are accessible elsewhere.

Adds metadata to MOSDBoost containing a list of compression algorithms
made available via the plugin interface.

Fixes: http://tracker.ceph.com/issues/22420

Signed-off-by: Jesse Williamson <jwilliamson@suse.de>
  • Loading branch information
Jesse Williamson committed Feb 24, 2018
1 parent 15e537e commit 6fa22e5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
41 changes: 11 additions & 30 deletions src/compressor/Compressor.cc
Expand Up @@ -23,40 +23,21 @@
#include "common/dout.h"

const char * Compressor::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";
case COMP_ALG_ZSTD: return "zstd";
#ifdef HAVE_LZ4
case COMP_ALG_LZ4: return "lz4";
#endif
#ifdef HAVE_BROTLI
case COMP_ALG_BROTLI: return "brotli";
#endif
default: return "???";
}

if(a < 0 || a >= COMP_ALG_LAST)
return "???"; // It would be nice to revise this...

return compression_algorithm_names[a];
}

boost::optional<Compressor::CompressionAlgorithm> Compressor::get_comp_alg_type(const std::string &s) {
if (s == "snappy")
return COMP_ALG_SNAPPY;
if (s == "zlib")
return COMP_ALG_ZLIB;
if (s == "zstd")
return COMP_ALG_ZSTD;
#ifdef HAVE_LZ4
if (s == "lz4")
return COMP_ALG_LZ4;
#endif
#ifdef HAVE_BROTLI
if (s == "brotli")
return COMP_ALG_BROTLI;
#endif
if (s == "" || s == "none")
return COMP_ALG_NONE;

return boost::optional<CompressionAlgorithm>();
for (int pos = 0; pos != sizeof(compression_algorithm_names); ++pos) {
if(compression_algorithm_names[pos] == s)
return { static_cast<CompressionAlgorithm>(pos) };
}

return {};
}

const char *Compressor::get_comp_mode_name(int m) {
Expand Down
11 changes: 11 additions & 0 deletions src/compressor/Compressor.h
Expand Up @@ -42,6 +42,17 @@ class Compressor {
#endif
COMP_ALG_LAST //the last value for range checks
};

// The names in this array must match the above values:
constexpr static char const* const compression_algorithm_names[] = {
"none",
"snappy",
"zlib",
"zstd",
"lz4",
"brotli",
};

// compression options
enum CompressionMode {
COMP_NONE, ///< compress never
Expand Down
40 changes: 36 additions & 4 deletions src/osd/OSD.cc
Expand Up @@ -12,14 +12,19 @@
* Foundation. See file COPYING.
*
*/

#include "acconfig.h"
#include <unistd.h>

#include <cerrno>
#include <cctype>
#include <fstream>
#include <iostream>
#include <errno.h>
#include <algorithm>

#include <unistd.h>

#include <sys/stat.h>
#include <signal.h>
#include <ctype.h>
#include <boost/scoped_ptr.hpp>

#ifdef HAVE_SYS_PARAM_H
Expand Down Expand Up @@ -47,6 +52,7 @@
#include "common/io_priority.h"
#include "common/pick_address.h"
#include "common/SubProcess.h"
#include "common/PluginRegistry.h"

#include "os/ObjectStore.h"
#ifdef HAVE_LIBFUSE
Expand All @@ -55,7 +61,6 @@

#include "PrimaryLogPG.h"


#include "msg/Messenger.h"
#include "msg/Message.h"

Expand Down Expand Up @@ -5536,6 +5541,28 @@ void OSD::_send_boot()
set_state(STATE_BOOTING);
}

std::string OSD::_collect_compression_algorithms()
{
const auto& compression_algorithm_names = Compressor::compression_algorithm_names;
const auto& plugin_registry = cct->get_plugin_registry()->plugins;

if(0 == plugin_registry.size())
return std::string();

ostringstream os;
for_each(begin(compression_algorithm_names), end(compression_algorithm_names),
[&os, &plugin_registry](const auto& algorithm_name) {
if (plugin_registry.end() != plugin_registry.find(algorithm_name))
os << algorithm_name << ',';
});

string s(os.str());

s.erase(s.find_last_of(','));

return s;
}

void OSD::_collect_metadata(map<string,string> *pm)
{
// config info
Expand All @@ -5544,6 +5571,7 @@ void OSD::_collect_metadata(map<string,string> *pm)
// not applicable for bluestore
(*pm)["osd_journal"] = journal_path;
}

(*pm)["front_addr"] = stringify(client_messenger->get_myaddr());
(*pm)["back_addr"] = stringify(cluster_messenger->get_myaddr());
(*pm)["hb_front_addr"] = stringify(hb_front_server_messenger->get_myaddr());
Expand All @@ -5566,6 +5594,10 @@ void OSD::_collect_metadata(map<string,string> *pm)
set<string> devnames;
store->get_devices(&devnames);
(*pm)["devices"] = stringify(devnames);

// Other information:
(*pm)["supported_compression_algorithms"] = _collect_compression_algorithms();

dout(10) << __func__ << " " << *pm << dendl;
}

Expand Down
1 change: 1 addition & 0 deletions src/osd/OSD.h
Expand Up @@ -1927,6 +1927,7 @@ class OSD : public Dispatcher,
void _preboot(epoch_t oldest, epoch_t newest);
void _send_boot();
void _collect_metadata(map<string,string> *pmeta);
void _collect_compression_algorithms(map<string,string>& pmeta);

void start_waiting_for_healthy();
bool _is_healthy();
Expand Down

0 comments on commit 6fa22e5

Please sign in to comment.