]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_period_history.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rgw / rgw_period_history.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #ifndef RGW_PERIOD_HISTORY_H
5 #define RGW_PERIOD_HISTORY_H
6
7 #include <deque>
8 #include <mutex>
9 #include <system_error>
10 #include <boost/intrusive/avl_set.hpp>
11 #include "include/ceph_assert.h"
12 #include "include/types.h"
13 #include "common/async/yield_context.h"
14
15 namespace bi = boost::intrusive;
16
17 class RGWPeriod;
18
19 /**
20 * RGWPeriodHistory tracks the relative history of all inserted periods,
21 * coordinates the pulling of missing intermediate periods, and provides a
22 * Cursor object for traversing through the connected history.
23 */
24 class RGWPeriodHistory final {
25 private:
26 /// an ordered history of consecutive periods
27 class History;
28
29 // comparisons for avl_set ordering
30 friend bool operator<(const History& lhs, const History& rhs);
31 friend struct NewestEpochLess;
32
33 class Impl;
34 std::unique_ptr<Impl> impl;
35
36 public:
37 /**
38 * Puller is a synchronous interface for pulling periods from the master
39 * zone. The abstraction exists mainly to support unit testing.
40 */
41 class Puller {
42 public:
43 virtual ~Puller() = default;
44
45 virtual int pull(const std::string& period_id, RGWPeriod& period,
46 optional_yield y) = 0;
47 };
48
49 RGWPeriodHistory(CephContext* cct, Puller* puller,
50 const RGWPeriod& current_period);
51 ~RGWPeriodHistory();
52
53 /**
54 * Cursor tracks a position in the period history and allows forward and
55 * backward traversal. Only periods that are fully connected to the
56 * current_period are reachable via a Cursor, because other histories are
57 * temporary and can be merged away. Cursors to periods in disjoint
58 * histories, as provided by insert() or lookup(), are therefore invalid and
59 * their operator bool() will return false.
60 */
61 class Cursor final {
62 public:
63 Cursor() = default;
64 explicit Cursor(int error) : error(error) {}
65
66 int get_error() const { return error; }
67
68 /// return false for a default-constructed or error Cursor
69 operator bool() const { return history != nullptr; }
70
71 epoch_t get_epoch() const { return epoch; }
72 const RGWPeriod& get_period() const;
73
74 bool has_prev() const;
75 bool has_next() const;
76
77 void prev() { epoch--; }
78 void next() { epoch++; }
79
80 friend bool operator==(const Cursor& lhs, const Cursor& rhs);
81 friend bool operator!=(const Cursor& lhs, const Cursor& rhs);
82
83 private:
84 // private constructors for RGWPeriodHistory
85 friend class RGWPeriodHistory::Impl;
86
87 Cursor(const History* history, std::mutex* mutex, epoch_t epoch)
88 : history(history), mutex(mutex), epoch(epoch) {}
89
90 int error{0};
91 const History* history{nullptr};
92 std::mutex* mutex{nullptr};
93 epoch_t epoch{0}; //< realm epoch of cursor position
94 };
95
96 /// return a cursor to the current period
97 Cursor get_current() const;
98
99 /// build up a connected period history that covers the span between
100 /// current_period and the given period, reading predecessor periods or
101 /// fetching them from the master as necessary. returns a cursor at the
102 /// given period that can be used to traverse the current_history
103 Cursor attach(RGWPeriod&& period, optional_yield y);
104
105 /// insert the given period into an existing history, or create a new
106 /// unconnected history. similar to attach(), but it doesn't try to fetch
107 /// missing periods. returns a cursor to the inserted period iff it's in
108 /// the current_history
109 Cursor insert(RGWPeriod&& period);
110
111 /// search for a period by realm epoch, returning a valid Cursor iff it's in
112 /// the current_history
113 Cursor lookup(epoch_t realm_epoch);
114 };
115
116 #endif // RGW_PERIOD_HISTORY_H