InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Table.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 INFINISQLTABLE_H
29 #define INFINISQLTABLE_H
30 
31 #include "gch.h"
32 #include "Field.h"
33 
37 typedef struct
38 {
39  int64_t rowid;
40  int64_t engineid;
42 
50 typedef struct
51 {
52  int64_t writelockHolder; // this is also the subtransactionid
54  char flags; // commit & rollback set this to 0
55  boost::unordered_set<int64_t> *readlockHolders;
56  string row;
57 } rowdata_s;
58 
62 typedef struct
63 {
64  int64_t pendingcmdid;
65  int64_t tacmdentrypoint;
69 
75 class Table
76 {
77 public:
78  Table(int64_t idarg);
79  virtual ~Table()
80  {
81  if (id)
82  {
83  delete shadowTable;
84  }
85  }
86 
87  friend class ApiInterface;
88  friend class TransactionAgent;
89  friend class Engine;
90  friend class Transaction;
91  friend class SubTransaction;
92  friend class UserSchemaMgr;
93 
94  //private:
100  void setname(string namearg);
107  std::string *getname();
118  int64_t addfield(fieldtype_e type, int64_t length, std::string name,
119  indextype_e indextype);
128  bool makerow(vector<fieldValue_s> *fieldVal, std::string *res);
137  bool unmakerow(std::string *rowstring,
138  vector<fieldValue_s> *resultFields);
139  // for fetch (cursor)
151  void getrows(vector<int64_t> rowids, locktype_e locktype,
152  int64_t subtransactionid, int64_t pendingcmdid,
153  vector<returnRow_s> *returnRows,
154  vector<int64_t> *lockPendingRowids, int64_t tacmdentrypoint);
155  // stage. return rowid. take command (insert|update|delete),
156  // subtransactionid,
157  // row, rowid
158  // int64_t stage(pendingprimitive_e, int64_t, string *, int64_t);
159  // commit, i guess just the rowid is enough to find it
160  // void commit(int64_t, int64_t);
161  // rollback
162  // void rollback(int64_t, int64_t);
169  int64_t getnextrowid();
177  void newrow(int64_t newrowid, int64_t subtransactionid, string &row);
187  int64_t updaterow(int64_t rowid, int64_t subtransactionid, string *row);
196  int64_t deleterow(int64_t rowid, int64_t subtransactionid);
207  int64_t deleterow(int64_t rowid, int64_t subtransactionid,
208  int64_t forward_rowid, int64_t forward_engineid);
219  void selectrows(vector<int64_t> *rowids, locktype_e locktype,
220  int64_t subtransactionid, int64_t pendingcmdid,
221  vector<returnRow_s> *returnRows, int64_t tacmdentrypoint);
233  locktype_e assignToLockQueue(int64_t rowid, locktype_e locktype,
234  int64_t subtransactionid,
235  int64_t pendingcmdid,
236  int64_t tacmdentrypoint);
237  void commitRollbackUnlock(int64_t rowid, int64_t subtransactionid,
238  enginecmd_e cmd);
239 
240  //private:
241  int64_t id;
242  std::string name;
243  int64_t nextindexid;
244  std::vector<class Field> fields;
245  boost::unordered_map< int64_t, std::queue<lockQueueRowEntry> > lockQueue;
247  boost::unordered_map<std::string, int64_t> columnaNameToFieldMap;
248  // std::unordered_map<int64_t, rowdata_s *> rows; // this is the actual data
249  boost::unordered_map<int64_t, rowdata_s *> rows; // this is the actual data
250  // boost::unordered_map<int64_t, rowdata_s> rows; // this is the actual data
251  int64_t rowsize;
252  int64_t nextrowid; // do not mess with this directly
253  // this is for the delete component of a replacement
254  boost::unordered_map<int64_t, forwarderEntry> forwarderMap;
255 };
256 
257 #endif /* INFINISQLTABLE_H */