Setting Log File Types and Parameters in C

As explained in the persistent database recovery page the eXtremeDB runtime uses the transaction log file to perform recovery automatically in the case of a prior application crash. The Persistent Database I/O page explains the different log types and how to choose the appropriate type for different application profiles. The manner in which transactions are written to the log is determined by the transaction commit policy. The following sections explain how to set the log type and commit policy in C applications.

Log type

The log type is specified in the mco_db_params_t.db_log_type. For example:

 
    mco_db_params_t    db_params;
    ...
     
    mco_db_params_init ( &db_params );             /* initialize the params with default values */
     
    // Set log file type
    db_params.db_log_type = UNDO_LOG;
     

Note that the valid options for db_log_type are : NO_LOG, REDO_LOG or UNDO_LOG.

Commit Policy

As explained in the Persistent Database I/O page, eXtremeDB offers four distinct commit policy options for log types REDO_LOG and UNDO_LOG. The application can call function mco_disk_transaction_policy() at runtime with one of the following values: MCO_COMMIT_SYNC_FLUSH, MCO_COMMIT_BUFFERED, MCO_COMMIT_DELAYED, or MCO_COMMIT_NO_SYNC. The commit policy can also be set in mco_log_params_t.default_commit_policy of the mco_db_params_t.log_params parameter passed to mco_db_open_dev().

The MCO_COMMIT_NO_SYNC policy causes all transactions to be held in the cache until the application explicitly forces the cache to be flushed to the media with the mco_disk_flush() function.

There are additional parameters to consider for the REDO_LOG log type. For the MCO_COMMIT_DELAYED policy, the database disk manager keeps the transaction in memory until a specified percentage of the log file size is reached. The threshold values mco_log_params_t.redo_log_limit, mco_log_params_t.delayed_commit_threshold and mco_log_params_t.max_delayed_transactions can be set by applications at runtime by calling function mco_disk_set_log_params(). Or these values can be specified in the mco_db_params_t.log_params parameter passed to mco_db_open_dev(). By default, the threshold is set to be a half of the available page pool size.