anchor.diff:                      [DbName, Reason]);
               {Doc} ->
                   Shards = mem3_util:build_ordered_shards(DbName, Doc),
  -                Msg = {cache_insert_change, DbName, Shards, Seq},
  +                IdleTimeout = config:get_integer(
  +                        "mem3", "writer_idle_timeout", 30000),
  +                Writer = spawn_shard_writer(DbName, Shards, IdleTimeout),
  +                ets:insert(?OPENERS, {DbName, Writer}),
  +                Msg = {cache_insert_change, DbName, Writer, Seq},
                   gen_server:cast(?MODULE, Msg),
                   [create_if_missing(mem3:name(S)) || S
                       <- Shards, mem3:node(S) =:= node()]
  
positive.code:         end
      end.
  
  cache_insert(#st{cur_size=Cur}=St, DbName, Shards) ->
      NewATime = now(),
      true = ets:delete(?SHARDS, DbName),
      true = ets:insert(?SHARDS, Shards),
      case ets:lookup(?DBS, DbName) of
          [{DbName, ATime}] ->
              true = ets:delete(?ATIMES, ATime),
  
negative.code:     true = ets:delete_all_objects(?ATIMES),
      St#st{cur_size=0}.
  
  maybe_spawn_shard_writer(DbName, Shards) ->
      case ets:member(?OPENERS, DbName) of
          true ->
              ignore;
          false ->
              spawn_shard_writer(DbName, Shards)
      end.
  
  spawn_shard_writer(DbName, Shards) ->
      erlang:spawn(fun() -> shard_writer(DbName, Shards) end).
  
  shard_writer(DbName, Shards) ->
      try
          receive
              write ->
                  true = ets:insert(?SHARDS, Shards);
              cancel ->
                  ok
          after ?WRITE_IDLE_TIMEOUT ->
              ok
          end
      after
          true = ets:delete_object(?OPENERS, {DbName, self()})
      end.
  
  flush_write(DbName, Writer) ->
      Ref = erlang:monitor(process, Writer),
      Writer ! write,
      receive
          {'DOWN', Ref, _, _, normal} ->
              ok;
          {'DOWN', Ref, _, _, Error} ->
              erlang:exit({mem3_shards_bad_write, Error})
      after ?WRITE_TIMEOUT ->
          erlang:exit({mem3_shards_write_timeout, DbName})
      end.
  
  filter_shards_by_name(Name, Shards) ->
      filter_shards_by_name(Name, [], Shards).
  
  