home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: activateCheckpoint.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 "bf_macro.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "threadstate.h"
- #include "log_extfuncs.h"
- #include "log_intfuncs.h"
- #include "thread_globals.h"
- #include "log_globals.h"
- #include "trans_globals.h"
-
-
- /*
- * activateCheckpoint() works with the thread started by
- * checkpointThread() to asynchronously perform a checkpoint.
- */
-
- void
- activateCheckpoint (
- BOOL forceCheckpoint, /* force the checkpoint to occur */
- BOOL syncForce, /* synchrounously flush dirty pages */
- BOOL do_wait /* wait for checkpoint to complete */
- )
- {
- int logPageCount; /* log pages since last flushed dirty page */
-
- TRPRINT(TR_LOG, TR_LEVEL_1, ("potentially activate checkpoint"));
-
- /*
- * See if a checkpoint is allowed at this time
- */
- if (!CheckpointsEnabled) {
- return;
- }
-
- if (forceCheckpoint) {
-
- /*
- * Wait for any active checkpoint to end
- */
- while (OpenLog.flags & LOG_CHECKPOINT_IN_PROGRESS) {
- if (waitList( &(OpenLog.checkPointList), THREAD_CHECKPOINT_WAIT )) {
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
- }
-
- } else {
-
- /*
- * calculate the number of log pages since the log record
- * for the oldest dirty page.
- */
- if (LastFlushedCheckpoint.wrapCount < OpenLog.wrapCount) {
- /*
- * The log wraps, so count pages at both the end of the
- * log buffer and the beginning.
- */
- logPageCount = (int) (OpenLog.filePages - LSN_TO_LOG_PAGE(LastFlushedCheckpoint.offset, &OpenLog)) + (int) OpenLog.tailPid;
- } else {
- /*
- * The log does not wrap, so the wrapcounts must be equal
- * and we only need to do a simple subtraction
- */
- SM_ASSERT(LEVEL_3, LastFlushedCheckpoint.wrapCount == OpenLog.wrapCount);
- logPageCount = (int) OpenLog.tailPid - (int)LSN_TO_LOG_PAGE(LastFlushedCheckpoint.offset, &OpenLog);
- }
-
- /*
- * If the number of log pages is beyond the checkpoint
- * frequency then take a checkpoint (assume one is not
- * already in progress), otherwise just return.
- */
- if (logPageCount <= OpenLog.checkPointInterval) {
- return;
- }
- if (OpenLog.flags & LOG_CHECKPOINT_IN_PROGRESS) {
- /* see if we should wait for the checkpoint to complete */
- if (do_wait) {
- if (waitList( &(OpenLog.checkPointList), THREAD_CHECKPOINT_WAIT )) {
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
- }
- return;
- }
- }
-
- CheckpointSyncForce = syncForce;
-
- SM_ASSERT(LEVEL_3, LIST_NOT_EMPTY(&CheckpointWaitList));
-
- /* wakup the checkpoint thread */
- OpenLog.flags |= LOG_CHECKPOINT_IN_PROGRESS;
- notify(&CheckpointWaitList, esmNOERROR, esmNOERROR);
-
- /* see if we should wait for the checkpoint to complete */
- if (do_wait) {
- if (waitList( &(OpenLog.checkPointList), THREAD_CHECKPOINT_WAIT )) {
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
- }
-
- return;
- }
-