Directives
SYSTEM_JRNL File System Journalization
   
Formats 1. Open System Journal: SYSTEM_JRNL OPEN journal$
2. Close System Journal: SYSTEM_JRNL CLOSE
3. Enable Journalization: SYSTEM_JRNL ENABLE filename$
4. Disable Journalization: SYSTEM_JRNL DISABLE filename$
5. Add Entry to File: SYSTEM_JRNL WRITE var$
6. EFF Begin Transaction: SYSTEM_JRNL BEGIN
7. Database Auto-Commit Control: SYSTEM_JRNL AUTO {ON | OFF}
8. Database Commit Transaction: SYSTEM_JRNL SAVE
9. Dynamic Auto-Commit: SYSTEM_JRNL BEGIN AUTO
10.
Database Roll Back Transaction: SYSTEM_JRNL RESTORE
11.
Dirty File Indicator: SYSTEM_JRNL DIRECTORY directory$
12.
Swap journal files: SYSTEM_JRNL SWAP

Where:

directory$ Name of common directory where tracking files are to be created.
filename$ Data file identified for journalization.
journal$ Name of the serial file being used as the journal. String expression. First, create the journal as an empty serial file; via SERIAL journal$
var$ String containing data to be added to open journal.
   
Description Use SYSTEM_JRNL to have ProvideX log all updates to specified data files.
   
Journal sequencing Journal files are limited to a size of 2GB. It is important to make sure that a journal file is closed and a new journal is started before exceeding this limit.

In order to avoid this problem, PxPlus provides for the automatic rollover to new journal files whenever a journal file exceeds 2,000,000,000 bytes in size. This option is enabled by specifying a directory name as the journal$ field when opening a system journal. If a directory is specified the system will automatically will create sub-ordinate files within the directory called journal.1, journal.2, ...

As each file fills up the system will automatically create and start logging to the next highest file.

Automatic journal sequencing is a +PxPlus Exclusive - version 9

   
See Also SERIAL Create a Sequential File.
   
Format 1 Open System Journal

SYSTEM_JRNL OPEN journal$

This format opens the journal (serial file); e.g.,

SERIAL "MYJRNL"
SYSTEM_JRNL OPEN "MYJRNL"

Journal Contents

The physical journal file is a binary file that has a special format designed for quick write access and efficient retrieval. Each of the journal file's records has a 16-byte header consisting of:

Bytes Description
1 Type of record (O-Open, A-After, B-Before, etc...)
2-4 Record size in bytes
5-8 Time of day when record was written in seconds past 01/01/1970 GMT
9-12 Address of prior record for session
13-16 Address of related record; e.g., After/Before image points to file
Open record. Open file record points to User login record

The rest of the record is the before/after image of the data. The file itself has a four-byte header with the address of the last record on the file.

   
   
Format 2 Close System Journal

SYSTEM_JRNL CLOSE

This format closes the open system journal.

   
Format 3 Enable Journalization

SYSTEM_JRNL ENABLE filename$

Use this format to enable journalization for the specified data file (Keyed or Indexed files only). Enabling journalization sets a bit in the file header for the specified file

Specifying a file name of * initiates the journalization of all keyed/indexed file updates..



*Note* If you have enabled journalization for a data file, you cannot access that file unless the journal file is open.


   
Format 4 Disable Journalization

SYSTEM_JRNL DISABLE filename$

Use this format to disable journalization for the specified data file.

   
Format 5 Add Entry to File

SYSTEM_JRNL WRITE var$

This format adds the contents of var$ to the currently open journal (serial file).

   
Format 6 EFF Begin Transaction

SYSTEM_JRNL BEGIN

This directive is used to mark the start of a transaction. All updates to file systems (EFF, ODB, DB2, Oracle, and MYSQL) will be deferred until the transaction completes and it is committed using the SYSTEM_JRNL SAVE directive.

   
Format 7 ODBC/OCI Auto-Commit Control

SYSTEM_JRNL AUTO {ON | OFF}

This format is used to control auto-commit mode of an EFF, ODBC, DB2, Oracle or MySql database connection. Auto-commit means that all updates to the database are made immediately and cannot be rolled back in case of an error.

SYSTEM_JRNL AUTO OFF will disable the auto-commit mode of operation. All updates to the database are deferred until the application successfully ends or a SYSTEM_JRNL SAVE directive is issued. SYSTEM_JRNL AUTO ON re-enables Auto-commit mode.

   
Format 8 ODBC/OCI/EFF Commit Transaction

SYSTEM_JRNL SAVE

This format will commit all pending/deferred updates to a database transaction, if auto-commit mode is disabled; Error #15 is reported, if a database error occurs.

   
Format 9 Dynamic Transaction Auto-commit

SYSTEM_JRNL BEGIN AUTO

PxPlus provides enhanced auto-commit logic that automatically uses transaction processing logic to defer all updates to a database until the application enters an idle state such as waiting for input or issuance of a WAIT directive. This Dynamic Auto-commit improves both system performance and the reliability of updates since all changes to the database occur at the same time. This helps assure synchronization of all updates between files and/or databases.



*Note* Due to the nature of the commitment process on different databases servers, the system cannot assure that updates done on different databases occur in unison. It is possible, although unlikely, that during a commit cycle, updates may be committed to one database and an error occur during the commit to another database thereby rendering a potential inconsistency between the databases.


  To disable the Dynamic Auto-commit, re-enable Auto-commit by issuing SYSTEM_JRNL AUTO ON.

Dynamic Auto-commits are a +PxPlus Exclusive

Format 10 ODBC/OCI/EFF Roll Back Transaction

SYSTEM_JRNL RESTORE

This format will roll back and discard all pending/deferred updates within database transaction, if auto-commit mode is disabled; Error #15 is reported, if a database error occurs.

   
Format 11 Dirty File Indicator

SYSTEM_JRNL DIRECTORY directory$

This format is used to track potential file corruption (dirty files) by maintaining a list of all the files that have been opened and modified during a ProvideX session. ProvideX creates a single tracking file per active process in directory$.

When a session terminates normally, it deletes its tracking file; therefore, the existence of a tracking file means there is either a ProvideX task currently active, or that a ProvideX task has terminated abnormally (due to software fault or operating system failure).

Specifying a null directory name will disable this feature. If the directory name specified does not already exist, an Error #12: File does not exist (or already exists) will be generated. An Error #13: File access mode invalid is reported, if a file of the same name exists, but not as a directory.

Tracking Files

Each tracking file (log) is created with a unique name using the following format:

username.MMDDHHMMSS.log Windows
username.MMDD.PPPPP.NNN.log Unix/Linux

Where:

username Name for the session. In the case of client/server applications, the workstation name (if present) or IP address will be used, otherwise the user name for the host process will be used. No attempt is made to determine the true workstation end-user name -- only the workstation name, as returned from the socket's 'GetPeerName' function, will be used.
MMDDHHMMSS Date and time that the log started.
MMDD.PPPPP.NNN Date and processid of the task that created the log file. 'NNN' is a sequence number in case the process id is duplicated during the day. Note, the length of the PID and sequence number will be based on their value; it is not a fixed length.

The use of the Process ID on Unix is a +PxPlus Exclusive

The tracking file contains a list of all the data files that have been physically updated and not yet closed by the ProvideX process. Every time a file has an update issued against it, the system will add the pathname to the tracking file. Each line will be separated by a standard (OS dependant) end-of-line sequence.

Multiple occurrences of the same file may exist in the tracking file, as entries are maintained based on open channels.

The tracking file is updated to indicate when a file is being updated prior to the execution of the WRITE or REMOVE directives. When a file that was logged is closed, its entry from the log file will be removed. To help ensure that the contents of the tracking file are accurate, ProvideX will close the file after each write.



*Note* Only Keyed files (EFF, VLR and FLR) and Indexed files are tracked.


   
Format 12 Swap journal files

SYSTEM_JRNL SWAP

This directive can be used in conjunction with the auto-sequencing of log files which is a +PxPlus Exclusive (version 9)

When issued the current journal file is marked full and a new journal file is started.

   
Examples The following code sample illustrates parsing of a SYSTEM_JRNL file:

00010 ! DumpJrnl - Sample routine to parse a System_Jrnl file
00020 ! Note: Time is in GMT
00030 OPEN (1,ISZ=1)"jrnl.dat"
00040 READ RECORD (1,IND=0,SIZ=4,ERR=0500)filesize$
00050 LET filesize=DEC($00$+filesize$)
00060 PRINT "Size of Journal file is: ",filesize
00070 LET nextindex=4
00080 !
00100 ! !^100
00110 IF nextindex=0 OR nextindex>filesize \
                    THEN GOTO 0500
00120 READ RECORD (1,IND=nextindex,SIZ=16,ERR=0500)header$

00130 LET type$=header$(1,1)
00140 LET recsize=DEC($00$+header$(2,3))
00150 LET time=DEC($00$+header$(5,4))
00160 LET priorrec=DEC($00$+header$(9,4))
00170 LET relatedrec=DEC($00$+header$(13,4))
00180 LET datarec$="";
          IF recsize \
 
                  THEN READ RECORD (1,IND=nextindex+16,SIZ=recsize-16,ERR=0500)datarec$
00190 LET nextindex+=recsize

00200 !
00300 ! !^100 - Format & display
00310 LET disprec$=SUB(SUB(datarec$,SEP,"~"),ESC,"~")
00320 LET days=INT(time/86400);
          IF (days*86400)>time \
 
                  THEN days--
00330 LET time=time-days*86400

00340 LET sv_by=PRM('BY'); SET_PARAM 'BY'=1970
00350 LET t$=DTE(days,time/3600:"%Ms%Dz/%Ys-%hz:%mz:%sz%p")

00360 SET_PARAM 'BY'=sv_by
00370 !
00380 PRINT t$," Type: ",type$," Prior Rec:",priorrec:"####,##0"," RelatedRec:",relatedrec:"####,##0"," RecSize",recsize:"###,##0"," Record:",disprec$
00390 GOTO 0100
00400 !
00500 ! ^100

  The following illustrates use of the SYSTEM_JRNL for tracking potential file corruption (dirty file indicator):

Dir$="/SysJrnl.Dir/"; DIRECTORY Dir$,ERR=*NEXT
WorkFile$="WorkFile.Dat"; KEYED WorkFile$,10,0,-256,ERR=*NEXT
!
! Generate a log file
SYSTEM_JRNL DIRECTORY Dir$
OPEN (UNT)WorkFile$; WorkFile=LFO
WRITE (WorkFile,KEY="Test")"Test","Record"
! List$=""
SELECT Log$ FROM Dir$ WHERE POS(".log"=Log$)
SELECT File$ FROM Dir$+Log$
IF POS(File$+SEP=List$) \
THEN CONTINUE \
ELSE List$+=File$+SEP
PRINT "Checking: ",File$," ",
CALL "*ufac",ERR=*NEXT,File$,1; PRINT "Okay"; CONTINUE
PRINT File$,":",MSG(ERR)
NEXT RECORD
NEXT RECORD
!
CLOSE (WorkFile)