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 / setLogStartLocation.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.2 KB  |  156 lines

  1. /*
  2.  *   $RCSfile: setLogStartLocation.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. #include "sysdefs.h"
  38. #include "ess.h"
  39. #include "checking.h"
  40. #include "trace.h"
  41. #include "error.h"
  42. #include "list.h"
  43. #include "pool.h"
  44. #include "tid.h"
  45. #include "io.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "latch.h"
  52. #include "link.h"
  53. #include "lsn.h"
  54. #include "bf.h"
  55. #include "volume.h"
  56. #include "openlog.h"
  57. #include "trans.h"
  58. #include "logrecs.h"
  59. #include "logaction.h"
  60. #include "threadstate.h"
  61. #include "util_funcs.h"
  62. #include "bf_extfuncs.h"
  63. #include "log_intfuncs.h"
  64. #include "log_extfuncs.h"
  65. #include "thread_funcs.h"
  66. #include "thread_globals.h"
  67. #include "log_globals.h"
  68. #include "trans_globals.h"
  69. #include "distr.h"
  70. #include "distr_globals.h"
  71.  
  72.  
  73. /*
  74.  *    FUNCTION DESCRIPTION:
  75.  *
  76.  *    This function moves the current end of the log to the next page.
  77.  *    It takes a checkpoint, whose log record is written to the new page.
  78.  *  The log's wrap count is adjusted so that it is >= the parameter wrapCount.
  79.  *
  80.  *    WARNING: this function should only be called on storage manager
  81.  *             startup.  There cannot be any logging activity.
  82.  */
  83.  
  84.  int
  85. setLogStartLocation (
  86.     int                wrapCount
  87. )
  88. {
  89.     SHORTPID            startpid;
  90.     register OPENLOG    *openLog;
  91.     int                    dirtyPages;
  92. #ifdef DEBUG
  93.      LSN                debugLSN;
  94. #endif
  95.     TRPRINT(TR_LOG, TR_LEVEL_1, ("start wrap count:%d", wrapCount));
  96.  
  97.     openLog = &OpenLog;
  98.  
  99.     /*
  100.      *    make sure there are no dirty pages
  101.      */
  102.     dirtyPages = checkPointDirtyPages();
  103.     SM_ASSERT(LEVEL_3, dirtyPages == 0);
  104.  
  105.     /*
  106.      *    check whether there are any prepared transactions
  107.      */
  108.     if ((numActiveServerDistrTrans + numActiveCoordDistrTrans) > 0) {
  109.         /*
  110.          *    we cannot boost the wrapCount because we have 
  111.          *    active transactions left over
  112.          *    print user message
  113.          */
  114.         fprintf(sm_ErrorStream, 
  115.             "WARNING: Active transactions left over; cannot boost wrap count.\n");
  116.  
  117.         wrapCount = openLog->wrapCount;
  118.  
  119.     } else {
  120.  
  121.         /* wrapcount must be larger than the current one */
  122.         if (wrapCount <= openLog->wrapCount) {
  123.             wrapCount = openLog->wrapCount+1;
  124.         }
  125.     }
  126.  
  127.     /* use the tailLSN left over from recovery */
  128.     startpid = ((LSN_TO_LOG_PAGE(openLog->tailLSN, openLog) + 1)
  129.                                                 % openLog->filePages);
  130.     if(startpid == 0) {
  131.         /* we wrapped */
  132.         wrapCount++;
  133.     }
  134.     openLog->tailLSN = LOG_PAGE_TO_LSN(startpid, openLog);
  135.     openLog->tailPid = startpid;
  136.     openLog->wrapCount = wrapCount;
  137.  
  138.     LastFlushedCheckpoint.wrapCount = openLog->wrapCount;
  139.     LastFlushedCheckpoint.offset = openLog->tailLSN;
  140.     OldestDirtyPageLSN = LastFlushedCheckpoint;
  141.  
  142. #ifdef DEBUG
  143.     /* make sure we don't overwrite important log records */
  144.     debugLSN.offset = openLog->tailLSN;
  145.     debugLSN.wrapCount = openLog->wrapCount;
  146.     debugLSN.wrapCount--;
  147.     if(compareLSN(&debugLSN, &OldestDirtyPageLSN) >= 0) {
  148.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  149.     }
  150. #endif
  151.  
  152.     activateCheckpoint(TRUE, FALSE, TRUE);
  153.  
  154.     return(esmNOERROR);
  155. }
  156.