/* PROGRAM: dbXAinit - Initialize the global xid free list * * * RETURNS: DSM_S_SUCCESS on success */ dsmStatus_t dbxaInit(dsmContext_t *pcontext) { dbcontext_t *pdbcontext = pcontext->pdbcontext; dbshm_t *pdbshm = pdbcontext->pdbpub; LONG maxxids,amount; int i; dbxaTransaction_t *pxids, *plastxid = NULL; if (!pdbshm->maxxids) return 0; amount = pdbshm->maxxids; for(pdbshm->maxxids = 0; pdbshm->maxxids < amount; pdbshm->maxxids += 64 ) { /* Allocate the xids in chunks of 64 */ pxids = (dbxaTransaction_t *) stGet(pcontext, XSTPOOL(pdbcontext, pdbshm->qdbpool), 64 * sizeof(dbxaTransaction_t)); if(!pxids) { MSGD_CALLBACK(pcontext, "%gInsuffient storage to allocate xid table."); } if(plastxid) { /* Make last of previous batch of 64 point to this batch */ plastxid->qnextXID = P_TO_QP(pcontext,pxids); } if(!pdbshm->qxidFree) { pdbshm->qxidFree = P_TO_QP(pcontext,pxids); } for(i = 0; i < 64;i++,pxids++) { QSELF(pxids) = P_TO_QP(pcontext,pxids); pxids->qnextXID = P_TO_QP(pcontext,pxids + 1); } plastxid = pxids--; plastxid->qnextXID = 0; } return 0; }
/* PROGRAM: dsmMandatoryFieldsCachePut - build mandatory field cache and it * is stored in shared memory * * RETURNS: DSM_S_SUCCES * */ dsmStatus_t dsmMandatoryFieldsPut(dsmContext_t *pcontext, struct meta_filectl *pInMetactl, /* new metadata ctl for cache */ struct meta_filectl *pOldmetactl, /* old metadata ctl for cache */ DL_VECT *pdl_vect_in, /* next dl column vector */ DL_VECT *pdl_col_in, /* next dl columns list to use */ int ndl_ent, /* # delayed columns */ int mandtblSize, /* size of mand fld table */ int useCache, /* use shm cache ? */ struct mand *pmand) /* storage for all mand flds */ { dbcontext_t *pdbcontext = pcontext->pdbcontext; dbshm_t *pdbshm = pdbcontext->pdbpub; dsmStatus_t returnCode; SHPTR *pmandhashtbl, qhashentry; struct meta_filectl *pmetactl = NULL; pdbcontext->inservice++; /* postpone signal handler processing */ SETJMP_ERROREXIT(pcontext, returnCode) /* Ensure error exit address set */ if ((returnCode = dsmThreadSafeEntry(pcontext)) != DSM_S_SUCCESS) { returnCode = dsmEntryProcessError(pcontext, returnCode, (TEXT *)"dsmMandatoryFieldsPut"); goto done; } /* get the schema cache latch */ MT_LOCK_SCC (); /* Check if the entry already exists */ dsmMandFindEntry(pcontext, &pmetactl, pInMetactl->fildbk, pInMetactl->filno, FILE_IDENT_DBKEY); if (pmetactl != NULL) { /* entry had already been made */ goto okdone; } /* get ptr to hash table array */ if (pdbshm->qmandctl) pmandhashtbl = (SHPTR *) QP_TO_P(pdbcontext, pdbshm->qmandctl); else /* need to allocate it */ { pmandhashtbl = (SHPTR *) stRent(pcontext, XSTPOOL(pdbcontext, pdbshm->qdbpool), SIZE_MAND_HASH * sizeof(SHPTR)); pdbshm->qmandctl = P_TO_QP(pcontext, pmandhashtbl); } /* allocate storage in shm */ pmetactl = (struct meta_filectl *)stRent(pcontext, XSTPOOL(pdbcontext, pdbshm->qdbpool), (unsigned)(sizeof(struct meta_filectl) + mandtblSize)); pmetactl->fildbk = pInMetactl->fildbk; pmetactl->filno = pInMetactl->filno; pmetactl->nmand = pInMetactl->nmand; pmetactl->schemavers = pInMetactl->schemavers; if ( (useCache != MANB_USECACHE_NONE) && (mandtblSize > 0) ) { bufcop(pmetactl->mand, pmand, (int) mandtblSize); } if ((useCache == MANB_USECACHE_PHYSICAL) && (pOldmetactl != NULL)) { pOldmetactl->filno = 0; pOldmetactl->fildbk = 0; } /* Chain this structure in shared memory. The assumption is that an entry for this fildbk does not already exist on the cache. */ qhashentry = pmandhashtbl[ABS(pmetactl->filno) % SIZE_MAND_HASH]; pmetactl->qnext = qhashentry; pmandhashtbl[ABS(pmetactl->filno) % SIZE_MAND_HASH] = P_TO_QP(pcontext, pmetactl); DEBUG_FPRINTF(pmetactl, "dbmanb (chained to sh mem):"); okdone: MT_UNLK_SCC (); returnCode = DSM_S_SUCCESS; done: dsmThreadSafeExit(pcontext); pdbcontext->inservice--; return returnCode; }