]> git.proxmox.com Git - ceph.git/blame - ceph/src/osd/TierAgentState.h
import ceph quincy 17.2.1
[ceph.git] / ceph / src / osd / TierAgentState.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2/*
3 * Ceph - scalable distributed file system
4 *
5 * Copyright (C) 2013 Sage Weil <sage@inktank.com>
6 *
7 * This is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License version 2.1, as published by the Free Software
10 * Foundation. See file COPYING.
11 *
12 */
13
14#ifndef CEPH_OSD_TIERAGENT_H
15#define CEPH_OSD_TIERAGENT_H
16
f67539c2
TL
17#include <ctime>
18#include <list>
19#include <map>
20#include <utility>
21
22#include "common/Formatter.h"
23#include "common/histogram.h"
24#include "common/hobject.h"
25
26#include "osd/HitSet.h"
27
7c673cae
FG
28struct TierAgentState {
29 /// current position iterating across pool
30 hobject_t position;
31 /// Count of agent_work since "start" position of object hash space
32 int started;
33 hobject_t start;
34 bool delaying;
35
36 /// histogram of ages we've encountered
37 pow2_hist_t temp_hist;
38 int hist_age;
39
40 /// past HitSet(s) (not current)
f67539c2 41 std::map<time_t,HitSetRef> hit_set_map;
7c673cae
FG
42
43 /// a few recent things we've seen that are clean
f67539c2 44 std::list<hobject_t> recent_clean;
7c673cae
FG
45
46 enum flush_mode_t {
47 FLUSH_MODE_IDLE, // nothing to flush
48 FLUSH_MODE_LOW, // flush dirty objects with a low speed
49 FLUSH_MODE_HIGH, //flush dirty objects with a high speed
50 } flush_mode; ///< current flush behavior
51 static const char *get_flush_mode_name(flush_mode_t m) {
52 switch (m) {
53 case FLUSH_MODE_IDLE: return "idle";
54 case FLUSH_MODE_LOW: return "low";
55 case FLUSH_MODE_HIGH: return "high";
11fdf7f2 56 default: ceph_abort_msg("bad flush mode");
7c673cae
FG
57 }
58 }
59 const char *get_flush_mode_name() const {
60 return get_flush_mode_name(flush_mode);
61 }
62
63 enum evict_mode_t {
64 EVICT_MODE_IDLE, // no need to evict anything
65 EVICT_MODE_SOME, // evict some things as we are near the target
66 EVICT_MODE_FULL, // evict anything
67 } evict_mode; ///< current evict behavior
68 static const char *get_evict_mode_name(evict_mode_t m) {
69 switch (m) {
70 case EVICT_MODE_IDLE: return "idle";
71 case EVICT_MODE_SOME: return "some";
72 case EVICT_MODE_FULL: return "full";
11fdf7f2 73 default: ceph_abort_msg("bad evict mode");
7c673cae
FG
74 }
75 }
76 const char *get_evict_mode_name() const {
77 return get_evict_mode_name(evict_mode);
78 }
79
80 /// approximate ratio of objects (assuming they are uniformly
81 /// distributed) that i should aim to evict.
82 unsigned evict_effort;
83
84 TierAgentState()
85 : started(0),
86 delaying(false),
87 hist_age(0),
88 flush_mode(FLUSH_MODE_IDLE),
89 evict_mode(EVICT_MODE_IDLE),
90 evict_effort(0)
91 {}
92
93 /// false if we have any work to do
94 bool is_idle() const {
95 return
96 delaying ||
97 (flush_mode == FLUSH_MODE_IDLE &&
98 evict_mode == EVICT_MODE_IDLE);
99 }
100
101 /// add archived HitSet
102 void add_hit_set(time_t start, HitSetRef hs) {
f67539c2 103 hit_set_map.insert(std::make_pair(start, hs));
7c673cae
FG
104 }
105
106 /// remove old/trimmed HitSet
107 void remove_oldest_hit_set() {
108 if (!hit_set_map.empty())
109 hit_set_map.erase(hit_set_map.begin());
110 }
111
112 /// discard all open hit sets
113 void discard_hit_sets() {
114 hit_set_map.clear();
115 }
116
f67539c2 117 void dump(ceph::Formatter *f) const {
7c673cae
FG
118 f->dump_string("flush_mode", get_flush_mode_name());
119 f->dump_string("evict_mode", get_evict_mode_name());
120 f->dump_unsigned("evict_effort", evict_effort);
121 f->dump_stream("position") << position;
122 f->open_object_section("temp_hist");
123 temp_hist.dump(f);
124 f->close_section();
125 }
126};
127
128#endif