]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDBalancer.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
17 #ifndef CEPH_MDBALANCER_H
18 #define CEPH_MDBALANCER_H
23 #include "include/types.h"
24 #include "common/Clock.h"
25 #include "common/Cond.h"
27 #include "msg/Message.h"
28 #include "messages/MHeartbeat.h"
41 using clock
= ceph::coarse_mono_clock
;
42 using time
= ceph::coarse_mono_time
;
43 friend class C_Bal_SendHeartbeat
;
45 MDBalancer(MDSRank
*m
, Messenger
*msgr
, MonClient
*monc
);
47 void handle_conf_change(const ConfigProxy
& conf
,
48 const std::set
<std::string
> &changed
,
49 const MDSMap
&mds_map
);
51 int proc_message(const Message::const_ref
&m
);
54 * Regularly called upkeep function.
56 * Sends MHeartbeat messages to the mons.
60 void subtract_export(CDir
*ex
);
61 void add_import(CDir
*im
);
62 void adjust_pop_for_rename(CDir
*pdir
, CDir
*dir
, bool inc
);
64 void hit_inode(CInode
*in
, int type
, int who
=-1);
65 void hit_dir(CDir
*dir
, int type
, int who
=-1, double amount
=1.0);
67 void queue_split(const CDir
*dir
, bool fast
);
68 void queue_merge(CDir
*dir
);
71 * Based on size and configuration, decide whether to issue a queue_split
72 * or queue_merge for this CDir.
74 * \param hot whether the directory's temperature is enough to split it
76 void maybe_fragment(CDir
*dir
, bool hot
);
78 void handle_mds_failure(mds_rank_t who
);
80 int dump_loads(Formatter
*f
);
83 bool bal_fragment_dirs
;
84 int64_t bal_fragment_interval
;
87 std::map
<mds_rank_t
, double> targets
;
88 std::map
<mds_rank_t
, double> imported
;
89 std::map
<mds_rank_t
, double> exported
;
92 //set up the rebalancing targets for export and do one if the
93 //MDSMap is up to date
94 void prep_rebalance(int beat
);
95 int mantle_prep_rebalance();
97 void handle_export_pins(void);
99 mds_load_t
get_load();
100 int localize_balancer();
101 void send_heartbeat();
102 void handle_heartbeat(const MHeartbeat::const_ref
&m
);
103 void find_exports(CDir
*dir
,
105 std::list
<CDir
*>& exports
,
107 set
<CDir
*>& already_exporting
);
109 double try_match(balance_state_t
&state
,
110 mds_rank_t ex
, double& maxex
,
111 mds_rank_t im
, double& maxim
);
113 double get_maxim(balance_state_t
&state
, mds_rank_t im
) {
114 return target_load
- mds_meta_load
[im
] - state
.imported
[im
];
116 double get_maxex(balance_state_t
&state
, mds_rank_t ex
) {
117 return mds_meta_load
[ex
] - target_load
- state
.exported
[ex
];
123 * Check if the monitor has recorded the current export targets;
124 * if it has then do the actual export. Otherwise send off our
125 * export targets message again.
127 void try_rebalance(balance_state_t
& state
);
130 Messenger
*messenger
;
131 MonClient
*mon_client
;
137 time last_heartbeat
= clock::zero();
138 time last_sample
= clock::zero();
139 time rebalance_time
= clock::zero(); //ensure a consistent view of load for rebalance
141 time last_get_load
= clock::zero();
142 uint64_t last_num_requests
= 0;
143 uint64_t last_cpu_time
= 0;
145 // Dirfrags which are marked to be passed on to MDCache::[split|merge]_dir
146 // just as soon as a delayed context comes back and triggers it.
147 // These sets just prevent us from spawning extra timer contexts for
148 // dirfrags that already have one in flight.
149 set
<dirfrag_t
> split_pending
, merge_pending
;
151 // per-epoch scatter/gathered info
152 std::map
<mds_rank_t
, mds_load_t
> mds_load
;
153 std::map
<mds_rank_t
, double> mds_meta_load
;
154 std::map
<mds_rank_t
, map
<mds_rank_t
, float> > mds_import_map
;
155 std::map
<mds_rank_t
, int> mds_last_epoch_under_map
;
159 double target_load
= 0;