Change tracking

Change tracking is an internal structure maintained by each individual ISAM file. Internal control entries, or change records, are automatically recorded to a file for each file update that occurs. Updates include STORE, DELETE, and WRITE operations, as well as the Select.AlphaEnumerator.Current property set method. Periodic timing controls, called snapshots, can then be applied to manage these change records over time. These controls are transparent to normal file operation, but you can use external routines to access these controls and influence sequential operations on the file. Change records represent all user updates and are accessed as a whole rather than by individual user.

Change tracking enables you to quickly access changes made to a file over a period of time. For example, change records can be used to apply period-end figures, update an SQL database, or do anything that would otherwise require a top-to-bottom sequential scan of an entire file when only changes made during a specific time period need to be queried. Reclamation and rollback operations are allowed at file snapshot points unless the rollback function is turned off. A file snapshot can also be used as a backup restore point.

When change tracking is first applied to a file (using the ctutl utility), or when the change tracking file has been cleared, an implied snapshot {#0} is applied to represent the beginning point, and the current snapshot number is set to 1. (This beginning point remains throughout the life of the file; however, as old snapshots are freed, the beginning point assumes the identity of the oldest applied snapshot.) All file inserts, updates, and deletes are logged with the current snapshot number until a new snapshot is applied using the ctutl utility (numerically identified by the current snapshot number, which is then incremented). Snapshot numbers continue to grow numerically in value until the file is cleared or re-initialized. Rolling a file back to an earlier snapshot also sets the current snapshot number back. Snapshots are freed (beginning with the oldest) and rolled back (beginning with the newest) using the ctutl utility. A maximum of 255 concurrent snapshots is allowed at one time, but snapshot numbers will continue to grow even beyond 255.

Tip

When using change tracking, we recommend using frequent snapshots (daily, weekly, or monthly, depending on your transaction cycle) and then managing those snapshots by freeing old ones as they become unnecessary. Neglecting to manage snapshots will result in unwanted file growth and/or exceeding the 255 concurrent snapshot maximum.

A file’s change tracking history is accessed using the Select class via the Synergy Change Tracking API. The Where class Changes and NetChange methods allow you to programmatically select all changes and net changes, respectively, made between two snapshots. In addition, the Where class Snapshot method enables you to make selections against a file entirely as it was when an applied snapshot was made. Using this method, end-of-period processing can occur without suspending current file update activity.

All changes made between one snapshot and the next snapshot get recorded as net changes. In other words, if you insert a record with a STORE and then update the same record with a WRITE before the next snapshot is made, the net result is an insert with the contents as of the last WRITE. Similarly, if a WRITE occurs at the beginning of a snapshot followed by another WRITE before the next snapshot, the result is an update with the contents of the last WRITE. Lastly, if a record is inserted and then deleted during the same snapshot, the record and its change history are removed entirely. The following table summarizes these results:

Changes

Net result

Insert + Update

Insert

Update + Update

Update

Update + Delete

Delete

Insert + Delete

<none>

Note

Snapshots are maintained within the ISAM file itself. If you unload the records or convert them with fconvert, the change history is not preserved in the new file.

ISAM files must be at Revision 6 in order to use change tracking capabilities. Use the ctutl utility to manage change tracking information on the files you’ve chosen. (See ctutl for details.) Change tracking is not allowed with multiple fixed-length files.