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

  1. /*
  2.  *   $RCSfile: updateEndOfLog.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 "volume.h"
  57. #include "openlog.h"
  58. #include "trans.h"
  59. #include "logrecs.h"
  60. #include "threadstate.h"
  61. #include "util_funcs.h"
  62. #include "log_extfuncs.h"
  63. #include "log_intfuncs.h"
  64. #include "thread_funcs.h"
  65. #include "thread_globals.h"
  66. #include "log_globals.h"
  67.  
  68. /*
  69.  *  Atomically make the new client log page the end of the
  70.  *  log.  The end of the log points to empty space on the
  71.  *  end of the client log page.  The log latch and semaphore are
  72.  *  also released.
  73.  */
  74.  
  75.  FORCEMARK
  76. updateEndOfLog (
  77.  
  78.     TRANSREC            *transRec,    
  79.     GROUPLINK            *tailLink,
  80.     SHORTPID            tailPid,
  81.     LSNOFFSET            tailLSN,
  82.     LSN                    *firstLSN,    /* first log record in page        */    
  83.     LSN                    *lastLSN,    /* last log record in page        */    
  84.     int                    logCount     /* number of log records in page*/
  85. )
  86. {
  87.  
  88.     register OPENLOG    *openLog;
  89.     FORCEMARK            forceMark;
  90.  
  91.     TRPRINT(TR_LOG, TR_LEVEL_1, ("last lsn:%d", lastLSN->offset));
  92.  
  93.     /*
  94.      *    get a register pointer to the openlog structure
  95.      */
  96.     openLog = &OpenLog;
  97.  
  98.     /*
  99.      *    check the open log magic number
  100.      */
  101.     CHECK_OPENLOG_MAGIC(openLog);
  102.  
  103.     /*
  104.      *    check the transaction magic number
  105.      */
  106.     CHECK_TRANSREC_MAGIC(transRec);
  107.  
  108.     /*
  109.      *    check to see if this is the first record for this transaction
  110.      */
  111.     if (transRec->logRecordCount == 0)    {
  112.  
  113.         /*
  114.          *    record this as the first log record
  115.          */
  116.         transRec->firstLogPid = LSN_TO_LOG_PAGE(firstLSN->offset, openLog);
  117.         transRec->logUnique   = openLog->logRecordCount + 1;
  118.         if (transRec->firstLSN.offset == NULL_LSN) transRec->firstLSN = *firstLSN;
  119.         TRPRINT(TR_LOG, TR_LEVEL_2, ("first log record for tid:%d", firstLSN->offset));
  120.  
  121.         /* 
  122.          *    check to see if the log queue is empty
  123.          */
  124.         if (LIST_EMPTY( &(openLog->activeList) ))    {
  125.  
  126.             /*
  127.              *    this is the new last page
  128.              */
  129.             openLog->activePid    = transRec->firstLogPid;
  130.             openLog->activeUnique = transRec->logUnique;
  131.             openLog->activeLSN    = firstLSN->offset;
  132.             TRPRINT(TR_LOG, TR_LEVEL_2, ("new first active log rec:%d", openLog->activeLSN));
  133.         }
  134.  
  135.         /*
  136.          *    hang the transaction record off the log ordering list
  137.          */
  138.         listEnq( &(openLog->activeList), &(transRec->logActiveList) );
  139.     }
  140.  
  141.     /*
  142.      *    increment the counter for this transaction
  143.      */
  144.     openLog->logRecordCount += logCount;
  145.     forceMark = openLog->logRecordCount;
  146.     TRPRINT(TR_LOG, TR_LEVEL_2, ("forceMark:%d", forceMark));
  147.  
  148.     /*
  149.      *    adjust log tail information
  150.      */
  151.     openLog->tailPid    = tailPid;
  152.     openLog->tailLSN    = tailLSN;
  153.     openLog->tailLink    = tailLink;
  154.     openLog->tailBuffer = tailLink->pageHash;
  155.  
  156.     /* Record the next LSN to be generated */
  157.     openLog->nextValidLSN.wrapCount = openLog->wrapCount;
  158.     openLog->nextValidLSN.offset = 
  159.             FIRST_LSN_ON_PAGE(openLog->tailLSN, openLog);
  160.  
  161.     /*
  162.      *    record this record as the last record
  163.      *    for backwards undo processing.  The nextUndoLSN is equal to
  164.      *    the lastLSN since the record is not a compensation log record
  165.      */
  166.     transRec->lastLSN      = lastLSN->offset;
  167.     transRec->nextUndoLSN = lastLSN->offset;
  168.  
  169.     /*
  170.      *    give the log latch back
  171.      */
  172.     signalLatch( &(openLog->logLatch) );
  173.     signalSemaphore( &(openLog->writeSemaphore) );
  174.  
  175.     /*
  176.      *    increment the checkpoint count
  177.      */
  178.     openLog->checkPointCount += logCount;
  179.  
  180.     /* increment the number of records written by the transaction */
  181.     transRec->logRecordCount += logCount;
  182.  
  183.     /* 
  184.      *    record the log space used by this trans 
  185.      *    We assume it was the entire page since there may be 
  186.      *    fragmentation during undo as well
  187.      */
  188.     ActiveLogSpace += openLog->pageSize;
  189.     transRec->logSpace += openLog->pageSize;
  190.  
  191.     /*
  192.      *    return the log count
  193.      */
  194.     return(forceMark);
  195. }
  196.