Informix problem
Posted in 1993
Informix Users,
Below are the code sections where the records are inserted into the
table and then the code where the data is retrieved.
Once again the process that occurs is:
o receive tx from process a
place record in master table
place record in queue for each client
broadcast to each client that there is something
in their queue
o process next transaction
When the problem shows up is when serveral TXs come in from
process a before a tx comes in from one of the client servers.
When the client server requests it usually gets the 1st record
and the immediately following TXs result in a record not found.
A later TX as a result of a later new TX from process a will
result in the record(s) that were not found earlier being returned.
Your help is greatly appreciated and please don't hestiate to call
me if there is any way that I can help.
Regards,
Hamoon Hedayat (301)340-4278
/* =========================================================================
section of code where records are placed into the table
========================================================================= */
$ struct QueRec *Qr;
LOGEnque( "CreateQue" );
NewPointer( Qr,struct QueRec *,sizeof(struct QueRec) );
NewPointer( Lastclientid,char *,clientidLen );
$ declare Newq cursor for INSERT into queue values ($Qr);
if ( sqlca.sqlcode != 0 ){
SqlErrMsg( sqlca.sqlcode,ERRLVLHEAD,
"Declaring Newq cursor" );
free(Qr);
LOGDeque();
return( sqlca.sqlcode );
}
/* Open the insert cursor for the queue table */
$ open Newq;
if ( sqlca.sqlcode != 0 ) {
SqlErrMsg( sqlca.sqlcode,ERRLVLHEAD,
"Open of Cursor for Queue Table Failed" );
LOGDeque();
return(sqlca.sqlcode);
}
/* Walk the list of clients and insert a Queue record for each client */
ClPtr = StreamHead; /* 1st in client list */
do {
if( ClPtr->serverid == SBSsvrID ) {
if((strcmp(Lastclientid,ClPtr->client->clientid)==0)) continue; /*
duplicate */
strcpy(Lastclientid,ClPtr->client->clientid); /* move ClientId */
strcpy(Qr->ClientId,ClPtr->client->clientid); /* move ClientId */
$ put Newq; /* Puts the record into the informix */
/* buffer */
if ( sqlca.sqlcode != 0 ) {
SqlErrMsg( sqlca.sqlcode,ERRLVLHEAD,
"PUT into Queue Cursor Failed" );
result = sqlca.sqlcode;
break;
}
$ flush Newq; /* force the Informix write to db */
if ( sqlca.sqlcode != 0 ) {
SqlErrMsg( sqlca.sqlcode,ERRLVLHEAD,
"SQLError FLUSH of Newq (Queue) Cursor Failed" );
result = sqlca.sqlcode;
break;
}
} /* end of if <tapelvl1 */
ClPtr = ClPtr->next; /* point to next client in list */
} while ( ClPtr != StreamHead ); /* end of while loop */
$ close Newq; /* close the cursor */
$ free Newq;
free(Qr);
/* ================== end of insertion code =============================== */
/* -------------------------------------------------------------------------
This function retrieves the NEXT record in the QUEUE table for a client
------------------------------------------------------------------------- */
long SqlGetNxtq( char *server, char *clientid,long requesttime,
char *fileid, char *accession, long *filesize )
{
long result;
$ struct QueRec Qrec;
$ char client[clientidLen];
LOGEnque( "SqlGetNxtq" );
strcpy( client,clientid );
/* declare the cursor for the retrieval */
$ DECLARE GetNxtQ cursor for
select * from queue
where clientid = $client and sbsstarttime = 0
and
qserialno = ( select min(qserialno) from queue
where clientid = $client
and
priority = ( select max(priority) from queue
where clientid = $client ) )
for Update;
/* open the queue cursor */
$ open GetNxtQ;
if ( sqlca.sqlcode == 0 ) {
$ fetch GetNxtQ into $Qrec;
if ( sqlca.sqlcode == 0 ) {
strcpy( accession, Qrec.Accession );
strcpy( fileid, Qrec.FileId );
*filesize = Qrec.FilingSize;
if ( requesttime 0 ) {
Qrec.SrvrStartTime = requesttime; /* requestors time hhmmdd*/
}
else {
Qrec.SrvrStartTime = GetTime(); /* hhmmss format as long */
}
Qrec.SrvrStartDate = GetDate(); /* YYYYMMDD format as long */
strcpy( Qrec.ServerId,server );
$ update queue set sbsstartdate=$Qrec.SrvrStartDate,
sbsstarttime=$Qrec.SrvrStartTime,serverid=$Qrec.ServerId
WHERE current of GetNxtQ;
if ( sqlca.sqlcode != 0 )
SqlErrMsg( sqlca.sqlcode,ERRLVLHEAD,
"Update of Queue Table Failed\\n" );
LOGOut(LOG,ERRLVLHEAD,
"Accession [%s] Client [%s]\\n",
Qrec.Accession,client);
result = sqlca.sqlcode;
}
else {
result = sqlca.sqlcode;
}
$ close GetNxtQ;
$ free GetNxtQ;
}
else {
result = sqlca.sqlcode;
SqlErrMsg( sqlca.sqlcode,ERRLVLHEAD,
"OPEN of GetNxtQ cursor Failed" );
}
#############################################################################
# In-Real-Life : Apostolos Dedes | GEnie : APOSTOLOS #
# Zodiac-Sign : Leo | uunet : uunet!ge!dedes #
# Organization : GEIS | Work : (301)340-4959 #
# 401 N. Washington Str. | Home : (301)990-6572 #
# Rockville, MD 20850 | Fax : (301)340-5250 #
#############################################################################