]>
git.proxmox.com Git - ceph.git/blob - 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
4 #ifndef RGW_PERIOD_HISTORY_H
5 #define RGW_PERIOD_HISTORY_H
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"
15 namespace bi
= boost::intrusive
;
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.
24 class RGWPeriodHistory final
{
26 /// an ordered history of consecutive periods
29 // comparisons for avl_set ordering
30 friend bool operator<(const History
& lhs
, const History
& rhs
);
31 friend struct NewestEpochLess
;
34 std::unique_ptr
<Impl
> impl
;
38 * Puller is a synchronous interface for pulling periods from the master
39 * zone. The abstraction exists mainly to support unit testing.
43 virtual ~Puller() = default;
45 virtual int pull(const std::string
& period_id
, RGWPeriod
& period
,
46 optional_yield y
) = 0;
49 RGWPeriodHistory(CephContext
* cct
, Puller
* puller
,
50 const RGWPeriod
& current_period
);
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.
64 explicit Cursor(int error
) : error(error
) {}
66 int get_error() const { return error
; }
68 /// return false for a default-constructed or error Cursor
69 operator bool() const { return history
!= nullptr; }
71 epoch_t
get_epoch() const { return epoch
; }
72 const RGWPeriod
& get_period() const;
74 bool has_prev() const;
75 bool has_next() const;
77 void prev() { epoch
--; }
78 void next() { epoch
++; }
80 friend bool operator==(const Cursor
& lhs
, const Cursor
& rhs
);
81 friend bool operator!=(const Cursor
& lhs
, const Cursor
& rhs
);
84 // private constructors for RGWPeriodHistory
85 friend class RGWPeriodHistory::Impl
;
87 Cursor(const History
* history
, std::mutex
* mutex
, epoch_t epoch
)
88 : history(history
), mutex(mutex
), epoch(epoch
) {}
91 const History
* history
{nullptr};
92 std::mutex
* mutex
{nullptr};
93 epoch_t epoch
{0}; //< realm epoch of cursor position
96 /// return a cursor to the current period
97 Cursor
get_current() const;
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
);
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
);
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
);
116 #endif // RGW_PERIOD_HISTORY_H