JRNSTART ;Start Journaling ; LFT686 03/01/99 ; Compiled March 6, 2000 19:36:08 ; +--------------------------------------------------------+ ; | Copyright 1986-2000 by InterSystems Corporation, | ; | Cambridge, Massachusetts, U.S.A. | ; | All rights reserved. | ; | | ; | Confidential, unpublished property of InterSystems. | ; | | ; | This media contains an authorized copy or copies | ; | of material copyrighted by InterSystems and is the | ; | confidential, unpublished property of InterSystems. | ; | This copyright notice and any other copyright notices | ; | included in machine readable copies must be reproduced | ; | on all authorized copies. | ; +--------------------------------------------------------+ ;%system.INC ; DAS280 06/29/99 ;%ST.INC DAS309 11/08/99 ; %system.inc: compiled for NETWIDENAMESPACE ; %system.inc: compiled for DDPGROUPS ; %system.inc: compiled for NETMOREDCPDMN ; %system.inc: compiled for USECLUSTER ; %system.inc: compiled for RTNINGBL ; %system.inc: compiled for DBMSNSP ; this is chui JRNSTART (also for STUCNFG) MAIN N curfile,filename,jrnall,jrnflag,jrninfo,shortnam,attempt N prefix,maxsize,expqty,started,altdir,curdir,deldir D init I curfile'="" W !,"Already journaling to "_curfile Q I $G(STU)="S" D Q:'started . I +$G(maxsize)>0 d MSG^%UTIL("Max Journal Size: "_maxsize,1,0) . I +$G(defexp)>0 d MSG^%UTIL("Expand by: "_expqty,1,0) . ;^%SYS("JOURNAL","CURRENT") carries jrnall value in config.def . S jrnall=$P($G(^%SYS("JOURNAL","CURRENT")),"^")\2#2 . I $G(QUIETLY) S started=1 ;as in Startup^STUCNFG1 . E S started=($$YN("Start Journaling","Y",60)="Y") W ! E D ask n err s started=$$INT(.curdir,altdir,shortnam,prefix,maxsize,expqty,jrnall,.err,0) d MSG^%UTIL("Journaling "_$S(jrnall:"all ",1:"selected ")_$S(started:"globals to "_curdir_prefix_shortnam,1:"NOT ")_" started.",$g(QUIETLY),0) d:$g(err)'="" MSG^%UTIL("ERROR: "_err,$g(QUIETLY),0) ;there may still be an error even if started Q ;This is the backend JRNSTART called by both chui and gui ;input: ; expqty: not used (for now) ;input/output: ; curdir - ;output: ; err - error message ; [return] - journal has started (0/1) INT(curdir,altdir,shortnam,prefix,maxsize,expqty,jrnall,err,io) s $zt="etINT" n fullname,stat,started,attempt,jrnflag,jrninfo,msg,glo s started=0,attempt=0 i $d(io),$e(io)="^" s glo=io k io ;ideally I should try a SET on glo i $g(altdir)="" s altdir=curdir d FIXDIR(.curdir),FIXDIR(.altdir) ;append delimiters if necessary i '$$VALIDIR(curdir)!'$$VALIDIR(altdir) s err=$$dirinvalidmsg(curdir,altdir) q 0 i shortnam="" s err="null journal file name" q 0 s fullname=curdir_prefix_shortnam ; make sure a (journal?) file with that name does not exist f s stat=$ZU(78,22,fullname) q:stat<1 d . s shortnam=$$getname(shortnam),fullname=curdir_prefix_shortnam i stat=-1 s err="exist non-journal file "_fullname q 0 s jrnall=''jrnall,jrnflag=$ZU(40,2,7),jrninfo=$V(jrnflag,-2) ;jrnall must be 0 or 1 i jrnall'=(jrninfo\2#2) s jrninfo=jrninfo-(jrninfo\2#2*2)+(jrnall*2) v jrnflag:-2:1:jrninfo ;set/clear Journal All bit retry ; s $zt="etINT1" L +^%SYS("JOURNAL"):1 e s err="locked" q 0 i +$zu(78,22) s err="Already journaling to "_$zu(78,3) L -^%SYS("JOURNAL") q 0 ; a sanity check to make sure last journal history record is complete i +$g(^%SYS("JOURNAL"))#2 d ;journal started, but record incomplete . d log(),loginfo("Last journal history log is completed with "_$name(^%SYS("TMPJRN"))) d prelog s (^%SYS("JOURNAL"),started)=$zu(78,0,prefix_shortnam,curdir,maxsize,0,expqty,altdir) i $d(^%SYS("JOURNAL","TESTSYS",1)) h +$g(^%SYS("JOURNAL","TESTSYS",1)) ;test interrupt i started d log(fullname) L -^%SYS("JOURNAL") s $zt="etINT" i 'started,attempt=0 d g retry . d loginfo("Journal Start Failed - Trying Secondary Path") . S attempt=1,curdir=altdir,fullname=curdir_prefix_shortnam q started etINT1 ; s $zt="" L -^%SYS("JOURNAL") ;fall through to etINT etINT s $zt="" s err=$ze q started ;input: fullname,curdir,altdir,prefix,shortnam,jrnall,expqty (as in retry) prelog ; s prelog=$name(^%SYS("TMPJRN")) k @prelog d HISTORY^JRNUTIL("START",fullname,curdir,altdir,prefix,shortnam,$name(@prelog@("HISTORY"))) d PURGE^JRNPRG ;KLMxxx i $d(@prelog@("a")) ;to get naked indicator right S ^("CURRENT")=(jrnall*2+1)_"^"_fullname S ^("LAST")=^("CURRENT") S ^("CURDIR")=curdir S ^("ALTDIR")=altdir S ^("MAXSIZE")=maxsize S ^("EXPSIZE")=expqty S ^("PREFIX")=prefix q log(fullname) ; d:$d(fullname) History^JRNUTIL("START",fullname) s jrnstat=$$CURRENT^%NOJRN() i 'jrnstat d ENABLE^%NOJRN i '$$CURRENT^%NOJRN(),$zu(9,"","fail to journal journal history updates") ts ;^%SYS("JOURNAL") value is not affected because $$$TMPJRNGLO is not defined m ^%SYS("JOURNAL")=^%SYS("TMPJRN") tc i 'jrnstat d DISABLE^%NOJRN s ^%SYS("JOURNAL")=0 ;log complete q ask N X,dn,ndays,from,ch D ASKSET("Current journal directory:",.curdir) D ASKSET("Alternate journal directory:",.altdir) f d ASKSET("Journal File Prefix:",.prefix) q:prefix?.AN!(prefix=".") s prefix="" w !,"Enter an alphanumeric string or . to reset prefix to null" S:prefix="." prefix="" ;HYY062: "." is not allowed in file name getsiz S X=maxsize\1048576 D ASKSET("Max journal file size in MB:",.X) W !,"Max journal file size is set to ",$S(X'<1:X\1,1:1),! ;HYY091 S maxsize=(+X*1048576)\1 S X=$S(jrnall:"Y",'jrnall:"N") S jrnall=($$YN("Journal ALL globals",X,60)="Y") Q init ;initialize, set defaults etc. N lastfile S curfile=$$curfile() S lastfile=$p($G(^%SYS("JOURNAL","LAST")),"^",2) S jrnall=$P($G(^%SYS("JOURNAL","LAST")),"^")\2#2 S expqty=+$G(^%SYS("JOURNAL","EXPSIZE")) S maxsize=$G(^%SYS("JOURNAL","MAXSIZE"),100*1048576) i ($zv["VMS") d . S altdir=$G(^%SYS("JOURNAL","ALTDIR"),$ZU(12,"[.journal]")) . S curdir=$G(^%SYS("JOURNAL","CURDIR"),$ZU(12,"[.journal]")) i '($zv["VMS") d . S altdir=$G(^%SYS("JOURNAL","ALTDIR"),$ZU(12,"journal")) . S curdir=$G(^%SYS("JOURNAL","CURDIR"),$ZU(12,"journal")) S prefix=$G(^%SYS("JOURNAL","PREFIX")) S shortnam=$S($F(lastfile,";"):$E(lastfile,$F(lastfile,";")-12-1,$f(lastfile,";")-2),1:$E(lastfile,$L(lastfile)-11,$L(lastfile))) nextname ;this should take care of the version transition once and for all S:shortnam'?8N1"."3N shortnam="00000000.000" ;which getname accepts S shortnam=$$getname(shortnam) Q getname(curfile) ;generates journal file names of the following format: YYYYMMDD.NNN ;where YYYY stands for year, MM for month, DD for day and NNN for a session ;number (ranging from 000 to 999). CURFILE is the current journal file name. n (curfile) s date=$zd($h,8),olddate=$e(curfile,1,8),sess=$e(curfile,10,12) q:olddate'=date date_".001" ;including the case curfile="" q:sess="999" "" q date_"."_$e(sess+1001,2,4) ;this function is called from JRNROLL altjfile(exist) ; exist=1 means we want to check if file exists n ok,jname,result s exist=+$g(exist) getjfnm w !?4,"Enter the journal file name ->" r jname:60 i $g(jname)="" q "" i '$$refok^SYSMGR(jname,"file") w !?4,"This file name is invalid" g getjfnm s result=$zu(12,jname) i exist d g getjfnm:'ok . o result:"r":0 . s ok=$t . i ok c result q . w !?4,"File ",result," does not exist" i ($$YN("Please confirm: the file chosen is "_result,"Y",60)'="Y") g getjfnm q result ; from altjfile YN(P,D,t) N R,X S P=$G(P),D=$E($G(D)_"?"),t=$G(t) ;ask Yes/No w/ Prompt,Default S D=$S("Yy"[D:"Yes => ","Nn"[D:"No => ",1:"") ;Yes, No or no default F W !,P_"? "_D Read:t R:t Read:'t R DO I "^YN"[R Q ;timed or non-timed read . S X=R,R=$TR($E(R_D_"?"),"yn","YN") I "^YN"'[R W " enter Yes or No, please" S POP=(R="^") W $E($S(R="N":"No",R="Y":"Yes",1:""),$L(X)+1,3) Q R UC(x) q $zcvt(x,"u") ; BITWISE.INC, DPB139 07/09/93 FIXDIR(dir) ;procedure, dir is passed by reference Q:dir="" i ($zv["VMS") d . n x . s x=$$ChkDirVALID(dir) . i x'="" s dir=x i '($zv["VMS") Q:$A(dir,$L(dir))=$A($s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:"")) i '($zv["VMS") s dir=dir_$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:"") Q fixdir(dir) ;function Q:dir="" "" i ($zv["VMS") d q dir . n x . s x=$$ChkDirVALID(dir) . i x'="" s dir=x Q:$A(dir,$L(dir))=$A($s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:"")) dir Q dir_$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:"") basename(f) ;similar to basename on UNIX Q $P(f,$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:""),1,$L(f,$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:""))-1)_$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:"") appdir(d1,d2) ;use $zu(12,d2) to append d2 to canonic dir i ($zv["VMS") S $E(d1,$L(d1))="."_d2_"]" i '($zv["VMS") S d1=d1_d2 Q d1 VALIDIR(dir) ;validate directory dir and create it if dir doesn't exist new flag s flag=1 g vdir2 validir(dir,flag) ;validate directory dir and optionally create it if it vdir2 ; VALIDIR(dir) comes here with flag set to 1 quit:$$ChkDirOrSpecEXISTS(dir)'="" 1 ; dir is valid and exists quit:$$ChkDirVALID(dir)="" 0 ; dir is not valid i flag'=1 q 0 ; flag says don't create, return failure new x set x=$$mkdir(dir) ; returns 0 for success, 1 for failure q:x=1 0 ; failed to create quit:$$ChkDirOrSpecEXISTS(dir)="" 0 ; it doesn't we failed q 1 ; success mkdir(dir) ;create a new directory i '($zv["VMS") Q $ZF(-1,"mkdir "_$S($E(dir)=""""!($F(dir," ")=0):dir,1:""""_dir_"""")) q:$$ChkDirVALID(dir)="" 1 ; dir is invalid, return failure n res s res=$ZF(-1,"create/directory "_dir) q '+($ZBOOLEAN(+(res),+(1),1)) jrnshort(jf,short) ;get/set short form of a journal file name N (jf,short) S len=$L($P(jf,";")) Q:$G(short)="" $E(jf,len-11,len) ;"GET" form S $E(jf,len-11,len)=short ;"SET" form Q jf GJrnPrefix(jf) ;extract prefix from the journal file name jf N (jf) S fname=$P(jf,$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:""),$L(jf,$s(($zv["UNIX"):"/",($zv["VMS"):"]",($zv["Windows"):"\",1:""))) i '($zv["VMS") Q $E(fname,1,$L(fname)-12) S fname=$P(fname,";") Q $E(fname,1,$L(fname)-12) dirinvalidmsg(dir1,dir2) n valid1,valid2,cnt,msg s valid1=$$VALIDIR(dir1),valid2=$$VALIDIR(dir2) s cnt=valid1+valid2 ; cnt = 0 if both invalid, 1 if one is valid s msg="The following journaling " s:cnt msg=msg_"directory is" s:'cnt msg=msg_"directories are" s msg=msg_" not valid"_$C(13,10) s:'valid1 msg=msg_" "_dir1_$C(13,10) s:'valid2 msg=msg_" "_dir2_$C(13,10) q msg ChkDirVALID(R) N N S $ZE="",$ZT="ChkBad",N=$ZU(12,R,1) Q N ChkDirEXISTS(R) N N S $ZE="",$ZT="ChkBad",N=$ZU(12,R,2) Q N ChkDirOrSpecEXISTS(R) N N S $ZE="",$ZT="ChkBad",N=$ZU(12,R,3) Q N ChkDir(R) N N S $ZE="",$ZT="ChkBad",N=$ZU(12,R,2) Q N ChkBad S $ZT="" W !,"<"_$P($P($ZE,"<",2),">")_"> error -- invalid directory" Q "" ASKSET(prompt,val) ;procedure N x W !,$G(prompt)," ",$G(val)," =>" R x,! S:x'="" val=x Q curfile() S $zt="etcurfile" Q $p($zu(78,4)_","_$zu(78,3),",",2) etcurfile Q "" loginfo(msg) ;must be called from within INT (JRNSTART, JRNSWTCH) i $d(glo) s @glo=$g(@glo)+1,@glo@(@glo)=msg i $d(io) u io w !,msg q