Ensuring Database Integrity After a Reset or Crash

1/16/2009 11:21 PM
You can subscribe to this wiki article using an RSS feed reader.

On a Palm OS device, database updates are done in real time to persistent memory; if you reset at any time, the database updates have not been lost (but you still have to worry about state information that may be lost).

With StyleTap Platform, each application database is read from persistent memory into program memory when the application opens the database. Database updates are done to the volatile copy in program memory -- they are not automatically flushed out to permanent memory. As a result, if the application crashes or the device is reset, the database updates may be lost.

For an ordinary Palm OS application running under StyleTap, database updates are written out to permanent memory in two cases: when the application explicitly closes the database, or when the application terminates with the database still open. (The application terminates when you go back to the StyleTap Launcher or when you terminate StyleTap. You can terminate StyleTap by selecting StyleTap Launcher menu option Applications/Exit , by entering Ctl-Q on the keyboard or through Windows Settings/System/Memory/Running Programs/Stop.)

To give application developers more control, we have added two StyleTap APIs that can be invoked from StyleTap-aware applications: DatabaseFlush and DatabaseFlushAll. (See StyleTapPlatform.h for the function prototypes.) Your application can call DatabaseFlush whenever it wants. That forces all current updates to a particular database to be flushed immediately to permanent memory. (You do not have to close the database.) After you call DatabaseFlush, a crash or system reset will not result in the loss of the database updates.

DatabaseFlush is a fairly big stick. If there have been any updates to the database (since the database was opened or the last time DatabaseFlush was called), DatabaseFlush writes the entire database out, not just the updates. (If there haven't been any updates, DatabaseFlush does nothing.) This may be a relatively expensive operation, especially if the database is large. You need to decide when it is appropriate to call DatabaseFlush -- perhaps when an order is complete or when a form is closed. You might even put a timer into your application so that DatabaseFlush is called periodically (e.g. every two minutes) in case the user is not actively using the application.

Using DatabaseFlush is the simplest way to update an existing application to handle resets under StyleTap. There is a more sophisticated and possibly more efficient alternative for new application logic. You can use VFS to maintain a journal/audit trail of update information. There is an option in the StyleTap VFS API to flush the output buffer immediately. Using this method you could easily preserve every keystroke, if that was the requirement.

Note that the latest Palm devices, such as the Treos and LifeDrives, are starting to incorporate different kinds of memories and exhibit similar application design issues. StyleTap's DatabaseFlush API is similar to Palm's DmSync API, which was introduced for these devices.