Diagnosis, repair and prevention of damaged JDataStore files.

Abstract: Diagnosis, repair and prevention of damaged JDataStore files.

Question: What can be done to prevent and repair damaged JDataStore files?

A damaged JDataStore file can be diagnosed using the StreamVerifier. This can be executed by opening the JDataStore database inside the DataStore explorer and pressing the verify button. There is also a StreamVerifier class with several options that can be called programmatically.

The typical cause of a JDataStore file damage occurs when using a non-transactional JDataStore. If a non-transactional JDataStore is not closed or its modified cache blocks have not all been saved to disk when System.exit() is called or the computer is shutdown, the database can be left in an inconsistent state.

Transactional JDataStores have built in crash recovery. If there is a power failure or System.exit() is called before the JDataStore has been shutdown, then all changes from uncommitted transactions will be rolled back when the JDataStore is opened again. This recovery will leave the JDataStore in a consistent state.

The following measures can prevent JDataStore file damage:
  • Make the JDataStore database transactional (supported since JBuilder 3.0). Transactional Databases The DataStore Explorer can be used to make a JDataStore database transactional. You can also set the DataStore.TxManager property to make a JDataStore transactional. Update operations are slower with a transactional JDataStore, but you get the safety and consistency guarantees of transactional operation with crash recovery support.
  • If you use a non-transactional JDataStore, make sure you close (shutdown() since JBuilder 3.0) the JDataStore before calling System.exit(1). Note that JDataStore Daemon thread is looks for modified cache blocks to save every 100 milliseconds. So the only way to corrupt such a DataStore is for the System or Application to abruptly terminate before modified cache blocks are saved. You can also set the DataStore.SaveMode property to 2. This causes all modified cache blocks to be saved after any edit (insert/update/deleted) operation. This slows things down a bit, but increases the frequency of cache block saves. Note that DataStore.SaveMode property is ignored for Transactional JDataStores because they have crash recovery support.
A damaged JDataStore can be partially or completely repaired by using the JDataStore copyStreams facility. Use the DataStoreExplorer Tools|Copy DataStore to copy a damaged JDataStore to a new JDataStore. You can also call this method programmatically via the DataStoreConnection.copyStreams() method.