]> git.proxmox.com Git - ceph.git/blame - ceph/src/journal/FutureImpl.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / journal / FutureImpl.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_JOURNAL_FUTURE_IMPL_H
5#define CEPH_JOURNAL_FUTURE_IMPL_H
6
7#include "include/int_types.h"
7c673cae 8#include "common/RefCountedObj.h"
11fdf7f2 9#include "include/Context.h"
7c673cae
FG
10#include "journal/Future.h"
11#include <list>
12#include <map>
13#include <boost/noncopyable.hpp>
11fdf7f2 14#include "include/ceph_assert.h"
7c673cae
FG
15
16class Context;
17
18namespace journal {
19
7c673cae
FG
20class FutureImpl : public RefCountedObject, boost::noncopyable {
21public:
22 struct FlushHandler {
9f95a23c
TL
23 using ref = std::shared_ptr<FlushHandler>;
24 virtual void flush(const ceph::ref_t<FutureImpl> &future) = 0;
25 virtual ~FlushHandler() = default;
7c673cae 26 };
7c673cae 27
9f95a23c 28 void init(const ceph::ref_t<FutureImpl> &prev_future);
7c673cae
FG
29
30 inline uint64_t get_tag_tid() const {
31 return m_tag_tid;
32 }
33 inline uint64_t get_entry_tid() const {
34 return m_entry_tid;
35 }
36 inline uint64_t get_commit_tid() const {
37 return m_commit_tid;
38 }
39
40 void flush(Context *on_safe = NULL);
41 void wait(Context *on_safe);
42
43 bool is_complete() const;
44 int get_return_value() const;
45
46 inline bool is_flush_in_progress() const {
9f95a23c 47 std::lock_guard locker{m_lock};
7c673cae
FG
48 return (m_flush_state == FLUSH_STATE_IN_PROGRESS);
49 }
50 inline void set_flush_in_progress() {
9f95a23c
TL
51 auto h = std::move(m_flush_handler);
52 ceph_assert(h);
53 std::lock_guard locker{m_lock};
7c673cae
FG
54 m_flush_state = FLUSH_STATE_IN_PROGRESS;
55 }
56
9f95a23c 57 bool attach(FlushHandler::ref flush_handler);
7c673cae 58 inline void detach() {
7c673cae
FG
59 m_flush_handler.reset();
60 }
9f95a23c 61 inline FlushHandler::ref get_flush_handler() const {
7c673cae
FG
62 return m_flush_handler;
63 }
64
65 void safe(int r);
66
67private:
68 friend std::ostream &operator<<(std::ostream &, const FutureImpl &);
69
9f95a23c 70 typedef std::map<FlushHandler::ref, ceph::ref_t<FutureImpl>> FlushHandlers;
7c673cae
FG
71 typedef std::list<Context *> Contexts;
72
73 enum FlushState {
74 FLUSH_STATE_NONE,
75 FLUSH_STATE_REQUESTED,
76 FLUSH_STATE_IN_PROGRESS
77 };
78
79 struct C_ConsistentAck : public Context {
9f95a23c
TL
80 ceph::ref_t<FutureImpl> future;
81 C_ConsistentAck(ceph::ref_t<FutureImpl> _future) : future(std::move(_future)) {}
7c673cae
FG
82 void complete(int r) override {
83 future->consistent(r);
84 future.reset();
85 }
86 void finish(int r) override {}
87 };
88
9f95a23c
TL
89 FRIEND_MAKE_REF(FutureImpl);
90 FutureImpl(uint64_t tag_tid, uint64_t entry_tid, uint64_t commit_tid);
91 ~FutureImpl() override = default;
92
7c673cae
FG
93 uint64_t m_tag_tid;
94 uint64_t m_entry_tid;
95 uint64_t m_commit_tid;
96
9f95a23c
TL
97 mutable ceph::mutex m_lock = ceph::make_mutex("FutureImpl::m_lock", false);
98 ceph::ref_t<FutureImpl> m_prev_future;
99 bool m_safe = false;
100 bool m_consistent = false;
101 int m_return_value = 0;
7c673cae 102
9f95a23c
TL
103 FlushHandler::ref m_flush_handler;
104 FlushState m_flush_state = FLUSH_STATE_NONE;
7c673cae
FG
105
106 C_ConsistentAck m_consistent_ack;
107 Contexts m_contexts;
108
9f95a23c
TL
109 ceph::ref_t<FutureImpl> prepare_flush(FlushHandlers *flush_handlers);
110 ceph::ref_t<FutureImpl> prepare_flush(FlushHandlers *flush_handlers, ceph::mutex &lock);
7c673cae
FG
111
112 void consistent(int r);
113 void finish_unlock();
114};
115
7c673cae
FG
116std::ostream &operator<<(std::ostream &os, const FutureImpl &future);
117
118} // namespace journal
119
120using journal::operator<<;
121
122#endif // CEPH_JOURNAL_FUTURE_IMPL_H