home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / log / activateCheckpoint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.5 KB  |  160 lines

  1. /*
  2.  *   $RCSfile: activateCheckpoint.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:50 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "bf_macro.h"
  57. #include "volume.h"
  58. #include "openlog.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "threadstate.h"
  62. #include "log_extfuncs.h"
  63. #include "log_intfuncs.h"
  64. #include "thread_globals.h"
  65. #include "log_globals.h"
  66. #include "trans_globals.h"
  67.  
  68.  
  69. /*
  70.  *    activateCheckpoint() works with the thread started by
  71.  *  checkpointThread() to asynchronously perform a checkpoint.
  72.  */
  73.  
  74.  void
  75. activateCheckpoint (
  76.     BOOL    forceCheckpoint,    /* force the checkpoint to occur     */
  77.     BOOL    syncForce,            /* synchrounously flush dirty pages    */
  78.     BOOL    do_wait                /* wait for checkpoint to complete    */
  79. )
  80. {
  81.     int    logPageCount;    /* log pages since last flushed dirty page    */
  82.  
  83.     TRPRINT(TR_LOG, TR_LEVEL_1, ("potentially activate checkpoint"));
  84.  
  85.     /*
  86.      *    See if a checkpoint is allowed at this time
  87.      */
  88.     if (!CheckpointsEnabled) {
  89.         return;
  90.     }
  91.  
  92.     if (forceCheckpoint) {
  93.  
  94.         /* 
  95.          *    Wait for any active checkpoint to end
  96.          */
  97.         while (OpenLog.flags & LOG_CHECKPOINT_IN_PROGRESS) {
  98.               if (waitList( &(OpenLog.checkPointList), THREAD_CHECKPOINT_WAIT ))    {
  99.                 SM_ERROR(TYPE_CRASH, esmINTERNAL);
  100.             }
  101.         }
  102.  
  103.     } else {
  104.  
  105.         /*
  106.          *    calculate the number of log pages since the log record
  107.          *    for the oldest dirty page.
  108.          */
  109.         if (LastFlushedCheckpoint.wrapCount < OpenLog.wrapCount) {
  110.             /*
  111.              *    The log wraps, so count pages at both the end of the
  112.              *    log buffer and the beginning.
  113.              */
  114.             logPageCount = (int) (OpenLog.filePages - LSN_TO_LOG_PAGE(LastFlushedCheckpoint.offset, &OpenLog)) + (int) OpenLog.tailPid;
  115.         } else {
  116.             /*
  117.              *    The log does not wrap, so the wrapcounts must be equal
  118.              *    and we only need to do a simple subtraction
  119.              */
  120.             SM_ASSERT(LEVEL_3, LastFlushedCheckpoint.wrapCount == OpenLog.wrapCount);
  121.             logPageCount = (int) OpenLog.tailPid - (int)LSN_TO_LOG_PAGE(LastFlushedCheckpoint.offset, &OpenLog); 
  122.         }
  123.  
  124.         /*
  125.          *    If the number of log pages is beyond the checkpoint
  126.          *    frequency then take a checkpoint (assume one is not
  127.          *    already in progress), otherwise just return.
  128.          */
  129.         if (logPageCount <= OpenLog.checkPointInterval) {
  130.             return;
  131.         }
  132.         if (OpenLog.flags & LOG_CHECKPOINT_IN_PROGRESS) {
  133.             /* see if we should wait for the checkpoint to complete */
  134.             if (do_wait) {
  135.                 if (waitList( &(OpenLog.checkPointList), THREAD_CHECKPOINT_WAIT ))    {
  136.                     SM_ERROR(TYPE_CRASH, esmINTERNAL);
  137.                 }
  138.             }
  139.             return;
  140.         }
  141.     }
  142.  
  143.     CheckpointSyncForce = syncForce;
  144.  
  145.     SM_ASSERT(LEVEL_3, LIST_NOT_EMPTY(&CheckpointWaitList));
  146.  
  147.     /* wakup the checkpoint thread */
  148.     OpenLog.flags |= LOG_CHECKPOINT_IN_PROGRESS;
  149.     notify(&CheckpointWaitList, esmNOERROR, esmNOERROR);
  150.  
  151.     /* see if we should wait for the checkpoint to complete */
  152.     if (do_wait) {
  153.         if (waitList( &(OpenLog.checkPointList), THREAD_CHECKPOINT_WAIT ))    {
  154.             SM_ERROR(TYPE_CRASH, esmINTERNAL);
  155.         }
  156.     }
  157.  
  158.     return;
  159. }
  160.