NDB Concepts › NDB Transaction Management: Database Protection
NDB Transaction Management: Database Protection
An NDB is protected against system failures that might occur when an update to the VSAM data set is in progress. Database record locking prevents data corruption caused by multiple users accessing the same record simultaneously.
If it is possible for more than one user to access an NDB record at once, use the &LOCK verb to ensure exclusive access to the record while it is being accessed. That is, perform an &LOCK on a record before any operation that accesses that record proceeds. If another user subsequently accesses the record, any modifications made by the second user do not proceed until the first accessing procedure concludes and the record ceases to be locked.
Protection against system failures is achieved as follows:
- A preformatted journal area is built when the NDB is created. This area consists of a journal control record, and n journal records.
- When an operation that involves updating the NDB starts, the journal area is used to record the updates, but they are not actually performed.
- When the updates are complete, the journaled updates are used to physically update the data set. Before this starts, a flag is set in the journal control record, indicating an update apply procedure is in progress, and the journal control record, and all journal data records are force-written to the VSAM data set.
- If the update apply completes successfully, then buffers are flushed, the journal control record flag is reset, and the journal control record is rewritten.
- If the update apply is interrupted by a system failure, then, when the NDB is next activated, the journal control record flag indicates that an update apply was in progress at the time of the failure. The entire update apply is redone (ignoring errors due to duplicate or already deleted records). Thus database integrity is assured.
- Physical errors on the VSAM data set (for example, out of space) are handled in the same way. Once the data set has been copied to a larger version, the reapply works in the same way.