Giter VIP home page Giter VIP logo

prevayler-clj's Introduction

Clojars Project

Features

Prevalence is the fastest possible and third simplest ACID persistence technique, combining the two simplest ones: http://en.wikipedia.org/wiki/System_Prevalence

"Simplicity is prerequisite for reliability." Dijkstra (1970)

Usage

  • Get enough RAM to hold all your data.
  • Model your business system as a pure (no I/O) event handling function.
  • Guarantee persistence by applying all events to you system through Prevayler, like this:
(let [my-file (File. "my-file")
      my-handler (fn [state event] [(str state "Event:" event " ") nil]) ; Any function returning a pair [new-state result]
      initial-state ""]                                                  ; Any value

  (with-open [p1 (prevayler! my-handler initial-state my-file)]
    (assert (= @p1 initial-state))
    (handle! p1 "A")                                                 ; Your events
    (handle! p1 "B")
    (assert (= @p1 "Event:A Event:B ")))                             ; Your system state

  (with-open [p2 (prevayler! my-handler initial-state my-file)]      ; Next time you run,
    (assert (= @p2 "Event:A Event:B "))))                            ; the state is recovered.

Transient Mode for Tests

Calling the prevayler! function without the file argument returns a transient prevayler the you can use for fast testing.

What it Does

Prevayler-clj implements the system prevalence pattern: it keeps a snapshot of your business system state followed by a journal of events. On startup or crash recovery it reads the last state and reapplies all events since.

Shortcomings

  • RAM: Requires enough RAM to hold all the data in your system.
  • Start-up time: Entire system is read into RAM.

Files

If your persistence file is called "my-file", for example, prevayler-clj will write files like this for you:

my-file

A Java serialization object stream with the system state at the moment the file was created followed by events.

my-file.backup

On startup, my-file is renamed to my-file.backup and a new my-file is created. This new my-file will only be consistent after the system state has been written to it so when my-file.backup exists, it takes precedence over my-file.

my-file.backup-[timestamp]

After a new consistent my-file is written, my-file.backup is renamed to this. You can keep these old versions or delete them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.