home *** CD-ROM | disk | FTP | other *** search
-
- #ifdef CHECKPOINT
-
- /*
- * @(#)cPLog.c 1.4 2/23/90
- */
-
- /*
- cPLog.c - Emerald checkPoint log file manager
-
- Copyright 1987, 1988 Clinton Jeffery
- Last edit: 4/28/88
-
- See ../h/cPLog.h for an account of what is going on here.
- */
-
- #include <stdio.h>
- #include <ndbm.h>
- #include "Kernel/h/stdTypes.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/kmdTypes.h"
- #include "Kernel/h/mmMsgDefs.h"
- #include "Kernel/h/cPLog.h"
- #include "Kernel/h/cPDBM.h"
- #include "Kernel/h/replicant.h"
-
- extern ODP OTLookup();
-
- /* Log file private variables */
- #define CPFILENAME "CheckPoint"
- #define CPNEWLOGEXTENSION ".cppnewlog"
-
- extern char NODEDIR[];
- extern void OTInsert();
- extern HResult RecoverItemHandler();
-
- static char LFName[200];
-
- #ifdef CPNEWLOG
- static char newLFName[200];
- #endif
-
-
- /* logFILE descriptors */
- FILE *LF;
-
- #ifdef CPNEWLOG
- FILE *newLF;
- #endif
-
- long CP_StartEntry(obj,f)
- OID obj;
- FILE *f;
- {
- long retval;
- char *strcpy();
-
- retval = ftell(f);
- CP_replicant->rep_Signature = REPSIGNATURE;
- CP_replicant->nextOID = obj;
- return retval;
- }
-
- /*
- init_Recover opens the log file specified for reading/writing.
- -DCPNEWLOG causes it to also open strcat(name,".cpnewlog") for writing.
- end_Recover seeks to the end of the log file; -DCPNEWLOG causes it
- to instead close both files, delete the old log file, and rename and
- reopen the new log file to the old name.
- */
-
- CP_InitRecover()
- {
- (void) sprintf(LFName, "%s/%s", NODEDIR, CPFILENAME);
-
- #ifdef CPNEWLOG /* open the new log file ("name.cppnewlog") for writing */
- (void) sprintf(newLFName,"%s%s",LFName,".cppnewlog");
-
- if((newLF = fopen(newLFName,"a+"))==NULL){
- FAIL("CP_InitRecover can't open newlogfile\n");
- }
- #endif
-
- /* open the old log file ("name") for reading/writing */
- if((LF = fopen(LFName,"a+"))==NULL) {
- FAIL("CP_InitRecover cannot open logfile\n");
- }
- SUCCEED;
- }
-
- CP_EndRecover()
- {
- #ifdef CPNEWLOG
- char command[256];
-
- CP_SwitchDbase();
- fclose(LF);
- fclose(newLF);
- (void) sprintf((char *)command,"mv %s %s",newLFName, LFName);
- system((char *)command);
- if((LF = fopen(LFName,"a+"))==NULL) {
- FAIL("CP_EndRecover cannot open new logfile\n");
- }
- #endif
- if(fseek(LF,0L,2)) {
- FAIL("CP_EndRecover cannot seek to end of logfile\n");
- }
- SUCCEED;
- }
-
- /*
- CP_Recover builds up an object and places it into the object table,
- including the recursive loading of local and attached objects that
- checkpointed with it.
- */
- CP_Recover(newOTE)
- GODP newOTE;
- {
- replicantPtr rp;
-
- #ifdef CPNEWLOG
- long offset;
- #endif
-
- KMDTrace("Recover", 4, "In CP_Recover with ote (0x%08x)\n", newOTE);
- if((rp=replicant_diskread(newOTE))==((replicantPtr)(-1))){
- FAIL("CP_Recover diskread fails\n");
- }
-
- #ifdef CPNEWLOG
- if((offset = replicant_diskwrite(rp,newLF))<0) {
- FAIL("CP_Recover diskwrite fails\n");
- }
- KMDTrace("Recover", 4, "CP_Recover writes copy to new file\n", newOTE);
- #endif
-
- /* reconstruct object's data area, load code,
- and execute recovery process all from within here. */
- RecoverItemHandler(rp,(ODP)newOTE);
-
- #ifdef CPNEWLOG
- /* update the dbase */
- if(CP_WriteDbase((ODP)newOTE,offset,newOTE->cPSize,newCP_DBM)<0)
- FAIL("CP_Recover write to update DBase fails\n");
- #endif
-
- if(newOTE->ownOID == 0) FAIL("CP_Recover sees NULL OID\n");
- SUCCEED;
- }
- #endif CHECKPOINT
-