InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
defs.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 
20 #ifndef INFINISQLDEFS_H
21 #define INFINISQLDEFS_H
22 
32 // statuses builtins
33 #define BUILTIN_STATUS_OK 0
34 #define BUILTIN_STATUS_NOTOK 1
35 
36 #define PAYLOADSIZE 128
37 #define NUMSOCKETS 1048576
38 /* following should match rtprio setting in limits.conf
39  * anything >0 and <99 should be good
40  * this is for prioritizing ObGateway & IbGateway threads
41  */
42 #define RTPRIO 30
43 #define MSGRECEIVEBATCHSIZE 500
44 #define OBGWMSGBATCHSIZE 5000
45 
46 #include "infinisql.h"
47 
52 enum __attribute__ ((__packed__)) listenertype_e
53 {
57  };
58 
59 // to builtins
65 {
66  NOCMD = 0,
73 };
74 
79 enum __attribute__ ((__packed__)) indextype_e
80 {
81  NONE = 0,
82  UNIQUE = 1,
83  NONUNIQUE = 2,
84  UNORDERED = 3,
88  };
89 
95 {
97  uniqueint = 0,
118 };
119 
125 {
126  Nomaptype = -1,
127  Unique = 0,
130 };
131 
136 enum __attribute__ ((__packed__)) topic_e
137 {
183  };
184 
191 enum __attribute__ ((__packed__)) payloadtype_e
192 {
206  };
207 
212 enum __attribute__ ((__packed__)) operationtype_e
213 {
216  };
217 
218 /* these should probably be in enums */
219 #define OPERAND_STRING 'a'
220 #define OPERAND_IDENTIFIER 'b'
221 #define OPERAND_PARAMETER 'c'
222 #define OPERAND_SUBQUERY 'd'
223 #define OPERAND_INTEGER 'e'
224 #define OPERAND_FLOAT 'f'
225 #define OPERAND_AGGREGATE 'g'
226 #define OPERAND_FIELDID 'h'
227 #define OPERAND_NULL 'i'
228 #define OPERAND_PREDICATERESULTS 'j'
229 #define OPERAND_SUBQUERYRESULTS 'k'
230 #define OPERAND_BOOLEAN 'l'
231 
232 #define AGGREGATE_AVG 'a'
233 #define AGGREGATE_COUNT 'b'
234 #define AGGREGATE_MAX 'c'
235 #define AGGREGATE_MIN 'd'
236 #define AGGREGATE_SUM 'e'
237 
238 // passing messages pertaining to specific builtins
239 #define BUILTINCREATESCHEMA 3
240 #define BUILTINCREATETABLE 4
241 #define BUILTINADDCOLUMN 5
242 #define BUILTINDELETEINDEX 6
243 #define BUILTINDELETETABLE 7
244 #define BUILTINDELETESCHEMA 8
245 #define BUILTINDUMPCONFIG 9
246 
247 // states
248 #define ST_USM 1 // waiting for user schema manager
249 #define ST_TASENGINES 2 // waiting for tas and engines to reply
250 
251 // operation type
252 #define OP_AUTH 1
253 #define OP_SCHEMA 2
254 #define OP_PGLOGIN 3
255 
256 // namespaces & usings
257 using namespace std;
258 using namespace CryptoPP;
259 using namespace msgpack;
260 using std::string;
261 using std::vector;
262 using std::map;
263 using std::multimap;
264 using msgpack::sbuffer;
265 using boost::lexical_cast;
266 
267 // enums
269 {
271 };
272 
277 enum __attribute__ ((__packed__)) pendingprimitive_e
278 {
297  };
298 
304 {
318 };
319 
321 #define SERIALIZEDMAXSIZE 1048576
322 
326 typedef struct
327 {
331 } cfg_s;
332 extern cfg_s cfgs;
333 
334 extern FILE *logfile;
335 extern std::string zmqsocket;
336 extern void *zmqcontext;
337 extern std::string storedprocprefix;
338 
343 typedef struct
344 {
345  uint64_t instance;
346  class Mbox *mbox;
347  int epollfd;
349 
354 typedef struct __attribute__ ((__packed__))
355 {
356  void *procedurecreator; //typedef ApiInterface*(*spclasscreate)();
357  void *proceduredestroyer; //typedef void(*spclassdestroy)(ApiInterface*);
358 } procedures_s;
359 
364 typedef struct
365 {
366  boost::unordered_set<std::string> locked;
367  boost::unordered_set<std::string> waiting;
369 
374 typedef struct
375 {
376  bool isrow;
377  int16_t tableid;
378  int64_t rowid; // used both for row's rowid, and index value
379  int16_t fieldid;
380  int16_t engineid; // used with rowid for index value if
381  bool deleteindexentry; // true=add, false=remove, for delete unique entry,
382  // add/delete nonunique, add/delete null
383  bool isnotaddunique; //simple flag for index entries that don't get prestaged
384  bool isreplace;
385  int64_t newrowid;
386  int16_t newengineid;
387 
389 } rowOrField_s;
390 
395 typedef struct
396 {
398  std::vector <fieldValue_s> values;
399  std::string regexString;
401 
406 typedef struct __attribute__ ((__packed__))
407 {
408  int64_t rowid;
409  int16_t engineid;
411 
413 
418 typedef struct
419 {
420  int64_t status;
421  bool isrow;
422  int64_t rowid;
423  int64_t tableid;
424  std::string row;
426  int64_t forward_rowid;
428  int64_t fieldid;
429  int64_t engineid; // index also uses rowid
430 
432  std::vector<nonLockingIndexEntry_s> indexHits;
434  std::vector<int64_t> rowids;
435  std::vector<returnRow_s> returnRows;
437 
442 typedef struct
443 {
444  std::string node;
445  std::string service;
446  int epollfd;
448 
453 typedef struct
454 {
456  bool isrow; // false, is index
457  int64_t rowid;
458  int64_t tableid;
459  int64_t engineid;
460 
461  // index entries are field value -> rowid,subtransactionid}
462  int64_t fieldid;
465 } locked_s;
466 
471 typedef struct
472 {
474  int64_t engineid;
477 
484 typedef struct
485 {
487 
488  std::string originalRow;
489  int64_t originalrowid;
492  std::string newRow;
493  int64_t newrowid;
494  int64_t newengineid;
496  // uniqueIndices[fieldid] = lockFieldValue
497  boost::unordered_map< int64_t, lockFieldValue_s > uniqueIndices;
498 } stagedRow_s;
499 
500 typedef boost::unordered_map<int64_t, class Schema *> domainidToSchemaMap;
501 
502 void debug(char *, int, char *);
503 
504 void trimspace(string &);
505 
506 // flags for row & unique index entry manipulation
507 #define DELETEFLAG 0
508 #define INSERTFLAG 1
509 #define LOCKEDFLAG 2
510 #define LOCKTYPEFLAG 3 // 0 is READLOCK 1 is WRITELOCK
511 #define REPLACEDELETEFLAG 4
512 
518 {
524 };
525 
526 class Topology;
527 extern class Topology nodeTopology;
528 extern pthread_mutex_t nodeTopologyMutex;
529 extern pthread_mutex_t connectionsMutex;
530 extern std::vector<class MboxProducer *> socketAffinity;
531 extern std::vector<listenertype_e> listenerTypes;
532 
540 void msgpack2Vector(vector<string> *resultvector, char *payload,
541  int64_t length);
549 char setdeleteflag(char *c);
557 bool getdeleteflag(char c);
565 char cleardeleteflag(char *c);
573 char setinsertflag(char *c);
581 bool getinsertflag(char c);
589 char clearinsertflag(char *c);
597 char clearlockedflag(char *c);
605 locktype_e getlocktype(char c);
613 bool setwritelock(char *c);
621 bool setreadlock(char *c);
629 char setreplacedeleteflag(char *c);
637 bool getreplacedeleteflag(char c);
645 char clearreplacedeleteflag(char *c);
646 // end of flags stuff
647 
657 int16_t getPartitionid(fieldValue_s &fieldVal, fieldtype_e type,
658  int16_t numpartitions);
664 void like2Regex(string &likeStr);
674 bool compareFields(fieldtype_e type, const fieldValue_s &val1,
675  const fieldValue_s &val2);
682 void stagedRow2ReturnRow(const stagedRow_s &stagedRow, returnRow_s &returnRow);
690 void setprio();
691 
692 #endif // INFINISQLDEFS_H