#include "common/config.h"
#include "common/errno.h"
#include "common/DecayCounter.h"
-#include "include/assert.h"
+#include "include/ceph_assert.h"
#include "include/stringify.h"
#define dout_context g_ceph_context
MDSRank *get_mds() override {return sessionmap->mds;}
public:
explicit SessionMapIOContext(SessionMap *sessionmap_) : sessionmap(sessionmap_) {
- assert(sessionmap != NULL);
+ ceph_assert(sessionmap != NULL);
}
};
};
void SessionMapStore::decode_header(
bufferlist &header_bl)
{
- bufferlist::iterator q = header_bl.begin();
+ auto q = header_bl.cbegin();
DECODE_START(1, q)
- ::decode(version, q);
+ decode(version, q);
DECODE_FINISH(q);
}
bufferlist *header_bl)
{
ENCODE_START(1, 1, *header_bl);
- ::encode(version, *header_bl);
+ encode(version, *header_bl);
ENCODE_FINISH(*header_bl);
}
s->set_state(Session::STATE_OPEN);
s->set_load_avg_decay_rate(decay_rate);
}
- auto q = i->second.begin();
+ auto q = i->second.cbegin();
s->decode(q);
}
}
object_locator_t oloc(mds->mdsmap->get_metadata_pool());
C_IO_SM_Load *c = new C_IO_SM_Load(this, false);
ObjectOperation op;
- op.omap_get_vals(last_key, "", g_conf->mds_sessionmap_keys_per_op,
+ op.omap_get_vals(last_key, "", g_conf()->mds_sessionmap_keys_per_op,
&c->session_vals, &c->more_session_vals, &c->values_r);
mds->objecter->read(oid, oloc, op, CEPH_NOSNAP, NULL, 0,
new C_OnFinisher(c, mds->finisher));
* Populate session state from OMAP records in this
* rank's sessionmap object.
*/
-void SessionMap::load(MDSInternalContextBase *onload)
+void SessionMap::load(MDSContext *onload)
{
dout(10) << "load" << dendl;
ObjectOperation op;
op.omap_get_header(&c->header_bl, &c->header_r);
- op.omap_get_vals("", "", g_conf->mds_sessionmap_keys_per_op,
+ op.omap_get_vals("", "", g_conf()->mds_sessionmap_keys_per_op,
&c->session_vals, &c->more_session_vals, &c->values_r);
mds->objecter->read(oid, oloc, op, CEPH_NOSNAP, NULL, 0, new C_OnFinisher(c, mds->finisher));
void SessionMap::_load_legacy_finish(int r, bufferlist &bl)
{
- bufferlist::iterator blp = bl.begin();
+ auto blp = bl.cbegin();
if (r < 0) {
derr << "_load_finish got " << cpp_strerror(r) << dendl;
- assert(0 == "failed to load sessionmap");
+ ceph_abort_msg("failed to load sessionmap");
}
dump();
decode_legacy(blp); // note: this sets last_cap_renew = now()
};
}
-void SessionMap::save(MDSInternalContextBase *onsave, version_t needv)
+void SessionMap::save(MDSContext *onsave, version_t needv)
{
dout(10) << __func__ << ": needv " << needv << ", v " << version << dendl;
if (needv && committing >= needv) {
- assert(committing > committed);
+ ceph_assert(committing > committed);
commit_waiters[committing].push_back(onsave);
return;
}
/**
* Deserialize sessions, and update by_state index
*/
-void SessionMap::decode_legacy(bufferlist::iterator &p)
+void SessionMap::decode_legacy(bufferlist::const_iterator &p)
{
// Populate `sessions`
SessionMapStore::decode_legacy(p);
return session->get_state_seq();
}
-void SessionMapStore::decode_legacy(bufferlist::iterator& p)
+void SessionMapStore::decode_legacy(bufferlist::const_iterator& p)
{
auto now = clock::now();
uint64_t pre;
- ::decode(pre, p);
+ decode(pre, p);
if (pre == (uint64_t)-1) {
DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, p);
- assert(struct_v >= 2);
+ ceph_assert(struct_v >= 2);
- ::decode(version, p);
+ decode(version, p);
while (!p.end()) {
entity_inst_t inst;
- ::decode(inst.name, p);
+ decode(inst.name, p);
Session *s = get_or_add_session(inst);
if (s->is_closed()) {
s->set_state(Session::STATE_OPEN);
// this is a meaningless upper bound. can be ignored.
__u32 n;
- ::decode(n, p);
+ decode(n, p);
while (n-- && !p.end()) {
auto p2 = p;
{
dout(10) << __func__ << " s=" << s << " name=" << s->info.inst.name << dendl;
- assert(session_map.count(s->info.inst.name) == 0);
+ ceph_assert(session_map.count(s->info.inst.name) == 0);
session_map[s->info.inst.name] = s;
auto by_state_entry = by_state.find(s->state);
if (by_state_entry == by_state.end())
// Move to the back of the session list for this state (should
// already be on a list courtesy of add_session and set_state)
- assert(session->item_session_list.is_on_list());
+ ceph_assert(session->item_session_list.is_on_list());
auto by_state_entry = by_state.find(session->state);
if (by_state_entry == by_state.end())
by_state_entry = by_state.emplace(session->state,
if (dirty_sessions.count(s->info.inst.name))
return;
- if (dirty_sessions.size() >= g_conf->mds_sessionmap_keys_per_op) {
+ if (dirty_sessions.size() >= g_conf()->mds_sessionmap_keys_per_op) {
// Pre-empt the usual save() call from journal segment trim, in
// order to avoid building up an oversized OMAP update operation
// from too many sessions modified at once
namespace {
class C_IO_SM_Save_One : public SessionMapIOContext {
- MDSInternalContextBase *on_safe;
+ MDSContext *on_safe;
public:
- C_IO_SM_Save_One(SessionMap *cm, MDSInternalContextBase *on_safe_)
+ C_IO_SM_Save_One(SessionMap *cm, MDSContext *on_safe_)
: SessionMapIOContext(cm), on_safe(on_safe_) {}
void finish(int r) override {
if (r != 0) {
void SessionMap::save_if_dirty(const std::set<entity_name_t> &tgt_sessions,
MDSGatherBuilder *gather_bld)
{
- assert(gather_bld != NULL);
+ ceph_assert(gather_bld != NULL);
std::vector<entity_name_t> write_sessions;
dout(4) << __func__ << ": writing " << write_sessions.size() << dendl;
// Batch writes into mds_sessionmap_keys_per_op
- const uint32_t kpo = g_conf->mds_sessionmap_keys_per_op;
+ const uint32_t kpo = g_conf()->mds_sessionmap_keys_per_op;
map<string, bufferlist> to_set;
for (uint32_t i = 0; i < write_sessions.size(); ++i) {
- // Start a new write transaction?
- if (i % g_conf->mds_sessionmap_keys_per_op == 0) {
- to_set.clear();
- }
-
const entity_name_t &session_id = write_sessions[i];
Session *session = session_map[session_id];
session->clear_dirty_completed_requests();
|| i % kpo == kpo - 1) {
ObjectOperation op;
op.omap_set(to_set);
+ to_set.clear(); // clear to start a new transaction
SnapContext snapc;
object_t oid = get_object_name();
object_locator_t oloc(mds->mdsmap->get_metadata_pool());
- MDSInternalContextBase *on_safe = gather_bld->new_sub();
+ MDSContext *on_safe = gather_bld->new_sub();
mds->objecter->mutate(oid, oloc, op, snapc,
ceph::real_clock::now(), 0,
new C_OnFinisher(
*/
void Session::notify_cap_release(size_t n_caps)
{
- recall_caps.hit(ceph_clock_now(), -(double)n_caps);
- release_caps.hit(ceph_clock_now(), n_caps);
+ recall_caps.hit(-(double)n_caps);
+ release_caps.hit(n_caps);
}
/**
* session that is not releasing caps (i.e. allow the session counter to
* throttle future RECALL messages).
*/
- recall_caps_throttle.hit(ceph_clock_now(), count);
- recall_caps.hit(ceph_clock_now(), count);
+ recall_caps_throttle.hit(count);
+ recall_caps_throttle2o.hit(count);
+ recall_caps.hit(count);
return new_change;
}
}
}
-void Session::decode(bufferlist::iterator &p)
+void Session::decode(bufferlist::const_iterator &p)
{
info.decode(p);
if (!in->is_base())
diri = in->get_projected_parent_dn()->get_dir()->get_inode();
if (diri && diri->is_stray()){
- path = std::string(boost::string_view(in->get_projected_inode()->stray_prior_path));
+ path = in->get_projected_inode()->stray_prior_path;
dout(20) << __func__ << " stray_prior_path " << path << dendl;
} else {
in->make_path_string(path, true);
if (!auth_caps.is_capable(path, in->inode.uid, in->inode.gid, in->inode.mode,
caller_uid, caller_gid, caller_gid_list, mask,
- new_uid, new_gid)) {
+ new_uid, new_gid,
+ socket_addr)) {
return -EACCES;
}
return 0;
void SessionMap::hit_session(Session *session) {
uint64_t sessions = get_session_count_in_state(Session::STATE_OPEN) +
get_session_count_in_state(Session::STATE_STALE);
- assert(sessions != 0);
+ ceph_assert(sessions != 0);
- double total_load = total_load_avg.hit(ceph_clock_now(), total_load_avg_rate);
+ double total_load = total_load_avg.hit();
double avg_load = total_load / sessions;
logger->set(l_mdssm_total_load, (uint64_t)total_load);
session->hit_session();
}
-void SessionMap::handle_conf_change(const struct md_config_t *conf,
+void SessionMap::handle_conf_change(const ConfigProxy &conf,
const std::set <std::string> &changed)
{
-
- if (changed.count("mds_request_load_average_decay_rate")) {
- auto d = g_conf->get_val<double>("mds_request_load_average_decay_rate");
- dout(20) << __func__ << " decay rate changed to " << d << dendl;
-
- decay_rate = d;
- total_load_avg = DecayCounter(ceph_clock_now(), d);
-
- auto it = by_state.find(Session::STATE_OPEN);
- if (it != by_state.end()) {
+ auto apply_to_open_sessions = [this](auto f) {
+ if (auto it = by_state.find(Session::STATE_OPEN); it != by_state.end()) {
for (const auto &session : *(it->second)) {
- session->set_load_avg_decay_rate(d);
+ f(session);
}
}
- it = by_state.find(Session::STATE_STALE);
- if (it != by_state.end()) {
+ if (auto it = by_state.find(Session::STATE_STALE); it != by_state.end()) {
for (const auto &session : *(it->second)) {
- session->set_load_avg_decay_rate(d);
+ f(session);
}
}
+ };
+
+ if (changed.count("mds_request_load_average_decay_rate")) {
+ auto d = g_conf().get_val<double>("mds_request_load_average_decay_rate");
+ dout(20) << __func__ << " decay rate changed to " << d << dendl;
+
+ decay_rate = d;
+ total_load_avg = DecayCounter(d);
+
+ auto mut = [d](auto s) {
+ s->set_load_avg_decay_rate(d);
+ };
+ apply_to_open_sessions(mut);
}
if (changed.count("mds_recall_max_decay_rate")) {
- auto d = g_conf->get_val<double>("mds_recall_max_decay_rate");
- auto it = by_state.find(Session::STATE_OPEN);
- if (it != by_state.end()) {
- for (const auto &session : *(it->second)) {
- session->recall_caps_throttle = DecayCounter(ceph_clock_now(), d);
- }
- }
- it = by_state.find(Session::STATE_STALE);
- if (it != by_state.end()) {
- for (const auto &session : *(it->second)) {
- session->recall_caps_throttle = DecayCounter(ceph_clock_now(), d);
- }
- }
+ auto d = g_conf().get_val<double>("mds_recall_max_decay_rate");
+ auto mut = [d](auto s) {
+ s->recall_caps_throttle = DecayCounter(d);
+ };
+ apply_to_open_sessions(mut);
}
if (changed.count("mds_recall_warning_decay_rate")) {
- auto d = g_conf->get_val<double>("mds_recall_warning_decay_rate");
- auto it = by_state.find(Session::STATE_OPEN);
- if (it != by_state.end()) {
- for (const auto &session : *(it->second)) {
- session->recall_caps = DecayCounter(ceph_clock_now(), d);
- session->release_caps = DecayCounter(ceph_clock_now(), d);
- }
- }
- it = by_state.find(Session::STATE_STALE);
- if (it != by_state.end()) {
- for (const auto &session : *(it->second)) {
- session->recall_caps = DecayCounter(ceph_clock_now(), d);
- session->release_caps = DecayCounter(ceph_clock_now(), d);
- }
- }
+ auto d = g_conf().get_val<double>("mds_recall_warning_decay_rate");
+ auto mut = [d](auto s) {
+ s->recall_caps = DecayCounter(d);
+ s->release_caps = DecayCounter(d);
+ };
+ apply_to_open_sessions(mut);
}
}
const std::vector<std::string> &args,
std::stringstream *ss)
{
- assert(ss != NULL);
+ ceph_assert(ss != NULL);
for (const auto &s : args) {
dout(20) << __func__ << " parsing filter '" << s << "'" << dendl;
* Strict boolean parser. Allow true/false/0/1.
* Anything else is -EINVAL.
*/
- auto is_true = [](boost::string_view bstr, bool *out) -> bool
+ auto is_true = [](std::string_view bstr, bool *out) -> bool
{
- assert(out != nullptr);
+ ceph_assert(out != nullptr);
if (bstr == "true" || bstr == "1") {
*out = true;
for (const auto &m : metadata) {
const auto &k = m.first;
const auto &v = m.second;
- if (session.info.client_metadata.count(k) == 0) {
+ auto it = session.info.client_metadata.find(k);
+ if (it == session.info.client_metadata.end()) {
return false;
}
- if (session.info.client_metadata.at(k) != v) {
+ if (it->second != v) {
return false;
}
}
std::ostream& operator<<(std::ostream &out, const Session &s)
{
- if (s.get_human_name() == stringify(s.info.inst.name.num())) {
+ if (s.get_human_name() == stringify(s.get_client())) {
out << s.get_human_name();
} else {
- out << s.get_human_name() << " (" << std::dec << s.info.inst.name.num() << ")";
+ out << s.get_human_name() << " (" << std::dec << s.get_client() << ")";
}
return out;
}