InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DeadlockMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Mark Travis <mtravis15432+src@gmail.com>
3  * All rights reserved. No warranty, explicit or implicit, provided.
4  *
5  * This file is part of InfiniSQL(tm).
6 
7  * InfiniSQL is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 3
9  * as published by the Free Software Foundation.
10  *
11  * InfiniSQL is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with InfiniSQL. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
28 #ifndef INFINISQLDEADLOCKMGR_H
29 #define INFINISQLDEADLOCKMGR_H
30 
31 #include "gch.h"
32 
38 typedef struct
39 {
41  int64_t pendingcmdid;
42 } taCmd;
43 
49 {
50 public:
59  virtual ~DeadlockMgr();
60 
61  friend class Transaction; // uses makeLockedItem
62 
63 private:
84  static void makeLockedItem(bool isrow, int64_t rowid, int64_t tableid,
85  int64_t engineid, int64_t domainid,
86  int64_t fieldid, long double floatentry,
87  std::string *stringentry,
88  std::string *returnstring);
93  void algorithm();
99  void deadlock(int64_t transactionid);
107  bool walk(int64_t transactionid);
115  bool walk(boost::unordered_set<string>::iterator itemIt);
121  void removeTransaction(int64_t transactionid);
122 
123  class Mbox *mymboxPtr;
125  class Mboxes mboxes;
127 
129  // maps:
130  // transactions with the locks it holds
131  boost::unordered_map< int64_t, boost::unordered_set<std::string> >
133  // transactions with what it waits on
134  boost::unordered_map< int64_t, boost::unordered_set<std::string> >
136  // items whose locks are held by transactions
137  boost::unordered_map< std::string, boost::unordered_set<int64_t> >
139  // items whose locks are waited for by transactions
140  boost::unordered_map< std::string, boost::unordered_set<int64_t> >
142 
143  boost::unordered_map<int64_t, taCmd> returnMap;
144 
145  boost::unordered_set<int64_t> skipTransactionSet;
146  boost::unordered_set<std::string> skipItemSet;
147 
148  // duplicates here mean deadlock:
149  boost::unordered_set<int64_t> transactionGraphSet;
150 
151 };
152 
160 void *deadlockMgr(void *identity);
161 
162 #endif /* INFINISQLDEADLOCKMGR_H */