Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / MDSTableClient.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_MDSTABLECLIENT_H
16 #define CEPH_MDSTABLECLIENT_H
17
18 #include "include/types.h"
19 #include "MDSContext.h"
20 #include "mds_table_types.h"
21
22 class MDSRank;
23 class LogSegment;
24 class MMDSTableRequest;
25
26 class MDSTableClient {
27 protected:
28   MDSRank *mds;
29   int table;
30
31   uint64_t last_reqid;
32
33   bool server_ready;
34
35   // prepares
36   struct _pending_prepare {
37     MDSInternalContextBase *onfinish;
38     version_t *ptid;
39     bufferlist *pbl; 
40     bufferlist mutation;
41
42     _pending_prepare() : onfinish(0), ptid(0), pbl(0) {}
43     _pending_prepare(MDSInternalContextBase *c, version_t *pt, bufferlist *pb, bufferlist& m) :
44       onfinish(c), ptid(pt), pbl(pb), mutation(m) {}
45   };
46
47   map<uint64_t, _pending_prepare> pending_prepare;
48   map<version_t, uint64_t> prepared_update;
49   list<_pending_prepare> waiting_for_reqid;
50
51   // pending commits
52   map<version_t, LogSegment*> pending_commit;
53   map<version_t, list<MDSInternalContextBase*> > ack_waiters;
54
55   void handle_reply(class MMDSTableQuery *m);  
56   void _logged_ack(version_t tid);
57   friend class C_LoggedAck;
58
59 public:
60   MDSTableClient(MDSRank *m, int tab) :
61     mds(m), table(tab), last_reqid(~0ULL), server_ready(false) {}
62   virtual ~MDSTableClient() {}
63
64   void handle_request(MMDSTableRequest *m);
65
66   void _prepare(bufferlist& mutation, version_t *ptid, bufferlist *pbl, MDSInternalContextBase *onfinish);
67   void commit(version_t tid, LogSegment *ls);
68
69   void resend_commits();
70   void resend_prepares();
71
72   // for recovery (by me)
73   void got_journaled_agree(version_t tid, LogSegment *ls);
74   void got_journaled_ack(version_t tid);
75
76   bool has_committed(version_t tid) const {
77     return pending_commit.count(tid) == 0;
78   }
79   void wait_for_ack(version_t tid, MDSInternalContextBase *c) {
80     ack_waiters[tid].push_back(c);
81   }
82
83   void handle_mds_failure(mds_rank_t mds);
84
85   // child must implement
86   virtual void resend_queries() = 0;
87   virtual void handle_query_result(MMDSTableRequest *m) = 0;
88
89   // and friendly front-end for _prepare.
90
91 };
92
93 #endif