Example #1
0
/**
 * Transaction 1 - T1 
 *
 * Update location and changed by/time on a subscriber
 *
 * Input: 
 *   SubscriberNumber,
 *   Location,
 *   ChangedBy,
 *   ChangedTime
 *
 * Output:
 */
int 
T1(void * obj,
   const SubscriberNumber number, 
   const Location new_location, 
   const ChangedBy changed_by, 
   const ChangedTime changed_time,
   BenchmarkTime * transaction_time){

  Ndb * pNDB = (Ndb *) obj;

  DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);

  BenchmarkTime start;
  get_time(&start);

  int check;
  NdbRecAttr * check2;

  NdbConnection * MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), 0);

  NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
  
  check = MyOperation->updateTuple();
  CHECK_MINUS_ONE(check, "T1: updateTuple", 
		  MyTransaction);
  
  check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
			     number);
  CHECK_MINUS_ONE(check, "T1: equal subscriber",
		  MyTransaction);

  check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION, 
				(char *)&new_location);
  CHECK_MINUS_ONE(check, "T1: setValue location", 
		  MyTransaction);

  check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY, 
				changed_by);
  CHECK_MINUS_ONE(check, "T1: setValue changed_by", 
		  MyTransaction);

  check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME, 
				changed_time);
  CHECK_MINUS_ONE(check, "T1: setValue changed_time", 
		  MyTransaction);

  check = MyTransaction->execute( Commit ); 
  CHECK_MINUS_ONE(check, "T1: Commit", 
		  MyTransaction);
  
  pNDB->closeTransaction(MyTransaction);
  
  get_time(transaction_time);
  time_diff(transaction_time, &start);
  return 0;
}
int
insert_subscriber(void * obj,
		  SubscriberNumber number, 
		  SubscriberName name,
		  GroupId groupId,
		  Location l,
		  ActiveSessions activeSessions,
		  ChangedBy changedBy,
		  ChangedTime changedTime){
  Ndb * pNDB = (Ndb *)obj;
  int check;
  
  NdbConnection * MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
  
  NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
  
  check = MyOperation->insertTuple();
  CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
  
  check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
  CHECK_MINUS_ONE(check, "equal", MyTransaction);

  check = MyOperation->setValue(SUBSCRIBER_NAME, name);
  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);

  check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
  CHECK_MINUS_ONE(check, "setValue group", MyTransaction);

  check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
  CHECK_MINUS_ONE(check, "setValue location", MyTransaction);

  check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
  CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);

  check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
  CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);

  check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
  CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);

  check = MyTransaction->execute( Commit ); 
  CHECK_MINUS_ONE(check, "commit", MyTransaction);  

  pNDB->closeTransaction(MyTransaction);
  return 0;
}
int
insert_server(void * obj,
	      ServerId serverId,
	      SubscriberSuffix suffix,
	      ServerName name,
	      Counter noOfRead,
	      Counter noOfInsert,
	      Counter noOfDelete){
  Ndb * pNDB = (Ndb *)obj;
  int check;

  NdbConnection * MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
  
  NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
  
  check = MyOperation->insertTuple();
  CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);  
  
  check = MyOperation->equal(SERVER_ID, (char*)&serverId);
  CHECK_MINUS_ONE(check, "setValue id", MyTransaction);  
  
  check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
  CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);  

  check = MyOperation->setValue(SERVER_NAME, name);
  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);  

  check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
  CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);  

  check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
  CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);  

  check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
  CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);  

  check = MyTransaction->execute( Commit ); 
  CHECK_MINUS_ONE(check, "commit", MyTransaction);  
  
  pNDB->closeTransaction(MyTransaction);
  return 0;
}
int
insert_group(void * obj,
	     GroupId groupId, 
	     GroupName name,
	     Permission allowRead,
	     Permission allowInsert,
	     Permission allowDelete){
  Ndb * pNDB = (Ndb *)obj;
  int check;
  
  NdbConnection * MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
  
  NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);  
  
  check = MyOperation->insertTuple();
  CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);  
  
  check = MyOperation->equal(GROUP_ID, (char*)&groupId);
  CHECK_MINUS_ONE(check, "equal", MyTransaction);  
  
  check = MyOperation->setValue(GROUP_NAME, name);
  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);  

  check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
  CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);  

  check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
  CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);  

  check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
  CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);  
  
  check = MyTransaction->execute( Commit ); 
  CHECK_MINUS_ONE(check, "commit", MyTransaction);  
  
  pNDB->closeTransaction(MyTransaction);
  return 0;
}
Example #5
0
/**
 * Transaction 1 - T1 
 *
 * Update location and changed by/time on a subscriber
 *
 * Input: 
 *   SubscriberNumber,
 *   Location,
 *   ChangedBy,
 *   ChangedTime
 *
 * Output:
 */
void
userTransaction_T1(UserHandle * uh,
		   SubscriberNumber number, 
		   Location new_location, 
		   ChangedBy changed_by, 
		   ChangedTime changed_time){
  Ndb * pNDB = uh->pNDB;

  DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);

  int check;
  NdbRecAttr * check2;

  NdbConnection * MyTransaction = pNDB->startTransaction();
  if (MyTransaction != NULL) {
    NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
    if (MyOperation != NULL) {  
      MyOperation->updateTuple();  
      MyOperation->equal(IND_SUBSCRIBER_NUMBER,
                         number);
      MyOperation->setValue(IND_SUBSCRIBER_LOCATION, 
		            (char *)&new_location);
      MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY, 
			    changed_by);
      MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME, 
			    changed_time);
      check = MyTransaction->execute( Commit );
      if (check != -1) {
        pNDB->closeTransaction(MyTransaction);
        return;
      } else {
        CHECK_MINUS_ONE(check, "T1: Commit", 
		        MyTransaction);
      }//if
    } else {
      CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
    }//if
  } else {
    error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
  }//if
}
Example #6
0
/**
 * Transaction 2 - T2
 *
 * Read from Subscriber:
 *
 * Input: 
 *   SubscriberNumber
 *
 * Output:
 *   Location
 *   Changed by
 *   Changed Timestamp
 *   Name
 */
void
userTransaction_T2(UserHandle * uh,
		   SubscriberNumber number, 
		   Location * readLocation, 
		   ChangedBy changed_by, 
		   ChangedTime changed_time,
		   SubscriberName subscriberName){
  Ndb * pNDB = uh->pNDB;

  DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);

  int check;
  NdbRecAttr * check2;

  NdbConnection * MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("T2-1: startTransaction", pNDB->getNdbErrorString(), pNDB->getNdbError());

  NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  CHECK_NULL(MyOperation, "T2: getNdbOperation", 
	     MyTransaction);
  
  MyOperation->readTuple();
  MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
		     number);
  MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
			(char *)readLocation);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
			changed_by);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
                        changed_time);
  MyOperation->getValue(IND_SUBSCRIBER_NAME, 
			subscriberName);
  check = MyTransaction->execute( Commit ); 
  CHECK_MINUS_ONE(check, "T2: Commit", 
		  MyTransaction);  
  pNDB->closeTransaction(MyTransaction);
}
/**
 * Transaction 5 - T5
 *
 * Delete session
 *
 * Input:
 *   SubscriberNumber
 *   ServerId
 *   ServerBit
 *   DoRollback
 * Output:
 *   ChangedBy
 *   ChangedTime
 *   Location
 *   BranchExecuted
 */
int
T5(void * obj,
   const SubscriberNumber   inNumber,
   const SubscriberSuffix   inSuffix,
   const ServerId           inServerId,
   const ServerBit          inServerBit,
   ChangedBy          outChangedBy,
   ChangedTime        outChangedTime,
   Location         * outLocation,
   DoRollback         inDoRollback,
   BranchExecuted   * outBranchExecuted,
   BenchmarkTime    * outTransactionTime) {

    Ndb           * pNDB = (Ndb *) obj;
    NdbConnection * MyTransaction = 0;
    NdbOperation  * MyOperation = 0;

    GroupId        groupId;
    ActiveSessions sessions;
    Permission     permission;

    BenchmarkTime start;
    get_time(&start);

    int check;
    NdbRecAttr * check2;

    MyTransaction = pNDB->startTransaction();
    if (MyTransaction == NULL)
        error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);

    MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
    CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
               MyTransaction);


    check = MyOperation->readTupleExclusive();
    CHECK_MINUS_ONE(check, "T5-1: readTuple",
                    MyTransaction);

    check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
                               inNumber);
    CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
                    MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
                                   (char *)outLocation);
    CHECK_NULL(check2, "T5-1: getValue location",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
                                   outChangedBy);
    CHECK_NULL(check2, "T5-1: getValue changed_by",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
                                   outChangedTime);
    CHECK_NULL(check2, "T5-1: getValue changed_time",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
                                   (char *)&groupId);
    CHECK_NULL(check2, "T5-1: getValue group",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
                                   (char *)&sessions);
    CHECK_NULL(check2, "T5-1: getValue sessions",
               MyTransaction);

    check = MyTransaction->execute( NoCommit );
    CHECK_MINUS_ONE(check, "T5-1: NoCommit",
                    MyTransaction);

    /* Operation 2 */

    MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
    CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
               MyTransaction);


    check = MyOperation->readTuple();
    CHECK_MINUS_ONE(check, "T5-2: readTuple",
                    MyTransaction);

    check = MyOperation->equal(IND_GROUP_ID,
                               (char*)&groupId);
    CHECK_MINUS_ONE(check, "T5-2: equal group",
                    MyTransaction);

    check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
                                   (char *)&permission);
    CHECK_NULL(check2, "T5-2: getValue allow_delete",
               MyTransaction);

    check = MyTransaction->execute( NoCommit );
    CHECK_MINUS_ONE(check, "T5-2: NoCommit",
                    MyTransaction);

    DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);

    if(((permission & inServerBit) == inServerBit) &&
            ((sessions   & inServerBit) == inServerBit)) {

        DEBUG("deleting - ");

        /* Operation 3 */
        MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
        CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
                   MyTransaction);

        check = MyOperation->deleteTuple();
        CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
                        MyTransaction);

        check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
                                   (char*)inNumber);
        CHECK_MINUS_ONE(check, "T5-3: equal number",
                        MyTransaction);

        check = MyOperation->equal(IND_SESSION_SERVER,
                                   (char*)&inServerId);
        CHECK_MINUS_ONE(check, "T5-3: equal server id",
                        MyTransaction);

        check = MyTransaction->execute( NoCommit );
        CHECK_MINUS_ONE(check, "T5-3: NoCommit",
                        MyTransaction);

        /* Operation 4 */
        MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
        CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
                   MyTransaction);

        check = MyOperation->interpretedUpdateTuple();
        CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
                        MyTransaction);

        check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
                                   (char*)inNumber);
        CHECK_MINUS_ONE(check, "T5-4: equal number",
                        MyTransaction);

        check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
                                      (uint32)inServerBit);
        CHECK_MINUS_ONE(check, "T5-4: dec value",
                        MyTransaction);

        check = MyTransaction->execute( NoCommit );
        CHECK_MINUS_ONE(check, "T5-4: NoCommit",
                        MyTransaction);

        /* Operation 5 */
        MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
        CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
                   MyTransaction);


        check = MyOperation->interpretedUpdateTuple();
        CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
                        MyTransaction);

        check = MyOperation->equal(IND_SERVER_ID,
                                   (char*)&inServerId);
        CHECK_MINUS_ONE(check, "T5-5: equal serverId",
                        MyTransaction);

        check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
                                   (char*)inSuffix);
        CHECK_MINUS_ONE(check, "T5-5: equal suffix",
                        MyTransaction);

        check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
        CHECK_MINUS_ONE(check, "T5-5: inc value",
                        MyTransaction);

        check = MyTransaction->execute( NoCommit );
        CHECK_MINUS_ONE(check, "T5-5: NoCommit",
                        MyTransaction);

        (* outBranchExecuted) = 1;
    } else {
        DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
        DEBUG1("%s", ((sessions   & inServerBit) ? "in session - " : "no in session - "));
        (* outBranchExecuted) = 0;
    }

    if(!inDoRollback) {
        DEBUG("commit\n");
        check = MyTransaction->execute( Commit );
        CHECK_MINUS_ONE(check, "T5: Commit",
                        MyTransaction);
    } else {
        DEBUG("rollback\n");
        check = MyTransaction->execute(Rollback);
        CHECK_MINUS_ONE(check, "T5:Rollback",
                        MyTransaction);

    }

    pNDB->closeTransaction(MyTransaction);

    get_time(outTransactionTime);
    time_diff(outTransactionTime, &start);
    return 0;
}
/**
 * Transaction 3 - T3
 *
 * Read session details
 *
 * Input:
 *   SubscriberNumber
 *   ServerId
 *   ServerBit
 *
 * Output:
 *   BranchExecuted
 *   SessionDetails
 *   ChangedBy
 *   ChangedTime
 *   Location
 */
int
T3(void * obj,
   const SubscriberNumber   inNumber,
   const SubscriberSuffix   inSuffix,
   const ServerId           inServerId,
   const ServerBit          inServerBit,
   SessionDetails     outSessionDetails,
   ChangedBy          outChangedBy,
   ChangedTime        outChangedTime,
   Location         * outLocation,
   BranchExecuted   * outBranchExecuted,
   BenchmarkTime    * outTransactionTime) {

    Ndb * pNDB = (Ndb *) obj;

    GroupId        groupId;
    ActiveSessions sessions;
    Permission     permission;

    BenchmarkTime start;
    get_time(&start);

    int check;
    NdbRecAttr * check2;

    NdbConnection * MyTransaction = pNDB->startTransaction();
    if (MyTransaction == NULL)
        error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);

    NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
    CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
               MyTransaction);


    check = MyOperation->readTuple();
    CHECK_MINUS_ONE(check, "T3-1: readTuple",
                    MyTransaction);

    check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
                               inNumber);
    CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
                    MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
                                   (char *)outLocation);
    CHECK_NULL(check2, "T3-1: getValue location",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
                                   outChangedBy);
    CHECK_NULL(check2, "T3-1: getValue changed_by",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
                                   outChangedTime);
    CHECK_NULL(check2, "T3-1: getValue changed_time",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
                                   (char *)&groupId);
    CHECK_NULL(check2, "T3-1: getValue group",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
                                   (char *)&sessions);
    CHECK_NULL(check2, "T3-1: getValue sessions",
               MyTransaction);

    check = MyTransaction->execute( NoCommit );
    CHECK_MINUS_ONE(check, "T3-1: NoCommit",
                    MyTransaction);

    /* Operation 2 */

    MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
    CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
               MyTransaction);


    check = MyOperation->readTuple();
    CHECK_MINUS_ONE(check, "T3-2: readTuple",
                    MyTransaction);

    check = MyOperation->equal(IND_GROUP_ID,
                               (char*)&groupId);
    CHECK_MINUS_ONE(check, "T3-2: equal group",
                    MyTransaction);

    check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
                                   (char *)&permission);
    CHECK_NULL(check2, "T3-2: getValue allow_read",
               MyTransaction);

    check = MyTransaction->execute( NoCommit );
    CHECK_MINUS_ONE(check, "T3-2: NoCommit",
                    MyTransaction);

    DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);

    if(((permission & inServerBit) == inServerBit) &&
            ((sessions   & inServerBit) == inServerBit)) {

        DEBUG("reading - ");

        /* Operation 3 */

        MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
        CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
                   MyTransaction);

        check = MyOperation->readTuple();
        CHECK_MINUS_ONE(check, "T3-3: readTuple",
                        MyTransaction);

        check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
                                   (char*)inNumber);
        CHECK_MINUS_ONE(check, "T3-3: equal number",
                        MyTransaction);

        check = MyOperation->equal(IND_SESSION_SERVER,
                                   (char*)&inServerId);
        CHECK_MINUS_ONE(check, "T3-3: equal server id",
                        MyTransaction);

        check2 = MyOperation->getValue(IND_SESSION_DATA,
                                       (char *)outSessionDetails);
        CHECK_NULL(check2, "T3-3: getValue session details",
                   MyTransaction);

        check = MyTransaction->execute( NoCommit );
        CHECK_MINUS_ONE(check, "T3-3: NoCommit",
                        MyTransaction);

        /* Operation 4 */

        MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
        CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
                   MyTransaction);

        check = MyOperation->interpretedUpdateTuple();
        CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
                        MyTransaction);

        check = MyOperation->equal(IND_SERVER_ID,
                                   (char*)&inServerId);
        CHECK_MINUS_ONE(check, "T3-4: equal serverId",
                        MyTransaction);

        check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
                                   (char*)inSuffix);
        CHECK_MINUS_ONE(check, "T3-4: equal suffix",
                        MyTransaction);

        check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
        CHECK_MINUS_ONE(check, "T3-4: inc value",
                        MyTransaction);

        check = MyTransaction->execute( NoCommit );
        CHECK_MINUS_ONE(check, "T3-4: NoCommit",
                        MyTransaction);

        (* outBranchExecuted) = 1;
    } else {
        (* outBranchExecuted) = 0;
    }
    DEBUG("commit\n");
    check = MyTransaction->execute( Commit );
    CHECK_MINUS_ONE(check, "T3: Commit",
                    MyTransaction);

    pNDB->closeTransaction(MyTransaction);

    get_time(outTransactionTime);
    time_diff(outTransactionTime, &start);
    return 0;
}
/**
 * Transaction 2 - T2
 *
 * Read from Subscriber:
 *
 * Input:
 *   SubscriberNumber
 *
 * Output:
 *   Location
 *   Changed by
 *   Changed Timestamp
 *   Name
 */
int
T2(void * obj,
   const SubscriberNumber number,
   Location * readLocation,
   ChangedBy changed_by,
   ChangedTime changed_time,
   SubscriberName subscriberName,
   BenchmarkTime * transaction_time) {

    Ndb * pNDB = (Ndb *) obj;

    BenchmarkTime start;
    get_time(&start);

    int check;
    NdbRecAttr * check2;

    NdbConnection * MyTransaction = pNDB->startTransaction();
    if (MyTransaction == NULL)
        error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);

    NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
    CHECK_NULL(MyOperation, "T2: getNdbOperation",
               MyTransaction);


    check = MyOperation->readTuple();
    CHECK_MINUS_ONE(check, "T2: readTuple",
                    MyTransaction);

    check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
                               number);
    CHECK_MINUS_ONE(check, "T2: equal subscriber",
                    MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
                                   (char *)readLocation);
    CHECK_NULL(check2, "T2: getValue location",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
                                   changed_by);
    CHECK_NULL(check2, "T2: getValue changed_by",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
                                   changed_time);
    CHECK_NULL(check2, "T2: getValue changed_time",
               MyTransaction);

    check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
                                   subscriberName);
    CHECK_NULL(check2, "T2: getValue name",
               MyTransaction);

    check = MyTransaction->execute( Commit );
    CHECK_MINUS_ONE(check, "T2: Commit",
                    MyTransaction);

    pNDB->closeTransaction(MyTransaction);

    get_time(transaction_time);
    time_diff(transaction_time, &start);
    return 0;
}
Example #10
0
/**
 * Transaction 5 - T5
 * 
 * Delete session
 *
 * Input:
 *   SubscriberNumber
 *   ServerId
 *   ServerBit
 *   DoRollback
 * Output:
 *   ChangedBy
 *   ChangedTime
 *   Location
 *   BranchExecuted
 */
void
userTransaction_T5(UserHandle * uh,
		   SubscriberNumber   inNumber,
		   ServerId           inServerId,
		   ServerBit          inServerBit,
		   DoRollback         inDoRollback,
		   BranchExecuted   * outBranchExecuted){
  Ndb * pNDB = uh->pNDB;

  DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);

  NdbConnection * MyTransaction = 0;
  NdbOperation  * MyOperation = 0;

  char             outChangedBy   [sizeof(ChangedBy)  +(4-(sizeof(ChangedBy)   & 3))];
  char             outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
  Location         outLocation;
  GroupId          groupId;
  ActiveSessions   sessions;
  Permission       permission;
  SubscriberSuffix inSuffix;

  int check;
  NdbRecAttr * check2;

  MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
  
  MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  CHECK_NULL(MyOperation, "T5-1: getNdbOperation", 
	     MyTransaction);
  
  MyOperation->interpretedUpdateTuple();
  MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
		     inNumber);
  MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
		        (char *)&outLocation);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
			&outChangedBy[0]);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
                        &outChangedTime[0]);
  MyOperation->getValue(IND_SUBSCRIBER_GROUP,
		        (char *)&groupId);
  MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
		        (char *)&sessions);
  MyOperation->subValue(IND_SUBSCRIBER_SESSIONS, 
		        (uint32)inServerBit);
  MyTransaction->execute( NoCommit ); 
    /* Operation 2 */

  MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
  CHECK_NULL(MyOperation, "T5-2: getNdbOperation", 
	     MyTransaction);
    
  MyOperation->readTuple();
  MyOperation->equal(IND_GROUP_ID,
		     (char*)&groupId);
  MyOperation->getValue(IND_GROUP_ALLOW_DELETE, 
			(char *)&permission);
  check = MyTransaction->execute( NoCommit ); 
  CHECK_MINUS_ONE(check, "T5-2: NoCommit", 
		  MyTransaction);
  
  if(((permission & inServerBit) == inServerBit) &&
     ((sessions   & inServerBit) == inServerBit)){
  
    memcpy(inSuffix,
	   &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
    
    DEBUG2("deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);

    /* Operation 3 */
    MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
    CHECK_NULL(MyOperation, "T5-3: getNdbOperation", 
	       MyTransaction);
    
    MyOperation->deleteTuple();
    MyOperation->equal(IND_SESSION_SUBSCRIBER,
		       (char*)inNumber);
    MyOperation->equal(IND_SESSION_SERVER,
		       (char*)&inServerId);
    /* Operation 4 */
        
    /* Operation 5 */
    MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
    CHECK_NULL(MyOperation, "T5-5: getNdbOperation", 
	       MyTransaction);
    
    
    MyOperation->interpretedUpdateTuple();
    MyOperation->equal(IND_SERVER_ID,
		       (char*)&inServerId);
    MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
		       (char*)inSuffix);
    MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
    (* outBranchExecuted) = 1;
  } else {
    (* outBranchExecuted) = 0;
    DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
    DEBUG1("%s", ((sessions   & inServerBit) ? "in session - " : "no in session - "));
  }

  if(!inDoRollback && (* outBranchExecuted)){
    DEBUG("commit\n");
    check = MyTransaction->execute( Commit ); 
    CHECK_MINUS_ONE(check, "T5: Commit", 
		    MyTransaction);
  } else {
    DEBUG("rollback\n");
    check = MyTransaction->execute(Rollback);
    CHECK_MINUS_ONE(check, "T5:Rollback", 
		    MyTransaction);
    
  }
  
  pNDB->closeTransaction(MyTransaction);
}
Example #11
0
/**
 * Transaction 3 - T3
 *
 * Read session details
 *
 * Input:
 *   SubscriberNumber
 *   ServerId
 *   ServerBit
 *
 * Output:
 *   BranchExecuted
 *   SessionDetails
 *   ChangedBy
 *   ChangedTime
 *   Location
 */
void
userTransaction_T3(UserHandle * uh,
		   SubscriberNumber   inNumber,
		   ServerId           inServerId,
		   ServerBit          inServerBit,
		   SessionDetails     outSessionDetails,
		   BranchExecuted   * outBranchExecuted){
  Ndb * pNDB = uh->pNDB;

  char               outChangedBy   [sizeof(ChangedBy)  +(4-(sizeof(ChangedBy)   & 3))];
  char               outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
  Location           outLocation;
  GroupId            groupId;
  ActiveSessions     sessions;
  Permission         permission;
  SubscriberSuffix   inSuffix;

  DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);

  int check;
  NdbRecAttr * check2;

  NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
  if (MyTransaction == NULL)	  
    error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());

  NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  CHECK_NULL(MyOperation, "T3-1: getNdbOperation", 
	     MyTransaction);
    
  MyOperation->readTuple();
  MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
			     inNumber);
  MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
			(char *)&outLocation);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
			outChangedBy);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
                        outChangedTime);
  MyOperation->getValue(IND_SUBSCRIBER_GROUP,
			(char *)&groupId);
  MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
			(char *)&sessions);
  check = MyTransaction->execute( NoCommit ); 
  CHECK_MINUS_ONE(check, "T3-1: NoCommit", 
		  MyTransaction);
  
    /* Operation 2 */

  MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
  CHECK_NULL(MyOperation, "T3-2: getNdbOperation", 
	     MyTransaction);
  
  
  MyOperation->readTuple();
  MyOperation->equal(IND_GROUP_ID,
		     (char*)&groupId);
  MyOperation->getValue(IND_GROUP_ALLOW_READ, 
			(char *)&permission);
  check = MyTransaction->execute( NoCommit ); 
  CHECK_MINUS_ONE(check, "T3-2: NoCommit", 
		  MyTransaction);
  
  if(((permission & inServerBit) == inServerBit) &&
     ((sessions   & inServerBit) == inServerBit)){

    memcpy(inSuffix,
	   &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
    DEBUG2("reading(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
    
    /* Operation 3 */
    MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
    CHECK_NULL(MyOperation, "T3-3: getNdbOperation", 
	       MyTransaction);
    
    MyOperation->simpleRead();
  
    MyOperation->equal(IND_SESSION_SUBSCRIBER,
		       (char*)inNumber);
    MyOperation->equal(IND_SESSION_SERVER,
		       (char*)&inServerId);
    MyOperation->getValue(IND_SESSION_DATA, 
			  (char *)outSessionDetails);
    /* Operation 4 */
    MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
    CHECK_NULL(MyOperation, "T3-4: getNdbOperation", 
	       MyTransaction);
    
    MyOperation->interpretedUpdateTuple();
    MyOperation->equal(IND_SERVER_ID,
		       (char*)&inServerId);
    MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
		        (char*)inSuffix);
    MyOperation->incValue(IND_SERVER_READS, (uint32)1);
    (* outBranchExecuted) = 1;
  } else {
    (* outBranchExecuted) = 0;
  }
  DEBUG("commit...");
  check = MyTransaction->execute( Commit ); 
  CHECK_MINUS_ONE(check, "T3: Commit", 
		  MyTransaction);
  
  pNDB->closeTransaction(MyTransaction);
  
  DEBUG("done\n");
}