23 #include <ndb_global.h>
28 #include "ndb_error.hpp"
29 #include "userInterface.h"
30 #include <NdbThread.h>
34 #include "ndb_schema.hpp"
36 #include <NdbSchemaCon.hpp>
78 double userGetTimeSync(
void)
80 static int initialized = 0;
81 static NDB_TICKS initSecs = 0;
82 static Uint32 initMicros = 0;
87 NdbTick_CurrentMicrosecond(&initSecs, &initMicros);
93 NdbTick_CurrentMicrosecond(&secs, µs);
95 double s = (double)secs - (
double)initSecs;
96 double us = (double)secs - (
double)initMicros;
98 timeValue = s + (us / 1000000.0);
109 if(uh->pCurrTrans != 0){
110 uh->pCurrTrans->
execute( Commit );
116 ndbout << err << endl;
120 NdbSleep_SecSleep(3);
136 extern int useTableLogging;
143 create_table_server(
Ndb * pNdb){
145 NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
146 if( MySchemaTransaction == NULL )
147 error_handler(
"startSchemaTransaction", pNdb->
getNdbError(), 0);
150 if( MySchemaOp == NULL )
151 error_handler(
"getNdbSchemaOp", MySchemaTransaction->
getNdbError(), 0);
154 check = MySchemaOp->createTable( SERVER_TABLE,
166 error_handler(
"createTable", MySchemaTransaction->
getNdbError(), 0);
168 check = MySchemaOp->createAttribute
169 ( SERVER_SUBSCRIBER_SUFFIX,
172 SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
181 error_handler(
"createAttribute (subscriber suffix)",
185 check = MySchemaOp->createAttribute( SERVER_ID,
187 sizeof(ServerId) << 3,
193 error_handler(
"createAttribute (serverid)",
197 check = MySchemaOp->createAttribute( SERVER_NAME,
205 error_handler(
"createAttribute (server name)",
209 check = MySchemaOp->createAttribute( SERVER_READS,
217 error_handler(
"createAttribute (server reads)",
220 check = MySchemaOp->createAttribute( SERVER_INSERTS,
228 error_handler(
"createAttribute (server inserts)",
231 check = MySchemaOp->createAttribute( SERVER_DELETES,
239 error_handler(
"createAttribute (server deletes)",
242 if( MySchemaTransaction->
execute() == -1 ) {
243 error_handler(
"schemaTransaction->execute()",
246 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
251 create_table_group(
Ndb * pNdb){
254 NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
255 if( MySchemaTransaction == NULL )
256 error_handler(
"startSchemaTransaction", pNdb->
getNdbError(), 0);
259 if( MySchemaOp == NULL )
260 error_handler(
"getNdbSchemaOp", MySchemaTransaction->
getNdbError(), 0);
263 check = MySchemaOp->createTable( GROUP_TABLE,
276 error_handler(
"createTable", MySchemaTransaction->
getNdbError(), 0);
279 check = MySchemaOp->createAttribute( GROUP_ID,
281 sizeof(GroupId) << 3,
287 error_handler(
"createAttribute (group id)",
290 check = MySchemaOp->createAttribute( NDB_GROUP_NAME,
298 error_handler(
"createAttribute (group name)",
302 check = MySchemaOp->createAttribute( GROUP_ALLOW_READ,
304 sizeof(Permission) << 3,
310 error_handler(
"createAttribute (group read)",
314 check = MySchemaOp->createAttribute( GROUP_ALLOW_INSERT,
316 sizeof(Permission) << 3,
322 error_handler(
"createAttribute (group insert)",
325 check = MySchemaOp->createAttribute( GROUP_ALLOW_DELETE,
327 sizeof(Permission) << 3,
333 error_handler(
"createAttribute (group delete)",
336 if( MySchemaTransaction->
execute() == -1 ) {
337 error_handler(
"schemaTransaction->execute()",
340 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
345 create_table_subscriber(
Ndb * pNdb){
347 NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
348 if( MySchemaTransaction == NULL )
349 error_handler(
"startSchemaTransaction", pNdb->
getNdbError(), 0);
352 if( MySchemaOp == NULL )
353 error_handler(
"getNdbSchemaOp", MySchemaTransaction->
getNdbError(), 0);
356 check = MySchemaOp->createTable( SUBSCRIBER_TABLE,
368 error_handler(
"createTable", MySchemaTransaction->
getNdbError(), 0);
371 check = MySchemaOp->createAttribute
375 SUBSCRIBER_NUMBER_LENGTH,
384 error_handler(
"createAttribute (subscriber number)",
387 check = MySchemaOp->createAttribute( SUBSCRIBER_NAME,
390 SUBSCRIBER_NAME_LENGTH,
395 error_handler(
"createAttribute (subscriber name)",
399 check = MySchemaOp->createAttribute( SUBSCRIBER_GROUP,
401 sizeof(GroupId) << 3,
407 error_handler(
"createAttribute (subscriber_group)",
411 check = MySchemaOp->createAttribute( SUBSCRIBER_LOCATION,
413 sizeof(Location) << 3,
419 error_handler(
"createAttribute (server reads)",
422 check = MySchemaOp->createAttribute( SUBSCRIBER_SESSIONS,
424 sizeof(ActiveSessions) << 3,
430 error_handler(
"createAttribute (subscriber_sessions)",
433 check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_BY,
441 error_handler(
"createAttribute (subscriber_changed_by)",
444 check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_TIME,
452 error_handler(
"createAttribute (subscriber_changed_time)",
455 if( MySchemaTransaction->
execute() == -1 ) {
456 error_handler(
"schemaTransaction->execute()",
459 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
464 create_table_session(
Ndb * pNdb){
466 NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
467 if( MySchemaTransaction == NULL )
468 error_handler(
"startSchemaTransaction", pNdb->
getNdbError(), 0);
471 if( MySchemaOp == NULL )
472 error_handler(
"getNdbSchemaOp",
476 check = MySchemaOp->createTable( SESSION_TABLE,
488 error_handler(
"createTable", MySchemaTransaction->
getNdbError(), 0);
490 check = MySchemaOp->createAttribute( SESSION_SUBSCRIBER,
493 SUBSCRIBER_NUMBER_LENGTH,
502 error_handler(
"createAttribute (session_subscriber)",
506 check = MySchemaOp->createAttribute( SESSION_SERVER,
508 sizeof(ServerId) << 3,
514 error_handler(
"createAttribute (session_server)",
518 check = MySchemaOp->createAttribute( SESSION_DATA,
521 SESSION_DETAILS_LENGTH,
526 error_handler(
"createAttribute (session_data)",
529 if( MySchemaTransaction->
execute() == -1 ) {
530 error_handler(
"schemaTransaction->execute()",
533 NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
539 printf(
"creating table %s...", name);
541 printf(
" it already exists\n");
547 printf(
"creating table %s... done\n", name);
550 static int dbCreate(
Ndb * pNdb)
552 create_table(SUBSCRIBER_TABLE, create_table_subscriber, pNdb);
554 create_table(SESSION_TABLE , create_table_session, pNdb);
564 userDbConnect(uint32 createDb,
const char *dbName)
567 if(con->
connect(12, 5, 1) != 0)
569 ndbout <<
"Unable to connect to management server." << endl;
574 ndbout <<
"Cluster nodes not ready in 30 seconds." << endl;
578 Ndb * pNdb =
new Ndb(con, dbName);
608 SubscriberSuffix suffix,
614 uint32 noOfInsert = 0;
615 uint32 noOfDelete = 0;
618 if(uh->pCurrTrans != 0){
619 MyTransaction = uh->pCurrTrans;
623 if (MyTransaction == NULL)
624 error_handler(
"startTranscation", uh->pNDB->
getNdbError(), 0);
627 CHECK_NULL(MyOperation,
"getNdbOperation", MyTransaction);
629 check = MyOperation->insertTuple();
630 CHECK_MINUS_ONE(check,
"insert tuple", MyTransaction);
632 check = MyOperation->equal(SERVER_ID, (
char*)&serverId);
633 CHECK_MINUS_ONE(check,
"setValue id", MyTransaction);
635 check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
636 CHECK_MINUS_ONE(check,
"setValue suffix", MyTransaction);
638 check = MyOperation->setValue(SERVER_NAME, name);
639 CHECK_MINUS_ONE(check,
"setValue name", MyTransaction);
641 check = MyOperation->setValue(SERVER_READS, (
char*)&noOfRead);
642 CHECK_MINUS_ONE(check,
"setValue reads", MyTransaction);
644 check = MyOperation->setValue(SERVER_INSERTS, (
char*)&noOfInsert);
645 CHECK_MINUS_ONE(check,
"setValue inserts", MyTransaction);
647 check = MyOperation->setValue(SERVER_DELETES, (
char*)&noOfDelete);
648 CHECK_MINUS_ONE(check,
"setValue deletes", MyTransaction);
654 SubscriberNumber number,
659 uint32 activeSessions = 0;
662 ChangedTime changedTime;
667 if(uh->pCurrTrans != 0){
668 MyTransaction = uh->pCurrTrans;
672 if (MyTransaction == NULL)
673 error_handler(
"startTranscation", uh->pNDB->
getNdbError(), 0);
676 CHECK_NULL(MyOperation,
"getNdbOperation", MyTransaction);
678 check = MyOperation->insertTuple();
679 CHECK_MINUS_ONE(check,
"insertTuple", MyTransaction);
681 check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
682 CHECK_MINUS_ONE(check,
"equal", MyTransaction);
684 check = MyOperation->setValue(SUBSCRIBER_NAME, name);
685 CHECK_MINUS_ONE(check,
"setValue name", MyTransaction);
687 check = MyOperation->setValue(SUBSCRIBER_GROUP, (
char*)&groupId);
688 CHECK_MINUS_ONE(check,
"setValue group", MyTransaction);
690 check = MyOperation->setValue(SUBSCRIBER_LOCATION, (
char*)&l);
691 CHECK_MINUS_ONE(check,
"setValue location", MyTransaction);
693 check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (
char*)&activeSessions);
694 CHECK_MINUS_ONE(check,
"setValue sessions", MyTransaction);
696 check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
697 CHECK_MINUS_ONE(check,
"setValue changedBy", MyTransaction);
699 check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
700 CHECK_MINUS_ONE(check,
"setValue changedTime", MyTransaction);
708 Permission allowRead,
709 Permission allowInsert,
710 Permission allowDelete)
715 if(uh->pCurrTrans != 0){
716 MyTransaction = uh->pCurrTrans;
720 if (MyTransaction == NULL)
721 error_handler(
"startTranscation", uh->pNDB->
getNdbError(), 0);
724 CHECK_NULL(MyOperation,
"getNdbOperation", MyTransaction);
726 check = MyOperation->insertTuple();
727 CHECK_MINUS_ONE(check,
"insertTuple", MyTransaction);
729 check = MyOperation->equal(GROUP_ID, (
char*)&groupId);
730 CHECK_MINUS_ONE(check,
"equal", MyTransaction);
732 check = MyOperation->setValue(NDB_GROUP_NAME, name);
733 CHECK_MINUS_ONE(check,
"setValue name", MyTransaction);
735 check = MyOperation->setValue(GROUP_ALLOW_READ, (
char*)&allowRead);
736 CHECK_MINUS_ONE(check,
"setValue allowRead", MyTransaction);
738 check = MyOperation->setValue(GROUP_ALLOW_INSERT, (
char*)&allowInsert);
739 CHECK_MINUS_ONE(check,
"setValue allowInsert", MyTransaction);
741 check = MyOperation->setValue(GROUP_ALLOW_DELETE, (
char*)&allowDelete);
742 CHECK_MINUS_ONE(check,
"setValue allowDelete", MyTransaction);