]>
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
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/assert.h"
12 #include "include/types.h"
14 namespace bi
= boost::intrusive
;
19 * RGWPeriodHistory tracks the relative history of all inserted periods,
20 * coordinates the pulling of missing intermediate periods, and provides a
21 * Cursor object for traversing through the connected history.
23 class RGWPeriodHistory final
{
25 /// an ordered history of consecutive periods
28 // comparisons for avl_set ordering
29 friend bool operator<(const History
& lhs
, const History
& rhs
);
30 friend struct NewestEpochLess
;
33 std::unique_ptr
<Impl
> impl
;
37 * Puller is a synchronous interface for pulling periods from the master
38 * zone. The abstraction exists mainly to support unit testing.
42 virtual ~Puller() = default;
44 virtual int pull(const std::string
& period_id
, RGWPeriod
& period
) = 0;
47 RGWPeriodHistory(CephContext
* cct
, Puller
* puller
,
48 const RGWPeriod
& current_period
);
52 * Cursor tracks a position in the period history and allows forward and
53 * backward traversal. Only periods that are fully connected to the
54 * current_period are reachable via a Cursor, because other histories are
55 * temporary and can be merged away. Cursors to periods in disjoint
56 * histories, as provided by insert() or lookup(), are therefore invalid and
57 * their operator bool() will return false.
62 explicit Cursor(int error
) : error(error
) {}
64 int get_error() const { return error
; }
66 /// return false for a default-constructed or error Cursor
67 operator bool() const { return history
!= nullptr; }
69 epoch_t
get_epoch() const { return epoch
; }
70 const RGWPeriod
& get_period() const;
72 bool has_prev() const;
73 bool has_next() const;
75 void prev() { epoch
--; }
76 void next() { epoch
++; }
78 friend bool operator==(const Cursor
& lhs
, const Cursor
& rhs
);
79 friend bool operator!=(const Cursor
& lhs
, const Cursor
& rhs
);
82 // private constructors for RGWPeriodHistory
83 friend class RGWPeriodHistory::Impl
;
85 Cursor(const History
* history
, std::mutex
* mutex
, epoch_t epoch
)
86 : history(history
), mutex(mutex
), epoch(epoch
) {}
89 const History
* history
{nullptr};
90 std::mutex
* mutex
{nullptr};
91 epoch_t epoch
{0}; //< realm epoch of cursor position
94 /// return a cursor to the current period
95 Cursor
get_current() const;
97 /// build up a connected period history that covers the span between
98 /// current_period and the given period, reading predecessor periods or
99 /// fetching them from the master as necessary. returns a cursor at the
100 /// given period that can be used to traverse the current_history
101 Cursor
attach(RGWPeriod
&& period
);
103 /// insert the given period into an existing history, or create a new
104 /// unconnected history. similar to attach(), but it doesn't try to fetch
105 /// missing periods. returns a cursor to the inserted period iff it's in
106 /// the current_history
107 Cursor
insert(RGWPeriod
&& period
);
109 /// search for a period by realm epoch, returning a valid Cursor iff it's in
110 /// the current_history
111 Cursor
lookup(epoch_t realm_epoch
);
114 #endif // RGW_PERIOD_HISTORY_H