repo
stringlengths
1
152
file
stringlengths
14
221
code
stringlengths
501
25k
file_length
int64
501
25k
avg_line_length
float64
20
99.5
max_line_length
int64
21
134
extension_type
stringclasses
2 values
null
ceph-main/src/messages/MOSDBackoff.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 Red Hat * * 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_MOSDBACKOFF_H #define CEPH_MOSDBACKOFF_H #include "MOSDFastDispatchOp.h" #include "osd/osd_types.h" class MOSDBackoff : public MOSDFastDispatchOp { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; spg_t pgid; epoch_t map_epoch = 0; uint8_t op = 0; ///< CEPH_OSD_BACKOFF_OP_* uint64_t id = 0; ///< unique id within this session hobject_t begin, end; ///< [) range to block, unless ==, block single obj spg_t get_spg() const override { return pgid; } epoch_t get_map_epoch() const override { return map_epoch; } MOSDBackoff() : MOSDFastDispatchOp{CEPH_MSG_OSD_BACKOFF, HEAD_VERSION, COMPAT_VERSION} {} MOSDBackoff(spg_t pgid_, epoch_t ep, uint8_t op_, uint64_t id_, hobject_t begin_, hobject_t end_) : MOSDFastDispatchOp{CEPH_MSG_OSD_BACKOFF, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid_), map_epoch(ep), op(op_), id(id_), begin(begin_), end(end_) { } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(op, payload); encode(id, payload); encode(begin, payload); encode(end, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(op, p); decode(id, p); decode(begin, p); decode(end, p); } std::string_view get_type_name() const override { return "osd_backoff"; } void print(std::ostream& out) const override { out << "osd_backoff(" << pgid << " " << ceph_osd_backoff_op_name(op) << " id " << id << " [" << begin << "," << end << ")" << " e" << map_epoch << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,295
25.390805
79
h
null
ceph-main/src/messages/MOSDBeacon.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "PaxosServiceMessage.h" class MOSDBeacon : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 1; public: std::vector<pg_t> pgs; epoch_t min_last_epoch_clean = 0; utime_t last_purged_snaps_scrub; int osd_beacon_report_interval = 0; MOSDBeacon() : PaxosServiceMessage{MSG_OSD_BEACON, 0, HEAD_VERSION, COMPAT_VERSION} {} MOSDBeacon(epoch_t e, epoch_t min_lec, utime_t ls, int interval) : PaxosServiceMessage{MSG_OSD_BEACON, e, HEAD_VERSION, COMPAT_VERSION}, min_last_epoch_clean(min_lec), last_purged_snaps_scrub(ls), osd_beacon_report_interval(interval) {} void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(pgs, payload); encode(min_last_epoch_clean, payload); encode(last_purged_snaps_scrub, payload); encode(osd_beacon_report_interval, payload); } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; paxos_decode(p); decode(pgs, p); decode(min_last_epoch_clean, p); if (header.version >= 2) { decode(last_purged_snaps_scrub, p); } if (header.version >= 3) { decode(osd_beacon_report_interval, p); } else { osd_beacon_report_interval = 0; } } std::string_view get_type_name() const override { return "osd_beacon"; } void print(std::ostream &out) const { out << get_type_name() << "(pgs " << pgs << " lec " << min_last_epoch_clean << " last_purged_snaps_scrub " << last_purged_snaps_scrub << " osd_beacon_report_interval " << osd_beacon_report_interval << " v" << version << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,954
29.076923
74
h
null
ceph-main/src/messages/MOSDBoot.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDBOOT_H #define CEPH_MOSDBOOT_H #include "messages/PaxosServiceMessage.h" #include "include/ceph_features.h" #include "include/types.h" #include "osd/osd_types.h" class MOSDBoot final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 7; static constexpr int COMPAT_VERSION = 7; public: OSDSuperblock sb; entity_addrvec_t hb_back_addrs, hb_front_addrs; entity_addrvec_t cluster_addrs; epoch_t boot_epoch; // last epoch this daemon was added to the map (if any) std::map<std::string,std::string> metadata; ///< misc metadata about this osd uint64_t osd_features; MOSDBoot() : PaxosServiceMessage{MSG_OSD_BOOT, 0, HEAD_VERSION, COMPAT_VERSION}, boot_epoch(0), osd_features(0) { } MOSDBoot(const OSDSuperblock& s, epoch_t e, epoch_t be, const entity_addrvec_t& hb_back_addr_ref, const entity_addrvec_t& hb_front_addr_ref, const entity_addrvec_t& cluster_addr_ref, uint64_t feat) : PaxosServiceMessage{MSG_OSD_BOOT, e, HEAD_VERSION, COMPAT_VERSION}, sb(s), hb_back_addrs(hb_back_addr_ref), hb_front_addrs(hb_front_addr_ref), cluster_addrs(cluster_addr_ref), boot_epoch(be), osd_features(feat) { } private: ~MOSDBoot() final { } public: std::string_view get_type_name() const override { return "osd_boot"; } void print(std::ostream& out) const override { out << "osd_boot(osd." << sb.whoami << " booted " << boot_epoch << " features " << osd_features << " v" << version << ")"; } void encode_payload(uint64_t features) override { header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; using ceph::encode; paxos_encode(); assert(HAVE_FEATURE(features, SERVER_NAUTILUS)); encode(sb, payload); encode(hb_back_addrs, payload, features); encode(cluster_addrs, payload, features); encode(boot_epoch, payload); encode(hb_front_addrs, payload, features); encode(metadata, payload); encode(osd_features, payload); } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; paxos_decode(p); assert(header.version >= 7); decode(sb, p); decode(hb_back_addrs, p); decode(cluster_addrs, p); decode(boot_epoch, p); decode(hb_front_addrs, p); decode(metadata, p); decode(osd_features, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,929
28.59596
79
h
null
ceph-main/src/messages/MOSDECSubOpRead.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDECSUBOPREAD_H #define MOSDECSUBOPREAD_H #include "MOSDFastDispatchOp.h" #include "osd/ECMsgTypes.h" class MOSDECSubOpRead : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 1; public: spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; ECSubRead op; int get_cost() const override { return 0; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDECSubOpRead() : MOSDFastDispatchOp{MSG_OSD_EC_READ, HEAD_VERSION, COMPAT_VERSION} {} void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(op, p); if (header.version >= 3) { decode(min_epoch, p); decode_trace(p); } else { min_epoch = map_epoch; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(op, payload, features); encode(min_epoch, payload); encode_trace(payload, features); } std::string_view get_type_name() const override { return "MOSDECSubOpRead"; } void print(std::ostream& out) const override { out << "MOSDECSubOpRead(" << pgid << " " << map_epoch << "/" << min_epoch << " " << op; out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,005
22.6
79
h
null
ceph-main/src/messages/MOSDECSubOpReadReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDECSUBOPREADREPLY_H #define MOSDECSUBOPREADREPLY_H #include "MOSDFastDispatchOp.h" #include "osd/ECMsgTypes.h" class MOSDECSubOpReadReply : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; ECSubReadReply op; int get_cost() const override { return 0; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDECSubOpReadReply() : MOSDFastDispatchOp{MSG_OSD_EC_READ_REPLY, HEAD_VERSION, COMPAT_VERSION} {} void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(op, p); if (header.version >= 2) { decode(min_epoch, p); decode_trace(p); } else { min_epoch = map_epoch; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(op, payload); encode(min_epoch, payload); encode_trace(payload, features); } std::string_view get_type_name() const override { return "MOSDECSubOpReadReply"; } void print(std::ostream& out) const override { out << "MOSDECSubOpReadReply(" << pgid << " " << map_epoch << "/" << min_epoch << " " << op; out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,036
22.964706
84
h
null
ceph-main/src/messages/MOSDECSubOpWrite.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDECSUBOPWRITE_H #define MOSDECSUBOPWRITE_H #include "MOSDFastDispatchOp.h" #include "osd/ECMsgTypes.h" class MOSDECSubOpWrite : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; ECSubWrite op; int get_cost() const override { return 0; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDECSubOpWrite() : MOSDFastDispatchOp{MSG_OSD_EC_WRITE, HEAD_VERSION, COMPAT_VERSION} {} MOSDECSubOpWrite(ECSubWrite &in_op) : MOSDFastDispatchOp{MSG_OSD_EC_WRITE, HEAD_VERSION, COMPAT_VERSION} { op.claim(in_op); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(op, p); if (header.version >= 2) { decode(min_epoch, p); decode_trace(p); } else { min_epoch = map_epoch; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(op, payload); encode(min_epoch, payload); encode_trace(payload, features); } std::string_view get_type_name() const override { return "MOSDECSubOpWrite"; } void print(std::ostream& out) const override { out << "MOSDECSubOpWrite(" << pgid << " " << map_epoch << "/" << min_epoch << " " << op; out << ")"; } void clear_buffers() override { op.t = ObjectStore::Transaction(); op.log_entries.clear(); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,247
22.914894
80
h
null
ceph-main/src/messages/MOSDECSubOpWriteReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDECSUBOPWRITEREPLY_H #define MOSDECSUBOPWRITEREPLY_H #include "MOSDFastDispatchOp.h" #include "osd/ECMsgTypes.h" class MOSDECSubOpWriteReply : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; ECSubWriteReply op; int get_cost() const override { return 0; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDECSubOpWriteReply() : MOSDFastDispatchOp{MSG_OSD_EC_WRITE_REPLY, HEAD_VERSION, COMPAT_VERSION} {} void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(op, p); if (header.version >= 2) { decode(min_epoch, p); decode_trace(p); } else { min_epoch = map_epoch; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(op, payload); encode(min_epoch, payload); encode_trace(payload, features); } std::string_view get_type_name() const override { return "MOSDECSubOpWriteReply"; } void print(std::ostream& out) const override { out << "MOSDECSubOpWriteReply(" << pgid << " " << map_epoch << "/" << min_epoch << " " << op; out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,042
23.035294
85
h
null
ceph-main/src/messages/MOSDFailure.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDFAILURE_H #define CEPH_MOSDFAILURE_H #include "messages/PaxosServiceMessage.h" class MOSDFailure final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 4; public: enum { FLAG_ALIVE = 0, // use this on its own to mark as "I'm still alive" FLAG_FAILED = 1, // if set, failure; if not, recovery FLAG_IMMEDIATE = 2, // known failure, not a timeout }; uuid_d fsid; int32_t target_osd; entity_addrvec_t target_addrs; __u8 flags = 0; epoch_t epoch = 0; int32_t failed_for = 0; // known to be failed since at least this long MOSDFailure() : PaxosServiceMessage(MSG_OSD_FAILURE, 0, HEAD_VERSION) { } MOSDFailure(const uuid_d &fs, int osd, const entity_addrvec_t& av, int duration, epoch_t e) : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION), fsid(fs), target_osd(osd), target_addrs(av), flags(FLAG_FAILED), epoch(e), failed_for(duration) { } MOSDFailure(const uuid_d &fs, int osd, const entity_addrvec_t& av, int duration, epoch_t e, __u8 extra_flags) : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION), fsid(fs), target_osd(osd), target_addrs(av), flags(extra_flags), epoch(e), failed_for(duration) { } private: ~MOSDFailure() final {} public: int get_target_osd() { return target_osd; } const entity_addrvec_t& get_target_addrs() { return target_addrs; } bool if_osd_failed() const { return flags & FLAG_FAILED; } bool is_immediate() const { return flags & FLAG_IMMEDIATE; } epoch_t get_epoch() const { return epoch; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); assert(header.version >= 4); decode(target_osd, p); decode(target_addrs, p); decode(epoch, p); decode(flags, p); decode(failed_for, p); } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); assert(HAVE_FEATURE(features, SERVER_NAUTILUS)); header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(fsid, payload); encode(target_osd, payload, features); encode(target_addrs, payload, features); encode(epoch, payload); encode(flags, payload); encode(failed_for, payload); } std::string_view get_type_name() const override { return "osd_failure"; } void print(std::ostream& out) const override { out << "osd_failure(" << (if_osd_failed() ? "failed " : "recovered ") << (is_immediate() ? "immediate " : "timeout ") << "osd." << target_osd << " " << target_addrs << " for " << failed_for << "sec e" << epoch << " v" << version << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
3,391
28.495652
76
h
null
ceph-main/src/messages/MOSDFastDispatchOp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MOSDFASTDISPATCHOP_H #define CEPH_MOSDFASTDISPATCHOP_H #include "msg/Message.h" #include "osd/osd_types.h" class MOSDFastDispatchOp : public Message { public: MOSDFastDispatchOp(int t, int version, int compat_version) : Message{t, version, compat_version} {} virtual epoch_t get_map_epoch() const = 0; virtual epoch_t get_min_epoch() const { return get_map_epoch(); } virtual spg_t get_spg() const = 0; }; #endif
548
22.869565
70
h
null
ceph-main/src/messages/MOSDForceRecovery.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 OVH * * 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_MOSDFORCERECOVERY_H #define CEPH_MOSDFORCERECOVERY_H #include "msg/Message.h" /* * instruct an OSD to boost/unboost recovery/backfill priority of some or all pg(s) */ // boost priority of recovery static const int OFR_RECOVERY = 1; // boost priority of backfill static const int OFR_BACKFILL = 2; // cancel priority boost, requeue if necessary static const int OFR_CANCEL = 4; class MOSDForceRecovery final : public Message { public: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 2; uuid_d fsid; std::vector<spg_t> forced_pgs; uint8_t options = 0; MOSDForceRecovery() : Message{MSG_OSD_FORCE_RECOVERY, HEAD_VERSION, COMPAT_VERSION} {} MOSDForceRecovery(const uuid_d& f, char opts) : Message{MSG_OSD_FORCE_RECOVERY, HEAD_VERSION, COMPAT_VERSION}, fsid(f), options(opts) {} MOSDForceRecovery(const uuid_d& f, std::vector<spg_t>& pgs, char opts) : Message{MSG_OSD_FORCE_RECOVERY, HEAD_VERSION, COMPAT_VERSION}, fsid(f), forced_pgs(pgs), options(opts) {} private: ~MOSDForceRecovery() final {} public: std::string_view get_type_name() const { return "force_recovery"; } void print(std::ostream& out) const { out << "force_recovery("; if (forced_pgs.empty()) out << "osd"; else out << forced_pgs; if (options & OFR_RECOVERY) out << " recovery"; if (options & OFR_BACKFILL) out << " backfill"; if (options & OFR_CANCEL) out << " cancel"; out << ")"; } void encode_payload(uint64_t features) { using ceph::encode; if (!HAVE_FEATURE(features, SERVER_MIMIC)) { header.version = 1; header.compat_version = 1; std::vector<pg_t> pgs; for (auto pgid : forced_pgs) { pgs.push_back(pgid.pgid); } encode(fsid, payload); encode(pgs, payload); encode(options, payload); return; } header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(fsid, payload); encode(forced_pgs, payload); encode(options, payload); } void decode_payload() { using ceph::decode; auto p = payload.cbegin(); if (header.version == 1) { std::vector<pg_t> pgs; decode(fsid, p); decode(pgs, p); decode(options, p); for (auto pg : pgs) { // note: this only works with replicated pools. if a pre-mimic mon // tries to force a mimic+ osd on an ec pool it will not work. forced_pgs.push_back(spg_t(pg)); } return; } decode(fsid, p); decode(forced_pgs, p); decode(options, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif /* CEPH_MOSDFORCERECOVERY_H_ */
3,127
26.2
88
h
null
ceph-main/src/messages/MOSDFull.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MOSDFULL_H #define CEPH_MOSDFULL_H #include "messages/PaxosServiceMessage.h" #include "osd/OSDMap.h" // tell the mon to update the full/nearfull bits. note that in the // future this message could be generalized to other state bits, but // for now name it for its sole application. class MOSDFull final : public PaxosServiceMessage { public: epoch_t map_epoch = 0; uint32_t state = 0; private: ~MOSDFull() final {} public: MOSDFull(epoch_t e, unsigned s) : PaxosServiceMessage{MSG_OSD_FULL, e}, map_epoch(e), state(s) { } MOSDFull() : PaxosServiceMessage{MSG_OSD_FULL, 0} {} public: void encode_payload(uint64_t features) { using ceph::encode; paxos_encode(); encode(map_epoch, payload); encode(state, payload); } void decode_payload() { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(map_epoch, p); decode(state, p); } std::string_view get_type_name() const { return "osd_full"; } void print(std::ostream &out) const { std::set<std::string> states; OSDMap::calc_state_set(state, states); out << "osd_full(e" << map_epoch << " " << states << " v" << version << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,419
24.818182
80
h
null
ceph-main/src/messages/MOSDMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDMAP_H #define CEPH_MOSDMAP_H #include "msg/Message.h" #include "osd/OSDMap.h" #include "include/ceph_features.h" class MOSDMap final : public Message { private: static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 3; public: uuid_d fsid; uint64_t encode_features = 0; std::map<epoch_t, ceph::buffer::list> maps; std::map<epoch_t, ceph::buffer::list> incremental_maps; /** * cluster_osdmap_trim_lower_bound * * Encodes a lower bound on the monitor's osdmap trim bound. Recipients * can safely trim up to this bound. The sender stores maps back to * cluster_osdmap_trim_lower_bound. * * This field was formerly named oldest_map and encoded the oldest map * stored by the sender. The primary usage of this field, however, was to * allow the recipient to trim. The secondary usage was to inform the * recipient of how many maps the sender stored in case it needed to request * more. For both purposes, it should be safe for an older OSD to interpret * this field as oldest_map, and it should be safe for a new osd to interpret * the oldest_map field sent by an older osd as * cluster_osdmap_trim_lower_bound. * See bug https://tracker.ceph.com/issues/49689 */ epoch_t cluster_osdmap_trim_lower_bound = 0; epoch_t newest_map = 0; epoch_t get_first() const { epoch_t e = 0; auto i = maps.cbegin(); if (i != maps.cend()) e = i->first; i = incremental_maps.begin(); if (i != incremental_maps.end() && (e == 0 || i->first < e)) e = i->first; return e; } epoch_t get_last() const { epoch_t e = 0; auto i = maps.crbegin(); if (i != maps.crend()) e = i->first; i = incremental_maps.rbegin(); if (i != incremental_maps.rend() && (e == 0 || i->first > e)) e = i->first; return e; } MOSDMap() : Message{CEPH_MSG_OSD_MAP, HEAD_VERSION, COMPAT_VERSION} { } MOSDMap(const uuid_d &f, const uint64_t features) : Message{CEPH_MSG_OSD_MAP, HEAD_VERSION, COMPAT_VERSION}, fsid(f), encode_features(features), cluster_osdmap_trim_lower_bound(0), newest_map(0) { } private: ~MOSDMap() final {} public: // marshalling void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(fsid, p); decode(incremental_maps, p); decode(maps, p); if (header.version >= 2) { decode(cluster_osdmap_trim_lower_bound, p); decode(newest_map, p); } else { cluster_osdmap_trim_lower_bound = 0; newest_map = 0; } if (header.version >= 4) { // removed in octopus mempool::osdmap::map<int64_t,snap_interval_set_t> gap_removed_snaps; decode(gap_removed_snaps, p); } } void encode_payload(uint64_t features) override { using ceph::encode; header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(fsid, payload); if (OSDMap::get_significant_features(encode_features) != OSDMap::get_significant_features(features)) { if ((features & CEPH_FEATURE_PGID64) == 0 || (features & CEPH_FEATURE_PGPOOL3) == 0) { header.version = 1; // old old_client version header.compat_version = 1; } else if ((features & CEPH_FEATURE_OSDENC) == 0) { header.version = 2; // old pg_pool_t header.compat_version = 2; } // reencode maps using old format // // FIXME: this can probably be done more efficiently higher up // the stack, or maybe replaced with something that only // includes the pools the client cares about. for (auto p = incremental_maps.begin(); p != incremental_maps.end(); ++p) { OSDMap::Incremental inc; auto q = p->second.cbegin(); inc.decode(q); // always encode with subset of osdmaps canonical features uint64_t f = inc.encode_features & features; p->second.clear(); if (inc.fullmap.length()) { // embedded full std::map? OSDMap m; m.decode(inc.fullmap); inc.fullmap.clear(); m.encode(inc.fullmap, f | CEPH_FEATURE_RESERVED); } if (inc.crush.length()) { // embedded crush std::map CrushWrapper c; auto p = inc.crush.cbegin(); c.decode(p); inc.crush.clear(); c.encode(inc.crush, f); } inc.encode(p->second, f | CEPH_FEATURE_RESERVED); } for (auto p = maps.begin(); p != maps.end(); ++p) { OSDMap m; m.decode(p->second); // always encode with subset of osdmaps canonical features uint64_t f = m.get_encoding_features() & features; p->second.clear(); m.encode(p->second, f | CEPH_FEATURE_RESERVED); } } encode(incremental_maps, payload); encode(maps, payload); if (header.version >= 2) { encode(cluster_osdmap_trim_lower_bound, payload); encode(newest_map, payload); } if (header.version >= 4) { encode((uint32_t)0, payload); } } std::string_view get_type_name() const override { return "osdmap"; } void print(std::ostream& out) const override { out << "osd_map(" << get_first() << ".." << get_last(); if (cluster_osdmap_trim_lower_bound || newest_map) out << " src has " << cluster_osdmap_trim_lower_bound << ".." << newest_map; out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
5,746
31.106145
81
h
null
ceph-main/src/messages/MOSDMarkMeDead.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "messages/PaxosServiceMessage.h" class MOSDMarkMeDead final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: uuid_d fsid; int32_t target_osd; epoch_t epoch = 0; MOSDMarkMeDead() : PaxosServiceMessage{MSG_OSD_MARK_ME_DEAD, 0, HEAD_VERSION, COMPAT_VERSION} { } MOSDMarkMeDead(const uuid_d &fs, int osd, epoch_t e) : PaxosServiceMessage{MSG_OSD_MARK_ME_DEAD, e, HEAD_VERSION, COMPAT_VERSION}, fsid(fs), target_osd(osd), epoch(e) {} private: ~MOSDMarkMeDead() final {} public: epoch_t get_epoch() const { return epoch; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(target_osd, p); decode(epoch, p); } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(fsid, payload); encode(target_osd, payload, features); encode(epoch, payload); } std::string_view get_type_name() const override { return "MOSDMarkMeDead"; } void print(std::ostream& out) const override { out << "MOSDMarkMeDead(" << "osd." << target_osd << ", epoch " << epoch << ", fsid=" << fsid << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,600
24.015625
78
h
null
ceph-main/src/messages/MOSDMarkMeDown.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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_MOSDMARKMEDOWN_H #define CEPH_MOSDMARKMEDOWN_H #include "messages/PaxosServiceMessage.h" class MOSDMarkMeDown final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 3; public: uuid_d fsid; int32_t target_osd; entity_addrvec_t target_addrs; epoch_t epoch = 0; bool request_ack = false; // ack requested bool down_and_dead = false; // mark down and dead MOSDMarkMeDown() : PaxosServiceMessage{MSG_OSD_MARK_ME_DOWN, 0, HEAD_VERSION, COMPAT_VERSION} { } MOSDMarkMeDown(const uuid_d &fs, int osd, const entity_addrvec_t& av, epoch_t e, bool request_ack) : PaxosServiceMessage{MSG_OSD_MARK_ME_DOWN, e, HEAD_VERSION, COMPAT_VERSION}, fsid(fs), target_osd(osd), target_addrs(av), epoch(e), request_ack(request_ack) {} MOSDMarkMeDown(const uuid_d &fs, int osd, const entity_addrvec_t& av, epoch_t e, bool request_ack, bool down_and_dead) : PaxosServiceMessage{MSG_OSD_MARK_ME_DOWN, e, HEAD_VERSION, COMPAT_VERSION}, fsid(fs), target_osd(osd), target_addrs(av), epoch(e), request_ack(request_ack), down_and_dead(down_and_dead) {} private: ~MOSDMarkMeDown() final {} public: epoch_t get_epoch() const { return epoch; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); assert(header.version >= 3); decode(fsid, p); decode(target_osd, p); decode(target_addrs, p); decode(epoch, p); decode(request_ack, p); if(header.version >= 4) decode(down_and_dead, p); } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); assert(HAVE_FEATURE(features, SERVER_NAUTILUS)); header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(fsid, payload); encode(target_osd, payload, features); encode(target_addrs, payload, features); encode(epoch, payload); encode(request_ack, payload); encode(down_and_dead, payload); } std::string_view get_type_name() const override { return "MOSDMarkMeDown"; } void print(std::ostream& out) const override { out << "MOSDMarkMeDown(" << "request_ack=" << request_ack << ", down_and_dead=" << down_and_dead << ", osd." << target_osd << ", " << target_addrs << ", fsid=" << fsid << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,937
28.979592
78
h
null
ceph-main/src/messages/MOSDOp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDOP_H #define CEPH_MOSDOP_H #include <atomic> #include "MOSDFastDispatchOp.h" #include "include/ceph_features.h" #include "common/hobject.h" /* * OSD op * * oid - object id * op - OSD_OP_DELETE, etc. * */ class MOSDOpReply; namespace _mosdop { template<typename V> class MOSDOp final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 8; static constexpr int COMPAT_VERSION = 3; private: uint32_t client_inc = 0; __u32 osdmap_epoch = 0; __u32 flags = 0; utime_t mtime; int32_t retry_attempt = -1; // 0 is first attempt. -1 if we don't know. hobject_t hobj; spg_t pgid; ceph::buffer::list::const_iterator p; // Decoding flags. Decoding is only needed for messages caught by pipe reader. // Transition from true -> false without locks being held // Can never see final_decode_needed == false and partial_decode_needed == true std::atomic<bool> partial_decode_needed; std::atomic<bool> final_decode_needed; // public: V ops; private: snapid_t snap_seq; std::vector<snapid_t> snaps; uint64_t features; bool bdata_encode; osd_reqid_t reqid; // reqid explicitly set by sender public: friend MOSDOpReply; ceph_tid_t get_client_tid() { return header.tid; } void set_snapid(const snapid_t& s) { hobj.snap = s; } void set_snaps(const std::vector<snapid_t>& i) { snaps = i; } void set_snap_seq(const snapid_t& s) { snap_seq = s; } void set_reqid(const osd_reqid_t rid) { reqid = rid; } void set_spg(spg_t p) { pgid = p; } // Fields decoded in partial decoding pg_t get_pg() const { ceph_assert(!partial_decode_needed); return pgid.pgid; } spg_t get_spg() const override { ceph_assert(!partial_decode_needed); return pgid; } pg_t get_raw_pg() const { ceph_assert(!partial_decode_needed); return pg_t(hobj.get_hash(), pgid.pgid.pool()); } epoch_t get_map_epoch() const override { ceph_assert(!partial_decode_needed); return osdmap_epoch; } int get_flags() const { ceph_assert(!partial_decode_needed); return flags; } osd_reqid_t get_reqid() const { ceph_assert(!partial_decode_needed); if (reqid.name != entity_name_t() || reqid.tid != 0) { return reqid; } else { if (!final_decode_needed) ceph_assert(reqid.inc == (int32_t)client_inc); // decode() should have done this return osd_reqid_t(get_orig_source(), reqid.inc, header.tid); } } // Fields decoded in final decoding int get_client_inc() const { ceph_assert(!final_decode_needed); return client_inc; } utime_t get_mtime() const { ceph_assert(!final_decode_needed); return mtime; } object_locator_t get_object_locator() const { ceph_assert(!final_decode_needed); if (hobj.oid.name.empty()) return object_locator_t(hobj.pool, hobj.nspace, hobj.get_hash()); else return object_locator_t(hobj); } const object_t& get_oid() const { ceph_assert(!final_decode_needed); return hobj.oid; } const hobject_t &get_hobj() const { return hobj; } snapid_t get_snapid() const { ceph_assert(!final_decode_needed); return hobj.snap; } const snapid_t& get_snap_seq() const { ceph_assert(!final_decode_needed); return snap_seq; } const std::vector<snapid_t> &get_snaps() const { ceph_assert(!final_decode_needed); return snaps; } /** * get retry attempt * * 0 is the first attempt. * * @return retry attempt, or -1 if we don't know */ int get_retry_attempt() const { return retry_attempt; } uint64_t get_features() const { if (features) return features; #ifdef WITH_SEASTAR ceph_abort("In crimson, conn is independently maintained outside Message"); #else return get_connection()->get_features(); #endif } MOSDOp() : MOSDFastDispatchOp(CEPH_MSG_OSD_OP, HEAD_VERSION, COMPAT_VERSION), partial_decode_needed(true), final_decode_needed(true), bdata_encode(false) { } MOSDOp(int inc, long tid, const hobject_t& ho, spg_t& _pgid, epoch_t _osdmap_epoch, int _flags, uint64_t feat) : MOSDFastDispatchOp(CEPH_MSG_OSD_OP, HEAD_VERSION, COMPAT_VERSION), client_inc(inc), osdmap_epoch(_osdmap_epoch), flags(_flags), retry_attempt(-1), hobj(ho), pgid(_pgid), partial_decode_needed(false), final_decode_needed(false), features(feat), bdata_encode(false) { set_tid(tid); // also put the client_inc in reqid.inc, so that get_reqid() can // be used before the full message is decoded. reqid.inc = inc; } private: ~MOSDOp() final {} public: void set_mtime(utime_t mt) { mtime = mt; } void set_mtime(ceph::real_time mt) { mtime = ceph::real_clock::to_timespec(mt); } // ops void add_simple_op(int o, uint64_t off, uint64_t len) { OSDOp osd_op; osd_op.op.op = o; osd_op.op.extent.offset = off; osd_op.op.extent.length = len; ops.push_back(osd_op); } void write(uint64_t off, uint64_t len, ceph::buffer::list& bl) { add_simple_op(CEPH_OSD_OP_WRITE, off, len); data = std::move(bl); header.data_off = off; } void writefull(ceph::buffer::list& bl) { add_simple_op(CEPH_OSD_OP_WRITEFULL, 0, bl.length()); data = std::move(bl); header.data_off = 0; } void zero(uint64_t off, uint64_t len) { add_simple_op(CEPH_OSD_OP_ZERO, off, len); } void truncate(uint64_t off) { add_simple_op(CEPH_OSD_OP_TRUNCATE, off, 0); } void remove() { add_simple_op(CEPH_OSD_OP_DELETE, 0, 0); } void read(uint64_t off, uint64_t len) { add_simple_op(CEPH_OSD_OP_READ, off, len); } void stat() { add_simple_op(CEPH_OSD_OP_STAT, 0, 0); } bool has_flag(__u32 flag) const { return flags & flag; }; bool is_retry_attempt() const { return flags & CEPH_OSD_FLAG_RETRY; } void set_retry_attempt(unsigned a) { if (a) flags |= CEPH_OSD_FLAG_RETRY; else flags &= ~CEPH_OSD_FLAG_RETRY; retry_attempt = a; } // marshalling void encode_payload(uint64_t features) override { using ceph::encode; if( false == bdata_encode ) { OSDOp::merge_osd_op_vector_in_data(ops, data); bdata_encode = true; } if ((features & CEPH_FEATURE_OBJECTLOCATOR) == 0) { // here is the old structure we are encoding to: // #if 0 struct ceph_osd_request_head { ceph_le32 client_inc; /* client incarnation */ struct ceph_object_layout layout; /* pgid */ ceph_le32 osdmap_epoch; /* client's osdmap epoch */ ceph_le32 flags; struct ceph_timespec mtime; /* for mutations only */ struct ceph_eversion reassert_version; /* if we are replaying op */ ceph_le32 object_len; /* length of object name */ ceph_le64 snapid; /* snapid to read */ ceph_le64 snap_seq; /* writer's snap context */ ceph_le32 num_snaps; ceph_le16 num_ops; struct ceph_osd_op ops[]; /* followed by ops[], obj, ticket, snaps */ } __attribute__ ((packed)); #endif header.version = 1; encode(client_inc, payload); __u32 su = 0; encode(get_raw_pg(), payload); encode(su, payload); encode(osdmap_epoch, payload); encode(flags, payload); encode(mtime, payload); encode(eversion_t(), payload); // reassert_version __u32 oid_len = hobj.oid.name.length(); encode(oid_len, payload); encode(hobj.snap, payload); encode(snap_seq, payload); __u32 num_snaps = snaps.size(); encode(num_snaps, payload); //::encode(ops, payload); __u16 num_ops = ops.size(); encode(num_ops, payload); for (unsigned i = 0; i < ops.size(); i++) encode(ops[i].op, payload); ceph::encode_nohead(hobj.oid.name, payload); ceph::encode_nohead(snaps, payload); } else if ((features & CEPH_FEATURE_NEW_OSDOP_ENCODING) == 0) { header.version = 6; encode(client_inc, payload); encode(osdmap_epoch, payload); encode(flags, payload); encode(mtime, payload); encode(eversion_t(), payload); // reassert_version encode(get_object_locator(), payload); encode(get_raw_pg(), payload); encode(hobj.oid, payload); __u16 num_ops = ops.size(); encode(num_ops, payload); for (unsigned i = 0; i < ops.size(); i++) encode(ops[i].op, payload); encode(hobj.snap, payload); encode(snap_seq, payload); encode(snaps, payload); encode(retry_attempt, payload); encode(features, payload); if (reqid.name != entity_name_t() || reqid.tid != 0) { encode(reqid, payload); } else { // don't include client_inc in the reqid for the legacy v6 // encoding or else we'll confuse older peers. encode(osd_reqid_t(), payload); } } else if (!HAVE_FEATURE(features, RESEND_ON_SPLIT)) { // reordered, v7 message encoding header.version = 7; encode(get_raw_pg(), payload); encode(osdmap_epoch, payload); encode(flags, payload); encode(eversion_t(), payload); // reassert_version encode(reqid, payload); encode(client_inc, payload); encode(mtime, payload); encode(get_object_locator(), payload); encode(hobj.oid, payload); __u16 num_ops = ops.size(); encode(num_ops, payload); for (unsigned i = 0; i < ops.size(); i++) encode(ops[i].op, payload); encode(hobj.snap, payload); encode(snap_seq, payload); encode(snaps, payload); encode(retry_attempt, payload); encode(features, payload); } else { // latest v8 encoding with hobject_t hash separate from pgid, no // reassert version header.version = HEAD_VERSION; encode(pgid, payload); encode(hobj.get_hash(), payload); encode(osdmap_epoch, payload); encode(flags, payload); encode(reqid, payload); encode_trace(payload, features); // -- above decoded up front; below decoded post-dispatch thread -- encode(client_inc, payload); encode(mtime, payload); encode(get_object_locator(), payload); encode(hobj.oid, payload); __u16 num_ops = ops.size(); encode(num_ops, payload); for (unsigned i = 0; i < ops.size(); i++) encode(ops[i].op, payload); encode(hobj.snap, payload); encode(snap_seq, payload); encode(snaps, payload); encode(retry_attempt, payload); encode(features, payload); } } void decode_payload() override { using ceph::decode; ceph_assert(partial_decode_needed && final_decode_needed); p = std::cbegin(payload); // Always keep here the newest version of decoding order/rule if (header.version == HEAD_VERSION) { decode(pgid, p); // actual pgid uint32_t hash; decode(hash, p); // raw hash value hobj.set_hash(hash); decode(osdmap_epoch, p); decode(flags, p); decode(reqid, p); decode_trace(p); } else if (header.version == 7) { decode(pgid.pgid, p); // raw pgid hobj.set_hash(pgid.pgid.ps()); decode(osdmap_epoch, p); decode(flags, p); eversion_t reassert_version; decode(reassert_version, p); decode(reqid, p); } else if (header.version < 2) { // old decode decode(client_inc, p); old_pg_t opgid; ceph::decode_raw(opgid, p); pgid.pgid = opgid; __u32 su; decode(su, p); decode(osdmap_epoch, p); decode(flags, p); decode(mtime, p); eversion_t reassert_version; decode(reassert_version, p); __u32 oid_len; decode(oid_len, p); decode(hobj.snap, p); decode(snap_seq, p); __u32 num_snaps; decode(num_snaps, p); //::decode(ops, p); __u16 num_ops; decode(num_ops, p); ops.resize(num_ops); for (unsigned i = 0; i < num_ops; i++) decode(ops[i].op, p); ceph::decode_nohead(oid_len, hobj.oid.name, p); ceph::decode_nohead(num_snaps, snaps, p); // recalculate pgid hash value pgid.pgid.set_ps(ceph_str_hash(CEPH_STR_HASH_RJENKINS, hobj.oid.name.c_str(), hobj.oid.name.length())); hobj.pool = pgid.pgid.pool(); hobj.set_hash(pgid.pgid.ps()); retry_attempt = -1; features = 0; OSDOp::split_osd_op_vector_in_data(ops, data); // we did the full decode final_decode_needed = false; // put client_inc in reqid.inc for get_reqid()'s benefit reqid = osd_reqid_t(); reqid.inc = client_inc; } else if (header.version < 7) { decode(client_inc, p); decode(osdmap_epoch, p); decode(flags, p); decode(mtime, p); eversion_t reassert_version; decode(reassert_version, p); object_locator_t oloc; decode(oloc, p); if (header.version < 3) { old_pg_t opgid; ceph::decode_raw(opgid, p); pgid.pgid = opgid; } else { decode(pgid.pgid, p); } decode(hobj.oid, p); //::decode(ops, p); __u16 num_ops; decode(num_ops, p); ops.resize(num_ops); for (unsigned i = 0; i < num_ops; i++) decode(ops[i].op, p); decode(hobj.snap, p); decode(snap_seq, p); decode(snaps, p); if (header.version >= 4) decode(retry_attempt, p); else retry_attempt = -1; if (header.version >= 5) decode(features, p); else features = 0; if (header.version >= 6) decode(reqid, p); else reqid = osd_reqid_t(); hobj.pool = pgid.pgid.pool(); hobj.set_key(oloc.key); hobj.nspace = oloc.nspace; hobj.set_hash(pgid.pgid.ps()); OSDOp::split_osd_op_vector_in_data(ops, data); // we did the full decode final_decode_needed = false; // put client_inc in reqid.inc for get_reqid()'s benefit if (reqid.name == entity_name_t() && reqid.tid == 0) reqid.inc = client_inc; } partial_decode_needed = false; } bool finish_decode() { using ceph::decode; ceph_assert(!partial_decode_needed); // partial decoding required if (!final_decode_needed) return false; // Message is already final decoded ceph_assert(header.version >= 7); decode(client_inc, p); decode(mtime, p); object_locator_t oloc; decode(oloc, p); decode(hobj.oid, p); __u16 num_ops; decode(num_ops, p); ops.resize(num_ops); for (unsigned i = 0; i < num_ops; i++) decode(ops[i].op, p); decode(hobj.snap, p); decode(snap_seq, p); decode(snaps, p); decode(retry_attempt, p); decode(features, p); hobj.pool = pgid.pgid.pool(); hobj.set_key(oloc.key); hobj.nspace = oloc.nspace; OSDOp::split_osd_op_vector_in_data(ops, data); final_decode_needed = false; return true; } void clear_buffers() override { OSDOp::clear_data(ops); bdata_encode = false; } std::string_view get_type_name() const override { return "osd_op"; } void print(std::ostream& out) const override { out << "osd_op("; if (!partial_decode_needed) { out << get_reqid() << ' '; out << pgid; if (!final_decode_needed) { out << ' '; out << hobj << " " << ops << " snapc " << get_snap_seq() << "=" << snaps; if (is_retry_attempt()) out << " RETRY=" << get_retry_attempt(); } else { out << " " << get_raw_pg() << " (undecoded)"; } out << " " << ceph_osd_flag_string(get_flags()); out << " e" << osdmap_epoch; } out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; } using MOSDOp = _mosdop::MOSDOp<std::vector<OSDOp>>; #endif
16,164
25.37031
82
h
null
ceph-main/src/messages/MOSDOpReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDOPREPLY_H #define CEPH_MOSDOPREPLY_H #include "msg/Message.h" #include "MOSDOp.h" #include "common/errno.h" /* * OSD op reply * * oid - object id * op - OSD_OP_DELETE, etc. * */ class MOSDOpReply final : public Message { private: static constexpr int HEAD_VERSION = 8; static constexpr int COMPAT_VERSION = 2; object_t oid; pg_t pgid; std::vector<OSDOp> ops; bool bdata_encode; int64_t flags = 0; errorcode32_t result; eversion_t bad_replay_version; eversion_t replay_version; version_t user_version = 0; epoch_t osdmap_epoch = 0; int32_t retry_attempt = -1; bool do_redirect; request_redirect_t redirect; public: const object_t& get_oid() const { return oid; } const pg_t& get_pg() const { return pgid; } int get_flags() const { return flags; } bool is_ondisk() const { return get_flags() & CEPH_OSD_FLAG_ONDISK; } bool is_onnvram() const { return get_flags() & CEPH_OSD_FLAG_ONNVRAM; } int get_result() const { return result; } const eversion_t& get_replay_version() const { return replay_version; } const version_t& get_user_version() const { return user_version; } void set_result(int r) { result = r; } void set_reply_versions(eversion_t v, version_t uv) { replay_version = v; user_version = uv; /* We go through some shenanigans here for backwards compatibility * with old clients, who do not look at our replay_version and * user_version but instead see what we now call the * bad_replay_version. On pools without caching * the user_version infrastructure is a slightly-laggy copy of * the regular pg version/at_version infrastructure; the difference * being it is not updated on watch ops like that is -- but on updates * it is set equal to at_version. This means that for non-watch write ops * on classic pools, all three of replay_version, user_version, and * bad_replay_version are identical. But for watch ops the replay_version * has been updated, while the user_at_version has not, and the semantics * we promised old clients are that the version they see is not an update. * So set the bad_replay_version to be the same as the user_at_version. */ bad_replay_version = v; if (uv) { bad_replay_version.version = uv; } } /* Don't fill in replay_version for non-write ops */ void set_enoent_reply_versions(const eversion_t& v, const version_t& uv) { user_version = uv; bad_replay_version = v; } void set_redirect(const request_redirect_t& redir) { redirect = redir; } const request_redirect_t& get_redirect() const { return redirect; } bool is_redirect_reply() const { return do_redirect; } void add_flags(int f) { flags |= f; } void claim_op_out_data(std::vector<OSDOp>& o) { ceph_assert(ops.size() == o.size()); for (unsigned i = 0; i < o.size(); i++) { ops[i].outdata = std::move(o[i].outdata); } } void claim_ops(std::vector<OSDOp>& o) { o.swap(ops); bdata_encode = false; } void set_op_returns(const std::vector<pg_log_op_return_item_t>& op_returns) { if (op_returns.size()) { ceph_assert(ops.empty() || ops.size() == op_returns.size()); ops.resize(op_returns.size()); for (unsigned i = 0; i < op_returns.size(); ++i) { ops[i].rval = op_returns[i].rval; ops[i].outdata = op_returns[i].bl; } } } /** * get retry attempt * * If we don't know the attempt (because the server is old), return -1. */ int get_retry_attempt() const { return retry_attempt; } // osdmap epoch_t get_map_epoch() const { return osdmap_epoch; } /*osd_reqid_t get_reqid() { return osd_reqid_t(get_dest(), head.client_inc, head.tid); } */ public: MOSDOpReply() : Message{CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION}, bdata_encode(false) { do_redirect = false; } MOSDOpReply(const MOSDOp *req, int r, epoch_t e, int acktype, bool ignore_out_data) : Message{CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION}, oid(req->hobj.oid), pgid(req->pgid.pgid), ops(req->ops), bdata_encode(false) { set_tid(req->get_tid()); result = r; flags = (req->flags & ~(CEPH_OSD_FLAG_ONDISK|CEPH_OSD_FLAG_ONNVRAM|CEPH_OSD_FLAG_ACK)) | acktype; osdmap_epoch = e; user_version = 0; retry_attempt = req->get_retry_attempt(); do_redirect = false; for (unsigned i = 0; i < ops.size(); i++) { // zero out input data ops[i].indata.clear(); if (ignore_out_data) { // original request didn't set the RETURNVEC flag ops[i].outdata.clear(); } } } private: ~MOSDOpReply() final {} public: void encode_payload(uint64_t features) override { using ceph::encode; if(false == bdata_encode) { OSDOp::merge_osd_op_vector_out_data(ops, data); bdata_encode = true; } if ((features & CEPH_FEATURE_PGID64) == 0) { header.version = 1; ceph_osd_reply_head head; memset(&head, 0, sizeof(head)); head.layout.ol_pgid = pgid.get_old_pg().v; head.flags = flags; head.osdmap_epoch = osdmap_epoch; head.reassert_version = bad_replay_version; head.result = result; head.num_ops = ops.size(); head.object_len = oid.name.length(); encode(head, payload); for (unsigned i = 0; i < head.num_ops; i++) { encode(ops[i].op, payload); } ceph::encode_nohead(oid.name, payload); } else { header.version = HEAD_VERSION; encode(oid, payload); encode(pgid, payload); encode(flags, payload); encode(result, payload); encode(bad_replay_version, payload); encode(osdmap_epoch, payload); __u32 num_ops = ops.size(); encode(num_ops, payload); for (unsigned i = 0; i < num_ops; i++) encode(ops[i].op, payload); encode(retry_attempt, payload); for (unsigned i = 0; i < num_ops; i++) encode(ops[i].rval, payload); encode(replay_version, payload); encode(user_version, payload); if ((features & CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING) == 0) { header.version = 6; encode(redirect, payload); } else { do_redirect = !redirect.empty(); encode(do_redirect, payload); if (do_redirect) { encode(redirect, payload); } } encode_trace(payload, features); } } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); // Always keep here the newest version of decoding order/rule if (header.version == HEAD_VERSION) { decode(oid, p); decode(pgid, p); decode(flags, p); decode(result, p); decode(bad_replay_version, p); decode(osdmap_epoch, p); __u32 num_ops = ops.size(); decode(num_ops, p); ops.resize(num_ops); for (unsigned i = 0; i < num_ops; i++) decode(ops[i].op, p); decode(retry_attempt, p); for (unsigned i = 0; i < num_ops; ++i) decode(ops[i].rval, p); OSDOp::split_osd_op_vector_out_data(ops, data); decode(replay_version, p); decode(user_version, p); decode(do_redirect, p); if (do_redirect) decode(redirect, p); decode_trace(p); } else if (header.version < 2) { ceph_osd_reply_head head; decode(head, p); ops.resize(head.num_ops); for (unsigned i = 0; i < head.num_ops; i++) { decode(ops[i].op, p); } ceph::decode_nohead(head.object_len, oid.name, p); pgid = pg_t(head.layout.ol_pgid); result = (int32_t)head.result; flags = head.flags; replay_version = head.reassert_version; user_version = replay_version.version; osdmap_epoch = head.osdmap_epoch; retry_attempt = -1; } else { decode(oid, p); decode(pgid, p); decode(flags, p); decode(result, p); decode(bad_replay_version, p); decode(osdmap_epoch, p); __u32 num_ops = ops.size(); decode(num_ops, p); ops.resize(num_ops); for (unsigned i = 0; i < num_ops; i++) decode(ops[i].op, p); if (header.version >= 3) decode(retry_attempt, p); else retry_attempt = -1; if (header.version >= 4) { for (unsigned i = 0; i < num_ops; ++i) decode(ops[i].rval, p); OSDOp::split_osd_op_vector_out_data(ops, data); } if (header.version >= 5) { decode(replay_version, p); decode(user_version, p); } else { replay_version = bad_replay_version; user_version = replay_version.version; } if (header.version == 6) { decode(redirect, p); do_redirect = !redirect.empty(); } if (header.version >= 7) { decode(do_redirect, p); if (do_redirect) { decode(redirect, p); } } if (header.version >= 8) { decode_trace(p); } } } std::string_view get_type_name() const override { return "osd_op_reply"; } void print(std::ostream& out) const override { out << "osd_op_reply(" << get_tid() << " " << oid << " " << ops << " v" << get_replay_version() << " uv" << get_user_version(); if (is_ondisk()) out << " ondisk"; else if (is_onnvram()) out << " onnvram"; else out << " ack"; out << " = " << get_result(); if (get_result() < 0) { out << " (" << cpp_strerror(get_result()) << ")"; } if (is_redirect_reply()) { out << " redirect: { " << redirect << " }"; } out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
10,058
27.415254
95
h
null
ceph-main/src/messages/MOSDPGBackfill.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGBACKFILL_H #define CEPH_MOSDPGBACKFILL_H #include "MOSDFastDispatchOp.h" class MOSDPGBackfill final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 3; public: enum { OP_BACKFILL_PROGRESS = 2, OP_BACKFILL_FINISH = 3, OP_BACKFILL_FINISH_ACK = 4, }; const char *get_op_name(int o) const { switch (o) { case OP_BACKFILL_PROGRESS: return "progress"; case OP_BACKFILL_FINISH: return "finish"; case OP_BACKFILL_FINISH_ACK: return "finish_ack"; default: return "???"; } } __u32 op = 0; epoch_t map_epoch = 0, query_epoch = 0; spg_t pgid; hobject_t last_backfill; pg_stat_t stats; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return query_epoch; } spg_t get_spg() const override { return pgid; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(op, p); decode(map_epoch, p); decode(query_epoch, p); decode(pgid.pgid, p); decode(last_backfill, p); // For compatibility with version 1 decode(stats.stats, p); decode(stats, p); // Handle hobject_t format change if (!last_backfill.is_max() && last_backfill.pool == -1) last_backfill.pool = pgid.pool(); decode(pgid.shard, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(op, payload); encode(map_epoch, payload); encode(query_epoch, payload); encode(pgid.pgid, payload); encode(last_backfill, payload); // For compatibility with version 1 encode(stats.stats, payload); encode(stats, payload); encode(pgid.shard, payload); } MOSDPGBackfill() : MOSDFastDispatchOp{MSG_OSD_PG_BACKFILL, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGBackfill(__u32 o, epoch_t e, epoch_t qe, spg_t p) : MOSDFastDispatchOp{MSG_OSD_PG_BACKFILL, HEAD_VERSION, COMPAT_VERSION}, op(o), map_epoch(e), query_epoch(e), pgid(p) {} private: ~MOSDPGBackfill() final {} public: std::string_view get_type_name() const override { return "pg_backfill"; } void print(std::ostream& out) const override { out << "pg_backfill(" << get_op_name(op) << " " << pgid << " e " << map_epoch << "/" << query_epoch << " lb " << last_backfill << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,955
24.050847
78
h
null
ceph-main/src/messages/MOSDPGBackfillRemove.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 Sage Weil <[email protected]> * * 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_MOSDPGBACKFILLREMOVE_H #define CEPH_MOSDPGBACKFILLREMOVE_H #include "MOSDFastDispatchOp.h" /* * instruct non-primary to remove some objects during backfill */ class MOSDPGBackfillRemove final : public MOSDFastDispatchOp { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; spg_t pgid; ///< target spg_t epoch_t map_epoch = 0; std::list<std::pair<hobject_t,eversion_t>> ls; ///< objects to remove epoch_t get_map_epoch() const override { return map_epoch; } spg_t get_spg() const override { return pgid; } MOSDPGBackfillRemove() : MOSDFastDispatchOp{MSG_OSD_PG_BACKFILL_REMOVE, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGBackfillRemove(spg_t pgid, epoch_t map_epoch) : MOSDFastDispatchOp{MSG_OSD_PG_BACKFILL_REMOVE, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid), map_epoch(map_epoch) {} private: ~MOSDPGBackfillRemove() final {} public: std::string_view get_type_name() const override { return "backfill_remove"; } void print(std::ostream& out) const override { out << "backfill_remove(" << pgid << " e" << map_epoch << " " << ls << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(ls, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(ls, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,051
24.333333
79
h
null
ceph-main/src/messages/MOSDPGCreate2.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" #include "osd/osd_types.h" /* * PGCreate2 - instruct an OSD to create some pgs */ class MOSDPGCreate2 final : public Message { public: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; epoch_t epoch = 0; std::map<spg_t,std::pair<epoch_t,utime_t>> pgs; std::map<spg_t,std::pair<pg_history_t,PastIntervals>> pg_extra; MOSDPGCreate2() : Message{MSG_OSD_PG_CREATE2, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGCreate2(epoch_t e) : Message{MSG_OSD_PG_CREATE2, HEAD_VERSION, COMPAT_VERSION}, epoch(e) { } private: ~MOSDPGCreate2() final {} public: std::string_view get_type_name() const override { return "pg_create2"; } void print(std::ostream& out) const override { out << "pg_create2(e" << epoch << " " << pgs << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(pgs, payload); encode(pg_extra, payload); } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; decode(epoch, p); decode(pgs, p); if (header.version >= 2) { decode(pg_extra, p); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,418
23.894737
70
h
null
ceph-main/src/messages/MOSDPGCreated.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "osd/osd_types.h" #include "messages/PaxosServiceMessage.h" class MOSDPGCreated : public PaxosServiceMessage { public: pg_t pgid; MOSDPGCreated() : PaxosServiceMessage{MSG_OSD_PG_CREATED, 0} {} MOSDPGCreated(pg_t pgid) : PaxosServiceMessage{MSG_OSD_PG_CREATED, 0}, pgid(pgid) {} std::string_view get_type_name() const override { return "pg_created"; } void print(std::ostream& out) const override { out << "osd_pg_created(" << pgid << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(pgid, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(pgid, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
981
24.842105
74
h
null
ceph-main/src/messages/MOSDPGInfo.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGINFO_H #define CEPH_MOSDPGINFO_H #include "msg/Message.h" #include "osd/osd_types.h" class MOSDPGInfo final : public Message { private: static constexpr int HEAD_VERSION = 6; static constexpr int COMPAT_VERSION = 6; epoch_t epoch = 0; public: using pg_list_t = std::vector<pg_notify_t>; pg_list_t pg_list; epoch_t get_epoch() const { return epoch; } MOSDPGInfo() : MOSDPGInfo{0, {}} {} MOSDPGInfo(epoch_t mv) : MOSDPGInfo(mv, {}) {} MOSDPGInfo(epoch_t mv, pg_list_t&& l) : Message{MSG_OSD_PG_INFO, HEAD_VERSION, COMPAT_VERSION}, epoch{mv}, pg_list{std::move(l)} { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGInfo() final {} public: std::string_view get_type_name() const override { return "pg_info"; } void print(std::ostream& out) const override { out << "pg_info("; for (auto i = pg_list.begin(); i != pg_list.end(); ++i) { if (i != pg_list.begin()) out << " "; out << *i; } out << " epoch " << epoch << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; header.version = HEAD_VERSION; encode(epoch, payload); assert(HAVE_FEATURE(features, SERVER_OCTOPUS)); encode(pg_list, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(pg_list, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,980
22.305882
71
h
null
ceph-main/src/messages/MOSDPGInfo2.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MOSDPGInfo2 final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: spg_t spgid; epoch_t epoch_sent; epoch_t min_epoch; pg_info_t info; std::optional<pg_lease_t> lease; std::optional<pg_lease_ack_t> lease_ack; spg_t get_spg() const override { return spgid; } epoch_t get_map_epoch() const override { return epoch_sent; } epoch_t get_min_epoch() const override { return min_epoch; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( epoch_sent, min_epoch, MInfoRec( pg_shard_t(get_source().num(), info.pgid.shard), info, epoch_sent, lease, lease_ack)); } MOSDPGInfo2() : MOSDPeeringOp{MSG_OSD_PG_INFO2, HEAD_VERSION, COMPAT_VERSION} { set_priority(CEPH_MSG_PRIO_HIGH); } MOSDPGInfo2( spg_t s, pg_info_t q, epoch_t sent, epoch_t min, std::optional<pg_lease_t> l, std::optional<pg_lease_ack_t> la) : MOSDPeeringOp{MSG_OSD_PG_INFO2, HEAD_VERSION, COMPAT_VERSION}, spgid(s), epoch_sent(sent), min_epoch(min), info(q), lease(l), lease_ack(la) { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGInfo2() final {} public: std::string_view get_type_name() const override { return "pg_info2"; } void inner_print(std::ostream& out) const override { out << spgid << " " << info; } void encode_payload(uint64_t features) override { using ceph::encode; encode(spgid, payload); encode(epoch_sent, payload); encode(min_epoch, payload); encode(info, payload); encode(lease, payload); encode(lease_ack, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(spgid, p); decode(epoch_sent, p); decode(min_epoch, p); decode(info, p); decode(lease, p); decode(lease_ack, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
2,246
21.69697
70
h
null
ceph-main/src/messages/MOSDPGLease.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" #include "osd/osd_types.h" class MOSDPGLease final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; epoch_t epoch = 0; spg_t spgid; pg_lease_t lease; public: spg_t get_spg() const { return spgid; } epoch_t get_map_epoch() const { return epoch; } epoch_t get_min_epoch() const { return epoch; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( epoch, epoch, MLease(epoch, get_source().num(), lease)); } MOSDPGLease() : MOSDPeeringOp{MSG_OSD_PG_LEASE, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGLease(version_t mv, spg_t p, pg_lease_t lease) : MOSDPeeringOp{MSG_OSD_PG_LEASE, HEAD_VERSION, COMPAT_VERSION}, epoch(mv), spgid(p), lease(lease) { } private: ~MOSDPGLease() final {} public: std::string_view get_type_name() const override { return "pg_lease"; } void inner_print(std::ostream& out) const override { out << lease; } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(spgid, payload); encode(lease, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(spgid, p); decode(lease, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,589
22.043478
72
h
null
ceph-main/src/messages/MOSDPGLeaseAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" #include "osd/osd_types.h" class MOSDPGLeaseAck final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; epoch_t epoch = 0; spg_t spgid; pg_lease_ack_t lease_ack; public: spg_t get_spg() const { return spgid; } epoch_t get_map_epoch() const { return epoch; } epoch_t get_min_epoch() const { return epoch; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( epoch, epoch, MLeaseAck(epoch, get_source().num(), lease_ack)); } MOSDPGLeaseAck() : MOSDPeeringOp{MSG_OSD_PG_LEASE_ACK, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGLeaseAck(version_t mv, spg_t p, pg_lease_ack_t lease_ack) : MOSDPeeringOp{MSG_OSD_PG_LEASE_ACK, HEAD_VERSION, COMPAT_VERSION}, epoch(mv), spgid(p), lease_ack(lease_ack) { } private: ~MOSDPGLeaseAck() final {} public: std::string_view get_type_name() const override { return "pg_lease_ack"; } void inner_print(std::ostream& out) const override { out << lease_ack; } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(spgid, payload); encode(lease_ack, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(spgid, p); decode(lease_ack, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,659
23.057971
76
h
null
ceph-main/src/messages/MOSDPGLog.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGLOG_H #define CEPH_MOSDPGLOG_H #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MOSDPGLog final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 6; static constexpr int COMPAT_VERSION = 6; epoch_t epoch = 0; /// query_epoch is the epoch of the query being responded to, or /// the current epoch if this is not being sent in response to a /// query. This allows the recipient to disregard responses to old /// queries. epoch_t query_epoch = 0; public: shard_id_t to; shard_id_t from; pg_info_t info; pg_log_t log; pg_missing_t missing; PastIntervals past_intervals; std::optional<pg_lease_t> lease; epoch_t get_epoch() const { return epoch; } spg_t get_pgid() const { return spg_t(info.pgid.pgid, to); } epoch_t get_query_epoch() const { return query_epoch; } spg_t get_spg() const override { return spg_t(info.pgid.pgid, to); } epoch_t get_map_epoch() const override { return epoch; } epoch_t get_min_epoch() const override { return query_epoch; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( epoch, query_epoch, MLogRec(pg_shard_t(get_source().num(), from), this), true, new PGCreateInfo( get_spg(), query_epoch, info.history, past_intervals, false)); } MOSDPGLog() : MOSDPeeringOp{MSG_OSD_PG_LOG, HEAD_VERSION, COMPAT_VERSION} { set_priority(CEPH_MSG_PRIO_HIGH); } MOSDPGLog(shard_id_t to, shard_id_t from, version_t mv, const pg_info_t& i, epoch_t query_epoch) : MOSDPeeringOp{MSG_OSD_PG_LOG, HEAD_VERSION, COMPAT_VERSION}, epoch(mv), query_epoch(query_epoch), to(to), from(from), info(i) { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGLog() final {} public: std::string_view get_type_name() const override { return "PGlog"; } void inner_print(std::ostream& out) const override { // NOTE: log is not const, but operator<< doesn't touch fields // swapped out by OSD code. out << "log " << log << " pi " << past_intervals; if (lease) { out << " " << *lease; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(info, payload); encode(log, payload); encode(missing, payload, features); assert(HAVE_FEATURE(features, SERVER_NAUTILUS)); encode(query_epoch, payload); encode(past_intervals, payload); encode(to, payload); encode(from, payload); encode(lease, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(info, p); log.decode(p, info.pgid.pool()); missing.decode(p, info.pgid.pool()); decode(query_epoch, p); decode(past_intervals, p); decode(to, p); decode(from, p); assert(header.version >= 6); decode(lease, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
3,482
25.587786
77
h
null
ceph-main/src/messages/MOSDPGNotify.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGPEERNOTIFY_H #define CEPH_MOSDPGPEERNOTIFY_H #include "msg/Message.h" #include "osd/osd_types.h" /* * PGNotify - notify primary of my PGs and versions. */ class MOSDPGNotify final : public Message { private: static constexpr int HEAD_VERSION = 7; static constexpr int COMPAT_VERSION = 7; epoch_t epoch = 0; /// query_epoch is the epoch of the query being responded to, or /// the current epoch if this is not being sent in response to a /// query. This allows the recipient to disregard responses to old /// queries. using pg_list_t = std::vector<pg_notify_t>; pg_list_t pg_list; public: version_t get_epoch() const { return epoch; } const pg_list_t& get_pg_list() const { return pg_list; } MOSDPGNotify() : MOSDPGNotify(0, {}) {} MOSDPGNotify(epoch_t e, pg_list_t&& l) : Message{MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION}, epoch(e), pg_list(std::move(l)) { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGNotify() final {} public: std::string_view get_type_name() const override { return "PGnot"; } void encode_payload(uint64_t features) override { using ceph::encode; header.version = HEAD_VERSION; encode(epoch, payload); assert(HAVE_FEATURE(features, SERVER_OCTOPUS)); encode(pg_list, payload); } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; decode(epoch, p); decode(pg_list, p); } void print(std::ostream& out) const override { out << "pg_notify("; for (auto i = pg_list.begin(); i != pg_list.end(); ++i) { if (i != pg_list.begin()) out << " "; out << *i; } out << " epoch " << epoch << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,294
23.945652
71
h
null
ceph-main/src/messages/MOSDPGNotify2.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MOSDPGNotify2 final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: spg_t spgid; pg_notify_t notify; spg_t get_spg() const override { return spgid; } epoch_t get_map_epoch() const override { return notify.epoch_sent; } epoch_t get_min_epoch() const override { return notify.query_epoch; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( notify.epoch_sent, notify.query_epoch, MNotifyRec( spgid, pg_shard_t(get_source().num(), notify.from), notify, #ifdef WITH_SEASTAR features #else get_connection()->get_features() #endif ), true, new PGCreateInfo( spgid, notify.epoch_sent, notify.info.history, notify.past_intervals, false)); } MOSDPGNotify2() : MOSDPeeringOp{MSG_OSD_PG_NOTIFY2, HEAD_VERSION, COMPAT_VERSION} { set_priority(CEPH_MSG_PRIO_HIGH); } MOSDPGNotify2( spg_t s, pg_notify_t n) : MOSDPeeringOp{MSG_OSD_PG_NOTIFY2, HEAD_VERSION, COMPAT_VERSION}, spgid(s), notify(n) { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGNotify2() final {} public: std::string_view get_type_name() const override { return "pg_notify2"; } void inner_print(std::ostream& out) const override { out << spgid << " " << notify; } void encode_payload(uint64_t features) override { using ceph::encode; encode(spgid, payload); encode(notify, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(spgid, p); decode(notify, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,949
20.666667
70
h
null
ceph-main/src/messages/MOSDPGPull.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDPGPULL_H #define MOSDPGPULL_H #include "MOSDFastDispatchOp.h" class MOSDPGPull : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 2; std::vector<PullOp> pulls; public: pg_shard_t from; spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; uint64_t cost = 0; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } std::vector<PullOp> take_pulls() { return std::move(pulls); } void set_pulls(std::vector<PullOp>&& pull_ops) { pulls = std::move(pull_ops); } MOSDPGPull() : MOSDFastDispatchOp{MSG_OSD_PG_PULL, HEAD_VERSION, COMPAT_VERSION} {} void compute_cost(CephContext *cct) { cost = 0; for (auto i = pulls.begin(); i != pulls.end(); ++i) { cost += i->cost(cct); } } int get_cost() const override { return cost; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid.pgid, p); decode(map_epoch, p); decode(pulls, p); decode(cost, p); decode(pgid.shard, p); decode(from, p); if (header.version >= 3) { decode(min_epoch, p); } else { min_epoch = map_epoch; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid.pgid, payload); encode(map_epoch, payload); encode(pulls, payload, features); encode(cost, payload); encode(pgid.shard, payload); encode(from, payload); encode(min_epoch, payload); } std::string_view get_type_name() const override { return "MOSDPGPull"; } void print(std::ostream& out) const override { out << "MOSDPGPull(" << pgid << " e" << map_epoch << "/" << min_epoch << " cost " << cost << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,426
21.682243
74
h
null
ceph-main/src/messages/MOSDPGPush.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDPGPUSH_H #define MOSDPGPUSH_H #include "MOSDFastDispatchOp.h" class MOSDPGPush : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 2; public: pg_shard_t from; spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; std::vector<PushOp> pushes; bool is_repair = false; private: uint64_t cost = 0; public: void compute_cost(CephContext *cct) { cost = 0; for (auto i = pushes.begin(); i != pushes.end(); ++i) { cost += i->cost(cct); } } int get_cost() const override { return cost; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } void set_cost(uint64_t c) { cost = c; } MOSDPGPush() : MOSDFastDispatchOp{MSG_OSD_PG_PUSH, HEAD_VERSION, COMPAT_VERSION} {} void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid.pgid, p); decode(map_epoch, p); decode(pushes, p); decode(cost, p); decode(pgid.shard, p); decode(from, p); if (header.version >= 3) { decode(min_epoch, p); } else { min_epoch = map_epoch; } if (header.version >= 4) { decode(is_repair, p); } else { is_repair = false; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid.pgid, payload); encode(map_epoch, payload); encode(pushes, payload, features); encode(cost, payload); encode(pgid.shard, payload); encode(from, payload); encode(min_epoch, payload); encode(is_repair, payload); } std::string_view get_type_name() const override { return "MOSDPGPush"; } void print(std::ostream& out) const override { out << "MOSDPGPush(" << pgid << " " << map_epoch << "/" << min_epoch << " " << pushes; out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,503
21.159292
74
h
null
ceph-main/src/messages/MOSDPGPushReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank Storage, Inc. * * 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 MOSDPGPUSHREPLY_H #define MOSDPGPUSHREPLY_H #include "MOSDFastDispatchOp.h" class MOSDPGPushReply : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 2; public: pg_shard_t from; spg_t pgid; epoch_t map_epoch = 0, min_epoch = 0; std::vector<PushReplyOp> replies; uint64_t cost = 0; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDPGPushReply() : MOSDFastDispatchOp{MSG_OSD_PG_PUSH_REPLY, HEAD_VERSION, COMPAT_VERSION} {} void compute_cost(CephContext *cct) { cost = 0; for (auto i = replies.begin(); i != replies.end(); ++i) { cost += i->cost(cct); } } int get_cost() const override { return cost; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid.pgid, p); decode(map_epoch, p); decode(replies, p); decode(cost, p); decode(pgid.shard, p); decode(from, p); if (header.version >= 3) { decode(min_epoch, p); } else { min_epoch = map_epoch; } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid.pgid, payload); encode(map_epoch, payload); encode(replies, payload); encode(cost, payload); encode(pgid.shard, payload); encode(from, payload); encode(min_epoch, payload); } void print(std::ostream& out) const override { out << "MOSDPGPushReply(" << pgid << " " << map_epoch << "/" << min_epoch << " " << replies; out << ")"; } std::string_view get_type_name() const override { return "MOSDPGPushReply"; } }; #endif
2,197
22.136842
79
h
null
ceph-main/src/messages/MOSDPGQuery.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGQUERY_H #define CEPH_MOSDPGQUERY_H #include "common/hobject.h" #include "msg/Message.h" /* * PGQuery - query another OSD as to the contents of their PGs */ class MOSDPGQuery final : public Message { private: static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 4; version_t epoch = 0; public: version_t get_epoch() const { return epoch; } using pg_list_t = std::map<spg_t, pg_query_t>; pg_list_t pg_list; MOSDPGQuery() : Message{MSG_OSD_PG_QUERY, HEAD_VERSION, COMPAT_VERSION} { set_priority(CEPH_MSG_PRIO_HIGH); } MOSDPGQuery(epoch_t e, pg_list_t&& ls) : Message{MSG_OSD_PG_QUERY, HEAD_VERSION, COMPAT_VERSION}, epoch(e), pg_list(std::move(ls)) { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGQuery() final {} public: std::string_view get_type_name() const override { return "pg_query"; } void print(std::ostream& out) const override { out << "pg_query("; for (auto p = pg_list.begin(); p != pg_list.end(); ++p) { if (p != pg_list.begin()) out << ","; out << p->first; } out << " epoch " << epoch << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(pg_list, payload, features); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(pg_list, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,012
23.253012
72
h
null
ceph-main/src/messages/MOSDPGQuery2.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MOSDPGQuery2 final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: spg_t spgid; pg_query_t query; spg_t get_spg() const override { return spgid; } epoch_t get_map_epoch() const override { return query.epoch_sent; } epoch_t get_min_epoch() const override { return query.epoch_sent; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( query.epoch_sent, query.epoch_sent, MQuery( spgid, pg_shard_t(get_source().num(), query.from), query, query.epoch_sent), false); } MOSDPGQuery2() : MOSDPeeringOp{MSG_OSD_PG_QUERY2, HEAD_VERSION, COMPAT_VERSION} { set_priority(CEPH_MSG_PRIO_HIGH); } MOSDPGQuery2( spg_t s, pg_query_t q) : MOSDPeeringOp{MSG_OSD_PG_QUERY2, HEAD_VERSION, COMPAT_VERSION}, spgid(s), query(q) { set_priority(CEPH_MSG_PRIO_HIGH); } private: ~MOSDPGQuery2() final {} public: std::string_view get_type_name() const override { return "pg_query2"; } void inner_print(std::ostream& out) const override { out << spgid << " " << query; } void encode_payload(uint64_t features) override { using ceph::encode; encode(spgid, payload); encode(query, payload, features); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(spgid, p); decode(query, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,761
21.303797
70
h
null
ceph-main/src/messages/MOSDPGReadyToMerge.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once class MOSDPGReadyToMerge : public PaxosServiceMessage { public: pg_t pgid; eversion_t source_version, target_version; epoch_t last_epoch_started = 0; epoch_t last_epoch_clean = 0; bool ready = true; MOSDPGReadyToMerge() : PaxosServiceMessage{MSG_OSD_PG_READY_TO_MERGE, 0} {} MOSDPGReadyToMerge(pg_t p, eversion_t sv, eversion_t tv, epoch_t les, epoch_t lec, bool r, epoch_t v) : PaxosServiceMessage{MSG_OSD_PG_READY_TO_MERGE, v}, pgid(p), source_version(sv), target_version(tv), last_epoch_started(les), last_epoch_clean(lec), ready(r) {} void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(pgid, payload); encode(source_version, payload); encode(target_version, payload); encode(last_epoch_started, payload); encode(last_epoch_clean, payload); encode(ready, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(pgid, p); decode(source_version, p); decode(target_version, p); decode(last_epoch_started, p); decode(last_epoch_clean, p); decode(ready, p); } std::string_view get_type_name() const override { return "osd_pg_ready_to_merge"; } void print(std::ostream &out) const { out << get_type_name() << "(" << pgid << " sv " << source_version << " tv " << target_version << " les/c " << last_epoch_started << "/" << last_epoch_clean << (ready ? " ready" : " NOT READY") << " v" << version << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,812
28.241935
85
h
null
ceph-main/src/messages/MOSDPGRecoveryDelete.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MOSDPGRECOVERYDELETE_H #define CEPH_MOSDPGRECOVERYDELETE_H #include "MOSDFastDispatchOp.h" /* * instruct non-primary to remove some objects during recovery */ class MOSDPGRecoveryDelete final : public MOSDFastDispatchOp { public: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; pg_shard_t from; spg_t pgid; ///< target spg_t epoch_t map_epoch, min_epoch; std::list<std::pair<hobject_t, eversion_t>> objects; ///< objects to remove private: uint64_t cost = 0; public: int get_cost() const override { return cost; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } void set_cost(uint64_t c) { cost = c; } MOSDPGRecoveryDelete() : MOSDFastDispatchOp{MSG_OSD_PG_RECOVERY_DELETE, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGRecoveryDelete(pg_shard_t from, spg_t pgid, epoch_t map_epoch, epoch_t min_epoch) : MOSDFastDispatchOp{MSG_OSD_PG_RECOVERY_DELETE, HEAD_VERSION, COMPAT_VERSION}, from(from), pgid(pgid), map_epoch(map_epoch), min_epoch(min_epoch) {} private: ~MOSDPGRecoveryDelete() final {} public: std::string_view get_type_name() const { return "recovery_delete"; } void print(std::ostream& out) const { out << "MOSDPGRecoveryDelete(" << pgid << " e" << map_epoch << "," << min_epoch << " " << objects << ")"; } void encode_payload(uint64_t features) { using ceph::encode; encode(from, payload); encode(pgid, payload); encode(map_epoch, payload); encode(min_epoch, payload); encode(cost, payload); encode(objects, payload); } void decode_payload() { using ceph::decode; auto p = payload.cbegin(); decode(from, p); decode(pgid, p); decode(map_epoch, p); decode(min_epoch, p); decode(cost, p); decode(objects, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,226
22.442105
80
h
null
ceph-main/src/messages/MOSDPGRecoveryDeleteReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef MOSDRECOVERYDELETEREPLY_H #define MOSDRECOVERYDELETEREPLY_H #include "MOSDFastDispatchOp.h" class MOSDPGRecoveryDeleteReply : public MOSDFastDispatchOp { public: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; pg_shard_t from; spg_t pgid; epoch_t map_epoch = 0; epoch_t min_epoch = 0; std::list<std::pair<hobject_t, eversion_t> > objects; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDPGRecoveryDeleteReply() : MOSDFastDispatchOp{MSG_OSD_PG_RECOVERY_DELETE_REPLY, HEAD_VERSION, COMPAT_VERSION} {} void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid.pgid, p); decode(map_epoch, p); decode(min_epoch, p); decode(objects, p); decode(pgid.shard, p); decode(from, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid.pgid, payload); encode(map_epoch, payload); encode(min_epoch, payload); encode(objects, payload); encode(pgid.shard, payload); encode(from, payload); } void print(std::ostream& out) const override { out << "MOSDPGRecoveryDeleteReply(" << pgid << " e" << map_epoch << "," << min_epoch << " " << objects << ")"; } std::string_view get_type_name() const override { return "recovery_delete_reply"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,719
24.294118
88
h
null
ceph-main/src/messages/MOSDPGRemove.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGREMOVE_H #define CEPH_MOSDPGREMOVE_H #include "common/hobject.h" #include "msg/Message.h" class MOSDPGRemove final : public Message { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 3; epoch_t epoch = 0; public: std::vector<spg_t> pg_list; epoch_t get_epoch() const { return epoch; } MOSDPGRemove() : Message{MSG_OSD_PG_REMOVE, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGRemove(epoch_t e, std::vector<spg_t>& l) : Message{MSG_OSD_PG_REMOVE, HEAD_VERSION, COMPAT_VERSION} { this->epoch = e; pg_list.swap(l); } private: ~MOSDPGRemove() final {} public: std::string_view get_type_name() const override { return "PGrm"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(pg_list, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(pg_list, p); } void print(std::ostream& out) const override { out << "osd pg remove(" << "epoch " << epoch << "; "; for (auto i = pg_list.begin(); i != pg_list.end(); ++i) { out << "pg" << *i << "; "; } out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,780
23.736111
71
h
null
ceph-main/src/messages/MOSDPGScan.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGSCAN_H #define CEPH_MOSDPGSCAN_H #include "MOSDFastDispatchOp.h" class MOSDPGScan final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 2; public: enum { OP_SCAN_GET_DIGEST = 1, // just objects and versions OP_SCAN_DIGEST = 2, // result }; const char *get_op_name(int o) const { switch (o) { case OP_SCAN_GET_DIGEST: return "get_digest"; case OP_SCAN_DIGEST: return "digest"; default: return "???"; } } __u32 op = 0; epoch_t map_epoch = 0, query_epoch = 0; pg_shard_t from; spg_t pgid; hobject_t begin, end; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return query_epoch; } spg_t get_spg() const override { return pgid; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(op, p); decode(map_epoch, p); decode(query_epoch, p); decode(pgid.pgid, p); decode(begin, p); decode(end, p); // handle hobject_t format upgrade if (!begin.is_max() && begin.pool == -1) begin.pool = pgid.pool(); if (!end.is_max() && end.pool == -1) end.pool = pgid.pool(); decode(from, p); decode(pgid.shard, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(op, payload); encode(map_epoch, payload); assert(HAVE_FEATURE(features, SERVER_NAUTILUS)); encode(query_epoch, payload); encode(pgid.pgid, payload); encode(begin, payload); encode(end, payload); encode(from, payload); encode(pgid.shard, payload); } MOSDPGScan() : MOSDFastDispatchOp{MSG_OSD_PG_SCAN, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGScan(__u32 o, pg_shard_t from, epoch_t e, epoch_t qe, spg_t p, hobject_t be, hobject_t en) : MOSDFastDispatchOp{MSG_OSD_PG_SCAN, HEAD_VERSION, COMPAT_VERSION}, op(o), map_epoch(e), query_epoch(qe), from(from), pgid(p), begin(be), end(en) { } private: ~MOSDPGScan() final {} public: std::string_view get_type_name() const override { return "pg_scan"; } void print(std::ostream& out) const override { out << "pg_scan(" << get_op_name(op) << " " << pgid << " " << begin << "-" << end << " e " << map_epoch << "/" << query_epoch << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,953
24.465517
74
h
null
ceph-main/src/messages/MOSDPGTemp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGTEMP_H #define CEPH_MOSDPGTEMP_H #include "messages/PaxosServiceMessage.h" class MOSDPGTemp final : public PaxosServiceMessage { public: epoch_t map_epoch = 0; std::map<pg_t, std::vector<int32_t> > pg_temp; bool forced = false; MOSDPGTemp(epoch_t e) : PaxosServiceMessage{MSG_OSD_PGTEMP, e, HEAD_VERSION, COMPAT_VERSION}, map_epoch(e) {} MOSDPGTemp() : MOSDPGTemp(0) {} private: ~MOSDPGTemp() final {} public: void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(map_epoch, payload); encode(pg_temp, payload); encode(forced, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(map_epoch, p); decode(pg_temp, p); if (header.version >= 2) { decode(forced, p); } } std::string_view get_type_name() const override { return "osd_pgtemp"; } void print(std::ostream &out) const override { out << "osd_pgtemp(e" << map_epoch << " " << pg_temp << " v" << version << ")"; } private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,737
23.828571
83
h
null
ceph-main/src/messages/MOSDPGTrim.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGTRIM_H #define CEPH_MOSDPGTRIM_H #include "msg/Message.h" #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MOSDPGTrim final : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 2; public: epoch_t epoch = 0; spg_t pgid; eversion_t trim_to; epoch_t get_epoch() const { return epoch; } spg_t get_spg() const { return pgid; } epoch_t get_map_epoch() const { return epoch; } epoch_t get_min_epoch() const { return epoch; } PGPeeringEvent *get_event() override { return new PGPeeringEvent( epoch, epoch, MTrim(epoch, get_source().num(), pgid.shard, trim_to)); } MOSDPGTrim() : MOSDPeeringOp{MSG_OSD_PG_TRIM, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGTrim(version_t mv, spg_t p, eversion_t tt) : MOSDPeeringOp{MSG_OSD_PG_TRIM, HEAD_VERSION, COMPAT_VERSION}, epoch(mv), pgid(p), trim_to(tt) { } private: ~MOSDPGTrim() final {} public: std::string_view get_type_name() const override { return "pg_trim"; } void inner_print(std::ostream& out) const override { out << trim_to; } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(pgid.pgid, payload); encode(trim_to, payload); encode(pgid.shard, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(pgid.pgid, p); decode(trim_to, p); decode(pgid.shard, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,112
24.457831
80
h
null
ceph-main/src/messages/MOSDPGUpdateLogMissing.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGUPDATELOGMISSING_H #define CEPH_MOSDPGUPDATELOGMISSING_H #include "MOSDFastDispatchOp.h" class MOSDPGUpdateLogMissing final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 1; public: epoch_t map_epoch = 0, min_epoch = 0; spg_t pgid; shard_id_t from; ceph_tid_t rep_tid = 0; mempool::osd_pglog::list<pg_log_entry_t> entries; // piggybacked osd/pg state eversion_t pg_trim_to; // primary->replica: trim to here eversion_t pg_roll_forward_to; // primary->replica: trim rollback info to here epoch_t get_epoch() const { return map_epoch; } spg_t get_pgid() const { return pgid; } epoch_t get_query_epoch() const { return map_epoch; } ceph_tid_t get_tid() const { return rep_tid; } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDPGUpdateLogMissing() : MOSDFastDispatchOp{MSG_OSD_PG_UPDATE_LOG_MISSING, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGUpdateLogMissing( const mempool::osd_pglog::list<pg_log_entry_t> &entries, spg_t pgid, shard_id_t from, epoch_t epoch, epoch_t min_epoch, ceph_tid_t rep_tid, eversion_t pg_trim_to, eversion_t pg_roll_forward_to) : MOSDFastDispatchOp{MSG_OSD_PG_UPDATE_LOG_MISSING, HEAD_VERSION, COMPAT_VERSION}, map_epoch(epoch), min_epoch(min_epoch), pgid(pgid), from(from), rep_tid(rep_tid), entries(entries), pg_trim_to(pg_trim_to), pg_roll_forward_to(pg_roll_forward_to) {} private: ~MOSDPGUpdateLogMissing() final {} public: std::string_view get_type_name() const override { return "PGUpdateLogMissing"; } void print(std::ostream& out) const override { out << "pg_update_log_missing(" << pgid << " epoch " << map_epoch << "/" << min_epoch << " rep_tid " << rep_tid << " entries " << entries << " trim_to " << pg_trim_to << " roll_forward_to " << pg_roll_forward_to << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(map_epoch, payload); encode(pgid, payload); encode(from, payload); encode(rep_tid, payload); encode(entries, payload); encode(min_epoch, payload); encode(pg_trim_to, payload); encode(pg_roll_forward_to, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(map_epoch, p); decode(pgid, p); decode(from, p); decode(rep_tid, p); decode(entries, p); if (header.version >= 2) { decode(min_epoch, p); } else { min_epoch = map_epoch; } if (header.version >= 3) { decode(pg_trim_to, p); decode(pg_roll_forward_to, p); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
3,400
26.208
82
h
null
ceph-main/src/messages/MOSDPGUpdateLogMissingReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDPGUPDATELOGMISSINGREPLY_H #define CEPH_MOSDPGUPDATELOGMISSINGREPLY_H #include "MOSDFastDispatchOp.h" class MOSDPGUpdateLogMissingReply final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 1; public: epoch_t map_epoch = 0, min_epoch = 0; spg_t pgid; shard_id_t from; ceph_tid_t rep_tid = 0; // piggybacked osd state eversion_t last_complete_ondisk; epoch_t get_epoch() const { return map_epoch; } spg_t get_pgid() const { return pgid; } epoch_t get_query_epoch() const { return map_epoch; } ceph_tid_t get_tid() const { return rep_tid; } pg_shard_t get_from() const { return pg_shard_t(get_source().num(), from); } epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDPGUpdateLogMissingReply() : MOSDFastDispatchOp{MSG_OSD_PG_UPDATE_LOG_MISSING_REPLY, HEAD_VERSION, COMPAT_VERSION} {} MOSDPGUpdateLogMissingReply( spg_t pgid, shard_id_t from, epoch_t epoch, epoch_t min_epoch, ceph_tid_t rep_tid, eversion_t last_complete_ondisk) : MOSDFastDispatchOp{MSG_OSD_PG_UPDATE_LOG_MISSING_REPLY, HEAD_VERSION, COMPAT_VERSION}, map_epoch(epoch), min_epoch(min_epoch), pgid(pgid), from(from), rep_tid(rep_tid), last_complete_ondisk(last_complete_ondisk) {} private: ~MOSDPGUpdateLogMissingReply() final {} public: std::string_view get_type_name() const override { return "PGUpdateLogMissingReply"; } void print(std::ostream& out) const override { out << "pg_update_log_missing_reply(" << pgid << " epoch " << map_epoch << "/" << min_epoch << " rep_tid " << rep_tid << " lcod " << last_complete_ondisk << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(map_epoch, payload); encode(pgid, payload); encode(from, payload); encode(rep_tid, payload); encode(min_epoch, payload); encode(last_complete_ondisk, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(map_epoch, p); decode(pgid, p); decode(from, p); decode(rep_tid, p); if (header.version >= 2) { decode(min_epoch, p); } else { min_epoch = map_epoch; } if (header.version >= 3) { decode(last_complete_ondisk, p); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
3,067
25.448276
87
h
null
ceph-main/src/messages/MOSDPeeringOp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" #include "osd/osd_types.h" class PGPeeringEvent; class MOSDPeeringOp : public Message { public: MOSDPeeringOp(int t, int version, int compat_version) : Message{t, version, compat_version} {} void print(std::ostream& out) const override final { out << get_type_name() << "(" << get_spg() << " "; inner_print(out); out << " e" << get_map_epoch() << "/" << get_min_epoch() << ")"; } virtual spg_t get_spg() const = 0; virtual epoch_t get_map_epoch() const = 0; virtual epoch_t get_min_epoch() const = 0; virtual PGPeeringEvent *get_event() = 0; virtual void inner_print(std::ostream& out) const = 0; #ifdef WITH_SEASTAR // In crimson, conn is independently maintained outside Message. // Instead of get features from the connection later, set features at // the start of the operation. void set_features(uint64_t _features) { features = _features; } protected: uint64_t features; #endif };
1,080
25.365854
71
h
null
ceph-main/src/messages/MOSDPing.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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. * */ /** * This is used to send pings between daemons (so far, the OSDs) for * heartbeat purposes. We include a timestamp and distinguish between * outgoing pings and responses to those. If you set the * min_message in the constructor, the message will inflate itself * to the specified size -- this is good for dealing with network * issues with jumbo frames. See http://tracker.ceph.com/issues/20087 * */ #ifndef CEPH_MOSDPING_H #define CEPH_MOSDPING_H #include "common/Clock.h" #include "msg/Message.h" #include "osd/osd_types.h" class MOSDPing final : public Message { private: static constexpr int HEAD_VERSION = 5; static constexpr int COMPAT_VERSION = 4; public: enum { HEARTBEAT = 0, START_HEARTBEAT = 1, YOU_DIED = 2, STOP_HEARTBEAT = 3, PING = 4, PING_REPLY = 5, }; const char *get_op_name(int op) const { switch (op) { case HEARTBEAT: return "heartbeat"; case START_HEARTBEAT: return "start_heartbeat"; case STOP_HEARTBEAT: return "stop_heartbeat"; case YOU_DIED: return "you_died"; case PING: return "ping"; case PING_REPLY: return "ping_reply"; default: return "???"; } } uuid_d fsid; epoch_t map_epoch = 0; __u8 op = 0; utime_t ping_stamp; ///< when the PING was sent ceph::signedspan mono_ping_stamp; ///< relative to sender's clock ceph::signedspan mono_send_stamp; ///< replier's send stamp std::optional<ceph::signedspan> delta_ub; ///< ping sender epoch_t up_from = 0; uint32_t min_message_size = 0; MOSDPing(const uuid_d& f, epoch_t e, __u8 o, utime_t s, ceph::signedspan ms, ceph::signedspan mss, epoch_t upf, uint32_t min_message, std::optional<ceph::signedspan> delta_ub = {}) : Message{MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION}, fsid(f), map_epoch(e), op(o), ping_stamp(s), mono_ping_stamp(ms), mono_send_stamp(mss), delta_ub(delta_ub), up_from(upf), min_message_size(min_message) { } MOSDPing() : Message{MSG_OSD_PING, HEAD_VERSION, COMPAT_VERSION} {} private: ~MOSDPing() final {} public: void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(fsid, p); decode(map_epoch, p); decode(op, p); decode(ping_stamp, p); int payload_mid_length = p.get_off(); uint32_t size; decode(size, p); if (header.version >= 5) { decode(up_from, p); decode(mono_ping_stamp, p); decode(mono_send_stamp, p); decode(delta_ub, p); } p += size; min_message_size = size + payload_mid_length; } void encode_payload(uint64_t features) override { using ceph::encode; encode(fsid, payload); encode(map_epoch, payload); encode(op, payload); encode(ping_stamp, payload); size_t s = 0; if (min_message_size > payload.length()) { s = min_message_size - payload.length(); } encode((uint32_t)s, payload); encode(up_from, payload); encode(mono_ping_stamp, payload); encode(mono_send_stamp, payload); encode(delta_ub, payload); if (s) { // this should be big enough for normal min_message padding sizes. since // we are targeting jumbo ethernet frames around 9000 bytes, 16k should // be more than sufficient! the compiler will statically zero this so // that at runtime we are only adding a bufferptr reference to it. static char zeros[16384] = {}; while (s > sizeof(zeros)) { payload.append(ceph::buffer::create_static(sizeof(zeros), zeros)); s -= sizeof(zeros); } if (s) { payload.append(ceph::buffer::create_static(s, zeros)); } } } std::string_view get_type_name() const override { return "osd_ping"; } void print(std::ostream& out) const override { out << "osd_ping(" << get_op_name(op) << " e" << map_epoch << " up_from " << up_from << " ping_stamp " << ping_stamp << "/" << mono_ping_stamp << " send_stamp " << mono_send_stamp; if (delta_ub) { out << " delta_ub " << *delta_ub; } out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
4,653
26.538462
78
h
null
ceph-main/src/messages/MOSDRepOp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDREPOP_H #define CEPH_MOSDREPOP_H #include "MOSDFastDispatchOp.h" /* * OSD sub op - for internal ops on pobjects between primary and replicas(/stripes/whatever) */ class MOSDRepOp final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 1; public: epoch_t map_epoch, min_epoch; // metadata from original request osd_reqid_t reqid; spg_t pgid; ceph::buffer::list::const_iterator p; // Decoding flags. Decoding is only needed for messages caught by pipe reader. bool final_decode_needed; // subop pg_shard_t from; hobject_t poid; __u8 acks_wanted; // transaction to exec ceph::buffer::list logbl; pg_stat_t pg_stats; // subop metadata eversion_t version; // piggybacked osd/og state eversion_t pg_trim_to; // primary->replica: trim to here eversion_t min_last_complete_ondisk; // lower bound on committed version hobject_t new_temp_oid; ///< new temp object that we must now start tracking hobject_t discard_temp_oid; ///< previously used temp object that we can now stop tracking /// non-empty if this transaction involves a hit_set history update std::optional<pg_hit_set_history_t> updated_hit_set_history; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } int get_cost() const override { return data.length(); } void decode_payload() override { using ceph::decode; p = payload.cbegin(); // split to partial and final decode(map_epoch, p); if (header.version >= 2) { decode(min_epoch, p); decode_trace(p); } else { min_epoch = map_epoch; } decode(reqid, p); decode(pgid, p); } void finish_decode() { using ceph::decode; if (!final_decode_needed) return; // Message is already final decoded decode(poid, p); decode(acks_wanted, p); decode(version, p); decode(logbl, p); decode(pg_stats, p); decode(pg_trim_to, p); decode(new_temp_oid, p); decode(discard_temp_oid, p); decode(from, p); decode(updated_hit_set_history, p); if (header.version >= 3) { decode(min_last_complete_ondisk, p); } else { /* This field used to mean pg_roll_foward_to, but ReplicatedBackend * simply assumes that we're rolling foward to version. */ eversion_t pg_roll_forward_to; decode(pg_roll_forward_to, p); } final_decode_needed = false; } void encode_payload(uint64_t features) override { using ceph::encode; encode(map_epoch, payload); assert(HAVE_FEATURE(features, SERVER_OCTOPUS)); header.version = HEAD_VERSION; encode(min_epoch, payload); encode_trace(payload, features); encode(reqid, payload); encode(pgid, payload); encode(poid, payload); encode(acks_wanted, payload); encode(version, payload); encode(logbl, payload); encode(pg_stats, payload); encode(pg_trim_to, payload); encode(new_temp_oid, payload); encode(discard_temp_oid, payload); encode(from, payload); encode(updated_hit_set_history, payload); encode(min_last_complete_ondisk, payload); } MOSDRepOp() : MOSDFastDispatchOp{MSG_OSD_REPOP, HEAD_VERSION, COMPAT_VERSION}, map_epoch(0), final_decode_needed(true), acks_wanted (0) {} MOSDRepOp(osd_reqid_t r, pg_shard_t from, spg_t p, const hobject_t& po, int aw, epoch_t mape, epoch_t min_epoch, ceph_tid_t rtid, eversion_t v) : MOSDFastDispatchOp{MSG_OSD_REPOP, HEAD_VERSION, COMPAT_VERSION}, map_epoch(mape), min_epoch(min_epoch), reqid(r), pgid(p), final_decode_needed(false), from(from), poid(po), acks_wanted(aw), version(v) { set_tid(rtid); } void set_rollback_to(const eversion_t &rollback_to) { header.version = 2; min_last_complete_ondisk = rollback_to; } private: ~MOSDRepOp() final {} public: std::string_view get_type_name() const override { return "osd_repop"; } void print(std::ostream& out) const override { out << "osd_repop(" << reqid << " " << pgid << " e" << map_epoch << "/" << min_epoch; if (!final_decode_needed) { out << " " << poid << " v " << version; if (updated_hit_set_history) out << ", has_updated_hit_set_history"; if (header.version < 3) { out << ", rollback_to(legacy)=" << min_last_complete_ondisk; } else { out << ", mlcod=" << min_last_complete_ondisk; } } out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
5,187
25.335025
93
h
null
ceph-main/src/messages/MOSDRepOpReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDREPOPREPLY_H #define CEPH_MOSDREPOPREPLY_H #include "MOSDFastDispatchOp.h" #include "MOSDRepOp.h" /* * OSD Client Subop reply * * oid - object id * op - OSD_OP_DELETE, etc. * */ class MOSDRepOpReply final : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: epoch_t map_epoch, min_epoch; // subop metadata osd_reqid_t reqid; pg_shard_t from; spg_t pgid; // result __u8 ack_type; int32_t result; // piggybacked osd state eversion_t last_complete_ondisk; ceph::buffer::list::const_iterator p; // Decoding flags. Decoding is only needed for messages caught by pipe reader. bool final_decode_needed; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } void decode_payload() override { using ceph::decode; p = payload.cbegin(); decode(map_epoch, p); if (header.version >= 2) { decode(min_epoch, p); decode_trace(p); } else { min_epoch = map_epoch; } decode(reqid, p); decode(pgid, p); } void finish_decode() { using ceph::decode; if (!final_decode_needed) return; // Message is already final decoded decode(ack_type, p); decode(result, p); decode(last_complete_ondisk, p); decode(from, p); final_decode_needed = false; } void encode_payload(uint64_t features) override { using ceph::encode; encode(map_epoch, payload); header.version = HEAD_VERSION; encode(min_epoch, payload); encode_trace(payload, features); encode(reqid, payload); encode(pgid, payload); encode(ack_type, payload); encode(result, payload); encode(last_complete_ondisk, payload); encode(from, payload); } spg_t get_pg() { return pgid; } int get_ack_type() { return ack_type; } bool is_ondisk() { return ack_type & CEPH_OSD_FLAG_ONDISK; } bool is_onnvram() { return ack_type & CEPH_OSD_FLAG_ONNVRAM; } int get_result() { return result; } void set_last_complete_ondisk(eversion_t v) { last_complete_ondisk = v; } eversion_t get_last_complete_ondisk() const { return last_complete_ondisk; } public: MOSDRepOpReply( const MOSDRepOp *req, pg_shard_t from, int result_, epoch_t e, epoch_t mine, int at) : MOSDFastDispatchOp{MSG_OSD_REPOPREPLY, HEAD_VERSION, COMPAT_VERSION}, map_epoch(e), min_epoch(mine), reqid(req->reqid), from(from), pgid(req->pgid.pgid, req->from.shard), ack_type(at), result(result_), final_decode_needed(false) { set_tid(req->get_tid()); } MOSDRepOpReply() : MOSDFastDispatchOp{MSG_OSD_REPOPREPLY, HEAD_VERSION, COMPAT_VERSION}, map_epoch(0), min_epoch(0), ack_type(0), result(0), final_decode_needed(true) {} private: ~MOSDRepOpReply() final {} public: std::string_view get_type_name() const override { return "osd_repop_reply"; } void print(std::ostream& out) const override { out << "osd_repop_reply(" << reqid << " " << pgid << " e" << map_epoch << "/" << min_epoch; if (!final_decode_needed) { if (ack_type & CEPH_OSD_FLAG_ONDISK) out << " ondisk"; if (ack_type & CEPH_OSD_FLAG_ONNVRAM) out << " onnvram"; if (ack_type & CEPH_OSD_FLAG_ACK) out << " ack"; out << ", result = " << result; } out << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
4,049
24.15528
80
h
null
ceph-main/src/messages/MOSDRepScrub.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDREPSCRUB_H #define CEPH_MOSDREPSCRUB_H #include "MOSDFastDispatchOp.h" /* * instruct an OSD initiate a replica scrub on a specific PG */ class MOSDRepScrub final : public MOSDFastDispatchOp { public: static constexpr int HEAD_VERSION = 9; static constexpr int COMPAT_VERSION = 6; spg_t pgid; // PG to scrub eversion_t scrub_from; // only scrub log entries after scrub_from eversion_t scrub_to; // last_update_applied when message sent (not used) epoch_t map_epoch = 0, min_epoch = 0; bool chunky; // true for chunky scrubs hobject_t start; // lower bound of scrub, inclusive hobject_t end; // upper bound of scrub, exclusive bool deep; // true if scrub should be deep bool allow_preemption = false; int32_t priority = 0; bool high_priority = false; epoch_t get_map_epoch() const override { return map_epoch; } epoch_t get_min_epoch() const override { return min_epoch; } spg_t get_spg() const override { return pgid; } MOSDRepScrub() : MOSDFastDispatchOp{MSG_OSD_REP_SCRUB, HEAD_VERSION, COMPAT_VERSION}, chunky(false), deep(false) { } MOSDRepScrub(spg_t pgid, eversion_t scrub_to, epoch_t map_epoch, epoch_t min_epoch, hobject_t start, hobject_t end, bool deep, bool preemption, int prio, bool highprio) : MOSDFastDispatchOp{MSG_OSD_REP_SCRUB, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid), scrub_to(scrub_to), map_epoch(map_epoch), min_epoch(min_epoch), chunky(true), start(start), end(end), deep(deep), allow_preemption(preemption), priority(prio), high_priority(highprio) { } private: ~MOSDRepScrub() final {} public: std::string_view get_type_name() const override { return "replica scrub"; } void print(std::ostream& out) const override { out << "replica_scrub(pg: " << pgid << ",from:" << scrub_from << ",to:" << scrub_to << ",epoch:" << map_epoch << "/" << min_epoch << ",start:" << start << ",end:" << end << ",chunky:" << chunky << ",deep:" << deep << ",version:" << header.version << ",allow_preemption:" << (int)allow_preemption << ",priority=" << priority << (high_priority ? " (high)":"") << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid.pgid, payload); encode(scrub_from, payload); encode(scrub_to, payload); encode(map_epoch, payload); encode(chunky, payload); encode(start, payload); encode(end, payload); encode(deep, payload); encode(pgid.shard, payload); encode((uint32_t)-1, payload); // seed encode(min_epoch, payload); encode(allow_preemption, payload); encode(priority, payload); encode(high_priority, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid.pgid, p); decode(scrub_from, p); decode(scrub_to, p); decode(map_epoch, p); decode(chunky, p); decode(start, p); decode(end, p); decode(deep, p); decode(pgid.shard, p); { uint32_t seed; decode(seed, p); } if (header.version >= 7) { decode(min_epoch, p); } else { min_epoch = map_epoch; } if (header.version >= 8) { decode(allow_preemption, p); } if (header.version >= 9) { decode(priority, p); decode(high_priority, p); } } }; #endif
3,918
26.405594
85
h
null
ceph-main/src/messages/MOSDRepScrubMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 Sage Weil <[email protected]> * * 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_MOSDREPSCRUBMAP_H #define CEPH_MOSDREPSCRUBMAP_H #include "MOSDFastDispatchOp.h" /* * pass a ScrubMap from a shard back to the primary */ class MOSDRepScrubMap final : public MOSDFastDispatchOp { public: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; spg_t pgid; // primary spg_t epoch_t map_epoch = 0; pg_shard_t from; // whose scrubmap this is ceph::buffer::list scrub_map_bl; bool preempted = false; epoch_t get_map_epoch() const override { return map_epoch; } spg_t get_spg() const override { return pgid; } MOSDRepScrubMap() : MOSDFastDispatchOp{MSG_OSD_REP_SCRUBMAP, HEAD_VERSION, COMPAT_VERSION} {} MOSDRepScrubMap(spg_t pgid, epoch_t map_epoch, pg_shard_t from) : MOSDFastDispatchOp{MSG_OSD_REP_SCRUBMAP, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid), map_epoch(map_epoch), from(from) {} private: ~MOSDRepScrubMap() final {} public: std::string_view get_type_name() const override { return "rep_scrubmap"; } void print(std::ostream& out) const override { out << "rep_scrubmap(" << pgid << " e" << map_epoch << " from shard " << from << (preempted ? " PREEMPTED":"") << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(from, payload); encode(preempted, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(from, p); if (header.version >= 2) { decode(preempted, p); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,196
24.847059
79
h
null
ceph-main/src/messages/MOSDScrub2.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" /* * instruct an OSD to scrub some or all pg(s) */ class MOSDScrub2 final : public Message { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; uuid_d fsid; epoch_t epoch; std::vector<spg_t> scrub_pgs; bool repair = false; bool deep = false; MOSDScrub2() : Message{MSG_OSD_SCRUB2, HEAD_VERSION, COMPAT_VERSION} {} MOSDScrub2(const uuid_d& f, epoch_t e, std::vector<spg_t>& pgs, bool r, bool d) : Message{MSG_OSD_SCRUB2, HEAD_VERSION, COMPAT_VERSION}, fsid(f), epoch(e), scrub_pgs(pgs), repair(r), deep(d) {} private: ~MOSDScrub2() final {} public: std::string_view get_type_name() const override { return "scrub2"; } void print(std::ostream& out) const override { out << "scrub2(" << scrub_pgs; if (repair) out << " repair"; if (deep) out << " deep"; out << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(fsid, payload); encode(epoch, payload); encode(scrub_pgs, payload); encode(repair, payload); encode(deep, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(fsid, p); decode(epoch, p); decode(scrub_pgs, p); decode(repair, p); decode(deep, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,559
24.16129
83
h
null
ceph-main/src/messages/MOSDScrubReserve.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MOSDSCRUBRESERVE_H #define CEPH_MOSDSCRUBRESERVE_H #include "MOSDFastDispatchOp.h" class MOSDScrubReserve : public MOSDFastDispatchOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: spg_t pgid; epoch_t map_epoch; enum { REQUEST = 0, GRANT = 1, RELEASE = 2, REJECT = 3, }; int32_t type; pg_shard_t from; epoch_t get_map_epoch() const override { return map_epoch; } spg_t get_spg() const override { return pgid; } MOSDScrubReserve() : MOSDFastDispatchOp{MSG_OSD_SCRUB_RESERVE, HEAD_VERSION, COMPAT_VERSION}, map_epoch(0), type(-1) {} MOSDScrubReserve(spg_t pgid, epoch_t map_epoch, int type, pg_shard_t from) : MOSDFastDispatchOp{MSG_OSD_SCRUB_RESERVE, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid), map_epoch(map_epoch), type(type), from(from) {} std::string_view get_type_name() const { return "MOSDScrubReserve"; } void print(std::ostream& out) const { out << "MOSDScrubReserve(" << pgid << " "; switch (type) { case REQUEST: out << "REQUEST "; break; case GRANT: out << "GRANT "; break; case REJECT: out << "REJECT "; break; case RELEASE: out << "RELEASE "; break; } out << "e" << map_epoch << ")"; return; } void decode_payload() { using ceph::decode; auto p = payload.cbegin(); decode(pgid, p); decode(map_epoch, p); decode(type, p); decode(from, p); } void encode_payload(uint64_t features) { using ceph::encode; encode(pgid, payload); encode(map_epoch, payload); encode(type, payload); encode(from, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,279
21.8
78
h
null
ceph-main/src/messages/MPGStats.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MPGSTATS_H #define CEPH_MPGSTATS_H #include "osd/osd_types.h" #include "messages/PaxosServiceMessage.h" class MPGStats final : public PaxosServiceMessage { static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: uuid_d fsid; std::map<pg_t, pg_stat_t> pg_stat; osd_stat_t osd_stat; std::map<int64_t, store_statfs_t> pool_stat; epoch_t epoch = 0; MPGStats() : PaxosServiceMessage{MSG_PGSTATS, 0, HEAD_VERSION, COMPAT_VERSION} {} MPGStats(const uuid_d& f, epoch_t e) : PaxosServiceMessage{MSG_PGSTATS, 0, HEAD_VERSION, COMPAT_VERSION}, fsid(f), epoch(e) {} private: ~MPGStats() final {} public: std::string_view get_type_name() const override { return "pg_stats"; } void print(std::ostream& out) const override { out << "pg_stats(" << pg_stat.size() << " pgs seq " << osd_stat.seq << " v " << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(osd_stat, payload, features); encode(pg_stat, payload); encode(epoch, payload); encode(utime_t{}, payload); encode(pool_stat, payload, features); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(osd_stat, p); if (osd_stat.num_osds == 0) { // for the benefit of legacy OSDs who don't set this field osd_stat.num_osds = 1; } decode(pg_stat, p); decode(epoch, p); utime_t dummy; decode(dummy, p); if (header.version >= 2) decode(pool_stat, p); } }; #endif
2,087
25.769231
99
h
null
ceph-main/src/messages/MPGStatsAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MPGSTATSACK_H #define CEPH_MPGSTATSACK_H #include "osd/osd_types.h" class MPGStatsAck final : public Message { public: std::map<pg_t,std::pair<version_t,epoch_t> > pg_stat; MPGStatsAck() : Message{MSG_PGSTATSACK} {} private: ~MPGStatsAck() final {} public: std::string_view get_type_name() const override { return "pg_stats_ack"; } void print(std::ostream& out) const override { out << "pg_stats_ack(" << pg_stat.size() << " pgs tid " << get_tid() << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(pg_stat, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(pg_stat, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,277
24.56
80
h
null
ceph-main/src/messages/MPing.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MPING_H #define CEPH_MPING_H #include "msg/Message.h" class MPing final : public Message { public: MPing() : Message{CEPH_MSG_PING} {} private: ~MPing() final {} public: void decode_payload() override { } void encode_payload(uint64_t features) override { } std::string_view get_type_name() const override { return "ping"; } }; #endif
791
22.294118
71
h
null
ceph-main/src/messages/MPoolOp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MPOOLOP_H #define CEPH_MPOOLOP_H #include "messages/PaxosServiceMessage.h" class MPoolOp final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 2; public: uuid_d fsid; __u32 pool = 0; std::string name; __u32 op = 0; snapid_t snapid; __s16 crush_rule = 0; MPoolOp() : PaxosServiceMessage{CEPH_MSG_POOLOP, 0, HEAD_VERSION, COMPAT_VERSION} {} MPoolOp(const uuid_d& f, ceph_tid_t t, int p, std::string& n, int o, version_t v) : PaxosServiceMessage{CEPH_MSG_POOLOP, v, HEAD_VERSION, COMPAT_VERSION}, fsid(f), pool(p), name(n), op(o), snapid(0), crush_rule(0) { set_tid(t); } private: ~MPoolOp() final {} public: std::string_view get_type_name() const override { return "poolop"; } void print(std::ostream& out) const override { out << "pool_op(" << ceph_pool_op_name(op) << " pool " << pool << " tid " << get_tid() << " name " << name << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(pool, payload); encode(op, payload); encode((uint64_t)0, payload); encode(snapid, payload); encode(name, payload); __u8 pad = 0; encode(pad, payload); /* for v3->v4 encoding change */ encode(crush_rule, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(pool, p); if (header.version < 2) decode(name, p); decode(op, p); uint64_t old_auid; decode(old_auid, p); decode(snapid, p); if (header.version >= 2) decode(name, p); if (header.version >= 3) { __u8 pad; decode(pad, p); if (header.version >= 4) decode(crush_rule, p); else crush_rule = pad; } else crush_rule = -1; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,484
24.10101
83
h
null
ceph-main/src/messages/MPoolOpReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MPOOLOPREPLY_H #define CEPH_MPOOLOPREPLY_H #include "common/errno.h" class MPoolOpReply : public PaxosServiceMessage { public: uuid_d fsid; __u32 replyCode = 0; epoch_t epoch = 0; ceph::buffer::list response_data; MPoolOpReply() : PaxosServiceMessage{CEPH_MSG_POOLOP_REPLY, 0} {} MPoolOpReply( uuid_d& f, ceph_tid_t t, int rc, int e, version_t v) : PaxosServiceMessage{CEPH_MSG_POOLOP_REPLY, v}, fsid(f), replyCode(rc), epoch(e) { set_tid(t); } MPoolOpReply(uuid_d& f, ceph_tid_t t, int rc, int e, version_t v, ceph::buffer::list *blp) : PaxosServiceMessage{CEPH_MSG_POOLOP_REPLY, v}, fsid(f), replyCode(rc), epoch(e) { set_tid(t); if (blp) response_data = std::move(*blp); } std::string_view get_type_name() const override { return "poolopreply"; } void print(std::ostream& out) const override { out << "pool_op_reply(tid " << get_tid() << " " << cpp_strerror(-replyCode) << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(replyCode, payload); encode(epoch, payload); if (response_data.length()) { encode(true, payload); encode(response_data, payload); } else encode(false, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(replyCode, p); decode(epoch, p); bool has_response_data; decode(has_response_data, p); if (has_response_data) { decode(response_data, p); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,209
24.697674
75
h
null
ceph-main/src/messages/MRecoveryReserve.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MRECOVERY_H #define CEPH_MRECOVERY_H #include "msg/Message.h" #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MRecoveryReserve : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 2; public: spg_t pgid; epoch_t query_epoch; enum { REQUEST = 0, // primary->replica: please reserve slot GRANT = 1, // replica->primary: ok, i reserved it RELEASE = 2, // primary->replica: release the slot i reserved before REVOKE = 3, // replica->primary: i'm taking back the slot i gave you }; uint32_t type; uint32_t priority = 0; spg_t get_spg() const { return pgid; } epoch_t get_map_epoch() const { return query_epoch; } epoch_t get_min_epoch() const { return query_epoch; } PGPeeringEvent *get_event() override { switch (type) { case REQUEST: return new PGPeeringEvent( query_epoch, query_epoch, RequestRecoveryPrio(priority)); case GRANT: return new PGPeeringEvent( query_epoch, query_epoch, RemoteRecoveryReserved()); case RELEASE: return new PGPeeringEvent( query_epoch, query_epoch, RecoveryDone()); case REVOKE: return new PGPeeringEvent( query_epoch, query_epoch, DeferRecovery(0.0)); default: ceph_abort(); } } MRecoveryReserve() : MOSDPeeringOp{MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION}, query_epoch(0), type(-1) {} MRecoveryReserve(int type, spg_t pgid, epoch_t query_epoch, unsigned prio = 0) : MOSDPeeringOp{MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid), query_epoch(query_epoch), type(type), priority(prio) {} std::string_view get_type_name() const override { return "MRecoveryReserve"; } void inner_print(std::ostream& out) const override { switch (type) { case REQUEST: out << "REQUEST"; break; case GRANT: out << "GRANT"; break; case RELEASE: out << "RELEASE"; break; case REVOKE: out << "REVOKE"; break; } if (type == REQUEST) out << " prio: " << priority; } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; decode(pgid.pgid, p); decode(query_epoch, p); decode(type, p); decode(pgid.shard, p); if (header.version >= 3) { decode(priority, p); } } void encode_payload(uint64_t features) override { using ceph::encode; encode(pgid.pgid, payload); encode(query_epoch, payload); encode(type, payload); encode(pgid.shard, payload); encode(priority, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
3,228
23.097015
76
h
null
ceph-main/src/messages/MRemoveSnaps.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MREMOVESNAPS_H #define CEPH_MREMOVESNAPS_H #include "messages/PaxosServiceMessage.h" class MRemoveSnaps final : public PaxosServiceMessage { public: std::map<int32_t, std::vector<snapid_t>> snaps; protected: MRemoveSnaps() : PaxosServiceMessage{MSG_REMOVE_SNAPS, 0} { } MRemoveSnaps(std::map<int, std::vector<snapid_t>>& s) : PaxosServiceMessage{MSG_REMOVE_SNAPS, 0} { snaps.swap(s); } ~MRemoveSnaps() final {} public: std::string_view get_type_name() const override { return "remove_snaps"; } void print(std::ostream& out) const override { out << "remove_snaps(" << snaps << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(snaps, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(snaps, p); ceph_assert(p.end()); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,595
26.050847
76
h
null
ceph-main/src/messages/MRoute.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MROUTE_H #define CEPH_MROUTE_H #include "msg/Message.h" #include "include/encoding.h" class MRoute final : public Message { public: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 3; uint64_t session_mon_tid; Message *msg; epoch_t send_osdmap_first; MRoute() : Message{MSG_ROUTE, HEAD_VERSION, COMPAT_VERSION}, session_mon_tid(0), msg(NULL), send_osdmap_first(0) {} MRoute(uint64_t t, Message *m) : Message{MSG_ROUTE, HEAD_VERSION, COMPAT_VERSION}, session_mon_tid(t), msg(m), send_osdmap_first(0) {} private: ~MRoute() final { if (msg) msg->put(); } public: void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; decode(session_mon_tid, p); entity_inst_t dest_unused; decode(dest_unused, p); bool m; decode(m, p); if (m) msg = decode_message(NULL, 0, p); decode(send_osdmap_first, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(session_mon_tid, payload); entity_inst_t dest_unused; encode(dest_unused, payload, features); bool m = msg ? true : false; encode(m, payload); if (msg) encode_message(msg, features, payload); encode(send_osdmap_first, payload); } std::string_view get_type_name() const override { return "route"; } void print(std::ostream& o) const override { if (msg) o << "route(" << *msg; else o << "route(no-reply"; if (send_osdmap_first) o << " send_osdmap_first " << send_osdmap_first; if (session_mon_tid) o << " tid " << session_mon_tid << ")"; else o << " tid (none)"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,273
23.989011
71
h
null
ceph-main/src/messages/MServiceMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" #include "mgr/ServiceMap.h" class MServiceMap final : public Message { public: ServiceMap service_map; MServiceMap() : Message{MSG_SERVICE_MAP} { } explicit MServiceMap(const ServiceMap& sm) : Message{MSG_SERVICE_MAP}, service_map(sm) { } private: ~MServiceMap() final {} public: std::string_view get_type_name() const override { return "service_map"; } void print(std::ostream& out) const override { out << "service_map(e" << service_map.epoch << " " << service_map.services.size() << " svc)"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(service_map, payload, features); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(service_map, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
1,034
24.875
75
h
null
ceph-main/src/messages/MStatfs.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MSTATFS_H #define CEPH_MSTATFS_H #include <optional> #include <sys/statvfs.h> /* or <sys/statfs.h> */ #include "messages/PaxosServiceMessage.h" class MStatfs final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: uuid_d fsid; std::optional<int64_t> data_pool; MStatfs() : PaxosServiceMessage{CEPH_MSG_STATFS, 0, HEAD_VERSION, COMPAT_VERSION} {} MStatfs(const uuid_d& f, ceph_tid_t t, std::optional<int64_t> _data_pool, version_t v) : PaxosServiceMessage{CEPH_MSG_STATFS, v, HEAD_VERSION, COMPAT_VERSION}, fsid(f), data_pool(_data_pool) { set_tid(t); } private: ~MStatfs() final {} public: std::string_view get_type_name() const override { return "statfs"; } void print(std::ostream& out) const override { out << "statfs(" << get_tid() << " pool " << (data_pool ? *data_pool : -1) << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(data_pool, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); if (header.version >= 2) { decode(data_pool, p); } else { data_pool = std::optional<int64_t> (); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,937
25.547945
86
h
null
ceph-main/src/messages/MStatfsReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MSTATFSREPLY_H #define CEPH_MSTATFSREPLY_H class MStatfsReply : public Message { public: struct ceph_mon_statfs_reply h{}; MStatfsReply() : Message{CEPH_MSG_STATFS_REPLY} {} MStatfsReply(uuid_d &f, ceph_tid_t t, epoch_t epoch) : Message{CEPH_MSG_STATFS_REPLY} { memcpy(&h.fsid, f.bytes(), sizeof(h.fsid)); header.tid = t; h.version = epoch; } std::string_view get_type_name() const override { return "statfs_reply"; } void print(std::ostream& out) const override { out << "statfs_reply(" << header.tid << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(h, payload); } void decode_payload() override { auto p = payload.cbegin(); decode(h, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,312
25.26
76
h
null
ceph-main/src/messages/MTimeCheck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2012 Inktank, Inc. * * 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_MTIMECHECK_H #define CEPH_MTIMECHECK_H class MTimeCheck final : public Message { public: static constexpr int HEAD_VERSION = 1; enum { OP_PING = 1, OP_PONG = 2, OP_REPORT = 3, }; int op = 0; version_t epoch = 0; version_t round = 0; utime_t timestamp; map<entity_inst_t, double> skews; map<entity_inst_t, double> latencies; MTimeCheck() : Message{MSG_TIMECHECK, HEAD_VERSION} {} MTimeCheck(int op) : Message{MSG_TIMECHECK, HEAD_VERSION}, op(op) {} private: ~MTimeCheck() final {} public: std::string_view get_type_name() const override { return "time_check"; } const char *get_op_name() const { switch (op) { case OP_PING: return "ping"; case OP_PONG: return "pong"; case OP_REPORT: return "report"; } return "???"; } void print(std::ostream &o) const override { o << "time_check( " << get_op_name() << " e " << epoch << " r " << round; if (op == OP_PONG) { o << " ts " << timestamp; } else if (op == OP_REPORT) { o << " #skews " << skews.size() << " #latencies " << latencies.size(); } o << " )"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(op, p); decode(epoch, p); decode(round, p); decode(timestamp, p); decode(skews, p); decode(latencies, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(op, payload); encode(epoch, payload); encode(round, payload); encode(timestamp, payload); encode(skews, payload, features); encode(latencies, payload, features); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif /* CEPH_MTIMECHECK_H */
2,211
22.784946
74
h
null
ceph-main/src/messages/MTimeCheck2.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2012 Inktank, Inc. * * 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. * */ #pragma once class MTimeCheck2 final : public Message { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; enum { OP_PING = 1, OP_PONG = 2, OP_REPORT = 3, }; int op = 0; version_t epoch = 0; version_t round = 0; utime_t timestamp; std::map<int, double> skews; std::map<int, double> latencies; MTimeCheck2() : Message{MSG_TIMECHECK2, HEAD_VERSION, COMPAT_VERSION} { } MTimeCheck2(int op) : Message{MSG_TIMECHECK2, HEAD_VERSION, COMPAT_VERSION}, op(op) { } private: ~MTimeCheck2() final { } public: std::string_view get_type_name() const override { return "time_check2"; } const char *get_op_name() const { switch (op) { case OP_PING: return "ping"; case OP_PONG: return "pong"; case OP_REPORT: return "report"; } return "???"; } void print(std::ostream &o) const override { o << "time_check( " << get_op_name() << " e " << epoch << " r " << round; if (op == OP_PONG) { o << " ts " << timestamp; } else if (op == OP_REPORT) { o << " #skews " << skews.size() << " #latencies " << latencies.size(); } o << " )"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(op, p); decode(epoch, p); decode(round, p); decode(timestamp, p); decode(skews, p); decode(latencies, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(op, payload); encode(epoch, payload); encode(round, payload); encode(timestamp, payload); encode(skews, payload, features); encode(latencies, payload, features); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); };
2,212
23.318681
75
h
null
ceph-main/src/messages/MWatchNotify.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MWATCHNOTIFY_H #define CEPH_MWATCHNOTIFY_H #include "msg/Message.h" class MWatchNotify final : public Message { private: static constexpr int HEAD_VERSION = 3; static constexpr int COMPAT_VERSION = 1; public: uint64_t cookie; ///< client unique id for this watch or notify uint64_t ver; ///< unused uint64_t notify_id; ///< osd unique id for a notify notification uint8_t opcode; ///< CEPH_WATCH_EVENT_* ceph::buffer::list bl; ///< notify payload (osd->client) errorcode32_t return_code; ///< notify result (osd->client) uint64_t notifier_gid; ///< who sent the notify MWatchNotify() : Message{CEPH_MSG_WATCH_NOTIFY, HEAD_VERSION, COMPAT_VERSION} { } MWatchNotify(uint64_t c, uint64_t v, uint64_t i, uint8_t o, ceph::buffer::list b, uint64_t n=0) : Message{CEPH_MSG_WATCH_NOTIFY, HEAD_VERSION, COMPAT_VERSION}, cookie(c), ver(v), notify_id(i), opcode(o), bl(b), return_code(0), notifier_gid(n) { } private: ~MWatchNotify() final {} public: void decode_payload() override { using ceph::decode; uint8_t msg_ver; auto p = payload.cbegin(); decode(msg_ver, p); decode(opcode, p); decode(cookie, p); decode(ver, p); decode(notify_id, p); if (msg_ver >= 1) decode(bl, p); if (header.version >= 2) decode(return_code, p); else return_code = 0; if (header.version >= 3) decode(notifier_gid, p); else notifier_gid = 0; } void encode_payload(uint64_t features) override { using ceph::encode; uint8_t msg_ver = 1; encode(msg_ver, payload); encode(opcode, payload); encode(cookie, payload); encode(ver, payload); encode(notify_id, payload); encode(bl, payload); encode(return_code, payload); encode(notifier_gid, payload); } std::string_view get_type_name() const override { return "watch-notify"; } void print(std::ostream& out) const override { out << "watch-notify(" << ceph_watch_event_name(opcode) << " (" << (int)opcode << ")" << " cookie " << cookie << " notify " << notify_id << " ret " << return_code << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
2,728
26.565657
97
h
null
ceph-main/src/messages/PaxosServiceMessage.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- #ifndef CEPH_PAXOSSERVICEMESSAGE_H #define CEPH_PAXOSSERVICEMESSAGE_H #include "msg/Message.h" #include "mon/Session.h" class PaxosServiceMessage : public Message { public: version_t version; __s16 deprecated_session_mon; uint64_t deprecated_session_mon_tid; // track which epoch the leader received a forwarded request in, so we can // discard forwarded requests appropriately on election boundaries. epoch_t rx_election_epoch; PaxosServiceMessage() : Message{MSG_PAXOS}, version(0), deprecated_session_mon(-1), deprecated_session_mon_tid(0), rx_election_epoch(0) { } PaxosServiceMessage(int type, version_t v, int enc_version=1, int compat_enc_version=0) : Message{type, enc_version, compat_enc_version}, version(v), deprecated_session_mon(-1), deprecated_session_mon_tid(0), rx_election_epoch(0) { } protected: ~PaxosServiceMessage() override {} public: void paxos_encode() { using ceph::encode; encode(version, payload); encode(deprecated_session_mon, payload); encode(deprecated_session_mon_tid, payload); } void paxos_decode(ceph::buffer::list::const_iterator& p ) { using ceph::decode; decode(version, p); decode(deprecated_session_mon, p); decode(deprecated_session_mon_tid, p); } void encode_payload(uint64_t features) override { ceph_abort(); paxos_encode(); } void decode_payload() override { ceph_abort(); auto p = payload.cbegin(); paxos_decode(p); } std::string_view get_type_name() const override { return "PaxosServiceMessage"; } }; #endif
1,661
26.7
89
h
null
ceph-main/src/mgr/ActivePyModule.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2016 John Spray <[email protected]> * * 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. */ #pragma once // Python.h comes first because otherwise it clobbers ceph's assert #include "Python.h" #include "common/cmdparse.h" #include "common/LogEntry.h" #include "common/Thread.h" #include "common/Finisher.h" #include "mon/health_check.h" #include "mgr/Gil.h" #include "PyModuleRunner.h" #include "PyModule.h" #include <vector> #include <string> class ActivePyModule; class ActivePyModules; class MgrSession; class ModuleCommand; class ActivePyModule : public PyModuleRunner { private: health_check_map_t health_checks; // Optional, URI exposed by plugins that implement serve() std::string uri; std::string m_command_perms; const MgrSession* m_session = nullptr; std::string fin_thread_name; public: Finisher finisher; // per active module finisher to execute commands public: ActivePyModule(const PyModuleRef &py_module_, LogChannelRef clog_) : PyModuleRunner(py_module_, clog_), fin_thread_name(std::string("m-fin-" + py_module->get_name()).substr(0,15)), finisher(g_ceph_context, thread_name, fin_thread_name) { } int load(ActivePyModules *py_modules); void notify(const std::string &notify_type, const std::string &notify_id); void notify_clog(const LogEntry &le); bool method_exists(const std::string &method) const; PyObject *dispatch_remote( const std::string &method, PyObject *args, PyObject *kwargs, std::string *err); int handle_command( const ModuleCommand& module_command, const MgrSession& session, const cmdmap_t &cmdmap, const bufferlist &inbuf, std::stringstream *ds, std::stringstream *ss); bool set_health_checks(health_check_map_t&& c) { // when health checks change a report is immediately sent to the monitors. // currently modules have static health check details, but this equality // test could be made smarter if too much noise shows up in the future. bool changed = health_checks != c; health_checks = std::move(c); return changed; } void get_health_checks(health_check_map_t *checks); void config_notify(); void set_uri(const std::string &str) { uri = str; } std::string get_uri() const { return uri; } std::string get_fin_thread_name() const { return fin_thread_name; } bool is_authorized(const std::map<std::string, std::string>& arguments) const; };
2,802
23.373913
82
h
null
ceph-main/src/mgr/ActivePyModules.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2014 John Spray <[email protected]> * * 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. */ #pragma once #include "ActivePyModule.h" #include "common/Finisher.h" #include "common/ceph_mutex.h" #include "PyFormatter.h" #include "osdc/Objecter.h" #include "client/Client.h" #include "common/LogClient.h" #include "mon/MgrMap.h" #include "mon/MonCommand.h" #include "mon/mon_types.h" #include "mon/ConfigMap.h" #include "mgr/TTLCache.h" #include "DaemonState.h" #include "ClusterState.h" #include "OSDPerfMetricTypes.h" class health_check_map_t; class DaemonServer; class MgrSession; class ModuleCommand; class PyModuleRegistry; class ActivePyModules { // module class instances not yet created std::set<std::string, std::less<>> pending_modules; // module class instances already created std::map<std::string, std::shared_ptr<ActivePyModule>> modules; PyModuleConfig &module_config; bool have_local_config_map = false; std::map<std::string, std::string> store_cache; ConfigMap config_map; ///< derived from store_cache config/ keys DaemonStateIndex &daemon_state; ClusterState &cluster_state; MonClient &monc; LogChannelRef clog, audit_clog; Objecter &objecter; Client &client; Finisher &finisher; TTLCache<std::string, PyObject*> ttl_cache; public: Finisher cmd_finisher; private: DaemonServer &server; PyModuleRegistry &py_module_registry; std::map<std::string,ProgressEvent> progress_events; mutable ceph::mutex lock = ceph::make_mutex("ActivePyModules::lock"); public: ActivePyModules( PyModuleConfig &module_config, std::map<std::string, std::string> store_data, bool mon_provides_kv_sub, DaemonStateIndex &ds, ClusterState &cs, MonClient &mc, LogChannelRef clog_, LogChannelRef audit_clog_, Objecter &objecter_, Client &client_, Finisher &f, DaemonServer &server, PyModuleRegistry &pmr); ~ActivePyModules(); // FIXME: wrap for send_command? MonClient &get_monc() {return monc;} Objecter &get_objecter() {return objecter;} Client &get_client() {return client;} PyObject *cacheable_get_python(const std::string &what); PyObject *get_python(const std::string &what); PyObject *get_server_python(const std::string &hostname); PyObject *list_servers_python(); PyObject *get_metadata_python( const std::string &svc_type, const std::string &svc_id); PyObject *get_daemon_status_python( const std::string &svc_type, const std::string &svc_id); PyObject *get_counter_python( const std::string &svc_type, const std::string &svc_id, const std::string &path); PyObject *get_latest_counter_python( const std::string &svc_type, const std::string &svc_id, const std::string &path); PyObject *get_perf_schema_python( const std::string &svc_type, const std::string &svc_id); PyObject *get_rocksdb_version(); PyObject *get_context(); PyObject *get_osdmap(); /// @note @c fct is not allowed to acquire locks when holding GIL PyObject *with_perf_counters( std::function<void( PerfCounterInstance& counter_instance, PerfCounterType& counter_type, PyFormatter& f)> fct, const std::string &svc_name, const std::string &svc_id, const std::string &path) const; MetricQueryID add_osd_perf_query( const OSDPerfMetricQuery &query, const std::optional<OSDPerfMetricLimit> &limit); void remove_osd_perf_query(MetricQueryID query_id); PyObject *get_osd_perf_counters(MetricQueryID query_id); MetricQueryID add_mds_perf_query( const MDSPerfMetricQuery &query, const std::optional<MDSPerfMetricLimit> &limit); void remove_mds_perf_query(MetricQueryID query_id); void reregister_mds_perf_queries(); PyObject *get_mds_perf_counters(MetricQueryID query_id); bool get_store(const std::string &module_name, const std::string &key, std::string *val) const; PyObject *get_store_prefix(const std::string &module_name, const std::string &prefix) const; void set_store(const std::string &module_name, const std::string &key, const std::optional<std::string> &val); bool get_config(const std::string &module_name, const std::string &key, std::string *val) const; std::pair<int, std::string> set_config(const std::string &module_name, const std::string &key, const std::optional<std::string> &val); PyObject *get_typed_config(const std::string &module_name, const std::string &key, const std::string &prefix = "") const; PyObject *get_foreign_config( const std::string& who, const std::string& name); void set_health_checks(const std::string& module_name, health_check_map_t&& checks); void get_health_checks(health_check_map_t *checks); void update_progress_event(const std::string& evid, const std::string& desc, float progress, bool add_to_ceph_s); void complete_progress_event(const std::string& evid); void clear_all_progress_events(); void get_progress_events(std::map<std::string,ProgressEvent>* events); void register_client(std::string_view name, std::string addrs, bool replace); void unregister_client(std::string_view name, std::string addrs); void config_notify(); void set_uri(const std::string& module_name, const std::string &uri); void set_device_wear_level(const std::string& devid, float wear_level); int handle_command( const ModuleCommand& module_command, const MgrSession& session, const cmdmap_t &cmdmap, const bufferlist &inbuf, std::stringstream *ds, std::stringstream *ss); std::map<std::string, std::string> get_services() const; void update_kv_data( const std::string prefix, bool incremental, const map<std::string, std::optional<bufferlist>, std::less<>>& data); void _refresh_config_map(); // Public so that MonCommandCompletion can use it // FIXME: for send_command completion notifications, // send it to only the module that sent the command, not everyone void notify_all(const std::string &notify_type, const std::string &notify_id); void notify_all(const LogEntry &log_entry); auto& get_module_finisher(const std::string &name) { return modules.at(name)->finisher; } bool is_pending(std::string_view name) const { return pending_modules.count(name) > 0; } bool module_exists(const std::string &name) const { return modules.count(name) > 0; } bool method_exists( const std::string &module_name, const std::string &method_name) const { return modules.at(module_name)->method_exists(method_name); } PyObject *dispatch_remote( const std::string &other_module, const std::string &method, PyObject *args, PyObject *kwargs, std::string *err); int init(); void shutdown(); void start_one(PyModuleRef py_module); void dump_server(const std::string &hostname, const DaemonStateCollection &dmc, Formatter *f); void cluster_log(const std::string &channel, clog_type prio, const std::string &message); PyObject* get_daemon_health_metrics(); bool inject_python_on() const; void update_cache_metrics(); };
7,526
31.029787
89
h
null
ceph-main/src/mgr/ClusterState.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2014 John Spray <[email protected]> * * 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 CLUSTER_STATE_H_ #define CLUSTER_STATE_H_ #include "mds/FSMap.h" #include "mon/MgrMap.h" #include "common/ceph_mutex.h" #include "osdc/Objecter.h" #include "mon/MonClient.h" #include "mon/PGMap.h" #include "mgr/ServiceMap.h" class MMgrDigest; class MMonMgrReport; class MPGStats; /** * Cluster-scope state (things like cluster maps) as opposed * to daemon-level state (things like perf counters and smart) */ class ClusterState { protected: MonClient *monc; Objecter *objecter; FSMap fsmap; ServiceMap servicemap; mutable ceph::mutex lock = ceph::make_mutex("ClusterState"); MgrMap mgr_map; std::map<int64_t,unsigned> existing_pools; ///< pools that exist, and pg_num, as of PGMap epoch PGMap pg_map; PGMap::Incremental pending_inc; bufferlist health_json; bufferlist mon_status_json; class ClusterSocketHook *asok_hook; public: void load_digest(MMgrDigest *m); void ingest_pgstats(ceph::ref_t<MPGStats> stats); void update_delta_stats(); ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap); void set_objecter(Objecter *objecter_); void set_fsmap(FSMap const &new_fsmap); void set_mgr_map(MgrMap const &new_mgrmap); void set_service_map(ServiceMap const &new_service_map); void notify_osdmap(const OSDMap &osd_map); bool have_fsmap() const { std::lock_guard l(lock); return fsmap.get_epoch() > 0; } template<typename Callback, typename...Args> auto with_servicemap(Callback&& cb, Args&&...args) const { std::lock_guard l(lock); return std::forward<Callback>(cb)(servicemap, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_fsmap(Callback&& cb, Args&&...args) const { std::lock_guard l(lock); return std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_mgrmap(Callback&& cb, Args&&...args) const { std::lock_guard l(lock); return std::forward<Callback>(cb)(mgr_map, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_pgmap(Callback&& cb, Args&&...args) const -> decltype(cb(pg_map, std::forward<Args>(args)...)) { std::lock_guard l(lock); return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_mutable_pgmap(Callback&& cb, Args&&...args) -> decltype(cb(pg_map, std::forward<Args>(args)...)) { std::lock_guard l(lock); return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); } template<typename... Args> auto with_monmap(Args &&... args) const { std::lock_guard l(lock); ceph_assert(monc != nullptr); return monc->with_monmap(std::forward<Args>(args)...); } template<typename... Args> auto with_osdmap(Args &&... args) const -> decltype(objecter->with_osdmap(std::forward<Args>(args)...)) { ceph_assert(objecter != nullptr); return objecter->with_osdmap(std::forward<Args>(args)...); } // call cb(osdmap, pg_map, ...args) with the appropriate locks template <typename Callback, typename ...Args> auto with_osdmap_and_pgmap(Callback&& cb, Args&& ...args) const { ceph_assert(objecter != nullptr); std::lock_guard l(lock); return objecter->with_osdmap( std::forward<Callback>(cb), pg_map, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_health(Callback&& cb, Args&&...args) const { std::lock_guard l(lock); return std::forward<Callback>(cb)(health_json, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_mon_status(Callback&& cb, Args&&...args) const { std::lock_guard l(lock); return std::forward<Callback>(cb)(mon_status_json, std::forward<Args>(args)...); } void final_init(); void shutdown(); bool asok_command(std::string_view admin_command, const cmdmap_t& cmdmap, Formatter *f, std::ostream& ss); }; #endif
4,480
26.323171
97
h
null
ceph-main/src/mgr/DaemonHealthMetric.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include <cstdint> #include <ostream> #include "include/denc.h" enum class daemon_metric : uint8_t { SLOW_OPS, PENDING_CREATING_PGS, NONE, }; static inline const char *daemon_metric_name(daemon_metric t) { switch (t) { case daemon_metric::SLOW_OPS: return "SLOW_OPS"; case daemon_metric::PENDING_CREATING_PGS: return "PENDING_CREATING_PGS"; case daemon_metric::NONE: return "NONE"; default: return "???"; } } union daemon_metric_t { struct { uint32_t n1; uint32_t n2; }; uint64_t n; daemon_metric_t(uint32_t x, uint32_t y) : n1(x), n2(y) {} daemon_metric_t(uint64_t x = 0) : n(x) {} }; class DaemonHealthMetric { public: DaemonHealthMetric() = default; DaemonHealthMetric(daemon_metric type_, uint64_t n) : type(type_), value(n) {} DaemonHealthMetric(daemon_metric type_, uint32_t n1, uint32_t n2) : type(type_), value(n1, n2) {} daemon_metric get_type() const { return type; } uint64_t get_n() const { return value.n; } uint32_t get_n1() const { return value.n1; } uint32_t get_n2() const { return value.n2; } DENC(DaemonHealthMetric, v, p) { DENC_START(1, 1, p); denc(v.type, p); denc(v.value.n, p); DENC_FINISH(p); } std::string get_type_name() const { return daemon_metric_name(get_type()); } friend std::ostream& operator<<(std::ostream& out, const DaemonHealthMetric& m) { return out << daemon_metric_name(m.get_type()) << "(" << m.get_n() << "|(" << m.get_n1() << "," << m.get_n2() << "))"; } private: daemon_metric type = daemon_metric::NONE; daemon_metric_t value; }; WRITE_CLASS_DENC(DaemonHealthMetric)
1,782
20.481928
83
h
null
ceph-main/src/mgr/DaemonHealthMetricCollector.h
#pragma once #include <memory> #include <string> #include "DaemonHealthMetric.h" #include "DaemonKey.h" #include "mon/health_check.h" class DaemonHealthMetricCollector { public: static std::unique_ptr<DaemonHealthMetricCollector> create(daemon_metric m); void update(const DaemonKey& daemon, const DaemonHealthMetric& metric) { if (_is_relevant(metric.get_type())) { reported |= _update(daemon, metric); } } void summarize(health_check_map_t& cm) { if (reported) { _summarize(_get_check(cm)); } } virtual ~DaemonHealthMetricCollector() {} private: virtual bool _is_relevant(daemon_metric type) const = 0; virtual health_check_t& _get_check(health_check_map_t& cm) const = 0; virtual bool _update(const DaemonKey& daemon, const DaemonHealthMetric& metric) = 0; virtual void _summarize(health_check_t& check) const = 0; protected: daemon_metric_t value; bool reported = false; };
933
27.30303
86
h
null
ceph-main/src/mgr/DaemonKey.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include <ostream> #include <string> #include <utility> // Unique reference to a daemon within a cluster struct DaemonKey { std::string type; // service type, like "osd", "mon" std::string name; // service id / name, like "1", "a" static std::pair<DaemonKey, bool> parse(const std::string& s); }; bool operator<(const DaemonKey& lhs, const DaemonKey& rhs); std::ostream& operator<<(std::ostream& os, const DaemonKey& key); namespace ceph { std::string to_string(const DaemonKey& key); }
612
23.52
70
h
null
ceph-main/src/mgr/DaemonServer.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2016 John Spray <[email protected]> * * 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 DAEMON_SERVER_H_ #define DAEMON_SERVER_H_ #include "PyModuleRegistry.h" #include <set> #include <string> #include <boost/variant.hpp> #include "common/ceph_mutex.h" #include "common/LogClient.h" #include "common/Timer.h" #include <msg/Messenger.h> #include <mon/MonClient.h> #include "ServiceMap.h" #include "MgrSession.h" #include "DaemonState.h" #include "MetricCollector.h" #include "OSDPerfMetricCollector.h" #include "MDSPerfMetricCollector.h" class MMgrReport; class MMgrOpen; class MMgrUpdate; class MMgrClose; class MMonMgrReport; class MCommand; class MMgrCommand; struct MonCommand; class CommandContext; struct OSDPerfMetricQuery; struct MDSPerfMetricQuery; struct offline_pg_report { set<int> osds; set<pg_t> ok, not_ok, unknown; set<pg_t> ok_become_degraded, ok_become_more_degraded; // ok set<pg_t> bad_no_pool, bad_already_inactive, bad_become_inactive; // not ok bool ok_to_stop() const { return not_ok.empty() && unknown.empty(); } void dump(Formatter *f) const { f->dump_bool("ok_to_stop", ok_to_stop()); f->open_array_section("osds"); for (auto o : osds) { f->dump_int("osd", o); } f->close_section(); f->dump_unsigned("num_ok_pgs", ok.size()); f->dump_unsigned("num_not_ok_pgs", not_ok.size()); // ambiguous if (!unknown.empty()) { f->open_array_section("unknown_pgs"); for (auto pg : unknown) { f->dump_stream("pg") << pg; } f->close_section(); } // bad news if (!bad_no_pool.empty()) { f->open_array_section("bad_no_pool_pgs"); for (auto pg : bad_no_pool) { f->dump_stream("pg") << pg; } f->close_section(); } if (!bad_already_inactive.empty()) { f->open_array_section("bad_already_inactive"); for (auto pg : bad_already_inactive) { f->dump_stream("pg") << pg; } f->close_section(); } if (!bad_become_inactive.empty()) { f->open_array_section("bad_become_inactive"); for (auto pg : bad_become_inactive) { f->dump_stream("pg") << pg; } f->close_section(); } // informative if (!ok_become_degraded.empty()) { f->open_array_section("ok_become_degraded"); for (auto pg : ok_become_degraded) { f->dump_stream("pg") << pg; } f->close_section(); } if (!ok_become_more_degraded.empty()) { f->open_array_section("ok_become_more_degraded"); for (auto pg : ok_become_more_degraded) { f->dump_stream("pg") << pg; } f->close_section(); } } }; /** * Server used in ceph-mgr to communicate with Ceph daemons like * MDSs and OSDs. */ class DaemonServer : public Dispatcher, public md_config_obs_t { protected: boost::scoped_ptr<Throttle> client_byte_throttler; boost::scoped_ptr<Throttle> client_msg_throttler; boost::scoped_ptr<Throttle> osd_byte_throttler; boost::scoped_ptr<Throttle> osd_msg_throttler; boost::scoped_ptr<Throttle> mds_byte_throttler; boost::scoped_ptr<Throttle> mds_msg_throttler; boost::scoped_ptr<Throttle> mon_byte_throttler; boost::scoped_ptr<Throttle> mon_msg_throttler; Messenger *msgr; MonClient *monc; Finisher &finisher; DaemonStateIndex &daemon_state; ClusterState &cluster_state; PyModuleRegistry &py_modules; LogChannelRef clog, audit_clog; // Connections for daemons, and clients with service names set // (i.e. those MgrClients that are allowed to send MMgrReports) std::set<ConnectionRef> daemon_connections; /// connections for osds ceph::unordered_map<int,std::set<ConnectionRef>> osd_cons; ServiceMap pending_service_map; // uncommitted epoch_t pending_service_map_dirty = 0; ceph::mutex lock = ceph::make_mutex("DaemonServer"); static void _generate_command_map(cmdmap_t& cmdmap, std::map<std::string,std::string> &param_str_map); static const MonCommand *_get_mgrcommand(const std::string &cmd_prefix, const std::vector<MonCommand> &commands); bool _allowed_command( MgrSession *s, const std::string &service, const std::string &module, const std::string &prefix, const cmdmap_t& cmdmap, const std::map<std::string,std::string>& param_str_map, const MonCommand *this_cmd); private: friend class ReplyOnFinish; bool _reply(MCommand* m, int ret, const std::string& s, const bufferlist& payload); void _prune_pending_service_map(); void _check_offlines_pgs( const std::set<int>& osds, const OSDMap& osdmap, const PGMap& pgmap, offline_pg_report *report); void _maximize_ok_to_stop_set( const set<int>& orig_osds, unsigned max, const OSDMap& osdmap, const PGMap& pgmap, offline_pg_report *report); utime_t started_at; std::atomic<bool> pgmap_ready; std::set<int32_t> reported_osds; void maybe_ready(int32_t osd_id); SafeTimer timer; bool shutting_down; Context *tick_event; void tick(); void schedule_tick_locked(double delay_sec); class OSDPerfMetricCollectorListener : public MetricListener { public: OSDPerfMetricCollectorListener(DaemonServer *server) : server(server) { } void handle_query_updated() override { server->handle_osd_perf_metric_query_updated(); } private: DaemonServer *server; }; OSDPerfMetricCollectorListener osd_perf_metric_collector_listener; OSDPerfMetricCollector osd_perf_metric_collector; void handle_osd_perf_metric_query_updated(); class MDSPerfMetricCollectorListener : public MetricListener { public: MDSPerfMetricCollectorListener(DaemonServer *server) : server(server) { } void handle_query_updated() override { server->handle_mds_perf_metric_query_updated(); } private: DaemonServer *server; }; MDSPerfMetricCollectorListener mds_perf_metric_collector_listener; MDSPerfMetricCollector mds_perf_metric_collector; void handle_mds_perf_metric_query_updated(); void handle_metric_payload(const OSDMetricPayload &payload) { osd_perf_metric_collector.process_reports(payload); } void handle_metric_payload(const MDSMetricPayload &payload) { mds_perf_metric_collector.process_reports(payload); } void handle_metric_payload(const UnknownMetricPayload &payload) { ceph_abort(); } struct HandlePayloadVisitor : public boost::static_visitor<void> { DaemonServer *server; HandlePayloadVisitor(DaemonServer *server) : server(server) { } template <typename MetricPayload> inline void operator()(const MetricPayload &payload) const { server->handle_metric_payload(payload); } }; void update_task_status(DaemonKey key, const std::map<std::string,std::string>& task_status); public: int init(uint64_t gid, entity_addrvec_t client_addrs); void shutdown(); entity_addrvec_t get_myaddrs() const; DaemonServer(MonClient *monc_, Finisher &finisher_, DaemonStateIndex &daemon_state_, ClusterState &cluster_state_, PyModuleRegistry &py_modules_, LogChannelRef cl, LogChannelRef auditcl); ~DaemonServer() override; bool ms_dispatch2(const ceph::ref_t<Message>& m) override; int ms_handle_authentication(Connection *con) override; bool ms_handle_reset(Connection *con) override; void ms_handle_remote_reset(Connection *con) override {} bool ms_handle_refused(Connection *con) override; void fetch_missing_metadata(const DaemonKey& key, const entity_addr_t& addr); bool handle_open(const ceph::ref_t<MMgrOpen>& m); bool handle_update(const ceph::ref_t<MMgrUpdate>& m); bool handle_close(const ceph::ref_t<MMgrClose>& m); bool handle_report(const ceph::ref_t<MMgrReport>& m); bool handle_command(const ceph::ref_t<MCommand>& m); bool handle_command(const ceph::ref_t<MMgrCommand>& m); bool _handle_command(std::shared_ptr<CommandContext>& cmdctx); void send_report(); void got_service_map(); void got_mgr_map(); void adjust_pgs(); void _send_configure(ConnectionRef c); MetricQueryID add_osd_perf_query( const OSDPerfMetricQuery &query, const std::optional<OSDPerfMetricLimit> &limit); int remove_osd_perf_query(MetricQueryID query_id); int get_osd_perf_counters(OSDPerfCollector *collector); MetricQueryID add_mds_perf_query(const MDSPerfMetricQuery &query, const std::optional<MDSPerfMetricLimit> &limit); int remove_mds_perf_query(MetricQueryID query_id); void reregister_mds_perf_queries(); int get_mds_perf_counters(MDSPerfCollector *collector); virtual const char** get_tracked_conf_keys() const override; virtual void handle_conf_change(const ConfigProxy& conf, const std::set <std::string> &changed) override; void schedule_tick(double delay_sec); void log_access_denied(std::shared_ptr<CommandContext>& cmdctx, MgrSession* session, std::stringstream& ss); void dump_pg_ready(ceph::Formatter *f); }; #endif
9,430
28.750789
86
h
null
ceph-main/src/mgr/DaemonState.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2016 John Spray <[email protected]> * * 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 DAEMON_STATE_H_ #define DAEMON_STATE_H_ #include <map> #include <string> #include <memory> #include <set> #include <boost/circular_buffer.hpp> #include "include/str_map.h" #include "msg/msg_types.h" // For PerfCounterType #include "messages/MMgrReport.h" #include "DaemonKey.h" namespace ceph { class Formatter; } // An instance of a performance counter type, within // a particular daemon. class PerfCounterInstance { class DataPoint { public: utime_t t; uint64_t v; DataPoint(utime_t t_, uint64_t v_) : t(t_), v(v_) {} }; class AvgDataPoint { public: utime_t t; uint64_t s; uint64_t c; AvgDataPoint(utime_t t_, uint64_t s_, uint64_t c_) : t(t_), s(s_), c(c_) {} }; boost::circular_buffer<DataPoint> buffer; boost::circular_buffer<AvgDataPoint> avg_buffer; uint64_t get_current() const; public: const boost::circular_buffer<DataPoint> & get_data() const { return buffer; } const DataPoint& get_latest_data() const { return buffer.back(); } const boost::circular_buffer<AvgDataPoint> & get_data_avg() const { return avg_buffer; } const AvgDataPoint& get_latest_data_avg() const { return avg_buffer.back(); } void push(utime_t t, uint64_t const &v); void push_avg(utime_t t, uint64_t const &s, uint64_t const &c); PerfCounterInstance(enum perfcounter_type_d type) { if (type & PERFCOUNTER_LONGRUNAVG) avg_buffer = boost::circular_buffer<AvgDataPoint>(20); else buffer = boost::circular_buffer<DataPoint>(20); }; }; typedef std::map<std::string, PerfCounterType> PerfCounterTypes; // Performance counters for one daemon class DaemonPerfCounters { public: // The record of perf stat types, shared between daemons PerfCounterTypes &types; explicit DaemonPerfCounters(PerfCounterTypes &types_) : types(types_) {} std::map<std::string, PerfCounterInstance> instances; void update(const MMgrReport& report); void clear() { instances.clear(); } }; // The state that we store about one daemon class DaemonState { public: ceph::mutex lock = ceph::make_mutex("DaemonState::lock"); DaemonKey key; // The hostname where daemon was last seen running (extracted // from the metadata) std::string hostname; // The metadata (hostname, version, etc) sent from the daemon std::map<std::string, std::string> metadata; /// device ids -> devname, derived from metadata[device_ids] std::map<std::string,std::string> devices; /// device ids -> by-path, derived from metadata[device_ids] std::map<std::string,std::string> devices_bypath; // TODO: this can be generalized to other daemons std::vector<DaemonHealthMetric> daemon_health_metrics; // Ephemeral state bool service_daemon = false; utime_t service_status_stamp; std::map<std::string, std::string> service_status; utime_t last_service_beacon; // running config std::map<std::string,std::map<int32_t,std::string>> config; // mon config values we failed to set std::map<std::string,std::string> ignored_mon_config; // compiled-in config defaults (rarely used, so we leave them encoded!) bufferlist config_defaults_bl; std::map<std::string,std::string> config_defaults; // The perf counters received in MMgrReport messages DaemonPerfCounters perf_counters; explicit DaemonState(PerfCounterTypes &types_) : perf_counters(types_) { } void set_metadata(const std::map<std::string,std::string>& m); const std::map<std::string,std::string>& _get_config_defaults(); }; typedef std::shared_ptr<DaemonState> DaemonStatePtr; typedef std::map<DaemonKey, DaemonStatePtr> DaemonStateCollection; struct DeviceState : public RefCountedObject { std::string devid; /// (server,devname,path) std::set<std::tuple<std::string,std::string,std::string>> attachments; std::set<DaemonKey> daemons; std::map<std::string,std::string> metadata; ///< persistent metadata std::pair<utime_t,utime_t> life_expectancy; ///< when device failure is expected utime_t life_expectancy_stamp; ///< when life expectency was recorded float wear_level = -1; ///< SSD wear level (negative if unknown) void set_metadata(std::map<std::string,std::string>&& m); void set_life_expectancy(utime_t from, utime_t to, utime_t now); void rm_life_expectancy(); void set_wear_level(float wear); std::string get_life_expectancy_str(utime_t now) const; /// true of we can be safely forgotten/removed from memory bool empty() const { return daemons.empty() && metadata.empty(); } void dump(Formatter *f) const; void print(std::ostream& out) const; private: FRIEND_MAKE_REF(DeviceState); DeviceState(const std::string& n) : devid(n) {} }; /** * Fuse the collection of per-daemon metadata from Ceph into * a view that can be queried by service type, ID or also * by server (aka fqdn). */ class DaemonStateIndex { private: mutable ceph::shared_mutex lock = ceph::make_shared_mutex("DaemonStateIndex", true, true, true); std::map<std::string, DaemonStateCollection> by_server; DaemonStateCollection all; std::set<DaemonKey> updating; std::map<std::string,ceph::ref_t<DeviceState>> devices; void _erase(const DaemonKey& dmk); ceph::ref_t<DeviceState> _get_or_create_device(const std::string& dev) { auto em = devices.try_emplace(dev, nullptr); auto& d = em.first->second; if (em.second) { d = ceph::make_ref<DeviceState>(dev); } return d; } void _erase_device(const ceph::ref_t<DeviceState>& d) { devices.erase(d->devid); } public: DaemonStateIndex() {} // FIXME: shouldn't really be public, maybe construct DaemonState // objects internally to avoid this. PerfCounterTypes types; void insert(DaemonStatePtr dm); void _insert(DaemonStatePtr dm); bool exists(const DaemonKey &key) const; DaemonStatePtr get(const DaemonKey &key); void rm(const DaemonKey &key); void _rm(const DaemonKey &key); // Note that these return by value rather than reference to avoid // callers needing to stay in lock while using result. Callers must // still take the individual DaemonState::lock on each entry though. DaemonStateCollection get_by_server(const std::string &hostname) const; DaemonStateCollection get_by_service(const std::string &svc_name) const; DaemonStateCollection get_all() const {return all;} template<typename Callback, typename...Args> auto with_daemons_by_server(Callback&& cb, Args&&... args) const -> decltype(cb(by_server, std::forward<Args>(args)...)) { std::shared_lock l{lock}; return std::forward<Callback>(cb)(by_server, std::forward<Args>(args)...); } template<typename Callback, typename...Args> bool with_device(const std::string& dev, Callback&& cb, Args&&... args) const { std::shared_lock l{lock}; auto p = devices.find(dev); if (p == devices.end()) { return false; } std::forward<Callback>(cb)(*p->second, std::forward<Args>(args)...); return true; } template<typename Callback, typename...Args> bool with_device_write(const std::string& dev, Callback&& cb, Args&&... args) { std::unique_lock l{lock}; auto p = devices.find(dev); if (p == devices.end()) { return false; } std::forward<Callback>(cb)(*p->second, std::forward<Args>(args)...); if (p->second->empty()) { _erase_device(p->second); } return true; } template<typename Callback, typename...Args> void with_device_create(const std::string& dev, Callback&& cb, Args&&... args) { std::unique_lock l{lock}; auto d = _get_or_create_device(dev); std::forward<Callback>(cb)(*d, std::forward<Args>(args)...); } template<typename Callback, typename...Args> void with_devices(Callback&& cb, Args&&... args) const { std::shared_lock l{lock}; for (auto& i : devices) { std::forward<Callback>(cb)(*i.second, std::forward<Args>(args)...); } } template<typename CallbackInitial, typename Callback, typename...Args> void with_devices2(CallbackInitial&& cbi, // with lock taken Callback&& cb, // for each device Args&&... args) const { std::shared_lock l{lock}; cbi(); for (auto& i : devices) { std::forward<Callback>(cb)(*i.second, std::forward<Args>(args)...); } } void list_devids_by_server(const std::string& server, std::set<std::string> *ls) { auto m = get_by_server(server); for (auto& i : m) { std::lock_guard l(i.second->lock); for (auto& j : i.second->devices) { ls->insert(j.first); } } } void notify_updating(const DaemonKey &k) { std::unique_lock l{lock}; updating.insert(k); } void clear_updating(const DaemonKey &k) { std::unique_lock l{lock}; updating.erase(k); } bool is_updating(const DaemonKey &k) { std::shared_lock l{lock}; return updating.count(k) > 0; } void update_metadata(DaemonStatePtr state, const std::map<std::string,std::string>& meta) { // remove and re-insert in case the device metadata changed std::unique_lock l{lock}; _rm(state->key); { std::lock_guard l2{state->lock}; state->set_metadata(meta); } _insert(state); } /** * Remove state for all daemons of this type whose names are * not present in `names_exist`. Use this function when you have * a cluster map and want to ensure that anything absent in the map * is also absent in this class. */ void cull(const std::string& svc_name, const std::set<std::string>& names_exist); void cull_services(const std::set<std::string>& types_exist); }; #endif
10,143
26.342318
83
h
null
ceph-main/src/mgr/Gil.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 SUSE LLC * * 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. * */ #pragma once #include <cassert> #include <functional> struct _ts; typedef struct _ts PyThreadState; #include <pthread.h> /** * Wrap PyThreadState to carry a record of which POSIX thread * the thread state relates to. This allows the Gil class to * validate that we're being used from the right thread. */ class SafeThreadState { public: explicit SafeThreadState(PyThreadState *ts_); SafeThreadState() : ts(nullptr), thread(0) { } PyThreadState *ts; pthread_t thread; void set(PyThreadState *ts_) { ts = ts_; thread = pthread_self(); } }; // // Use one of these in any scope in which you need to hold Python's // Global Interpreter Lock. // // Do *not* nest these, as a second GIL acquire will deadlock (see // https://docs.python.org/2/c-api/init.html#c.PyEval_RestoreThread) // // If in doubt, explicitly put a scope around the block of code you // know you need the GIL in. // // See the comment in Gil::Gil for when to set new_thread == true // class Gil { public: Gil(const Gil&) = delete; Gil& operator=(const Gil&) = delete; Gil(SafeThreadState &ts, bool new_thread = false); ~Gil(); private: SafeThreadState &pThreadState; PyThreadState *pNewThreadState = nullptr; }; // because the Python runtime could relinquish the GIL when performing GC // and re-acquire it afterwards, we should enforce following locking policy: // 1. do not acquire locks when holding the GIL, use a without_gil or // without_gil_t to guard the code which acquires non-gil locks. // 2. always hold a GIL when calling python functions, for example, when // constructing a PyFormatter instance. // // a wrapper that provides a convenient RAII-style mechinary for acquiring // and releasing GIL, like the macros of Py_BEGIN_ALLOW_THREADS and // Py_END_ALLOW_THREADS. struct without_gil_t { without_gil_t(); ~without_gil_t(); void release_gil(); void acquire_gil(); private: PyThreadState *save = nullptr; friend struct with_gil_t; }; struct with_gil_t { with_gil_t(without_gil_t& allow_threads); ~with_gil_t(); private: without_gil_t& allow_threads; }; // invoke func with GIL acquired template<typename Func> auto with_gil(without_gil_t& no_gil, Func&& func) { with_gil_t gil{no_gil}; return std::invoke(std::forward<Func>(func)); } template<typename Func> auto without_gil(Func&& func) { without_gil_t no_gil; return std::invoke(std::forward<Func>(func)); }
2,834
23.652174
76
h
null
ceph-main/src/mgr/MDSPerfMetricCollector.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MGR_MDS_PERF_COLLECTOR_H #define CEPH_MGR_MDS_PERF_COLLECTOR_H #include "mgr/MetricCollector.h" #include "mgr/MDSPerfMetricTypes.h" // MDS performance query class class MDSPerfMetricCollector : public MetricCollector<MDSPerfMetricQuery, MDSPerfMetricLimit, MDSPerfMetricKey, MDSPerfMetrics> { private: std::set<mds_rank_t> delayed_ranks; struct timespec last_updated_mono; void get_delayed_ranks(std::set<mds_rank_t> *ranks); void get_last_updated(utime_t *ts); public: MDSPerfMetricCollector(MetricListener &listener); void process_reports(const MetricPayload &payload) override; int get_counters(PerfCollector *collector) override; }; #endif // CEPH_MGR_MDS_PERF_COLLECTOR_H
838
27.931034
84
h
null
ceph-main/src/mgr/MDSPerfMetricTypes.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MGR_MDS_PERF_METRIC_TYPES_H #define CEPH_MGR_MDS_PERF_METRIC_TYPES_H #include <regex> #include <vector> #include <iostream> #include "include/denc.h" #include "include/stringify.h" #include "mds/mdstypes.h" #include "mgr/Types.h" typedef std::vector<std::string> MDSPerfMetricSubKey; // array of regex match typedef std::vector<MDSPerfMetricSubKey> MDSPerfMetricKey; enum class MDSPerfMetricSubKeyType : uint8_t { MDS_RANK = 0, CLIENT_ID = 1, }; struct MDSPerfMetricSubKeyDescriptor { MDSPerfMetricSubKeyType type = static_cast<MDSPerfMetricSubKeyType>(-1); std::string regex_str; std::regex regex; bool is_supported() const { switch (type) { case MDSPerfMetricSubKeyType::MDS_RANK: case MDSPerfMetricSubKeyType::CLIENT_ID: return true; default: return false; } } MDSPerfMetricSubKeyDescriptor() { } MDSPerfMetricSubKeyDescriptor(MDSPerfMetricSubKeyType type, const std::string &regex_str) : type(type), regex_str(regex_str) { } bool operator<(const MDSPerfMetricSubKeyDescriptor &other) const { if (type < other.type) { return true; } if (type > other.type) { return false; } return regex_str < other.regex_str; } DENC(MDSPerfMetricSubKeyDescriptor, v, p) { DENC_START(1, 1, p); denc(v.type, p); denc(v.regex_str, p); DENC_FINISH(p); } }; WRITE_CLASS_DENC(MDSPerfMetricSubKeyDescriptor) std::ostream& operator<<(std::ostream& os, const MDSPerfMetricSubKeyDescriptor &d); typedef std::vector<MDSPerfMetricSubKeyDescriptor> MDSPerfMetricKeyDescriptor; template<> struct denc_traits<MDSPerfMetricKeyDescriptor> { static constexpr bool supported = true; static constexpr bool bounded = false; static constexpr bool featured = false; static constexpr bool need_contiguous = true; static void bound_encode(const MDSPerfMetricKeyDescriptor& v, size_t& p) { p += sizeof(uint32_t); const auto size = v.size(); if (size) { size_t per = 0; denc(v.front(), per); p += per * size; } } static void encode(const MDSPerfMetricKeyDescriptor& v, ceph::buffer::list::contiguous_appender& p) { denc_varint(v.size(), p); for (auto& i : v) { denc(i, p); } } static void decode(MDSPerfMetricKeyDescriptor& v, ceph::buffer::ptr::const_iterator& p) { unsigned num; denc_varint(num, p); v.clear(); v.reserve(num); for (unsigned i=0; i < num; ++i) { MDSPerfMetricSubKeyDescriptor d; denc(d, p); if (!d.is_supported()) { v.clear(); return; } try { d.regex = d.regex_str.c_str(); } catch (const std::regex_error& e) { v.clear(); return; } if (d.regex.mark_count() == 0) { v.clear(); return; } v.push_back(std::move(d)); } } }; enum class MDSPerformanceCounterType : uint8_t { CAP_HIT_METRIC = 0, READ_LATENCY_METRIC = 1, WRITE_LATENCY_METRIC = 2, METADATA_LATENCY_METRIC = 3, DENTRY_LEASE_METRIC = 4, OPENED_FILES_METRIC = 5, PINNED_ICAPS_METRIC = 6, OPENED_INODES_METRIC = 7, READ_IO_SIZES_METRIC = 8, WRITE_IO_SIZES_METRIC = 9, AVG_READ_LATENCY_METRIC = 10, STDEV_READ_LATENCY_METRIC = 11, AVG_WRITE_LATENCY_METRIC = 12, STDEV_WRITE_LATENCY_METRIC = 13, AVG_METADATA_LATENCY_METRIC = 14, STDEV_METADATA_LATENCY_METRIC = 15, }; struct MDSPerformanceCounterDescriptor { MDSPerformanceCounterType type = static_cast<MDSPerformanceCounterType>(-1); bool is_supported() const { switch(type) { case MDSPerformanceCounterType::CAP_HIT_METRIC: case MDSPerformanceCounterType::READ_LATENCY_METRIC: case MDSPerformanceCounterType::WRITE_LATENCY_METRIC: case MDSPerformanceCounterType::METADATA_LATENCY_METRIC: case MDSPerformanceCounterType::DENTRY_LEASE_METRIC: case MDSPerformanceCounterType::OPENED_FILES_METRIC: case MDSPerformanceCounterType::PINNED_ICAPS_METRIC: case MDSPerformanceCounterType::OPENED_INODES_METRIC: case MDSPerformanceCounterType::READ_IO_SIZES_METRIC: case MDSPerformanceCounterType::WRITE_IO_SIZES_METRIC: case MDSPerformanceCounterType::AVG_READ_LATENCY_METRIC: case MDSPerformanceCounterType::STDEV_READ_LATENCY_METRIC: case MDSPerformanceCounterType::AVG_WRITE_LATENCY_METRIC: case MDSPerformanceCounterType::STDEV_WRITE_LATENCY_METRIC: case MDSPerformanceCounterType::AVG_METADATA_LATENCY_METRIC: case MDSPerformanceCounterType::STDEV_METADATA_LATENCY_METRIC: return true; default: return false; } } MDSPerformanceCounterDescriptor() { } MDSPerformanceCounterDescriptor(MDSPerformanceCounterType type) : type(type) { } bool operator<(const MDSPerformanceCounterDescriptor &other) const { return type < other.type; } bool operator==(const MDSPerformanceCounterDescriptor &other) const { return type == other.type; } bool operator!=(const MDSPerformanceCounterDescriptor &other) const { return type != other.type; } DENC(MDSPerformanceCounterDescriptor, v, p) { DENC_START(1, 1, p); denc(v.type, p); DENC_FINISH(p); } void pack_counter(const PerformanceCounter &c, ceph::buffer::list *bl) const; void unpack_counter(ceph::buffer::list::const_iterator& bl, PerformanceCounter *c) const; }; WRITE_CLASS_DENC(MDSPerformanceCounterDescriptor) std::ostream& operator<<(std::ostream &os, const MDSPerformanceCounterDescriptor &d); typedef std::vector<MDSPerformanceCounterDescriptor> MDSPerformanceCounterDescriptors; template<> struct denc_traits<MDSPerformanceCounterDescriptors> { static constexpr bool supported = true; static constexpr bool bounded = false; static constexpr bool featured = false; static constexpr bool need_contiguous = true; static void bound_encode(const MDSPerformanceCounterDescriptors& v, size_t& p) { p += sizeof(uint32_t); const auto size = v.size(); if (size) { size_t per = 0; denc(v.front(), per); p += per * size; } } static void encode(const MDSPerformanceCounterDescriptors& v, ceph::buffer::list::contiguous_appender& p) { denc_varint(v.size(), p); for (auto& i : v) { denc(i, p); } } static void decode(MDSPerformanceCounterDescriptors& v, ceph::buffer::ptr::const_iterator& p) { unsigned num; denc_varint(num, p); v.clear(); v.reserve(num); for (unsigned i=0; i < num; ++i) { MDSPerformanceCounterDescriptor d; denc(d, p); if (d.is_supported()) { v.push_back(std::move(d)); } } } }; struct MDSPerfMetricLimit { MDSPerformanceCounterDescriptor order_by; uint64_t max_count; MDSPerfMetricLimit() { } MDSPerfMetricLimit(const MDSPerformanceCounterDescriptor &order_by, uint64_t max_count) : order_by(order_by), max_count(max_count) { } bool operator<(const MDSPerfMetricLimit &other) const { if (order_by != other.order_by) { return order_by < other.order_by; } return max_count < other.max_count; } DENC(MDSPerfMetricLimit, v, p) { DENC_START(1, 1, p); denc(v.order_by, p); denc(v.max_count, p); DENC_FINISH(p); } }; WRITE_CLASS_DENC(MDSPerfMetricLimit) std::ostream &operator<<(std::ostream &os, const MDSPerfMetricLimit &limit); typedef std::set<MDSPerfMetricLimit> MDSPerfMetricLimits; struct MDSPerfMetricQuery { MDSPerfMetricKeyDescriptor key_descriptor; MDSPerformanceCounterDescriptors performance_counter_descriptors; MDSPerfMetricQuery() { } MDSPerfMetricQuery(const MDSPerfMetricKeyDescriptor &key_descriptor, const MDSPerformanceCounterDescriptors &performance_counter_descriptors) : key_descriptor(key_descriptor), performance_counter_descriptors(performance_counter_descriptors) { } bool operator<(const MDSPerfMetricQuery &other) const { if (key_descriptor < other.key_descriptor) { return true; } if (key_descriptor > other.key_descriptor) { return false; } return performance_counter_descriptors < other.performance_counter_descriptors; } template <typename L> bool get_key(L&& get_sub_key, MDSPerfMetricKey *key) const { for (auto &sub_key_descriptor : key_descriptor) { MDSPerfMetricSubKey sub_key; if (!get_sub_key(sub_key_descriptor, &sub_key)) { return false; } key->push_back(sub_key); } return true; } void get_performance_counter_descriptors(MDSPerformanceCounterDescriptors *descriptors) const { *descriptors = performance_counter_descriptors; } template <typename L> void update_counters(L &&update_counter, PerformanceCounters *counters) const { auto it = counters->begin(); for (auto &descriptor : performance_counter_descriptors) { // TODO: optimize if (it == counters->end()) { counters->push_back(PerformanceCounter()); it = std::prev(counters->end()); } update_counter(descriptor, &(*it)); it++; } } DENC(MDSPerfMetricQuery, v, p) { DENC_START(1, 1, p); denc(v.key_descriptor, p); denc(v.performance_counter_descriptors, p); DENC_FINISH(p); } void pack_counters(const PerformanceCounters &counters, ceph::buffer::list *bl) const; }; WRITE_CLASS_DENC(MDSPerfMetricQuery) std::ostream &operator<<(std::ostream &os, const MDSPerfMetricQuery &query); struct MDSPerfCollector : PerfCollector { std::map<MDSPerfMetricKey, PerformanceCounters> counters; std::set<mds_rank_t> delayed_ranks; utime_t last_updated_mono; MDSPerfCollector(MetricQueryID query_id) : PerfCollector(query_id) { } }; struct MDSPerfMetrics { MDSPerformanceCounterDescriptors performance_counter_descriptors; std::map<MDSPerfMetricKey, ceph::buffer::list> group_packed_performance_counters; DENC(MDSPerfMetrics, v, p) { DENC_START(1, 1, p); denc(v.performance_counter_descriptors, p); denc(v.group_packed_performance_counters, p); DENC_FINISH(p); } }; struct MDSPerfMetricReport { std::map<MDSPerfMetricQuery, MDSPerfMetrics> reports; // set of active ranks that have delayed (stale) metrics std::set<mds_rank_t> rank_metrics_delayed; DENC(MDSPerfMetricReport, v, p) { DENC_START(1, 1, p); denc(v.reports, p); denc(v.rank_metrics_delayed, p); DENC_FINISH(p); } }; WRITE_CLASS_DENC(MDSPerfMetrics) WRITE_CLASS_DENC(MDSPerfMetricReport) #endif // CEPH_MGR_MDS_PERF_METRIC_TYPES_H
10,607
27.826087
97
h
null
ceph-main/src/mgr/MetricCollector.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MGR_METRIC_COLLECTOR_H #define CEPH_MGR_METRIC_COLLECTOR_H #include <map> #include <set> #include <tuple> #include <vector> #include <utility> #include <algorithm> #include "common/ceph_mutex.h" #include "msg/Message.h" #include "mgr/Types.h" #include "mgr/MetricTypes.h" class MMgrReport; template <typename Query, typename Limit, typename Key, typename Report> class MetricCollector { public: virtual ~MetricCollector() { } using Limits = std::set<Limit>; MetricCollector(MetricListener &listener); MetricQueryID add_query(const Query &query, const std::optional<Limit> &limit); int remove_query(MetricQueryID query_id); void remove_all_queries(); void reregister_queries(); std::map<Query, Limits> get_queries() const { std::lock_guard locker(lock); std::map<Query, Limits> result; for (auto& [query, limits] : queries) { auto result_it = result.insert({query, {}}).first; if (is_limited(limits)) { for (auto& limit : limits) { if (limit.second) { result_it->second.insert(*limit.second); } } } } return result; } virtual void process_reports(const MetricPayload &payload) = 0; virtual int get_counters(PerfCollector *collector) = 0; protected: typedef std::optional<Limit> OptionalLimit; typedef std::map<MetricQueryID, OptionalLimit> QueryIDLimit; typedef std::map<Query, QueryIDLimit> Queries; typedef std::map<MetricQueryID, std::map<Key, PerformanceCounters>> Counters; typedef std::function<void(PerformanceCounter *, const PerformanceCounter &)> UpdateCallback; mutable ceph::mutex lock = ceph::make_mutex("mgr::metric::collector::lock"); Queries queries; Counters counters; void process_reports_generic(const std::map<Query, Report> &reports, UpdateCallback callback); int get_counters_generic(MetricQueryID query_id, std::map<Key, PerformanceCounters> *counters); private: MetricListener &listener; MetricQueryID next_query_id = 0; bool is_limited(const std::map<MetricQueryID, OptionalLimit> &limits) const { return std::any_of(begin(limits), end(limits), [](auto &limits) { return limits.second.has_value(); }); } }; #endif // CEPH_MGR_METRIC_COLLECTOR_H
2,367
26.534884
97
h
null
ceph-main/src/mgr/MetricTypes.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MGR_METRIC_TYPES_H #define CEPH_MGR_METRIC_TYPES_H #include <boost/variant.hpp> #include "include/denc.h" #include "include/ceph_features.h" #include "mgr/OSDPerfMetricTypes.h" #include "mgr/MDSPerfMetricTypes.h" enum class MetricReportType { METRIC_REPORT_TYPE_OSD = 0, METRIC_REPORT_TYPE_MDS = 1, }; struct OSDMetricPayload { static const MetricReportType METRIC_REPORT_TYPE = MetricReportType::METRIC_REPORT_TYPE_OSD; std::map<OSDPerfMetricQuery, OSDPerfMetricReport> report; OSDMetricPayload() { } OSDMetricPayload(const std::map<OSDPerfMetricQuery, OSDPerfMetricReport> &report) : report(report) { } DENC(OSDMetricPayload, v, p) { DENC_START(1, 1, p); denc(v.report, p); DENC_FINISH(p); } }; struct MDSMetricPayload { static const MetricReportType METRIC_REPORT_TYPE = MetricReportType::METRIC_REPORT_TYPE_MDS; MDSPerfMetricReport metric_report; MDSMetricPayload() { } MDSMetricPayload(const MDSPerfMetricReport &metric_report) : metric_report(metric_report) { } DENC(MDSMetricPayload, v, p) { DENC_START(1, 1, p); denc(v.metric_report, p); DENC_FINISH(p); } }; struct UnknownMetricPayload { static const MetricReportType METRIC_REPORT_TYPE = static_cast<MetricReportType>(-1); UnknownMetricPayload() { } DENC(UnknownMetricPayload, v, p) { ceph_abort(); } }; WRITE_CLASS_DENC(OSDMetricPayload) WRITE_CLASS_DENC(MDSMetricPayload) WRITE_CLASS_DENC(UnknownMetricPayload) typedef boost::variant<OSDMetricPayload, MDSMetricPayload, UnknownMetricPayload> MetricPayload; class EncodeMetricPayloadVisitor : public boost::static_visitor<void> { public: explicit EncodeMetricPayloadVisitor(ceph::buffer::list &bl) : m_bl(bl) { } template <typename MetricPayload> inline void operator()(const MetricPayload &payload) const { using ceph::encode; encode(static_cast<uint32_t>(MetricPayload::METRIC_REPORT_TYPE), m_bl); encode(payload, m_bl); } private: ceph::buffer::list &m_bl; }; class DecodeMetricPayloadVisitor : public boost::static_visitor<void> { public: DecodeMetricPayloadVisitor(ceph::buffer::list::const_iterator &iter) : m_iter(iter) { } template <typename MetricPayload> inline void operator()(MetricPayload &payload) const { using ceph::decode; decode(payload, m_iter); } private: ceph::buffer::list::const_iterator &m_iter; }; struct MetricReportMessage { MetricPayload payload; MetricReportMessage(const MetricPayload &payload = UnknownMetricPayload()) : payload(payload) { } bool should_encode(uint64_t features) const { if (!HAVE_FEATURE(features, SERVER_PACIFIC) && boost::get<MDSMetricPayload>(&payload)) { return false; } return true; } void encode(ceph::buffer::list &bl) const { boost::apply_visitor(EncodeMetricPayloadVisitor(bl), payload); } void decode(ceph::buffer::list::const_iterator &iter) { using ceph::decode; uint32_t metric_report_type; decode(metric_report_type, iter); switch (static_cast<MetricReportType>(metric_report_type)) { case MetricReportType::METRIC_REPORT_TYPE_OSD: payload = OSDMetricPayload(); break; case MetricReportType::METRIC_REPORT_TYPE_MDS: payload = MDSMetricPayload(); break; default: payload = UnknownMetricPayload(); break; } boost::apply_visitor(DecodeMetricPayloadVisitor(iter), payload); } }; WRITE_CLASS_ENCODER(MetricReportMessage); // variant for sending configure message to mgr clients enum MetricConfigType { METRIC_CONFIG_TYPE_OSD = 0, METRIC_CONFIG_TYPE_MDS = 1, }; struct OSDConfigPayload { static const MetricConfigType METRIC_CONFIG_TYPE = MetricConfigType::METRIC_CONFIG_TYPE_OSD; std::map<OSDPerfMetricQuery, OSDPerfMetricLimits> config; OSDConfigPayload() { } OSDConfigPayload(const std::map<OSDPerfMetricQuery, OSDPerfMetricLimits> &config) : config(config) { } DENC(OSDConfigPayload, v, p) { DENC_START(1, 1, p); denc(v.config, p); DENC_FINISH(p); } }; struct MDSConfigPayload { static const MetricConfigType METRIC_CONFIG_TYPE = MetricConfigType::METRIC_CONFIG_TYPE_MDS; std::map<MDSPerfMetricQuery, MDSPerfMetricLimits> config; MDSConfigPayload() { } MDSConfigPayload(const std::map<MDSPerfMetricQuery, MDSPerfMetricLimits> &config) : config(config) { } DENC(MDSConfigPayload, v, p) { DENC_START(1, 1, p); denc(v.config, p); DENC_FINISH(p); } }; struct UnknownConfigPayload { static const MetricConfigType METRIC_CONFIG_TYPE = static_cast<MetricConfigType>(-1); UnknownConfigPayload() { } DENC(UnknownConfigPayload, v, p) { ceph_abort(); } }; WRITE_CLASS_DENC(OSDConfigPayload) WRITE_CLASS_DENC(MDSConfigPayload) WRITE_CLASS_DENC(UnknownConfigPayload) typedef boost::variant<OSDConfigPayload, MDSConfigPayload, UnknownConfigPayload> ConfigPayload; class EncodeConfigPayloadVisitor : public boost::static_visitor<void> { public: explicit EncodeConfigPayloadVisitor(ceph::buffer::list &bl) : m_bl(bl) { } template <typename ConfigPayload> inline void operator()(const ConfigPayload &payload) const { using ceph::encode; encode(static_cast<uint32_t>(ConfigPayload::METRIC_CONFIG_TYPE), m_bl); encode(payload, m_bl); } private: ceph::buffer::list &m_bl; }; class DecodeConfigPayloadVisitor : public boost::static_visitor<void> { public: DecodeConfigPayloadVisitor(ceph::buffer::list::const_iterator &iter) : m_iter(iter) { } template <typename ConfigPayload> inline void operator()(ConfigPayload &payload) const { using ceph::decode; decode(payload, m_iter); } private: ceph::buffer::list::const_iterator &m_iter; }; struct MetricConfigMessage { ConfigPayload payload; MetricConfigMessage(const ConfigPayload &payload = UnknownConfigPayload()) : payload(payload) { } bool should_encode(uint64_t features) const { if (!HAVE_FEATURE(features, SERVER_PACIFIC) && boost::get<MDSConfigPayload>(&payload)) { return false; } return true; } void encode(ceph::buffer::list &bl) const { boost::apply_visitor(EncodeConfigPayloadVisitor(bl), payload); } void decode(ceph::buffer::list::const_iterator &iter) { using ceph::decode; uint32_t metric_config_type; decode(metric_config_type, iter); switch (metric_config_type) { case MetricConfigType::METRIC_CONFIG_TYPE_OSD: payload = OSDConfigPayload(); break; case MetricConfigType::METRIC_CONFIG_TYPE_MDS: payload = MDSConfigPayload(); break; default: payload = UnknownConfigPayload(); break; } boost::apply_visitor(DecodeConfigPayloadVisitor(iter), payload); } }; WRITE_CLASS_ENCODER(MetricConfigMessage); #endif // CEPH_MGR_METRIC_TYPES_H
6,982
24.118705
94
h
null
ceph-main/src/mgr/Mgr.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2014 John Spray <[email protected]> * * 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_MGR_H_ #define CEPH_MGR_H_ // Python.h comes first because otherwise it clobbers ceph's assert #include <Python.h> #include "mds/FSMap.h" #include "messages/MFSMap.h" #include "msg/Messenger.h" #include "auth/Auth.h" #include "common/Finisher.h" #include "mon/MgrMap.h" #include "DaemonServer.h" #include "PyModuleRegistry.h" #include "DaemonState.h" #include "ClusterState.h" class MCommand; class MMgrDigest; class MLog; class MServiceMap; class Objecter; class Client; class Mgr : public AdminSocketHook { protected: MonClient *monc; Objecter *objecter; Client *client; Messenger *client_messenger; mutable ceph::mutex lock = ceph::make_mutex("Mgr::lock"); Finisher finisher; // Track receipt of initial data during startup ceph::condition_variable fs_map_cond; bool digest_received; ceph::condition_variable digest_cond; PyModuleRegistry *py_module_registry; DaemonStateIndex daemon_state; ClusterState cluster_state; DaemonServer server; LogChannelRef clog; LogChannelRef audit_clog; std::map<std::string, std::string> pre_init_store; void load_all_metadata(); std::map<std::string, std::string> load_store(); void init(); bool initialized; bool initializing; public: Mgr(MonClient *monc_, const MgrMap& mgrmap, PyModuleRegistry *py_module_registry_, Messenger *clientm_, Objecter *objecter_, Client *client_, LogChannelRef clog_, LogChannelRef audit_clog_); ~Mgr(); bool is_initialized() const {return initialized;} entity_addrvec_t get_server_addrs() const { return server.get_myaddrs(); } void handle_mgr_digest(ceph::ref_t<MMgrDigest> m); void handle_fs_map(ceph::ref_t<MFSMap> m); void handle_osd_map(); void handle_log(ceph::ref_t<MLog> m); void handle_service_map(ceph::ref_t<MServiceMap> m); void handle_mon_map(); bool got_mgr_map(const MgrMap& m); bool ms_dispatch2(const ceph::ref_t<Message>& m); void background_init(Context *completion); void shutdown(); void handle_signal(int signum); std::map<std::string, std::string> get_services() const; int call( std::string_view command, const cmdmap_t& cmdmap, const bufferlist& inbl, Formatter *f, std::ostream& errss, ceph::buffer::list& out) override; }; /** * Context for completion of metadata mon commands: take * the result and stash it in DaemonStateIndex */ class MetadataUpdate : public Context { private: DaemonStateIndex &daemon_state; DaemonKey key; std::map<std::string, std::string> defaults; public: bufferlist outbl; std::string outs; MetadataUpdate(DaemonStateIndex &daemon_state_, const DaemonKey &key_) : daemon_state(daemon_state_), key(key_) { daemon_state.notify_updating(key); } void set_default(const std::string &k, const std::string &v) { defaults[k] = v; } void finish(int r) override; }; #endif
3,325
21.937931
72
h
null
ceph-main/src/mgr/MgrCap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MGRCAP_H #define CEPH_MGRCAP_H #include <iosfwd> #include "include/common_fwd.h" #include "include/types.h" #include "common/entity_name.h" static const __u8 MGR_CAP_R = (1 << 1); // read static const __u8 MGR_CAP_W = (1 << 2); // write static const __u8 MGR_CAP_X = (1 << 3); // execute static const __u8 MGR_CAP_ANY = 0xff; // * struct mgr_rwxa_t { __u8 val = 0U; mgr_rwxa_t() {} explicit mgr_rwxa_t(__u8 v) : val(v) {} mgr_rwxa_t& operator=(__u8 v) { val = v; return *this; } operator __u8() const { return val; } }; std::ostream& operator<<(std::ostream& out, const mgr_rwxa_t& p); struct MgrCapGrantConstraint { enum MatchType { MATCH_TYPE_NONE, MATCH_TYPE_EQUAL, MATCH_TYPE_PREFIX, MATCH_TYPE_REGEX }; MatchType match_type = MATCH_TYPE_NONE; std::string value; MgrCapGrantConstraint() {} MgrCapGrantConstraint(MatchType match_type, std::string value) : match_type(match_type), value(value) { } }; std::ostream& operator<<(std::ostream& out, const MgrCapGrantConstraint& c); struct MgrCapGrant { /* * A grant can come in one of four forms: * * - a blanket allow ('allow rw', 'allow *') * - this will match against any service and the read/write/exec flags * in the mgr code. semantics of what X means are somewhat ad hoc. * * - a service allow ('allow service mds rw') * - this will match against a specific service and the r/w/x flags. * * - a module allow ('allow module rbd_support rw, allow module rbd_support with pool=rbd rw') * - this will match against a specific python add-on module and the r/w/x * flags. * * - a profile ('profile read-only, profile rbd pool=rbd') * - this will match against specific MGR-enforced semantics of what * this type of user should need to do. examples include 'read-write', * 'read-only', 'crash'. * * - a command ('allow command foo', 'allow command bar with arg1=val1 arg2 prefix val2') * this includes the command name (the prefix string) * * The command, module, and profile caps can also accept an optional * key/value map. If not provided, all command arguments and module * meta-arguments are allowed. If a key/value pair is specified, that * argument must be present and must match the provided constraint. */ typedef std::map<std::string, MgrCapGrantConstraint> Arguments; std::string service; std::string module; std::string profile; std::string command; Arguments arguments; // restrict by network std::string network; // these are filled in by parse_network(), called by MgrCap::parse() entity_addr_t network_parsed; unsigned network_prefix = 0; bool network_valid = true; void parse_network(); mgr_rwxa_t allow; // explicit grants that a profile grant expands to; populated as // needed by expand_profile() (via is_match()) and cached here. mutable std::list<MgrCapGrant> profile_grants; void expand_profile(std::ostream *err=nullptr) const; MgrCapGrant() : allow(0) {} MgrCapGrant(std::string&& service, std::string&& module, std::string&& profile, std::string&& command, Arguments&& arguments, mgr_rwxa_t allow) : service(std::move(service)), module(std::move(module)), profile(std::move(profile)), command(std::move(command)), arguments(std::move(arguments)), allow(allow) { } bool validate_arguments( const std::map<std::string, std::string>& arguments) const; /** * check if given request parameters match our constraints * * @param cct context * @param name entity name * @param service service (if any) * @param module module (if any) * @param command command (if any) * @param arguments profile/module/command args (if any) * @return bits we allow */ mgr_rwxa_t get_allowed( CephContext *cct, EntityName name, const std::string& service, const std::string& module, const std::string& command, const std::map<std::string, std::string>& arguments) const; bool is_allow_all() const { return (allow == MGR_CAP_ANY && service.empty() && module.empty() && profile.empty() && command.empty()); } }; std::ostream& operator<<(std::ostream& out, const MgrCapGrant& g); struct MgrCap { std::string text; std::vector<MgrCapGrant> grants; MgrCap() {} explicit MgrCap(const std::vector<MgrCapGrant> &g) : grants(g) {} std::string get_str() const { return text; } bool is_allow_all() const; void set_allow_all(); bool parse(const std::string& str, std::ostream *err=NULL); /** * check if we are capable of something * * This method actually checks a description of a particular operation against * what the capability has specified. * * @param service service name * @param module module name * @param command command id * @param arguments * @param op_may_read whether the operation may need to read * @param op_may_write whether the operation may need to write * @param op_may_exec whether the operation may exec * @return true if the operation is allowed, false otherwise */ bool is_capable(CephContext *cct, EntityName name, const std::string& service, const std::string& module, const std::string& command, const std::map<std::string, std::string>& arguments, bool op_may_read, bool op_may_write, bool op_may_exec, const entity_addr_t& addr) const; void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<MgrCap*>& ls); }; WRITE_CLASS_ENCODER(MgrCap) std::ostream& operator<<(std::ostream& out, const MgrCap& cap); #endif // CEPH_MGRCAP_H
6,053
28.970297
97
h
null
ceph-main/src/mgr/MgrClient.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2016 John Spray <[email protected]> * * 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 MGR_CLIENT_H_ #define MGR_CLIENT_H_ #include <boost/variant.hpp> #include "msg/Connection.h" #include "msg/Dispatcher.h" #include "mon/MgrMap.h" #include "mgr/DaemonHealthMetric.h" #include "messages/MMgrReport.h" #include "mgr/MetricTypes.h" #include "common/perf_counters.h" #include "common/Timer.h" #include "common/CommandTable.h" class MMgrMap; class MMgrConfigure; class MMgrClose; class Messenger; class MCommandReply; class MPGStats; class MonMap; class MgrSessionState { public: // Which performance counters have we already transmitted schema for? std::set<std::string> declared; // Our connection to the mgr ConnectionRef con; }; class MgrCommand : public CommandOp { public: std::string name; bool tell = false; explicit MgrCommand(ceph_tid_t t) : CommandOp(t) {} MgrCommand() : CommandOp() {} }; class MgrClient : public Dispatcher { protected: CephContext *cct; MgrMap map; Messenger *msgr; MonMap *monmap; std::unique_ptr<MgrSessionState> session; ceph::mutex lock = ceph::make_mutex("MgrClient::lock"); ceph::condition_variable shutdown_cond; uint32_t stats_period = 0; uint32_t stats_threshold = 0; SafeTimer timer; CommandTable<MgrCommand> command_table; using clock_t = ceph::mono_clock; clock_t::time_point last_connect_attempt; uint64_t last_config_bl_version = 0; Context *report_callback = nullptr; Context *connect_retry_callback = nullptr; // If provided, use this to compose an MPGStats to send with // our reports (hook for use by OSD) std::function<MPGStats*()> pgstats_cb; std::function<void(const ConfigPayload &)> set_perf_queries_cb; std::function<MetricPayload()> get_perf_report_cb; // for service registration and beacon bool service_daemon = false; bool daemon_dirty_status = false; bool task_dirty_status = false; bool need_metadata_update = true; std::string service_name, daemon_name; std::map<std::string,std::string> daemon_metadata; std::map<std::string,std::string> daemon_status; std::map<std::string,std::string> task_status; std::vector<DaemonHealthMetric> daemon_health_metrics; void reconnect(); void _send_open(); void _send_update(); // In pre-luminous clusters, the ceph-mgr service is absent or optional, // so we must not block in start_command waiting for it. bool mgr_optional = false; public: MgrClient(CephContext *cct_, Messenger *msgr_, MonMap *monmap); void set_messenger(Messenger *msgr_) { msgr = msgr_; } void init(); void shutdown(); void set_mgr_optional(bool optional_) {mgr_optional = optional_;} bool ms_dispatch2(const ceph::ref_t<Message>& m) override; bool ms_handle_reset(Connection *con) override; void ms_handle_remote_reset(Connection *con) override {} bool ms_handle_refused(Connection *con) override; bool handle_mgr_map(ceph::ref_t<MMgrMap> m); bool handle_mgr_configure(ceph::ref_t<MMgrConfigure> m); bool handle_mgr_close(ceph::ref_t<MMgrClose> m); bool handle_command_reply( uint64_t tid, ceph::buffer::list& data, const std::string& rs, int r); void set_perf_metric_query_cb( std::function<void(const ConfigPayload &)> cb_set, std::function<MetricPayload()> cb_get) { std::lock_guard l(lock); set_perf_queries_cb = cb_set; get_perf_report_cb = cb_get; } void send_pgstats(); void set_pgstats_cb(std::function<MPGStats*()>&& cb_) { std::lock_guard l(lock); pgstats_cb = std::move(cb_); } int start_command( const std::vector<std::string>& cmd, const ceph::buffer::list& inbl, ceph::buffer::list *outbl, std::string *outs, Context *onfinish); int start_tell_command( const std::string& name, const std::vector<std::string>& cmd, const ceph::buffer::list& inbl, ceph::buffer::list *outbl, std::string *outs, Context *onfinish); int update_daemon_metadata( const std::string& service, const std::string& name, const std::map<std::string,std::string>& metadata); int service_daemon_register( const std::string& service, const std::string& name, const std::map<std::string,std::string>& metadata); int service_daemon_update_status( std::map<std::string,std::string>&& status); int service_daemon_update_task_status( std::map<std::string,std::string> &&task_status); void update_daemon_health(std::vector<DaemonHealthMetric>&& metrics); bool is_initialized() const { return initialized; } private: void handle_config_payload(const OSDConfigPayload &payload) { if (set_perf_queries_cb) { set_perf_queries_cb(payload); } } void handle_config_payload(const MDSConfigPayload &payload) { if (set_perf_queries_cb) { set_perf_queries_cb(payload); } } void handle_config_payload(const UnknownConfigPayload &payload) { ceph_abort(); } struct HandlePayloadVisitor : public boost::static_visitor<void> { MgrClient *mgrc; HandlePayloadVisitor(MgrClient *mgrc) : mgrc(mgrc) { } template <typename ConfigPayload> inline void operator()(const ConfigPayload &payload) const { mgrc->handle_config_payload(payload); } }; void _send_stats(); void _send_pgstats(); void _send_report(); bool initialized = false; }; #endif
5,703
25.407407
74
h
null
ceph-main/src/mgr/MgrCommands.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* no guard; may be included multiple times */ // see MonCommands.h COMMAND("pg stat", "show placement group status.", "pg", "r") COMMAND("pg getmap", "get binary pg map to -o/stdout", "pg", "r") COMMAND("pg dump " \ "name=dumpcontents,type=CephChoices,strings=all|summary|sum|delta|pools|osds|pgs|pgs_brief,n=N,req=false", \ "show human-readable versions of pg map (only 'all' valid with plain)", "pg", "r") COMMAND("pg dump_json " \ "name=dumpcontents,type=CephChoices,strings=all|summary|sum|pools|osds|pgs,n=N,req=false", \ "show human-readable version of pg map in json only",\ "pg", "r") COMMAND("pg dump_pools_json", "show pg pools info in json only",\ "pg", "r") COMMAND("pg ls-by-pool " \ "name=poolstr,type=CephString " \ "name=states,type=CephString,n=N,req=false", \ "list pg with pool = [poolname]", "pg", "r") COMMAND("pg ls-by-primary " \ "name=osd,type=CephOsdName " \ "name=pool,type=CephInt,req=false " \ "name=states,type=CephString,n=N,req=false", \ "list pg with primary = [osd]", "pg", "r") COMMAND("pg ls-by-osd " \ "name=osd,type=CephOsdName " \ "name=pool,type=CephInt,req=false " \ "name=states,type=CephString,n=N,req=false", \ "list pg on osd [osd]", "pg", "r") COMMAND("pg ls " \ "name=pool,type=CephInt,req=false " \ "name=states,type=CephString,n=N,req=false", \ "list pg with specific pool, osd, state", "pg", "r") COMMAND("pg dump_stuck " \ "name=stuckops,type=CephChoices,strings=inactive|unclean|stale|undersized|degraded,n=N,req=false " \ "name=threshold,type=CephInt,req=false", "show information about stuck pgs",\ "pg", "r") COMMAND("pg debug " \ "name=debugop,type=CephChoices,strings=unfound_objects_exist|degraded_pgs_exist", \ "show debug info about pgs", "pg", "r") COMMAND("pg scrub name=pgid,type=CephPgid", "start scrub on <pgid>", \ "pg", "rw") COMMAND("pg deep-scrub name=pgid,type=CephPgid", "start deep-scrub on <pgid>", \ "pg", "rw") COMMAND("pg repair name=pgid,type=CephPgid", "start repair on <pgid>", \ "pg", "rw") COMMAND("pg force-recovery name=pgid,type=CephPgid,n=N", "force recovery of <pgid> first", \ "pg", "rw") COMMAND("pg force-backfill name=pgid,type=CephPgid,n=N", "force backfill of <pgid> first", \ "pg", "rw") COMMAND("pg cancel-force-recovery name=pgid,type=CephPgid,n=N", "restore normal recovery priority of <pgid>", \ "pg", "rw") COMMAND("pg cancel-force-backfill name=pgid,type=CephPgid,n=N", "restore normal backfill priority of <pgid>", \ "pg", "rw") // stuff in osd namespace COMMAND("osd perf", \ "print dump of OSD perf summary stats", \ "osd", \ "r") COMMAND("osd df " \ "name=output_method,type=CephChoices,strings=plain|tree,req=false " \ "name=filter_by,type=CephChoices,strings=class|name,req=false " \ "name=filter,type=CephString,req=false", \ "show OSD utilization", "osd", "r") COMMAND("osd blocked-by", \ "print histogram of which OSDs are blocking their peers", \ "osd", "r") COMMAND("osd pool stats " \ "name=pool_name,type=CephPoolname,req=false", "obtain stats from all pools, or from specified pool", "osd", "r") COMMAND("osd pool scrub " \ "name=who,type=CephPoolname,n=N", \ "initiate scrub on pool <who>", \ "osd", "rw") COMMAND("osd pool deep-scrub " \ "name=who,type=CephPoolname,n=N", \ "initiate deep-scrub on pool <who>", \ "osd", "rw") COMMAND("osd pool repair " \ "name=who,type=CephPoolname,n=N", \ "initiate repair on pool <who>", \ "osd", "rw") COMMAND("osd pool force-recovery " \ "name=who,type=CephPoolname,n=N", \ "force recovery of specified pool <who> first", \ "osd", "rw") COMMAND("osd pool force-backfill " \ "name=who,type=CephPoolname,n=N", \ "force backfill of specified pool <who> first", \ "osd", "rw") COMMAND("osd pool cancel-force-recovery " \ "name=who,type=CephPoolname,n=N", \ "restore normal recovery priority of specified pool <who>", \ "osd", "rw") COMMAND("osd pool cancel-force-backfill " \ "name=who,type=CephPoolname,n=N", \ "restore normal recovery priority of specified pool <who>", \ "osd", "rw") COMMAND("osd reweight-by-utilization " \ "name=oload,type=CephInt,req=false " \ "name=max_change,type=CephFloat,req=false " \ "name=max_osds,type=CephInt,req=false " \ "name=no_increasing,type=CephBool,req=false",\ "reweight OSDs by utilization [overload-percentage-for-consideration, default 120]", \ "osd", "rw") COMMAND("osd test-reweight-by-utilization " \ "name=oload,type=CephInt,req=false " \ "name=max_change,type=CephFloat,req=false " \ "name=max_osds,type=CephInt,req=false " \ "name=no_increasing,type=CephBool,req=false",\ "dry run of reweight OSDs by utilization [overload-percentage-for-consideration, default 120]", \ "osd", "r") COMMAND("osd reweight-by-pg " \ "name=oload,type=CephInt,req=false " \ "name=max_change,type=CephFloat,req=false " \ "name=max_osds,type=CephInt,req=false " \ "name=pools,type=CephPoolname,n=N,req=false", \ "reweight OSDs by PG distribution [overload-percentage-for-consideration, default 120]", \ "osd", "rw") COMMAND("osd test-reweight-by-pg " \ "name=oload,type=CephInt,req=false " \ "name=max_change,type=CephFloat,req=false " \ "name=max_osds,type=CephInt,req=false " \ "name=pools,type=CephPoolname,n=N,req=false", \ "dry run of reweight OSDs by PG distribution [overload-percentage-for-consideration, default 120]", \ "osd", "r") COMMAND("osd destroy " \ "name=id,type=CephOsdName " \ "name=force,type=CephBool,req=false " // backward compat synonym for --force "name=yes_i_really_mean_it,type=CephBool,req=false", \ "mark osd as being destroyed. Keeps the ID intact (allowing reuse), " \ "but removes cephx keys, config-key data and lockbox keys, "\ "rendering data permanently unreadable.", \ "osd", "rw") COMMAND("osd purge " \ "name=id,type=CephOsdName " \ "name=force,type=CephBool,req=false " // backward compat synonym for --force "name=yes_i_really_mean_it,type=CephBool,req=false", \ "purge all osd data from the monitors including the OSD id " \ "and CRUSH position", \ "osd", "rw") COMMAND("osd safe-to-destroy name=ids,type=CephString,n=N", "check whether osd(s) can be safely destroyed without reducing data durability", "osd", "r") COMMAND("osd ok-to-stop name=ids,type=CephString,n=N "\ "name=max,type=CephInt,req=false", "check whether osd(s) can be safely stopped without reducing immediate"\ " data availability", "osd", "r") COMMAND("osd scrub " \ "name=who,type=CephString", \ "initiate scrub on osd <who>, or use <all|any> to scrub all", \ "osd", "rw") COMMAND("osd deep-scrub " \ "name=who,type=CephString", \ "initiate deep scrub on osd <who>, or use <all|any> to deep scrub all", \ "osd", "rw") COMMAND("osd repair " \ "name=who,type=CephString", \ "initiate repair on osd <who>, or use <all|any> to repair all", \ "osd", "rw") COMMAND("service dump", "dump service map", "service", "r") COMMAND("service status", "dump service state", "service", "r") COMMAND("config show " \ "name=who,type=CephString name=key,type=CephString,req=false", "Show running configuration", "mgr", "r") COMMAND("config show-with-defaults " \ "name=who,type=CephString", "Show running configuration (including compiled-in defaults)", "mgr", "r") COMMAND("device ls", "Show devices", "mgr", "r") COMMAND("device info name=devid,type=CephString", "Show information about a device", "mgr", "r") COMMAND("device ls-by-daemon name=who,type=CephString", "Show devices associated with a daemon", "mgr", "r") COMMAND("device ls-by-host name=host,type=CephString", "Show devices on a host", "mgr", "r") COMMAND("device set-life-expectancy name=devid,type=CephString "\ "name=from,type=CephString "\ "name=to,type=CephString,req=false", "Set predicted device life expectancy", "mgr", "rw") COMMAND("device rm-life-expectancy name=devid,type=CephString", "Clear predicted device life expectancy", "mgr", "rw")
8,339
38.339623
111
h
null
ceph-main/src/mgr/MgrStandby.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2016 John Spray <[email protected]> * * 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 MGR_STANDBY_H_ #define MGR_STANDBY_H_ #include "auth/Auth.h" #include "common/async/context_pool.h" #include "common/Finisher.h" #include "common/Timer.h" #include "common/LogClient.h" #include "client/Client.h" #include "mon/MonClient.h" #include "osdc/Objecter.h" #include "PyModuleRegistry.h" #include "MgrClient.h" class MMgrMap; class Mgr; class PyModuleConfig; class MgrStandby : public Dispatcher, public md_config_obs_t { public: // config observer bits const char** get_tracked_conf_keys() const override; void handle_conf_change(const ConfigProxy& conf, const std::set <std::string> &changed) override; protected: ceph::async::io_context_pool poolctx; MonClient monc; std::unique_ptr<Messenger> client_messenger; Objecter objecter; Client client; MgrClient mgrc; LogClient log_client; LogChannelRef clog, audit_clog; ceph::mutex lock = ceph::make_mutex("MgrStandby::lock"); Finisher finisher; SafeTimer timer; PyModuleRegistry py_module_registry; std::shared_ptr<Mgr> active_mgr; int orig_argc; const char **orig_argv; std::string state_str(); void handle_mgr_map(ceph::ref_t<MMgrMap> m); void _update_log_config(); void send_beacon(); bool available_in_map; public: MgrStandby(int argc, const char **argv); ~MgrStandby() override; bool ms_dispatch2(const ceph::ref_t<Message>& m) override; bool ms_handle_reset(Connection *con) override { return false; } void ms_handle_remote_reset(Connection *con) override {} bool ms_handle_refused(Connection *con) override; int init(); void shutdown(); void respawn(); int main(std::vector<const char *> args); void tick(); }; #endif
2,111
22.466667
70
h
null
ceph-main/src/mgr/OSDPerfMetricCollector.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef OSD_PERF_METRIC_COLLECTOR_H_ #define OSD_PERF_METRIC_COLLECTOR_H_ #include "mgr/MetricCollector.h" #include "mgr/OSDPerfMetricTypes.h" /** * OSD performance query class. */ class OSDPerfMetricCollector : public MetricCollector<OSDPerfMetricQuery, OSDPerfMetricLimit, OSDPerfMetricKey, OSDPerfMetricReport> { public: OSDPerfMetricCollector(MetricListener &listener); void process_reports(const MetricPayload &payload) override; int get_counters(PerfCollector *collector) override; }; #endif // OSD_PERF_METRIC_COLLECTOR_H_
670
26.958333
84
h
null
ceph-main/src/mgr/OSDPerfMetricTypes.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef OSD_PERF_METRIC_H_ #define OSD_PERF_METRIC_H_ #include "include/denc.h" #include "include/stringify.h" #include "mgr/Types.h" #include <regex> typedef std::vector<std::string> OSDPerfMetricSubKey; // array of regex match typedef std::vector<OSDPerfMetricSubKey> OSDPerfMetricKey; enum class OSDPerfMetricSubKeyType : uint8_t { CLIENT_ID = 0, CLIENT_ADDRESS = 1, POOL_ID = 2, NAMESPACE = 3, OSD_ID = 4, PG_ID = 5, OBJECT_NAME = 6, SNAP_ID = 7, }; struct OSDPerfMetricSubKeyDescriptor { OSDPerfMetricSubKeyType type = static_cast<OSDPerfMetricSubKeyType>(-1); std::string regex_str; std::regex regex; bool is_supported() const { switch (type) { case OSDPerfMetricSubKeyType::CLIENT_ID: case OSDPerfMetricSubKeyType::CLIENT_ADDRESS: case OSDPerfMetricSubKeyType::POOL_ID: case OSDPerfMetricSubKeyType::NAMESPACE: case OSDPerfMetricSubKeyType::OSD_ID: case OSDPerfMetricSubKeyType::PG_ID: case OSDPerfMetricSubKeyType::OBJECT_NAME: case OSDPerfMetricSubKeyType::SNAP_ID: return true; default: return false; } } OSDPerfMetricSubKeyDescriptor() { } OSDPerfMetricSubKeyDescriptor(OSDPerfMetricSubKeyType type, const std::string regex) : type(type), regex_str(regex) { } bool operator<(const OSDPerfMetricSubKeyDescriptor &other) const { if (type < other.type) { return true; } if (type > other.type) { return false; } return regex_str < other.regex_str; } DENC(OSDPerfMetricSubKeyDescriptor, v, p) { DENC_START(1, 1, p); denc(v.type, p); denc(v.regex_str, p); DENC_FINISH(p); } }; WRITE_CLASS_DENC(OSDPerfMetricSubKeyDescriptor) std::ostream& operator<<(std::ostream& os, const OSDPerfMetricSubKeyDescriptor &d); typedef std::vector<OSDPerfMetricSubKeyDescriptor> OSDPerfMetricKeyDescriptor; template<> struct denc_traits<OSDPerfMetricKeyDescriptor> { static constexpr bool supported = true; static constexpr bool bounded = false; static constexpr bool featured = false; static constexpr bool need_contiguous = true; static void bound_encode(const OSDPerfMetricKeyDescriptor& v, size_t& p) { p += sizeof(uint32_t); const auto size = v.size(); if (size) { size_t per = 0; denc(v.front(), per); p += per * size; } } static void encode(const OSDPerfMetricKeyDescriptor& v, ceph::buffer::list::contiguous_appender& p) { denc_varint(v.size(), p); for (auto& i : v) { denc(i, p); } } static void decode(OSDPerfMetricKeyDescriptor& v, ceph::buffer::ptr::const_iterator& p) { unsigned num; denc_varint(num, p); v.clear(); v.reserve(num); for (unsigned i=0; i < num; ++i) { OSDPerfMetricSubKeyDescriptor d; denc(d, p); if (!d.is_supported()) { v.clear(); return; } try { d.regex = d.regex_str.c_str(); } catch (const std::regex_error& e) { v.clear(); return; } if (d.regex.mark_count() == 0) { v.clear(); return; } v.push_back(std::move(d)); } } }; enum class PerformanceCounterType : uint8_t { OPS = 0, WRITE_OPS = 1, READ_OPS = 2, BYTES = 3, WRITE_BYTES = 4, READ_BYTES = 5, LATENCY = 6, WRITE_LATENCY = 7, READ_LATENCY = 8, }; struct PerformanceCounterDescriptor { PerformanceCounterType type = static_cast<PerformanceCounterType>(-1); bool is_supported() const { switch (type) { case PerformanceCounterType::OPS: case PerformanceCounterType::WRITE_OPS: case PerformanceCounterType::READ_OPS: case PerformanceCounterType::BYTES: case PerformanceCounterType::WRITE_BYTES: case PerformanceCounterType::READ_BYTES: case PerformanceCounterType::LATENCY: case PerformanceCounterType::WRITE_LATENCY: case PerformanceCounterType::READ_LATENCY: return true; default: return false; } } PerformanceCounterDescriptor() { } PerformanceCounterDescriptor(PerformanceCounterType type) : type(type) { } bool operator<(const PerformanceCounterDescriptor &other) const { return type < other.type; } bool operator==(const PerformanceCounterDescriptor &other) const { return type == other.type; } bool operator!=(const PerformanceCounterDescriptor &other) const { return type != other.type; } DENC(PerformanceCounterDescriptor, v, p) { DENC_START(1, 1, p); denc(v.type, p); DENC_FINISH(p); } void pack_counter(const PerformanceCounter &c, ceph::buffer::list *bl) const; void unpack_counter(ceph::buffer::list::const_iterator& bl, PerformanceCounter *c) const; }; WRITE_CLASS_DENC(PerformanceCounterDescriptor) std::ostream& operator<<(std::ostream& os, const PerformanceCounterDescriptor &d); typedef std::vector<PerformanceCounterDescriptor> PerformanceCounterDescriptors; template<> struct denc_traits<PerformanceCounterDescriptors> { static constexpr bool supported = true; static constexpr bool bounded = false; static constexpr bool featured = false; static constexpr bool need_contiguous = true; static void bound_encode(const PerformanceCounterDescriptors& v, size_t& p) { p += sizeof(uint32_t); const auto size = v.size(); if (size) { size_t per = 0; denc(v.front(), per); p += per * size; } } static void encode(const PerformanceCounterDescriptors& v, ceph::buffer::list::contiguous_appender& p) { denc_varint(v.size(), p); for (auto& i : v) { denc(i, p); } } static void decode(PerformanceCounterDescriptors& v, ceph::buffer::ptr::const_iterator& p) { unsigned num; denc_varint(num, p); v.clear(); v.reserve(num); for (unsigned i=0; i < num; ++i) { PerformanceCounterDescriptor d; denc(d, p); if (d.is_supported()) { v.push_back(std::move(d)); } } } }; struct OSDPerfMetricLimit { PerformanceCounterDescriptor order_by; uint64_t max_count = 0; OSDPerfMetricLimit() { } OSDPerfMetricLimit(const PerformanceCounterDescriptor &order_by, uint64_t max_count) : order_by(order_by), max_count(max_count) { } bool operator<(const OSDPerfMetricLimit &other) const { if (order_by != other.order_by) { return order_by < other.order_by; } return max_count < other.max_count; } DENC(OSDPerfMetricLimit, v, p) { DENC_START(1, 1, p); denc(v.order_by, p); denc(v.max_count, p); DENC_FINISH(p); } }; WRITE_CLASS_DENC(OSDPerfMetricLimit) std::ostream& operator<<(std::ostream& os, const OSDPerfMetricLimit &limit); typedef std::set<OSDPerfMetricLimit> OSDPerfMetricLimits; struct OSDPerfMetricQuery { bool operator<(const OSDPerfMetricQuery &other) const { if (key_descriptor < other.key_descriptor) { return true; } if (key_descriptor > other.key_descriptor) { return false; } return (performance_counter_descriptors < other.performance_counter_descriptors); } OSDPerfMetricQuery() { } OSDPerfMetricQuery( const OSDPerfMetricKeyDescriptor &key_descriptor, const PerformanceCounterDescriptors &performance_counter_descriptors) : key_descriptor(key_descriptor), performance_counter_descriptors(performance_counter_descriptors) { } template <typename L> bool get_key(L&& get_sub_key, OSDPerfMetricKey *key) const { for (auto &sub_key_descriptor : key_descriptor) { OSDPerfMetricSubKey sub_key; if (!get_sub_key(sub_key_descriptor, &sub_key)) { return false; } key->push_back(sub_key); } return true; } DENC(OSDPerfMetricQuery, v, p) { DENC_START(1, 1, p); denc(v.key_descriptor, p); denc(v.performance_counter_descriptors, p); DENC_FINISH(p); } void get_performance_counter_descriptors( PerformanceCounterDescriptors *descriptors) const { *descriptors = performance_counter_descriptors; } template <typename L> void update_counters(L &&update_counter, PerformanceCounters *counters) const { auto it = counters->begin(); for (auto &descriptor : performance_counter_descriptors) { // TODO: optimize if (it == counters->end()) { counters->push_back(PerformanceCounter()); it = std::prev(counters->end()); } update_counter(descriptor, &(*it)); it++; } } void pack_counters(const PerformanceCounters &counters, ceph::buffer::list *bl) const; OSDPerfMetricKeyDescriptor key_descriptor; PerformanceCounterDescriptors performance_counter_descriptors; }; WRITE_CLASS_DENC(OSDPerfMetricQuery) struct OSDPerfCollector : PerfCollector { std::map<OSDPerfMetricKey, PerformanceCounters> counters; OSDPerfCollector(MetricQueryID query_id) : PerfCollector(query_id) { } }; std::ostream& operator<<(std::ostream& os, const OSDPerfMetricQuery &query); struct OSDPerfMetricReport { PerformanceCounterDescriptors performance_counter_descriptors; std::map<OSDPerfMetricKey, ceph::buffer::list> group_packed_performance_counters; DENC(OSDPerfMetricReport, v, p) { DENC_START(1, 1, p); denc(v.performance_counter_descriptors, p); denc(v.group_packed_performance_counters, p); DENC_FINISH(p); } }; WRITE_CLASS_DENC(OSDPerfMetricReport) #endif // OSD_PERF_METRIC_H_
9,625
25.66482
88
h
null
ceph-main/src/mgr/PyFormatter.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2015 Red Hat Inc * * Author: John Spray <[email protected]> * * 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 PY_FORMATTER_H_ #define PY_FORMATTER_H_ // Python.h comes first because otherwise it clobbers ceph's assert #include <Python.h> #include <stack> #include <string> #include <string_view> #include <sstream> #include <memory> #include <list> #include "common/Formatter.h" #include "include/ceph_assert.h" class PyFormatter : public ceph::Formatter { public: PyFormatter (const PyFormatter&) = delete; PyFormatter& operator= (const PyFormatter&) = delete; PyFormatter(bool pretty = false, bool array = false) { // It is forbidden to instantiate me outside of the GIL, // because I construct python objects right away // Initialise cursor to an empty dict if (!array) { root = cursor = PyDict_New(); } else { root = cursor = PyList_New(0); } } ~PyFormatter() override { cursor = NULL; Py_DECREF(root); root = NULL; } // Obscure, don't care. void open_array_section_in_ns(std::string_view name, const char *ns) override {ceph_abort();} void open_object_section_in_ns(std::string_view name, const char *ns) override {ceph_abort();} void reset() override { const bool array = PyList_Check(root); Py_DECREF(root); if (array) { root = cursor = PyList_New(0); } else { root = cursor = PyDict_New(); } } void set_status(int status, const char* status_name) override {} void output_header() override {}; void output_footer() override {}; void enable_line_break() override {}; void open_array_section(std::string_view name) override; void open_object_section(std::string_view name) override; void close_section() override { ceph_assert(cursor != root); ceph_assert(!stack.empty()); cursor = stack.top(); stack.pop(); } void dump_bool(std::string_view name, bool b) override; void dump_unsigned(std::string_view name, uint64_t u) override; void dump_int(std::string_view name, int64_t u) override; void dump_float(std::string_view name, double d) override; void dump_string(std::string_view name, std::string_view s) override; std::ostream& dump_stream(std::string_view name) override; void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; void flush(std::ostream& os) override { // This class is not a serializer: this doesn't make sense ceph_abort(); } int get_len() const override { // This class is not a serializer: this doesn't make sense ceph_abort(); return 0; } void write_raw_data(const char *data) override { // This class is not a serializer: this doesn't make sense ceph_abort(); } PyObject *get() { finish_pending_streams(); Py_INCREF(root); return root; } void finish_pending_streams(); private: PyObject *root; PyObject *cursor; std::stack<PyObject *> stack; void dump_pyobject(std::string_view name, PyObject *p); class PendingStream { public: PyObject *cursor; std::string name; std::stringstream stream; }; std::list<std::shared_ptr<PendingStream> > pending_streams; }; class PyJSONFormatter : public JSONFormatter { public: PyObject *get(); PyJSONFormatter (const PyJSONFormatter&) = default; PyJSONFormatter(bool pretty=false, bool is_array=false) : JSONFormatter(pretty) { if(is_array) { open_array_section(""); } else { open_object_section(""); } } private: using json_formatter = JSONFormatter; template <class T> void add_value(std::string_view name, T val); void add_value(std::string_view name, std::string_view val, bool quoted); }; #endif
4,101
24.012195
112
h
null
ceph-main/src/mgr/PyModule.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 John Spray <[email protected]> * * 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. */ #pragma once #include <map> #include <memory> #include <string> #include <vector> #include <boost/optional.hpp> #include "common/ceph_mutex.h" #include "Python.h" #include "Gil.h" #include "mon/MgrMap.h" class MonClient; std::string handle_pyerror(bool generate_crash_dump = false, std::string module = {}, std::string caller = {}); std::string peek_pyerror(); /** * A Ceph CLI command description provided from a Python module */ class ModuleCommand { public: std::string cmdstring; std::string helpstring; std::string perm; bool polling; // Call the ActivePyModule of this name to handle the command std::string module_name; }; class PyModule { mutable ceph::mutex lock = ceph::make_mutex("PyModule::lock"); private: const std::string module_name; std::string get_site_packages(); int load_subclass_of(const char* class_name, PyObject** py_class); // Did the MgrMap identify this module as one that should run? bool enabled = false; // Did the MgrMap flag this module as always on? bool always_on = false; // Did we successfully import this python module and look up symbols? // (i.e. is it possible to instantiate a MgrModule subclass instance?) bool loaded = false; // Did the module identify itself as being able to run? // (i.e. should we expect instantiating and calling serve() to work?) bool can_run = false; // Did the module encounter an unexpected error while running? // (e.g. throwing an exception from serve()) bool failed = false; // Populated if loaded, can_run or failed indicates a problem std::string error_string; // Helper for loading MODULE_OPTIONS and COMMANDS members int walk_dict_list( const std::string &attr_name, std::function<int(PyObject*)> fn); int load_commands(); std::vector<ModuleCommand> commands; int register_options(PyObject *cls); int load_options(); std::map<std::string, MgrMap::ModuleOption> options; int load_notify_types(); std::set<std::string> notify_types; public: static std::string mgr_store_prefix; SafeThreadState pMyThreadState; PyObject *pClass = nullptr; PyObject *pStandbyClass = nullptr; explicit PyModule(const std::string &module_name_) : module_name(module_name_) { } ~PyModule(); bool is_option(const std::string &option_name); const std::map<std::string,MgrMap::ModuleOption>& get_options() const { return options; } PyObject *get_typed_option_value( const std::string& option, const std::string& value); int load(PyThreadState *pMainThreadState); static PyObject* init_ceph_logger(); static PyObject* init_ceph_module(); void set_enabled(const bool enabled_) { enabled = enabled_; } void set_always_on(const bool always_on_) { always_on = always_on_; } /** * Extend `out` with the contents of `this->commands` */ void get_commands(std::vector<ModuleCommand> *out) const { std::lock_guard l(lock); ceph_assert(out != nullptr); out->insert(out->end(), commands.begin(), commands.end()); } /** * Mark the module as failed, recording the reason in the error * string. */ void fail(const std::string &reason) { std::lock_guard l(lock); failed = true; error_string = reason; } bool is_enabled() const { std::lock_guard l(lock); return enabled || always_on; } bool is_failed() const { std::lock_guard l(lock) ; return failed; } bool is_loaded() const { std::lock_guard l(lock) ; return loaded; } bool is_always_on() const { std::lock_guard l(lock) ; return always_on; } bool should_notify(const std::string& notify_type) const { return notify_types.count(notify_type); } const std::string &get_name() const { std::lock_guard l(lock) ; return module_name; } const std::string &get_error_string() const { std::lock_guard l(lock) ; return error_string; } bool get_can_run() const { std::lock_guard l(lock) ; return can_run; } }; typedef std::shared_ptr<PyModule> PyModuleRef; class PyModuleConfig { public: mutable ceph::mutex lock = ceph::make_mutex("PyModuleConfig::lock"); std::map<std::string, std::string> config; PyModuleConfig(); PyModuleConfig(PyModuleConfig &mconfig); ~PyModuleConfig(); std::pair<int, std::string> set_config( MonClient *monc, const std::string &module_name, const std::string &key, const std::optional<std::string>& val); };
4,863
24.072165
75
h
null
ceph-main/src/mgr/PyModuleRegistry.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 John Spray <[email protected]> * * 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. */ #pragma once // First because it includes Python.h #include "PyModule.h" #include <string> #include <map> #include <set> #include <memory> #include "common/LogClient.h" #include "ActivePyModules.h" #include "StandbyPyModules.h" class MgrSession; /** * This class is responsible for setting up the python runtime environment * and importing the python modules. * * It is *not* responsible for constructing instances of their BaseMgrModule * subclasses: that is the job of ActiveMgrModule, which consumes the class * references that we load here. */ class PyModuleRegistry { private: mutable ceph::mutex lock = ceph::make_mutex("PyModuleRegistry::lock"); LogChannelRef clog; std::map<std::string, PyModuleRef> modules; std::multimap<std::string, entity_addrvec_t> clients; std::unique_ptr<ActivePyModules> active_modules; std::unique_ptr<StandbyPyModules> standby_modules; PyThreadState *pMainThreadState; // We have our own copy of MgrMap, because we are constructed // before ClusterState exists. MgrMap mgr_map; /** * Discover python modules from local disk */ std::vector<std::string> probe_modules(const std::string &path) const; PyModuleConfig module_config; public: void handle_config(const std::string &k, const std::string &v); void handle_config_notify(); void update_kv_data( const std::string prefix, bool incremental, const map<std::string, std::optional<bufferlist>, std::less<>>& data) { ceph_assert(active_modules); active_modules->update_kv_data(prefix, incremental, data); } /** * Get references to all modules (whether they have loaded and/or * errored) or not. */ auto get_modules() const { std::vector<PyModuleRef> modules_out; std::lock_guard l(lock); for (const auto &i : modules) { modules_out.push_back(i.second); } return modules_out; } explicit PyModuleRegistry(LogChannelRef clog_) : clog(clog_) {} /** * @return true if the mgrmap has changed such that the service needs restart */ bool handle_mgr_map(const MgrMap &mgr_map_); bool have_standby_modules() const { return !!standby_modules; } void init(); void upgrade_config( MonClient *monc, const std::map<std::string, std::string> &old_config); void active_start( DaemonStateIndex &ds, ClusterState &cs, const std::map<std::string, std::string> &kv_store, bool mon_provides_kv_sub, MonClient &mc, LogChannelRef clog_, LogChannelRef audit_clog_, Objecter &objecter_, Client &client_, Finisher &f, DaemonServer &server); void standby_start(MonClient &mc, Finisher &f); bool is_standby_running() const { return standby_modules != nullptr; } void active_shutdown(); void shutdown(); std::vector<MonCommand> get_commands() const; std::vector<ModuleCommand> get_py_commands() const; /** * Get the specified module. The module does not have to be * loaded or runnable. * * Returns an empty reference if it does not exist. */ PyModuleRef get_module(const std::string &module_name) { std::lock_guard l(lock); auto module_iter = modules.find(module_name); if (module_iter == modules.end()) { return {}; } return module_iter->second; } /** * Pass through command to the named module for execution. * * The command must exist in the COMMANDS reported by the module. If it * doesn't then this will abort. * * If ActivePyModules has not been instantiated yet then this will * return EAGAIN. */ int handle_command( const ModuleCommand& module_command, const MgrSession& session, const cmdmap_t &cmdmap, const bufferlist &inbuf, std::stringstream *ds, std::stringstream *ss); /** * Pass through health checks reported by modules, and report any * modules that have failed (i.e. unhandled exceptions in serve()) */ void get_health_checks(health_check_map_t *checks); void get_progress_events(map<std::string,ProgressEvent> *events) { if (active_modules) { active_modules->get_progress_events(events); } } // FIXME: breaking interface so that I don't have to go rewrite all // the places that call into these (for now) // >>> void notify_all(const std::string &notify_type, const std::string &notify_id) { if (active_modules) { active_modules->notify_all(notify_type, notify_id); } } void notify_all(const LogEntry &log_entry) { if (active_modules) { active_modules->notify_all(log_entry); } } bool should_notify(const std::string& name, const std::string& notify_type) { return modules.at(name)->should_notify(notify_type); } std::map<std::string, std::string> get_services() const { ceph_assert(active_modules); return active_modules->get_services(); } void register_client(std::string_view name, entity_addrvec_t addrs, bool replace) { std::lock_guard l(lock); auto n = std::string(name); if (replace) { clients.erase(n); } clients.emplace(n, std::move(addrs)); } void unregister_client(std::string_view name, const entity_addrvec_t& addrs) { std::lock_guard l(lock); auto itp = clients.equal_range(std::string(name)); for (auto it = itp.first; it != itp.second; ++it) { if (it->second == addrs) { clients.erase(it); return; } } } auto get_clients() const { std::lock_guard l(lock); return clients; } bool is_module_active(const std::string &name) { ceph_assert(active_modules); return active_modules->module_exists(name); } auto& get_active_module_finisher(const std::string &name) { ceph_assert(active_modules); return active_modules->get_module_finisher(name); } // <<< (end of ActivePyModules cheeky call-throughs) };
6,354
25.045082
83
h
null
ceph-main/src/mgr/ServiceMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include <string> #include <map> #include <list> #include <sstream> #include "include/utime.h" #include "include/buffer.h" #include "msg/msg_types.h" namespace ceph { class Formatter; } struct ServiceMap { struct Daemon { uint64_t gid = 0; entity_addr_t addr; epoch_t start_epoch = 0; ///< epoch first registered utime_t start_stamp; ///< timestamp daemon started/registered std::map<std::string,std::string> metadata; ///< static metadata std::map<std::string,std::string> task_status; ///< running task status void encode(ceph::buffer::list& bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<Daemon*>& ls); }; struct Service { std::map<std::string,Daemon> daemons; std::string summary; ///< summary status std::string for 'ceph -s' void encode(ceph::buffer::list& bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<Service*>& ls); std::string get_summary() const; bool has_running_tasks() const; std::string get_task_summary(const std::string_view task_prefix) const; void count_metadata(const std::string& field, std::map<std::string,int> *out) const; }; epoch_t epoch = 0; utime_t modified; std::map<std::string,Service> services; void encode(ceph::buffer::list& bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<ServiceMap*>& ls); std::pair<Daemon*,bool> get_daemon(const std::string& service, const std::string& daemon) { auto& s = services[service]; auto [d, added] = s.daemons.try_emplace(daemon); return {&d->second, added}; } bool rm_daemon(const std::string& service, const std::string& daemon) { auto p = services.find(service); if (p == services.end()) { return false; } auto q = p->second.daemons.find(daemon); if (q == p->second.daemons.end()) { return false; } p->second.daemons.erase(q); if (p->second.daemons.empty()) { services.erase(p); } return true; } static inline bool is_normal_ceph_entity(std::string_view type) { if (type == "osd" || type == "client" || type == "mon" || type == "mds" || type == "mgr") { return true; } return false; } }; WRITE_CLASS_ENCODER_FEATURES(ServiceMap) WRITE_CLASS_ENCODER_FEATURES(ServiceMap::Service) WRITE_CLASS_ENCODER_FEATURES(ServiceMap::Daemon)
2,838
27.969388
75
h
null
ceph-main/src/mgr/StandbyPyModules.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2016 John Spray <[email protected]> * * 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. */ #pragma once #include <string> #include <map> #include <Python.h> #include "common/Thread.h" #include "common/ceph_mutex.h" #include "mgr/Gil.h" #include "mon/MonClient.h" #include "mon/MgrMap.h" #include "mgr/PyModuleRunner.h" class Finisher; /** * State that is read by all modules running in standby mode */ class StandbyPyModuleState { mutable ceph::mutex lock = ceph::make_mutex("StandbyPyModuleState::lock"); MgrMap mgr_map; PyModuleConfig &module_config; MonClient &monc; public: StandbyPyModuleState(PyModuleConfig &module_config_, MonClient &monc_) : module_config(module_config_), monc(monc_) {} void set_mgr_map(const MgrMap &mgr_map_) { std::lock_guard l(lock); mgr_map = mgr_map_; } // MonClient does all its own locking so we're happy to hand out // references. MonClient &get_monc() {return monc;}; template<typename Callback, typename...Args> void with_mgr_map(Callback&& cb, Args&&...args) const { std::lock_guard l(lock); std::forward<Callback>(cb)(mgr_map, std::forward<Args>(args)...); } template<typename Callback, typename...Args> auto with_config(Callback&& cb, Args&&... args) const -> decltype(cb(module_config, std::forward<Args>(args)...)) { std::lock_guard l(lock); return std::forward<Callback>(cb)(module_config, std::forward<Args>(args)...); } }; class StandbyPyModule : public PyModuleRunner { StandbyPyModuleState &state; public: StandbyPyModule( StandbyPyModuleState &state_, const PyModuleRef &py_module_, LogChannelRef clog_) : PyModuleRunner(py_module_, clog_), state(state_) { } bool get_config(const std::string &key, std::string *value) const; bool get_store(const std::string &key, std::string *value) const; std::string get_active_uri() const; entity_addrvec_t get_myaddrs() const { return state.get_monc().get_myaddrs(); } int load(); }; class StandbyPyModules { private: mutable ceph::mutex lock = ceph::make_mutex("StandbyPyModules::lock"); std::map<std::string, std::unique_ptr<StandbyPyModule>> modules; StandbyPyModuleState state; LogChannelRef clog; Finisher &finisher; public: StandbyPyModules( const MgrMap &mgr_map_, PyModuleConfig &module_config, LogChannelRef clog_, MonClient &monc, Finisher &f); void start_one(PyModuleRef py_module); void shutdown(); void handle_mgr_map(const MgrMap &mgr_map) { state.set_mgr_map(mgr_map); } };
2,931
20.880597
82
h
null
ceph-main/src/mgr/TTLCache.h
#pragma once #include <atomic> #include <chrono> #include <functional> #include <map> #include <memory> #include <string> #include <vector> #include "PyUtil.h" template <class Key, class Value> class Cache { private: std::atomic<uint64_t> hits, misses; protected: unsigned int capacity; Cache(unsigned int size = UINT16_MAX) : hits{0}, misses{0}, capacity{size} {}; std::map<Key, Value> content; std::vector<std::string> allowed_keys = {"osd_map", "pg_dump", "pg_stats"}; void mark_miss() { misses++; } void mark_hit() { hits++; } unsigned int get_misses() { return misses; } unsigned int get_hits() { return hits; } void throw_key_not_found(Key key) { std::stringstream ss; ss << "Key " << key << " couldn't be found\n"; throw std::out_of_range(ss.str()); } public: void insert(Key key, Value value) { mark_miss(); if (content.size() < capacity) { content.insert({key, value}); } } Value get(Key key, bool count_hit = true) { if (count_hit) { mark_hit(); } return content[key]; } void erase(Key key) { content.erase(content.find(key)); } void clear() { content.clear(); } bool exists(Key key) { return content.find(key) != content.end(); } std::pair<uint64_t, uint64_t> get_hit_miss_ratio() { return std::make_pair(hits.load(), misses.load()); } bool is_cacheable(Key key) { for (auto k : allowed_keys) { if (key == k) return true; } return false; } int size() { return content.size(); } ~Cache(){}; }; using ttl_time_point = std::chrono::time_point<std::chrono::steady_clock>; template <class Key, class Value> class TTLCacheBase : public Cache<Key, std::pair<Value, ttl_time_point>> { private: uint16_t ttl; float ttl_spread_ratio; using value_type = std::pair<Value, ttl_time_point>; using cache = Cache<Key, value_type>; protected: Value get_value(Key key, bool count_hit = true); ttl_time_point get_value_time_point(Key key); bool exists(Key key); bool expired(Key key); void finish_get(Key key); void finish_erase(Key key); void throw_key_not_found(Key key); public: TTLCacheBase(uint16_t ttl_ = 0, uint16_t size = UINT16_MAX, float spread = 0.25) : Cache<Key, value_type>(size), ttl{ttl_}, ttl_spread_ratio{spread} {} ~TTLCacheBase(){}; void insert(Key key, Value value); Value get(Key key); void erase(Key key); void clear(); uint16_t get_ttl() { return ttl; }; void set_ttl(uint16_t ttl); }; template <class Key, class Value> class TTLCache : public TTLCacheBase<Key, Value> { public: TTLCache(uint16_t ttl_ = 0, uint16_t size = UINT16_MAX, float spread = 0.25) : TTLCacheBase<Key, Value>(ttl_, size, spread) {} ~TTLCache(){}; }; template <class Key> class TTLCache<Key, PyObject*> : public TTLCacheBase<Key, PyObject*> { public: TTLCache(uint16_t ttl_ = 0, uint16_t size = UINT16_MAX, float spread = 0.25) : TTLCacheBase<Key, PyObject*>(ttl_, size, spread) {} ~TTLCache(){}; PyObject* get(Key key); void erase(Key key); private: using ttl_base = TTLCacheBase<Key, PyObject*>; }; #include "TTLCache.cc"
3,154
24.650407
80
h
null
ceph-main/src/mon/AuthMonitor.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_AUTHMONITOR_H #define CEPH_AUTHMONITOR_H #include <map> #include <set> #include "global/global_init.h" #include "include/ceph_features.h" #include "include/types.h" #include "mon/PaxosService.h" #include "mon/MonitorDBStore.h" class MAuth; class KeyRing; class Monitor; #define MIN_GLOBAL_ID 0x1000 class AuthMonitor : public PaxosService { public: enum IncType { GLOBAL_ID, AUTH_DATA, }; struct Incremental { IncType inc_type; uint64_t max_global_id; uint32_t auth_type; ceph::buffer::list auth_data; Incremental() : inc_type(GLOBAL_ID), max_global_id(0), auth_type(0) {} void encode(ceph::buffer::list& bl, uint64_t features=-1) const { using ceph::encode; ENCODE_START(2, 2, bl); __u32 _type = (__u32)inc_type; encode(_type, bl); if (_type == GLOBAL_ID) { encode(max_global_id, bl); } else { encode(auth_type, bl); encode(auth_data, bl); } ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); __u32 _type; decode(_type, bl); inc_type = (IncType)_type; ceph_assert(inc_type >= GLOBAL_ID && inc_type <= AUTH_DATA); if (_type == GLOBAL_ID) { decode(max_global_id, bl); } else { decode(auth_type, bl); decode(auth_data, bl); } DECODE_FINISH(bl); } void dump(ceph::Formatter *f) const { f->dump_int("type", inc_type); f->dump_int("max_global_id", max_global_id); f->dump_int("auth_type", auth_type); f->dump_int("auth_data_len", auth_data.length()); } static void generate_test_instances(std::list<Incremental*>& ls) { ls.push_back(new Incremental); ls.push_back(new Incremental); ls.back()->inc_type = GLOBAL_ID; ls.back()->max_global_id = 1234; ls.push_back(new Incremental); ls.back()->inc_type = AUTH_DATA; ls.back()->auth_type = 12; ls.back()->auth_data.append("foo"); } }; struct auth_entity_t { EntityName name; EntityAuth auth; }; private: std::vector<Incremental> pending_auth; uint64_t max_global_id; uint64_t last_allocated_id; // these are protected by mon->auth_lock int mon_num = 0, mon_rank = 0; bool _upgrade_format_to_dumpling(); bool _upgrade_format_to_luminous(); bool _upgrade_format_to_mimic(); void upgrade_format() override; void export_keyring(KeyRing& keyring); int import_keyring(KeyRing& keyring); void push_cephx_inc(KeyServerData::Incremental& auth_inc) { Incremental inc; inc.inc_type = AUTH_DATA; encode(auth_inc, inc.auth_data); inc.auth_type = CEPH_AUTH_CEPHX; pending_auth.push_back(inc); } template<typename CAP_ENTITY_CLASS> bool _was_parsing_fine(const std::string& entity, const std::string& caps, std::ostream* out); /* validate mon/osd/mgr/mds caps; fail on unrecognized service/type */ bool valid_caps(const std::string& entity, const std::string& caps, std::ostream *out); bool valid_caps(const std::string& type, const ceph::buffer::list& bl, std::ostream *out) { auto p = bl.begin(); std::string v; try { using ceph::decode; decode(v, p); } catch (ceph::buffer::error& e) { *out << "corrupt capability encoding"; return false; } return valid_caps(type, v, out); } bool valid_caps(const std::map<std::string, std::string>& caps, std::ostream *out); void on_active() override; bool should_propose(double& delay) override; void get_initial_keyring(KeyRing *keyring); void create_initial_keys(KeyRing *keyring); void create_initial() override; void update_from_paxos(bool *need_bootstrap) override; void create_pending() override; // prepare a new pending bool prepare_global_id(MonOpRequestRef op); bool _should_increase_max_global_id(); ///< called under mon->auth_lock void increase_max_global_id(); uint64_t assign_global_id(bool should_increase_max); public: uint64_t _assign_global_id(); ///< called under mon->auth_lock void _set_mon_num_rank(int num, int rank); ///< called under mon->auth_lock private: bool prepare_used_pending_keys(MonOpRequestRef op); // propose pending update to peers void encode_pending(MonitorDBStore::TransactionRef t) override; void encode_full(MonitorDBStore::TransactionRef t) override; version_t get_trim_to() const override; bool preprocess_query(MonOpRequestRef op) override; // true if processed. bool prepare_update(MonOpRequestRef op) override; bool prep_auth(MonOpRequestRef op, bool paxos_writable); bool preprocess_command(MonOpRequestRef op); bool prepare_command(MonOpRequestRef op); void _encode_keyring(KeyRing& kr, const EntityName& entity, bufferlist& rdata, Formatter* fmtr, std::map<std::string, bufferlist>* wanted_caps=nullptr); void _encode_auth(const EntityName& entity, const EntityAuth& eauth, bufferlist& rdata, Formatter* fmtr, bool pending_key=false, std::map<std::string, bufferlist>* caps=nullptr); void _encode_key(const EntityName& entity, const EntityAuth& eauth, bufferlist& rdata, Formatter* fmtr, bool pending_key=false, std::map<std::string, bufferlist>* caps=nullptr); int _check_and_encode_caps(const std::map<std::string, std::string>& caps, std::map<std::string, bufferlist>& encoded_caps, std::stringstream& ss); int _update_or_create_entity(const EntityName& entity, const std::map<std::string, std::string>& caps, MonOpRequestRef op, std::stringstream& ds, bufferlist* rdata=nullptr, Formatter* fmtr=nullptr, bool create_entity=false); int _create_entity(const EntityName& entity, const std::map<std::string, std::string>& caps, MonOpRequestRef op, std::stringstream& ds, bufferlist* rdata, Formatter* fmtr); int _update_caps(const EntityName& entity, const std::map<std::string, std::string>& caps, MonOpRequestRef op, std::stringstream& ds, bufferlist* rdata, Formatter* fmtr); bool check_rotate(); void process_used_pending_keys(const std::map<EntityName,CryptoKey>& keys); bool entity_is_pending(EntityName& entity); int exists_and_matches_entity( const auth_entity_t& entity, bool has_secret, std::stringstream& ss); int exists_and_matches_entity( const EntityName& name, const EntityAuth& auth, const std::map<std::string,ceph::buffer::list>& caps, bool has_secret, std::stringstream& ss); int remove_entity(const EntityName &entity); int add_entity( const EntityName& name, const EntityAuth& auth); public: AuthMonitor(Monitor &mn, Paxos &p, const std::string& service_name) : PaxosService(mn, p, service_name), max_global_id(0), last_allocated_id(0) {} void pre_auth(MAuth *m); void tick() override; // check state, take actions int validate_osd_destroy( int32_t id, const uuid_d& uuid, EntityName& cephx_entity, EntityName& lockbox_entity, std::stringstream& ss); int do_osd_destroy( const EntityName& cephx_entity, const EntityName& lockbox_entity); int do_osd_new( const auth_entity_t& cephx_entity, const auth_entity_t& lockbox_entity, bool has_lockbox); int validate_osd_new( int32_t id, const uuid_d& uuid, const std::string& cephx_secret, const std::string& lockbox_secret, auth_entity_t& cephx_entity, auth_entity_t& lockbox_entity, std::stringstream& ss); void dump_info(ceph::Formatter *f); bool is_valid_cephx_key(const std::string& k) { if (k.empty()) return false; EntityAuth ea; try { ea.key.decode_base64(k); return true; } catch (ceph::buffer::error& e) { /* fallthrough */ } return false; } }; WRITE_CLASS_ENCODER_FEATURES(AuthMonitor::Incremental) #endif
8,296
29.72963
93
h
null
ceph-main/src/mon/CommandHandler.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2019 Red Hat Ltd * * 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 COMMAND_HANDLER_H_ #define COMMAND_HANDLER_H_ #include <ostream> #include <string_view> class CommandHandler { public: /** * Parse true|yes|1 style boolean string from `bool_str` * `result` must be non-null. * `ss` will be populated with error message on error. * * @return 0 on success, else -EINVAL */ int parse_bool(std::string_view str, bool* result, std::ostream& ss); }; #endif
823
21.888889
71
h
null
ceph-main/src/mon/ConfigMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include <map> #include <optional> #include <ostream> #include <string> #include "include/utime.h" #include "common/options.h" #include "common/entity_name.h" class CrushWrapper; // the precedence is thus: // // global // crush location (coarse to fine, ordered by type id) // daemon type (e.g., osd) // device class (osd only) // crush location (coarse to fine, ordered by type id) // daemon name (e.g., mds.foo) // // Note that this means that if we have // // config/host:foo/a = 1 // config/osd/rack:foo/a = 2 // // then we get a = 2. The osd-level config wins, even though rack // is less precise than host, because the crush limiters are only // resolved within a section (global, per-daemon, per-instance). struct OptionMask { std::string location_type, location_value; ///< matches crush_location std::string device_class; ///< matches device class bool empty() const { return location_type.size() == 0 && location_value.size() == 0 && device_class.size() == 0; } std::string to_str() const { std::string r; if (location_type.size()) { r += location_type + ":" + location_value; } if (device_class.size()) { if (r.size()) { r += "/"; } r += "class:" + device_class; } return r; } void dump(ceph::Formatter *f) const; }; struct MaskedOption { std::string raw_value; ///< raw, unparsed, unvalidated value const Option *opt; ///< the option OptionMask mask; std::unique_ptr<const Option> unknown_opt; ///< if fabricated for an unknown option MaskedOption(const Option *o, bool fab=false) : opt(o) { if (fab) { unknown_opt.reset(o); } } MaskedOption(MaskedOption&& o) { raw_value = std::move(o.raw_value); opt = o.opt; mask = std::move(o.mask); unknown_opt = std::move(o.unknown_opt); } const MaskedOption& operator=(const MaskedOption& o) = delete; const MaskedOption& operator=(MaskedOption&& o) = delete; /// return a precision metric (smaller is more precise) int get_precision(const CrushWrapper *crush); friend std::ostream& operator<<(std::ostream& out, const MaskedOption& o); void dump(ceph::Formatter *f) const; }; struct Section { std::multimap<std::string,MaskedOption> options; void clear() { options.clear(); } void dump(ceph::Formatter *f) const; std::string get_minimal_conf() const; }; struct ConfigMap { Section global; std::map<std::string,Section, std::less<>> by_type; std::map<std::string,Section, std::less<>> by_id; std::list<std::unique_ptr<Option>> stray_options; Section *find_section(const std::string& name) { if (name == "global") { return &global; } auto i = by_type.find(name); if (i != by_type.end()) { return &i->second; } i = by_id.find(name); if (i != by_id.end()) { return &i->second; } return nullptr; } void clear() { global.clear(); by_type.clear(); by_id.clear(); stray_options.clear(); } void dump(ceph::Formatter *f) const; std::map<std::string,std::string,std::less<>> generate_entity_map( const EntityName& name, const std::map<std::string,std::string>& crush_location, const CrushWrapper *crush, const std::string& device_class, std::map<std::string,std::pair<std::string,const MaskedOption*>> *src=0); void parse_key( const std::string& key, std::string *name, std::string *who); static bool parse_mask( const std::string& in, std::string *section, OptionMask *mask); }; struct ConfigChangeSet { version_t version; utime_t stamp; std::string name; // key -> (old value, new value) std::map<std::string,std::pair<std::optional<std::string>,std::optional<std::string>>> diff; void dump(ceph::Formatter *f) const; void print(std::ostream& out) const; };
3,994
24.774194
94
h
null
ceph-main/src/mon/ConfigMonitor.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include <optional> #include "ConfigMap.h" #include "mon/PaxosService.h" class MonSession; class ConfigMonitor : public PaxosService { version_t version = 0; ConfigMap config_map; std::map<std::string,std::optional<ceph::buffer::list>> pending; std::string pending_description; std::map<std::string,std::optional<ceph::buffer::list>> pending_cleanup; std::map<std::string,ceph::buffer::list> current; void encode_pending_to_kvmon(); public: ConfigMonitor(Monitor &m, Paxos &p, const std::string& service_name); void init() override; void load_config(); void load_changeset(version_t v, ConfigChangeSet *ch); bool preprocess_query(MonOpRequestRef op) override; bool prepare_update(MonOpRequestRef op) override; bool preprocess_command(MonOpRequestRef op); bool prepare_command(MonOpRequestRef op); void handle_get_config(MonOpRequestRef op); void create_initial() override; void update_from_paxos(bool *need_bootstrap) override; void create_pending() override; void encode_pending(MonitorDBStore::TransactionRef t) override; version_t get_trim_to() const override; void encode_full(MonitorDBStore::TransactionRef t) override { } void on_active() override; void tick() override; bool refresh_config(MonSession *s); bool maybe_send_config(MonSession *s); void send_config(MonSession *s); void check_sub(MonSession *s); void check_sub(Subscription *sub); void check_all_subs(); };
1,565
25.542373
74
h
null
ceph-main/src/mon/ConnectionTracker.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2019 Red Hat * * 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. * */ #pragma once #include "include/types.h" struct ConnectionReport { int rank = -1; // mon rank this state belongs to std::map<int, bool> current; // true if connected to the other mon std::map<int, double> history; // [0-1]; the connection reliability epoch_t epoch = 0; // the (local) election epoch the ConnectionReport came from uint64_t epoch_version = 0; // version of the ConnectionReport within the epoch void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); encode(rank, bl); encode(current, bl); encode(history, bl); encode(epoch, bl); encode(epoch_version, bl); ENCODE_FINISH(bl); } void decode(bufferlist::const_iterator& bl) { DECODE_START(1, bl); decode(rank, bl); decode(current, bl); decode(history, bl); decode(epoch, bl); decode(epoch_version, bl); DECODE_FINISH(bl); } bool operator==(const ConnectionReport& o) const { return o.rank == rank && o.current == current && o.history == history && o.epoch == epoch && o.epoch_version == epoch_version; } friend std::ostream& operator<<(std::ostream&o, const ConnectionReport& c); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<ConnectionReport*>& o); }; WRITE_CLASS_ENCODER(ConnectionReport); class RankProvider { public: /** * Get the rank of the running daemon. * It can be -1, meaning unknown/invalid, or it * can be >1. * You should not invoke the function get_total_connection_score() * with an unknown rank. */ virtual int get_my_rank() const = 0; /** * Asks our owner to encode us and persist it to disk. * Presently we do this every tenth update. */ virtual void persist_connectivity_scores() = 0; virtual ~RankProvider() {} }; class ConnectionTracker { public: /** * Receive a report from a peer and update our internal state * if the peer has newer data. */ void receive_peer_report(const ConnectionTracker& o); /** * Bump up the epoch to the specified number. * Validates that it is > current epoch and resets * version to 0; returns false if not. */ bool increase_epoch(epoch_t e); /** * Bump up the version within our epoch. * If the new version is a multiple of ten, we also persist it. */ void increase_version(); /** * Report a connection to a peer rank has been considered alive for * the given time duration. We assume the units_alive is <= the time * since the previous reporting call. * (Or, more precisely, we assume that the total amount of time * passed in is less than or equal to the time which has actually * passed -- you can report a 10-second death immediately followed * by reporting 5 seconds of liveness if your metrics are delayed.) */ void report_live_connection(int peer_rank, double units_alive); /** * Report a connection to a peer rank has been considered dead for * the given time duration, analogous to that above. */ void report_dead_connection(int peer_rank, double units_dead); /** * Set the half-life for dropping connection state * out of the ongoing score. * Whenever you add a new data point: * new_score = old_score * ( 1 - units / (2d)) + (units/(2d)) * where units is the units reported alive (for dead, you subtract them). */ void set_half_life(double d) { half_life = d; } /** * Get the total connection score of a rank across * all peers, and the count of how many electors think it's alive. * For this summation, if a rank reports a peer as down its score is zero. */ void get_total_connection_score(int peer_rank, double *rating, int *live_count) const; /** * Check if our ranks are clean and make * sure there are no extra peer_report lingering. * In the future we also want to check the reports * current and history of each peer_report. */ bool is_clean(int mon_rank, int monmap_size); /** * Encode this ConnectionTracker. Useful both for storing on disk * and for sending off to peers for decoding and import * with receive_peer_report() above. */ void encode(bufferlist &bl) const; void decode(bufferlist::const_iterator& bl); /** * Get a bufferlist containing the ConnectionTracker. * This is like encode() but holds a copy so it * doesn't re-encode on every invocation. */ const bufferlist& get_encoded_bl(); private: epoch_t epoch; uint64_t version; std::map<int,ConnectionReport> peer_reports; ConnectionReport my_reports; double half_life; RankProvider *owner; int rank; int persist_interval; bufferlist encoding; CephContext *cct; int get_my_rank() const { return rank; } ConnectionReport *reports(int p); const ConnectionReport *reports(int p) const; void clear_peer_reports() { encoding.clear(); peer_reports.clear(); my_reports = ConnectionReport(); my_reports.rank = rank; } public: ConnectionTracker() : epoch(0), version(0), half_life(12*60*60), owner(NULL), rank(-1), persist_interval(10) { } ConnectionTracker(RankProvider *o, int rank, double hl, int persist_i, CephContext *c) : epoch(0), version(0), half_life(hl), owner(o), rank(rank), persist_interval(persist_i), cct(c) { my_reports.rank = rank; } ConnectionTracker(const bufferlist& bl, CephContext *c) : epoch(0), version(0), half_life(0), owner(NULL), rank(-1), persist_interval(10), cct(c) { auto bi = bl.cbegin(); decode(bi); } ConnectionTracker(const ConnectionTracker& o) : epoch(o.epoch), version(o.version), half_life(o.half_life), owner(o.owner), rank(o.rank), persist_interval(o.persist_interval), cct(o.cct) { peer_reports = o.peer_reports; my_reports = o.my_reports; } void notify_reset() { clear_peer_reports(); } void set_rank(int new_rank) { rank = new_rank; my_reports.rank = rank; } void notify_rank_changed(int new_rank); void notify_rank_removed(int rank_removed, int new_rank); friend std::ostream& operator<<(std::ostream& o, const ConnectionTracker& c); friend ConnectionReport *get_connection_reports(ConnectionTracker& ct); friend std::map<int,ConnectionReport> *get_peer_reports(ConnectionTracker& ct); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<ConnectionTracker*>& o); }; WRITE_CLASS_ENCODER(ConnectionTracker);
6,799
32.009709
81
h
null
ceph-main/src/mon/CreatingPGs.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include <map> #include <set> #include <vector> #include "include/encoding.h" #include "include/utime.h" #include "osd/osd_types.h" struct creating_pgs_t { epoch_t last_scan_epoch = 0; struct pg_create_info { epoch_t create_epoch; utime_t create_stamp; // NOTE: pre-octopus instances of this class will have a // zeroed-out history std::vector<int> up; int up_primary = -1; std::vector<int> acting; int acting_primary = -1; pg_history_t history; PastIntervals past_intervals; void encode(ceph::buffer::list& bl, uint64_t features) const { using ceph::encode; if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) { // was pair<epoch_t,utime_t> prior to octopus encode(create_epoch, bl); encode(create_stamp, bl); return; } ENCODE_START(1, 1, bl); encode(create_epoch, bl); encode(create_stamp, bl); encode(up, bl); encode(up_primary, bl); encode(acting, bl); encode(acting_primary, bl); encode(history, bl); encode(past_intervals, bl); ENCODE_FINISH(bl); } void decode_legacy(ceph::buffer::list::const_iterator& p) { using ceph::decode; decode(create_epoch, p); decode(create_stamp, p); } void decode(ceph::buffer::list::const_iterator& p) { using ceph::decode; DECODE_START(1, p); decode(create_epoch, p); decode(create_stamp, p); decode(up, p); decode(up_primary, p); decode(acting, p); decode(acting_primary, p); decode(history, p); decode(past_intervals, p); DECODE_FINISH(p); } void dump(ceph::Formatter *f) const { f->dump_unsigned("create_epoch", create_epoch); f->dump_stream("create_stamp") << create_stamp; f->open_array_section("up"); for (auto& i : up) { f->dump_unsigned("osd", i); } f->close_section(); f->dump_int("up_primary", up_primary); f->open_array_section("acting"); for (auto& i : acting) { f->dump_unsigned("osd", i); } f->close_section(); f->dump_int("acting_primary", up_primary); f->dump_object("pg_history", history); f->dump_object("past_intervals", past_intervals); } pg_create_info() {} pg_create_info(epoch_t e, utime_t t) : create_epoch(e), create_stamp(t) { // NOTE: we don't initialize the other fields here; see // OSDMonitor::update_pending_pgs() } }; /// pgs we are currently creating std::map<pg_t, pg_create_info> pgs; struct pool_create_info { epoch_t created; utime_t modified; uint64_t start = 0; uint64_t end = 0; bool done() const { return start >= end; } void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(created, bl); encode(modified, bl); encode(start, bl); encode(end, bl); } void decode(ceph::buffer::list::const_iterator& p) { using ceph::decode; decode(created, p); decode(modified, p); decode(start, p); decode(end, p); } }; /// queue of pgs we still need to create (poolid -> <created, set of ps>) std::map<int64_t,pool_create_info> queue; /// pools that exist in the osdmap for which at least one pg has been created std::set<int64_t> created_pools; bool still_creating_pool(int64_t poolid) { for (auto& i : pgs) { if (i.first.pool() == poolid) { return true; } } if (queue.count(poolid)) { return true; } return false; } void create_pool(int64_t poolid, uint32_t pg_num, epoch_t created, utime_t modified) { ceph_assert(created_pools.count(poolid) == 0); auto& c = queue[poolid]; c.created = created; c.modified = modified; c.end = pg_num; created_pools.insert(poolid); } unsigned remove_pool(int64_t removed_pool) { const unsigned total = pgs.size(); auto first = pgs.lower_bound(pg_t{0, (uint64_t)removed_pool}); auto last = pgs.lower_bound(pg_t{0, (uint64_t)removed_pool + 1}); pgs.erase(first, last); created_pools.erase(removed_pool); queue.erase(removed_pool); return total - pgs.size(); } void encode(ceph::buffer::list& bl, uint64_t features) const { unsigned v = 3; if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) { v = 2; } ENCODE_START(v, 1, bl); encode(last_scan_epoch, bl); encode(pgs, bl, features); encode(created_pools, bl); encode(queue, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator& bl) { DECODE_START(3, bl); decode(last_scan_epoch, bl); if (struct_v >= 3) { decode(pgs, bl); } else { // legacy pg encoding pgs.clear(); uint32_t num; decode(num, bl); while (num--) { pg_t pgid; decode(pgid, bl); pgs[pgid].decode_legacy(bl); } } decode(created_pools, bl); if (struct_v >= 2) decode(queue, bl); DECODE_FINISH(bl); } void dump(ceph::Formatter *f) const { f->dump_unsigned("last_scan_epoch", last_scan_epoch); f->open_array_section("creating_pgs"); for (auto& pg : pgs) { f->open_object_section("pg"); f->dump_stream("pgid") << pg.first; f->dump_object("pg_create_info", pg.second); f->close_section(); } f->close_section(); f->open_array_section("queue"); for (auto& p : queue) { f->open_object_section("pool"); f->dump_unsigned("pool", p.first); f->dump_unsigned("created", p.second.created); f->dump_stream("modified") << p.second.modified; f->dump_unsigned("ps_start", p.second.start); f->dump_unsigned("ps_end", p.second.end); f->close_section(); } f->close_section(); f->open_array_section("created_pools"); for (auto pool : created_pools) { f->dump_unsigned("pool", pool); } f->close_section(); } static void generate_test_instances(std::list<creating_pgs_t*>& o) { auto c = new creating_pgs_t; c->last_scan_epoch = 17; c->pgs.emplace(pg_t{42, 2}, pg_create_info(31, utime_t{891, 113})); c->pgs.emplace(pg_t{44, 2}, pg_create_info(31, utime_t{891, 113})); c->created_pools = {0, 1}; o.push_back(c); c = new creating_pgs_t; c->last_scan_epoch = 18; c->pgs.emplace(pg_t{42, 3}, pg_create_info(31, utime_t{891, 113})); c->created_pools = {}; o.push_back(c); } }; WRITE_CLASS_ENCODER_FEATURES(creating_pgs_t::pg_create_info) WRITE_CLASS_ENCODER(creating_pgs_t::pool_create_info) WRITE_CLASS_ENCODER_FEATURES(creating_pgs_t)
6,662
27.353191
79
h
null
ceph-main/src/mon/ElectionLogic.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_ELECTIONLOGIC_H #define CEPH_ELECTIONLOGIC_H #include <map> #include <set> #include "include/types.h" #include "ConnectionTracker.h" class ElectionOwner { public: /** * Write down the given epoch in persistent storage, such that it * can later be retrieved by read_persisted_epoch even across process * or machine restarts. * * @param e The epoch to write */ virtual void persist_epoch(epoch_t e) = 0; /** * Retrieve the most-previously-persisted epoch. * * @returns The latest epoch passed to persist_epoch() */ virtual epoch_t read_persisted_epoch() const = 0; /** * Validate that the persistent store is working by committing * to it. (There is no interface for retrieving the value; this * tests local functionality before doing things like triggering * elections to try and join a quorum.) */ virtual void validate_store() = 0; /** * Notify the ElectionOwner that ElectionLogic has increased its * election epoch. This resets an election (either on local loss or victory, * or when trying a new election round) and the ElectionOwner * should reset any tracking of its own to match. (The ElectionLogic * will further trigger sending election messages if that is * appropriate.) */ virtual void notify_bump_epoch() = 0; /** * Notify the ElectionOwner we must start a new election. */ virtual void trigger_new_election() = 0; /** * Retrieve this Paxos instance's rank. */ virtual int get_my_rank() const = 0; /** * Send a PROPOSE message to all our peers. This happens when * we have started a new election (which may mean attempting to * override a current one). * * @param e The election epoch of our proposal. * @param bl A bufferlist containing data the logic wishes to share */ virtual void propose_to_peers(epoch_t e, bufferlist& bl) = 0; /** * The election has failed and we aren't sure what the state of the * quorum is, so reset the entire system as if from scratch. */ virtual void reset_election() = 0; /** * Ask the ElectionOwner if we-the-Monitor have ever participated in the * quorum (including across process restarts!). * * @returns true if we have participated, false otherwise */ virtual bool ever_participated() const = 0; /** * Ask the ElectionOwner for the size of the Paxos set. This includes * those monitors which may not be in the current quorum! * The value returned by this function can change between elections, * but not during them. (In practical terms, it can be updated * by making a paxos commit, but not by injecting values while * an election is ongoing.) */ virtual unsigned paxos_size() const = 0; /** * Retrieve a set of ranks which are not allowed to become the leader. * Like paxos_size(), This set can change between elections, but not * during them. */ virtual const std::set<int>& get_disallowed_leaders() const = 0; /** * Tell the ElectionOwner we have started a new election. * * The ElectionOwner is responsible for timing out the election (by invoking * end_election_period()) if it takes too long (as defined by the ElectionOwner). * This function is the opportunity to do that and to clean up any other external * election state it may be maintaining. */ virtual void _start() = 0; /** * Tell the ElectionOwner to defer to the identified peer. Tell that peer * we have deferred to it. * * @post we sent an ack message to @p who */ virtual void _defer_to(int who) = 0; /** * We have won an election, so have the ElectionOwner message that to * our new quorum! * * @param quorum The ranks of our peers which deferred to us and * must be told of our victory */ virtual void message_victory(const std::set<int>& quorum) = 0; /** * Query the ElectionOwner about if a given rank is in the * currently active quorum. * @param rank the Paxos rank whose status we are checking * @returns true if the rank is in our current quorum, false otherwise. */ virtual bool is_current_member(int rank) const = 0; virtual ~ElectionOwner() {} }; /** * This class maintains local state for running an election * between Paxos instances. It receives input requests * and calls back out to its ElectionOwner to do persistence * and message other entities. */ class ElectionLogic { ElectionOwner *elector; ConnectionTracker *peer_tracker; CephContext *cct; /** * Latest epoch we've seen. * * @remarks if its value is odd, we're electing; if it's even, then we're * stable. */ epoch_t epoch = 0; /** * The last rank which won an election we participated in */ int last_election_winner = -1; /** * Only used in the connectivity handler. * The rank we voted for in the last election we voted in. */ int last_voted_for = -1; double ignore_propose_margin = 0.0001; /** * Only used in the connectivity handler. * Points at a stable copy of the peer_tracker we use to keep scores * throughout an election period. */ std::unique_ptr<ConnectionTracker> stable_peer_tracker; std::unique_ptr<ConnectionTracker> leader_peer_tracker; /** * Indicates who we have acked */ int leader_acked; public: enum election_strategy { // Keep in sync with MonMap.h! CLASSIC = 1, // the original rank-based one DISALLOW = 2, // disallow a set from being leader CONNECTIVITY = 3 // includes DISALLOW, extends to prefer stronger connections }; election_strategy strategy; /** * Indicates if we are participating in the quorum. * * @remarks By default, we are created as participating. We may stop * participating if something explicitly sets our value * false, though. If that happens, it will * have to set participating=true and invoke start() for us to resume * participating in the quorum. */ bool participating; /** * Indicates if we are the ones being elected. * * We always attempt to be the one being elected if we are the ones starting * the election. If we are not the ones that started it, we will only attempt * to be elected if we think we might have a chance (i.e., the other guy's * rank is lower than ours). */ bool electing_me; /** * Set containing all those that acked our proposal to become the Leader. * * If we are acked by ElectionOwner::paxos_size() peers, we will declare * victory. */ std::set<int> acked_me; ElectionLogic(ElectionOwner *e, election_strategy es, ConnectionTracker *t, double ipm, CephContext *c) : elector(e), peer_tracker(t), cct(c), last_election_winner(-1), last_voted_for(-1), ignore_propose_margin(ipm), stable_peer_tracker(), leader_peer_tracker(), leader_acked(-1), strategy(es), participating(true), electing_me(false) {} /** * Set the election strategy to use. If this is not consistent across the * electing cluster, you're going to have a bad time. * Defaults to CLASSIC. */ void set_election_strategy(election_strategy es) { strategy = es; } /** * If there are no other peers in this Paxos group, ElectionOwner * can simply declare victory and we will make it so. * * @pre paxos_size() is 1 * @pre get_my_rank is 0 */ void declare_standalone_victory(); /** * Start a new election by proposing ourselves as the new Leader. * * Basically, send propose messages to all the peers. * * @pre participating is true * @post epoch is an odd value * @post electing_me is true * @post We have invoked propose_to_peers() on our ElectionOwner * @post We have invoked _start() on our ElectionOwner */ void start(); /** * ElectionOwner has decided the election has taken too long and expired. * * This will happen when no one declared victory or started a new election * during the allowed time span. * * When the election expires, we will check if we were the ones who won, and * if so we will declare victory. If that is not the case, then we assume * that the one we deferred to didn't declare victory quickly enough (in fact, * as far as we know, it may even be dead); so, just propose ourselves as the * Leader. */ void end_election_period(); /** * Handle a proposal from some other node proposing asking to become * the Leader. * * If the message appears to be old (i.e., its epoch is lower than our epoch), * then we may take one of two actions: * * @li Ignore it because it's nothing more than an old proposal * @li Start new elections if we verify that it was sent by a monitor from * outside the quorum; given its old state, it's fair to assume it just * started, so we should start new elections so it may rejoin. (Some * handlers may choose to ignore even these, if they think it's flapping.) * * We pass the propose off to a propose_*_handler function based * on the election strategy we're using. * Only the Connectivity strategy cares about the ConnectionTracker; it should * be NULL if other strategies are in use. Otherwise, it will take ownership * of the underlying data and delete it as needed. * * @pre Message epoch is from the current or a newer epoch * @param mepoch The epoch of the proposal * @param from The rank proposing itself as leader * @param ct Any incoming ConnectionTracker data sent with the message. * Callers are responsible for deleting this -- we will copy it if we want * to keep the data. */ void receive_propose(int from, epoch_t mepoch, const ConnectionTracker *ct); /** * Handle a message from some other participant Acking us as the Leader. * * When we receive such a message, one of three thing may be happening: * @li We received a message with a newer epoch, which means we must have * somehow lost track of what was going on (maybe we rebooted), thus we * will start a new election * @li We consider ourselves in the run for the Leader (i.e., @p electing_me * is true), and we are actually being Acked by someone; thus simply add * the one acking us to the @p acked_me set. If we do now have acks from * all the participants, then we can declare victory * @li We already deferred the election to somebody else, so we will just * ignore this message * * @pre Message epoch is from the current or a newer epoch * @post Election is on-going if we deferred to somebody else * @post Election is on-going if we are still waiting for further Acks * @post Election is not on-going if we are victorious * @post Election is not on-going if we must start a new one * * @param from The rank which acked us * @param from_epoch The election epoch the ack belongs to */ void receive_ack(int from, epoch_t from_epoch); /** * Handle a message from some other participant declaring Victory. * * We just got a message from someone declaring themselves Victorious, thus * the new Leader. * * However, if the message's epoch happens to be different from our epoch+1, * then it means we lost track of something and we must start a new election. * * If that is not the case, then we will simply update our epoch to the one * in the message and invoke start() to reset the quorum. * * @pre from_epoch is the current or a newer epoch * @post Election is not on-going * @post Updated @p epoch * @post We are a peon in a new quorum if we lost the election * * @param from The victory-claiming rank * @param from_epoch The election epoch in which they claim victory */ bool receive_victory_claim(int from, epoch_t from_epoch); /** * Obtain our epoch * * @returns Our current epoch number */ epoch_t get_epoch() const { return epoch; } int get_election_winner() { return last_election_winner; } private: /** * Initiate the ElectionLogic class. * * Basically, we will simply read whatever epoch value we have in our stable * storage, or consider it to be 1 if none is read. * * @post @p epoch is set to 1 or higher. */ void init(); /** * Update our epoch. * * If we come across a higher epoch, we simply update ours, also making * sure we are no longer being elected (even though we could have been, * we no longer are since we no longer are on that old epoch). * * @pre Our epoch is not larger than @p e * @post Our epoch equals @p e * * @param e Epoch to which we will update our epoch */ void bump_epoch(epoch_t e); /** * If the incoming proposal is newer, bump our own epoch; if * it comes from an out-of-quorum peer, trigger a new eleciton. * @returns true if you should drop this proposal, false otherwise. */ bool propose_classic_prefix(int from, epoch_t mepoch); /** * Handle a proposal from another rank using the classic strategy. * We will take one of the following actions: * * @li Ignore it because we already acked another node with higher rank * @li Ignore it and start a new election because we outrank it * @li Defer to it because it outranks us and the node we previously * acked, if any */ void propose_classic_handler(int from, epoch_t mepoch); /** * Handle a proposal from another rank using our disallow strategy. * This is the same as the classic strategy except we also disallow * certain ranks from becoming the leader. */ void propose_disallow_handler(int from, epoch_t mepoch); /** * Handle a proposal from another rank using the connectivity strategy. * We will choose to defer or not based on the ordered criteria: * * @li Whether the other monitor (or ourself) is on the disallow list * @li Whether the other monitor or ourself has the most connectivity to peers * @li Whether the other monitor or ourself has the lower rank */ void propose_connectivity_handler(int from, epoch_t mepoch, const ConnectionTracker *ct); /** * Helper function for connectivity handler. Combines the disallowed list * with ConnectionTracker scores. */ double connectivity_election_score(int rank); /** * Defer the current election to some other monitor. * * This means that we will ack some other monitor and drop out from the run * to become the Leader. We will only defer an election if the monitor we * are deferring to outranks us. * * @pre @p who outranks us (i.e., who < our rank) * @pre @p who outranks any other monitor we have deferred to in the past * @post electing_me is false * @post leader_acked equals @p who * @post we triggered ElectionOwner's _defer_to() on @p who * * @param who Some other monitor's numeric identifier. */ void defer(int who); /** * Declare Victory. * * We won. Or at least we believe we won, but for all intents and purposes * that does not matter. What matters is that we Won. * * That said, we must now bump our epoch to reflect that the election is over * and then we must let everybody in the quorum know we are their brand new * Leader. * * Actually, the quorum will be now defined as the group of monitors that * acked us during the election process. * * @pre Election is on-going * @pre electing_me is true * @post electing_me is false * @post epoch is bumped up into an even value * @post Election is not on-going * @post We have a quorum, composed of the monitors that acked us * @post We invoked message_victory() on the ElectionOwner */ void declare_victory(); /** * This is just a helper function to validate that the victory claim we * get from another rank makes any sense. */ bool victory_makes_sense(int from); /** * Reset some data members which we only care about while we are in an election * or need to be set consistently during stable states. */ void clear_live_election_state(); void reset_stable_tracker(); /** * Only for the connectivity handler, Bump the epoch * when we get a message from a newer one and clear * out leader and stable tracker * data so that we can switch our allegiance. */ void connectivity_bump_epoch_in_election(epoch_t mepoch); }; #endif
16,840
35.531453
91
h
null
ceph-main/src/mon/Elector.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * 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_MON_ELECTOR_H #define CEPH_MON_ELECTOR_H #include <map> #include "include/types.h" #include "include/Context.h" #include "mon/MonOpRequest.h" #include "mon/mon_types.h" #include "mon/ElectionLogic.h" #include "mon/ConnectionTracker.h" class Monitor; /** * This class is responsible for handling messages and maintaining * an ElectionLogic which holds the local state when electing * a new Leader. We may win or we may lose. If we win, it means we became the * Leader; if we lose, it means we are a Peon. */ class Elector : public ElectionOwner, RankProvider { /** * @defgroup Elector_h_class Elector * @{ */ ElectionLogic logic; // connectivity validation and scoring ConnectionTracker peer_tracker; std::map<int, utime_t> peer_acked_ping; // rank -> last ping stamp they acked std::map<int, utime_t> peer_sent_ping; // rank -> last ping stamp we sent std::set<int> live_pinging; // ranks which we are currently pinging std::set<int> dead_pinging; // ranks which didn't answer (degrading scores) double ping_timeout; // the timeout after which we consider a ping to be dead int PING_DIVISOR = 2; // we time out pings /** * @defgroup Elector_h_internal_types Internal Types * @{ */ /** * This struct will hold the features from a given peer. * Features may both be the cluster's (in the form of a uint64_t), or * mon-specific features. Instead of keeping maps to hold them both, or * a pair, which would be weird, a struct to keep them seems appropriate. */ struct elector_info_t { uint64_t cluster_features = 0; mon_feature_t mon_features; ceph_release_t mon_release{0}; std::map<std::string,std::string> metadata; }; /** * @} */ /** * The Monitor instance associated with this class. */ Monitor *mon; /** * Event callback responsible for dealing with an expired election once a * timer runs out and fires up. */ Context *expire_event = nullptr; /** * Resets the expire_event timer, by cancelling any existing one and * scheduling a new one. * * @remarks This function assumes as a default firing value the duration of * the monitor's lease interval, and adds to it the value specified * in @e plus * * @post expire_event is set * * @param plus The amount of time to be added to the default firing value. */ void reset_timer(double plus=0.0); /** * Cancel the expire_event timer, if it is defined. * * @post expire_event is not set */ void cancel_timer(); // electing me /** * @defgroup Elector_h_electing_me_vars We are being elected * @{ */ /** * Map containing info of all those that acked our proposal to become the Leader. * Note each peer's info. */ std::map<int, elector_info_t> peer_info; /** * @} */ /** * Handle a message from some other node proposing itself to become it * the Leader. * * We validate that the sending Monitor is allowed to participate based on * its supported features, then pass the request to our ElectionLogic. * * @invariant The received message is an operation of type OP_PROPOSE * * @pre Message epoch is from the current or a newer epoch * * @param m A message sent by another participant in the quorum. */ void handle_propose(MonOpRequestRef op); /** * Handle a message from some other participant Acking us as the Leader. * * We validate that the sending Monitor is allowed to participate based on * its supported features, add it to peer_info, and pass the ack to our * ElectionLogic. * * @pre Message epoch is from the current or a newer epoch * * @param m A message with an operation type of OP_ACK */ void handle_ack(MonOpRequestRef op); /** * Handle a message from some other participant declaring Victory. * * We just got a message from someone declaring themselves Victorious, thus * the new Leader. * * We pass the Victory to our ElectionLogic, and if it confirms the * victory we lose the election and start following this Leader. Otherwise, * drop the message. * * @pre Message epoch is from the current or a newer epoch * @post Election is not on-going * @post Updated @p epoch * @post We have a new quorum if we lost the election * * @param m A message with an operation type of OP_VICTORY */ void handle_victory(MonOpRequestRef op); /** * Send a nak to a peer who's out of date, containing information about why. * * If we get a message from a peer who can't support the required quorum * features, we have to ignore them. This function will at least send * them a message about *why* they're being ignored -- if they're new * enough to support such a message. * * @param m A message from a monitor not supporting required features. We * take ownership of the reference. */ void nak_old_peer(MonOpRequestRef op); /** * Handle a message from some other participant declaring * we cannot join the quorum. * * Apparently the quorum requires some feature that we do not implement. Shut * down gracefully. * * @pre Election is on-going. * @post We've shut down. * * @param m A message with an operation type of OP_NAK */ void handle_nak(MonOpRequestRef op); /** * Send a ping to the specified peer. * @n optional time that we will use instead of calling ceph_clock_now() */ bool send_peer_ping(int peer, const utime_t *n=NULL); /** * Check the state of pinging the specified peer. This is our * "tick" for heartbeating; scheduled by itself and begin_peer_ping(). */ void ping_check(int peer); /** * Move the peer out of live_pinging into dead_pinging set * and schedule dead_ping()ing on it. */ void begin_dead_ping(int peer); /** * Checks that the peer is still marked for dead pinging, * and then marks it as dead for the appropriate interval. */ void dead_ping(int peer); /** * Handle a ping from another monitor and assimilate the data it contains. */ void handle_ping(MonOpRequestRef op); /** * Update our view of everybody else's connectivity based on the provided * tracker bufferlist */ void assimilate_connection_reports(const bufferlist& bl); public: /** * @defgroup Elector_h_ElectionOwner Functions from the ElectionOwner interface * @{ */ /* Commit the given epoch to our MonStore. * We also take the opportunity to persist our peer_tracker. */ void persist_epoch(epoch_t e); /* Read the epoch out of our MonStore */ epoch_t read_persisted_epoch() const; /* Write a nonsense key "election_writeable_test" to our MonStore */ void validate_store(); /* Reset my tracking. Currently, just call Monitor::join_election() */ void notify_bump_epoch(); /* Call a new election: Invoke Monitor::start_election() */ void trigger_new_election(); /* Retrieve rank from the Monitor */ int get_my_rank() const; /* Send MMonElection OP_PROPOSE to every monitor in the map. */ void propose_to_peers(epoch_t e, bufferlist &bl); /* bootstrap() the Monitor */ void reset_election(); /* Retrieve the Monitor::has_ever_joined member */ bool ever_participated() const; /* Retrieve monmap->size() */ unsigned paxos_size() const; /* Right now we don't disallow anybody */ std::set<int> disallowed_leaders; const std::set<int>& get_disallowed_leaders() const { return disallowed_leaders; } /** * Reset the expire_event timer so we can limit the amount of time we * will be electing. Clean up our peer_info. * * @post we reset the expire_event timer */ void _start(); /** * Send an MMonElection message deferring to the identified monitor. We * also increase the election timeout so the monitor we defer to * has some time to gather deferrals and actually win. (FIXME: necessary to protocol?) * * @post we sent an ack message to @p who * @post we reset the expire_event timer * * @param who Some other monitor's numeric identifier. */ void _defer_to(int who); /** * Our ElectionLogic told us we won an election! Identify the quorum * features, tell our new peons we've won, and invoke Monitor::win_election(). */ void message_victory(const std::set<int>& quorum); /* Check if rank is in mon->quorum */ bool is_current_member(int rank) const; /* * @} */ /** * Persist our peer_tracker to disk. */ void persist_connectivity_scores(); Elector *elector; /** * Create an Elector class * * @param m A Monitor instance * @param strategy The election strategy to use, defined in MonMap/ElectionLogic */ explicit Elector(Monitor *m, int strategy); virtual ~Elector() {} /** * Inform this class it is supposed to shutdown. * * We will simply cancel the @p expire_event if any exists. * * @post @p expire_event is cancelled */ void shutdown(); /** * Obtain our epoch from ElectionLogic. * * @returns Our current epoch number */ epoch_t get_epoch() { return logic.get_epoch(); } /** * If the Monitor knows there are no Paxos peers (so * we are rank 0 and there are no others) we can declare victory. */ void declare_standalone_victory() { logic.declare_standalone_victory(); } /** * Tell the Elector to start pinging a given peer. * Do this when you discover a peer and it has a rank assigned. * We do it ourselves on receipt of pings and when receiving other messages. */ void begin_peer_ping(int peer); /** * Handle received messages. * * We will ignore all messages that are not of type @p MSG_MON_ELECTION * (i.e., messages whose interface is not of type @p MMonElection). All of * those that are will then be dispatched to their operation-specific * functions. * * @param m A received message */ void dispatch(MonOpRequestRef op); /** * Call an election. * * This function simply calls ElectionLogic::start. */ void call_election() { logic.start(); } /** * Stop participating in subsequent Elections. * * @post @p participating is false */ void stop_participating() { logic.participating = false; } /** * Start participating in Elections. * * If we are already participating (i.e., @p participating is true), then * calling this function is moot. * * However, if we are not participating (i.e., @p participating is false), * then we will start participating by setting @p participating to true and * we will call for an Election. * * @post @p participating is true */ void start_participating(); /** * Check if our peer_tracker is self-consistent, not suffering from * https://tracker.ceph.com/issues/58049 */ bool peer_tracker_is_clean(); /** * Forget everything about our peers. :( */ void notify_clear_peer_state(); /** * Notify that our local rank has changed * and we may need to update internal data structures. */ void notify_rank_changed(int new_rank); /** * A peer has been removed so we should clean up state related to it. * This is safe to call even if we haven't joined or are currently * in a quorum. */ void notify_rank_removed(unsigned rank_removed, unsigned new_rank); void notify_strategy_maybe_changed(int strategy); /** * Set the disallowed leaders. * * If you call this and the new disallowed set * contains your current leader, you are * responsible for calling an election! * * @returns false if the set is unchanged, * true if the set changed */ bool set_disallowed_leaders(const std::set<int>& dl) { if (dl == disallowed_leaders) return false; disallowed_leaders = dl; return true; } void dump_connection_scores(Formatter *f) { f->open_object_section("connection scores"); peer_tracker.dump(f); f->close_section(); } /** * @} */ }; #endif
12,433
29.550369
88
h
null
ceph-main/src/mon/FSCommands.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2017 Red Hat Ltd * * 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 FS_COMMANDS_H_ #define FS_COMMANDS_H_ #include "Monitor.h" #include "CommandHandler.h" #include "osd/OSDMap.h" #include "mds/FSMap.h" #include <string> #include <ostream> class FileSystemCommandHandler : protected CommandHandler { protected: std::string prefix; enum { POOL_METADATA, POOL_DATA_DEFAULT, POOL_DATA_EXTRA, }; /** * Return 0 if the pool is suitable for use with CephFS, or * in case of errors return a negative error code, and populate * the passed ostream with an explanation. * * @param metadata whether the pool will be for metadata (stricter checks) */ int _check_pool( OSDMap &osd_map, const int64_t pool_id, int type, bool force, std::ostream *ss, bool allow_overlay = false) const; virtual std::string const &get_prefix() const {return prefix;} public: FileSystemCommandHandler(const std::string &prefix_) : prefix(prefix_) {} virtual ~FileSystemCommandHandler() {} int is_op_allowed(const MonOpRequestRef& op, const FSMap& fsmap, const cmdmap_t& cmdmap, std::ostream &ss) const; int can_handle(std::string const &prefix_, MonOpRequestRef& op, FSMap& fsmap, const cmdmap_t& cmdmap, std::ostream &ss) const { if (get_prefix() != prefix_) { return 0; } if (get_prefix() == "fs new" || get_prefix() == "fs flag set") { return 1; } return is_op_allowed(op, fsmap, cmdmap, ss); } static std::list<std::shared_ptr<FileSystemCommandHandler> > load(Paxos *paxos); virtual int handle( Monitor *mon, FSMap &fsmap, MonOpRequestRef op, const cmdmap_t& cmdmap, std::ostream &ss) = 0; }; #endif
2,100
22.087912
82
h
null
ceph-main/src/mon/HealthMonitor.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2013 Inktank, Inc * * 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_HEALTH_MONITOR_H #define CEPH_HEALTH_MONITOR_H #include "mon/PaxosService.h" class HealthMonitor : public PaxosService { version_t version = 0; std::map<int,health_check_map_t> quorum_checks; // for each quorum member health_check_map_t leader_checks; // leader only std::map<std::string,health_mute_t> mutes; std::map<std::string,health_mute_t> pending_mutes; public: HealthMonitor(Monitor &m, Paxos &p, const std::string& service_name); /** * @defgroup HealthMonitor_Inherited_h Inherited abstract methods * @{ */ void init() override; bool preprocess_query(MonOpRequestRef op) override; bool prepare_update(MonOpRequestRef op) override; void create_initial() override; void update_from_paxos(bool *need_bootstrap) override; void create_pending() override; void encode_pending(MonitorDBStore::TransactionRef t) override; version_t get_trim_to() const override; void encode_full(MonitorDBStore::TransactionRef t) override { } void tick() override; void gather_all_health_checks(health_check_map_t *all); health_status_t get_health_status( bool want_detail, ceph::Formatter *f, std::string *plain, const char *sep1 = " ", const char *sep2 = "; "); /** * @} // HealthMonitor_Inherited_h */ private: bool preprocess_command(MonOpRequestRef op); bool prepare_command(MonOpRequestRef op); bool prepare_health_checks(MonOpRequestRef op); void check_for_older_version(health_check_map_t *checks); void check_for_mon_down(health_check_map_t *checks); void check_for_clock_skew(health_check_map_t *checks); void check_if_msgr2_enabled(health_check_map_t *checks); bool check_leader_health(); bool check_member_health(); bool check_mutes(); }; #endif // CEPH_HEALTH_MONITOR_H
2,202
27.986842
76
h