Happstack-state concept and docs?
Asked Answered
T

2

5

I'm starting making Haskell web server. I've decided to start with Happstack and Happstack-state. And I'm feeling hard to understand concept and attribute of Happstack-state. Is it a new kind of database? or Just object-graph like system?

Can you explain it's concept and attribute (especially about ACID, how it persistent data on disk!) or point me a document describes it well?

Takahashi answered 24/2, 2011 at 3:37 Comment(0)
A
5

Here are two basic introductions to MACID:

http://happstack.com/docs/crashcourse/HappstackState.html#happstack_state

http://www.kuliniewicz.org/blog/archives/2009/04/05/happstackstate-the-basics/

Alas, neither covers IxSet, which is a datatype that is often used with MACID to provide sets with multiple indexes (similar to a SQL table).

MACID is a "ram cloud" style persistent store, meaning your entire dataset is stored in RAM. It currently supports replication. The development version is focused on adding sharding support (among other things).

The thing that makes MACID unique is that it stores normal Haskell dataypes and queries are written using normal Haskell functions. You are not limited to just a small subset of Haskell datatypes such as Int and String. Instead, you can use almost any user defined datatype.

Although MACID stores the working dataset in RAM and is not built around the relational model, it does still provide ACID guarantees. The durability property ensures that once a commit returns successfully, the event will not be lost if their is a server failure (or restart).

Durability is achieved by logging each update event to a write-ahead log. If the the server goes down, the state can be restored by replaying any events since the last checkpoint.

An event in the write-ahead log consists of the name of the update function and the arguments to that function. Since update events are pure, replaying them always results in the same final state.

The actually binary format for the data stored in checkpoints or log events is specified by creating a instance of the Serialize class. In most cases this can be done automatically by calling the template-haskell function 'deriveSerialize'. There is also a Migrate class which is used to migrate values from old formats to new formats when you change your datatypes.

There is an old blog post on the serialization and migration mechanisms here:

http://nhlab.blogspot.com/2008/12/data-migration-with-happs-data.html

That post refers to 'HAppS', but it is pretty much the same in Happstack aside from the module names.

Hope this helps.

Azeria answered 25/2, 2011 at 1:1 Comment(2)
Really any kind of data can be stored without any special requirements? Serialization mark...deriving from a specific class... (oh I'm Haskell newbie from OO) such a things?Takahashi
There are a few limitations on the types you can serialize. For example, you can not serialize a data-type that contains a function. Basically, if you can create Read and Show instances for a type where 'read . show == id', then you can use that type directly in your MACID database.Azeria
B
3

MACID is not a database, foremost its's just an ACID framework, that is, it cares about transactional safety, precisely by keeping an on-disk transaction log. On top of that, you can use e.g. IxSet, which are sets on steroids and a standard choice, but you could equally well roll your own.

I'm afraid the best documentation I know about is the source, itself. HappStack is whoefully underdocumented.

Beene answered 24/2, 2011 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.