T4.3: Ensures Data Integrity

Knowledge Review - InterSystems IRIS Development Professional

1. Understands journaling behavior within transactions

Key Points

  • Automatic journaling: All global updates within transactions are journaled regardless of database journal state
  • TSTART to TCOMMIT: Transaction boundaries define journaled scope
  • Nested transactions: Each TSTART increments $TLEVEL, creating nested journaling contexts
  • Commit guarantee: Changes only committed when outermost TCOMMIT sets $TLEVEL to 0
  • Rollback capability: Journal entries enable complete transaction rollback to pre-TSTART state

Detailed Notes

InterSystems IRIS automatically journals any global update that is part of a transaction, regardless of the global journal state setting for the database in which the affected global resides. This ensures complete transaction integrity and recoverability even for non-journaled databases. When a transaction begins with TSTART, the $TLEVEL special variable increments to track nesting depth. All SET and KILL operations on globals within the transaction are recorded in the journal with transaction markers.

The journal contains specific transaction record types: BT (Begin Transaction) when $TLEVEL was zero, and BTL (Begin Transaction with Level) for nested transactions. During a transaction, journal entries accumulate but actual commitment is deferred until the outermost TCOMMIT decrements $TLEVEL to 0. This deferred commitment allows nested transactions to be individually rolled back while maintaining overall transaction consistency. The journal write cycle ensures that TCOMMIT operations request a flush of journal data to disk, with configurable synchronous commit behavior determining whether the operation waits for disk write completion.

Within transactions, the journal provides both atomicity and durability. If a system crash occurs during a transaction, InterSystems IRIS uses journal entries during startup recovery to roll back any incomplete transactions, ensuring that no partial transaction changes remain in the database. The journal also records transaction markers that identify transaction boundaries, enabling tools like %SYS.Journal.System.GetImageJournalInfo() to analyze transaction history and identify open transactions. This comprehensive journaling of transactional operations is fundamental to ACID compliance in InterSystems IRIS.

2. Understands journaling behavior outside transactions

Key Points

  • Database journal state: Journaling controlled by Global Journal State property (Yes/No)
  • Default behavior: All user-created databases journaled by default
  • System databases: IRISAUDIT, IRISSYS, USER journaled; IRISLIB, IRISTEMP not journaled
  • IRISTEMP exception: Operations to temporary globals never journaled
  • Non-transactional updates: Journaled only if database Global Journal State is Yes

Detailed Notes

Outside of transactions, journaling behavior is controlled by the database-level Global Journal State property, which can be either Yes or No. The journaling state is a property of the database, not individual globals. By default, all databases you create are journaled. In newly installed InterSystems IRIS instances, the IRISAUDIT, IRISSYS, and USER databases are journaled by default, while IRISLIB, IRISTEMP, and IRISLOCALDATA databases are not journaled. Operations to globals in IRISTEMP are never journaled; you should map temporary globals to the IRISTEMP database to avoid unnecessary journal overhead.

When a global update occurs outside a transaction, InterSystems IRIS checks the Global Journal State of the database containing that global. If the state is Yes, the SET or KILL operation is journaled. If the state is No, the operation is not journaled. This differs fundamentally from transactional behavior, where updates are journaled regardless of the database journal state. The journal write cycle operates continuously, with journal sync operations triggered every two seconds when the system is idle, or more frequently under active load.

Non-transactional journaling provides crash recovery capability but not atomicity guarantees. If a system crash occurs, journal recovery at startup reapplies all journaled operations since the last write daemon pass, ensuring that committed global updates are preserved. However, without transaction boundaries, there is no automatic rollback of incomplete operations. Operations on local variables, process-private globals, and special variables like $TEST are never journaled, whether inside or outside transactions. Understanding this distinction is critical for designing robust applications that balance data integrity requirements with performance optimization through selective journaling.

3. Minimizes journal volume and performance impact

Key Points

  • Journal file compression: Enable CompressFiles setting to minimize disk space (enabled by default)
  • Separate storage devices: Place journal directories on separate physical drives from databases and WIJ
  • Primary and alternate: Configure separate primary and alternate journal directories for resilience
  • Temporary globals: Map transient data to IRISTEMP to avoid journaling overhead
  • Selective journaling: Disable journaling for databases containing only transient or reconstructible data

Detailed Notes

Minimizing journal volume and performance impact requires careful planning of journal configuration and application design. Journal file compression should be enabled using the CompressFiles CPF setting, which is enabled by default for new InterSystems IRIS installations. This significantly reduces the amount of disk space consumed by journal files without impacting recovery capability. For storage architecture, InterSystems recommends placing the primary and alternate journal directories on storage devices that are separated from the devices used by databases and the write image journal (WIJ). While these different devices may be different logical unit numbers (LUNs) on the same storage area network (SAN), the general rule is the more separation the better, with separate sets of physical drives highly recommended.

The major benefits of separating database/WIJ storage from primary and alternate journal storage include isolating journal directories from failures that may compromise the databases, ensuring journaling can continue when the primary directory becomes unavailable, and achieving I/O concurrency that most applications require. The default installation creates a single journal directory as both primary and alternate, but this should be reconfigured as soon as possible after installation. Application design decisions also significantly impact journal volume: map temporary globals and working data to IRISTEMP database, which is never journaled, and consider disabling journaling for databases that contain only transient data or data that can be easily reconstructed from other sources.

Additional optimization strategies include managing journal file retention policies appropriately - only purge journal files that were closed prior to the last known good backup. Set the number of days and number of successful backups after which to keep journal files based on your recovery time objectives and storage capacity. Consider implementing journal archiving to copy journal files to archive storage when they reach maximum size, optionally purging the original after successful archiving. Monitor journal I/O performance through Management Portal metrics and adjust the journal buffer size if needed. The Freeze on error setting should be carefully considered: setting it to Yes prioritizes data integrity over availability by freezing the system if both primary and alternate journal devices fail, while No allows the system to continue with journaling disabled.

4. Manages transactions effectively

Key Points

  • TSTART/TCOMMIT pairing: Every TSTART must have matching TCOMMIT or TROLLBACK
  • $TLEVEL monitoring: Track transaction nesting depth (0=no transaction, max 255 levels)
  • Nested transaction support: Use TSTART within transactions for modular code design
  • Error handling: Always implement TRY-CATCH with TROLLBACK in CATCH block
  • Lock retention: Locks acquired in transactions held until outermost TCOMMIT/TROLLBACK

Detailed Notes

Effective transaction management begins with proper pairing of TSTART and TCOMMIT commands. TSTART marks the beginning of a transaction and increments $TLEVEL, while TCOMMIT marks successful completion and decrements $TLEVEL. The transaction is only committed when $TLEVEL returns to 0, meaning the outermost TCOMMIT has been executed. Calling TCOMMIT when $TLEVEL is already 0 results in a COMMAND error, so always check transaction state before issuing transaction control commands. InterSystems IRIS supports nested transactions up to 255 levels, allowing modules to issue their own TSTART/TCOMMIT pairs independently of calling code.

Transaction management requires comprehensive error handling. Use TRY-CATCH blocks with TROLLBACK in the CATCH section to ensure transactions are rolled back on errors. TROLLBACK has two forms: TROLLBACK 1 rolls back only the current nesting level and decrements $TLEVEL by 1, while TROLLBACK (without argument) rolls back all transactions and resets $TLEVEL to 0. Be cautious with nested transactions - if you TROLLBACK 1 an inner transaction and then TCOMMIT the outer transaction, the inner rollback is preserved. Conversely, if you TCOMMIT an inner transaction but TROLLBACK the outer transaction, all changes including the "committed" inner transaction are rolled back because actual commitment is deferred until $TLEVEL reaches 0.

Lock management within transactions requires special attention. By default, locks issued within a transaction are held until the end of the transaction, even if explicitly released. This default can be overridden when setting the lock. Transaction suspension using %SYSTEM.Process.TransactionsSuspended() suspends journaling of changes, and TROLLBACK cannot roll back changes made while transactions were suspended. For performance optimization, consider using synchronous commit (%SYSTEM.Process.SynchCommit()) to control whether TCOMMIT waits for journal data to be written to disk. The default is asynchronous (faster but slightly less durable), while synchronous mode ensures durability at the cost of transaction latency. Monitor transaction duration and avoid long-running transactions that hold locks and increase rollback overhead.

5. Understands automatic rollback causes and prevention

Key Points

  • System crash recovery: Incomplete transactions automatically rolled back at startup
  • Process termination: Halting or terminating processes triggers transaction rollback
  • ROLLFAIL errors: Journal unavailable or corrupted during rollback causes ROLLFAIL
  • Freeze on error: Configuration determines system behavior when rollback fails
  • Operations not rolled back: Local variables, $INCREMENT, $SEQUENCE, LOCK operations, namespace changes

Detailed Notes

InterSystems IRIS automatically rolls back incomplete transactions in several scenarios. During recovery after a system crash, which occurs as part of InterSystems IRIS startup, the system uses journal entries to roll back any transactions that were in progress at the time of the failure. When you halt your process while transactions are in progress, the system automatically rolls back those transactions. If you terminate a process using the Terminate option from the Processes page of the Management Portal (System Operation > Processes), the system handles rollback differently depending on how the process was initiated: for processes started with the Job command, transactions are automatically rolled back; for user processes, the system prompts whether to commit or roll back incomplete transactions.

ROLLFAIL errors occur when TROLLBACK cannot successfully complete the rollback operation. Common causes include journal files being unavailable, corrupted, or deleted; the database being dismounted during the transaction; or journaling being disabled before database changes were made. The system behavior when a ROLLFAIL occurs depends on the Freeze on error journal configuration setting. If Freeze on error is not set (the default), the process receives a ROLLFAIL error, the transaction is closed, and any locks retained for the transaction are released - this trades data integrity for system availability. If Freeze on error is set, the process halts and the clean job daemon (CLNDMN) retries rolling back the transaction, potentially causing the system to hang while locks remain held - this trades availability for data integrity.

Prevention of rollback failures requires understanding what cannot be rolled back. TROLLBACK does not restore changes to local variables, process-private globals, special variables like $TEST, the current namespace, or LOCK operations. Additionally, $INCREMENT and $SEQUENCE operations on globals are not rolled back - these operations are atomic but not transactional. To prevent ROLLFAIL errors, ensure journaling remains enabled throughout transactions, avoid dismounting databases that contain globals modified in active transactions, maintain adequate disk space for journal files, and configure proper primary and alternate journal directories. When designing applications, structure transactions to be as short as possible, implement proper error handling with explicit TROLLBACK in CATCH blocks, and validate that critical operations completed successfully before committing transactions.

Exam Preparation Summary

Critical Concepts to Master:

  1. Transaction vs Non-Transaction Journaling: Understand that transactional updates are always journaled regardless of database journal state, while non-transactional updates honor the database Global Journal State setting
  2. $TLEVEL Management: Know that $TLEVEL=0 means no transaction, TSTART increments it, and actual commitment only occurs when TCOMMIT returns it to 0
  3. Nested Transaction Behavior: Understand that nested transaction commitment is deferred until outermost TCOMMIT, and rolling back outer transactions also rolls back "committed" inner transactions
  4. Journal Volume Optimization: Recognize strategies including compression, separate storage devices, IRISTEMP for temporary data, and selective database journaling
  5. Rollback Scenarios: Know the three automatic rollback situations (crash recovery, process halt, process termination) and what operations cannot be rolled back

Common Exam Scenarios:

  • Predicting $TLEVEL values after sequences of TSTART, TCOMMIT, and TROLLBACK commands
  • Identifying which database operations will be journaled in transaction vs non-transaction contexts
  • Recognizing proper error handling patterns with TRY-CATCH and TROLLBACK
  • Determining the final state of globals and local variables after TROLLBACK operations
  • Selecting appropriate journal configuration settings for performance vs integrity requirements
  • Understanding ROLLFAIL error causes and system behavior based on Freeze on error setting

Hands-On Practice Recommendations:

  • Write code with nested transactions and experiment with different TCOMMIT/TROLLBACK combinations
  • Create test databases and toggle Global Journal State to observe journaling behavior differences
  • Implement error handling with intentional failures to trigger and observe automatic rollback
  • Use Management Portal to configure journal settings and monitor journal file creation/rollover
  • Practice with $INCREMENT and $SEQUENCE to understand operations that cannot be rolled back
  • Simulate ROLLFAIL conditions by disabling journaling mid-transaction
  • Examine journal files using ^JOURNAL utility to understand transaction markers (BT, BTL)

Key Commands and Variables:

  • TSTART: Begin transaction, increment $TLEVEL
  • TCOMMIT: Commit transaction, decrement $TLEVEL (actual commit when $TLEVEL=0)
  • TROLLBACK: Roll back all transactions, reset $TLEVEL to 0
  • TROLLBACK 1: Roll back one nesting level, decrement $TLEVEL by 1
  • $TLEVEL: Transaction nesting level (0=no transaction, max=255)
  • %SYSTEM.Process.SynchCommit(): Configure synchronous vs asynchronous commit
  • %SYSTEM.Process.TransactionsSuspended(): Suspend/resume transaction journaling

Documentation Quick Reference:

  • Data Integrity Guide (GCDI): Sections 5 (Journaling Overview) and 6 (Configuring Journaling)
  • ObjectScript Reference (RCOS): TSTART, TCOMMIT, TROLLBACK command reference
  • Using ObjectScript (GCOS): Transaction Processing chapter
  • Management Portal: System Configuration > Journal Settings for configuration options

Report an Issue