summaryrefslogtreecommitdiffstats
path: root/src/osd/TierAgentState.h
blob: 28e1598a95962a04a1b83e90503428beb70314f0 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2013 Sage Weil <sage@inktank.com>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#ifndef CEPH_OSD_TIERAGENT_H
#define CEPH_OSD_TIERAGENT_H

#include <ctime>
#include <list>
#include <map>
#include <utility>

#include "common/Formatter.h"
#include "common/histogram.h"
#include "common/hobject.h"

#include "osd/HitSet.h"

struct TierAgentState {
  /// current position iterating across pool
  hobject_t position;
  /// Count of agent_work since "start" position of object hash space
  int started;
  hobject_t start;
  bool delaying;

  /// histogram of ages we've encountered
  pow2_hist_t temp_hist;
  int hist_age;

  /// past HitSet(s) (not current)
  std::map<time_t,HitSetRef> hit_set_map;

  /// a few recent things we've seen that are clean
  std::list<hobject_t> recent_clean;

  enum flush_mode_t {
    FLUSH_MODE_IDLE,   // nothing to flush
    FLUSH_MODE_LOW, // flush dirty objects with a low speed
    FLUSH_MODE_HIGH, //flush dirty objects with a high speed
  } flush_mode;     ///< current flush behavior
  static const char *get_flush_mode_name(flush_mode_t m) {
    switch (m) {
    case FLUSH_MODE_IDLE: return "idle";
    case FLUSH_MODE_LOW: return "low";
    case FLUSH_MODE_HIGH: return "high";
    default: ceph_abort_msg("bad flush mode");
    }
  }
  const char *get_flush_mode_name() const {
    return get_flush_mode_name(flush_mode);
  }

  enum evict_mode_t {
    EVICT_MODE_IDLE,      // no need to evict anything
    EVICT_MODE_SOME,      // evict some things as we are near the target
    EVICT_MODE_FULL,      // evict anything
  } evict_mode;     ///< current evict behavior
  static const char *get_evict_mode_name(evict_mode_t m) {
    switch (m) {
    case EVICT_MODE_IDLE: return "idle";
    case EVICT_MODE_SOME: return "some";
    case EVICT_MODE_FULL: return "full";
    default: ceph_abort_msg("bad evict mode");
    }
  }
  const char *get_evict_mode_name() const {
    return get_evict_mode_name(evict_mode);
  }

  /// approximate ratio of objects (assuming they are uniformly
  /// distributed) that i should aim to evict.
  unsigned evict_effort;

  TierAgentState()
    : started(0),
      delaying(false),
      hist_age(0),
      flush_mode(FLUSH_MODE_IDLE),
      evict_mode(EVICT_MODE_IDLE),
      evict_effort(0)
  {}

  /// false if we have any work to do
  bool is_idle() const {
    return
      delaying ||
      (flush_mode == FLUSH_MODE_IDLE &&
      evict_mode == EVICT_MODE_IDLE);
  }

  /// add archived HitSet
  void add_hit_set(time_t start, HitSetRef hs) {
    hit_set_map.insert(std::make_pair(start, hs));
  }

  /// remove old/trimmed HitSet
  void remove_oldest_hit_set() {
    if (!hit_set_map.empty())
      hit_set_map.erase(hit_set_map.begin());
  }

  /// discard all open hit sets
  void discard_hit_sets() {
    hit_set_map.clear();
  }

  void dump(ceph::Formatter *f) const {
    f->dump_string("flush_mode", get_flush_mode_name());
    f->dump_string("evict_mode", get_evict_mode_name());
    f->dump_unsigned("evict_effort", evict_effort);
    f->dump_stream("position") << position;
    f->open_object_section("temp_hist");
    temp_hist.dump(f);
    f->close_section();
  }
};

#endif