]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSTableServer.h
import ceph 16.2.6
[ceph.git] / ceph / src / mds / MDSTableServer.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
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.
12 *
13 */
14
15 #ifndef CEPH_MDSTABLESERVER_H
16 #define CEPH_MDSTABLESERVER_H
17
18 #include "MDSTable.h"
19 #include "MDSContext.h"
20
21 #include "messages/MMDSTableRequest.h"
22
23 class MDSTableServer : public MDSTable {
24 public:
25 friend class C_ServerRecovery;
26
27 MDSTableServer(MDSRank *m, int tab) :
28 MDSTable(m, get_mdstable_name(tab), false), table(tab) {}
29 ~MDSTableServer() override {}
30
31 virtual void handle_query(const cref_t<MMDSTableRequest> &m) = 0;
32 virtual void _prepare(const bufferlist &bl, uint64_t reqid, mds_rank_t bymds, bufferlist& out) = 0;
33 virtual void _get_reply_buffer(version_t tid, bufferlist *pbl) const = 0;
34 virtual void _commit(version_t tid, cref_t<MMDSTableRequest> req) = 0;
35 virtual void _rollback(version_t tid) = 0;
36 virtual void _server_update(bufferlist& bl) { ceph_abort(); }
37 virtual bool _notify_prep(version_t tid) { return false; };
38
39 void _note_prepare(mds_rank_t mds, uint64_t reqid, bool replay=false) {
40 version++;
41 if (replay)
42 projected_version = version;
43 pending_for_mds[version].mds = mds;
44 pending_for_mds[version].reqid = reqid;
45 pending_for_mds[version].tid = version;
46 }
47 void _note_commit(uint64_t tid, bool replay=false) {
48 version++;
49 if (replay)
50 projected_version = version;
51 pending_for_mds.erase(tid);
52 }
53 void _note_rollback(uint64_t tid, bool replay=false) {
54 version++;
55 if (replay)
56 projected_version = version;
57 pending_for_mds.erase(tid);
58 }
59 void _note_server_update(bufferlist& bl, bool replay=false) {
60 version++;
61 if (replay)
62 projected_version = version;
63 }
64
65 void reset_state() override {
66 pending_for_mds.clear();
67 ++version;
68 }
69
70 void handle_request(const cref_t<MMDSTableRequest> &m);
71 void do_server_update(bufferlist& bl);
72
73 virtual void encode_server_state(bufferlist& bl) const = 0;
74 virtual void decode_server_state(bufferlist::const_iterator& bl) = 0;
75
76 void encode_state(bufferlist& bl) const override {
77 encode_server_state(bl);
78 encode(pending_for_mds, bl);
79 }
80 void decode_state(bufferlist::const_iterator& bl) override {
81 decode_server_state(bl);
82 decode(pending_for_mds, bl);
83 }
84
85 // recovery
86 void finish_recovery(set<mds_rank_t>& active);
87 void _do_server_recovery();
88
89 void handle_mds_recovery(mds_rank_t who);
90 void handle_mds_failure_or_stop(mds_rank_t who);
91 protected:
92 int table;
93 bool recovered = false;
94 set<mds_rank_t> active_clients;
95 private:
96 struct notify_info_t {
97 notify_info_t() {}
98 set<mds_rank_t> notify_ack_gather;
99 mds_rank_t mds;
100 ref_t<MMDSTableRequest> reply = NULL;
101 MDSContext *onfinish = nullptr;
102 };
103
104 friend class C_Prepare;
105 friend class C_Commit;
106 friend class C_Rollback;
107 friend class C_ServerUpdate;
108
109 void handle_prepare(const cref_t<MMDSTableRequest> &m);
110 void _prepare_logged(const cref_t<MMDSTableRequest> &m, version_t tid);
111
112 void handle_commit(const cref_t<MMDSTableRequest> &m);
113 void _commit_logged(const cref_t<MMDSTableRequest> &m);
114
115 void handle_rollback(const cref_t<MMDSTableRequest> &m);
116 void _rollback_logged(const cref_t<MMDSTableRequest> &m);
117
118 void _server_update_logged(bufferlist& bl);
119
120 void handle_notify_ack(const cref_t<MMDSTableRequest> &m);
121
122 map<version_t,mds_table_pending_t> pending_for_mds; // ** child should encode this! **
123 set<version_t> committing_tids;
124
125 map<version_t, notify_info_t> pending_notifies;
126 };
127 #endif