]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/immutable_object_cache/ObjectCacheStore.h
import ceph 16.2.7
[ceph.git] / ceph / src / tools / immutable_object_cache / ObjectCacheStore.h
CommitLineData
9f95a23c
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_CACHE_OBJECT_CACHE_STORE_H
5#define CEPH_CACHE_OBJECT_CACHE_STORE_H
6
7#include "common/ceph_context.h"
8#include "common/ceph_mutex.h"
a4b75251 9#include "common/Timer.h"
f67539c2
TL
10#include "common/Throttle.h"
11#include "common/Cond.h"
9f95a23c
TL
12#include "include/rados/librados.hpp"
13
14#include "SimplePolicy.h"
15
16
17using librados::Rados;
18using librados::IoCtx;
19class Context;
20
21namespace ceph {
22namespace immutable_obj_cache {
23
24typedef shared_ptr<librados::Rados> RadosRef;
25typedef shared_ptr<librados::IoCtx> IoCtxRef;
26
27class ObjectCacheStore {
28 public:
29 ObjectCacheStore(CephContext *cct);
30 ~ObjectCacheStore();
31 int init(bool reset);
32 int shutdown();
33 int init_cache();
34 int lookup_object(std::string pool_nspace,
35 uint64_t pool_id, uint64_t snap_id,
f67539c2 36 uint64_t object_size,
9f95a23c 37 std::string object_name,
f91f0fd5 38 bool return_dne_path,
9f95a23c 39 std::string& target_cache_file_path);
9f95a23c 40 private:
f67539c2
TL
41 enum ThrottleTypeCode {
42 THROTTLE_CODE_BYTE,
43 THROTTLE_CODE_OBJECT
44 };
45
9f95a23c
TL
46 std::string get_cache_file_name(std::string pool_nspace, uint64_t pool_id,
47 uint64_t snap_id, std::string oid);
48 std::string get_cache_file_path(std::string cache_file_name,
49 bool mkdir = false);
50 int evict_objects();
51 int do_promote(std::string pool_nspace, uint64_t pool_id,
52 uint64_t snap_id, std::string object_name);
53 int promote_object(librados::IoCtx*, std::string object_name,
54 librados::bufferlist* read_buf,
55 Context* on_finish);
56 int handle_promote_callback(int, bufferlist*, std::string);
57 int do_evict(std::string cache_file);
58
f67539c2
TL
59 bool take_token_from_throttle(uint64_t object_size, uint64_t object_num);
60 void handle_throttle_ready(uint64_t tokens, uint64_t type);
61 void apply_qos_tick_and_limit(const uint64_t flag,
62 std::chrono::milliseconds min_tick,
63 uint64_t limit, uint64_t burst,
64 std::chrono::seconds burst_seconds);
65
9f95a23c
TL
66 CephContext *m_cct;
67 RadosRef m_rados;
68 std::map<uint64_t, librados::IoCtx> m_ioctx_map;
69 ceph::mutex m_ioctx_map_lock =
70 ceph::make_mutex("ceph::cache::ObjectCacheStore::m_ioctx_map_lock");
71 Policy* m_policy;
72 std::string m_cache_root_dir;
f67539c2
TL
73 // throttle mechanism
74 uint64_t m_qos_enabled_flag{0};
75 std::map<uint64_t, TokenBucketThrottle*> m_throttles;
76 bool m_io_throttled{false};
77 ceph::mutex m_throttle_lock =
78 ceph::make_mutex("ceph::cache::ObjectCacheStore::m_throttle_lock");;
79 uint64_t m_iops_tokens{0};
80 uint64_t m_bps_tokens{0};
9f95a23c
TL
81};
82
83} // namespace immutable_obj_cache
84} // ceph
85#endif // CEPH_CACHE_OBJECT_CACHE_STORE_H