 
 exports.Flat = class Flat extends Base
 
+  constructor : () ->
+    @flat_lock = new Lock
+
   make_kvstore_key : ({type,key}) -> 
     type or= key[-2...]
     "kv:" + super { type, key }

      err = new E.LookupNotFoundError "No lookup available for #{name}"

##=======================================================================

  make_lookup_name : ({type,name}) ->
    "lo:" + super { type, name }

  _get_reverse_lookup : ({name}, cb) ->
    await @_get { key : ("r" + name) }, defer err, rlookup
    if err? and (err instanceof E.NotFoundError)
      err = null
      rlookup = []
    cb err, rlookup

  _put_reverse_lookup : ({name, list}, cb) ->
    await @_put { key : ("r" + name), value : list }, defer err
    cb err

  _link : ({key, name}, cb) ->
    await @flat_lock.acquire defer()
    esc = make_esc cb, "Flat::_link"
    await @_get_reverse_lookup { name }, defer err, list
    unless err?
      list.push name
      await @_put_reverse_lookup { name, list }, defer err
    unless err?
      await @_put { key : name, value : key }, defer err
    @flat_lock.release() 
    cb err

  _unlink : ({name}, cb) ->
