Example #1
0
/* PROGRAM: dsmDatabaseProcessEvents - perform xxx processing
 *
 * NOTE: Quiet points and tmdelayed commit are supported here
 * 
 * RETURNS: DSM_S_SUCCESS
 *          DSM_S_INVALID_USER
 *          DSM_S_SHUT_DOWN on EXBAD or EXGOOD
 */
dsmStatus_t
dsmDatabaseProcessEvents(
        dsmContext_t *pcontext)
{
    dbcontext_t *pdbcontext = pcontext->pdbcontext;
    dbshm_t     *pdbshm     = pdbcontext->pdbpub;
    usrctl_t    *pusr       = pcontext->pusrctl;
    mstrblk_t   *pmstr;
    dsmStatus_t  returnCode;

#if OPSYS==WIN32API
    if (fWin95)
        return -1;
#endif

    pdbcontext->inservice++;  /* "post-pone" signal handling while in DSM API */
 
    SETJMP_ERROREXIT(pcontext, returnCode) /* Ensure error exit address set */

    if ((returnCode = dsmThreadSafeEntry(pcontext)) != DSM_S_SUCCESS)
    {
        returnCode = dsmEntryProcessError(pcontext, returnCode,
                      (TEXT *)"dsmDatabaseProcessEvents");
        goto done;
    }

    /* Check for quiet point command requests */
    if (pdbshm->quietpoint == QUIET_POINT_REQUEST)
    {
        /* Shut off update activity for the quiet point */
        rlTXElock(pcontext,RL_TXE_EXCL,RL_MISC_OP);
        MT_LOCK_MTX();
        pmstr = pdbcontext->pmstrblk;

        /* Switch after imaging extent if there are ai extents */
        if( rlaiqon(pcontext) && pmstr->mb_aibusy_extent > 0 )
        {
            MT_LOCK_AIB();
            if (rlaiswitch(pcontext, (int)RLAI_NEW, 1) )
            {
                MT_UNLK_AIB();
                /* Unable to switch to new ai extent */
                MSGN_CALLBACK(pcontext, drMSG205);
                if ( MTHOLDING(MTL_MTX) )
                     MT_UNLK_MTX();

                if ( pusr->uc_txelk )
                    rlTXEunlock(pcontext);
                goto done;
            }
            MT_UNLK_AIB();
        }

        /* Flush the buffer pool and bi buffers */
        rlbiflsh(pcontext,RL_FLUSH_ALL_BI_BUFFERS);
 
        /* At this point, the quiet point is in place */
        MSGN_CALLBACK(pcontext, drMSG402);
        pdbshm->quietpoint = QUIET_POINT_ENABLED;
        while(pdbshm->quietpoint == QUIET_POINT_ENABLED &&
              !pdbshm->shutdn)
        {
            utsleep(1);
        }
        MT_UNLK_MTX();
        rlTXEunlock(pcontext);        /* Release transaction end lock */

        /* At this point, normal operations can return */
        MSGN_CALLBACK(pcontext, drMSG403);
        pdbshm->quietpoint = QUIET_POINT_NORMAL;       
    }
 
    /* Process delayed commit (-Mf) */
    tmchkdelay(pcontext, 0);
    /* Check if table locking can be shut off    */
    lkTableLockCheck(pcontext);

    returnCode = DSM_S_SUCCESS;

done:
    dsmThreadSafeExit(pcontext);
    pdbcontext->inservice--;  /* re-allow signal handling */

    return returnCode;

}  /* end dsmDatabaseProcessEvents */
Example #2
0
/* PROGRAM: dbQuietPoint - evaluate the quiet request and
 *                         enable or disable the quiet point.
 *
 * RETURNS: 0 - success
 *          non-zero - failure
 */
int
dbQuietPoint(dsmContext_t *pcontext,
             UCOUNT        quietRequest,
             ULONG         quietArg)
{
    int returnCode = 0;       /* status of the quiet request */
    dbcontext_t  *pdbcontext = pcontext->pdbcontext;
    dbshm_t      *pdbshm = pdbcontext->pdbpub;
    usrctl_t     *pusrctl = pcontext->pusrctl;
    RLCTL        *prl = pdbcontext->prlctl;
    LONG64        bithreshold = 0;
    DOUBLE        bitholdBytes = 0;
    DOUBLE        bitholdSize = 0;
    TEXT          sizeId;
    DOUBLE        fromBitholdBytes = 0;
    DOUBLE        fromBitholdSize = 0;
    TEXT          fromSizeId;
    DOUBLE        toBitholdBytes = 0;
    DOUBLE        toBitholdSize = 0;
    TEXT          toSizeId;
    TEXT          printBuffer[13];
    TEXT          fromPrintBuffer[13];
    TEXT          toPrintBuffer[13];


    /* Before we attempt to enable or disable the quiescent point */
    /* we need to check for the existence of the broker.          */

        if (!deadpid(pcontext, pdbshm->brokerpid))
        {
            if (quietRequest == QUIET_POINT_REQUEST)
            {
                if (!pdbshm->quietpoint == QUIET_POINT_NORMAL)
                {
                    if ((pdbshm->quietpoint == QUIET_POINT_REQUEST) ||
                       (pdbshm->quietpoint == QUIET_POINT_ENABLED)) 
                    {
                        /* Quiet point has already been requested. */
                        MSGN_CALLBACK(pcontext, drMSG392);
                        returnCode = 4;
                    }
                     else
                    {
                        /* Protect against a second user trying to quiet */
                        /* Enabling the quiet point is in effect. */
                        MSGN_CALLBACK(pcontext, drMSG393);
                        returnCode = 6;
                    }
                }
                else
                /* Database is in the Normal Processing State */
                {
                    
                    /* Check if after imaging is enabled without */
                    /* the use of after image extents.           */
                    if ( rlaiqon(pcontext) == 1 && 
                         pdbcontext->pmstrblk->mb_aibusy_extent == 0 )
                    {
                        /* Cannot enable with single ai file */
                        MSGN_CALLBACK(pcontext, drMSG394);
                        returnCode = 2;
                    }
                    else  
                    {

                    /* Reset the shared memory variable to request    */
                    /* the enabling of the quiet point by the broker. */
                    pdbshm->quietpoint = QUIET_POINT_REQUEST;

                    /* Loop until the quietpoint state changes to */
                    /* QUIET_POINT_ENABLED */
                    for (;;)
                    {
                        /* Test for brokers existence and whether */
                        /* shutdown has already occurred. */
                        if (deadpid(pcontext, pdbshm->brokerpid)) 
                        {
                            MSGN_CALLBACK(pcontext, drMSG395);
                            returnCode = 16;
                            break;
                        }

                        /* Check to see if a shutdown was received. */
                        if (pusrctl->usrtodie)
                        {
                                MSGN_CALLBACK(pcontext, drMSG396);
                                returnCode = 16;
                                break;
                        }

                        if (pdbshm->quietpoint == QUIET_POINT_ENABLED)
                        {
                            pdbcontext->usertype |= DBSHUT;
                            returnCode = 0;
                            break;
                        }
                        utsleep(1);
                    }

                    } 
                }
            }
            /* Disable the Ouiet Point */
            else if (quietRequest == QUIET_POINT_DISABLE)
            {
                /* Database is in the Normal Processing State */
                if (pdbshm->quietpoint == QUIET_POINT_ENABLED)
                {
                    /* Reset the shared memory variable to request    */
                    /* the enabling of the quiet point by the broker. */
                    pdbshm->quietpoint = QUIET_POINT_DISABLE;

                    /* Loop until the quietpoint state changes to */
                    /* QUIET_POINT_ENABLED */
                    for (;;)
                    {
                        /* Test for brokers existence */
                        if (deadpid(pcontext, pdbshm->brokerpid))
                        {
                            MSGN_CALLBACK(pcontext, drMSG397);
                            pdbcontext->usertype |= DBSHUT;
                            returnCode = 16;
                            break;
                        }

                        /* Check to see if a shutdown was received. */
                        if (pusrctl->usrtodie)
                        {
                            MSGN_CALLBACK(pcontext, drMSG398);
                            pdbcontext->usertype |= DBSHUT;
                            returnCode = 16;
                            break;
                        }
                            
                        if (pdbshm->quietpoint == QUIET_POINT_NORMAL)
                        {
                            pdbcontext->usertype |= DBSHUT;
                            returnCode = 0;
                            break;
                        }
                        utsleep(1);
                    }
                }
                else if (pdbshm->quietpoint != QUIET_POINT_ENABLED)
                {
                    /* Quiet point does not need to be disabled. */
                    MSGN_CALLBACK(pcontext, drMSG399);
                    pdbcontext->usertype |= DBSHUT;
                    returnCode = 3;
                }
            }
            else if (quietRequest == QUIET_POINT_BITHRESHOLD)
            {
                 /* Round down bi threshold by a cluster if it is set */
                 bithreshold =
                     ( (((LONG64)quietArg * 1048576) / prl->rlbiblksize)
                          - (prl->rlclbytes / prl->rlbiblksize) );

                 if (bithreshold > 0 && bithreshold > prl->rlsize)
                     
                 {
                     /* Validate the bi threshold value */
                     if (pdbshm->bithold == bithreshold)
                     {
                         /* bithold size same, request to change rejected */
                         bitholdBytes =
                                    (DOUBLE)bithreshold * prl->rlbiblksize;
                         utConvertBytes(bitholdBytes,
                                        &bitholdSize, &sizeId);
                         sprintf((char *)printBuffer, "%-5.1f %cBytes",
                                               bitholdSize, sizeId);
                         MSGN_CALLBACK(pcontext, drMSG687, printBuffer);
                         MSGN_CALLBACK(pcontext, drMSG451);
                         returnCode = 3;
                     }
                     else if (pdbshm->bithold == 0 
                              || pdbshm->bithold > (ULONG)prl->rlsize)
                     {
                         if (pdbshm->quietpoint != QUIET_POINT_ENABLED)
                         {
                             /* Quiet point not enabled and stall did not occur.
                                Request to change bi threshold rejected */
                             MSGN_CALLBACK(pcontext, drMSG452);
                             MSGN_CALLBACK(pcontext, drMSG451);
                             returnCode = 3;
                         }
                         else
                         {
                             /* Make sure new bi threshold is larger than
                                bi file size */
                             if (bithreshold >= prl->rlsize)
                             {
                                 /* bi threshold changed from value to value */
                                 fromBitholdBytes =
                                    (DOUBLE)pdbshm->bithold * prl->rlbiblksize;
                                 utConvertBytes(fromBitholdBytes,
                                                &fromBitholdSize, &fromSizeId);
                                 sprintf((char *)fromPrintBuffer, "%-5.1f %cBytes",
                                               fromBitholdSize, fromSizeId);
                                 toBitholdBytes =
                                    (DOUBLE)bithreshold * prl->rlbiblksize;
                                 utConvertBytes(toBitholdBytes,
                                                &toBitholdSize, &toSizeId);
                                 sprintf((char *)toPrintBuffer, "%-5.1f %cBytes",
                                               toBitholdSize, toSizeId);
                                 MSGN_CALLBACK(pcontext, drMSG686,
                                               fromPrintBuffer, toPrintBuffer);
                                 pdbshm->bithold = bithreshold;
                                 returnCode = 0;
                             }
                             else
                             {
                                 /* Invalid value provided, request to change
                                    bi threshold rejected */
                                 MSGN_CALLBACK(pcontext, drMSG454);
                                 MSGN_CALLBACK(pcontext, drMSG451);
                                 returnCode = 3;
                             }
                         }
                     }
                     else if ((pdbshm->bithold) <= (ULONG)prl->rlsize) 
                     {
                         /* bi threshold reached */
                         /* bi threshold changed from value to value */
                         fromBitholdBytes =
                                    (DOUBLE)pdbshm->bithold * prl->rlbiblksize;
                         utConvertBytes(fromBitholdBytes,
                                        &fromBitholdSize, &fromSizeId);
                         sprintf((char *)fromPrintBuffer, "%-5.1f %cBytes",
                                                  fromBitholdSize, fromSizeId);
                         toBitholdBytes =
                                    (DOUBLE)bithreshold * prl->rlbiblksize;
                         utConvertBytes(toBitholdBytes,
                                        &toBitholdSize, &toSizeId);
                         sprintf((char *)toPrintBuffer, "%-5.1f %cBytes",
                                                toBitholdSize, toSizeId);
                         MSGN_CALLBACK(pcontext, drMSG686,
                                            fromPrintBuffer, toPrintBuffer);
                         
                         pdbshm->bithold = bithreshold;
                         pdbshm->quietpoint = QUIET_POINT_NORMAL;
                         returnCode = 0;
                     }
                     else
                     {
                         /* Invalid value provided, request to change
                            bi threshold rejected */
                         MSGN_CALLBACK(pcontext, drMSG454);
                         MSGN_CALLBACK(pcontext, drMSG451);
                         returnCode = 3;
                     }
                 }
                 else
                 {
                     /* Invalid value provided, request to change
                        bi threshold rejected */
                     MSGN_CALLBACK(pcontext, drMSG454);
                     MSGN_CALLBACK(pcontext, drMSG451);
                     returnCode = 3;
                 }
           }
        }
        else 
        /* The broker does not exist and shutdown may be in progress */
        {
            /* Broker is dead - abnormal shutdown of the database */
            MSGN_CALLBACK(pcontext, drMSG400);
            returnCode = 16;
        }

    return(returnCode);
}