anchor.diff:  %% @private 
   all_frags(Bucket) when is_atom(Bucket) ->
       [atom_to_list(Bucket) ++ "-" ++ X || X <- [integer_to_list(I) || 
  -                                                  I <- lists:seq(0, ?NFRAGS-1)]].
  -
  +                                               I <- lists:seq(0, ?NFRAGS-1)]].
   %% @private
   ensure_ring(State=#state{ring=undefined}) ->
       riak_ring_manager:subscribe(self()),
  
positive.code: %% @spec put_key(riak_object:bucket(), riak_object:key()) -> ok
  %% @doc Add Key to the keylist for Bucket.
  put_key(Bucket,Key) -> 
      gen_fsm:send_event(?MODULE,{add,Bucket,Key}).
  
  %% @spec del_key(riak_object:bucket(), riak_object:key()) -> ok
  %% @doc Remove Key from the keylist for Bucket.
  del_key(Bucket,Key) -> gen_fsm:send_event(?MODULE,{del,Bucket,Key}).
  
  %% @private
  start_link() -> gen_fsm:start_link({local, ?MODULE}, ?MODULE, [], []).
  
  %% @private
  init(_) -> 
      {ok, waiting, #state{ops=dict:new(),ring=undefined}, ?FLUSH_INTERVAL}.
  
  %% @private
  waiting(timeout, State=#state{ops=Ops}) ->
      NewState = ensure_ring(State),
      do_write_all(Ops, NewState#state.ring),
      {next_state, waiting, NewState#state{ops=dict:new()}, ?FLUSH_INTERVAL};
  
  %% @private
  waiting({OpType,Bucket,Key}, State=#state{ops=Ops}) ->
      BucketFrag = lists:flatten(
                     io_lib:format("~s-~b", 
                                   [Bucket, 
                                    erlang:phash2(Key) rem ?NFRAGS])),
      NewState = ensure_ring(State),
      OpList = case dict:find(BucketFrag, Ops) of
          error -> [{OpType,Key}];
          {ok, L} -> [{OpType,Key}|L]
      end,
      case length(OpList) > ?QSIZE of
          true ->
              do_write_all(dict:store(BucketFrag, OpList, Ops), 
                           NewState#state.ring),
              {next_state,waiting,NewState#state{ops=dict:new()},?FLUSH_INTERVAL};
          false ->
              {next_state,waiting,
               NewState#state{ops=dict:store(BucketFrag,OpList,Ops)},
               ?FLUSH_INTERVAL}
      end.
  
  %% @private
  
negative.code: 
  %% @doc Management of keylists for Riak buckets.
  -module(riak_bucketkeys).
  -behavior(gen_server2).
  
  -export([put_key/2,
           del_key/2,
           get_keys/1]).
  -export([start_link/0,
           init/1,
           handle_call/3,
           handle_cast/2,
           handle_info/2,
           code_change/3,
           terminate/2]).
  
  -define(BUCK, ' bucketkeys').
  -define(QSIZE, 1000).
  -define(NFRAGS, 1024).
  -define(FLUSH_INTERVAL, 1000).
  -record(state, {ops, ring, tref}).
  
  % State.ops is a dict, keys are bucketname atoms, vals are lists of operations,
  % where operations are tuples of {Op::[add|del], riak_object:key()}
  