25.01.2015 Views

Caché System Administration Guide - InterSystems Documentation

Caché System Administration Guide - InterSystems Documentation

Caché System Administration Guide - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In addition to the new values of 900 and 600, the journal contains the pre-transaction values of 1000<br />

and 500. In the event that a rollback is required before the transaction is committed, these old values<br />

are used.<br />

When a system crash occurs, rollback happens automatically. First, recovery via the two-phase write<br />

protocol restores the internal consistency of the database. Next, all incomplete transactions (those that<br />

began but were never committed) are rolled back.<br />

10.4.2 Transactions and Locking<br />

You use the Lock command in <strong>Caché</strong> applications to protect against simultaneous access to data.<br />

For example, an application might contain the following steps:<br />

TSTART<br />

//begin transaction<br />

Lock +^SAVINGS(ACCOUNT,"BALANCE") //lock record<br />

Set ^SAVINGS(ACCOUNT,"BALANCE") = ^SAVINGS(ACCOUNT,"BALANCE") - 100<br />

Lock -^SAVINGS(ACCOUNT,"BALANCE") //unlock record<br />

Lock +^CHECKING(ACCOUNT,"BALANCE") //lock record<br />

Set ^CHECKING(ACCOUNT,"BALANCE") = ^CHECKING(ACCOUNT,"BALANCE") + 100<br />

Lock -^CHECKING(ACCOUNT,"BALANCE") //unlock record<br />

TCOMMIT<br />

The value of SAVINGS becomes unavailable to other processes when it is locked, and available again<br />

as soon as it is unlocked.<br />

Now suppose that a transaction fails as the application is updating CHECKING. Transaction rollback<br />

occurs, restoring SAVINGS to its pre-transaction value. But, what if between the instant the application<br />

unlocks SAVINGS and transaction rollback completes, another process accesses SAVINGS If it<br />

examines this value, it may carry out further processing that is erroneous. Worse yet, if it changes this<br />

value, rollback cannot occur.<br />

<strong>Caché</strong> automatically avoids this problem by deferring any unlocks within a transaction until the<br />

transaction is committed or rolled back. Within the transaction, the data appears to be unlocked, permitting<br />

a subsequent lock of the same value in the same transaction to work correctly. Outside the<br />

transaction, however, the data remains locked.<br />

10.4.3 Global Journaling<br />

Logical Data Protection<br />

Global journaling preserves changes in the database since the last backup. While a backup is the cornerstone<br />

of physical recovery, it is not the complete answer. Restoring the database from a backup<br />

makes the contents of the database current as of the time the backup was completed. Typically, this is<br />

a long time (at least a number of hours) before the point at which physical integrity was lost. What<br />

happens to all the database changes that occurred since then The answer lies with journaling.<br />

Each computer running <strong>Caché</strong> keeps a journal. The journal is a file that keeps a time-sequenced log<br />

of changes that have been made to the database since the last backup. The process is redundant and<br />

<strong>Caché</strong> <strong>System</strong> <strong>Administration</strong> <strong>Guide</strong> 103

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!