InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Transaction.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 
29 #ifndef INFINISQLTRANSACTION_H
30 #define INFINISQLTRANSACTION_H
31 
32 #include "gch.h"
33 #include "TransactionAgent.h"
34 #include "DeadlockMgr.h"
35 
36 class TransactionAgent;
37 
38 class ApiInterface;
39 typedef void(ApiInterface::*apifPtr)(int64_t, void *);
40 
41 typedef void(Statement::*statementfPtr)(int64_t, void *);
42 
47 typedef struct
48 {
49  bool isaddunique; // tells commit & rollback whether this was pre-staged by
50  // insert,update,replace
52  int64_t engineid;
53  int64_t tableid;
54  int64_t fieldid;
56 } indexInfo_s;
57 
65 {
66 public:
72  {
74  boost::unordered_map<uuRecord_s, returnRow_s> *results;
75  int64_t tableid;
77  int64_t eventwaitcount;
78  std::vector<indexEntry_s> indexHits;
81  };
82 
89  typedef struct
90  {
91  int64_t tableid;
92  class Table *tablePtr;
93  std::vector<indexInfo_s> indexEntries;
94  int64_t rowEngineid; // partition for the main field of the table
95  // where the row lives
96  int64_t rowid;
97  int64_t engineid; // for index value, not message destination!
99  std::string row;
101  int64_t engines;
102  int64_t fieldid;
103  bool isunique; // for update 1 field
105  std::string *rowPtr;
106 
107  std::vector<indexEntry_s> rowidsEngineids;
109  boost::unordered_map< int64_t, class MessageCommitRollback *>
110  replaceEngineMsgs; // for select
112  boost::unordered_map< uuRecord_s, stagedRow_s > pendingStagedRows;
117  std::string newRow;
118  std::vector<fieldValue_s> originalFieldValues;
119  std::vector<fieldValue_s> newFieldValues;
120  int64_t uniqueindices;
121  } cmdState_s;
122 
128  {
135  };
136 
137  Transaction(class TransactionAgent *taPtrarg, int64_t domainidarg);
138  virtual ~Transaction();
139 
140  // keep all/mostly public for stored procedures
141  //private:
146  void zeroCurrentCmdState();
152  void processTransactionMessage(class Message *msgrcvarg);
161  int64_t getEngineid(class Table *tablePtr, int64_t fieldnum);
171  int64_t getEngineid(class Table *tablePtr, int64_t fieldid,
172  fieldValue_s *val);
180  int64_t getEngineid(int64_t input);
188  int64_t getEngineid(uint64_t input);
196  int64_t getEngineid(bool input);
204  int64_t getEngineid(long double input);
212  int64_t getEngineid(char input);
220  int64_t getEngineid(string *input);
229  int64_t getengine(fieldtype_e fieldtype, fieldValue_s &fieldValue);
235  void dispatch(class Message *msgrcv);
241  void dispatched(class Message *msgrcv);
253  void checkLock(deadlockchange_e changetype, bool isrow, int64_t rowid,
254  int64_t tableid, int64_t engineid, int64_t fieldid,
255  fieldValue_s *fieldValue);
260  void badMessageHandler();
261  // for ApiInterface::insert()
266  void addFieldToRow();
271  void addFieldToRow(int64_t val);
276  void addFieldToRow(uint64_t val);
281  void addFieldToRow(bool val);
286  void addFieldToRow(long double val);
291  void addFieldToRow(char val);
296  void addFieldToRow(string &val);
301  void reenter();
309  bool checkNullConstraintOK(int64_t fieldnum);
317  void makeFieldValue(fieldValue_s *val, bool isnull, int64_t input);
325  void makeFieldValue(fieldValue_s *val, bool isnull, uint64_t input);
333  void makeFieldValue(fieldValue_s *val, bool isnull, bool input);
341  void makeFieldValue(fieldValue_s *val, bool isnull, long double input);
349  void makeFieldValue(fieldValue_s *val, bool isnull, char input);
357  void makeFieldValue(fieldValue_s *val, bool isnull, string input);
363  void reenter(int64_t res);
368  void replace();
377  void select(int64_t tableid, int64_t fieldid, locktype_e locktype,
378  searchParams_s *searchParameters);
384  void continueInsertRow(int64_t entrypoint);
390  void continueUpdateRow(int64_t entrypoint);
396  void continueDeleteRow(int64_t entrypoint);
402  void continueReplaceRow(int64_t entrypoint);
408  void continueSelectRows(int64_t entrypoint);
414  void continueFetchRows(int64_t entrypoint);
420  void continueUnlockRow(int64_t entrypoint);
426  void continueCommitTransaction(int64_t entrypoint);
432  void continueRollbackTransaction(int64_t entrypoint);
437  void rollback();
444  void revertback(uuRecord_s &uur, enginecmd_e cmd);
450  void abortCmd(int reentrystatus);
461  int64_t tacmdentrypoint, int64_t engineid , void *data);
467  void deadlockAbort(class MessageDeadlock &msgref);
472  void updateRow();
478  void rollback(uuRecord_s &uur);
484  void revert(uuRecord_s &uur);
492  void addRof(int64_t engineid, rowOrField_s &rof,
493  boost::unordered_map< int64_t,
494  class MessageCommitRollback *> &msgs);
502 
516  void sqlPredicate(class Statement *statement, operatortypes_e op,
517  int64_t tableid, string &leftoperand,
518  string &rightoperand, locktype_e locktype,
519  vector<fieldValue_s> &inValues, void *continuationData,
520  boost::unordered_map<uuRecord_s, returnRow_s> &results);
526  void continueSqlPredicate(int64_t entrypoint);
536  void sqlSelectAll(class Statement *statement, int64_t tableid,
537  locktype_e locktype, pendingprimitive_e pendingprimitive,
538  boost::unordered_map<uuRecord_s, returnRow_s> &results);
544  void continueSqlDelete(int64_t entrypoint);
550  void continueSqlInsert(int64_t entrypoint);
556  void continueSqlUpdate(int64_t entrypoint);
562  void continueSqlReplace(int64_t entrypoint);
574  void checkSqlLock(deadlockchange_e changetype, bool isrow, int64_t rowid,
575  int64_t tableid, int64_t engineid, int64_t fieldid,
576  fieldValue_s *fieldVal);
581  void commit();
588  int64_t getnextpendingcmdid();
589 
590  //private:
592  int64_t transactionid;
593  int64_t domainid;
595  boost::unordered_map<int64_t, int64_t> engineToSubTransactionids;
598  int64_t pendingcmdid;
599  class Message *msgrcv;
601  // lock stuff
602  int64_t lockcount;
604  // vector<locked_s> lockedItems;
605  // re-entry info for stored procedure
608  int64_t reentryCmd;
610  // end re-entry info
611  // things for each dml
613  int64_t tableid;
614  int64_t rowEngineid; // partition for the main field of the table where the
615  // row lives
616  int64_t resultCode;
617  // things for insert()
618  std::vector<fieldValue_s> fieldValues;
619  int64_t enginesWithUniqueIndices; // drain this as unique index insert
620  // messages come in
621  // rowid,tableid,engineid
622  uuRecord_s returnNewRow; // value to return as unique row after insert!,
623  // also this is the data necessary for rollback of a particular insert:
624  // rowid,tableid,engineid (and subtransactionid)
625  // for update
628  // update rollback info: engineid,tableid,fieldid,entry (and
629  // subtransactionid)
630  // for delete
631  // to rollback: rowid,tableid,engineid (and subtransactionid)
632  // for select, vector of [rowid,tableid,engineid]:
633  std::vector< uuRecord_s > returnselectedrows;
634  boost::unordered_map< uuRecord_s, stagedRow_s > stagedRows;
635  boost::unordered_map< int64_t, fieldValue_s > fieldsToUpdate;
636 
638 
640 };
641 
642 #endif /* INFINISQLTRANSACTION_H */