Write-Behind Caching

ActiveSpaces supports write-behind caching in addition to write-through caching to a back-end database. Write-behind caching provides asynchronous writes to the database for faster performance, and allows writes to be buffered in cache and written to the database later in case the database is down.

The writes to the database are asynchronous to the cache operation. The process is fault-tolerant of Persister failures and seeder failures of the space up to its replication degree.

To enable the write-behind feature, you must set the shared-all persistence policy to ASYNC.

To indicate that an update failed to persist to the back-end data store due to the database connection being down, your persister code must return a PERSISTER_OFFLINE error within the onWrite callback.

The PERSISTER_OFFLINE error indicates that the update is to be retried later. ActiveSpaces does not handle any other persister-related failures, continues with a warning, and removes the specific update that failed.

The following example shows how your code can return the PERSISTER_OFFLINE error message.

ActionResult.create().setFailed(new    ASException(ASStatus.PERSISTER_OFFLINE, sqlException))

The as-admin utility can display statistics indicating the pending update count on each node. If a system is not able to catch up with incoming user updates, the ToPersist count shows the status of pending updates.

Because writes are now asynchronous, changes done in cache are not reflected immediately in the database. ActiveSpaces conflates multiple updates on the same key to a single update to reflect the last update. If the database cannot keep up with cache updates, then updates on different keys are aggregated in memory and potentially use more memory than expected. Running more Persisters might help scale out the workload.

If there are pending updates, caching with a defined limit cannot guarantee that the limit is respected. Once all updates have been flushed, the limit is applied and eviction takes place. Until then, the cache might grow and necessary tuning might be required.