Directory
=========

data Version = Stable VersionRange | Tracking BranchID | Transitional
data Directory = Directory {
    directoryVersion :: Map Key Version,
    directoryBlueprint :: Blueprint,
    
    }


Procedure
=========

For all shards in the current blueprint:

    On condition:
        Blueprint designates us primary for that shard
        No overlapping masters are present in the directory
        We don’t have anything active for that shard
        Directory for this shard for every peer indicates Stable for some
            version less than or equal to our version
        We have received the directory-echo from the last blueprint from every
            peer in the blueprint's scope and the reply blueprint does not list
            any of them as primary for this shard or overlapping shards
    Do:
        Start up a broadcaster+master+listener+replier for that shard

    On condition:
        Blueprint designates us secondary for that shard
        We don't have anything active for that shard
        A master for that shard is present in the directory
    Do:
        Start up a listener+replier for that shard

    On condition:
        Blueprint designates us nothing for that shard
        We have some data for that shard
        We don't have anything active for that shard
        We have received the directory-echo from the last blueprint from every
            peer in the blueprint's scope and the reply blueprint lists them as
            secondary if our blueprint lists them as secondary

For all active broadcaster+master+listener+repliers:

    On condition:
        Blueprint does not designate us primary for that shard
        Something would react on this machine if we stopped
    Do:
        Stop the broadcaster+master+listener+replier

For all active listener+repliers:

    On condition:
        Blueprint does not designate us secondary or primary for that shard
        All secondaries mentioned in blueprint are in directory
        We have received the directory-echo from the last blueprint from every
            peer in the blueprint's scope and the reply blueprint lists them as
            secondary if our blueprint lists them as secondary
    Do:
        Stop the listener+replier

For all regions formed by taking a shard in the current blueprint and
    intersecting or subtracting regions from active components:

    On condition:
        Blueprint designates us primary for the shard
        We don’t have anything active for this region
        Directory for this region for some peer indicates Stable for some
            version greater than our version
    Do:
        Begin backfilling from that peer in that region

Procedure notes
===============

Backfills end on their own.

Listeners and repliers stop on their own if they lose contact with master.
Add some notes on reactor stuff.
Add some notes on reactor stuff.
