home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: convertClientLogPage.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:50 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "util_funcs.h"
- #include "log_extfuncs.h"
- #include "log_globals.h"
-
- /*
- * This function converts all the lsn's on in all the log records on
- * the client log page. Also, the wrapcounts in the log page
- * headers are updated. This functions enforces the assumption
- * the the log records all pertain to the same transaction.
- */
-
- int
- convertClientLogPage (
- GROUPLINK *tailLink, /* client log page, new log tail*/
- SHORTPID newTailPage,/* page # for tail of log */
- TRANSREC *transRec, /* transaction for all records */
- LSN *firstLSN, /* lsn of first log record */
- LSN *lastLSN, /* lsn of last log record */
- LSNOFFSET *newTailLSN,/* lsn of new log tail */
- int *count /* number of log records */
- )
- {
-
- LSNOFFSET tailLSN;
- OPENLOG *openLog;
- LOGPAGEHDR *pageHeader;
- LOGPAGEHDR *endHeader;
- int wrapCount;
- LOGRECORDHDR *current;
- int offset;
- LSNOFFSET previousLSN;
- int logCount;
- #ifdef DEBUG
- LSN debugLSN;
- #endif
-
-
- TRPRINT(TR_LOG, TR_LEVEL_1, ("new tailPid:%d", newTailPage));
-
- /*
- * Get the log information
- */
- openLog = &OpenLog;
- tailLSN = LOG_PAGE_TO_LSN(newTailPage, openLog);
-
- /*
- * Determine what the wrap count will be assuming the page
- * is converted without error. The wrap count does not
- * need to be incremented if the newTailPage is the current tail
- * page of the log.
- */
- if (newTailPage == 0 && newTailPage != openLog->tailPid) {
- openLog->wrapCount++;
- }
- wrapCount = openLog->wrapCount;
-
- #ifdef DEBUG
- /* make sure we don't overwrite important log records */
- debugLSN.offset = tailLSN;
- debugLSN.wrapCount = openLog->wrapCount;
- debugLSN.wrapCount--;
- if(compareLSN(&debugLSN, &OldestDirtyPageLSN) >= 0) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- #endif
- /*
- * Find the headers on the log page and
- * make sure client log page is valid
- */
- pageHeader = (LOGPAGEHDR*) tailLink->bufFrame;
- endHeader = (LOGPAGEHDR *)(((char *) pageHeader) + openLog->lastUsableByte);
- if (CHECK_LOGPAGE_MAGIC(pageHeader) ||
- CHECK_LOGPAGE_MAGIC(endHeader) ) {
-
- SM_ERROR(TYPE_USER, esmBADLOGPAGEHEADER);
- return(esmFAILURE);
- }
- pageHeader->pageNumber = newTailPage;
- endHeader->pageNumber = newTailPage;
-
- /*
- * Convert the LSN and prevLSN fields on all the log records
- * on the page to be valid in the current log. It is assumed
- * that the page begins with a log record header and
- * contains no partial log record at the end.
- *
- * It is also assumed that the LSN's on the page are relative
- * to the beginning of the page.
- */
- offset = FIRST_LSN; /* offset of first record */
- current = (LOGRECORDHDR*) (tailLink->bufFrame + offset);
- tailLSN += offset;
- firstLSN->offset = tailLSN;
- firstLSN->wrapCount = wrapCount;
- previousLSN = transRec->lastLSN;
- *count = 0;
- logCount = 0;
- while (TRUE) {
-
- if (CHECK_LOGRECORD_MAGIC(current)) {
-
- /*
- * if the magic is zero, the we are at the end of
- * the page. If not then there is an error.
- */
- if (current->magic == 0) {
-
- /*
- * done converting
- */
- break;
-
- } else {
- SM_ERROR(TYPE_USER, esmBADLOGRECORDHEADER);
- return(esmFAILURE);
- }
-
- }
-
- /*
- * Valid record, so update the count
- */
- logCount++;
-
- /*
- * For now make sure all the records correspond to the
- * same transaction and are the correct type.
- *
- * If compensation log records are allowed then the n
- * nextUndoLSN field for the record and for the transaction
- * will have to be updated.
- */
- SM_ASSERT(LEVEL_3, transRec->tid == current->tid);
- SM_ASSERT(LEVEL_3, current->type == LOG_REC_TYPE_USER);
-
- /*
- * Convert the LSN field
- */
- SM_ASSERT(LEVEL_3, offset == current->recordLSN.offset);
- current->recordLSN.offset = tailLSN;
- current->recordLSN.wrapCount = wrapCount;
-
- /*
- * Convert the previous LSN field, check to see if
- * this is the first log record on the page
- */
- if (offset == FIRST_LSN) {
-
- /*
- * This is the first log record, so the prev LSN
- * should have been set to zero by the client.
- */
- SM_ASSERT(LEVEL_3, current->previousLSN == 0);
-
- } else {
-
- /*
- * The previous LSN is the lsn of the previous record
- * in the page.
- */
- SM_ASSERT(LEVEL_3, current->previousLSN ==
- LOG_PAGE_OFFSET(previousLSN, openLog));
- }
- current->previousLSN = previousLSN;
-
- /*
- * Remember the current lsn
- */
- previousLSN = current->recordLSN.offset;
-
- /*
- * Advance to the next log record
- */
- offset += current->length;
- tailLSN += current->length;
- current = (LOGRECORDHDR*) (tailLink->bufFrame + offset);
-
- /*
- * If a log record header can't fit on the rest of the page,
- * then we are at the end-of-page. Otherwise, it is possible
- * that there is another log record.
- */
- if ((openLog->lastUsableByte - offset) < sizeof(LOGRECORDHDR)) {
-
- TRPRINT(TR_LOG, TR_LEVEL_2, ("header will not fit"));
-
- /*
- * At end-of-page, so exit the loop
- */
- break;
- }
-
- }
-
- /*
- * Make sure the log page header is correct
- */
- if (pageHeader->lastRecord != endHeader->lastRecord) {
- SM_ERROR(TYPE_USER, esmBADLOGPAGEHEADER);
- return(esmFAILURE);
- }
- if (endHeader->lastRecord != LOG_PAGE_OFFSET(previousLSN, openLog)) {
- SM_ERROR(TYPE_USER, esmBADLOGPAGEHEADER);
- return(esmFAILURE);
- }
-
- /*
- * remember the last lsn for this transaction and the number
- * of log records.
- * make sure that the new previous lsn is greater that the old
- * previous lsn. Also, return the new tail lsn
- */
- SM_ASSERT(LEVEL_3, logCount > 0);
- lastLSN->offset = previousLSN;
- lastLSN->wrapCount = wrapCount;
- *count = logCount;
- *newTailLSN = tailLSN;
-
- /*
- * Make sure the last log record didn't accidentally overlap
- */
- if (LOG_PAGE_OFFSET((*newTailLSN), openLog) > openLog->lastUsableByte) {
-
- /*
- * Bad log record
- */
- SM_ERROR(TYPE_USER, esmBADLOGRECORDHEADER);
- return(esmFAILURE);
- }
-
- /*
- * Update the wrapcounts in the page headers
- */
- pageHeader->wrapCount = wrapCount;
- endHeader->wrapCount = wrapCount;
-
- /*
- * return success
- */
- return(esmNOERROR);
- }
-