summaryrefslogtreecommitdiffstats
path: root/src/tools/immutable_object_cache/SimplePolicy.h
blob: a75bf3ca3d74d422c3b5afcd65fc68f84b4b2b31 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_CACHE_SIMPLE_POLICY_H
#define CEPH_CACHE_SIMPLE_POLICY_H

#include "common/ceph_context.h"
#include "common/RWLock.h"
#include "common/Mutex.h"
#include "common/debug.h"
#include "include/lru.h"
#include "Policy.h"

#include <vector>
#include <unordered_map>
#include <string>

namespace ceph {
namespace immutable_obj_cache {

class SimplePolicy : public Policy {
public:
  SimplePolicy(CephContext *cct, uint64_t block_num, float watermark);
  ~SimplePolicy() ;

  cache_status_t lookup_object(std::string file_name);
  cache_status_t get_status(std::string file_name);

  void update_status(std::string file_name, cache_status_t new_status);

  int evict_entry(std::string file_name);

  void get_evict_list(std::list<std::string>* obj_list);

  uint64_t get_free_entry_num();
  uint64_t get_promoting_entry_num();
  uint64_t get_promoted_entry_num();
  std::string get_evict_entry();

private:
  cache_status_t alloc_entry(std::string file_name);

  class Entry : public LRUObject {
    public:
      cache_status_t status;
      Entry() : status(OBJ_CACHE_NONE){}
      std::string file_name;
  };

  CephContext* cct;
  float m_watermark;
  uint64_t m_entry_count;
  uint64_t m_max_inflight_ops;
  std::atomic<uint64_t> inflight_ops = 0;

  std::unordered_map<std::string, Entry*> m_cache_map;
  RWLock m_cache_map_lock;

  std::deque<Entry*> m_free_list;
  Mutex m_free_list_lock;

  LRU m_promoted_lru;
};

} // namespace immutable_obj_cache
} // namespace ceph
#endif // CEPH_CACHE_SIMPLE_POLICY_H