Materialiser fix

The materialiser cache stores snapshots and operations for each key. Here I present a basic, per key mechanism to garbage collect its state with the intention of releasing memory and avoiding reading from the log (stable storage). Keep in mind that this is the first and most basic approach ever taken, and there is no particular reason for not doing it in any other different way, so all feedback and ideas are welcome.

As there are object views (snapshots) and operations, the growing number of any of them needs to trigger the GC mechanism. 

1. Snapshot (or read-triggered) GC: 
     In case the number of snapshots stored for a key grows up to a value “snapshot_threshold”, keep just the latest “snapshot_min” snapshots. Proposed initial values (for no particular reason) are 10 and 2 respectively. Note that the snapshot generation is done on reads, that’s why this mechanism is triggered only on reads. All the operations that are not included in the remaining snapshots and are not older than the oldest one, remain in the operation cache. The rest are removed.

2. Operation (or write triggered) GC:
      In case the number of update operations stored for a key grows up to a number “ops_threshold”, just perform a read. This read operation will generate snapshots, therefore eventually triggering the Snapshot GC mechanism. Initial value for ops_threshold is 50.

Note that right now each update generates a snapshot in order to generate the downstream operation. That's why if snapshot_threshold is bigger than ops_thresold the Operation GC mechanism will never be triggered. 



Well, we had lengthy discussion on this which was triggered by Marc.
When a client update is submitted, we need to do some form of type checking before the message/op is forwarded to the other layers.

	Annette


On 15.10.2014, at 17:24, Alejandro Zlatko Tomsic <notifications@github.com> wrote:

> In src/clocksi_materializer.erl:
> 
> >                              update_snapshot(Type,
> >                                              NewSnapshot,
> >                                              SnapshotTime,
> >                                              Rest,
> >                                              TxId);
> > -                        {error, Reason} ->
> > -                            {error, Reason}
> > -                    end
> > +                        {Update, Actor} ->
> > +                            case Type:update(Update, Actor, Snapshot) of
> I have not modified that. I don’t think we have reached an agreement on what to do in such cases, or did we? Alejandro Z. Tomsic aletomsic@gmail.com
> …
> —
> Reply to this email directly or view it on GitHub.
>