summaryrefslogtreecommitdiffstats
path: root/src/msg/compressor_registry.h
blob: d6b3f6867d8e01ee81c100cb656240595bb9e4d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <map>
#include <vector>

#include "compressor/Compressor.h"
#include "common/ceph_mutex.h"
#include "common/ceph_context.h"
#include "common/config_cacher.h"

class CompressorRegistry : public md_config_obs_t {
public:
  CompressorRegistry(CephContext *cct);
  ~CompressorRegistry();

  void refresh_config() {
    std::scoped_lock l(lock);
    _refresh_config();
  }

  const char** get_tracked_conf_keys() const override;
  void handle_conf_change(const ConfigProxy& conf,
                          const std::set<std::string>& changed) override;

  TOPNSPC::Compressor::CompressionAlgorithm pick_method(uint32_t peer_type,
					       const std::vector<uint32_t>& preferred_methods);

  TOPNSPC::Compressor::CompressionMode get_mode(uint32_t peer_type, bool is_secure);

  const std::vector<uint32_t> get_methods(uint32_t peer_type) { 
    std::scoped_lock l(lock);
    switch (peer_type) {
      case CEPH_ENTITY_TYPE_OSD:
        return ms_osd_compression_methods;
      default:
        return {};
    }
   }

  uint64_t get_min_compression_size(uint32_t peer_type) const {
    std::scoped_lock l(lock);
    switch (peer_type) {
      case CEPH_ENTITY_TYPE_OSD:
        return ms_osd_compress_min_size;
      default:
        return 0;
    }
  }

  bool get_is_compress_secure() const { 
    std::scoped_lock l(lock);
    return ms_compress_secure; 
  }

private:
  CephContext *cct;
  mutable ceph::mutex lock = ceph::make_mutex("CompressorRegistry::lock");

  uint32_t ms_osd_compress_mode;
  bool ms_compress_secure;
  std::uint64_t ms_osd_compress_min_size;
  std::vector<uint32_t> ms_osd_compression_methods;

  void _refresh_config();
  std::vector<uint32_t> _parse_method_list(const std::string& s);
};