1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 Red Hat Inc.
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
20 #include "include/types.h"
21 #include "include/utime.h"
22 #include "osd/OpRequest.h"
31 explicit PGScrub(epoch_t e) : epoch_queued(e) {}
32 ostream &operator<<(ostream &rhs) {
33 return rhs << "PGScrub";
39 explicit PGSnapTrim(epoch_t e) : epoch_queued(e) {}
40 ostream &operator<<(ostream &rhs) {
41 return rhs << "PGSnapTrim";
47 uint64_t reserved_pushes;
48 PGRecovery(epoch_t e, uint64_t reserved_pushes)
49 : epoch_queued(e), reserved_pushes(reserved_pushes) {}
50 ostream &operator<<(ostream &rhs) {
51 return rhs << "PGRecovery(epoch=" << epoch_queued
52 << ", reserved_pushes: " << reserved_pushes << ")";
58 typedef boost::variant<
69 epoch_t map_epoch; ///< an epoch we expect the PG to exist in
71 struct RunVis : public boost::static_visitor<> {
74 ThreadPool::TPHandle &handle;
75 RunVis(OSD *osd, PGRef &pg, ThreadPool::TPHandle &handle)
76 : osd(osd), pg(pg), handle(handle) {}
77 void operator()(const OpRequestRef &op);
78 void operator()(const PGSnapTrim &op);
79 void operator()(const PGScrub &op);
80 void operator()(const PGRecovery &op);
83 struct StringifyVis : public boost::static_visitor<std::string> {
84 std::string operator()(const OpRequestRef &op) {
87 std::string operator()(const PGSnapTrim &op) {
90 std::string operator()(const PGScrub &op) {
93 std::string operator()(const PGRecovery &op) {
98 friend ostream& operator<<(ostream& out, const PGQueueable& q) {
100 return out << "PGQueueable(" << boost::apply_visitor(v, q.qvariant)
101 << " prio " << q.priority << " cost " << q.cost
102 << " e" << q.map_epoch << ")";
107 PGQueueable(OpRequestRef op, epoch_t e)
108 : qvariant(op), cost(op->get_req()->get_cost()),
109 priority(op->get_req()->get_priority()),
110 start_time(op->get_req()->get_recv_stamp()),
111 owner(op->get_req()->get_source_inst()),
115 const PGSnapTrim &op, int cost, unsigned priority, utime_t start_time,
116 const entity_inst_t &owner, epoch_t e)
117 : qvariant(op), cost(cost), priority(priority), start_time(start_time),
118 owner(owner), map_epoch(e) {}
120 const PGScrub &op, int cost, unsigned priority, utime_t start_time,
121 const entity_inst_t &owner, epoch_t e)
122 : qvariant(op), cost(cost), priority(priority), start_time(start_time),
123 owner(owner), map_epoch(e) {}
125 const PGRecovery &op, int cost, unsigned priority, utime_t start_time,
126 const entity_inst_t &owner, epoch_t e)
127 : qvariant(op), cost(cost), priority(priority), start_time(start_time),
128 owner(owner), map_epoch(e) {}
130 const boost::optional<OpRequestRef> maybe_get_op() const {
131 const OpRequestRef *op = boost::get<OpRequestRef>(&qvariant);
132 return op ? OpRequestRef(*op) : boost::optional<OpRequestRef>();
134 uint64_t get_reserved_pushes() const {
135 const PGRecovery *op = boost::get<PGRecovery>(&qvariant);
136 return op ? op->reserved_pushes : 0;
138 void run(OSD *osd, PGRef &pg, ThreadPool::TPHandle &handle) {
139 RunVis v(osd, pg, handle);
140 boost::apply_visitor(v, qvariant);
142 unsigned get_priority() const { return priority; }
143 int get_cost() const { return cost; }
144 utime_t get_start_time() const { return start_time; }
145 entity_inst_t get_owner() const { return owner; }
146 epoch_t get_map_epoch() const { return map_epoch; }
147 const QVariant& get_variant() const { return qvariant; }
148 }; // struct PGQueueable