InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.cc File Reference

Contains main and various global function definitions. More...

#include <sys/un.h>
#include "version.h"
#include "gch.h"
#include "Topology.h"
Include dependency graph for main.cc:

Go to the source code of this file.

Functions

void * topologyMgr (void *)
 
int main (int argc, char **argv)
 
void msgpack2Vector (vector< string > *resultvector, char *payload, int64_t length)
 convert msgpack to a vector of strings More...
 
void debug (char *description, int line, char *file)
 
char setdeleteflag (char *c)
 for delete operations on row More...
 
bool getdeleteflag (char c)
 check if row operation is delete More...
 
char cleardeleteflag (char *c)
 clear delete operation on row More...
 
char setinsertflag (char *c)
 for insert operations on row More...
 
bool getinsertflag (char c)
 check if row operation is insert More...
 
char clearinsertflag (char *c)
 clear insert operation on row More...
 
bool setwritelock (char *c)
 set write lock on row More...
 
bool setreadlock (char *c)
 set read lock on row More...
 
char clearlockedflag (char *c)
 clear locked flag on row More...
 
locktype_e getlocktype (char c)
 check if row is locked and type More...
 
char clearreplacedeleteflag (char *c)
 clear row as deleted as part of row replacement More...
 
bool getreplacedeleteflag (char c)
 get whether or not row is deleted as part of row replacement More...
 
char setreplacedeleteflag (char *c)
 set delete as part of replace row flag More...
 
int16_t getPartitionid (fieldValue_s &fieldVal, fieldtype_e type, int16_t numpartitions)
 hash of field value for partition id More...
 
void like2Regex (string &likeStr)
 might be orpha, but convert LIKE operand to regex More...
 
bool compareFields (fieldtype_e type, const fieldValue_s &val1, const fieldValue_s &val2)
 compare field values for equality More...
 
void trimspace (string &input)
 
void stagedRow2ReturnRow (const stagedRow_s &stagedRow, returnRow_s &returnRow)
 convert stagedRow_s to returnRow_s More...
 
void setprio ()
 set real-time priority More...
 

Variables

FILE * logfile
 
cfg_s cfgs
 
std::string zmqsocket
 
class Topology nodeTopology
 
pthread_mutex_t nodeTopologyMutex
 
pthread_mutex_t connectionsMutex
 
void * zmqcontext
 
std::string storedprocprefix = "InfiniSQL_"
 
std::vector< class MboxProducer * > socketAffinity
 
std::vector< listenertype_elistenerTypes
 

Detailed Description

Contains main and various global function definitions.

Author
Mark Travis mtrav.nosp@m.is15.nosp@m.432+s.nosp@m.rc@g.nosp@m.mail..nosp@m.com
Date
Tue Dec 17 13:30:10 2013

Definition in file main.cc.

Function Documentation

char cleardeleteflag ( char *  c)

clear delete operation on row

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 156 of file main.cc.

References DELETEFLAG.

Referenced by Table::commitRollbackUnlock().

157 {
158  return *c &= ~(1 << DELETEFLAG);
159 }

Here is the caller graph for this function:

char clearinsertflag ( char *  c)

clear insert operation on row

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 171 of file main.cc.

References INSERTFLAG.

172 {
173  return *c &= ~(1 << INSERTFLAG);
174 }
char clearlockedflag ( char *  c)

clear locked flag on row

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 200 of file main.cc.

References LOCKEDFLAG.

Referenced by Table::commitRollbackUnlock().

201 {
202  return *c &= ~(1 << LOCKEDFLAG);
203 }

Here is the caller graph for this function:

char clearreplacedeleteflag ( char *  c)

clear row as deleted as part of row replacement

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 222 of file main.cc.

References REPLACEDELETEFLAG.

Referenced by Table::commitRollbackUnlock().

223 {
224  return *c &= ~(1 << REPLACEDELETEFLAG);
225 }

Here is the caller graph for this function:

bool compareFields ( fieldtype_e  type,
const fieldValue_s val1,
const fieldValue_s val2 
)

compare field values for equality

Parameters
typefield type
val1operand 1
val2operand 2
Returns
true (equal), false (unequal)

Definition at line 305 of file main.cc.

References BOOL, fieldInput_u::boolean, CHAR, fieldInput_u::character, CHARX, FLOAT, fieldInput_u::floating, INT, fieldInput_u::integer, fieldValue_s::isnull, fieldValue_s::str, UINT, fieldInput_u::uinteger, fieldValue_s::value, and VARCHAR.

Referenced by Statement::andPredicate(), Statement::stagedPredicate(), and Statement::subqueryUnique().

307 {
308  if (val1.isnull==true && val2.isnull==true)
309  {
310  return true;
311  }
312  else if (val1.isnull==true || val2.isnull==true)
313  {
314  return false;
315  }
316 
317  switch (type)
318  {
319  case INT:
320  if (val1.value.integer==val2.value.integer)
321  {
322  return true;
323  }
324 
325  break;
326 
327  case UINT:
328  if (val1.value.uinteger==val2.value.uinteger)
329  {
330  return true;
331  }
332 
333  break;
334 
335  case BOOL:
336  if (val1.value.boolean==val2.value.boolean)
337  {
338  return true;
339  }
340 
341  break;
342 
343  case FLOAT:
344  if (val1.value.floating==val2.value.floating)
345  {
346  return true;
347  }
348 
349  break;
350 
351  case CHAR:
352  if (val1.value.character==val2.value.character)
353  {
354  return true;
355  }
356 
357  break;
358 
359  case CHARX:
360  if (val1.str.compare(val2.str)==0)
361  {
362  return true;
363  }
364 
365  break;
366 
367  case VARCHAR:
368  if (val1.str.compare(val2.str)==0)
369  {
370  return true;
371  }
372 
373  break;
374 
375  default:
376  printf("%s %i anomaly %i\n", __FILE__, __LINE__, type);
377  }
378 
379  return false;
380 }

Here is the caller graph for this function:

void debug ( char *  description,
int  line,
char *  file 
)

Definition at line 141 of file main.cc.

References logfile.

142 {
143  fprintf(logfile, "DEBUG %i %s %s\n", line, file, description);
144 }
bool getdeleteflag ( char  c)

check if row operation is delete

Parameters
crowdata_s flags
Returns
is or is not set

Definition at line 151 of file main.cc.

References DELETEFLAG.

Referenced by Table::commitRollbackUnlock().

152 {
153  return c & 1 << DELETEFLAG;
154 }

Here is the caller graph for this function:

bool getinsertflag ( char  c)

check if row operation is insert

Parameters
crowdata_s flags
Returns
is or is not set

Definition at line 166 of file main.cc.

References INSERTFLAG.

Referenced by Table::assignToLockQueue(), Table::commitRollbackUnlock(), and Table::getrows().

167 {
168  return c & 1 << INSERTFLAG;
169 }

Here is the caller graph for this function:

locktype_e getlocktype ( char  c)

check if row is locked and type

Parameters
crowdata_s flags
Returns
NOLOCK|READLOCK|WRITELOCK

Definition at line 205 of file main.cc.

References LOCKEDFLAG, LOCKTYPEFLAG, NOLOCK, READLOCK, and WRITELOCK.

Referenced by Table::commitRollbackUnlock(), Table::deleterow(), Table::getrows(), Table::selectrows(), and Table::updaterow().

206 {
207  if (!(c & 1 << LOCKEDFLAG))
208  {
209  return NOLOCK;
210  }
211 
212  if (c & 1 << LOCKTYPEFLAG)
213  {
214  return WRITELOCK;
215  }
216  else
217  {
218  return READLOCK;
219  }
220 }

Here is the caller graph for this function:

int16_t getPartitionid ( fieldValue_s fieldVal,
fieldtype_e  type,
int16_t  numpartitions 
)

hash of field value for partition id

Parameters
fieldValfield value
typefield type
numpartitionsnumber of partitions
Returns

Definition at line 237 of file main.cc.

References BOOL, fieldInput_u::boolean, CHAR, fieldInput_u::character, CHARX, FLOAT, fieldInput_u::floating, SpookyHash::Hash64(), INT, fieldInput_u::integer, fieldValue_s::str, UINT, fieldInput_u::uinteger, fieldValue_s::value, and VARCHAR.

Referenced by TransactionAgent::handledispatch().

239 {
240  switch (type)
241  {
242  case INT:
243  return SpookyHash::Hash64((void *) &fieldVal.value.integer,
244  sizeof(fieldVal.value.integer), 0) %
245  numpartitions;
246  break;
247 
248  case UINT:
249  return SpookyHash::Hash64((void *) &fieldVal.value.uinteger,
250  sizeof(fieldVal.value.uinteger), 0) %
251  numpartitions;
252  break;
253 
254  case BOOL:
255  return SpookyHash::Hash64((void *) &fieldVal.value.boolean,
256  sizeof(fieldVal.value.boolean), 0) %
257  numpartitions;
258  break;
259 
260  case FLOAT:
261  return SpookyHash::Hash64((void *) &fieldVal.value.floating,
262  sizeof(fieldVal.value.floating), 0) %
263  numpartitions;
264  break;
265 
266  case CHAR:
267  return SpookyHash::Hash64((void *) &fieldVal.value.character,
268  sizeof(fieldVal.value.character), 0) %
269  numpartitions;
270  break;
271 
272  case CHARX:
273  return SpookyHash::Hash64((void *) fieldVal.str.c_str(),
274  fieldVal.str.length(), 0) % numpartitions;
275  break;
276 
277  case VARCHAR:
278  return SpookyHash::Hash64((void *) fieldVal.str.c_str(),
279  fieldVal.str.length(), 0) % numpartitions;
280  break;
281 
282  default:
283  printf("%s %i anomaly fieldtype %i\n", __FILE__, __LINE__, type);
284  return -1;
285  }
286 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool getreplacedeleteflag ( char  c)

get whether or not row is deleted as part of row replacement

Parameters
crowdata_s flags
Returns
is or is not

Definition at line 227 of file main.cc.

References REPLACEDELETEFLAG.

Referenced by Table::commitRollbackUnlock().

228 {
229  return c & 1 << REPLACEDELETEFLAG;
230 }

Here is the caller graph for this function:

void like2Regex ( string &  likeStr)

might be orpha, but convert LIKE operand to regex

Parameters
likeStrLIKE operand

Definition at line 289 of file main.cc.

Referenced by Statement::andPredicate(), Index::like(), and Index::notlike().

290 {
291  size_t pos;
292 
293  while ((pos = likeStr.find('_', 0)) != string::npos)
294  {
295  likeStr[pos]='.';
296  }
297 
298  while ((pos = likeStr.find('%', 0)) != string::npos)
299  {
300  likeStr[pos]='*';
301  likeStr.insert(pos, 1, '.');
302  }
303 }

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file main.cc.

References Topology::addressStruct::actorid, Topology::partitionAddress::address, cfg_s::compressgw, connectionsMutex, Topology::partitionAddress::instance, logfile, Topology::partitionAddress::mbox, Topology::addressStruct::nodeid, Topology::nodeid, nodeTopology, nodeTopologyMutex, topologyMgr(), Topology::partitionAddress::type, zmqcontext, and zmqsocket.

48 {
49  zmqcontext = zmq_ctx_new();
50  zmq_ctx_set(zmqcontext, ZMQ_IO_THREADS, 2);
51  setlinebuf(stdout);
52 
53  string logfilename;
54  int c;
55 
56  while ((c = getopt(argc, argv, "l:m:n:hv")) != -1)
57  {
58  switch (c)
59  {
60  case 'm':
61  zmqsocket.assign("tcp://");
62  zmqsocket.append(optarg, strlen(optarg));
63  break;
64 
65  case 'l':
66  logfilename.assign(optarg, strlen(optarg));
67  break;
68 
69  case 'n':
70  nodeTopology.nodeid = atol(optarg);
71  break;
72 
73  case 'h':
74  printf("-m <management ip:port> -n <nodeid> -l <log path/file> -v\n");
75  exit(0);
76  break;
77 
78  case 'v':
79  printf("%s\n", version);
80  exit(0);
81 
82  default:
83  ;
84  }
85  }
86 
87  if (!logfilename.size())
88  {
89  logfilename.assign("/tmp/infinisqld.log");
90  }
91 
92  logfile = fopen(logfilename.c_str(), "a");
93 
94  if (logfile==NULL)
95  {
96  printf("%s %i cannot open logfile %s errno %i\n", __FILE__, __LINE__,
97  logfilename.c_str(), errno);
98  exit(1);
99  }
100 
101  setlinebuf(logfile);
102 
103  pthread_mutexattr_t attr;
104  attr.__align = PTHREAD_MUTEX_ADAPTIVE_NP;
105  pthread_mutex_init(&nodeTopologyMutex, &attr);
106  pthread_mutex_init(&connectionsMutex, &attr);
107  pthread_t topologyMgrThread;
109  arg->type = ACTOR_TOPOLOGYMGR;
110  arg->mbox = new class Mbox;
111  arg->address.nodeid = 1;
112  arg->address.actorid = 1;
113  arg->instance = -1;
114 
115  cfgs.compressgw=true;
116 
117  int rv=pthread_create(&topologyMgrThread, NULL, topologyMgr, arg);
118  if (rv)
119  {
120  printf("%s %i pthread_create rv %i\n", __FILE__, __LINE__, rv);
121  exit(1);
122  }
123 
124  while (1)
125  {
126  sleep(10);
127  }
128 
129  return 0;
130 }

Here is the call graph for this function:

void msgpack2Vector ( vector< string > *  resultvector,
char *  payload,
int64_t  length 
)

convert msgpack to a vector of strings

Parameters
resultvectoroutput
payloadmsgpack data
lengthmsgpack length

Definition at line 133 of file main.cc.

Referenced by TransactionAgent::compile(), TransactionAgent::login(), TransactionAgent::newprocedure(), and UserSchemaMgr::UserSchemaMgr().

134 {
135  msgpack::unpacked msg;
136  msgpack::unpack(&msg, payload, length);
137  msgpack::object obj = msg.get();
138  obj.convert(resultvector);
139 }

Here is the caller graph for this function:

char setdeleteflag ( char *  c)

for delete operations on row

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 146 of file main.cc.

References DELETEFLAG.

Referenced by Table::deleterow().

147 {
148  return *c |= 1 << DELETEFLAG;
149 }

Here is the caller graph for this function:

char setinsertflag ( char *  c)

for insert operations on row

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 161 of file main.cc.

References INSERTFLAG.

Referenced by Table::newrow().

162 {
163  return *c |= 1 << INSERTFLAG;
164 }

Here is the caller graph for this function:

void setprio ( )

set real-time priority

for IbGateway and ObGateway to maximize throughput. Needs to be configured at OS level

Definition at line 424 of file main.cc.

References logfile, and RTPRIO.

Referenced by IbGateway::IbGateway(), and ObGateway::updateRemoteGateways().

425 {
426  struct sched_param params;
427  params.sched_priority=RTPRIO;
428  int rv=pthread_setschedparam(pthread_self(), SCHED_FIFO, &params);
429  if (rv != 0)
430  {
431  fprintf(logfile, "%s %i some problem setting priority %i for tid %li error %i\n", __FILE__, __LINE__, RTPRIO, pthread_self(), rv);
432  }
433 }

Here is the caller graph for this function:

bool setreadlock ( char *  c)

set read lock on row

Parameters
crowdata_s flags
Returns
success or failure

Definition at line 188 of file main.cc.

References LOCKEDFLAG, and LOCKTYPEFLAG.

Referenced by Table::commitRollbackUnlock(), Table::getrows(), and Table::selectrows().

189 {
190  if (*c & 1 << LOCKEDFLAG) // already locked
191  {
192  return false;
193  }
194 
195  *c |= 1 << LOCKEDFLAG;
196  *c &= ~(1 << LOCKTYPEFLAG);
197  return true;
198 }

Here is the caller graph for this function:

char setreplacedeleteflag ( char *  c)

set delete as part of replace row flag

Parameters
crowdata_s flags
Returns
rowdata_s flags

Definition at line 232 of file main.cc.

References REPLACEDELETEFLAG.

Referenced by Table::deleterow().

233 {
234  return *c |= 1 << REPLACEDELETEFLAG;
235 }

Here is the caller graph for this function:

bool setwritelock ( char *  c)

set write lock on row

Parameters
crowdata_s flags
Returns
success or failure

Definition at line 176 of file main.cc.

References LOCKEDFLAG, and LOCKTYPEFLAG.

Referenced by Table::getrows(), Table::newrow(), and Table::selectrows().

177 {
178  if (*c & 1 << LOCKEDFLAG) // already locked
179  {
180  return false;
181  }
182 
183  *c |= 1 << LOCKEDFLAG;
184  *c |= 1 << LOCKTYPEFLAG;
185  return true;
186 }

Here is the caller graph for this function:

void stagedRow2ReturnRow ( const stagedRow_s stagedRow,
returnRow_s returnRow 
)

convert stagedRow_s to returnRow_s

Parameters
stagedRowinput stagedRow_s
returnRowoutput returnRow_s

Definition at line 396 of file main.cc.

References stagedRow_s::cmd, INSERT, returnRow_s::locktype, stagedRow_s::locktype, stagedRow_s::newRow, stagedRow_s::newrowid, NOCOMMAND, stagedRow_s::originalRow, stagedRow_s::originalrowid, returnRow_s::previoussubtransactionid, stagedRow_s::previoussubtransactionid, returnRow_s::row, returnRow_s::rowid, and UPDATE.

Referenced by Statement::branchtotype(), and Statement::stagedPredicate().

397 {
399  returnRow.locktype=stagedRow.locktype;
400 
401  switch (stagedRow.cmd)
402  {
403  case NOCOMMAND:
404  returnRow.rowid=stagedRow.originalrowid;
405  returnRow.row=stagedRow.originalRow;
406  break;
407 
408  case INSERT:
409  returnRow.rowid=stagedRow.newrowid;
410  returnRow.row=stagedRow.newRow;
411  break;
412 
413  case UPDATE:
414  returnRow.rowid=stagedRow.newrowid;
415  returnRow.row=stagedRow.newRow;
416  break;
417 
418  default:
419  printf("%s %i anomaly %i\n", __FILE__, __LINE__, stagedRow.cmd);
420  returnRow=returnRow_s();
421  }
422 }

Here is the caller graph for this function:

void* topologyMgr ( void *  identity)

Launcher function for TopologyMgr actor

Definition at line 599 of file TopologyMgr.cc.

Referenced by main().

600 {
601  new TopologyMgr((Topology::partitionAddress *)identity);
602  while (1)
603  {
604  sleep(1000000);
605  }
606  return NULL;
607 }

Here is the caller graph for this function:

void trimspace ( string &  input)

Definition at line 382 of file main.cc.

Referenced by Index::between(), Index::comparison(), Transaction::continueCommitTransaction(), Index::deleteNonuniqueEntry(), Index::deleteUniqueEntry(), Transaction::getengine(), Transaction::getEngineid(), Index::getequal_f(), Index::getnotequal(), Index::getnotin(), Index::insertNonuniqueEntry(), Index::like(), Index::notlike(), Index::replaceNonunique(), Index::replaceUnique(), and SubTransaction::uniqueIndex().

383 {
384  size_t last=input.find_last_not_of(' ');
385 
386  if (last != string::npos)
387  {
388  input.erase(last+1);
389  }
390  else
391  {
392  input.clear();
393  }
394 }

Here is the caller graph for this function:

Variable Documentation

pthread_mutex_t connectionsMutex

Definition at line 41 of file main.cc.

Referenced by Listener::Listener(), main(), and Pg::pgclosesocket().

std::vector<listenertype_e> listenerTypes

Definition at line 45 of file main.cc.

Referenced by Listener::Listener(), and Pg::pgclosesocket().

FILE* logfile

Definition at line 36 of file main.cc.

Referenced by UserSchemaMgr::addcolumn(), TransactionAgent::addcolumn(), Table::addfield(), Statement::andPredicate(), TransactionAgent::badMessageHandler(), Index::between(), TransactionAgent::changepassword(), Index::checkAndLock(), Transaction::checkLock(), Transaction::checkSqlLock(), Index::commitRollback(), SubTransaction::commitRollbackUnlock(), Table::commitRollbackUnlock(), Index::comparison(), Transaction::continueCommitTransaction(), Transaction::continueFetchRows(), Transaction::continueInsertRow(), Pg::continuePgCommitexplicit(), Pg::continuePgCommitimplicit(), Pg::continuePgFunc(), Pg::continuePgRollbackexplicit(), Pg::continuePgRollbackimplicit(), Transaction::continueReplaceRow(), Transaction::continueRollbackTransaction(), Transaction::continueSelectRows(), Transaction::continueSqlInsert(), Transaction::continueSqlPredicate(), Transaction::continueUnlockRow(), Transaction::continueUpdateRow(), TransactionAgent::createdomain(), UserSchemaMgr::createschema(), TransactionAgent::createschema(), UserSchemaMgr::createtable(), TransactionAgent::createtable(), TransactionAgent::createuser(), DeadlockMgr::DeadlockMgr(), debug(), TransactionAgent::deletedomain(), UserSchemaMgr::deleteindex(), TransactionAgent::deleteindex(), Table::deleterow(), UserSchemaMgr::deleteschema(), TransactionAgent::deleteschema(), UserSchemaMgr::deletetable(), TransactionAgent::deletetable(), Index::deleteUniqueEntry(), TransactionAgent::deleteuser(), SubTransaction::drainIndexLockQueue(), Engine::Engine(), Transaction::getengine(), Transaction::getEngineid(), Index::getequal_f(), Index::getnotequal(), Index::getnotin(), Index::getnotnulls(), Table::getrows(), IbGateway::IbGateway(), SubTransaction::indexSearch(), Pg::initcmd(), Listener::Listener(), TransactionAgent::login(), main(), Index::makeindex(), Table::makerow(), Topology::newActor(), Pg::pgclosesocket(), SubTransaction::processTransactionMessage(), Transaction::processTransactionMessage(), Index::regex(), IbGateway::removefds(), Index::replaceUnique(), TransactionAgent::schemaBoilerplate(), Transaction::select(), Table::selectrows(), Message::ser(), MessageSocket::ser(), MessageUserSchema::ser(), MessageDeadlock::ser(), MessageTransaction::ser(), MessageSubtransactionCmd::ser(), MessageCommitRollback::ser(), MessageDispatch::ser(), MessageAckDispatch::ser(), MessageApply::ser(), MessageAckApply::ser(), setprio(), Listener::startsocket(), TopologyMgr::TopologyMgr(), TransactionAgent::TransactionAgent(), Table::unmakerow(), ObGateway::updateRemoteGateways(), Table::updaterow(), and UserSchemaMgr::UserSchemaMgr().

pthread_mutex_t nodeTopologyMutex
std::vector<class MboxProducer *> socketAffinity

Definition at line 44 of file main.cc.

Referenced by Listener::Listener(), and Pg::pgclosesocket().

std::string storedprocprefix = "InfiniSQL_"

Definition at line 43 of file main.cc.

Referenced by Pg::continueLogin(), and TransactionAgent::newprocedure().

void* zmqcontext

Definition at line 42 of file main.cc.

Referenced by main(), and TopologyMgr::TopologyMgr().

std::string zmqsocket

Definition at line 38 of file main.cc.

Referenced by main(), and TopologyMgr::TopologyMgr().