]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSTableServer.h
update sources to ceph Nautilus 14.2.1
[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 protected:
25 int table;
26 bool recovered;
27 set<mds_rank_t> active_clients;
28 private:
29 map<version_t,mds_table_pending_t> pending_for_mds; // ** child should encode this! **
30 set<version_t> committing_tids;
31
32 struct notify_info_t {
33 set<mds_rank_t> notify_ack_gather;
34 mds_rank_t mds;
35 MMDSTableRequest::ref reply;
36 MDSContext *onfinish;
37 notify_info_t() : reply(NULL), onfinish(NULL) {}
38 };
39 map<version_t, notify_info_t> pending_notifies;
40
41 void handle_prepare(const MMDSTableRequest::const_ref &m);
42 void _prepare_logged(const MMDSTableRequest::const_ref &m, version_t tid);
43 friend class C_Prepare;
44
45 void handle_commit(const MMDSTableRequest::const_ref &m);
46 void _commit_logged(const MMDSTableRequest::const_ref &m);
47 friend class C_Commit;
48
49 void handle_rollback(const MMDSTableRequest::const_ref &m);
50 void _rollback_logged(const MMDSTableRequest::const_ref &m);
51 friend class C_Rollback;
52
53 void _server_update_logged(bufferlist& bl);
54 friend class C_ServerUpdate;
55
56 void handle_notify_ack(const MMDSTableRequest::const_ref &m);
57
58 public:
59 virtual void handle_query(const MMDSTableRequest::const_ref &m) = 0;
60 virtual void _prepare(const bufferlist &bl, uint64_t reqid, mds_rank_t bymds, bufferlist& out) = 0;
61 virtual void _get_reply_buffer(version_t tid, bufferlist *pbl) const = 0;
62 virtual void _commit(version_t tid, MMDSTableRequest::const_ref req) = 0;
63 virtual void _rollback(version_t tid) = 0;
64 virtual void _server_update(bufferlist& bl) { ceph_abort(); }
65 virtual bool _notify_prep(version_t tid) { return false; };
66
67 void _note_prepare(mds_rank_t mds, uint64_t reqid, bool replay=false) {
68 version++;
69 if (replay)
70 projected_version = version;
71 pending_for_mds[version].mds = mds;
72 pending_for_mds[version].reqid = reqid;
73 pending_for_mds[version].tid = version;
74 }
75 void _note_commit(uint64_t tid, bool replay=false) {
76 version++;
77 if (replay)
78 projected_version = version;
79 pending_for_mds.erase(tid);
80 }
81 void _note_rollback(uint64_t tid, bool replay=false) {
82 version++;
83 if (replay)
84 projected_version = version;
85 pending_for_mds.erase(tid);
86 }
87 void _note_server_update(bufferlist& bl, bool replay=false) {
88 version++;
89 if (replay)
90 projected_version = version;
91 }
92
93 MDSTableServer(MDSRank *m, int tab) :
94 MDSTable(m, get_mdstable_name(tab), false), table(tab), recovered(false) {}
95 ~MDSTableServer() override {}
96
97 void reset_state() override {
98 pending_for_mds.clear();
99 ++version;
100 }
101
102 void handle_request(const MMDSTableRequest::const_ref &m);
103 void do_server_update(bufferlist& bl);
104
105 virtual void encode_server_state(bufferlist& bl) const = 0;
106 virtual void decode_server_state(bufferlist::const_iterator& bl) = 0;
107
108 void encode_state(bufferlist& bl) const override {
109 encode_server_state(bl);
110 encode(pending_for_mds, bl);
111 }
112 void decode_state(bufferlist::const_iterator& bl) override {
113 decode_server_state(bl);
114 decode(pending_for_mds, bl);
115 }
116
117 // recovery
118 void finish_recovery(set<mds_rank_t>& active);
119 void _do_server_recovery();
120 friend class C_ServerRecovery;
121
122 void handle_mds_recovery(mds_rank_t who);
123 void handle_mds_failure_or_stop(mds_rank_t who);
124 };
125
126 #endif