clobber

2022-11-07

Library for transaction-oriented data bases.

Upstream URL

github.com/robert-strandh/Clobber

Author

Robert Strandh <robert.strandh@gmail.com>

License

FreeBSD, see file LICENSE.text
README

1Explanation

Clobber is an alternative to so-called "object prevalence", and inparticular to cl-prevalence.

Clobber is both simpler, more flexible, and more robust than systems based on object prevalence.

1.1Simplicity

Clobber is simpler because we do not take any snapshots at all. Othersystems typically use a combination of transaction logs and snapshots.Clobber uses only a transaction log which is always read into an emptysystem.

1.2Flexibility

Clobber is more flexible because the system itself does not define theformat of a transaction. Client code can save transactions as Lisplists, as instances of standard-object, or anything else that can beserialized. It is also more flexible because transactions can containany object that can be serialized, including model objects. With thismethod, client code does not need to manipulate "manually createdpointers" such as social security numbers, account numbers, membershipnumbers, etc. whenever it needs to execute a transaction. Instead itcan use the model objects themselves such as people, accounts,automobiles and whatnot.

1.3Robustness

Clobber is more robust because serialization of instances of (subclassesof) standard-object is not accomplished based on slots. Clobber considers slots to beimplementation details. In other object prevalence systems, wheneverthe model evolves, the serialization might no longer be valid. Incontrast, Clobber serializes instances of standard-object as a list ofpairs, each one consisting of an initarg and a value. These pairs canbe handled by client code in any way it sees fit. They can be handledby an :initarg, by initialize-instance, or they can be ignored. Thedownside of the Clobber method is that client code must specify thesepairs in the form of an initarg and the name of an accessor functionto be called to obtain the value used for the initarg. Thisinconvenience is however relatively minor, especially considering theadditional robustness it buys in terms of less sensitivity to changesin the model classes.

1.4Design

At the heart of Clobber is a mechanism for serializing objects thatpreserves object identity, much like the reader macros #= and ##,except that Clobber detects sharing within the entire transaction log,not only within a single transaction. This mechanism is what makes itpossible for client code to put any old object in a transaction, whilemaking sure that sharing is preserved.

1.5Examples

Two examples are included - see files demo.lisp and demo2.lisp

To run demo.lisp -

(ql:quickload :clobber)
(in-package :clobber-demo)
(start "/path/to/new/file")
(do-things-1)
;; inspect the file to see the transaction log

1.6License

Clobber is in the public domain in countries where it is possible toplace works in the public domain explicitly. In other countries, wewill distribute Clobber according to a license that lets the user dowhatever he or she pleases with the code.

1.7Contact

Send comments to robert.strandh@gmail.com

A manual might be written one day.

2How to use Clobber

  1. If your application objects are instances of (subclasses of) standard-object, use clobber:define-save-info to tell Clobber how to serialize them.
  2. Determine the data structure your application will use to represent each transaction, and how the application will restore state from each transaction.

    e.g. a transaction could be a list whose car is a function and whose cdr is a list of arguments to the function. State can be restored from such a transaction through (lambda (txn) (apply (first txn) (rest txn)))

  3. When you update your application state -
    1. Use clobber:with-transaction-log to create a transaction log.
    2. Within the body of clobber:with-transaction-log, use clobber:log-transaction to persist the changes to your application state. You may wish to define a helper function or macro for this.

If clobber:with-transaction-log is for some reason unsuitable -

  1. Use clobber:open-transaction-log to create a transaction log, usually stored in a special variable.
  2. Use clobber:log-transaction to persist changes to your application state.
  3. When the transaction log is no longer required, close it using clobber:close-transaction-log.

3Reference

3.0.1define-save-info (type &body save-info) :macro:

3.0.2with-transaction-log ((var file function) &body forms) :macro:

3.0.3open-transaction-log (filename function) :function:

3.0.4log-transaction (transaction transaction-log) :function:

3.0.5close-transaction-log (transaction-log) :function:

Dependencies (0)

    Dependents (0)

      • GitHub
      • Quicklisp