anchor.diff:      end.
   
   delete_by_channel(ChannelId) when is_integer(ChannelId) ->
  +    Ids = lookup_ids_by_channel(ChannelId),
       [ ets:delete(?TOKEN_TAB, Id)
  -      || #token_idx{id = Id} <- lookup_ids_by_channel(ChannelId) ],
  -    ets:delete(?CHAN_TOKEN_TAB, ChannelId).
  +      || Id <- Ids ],
  +    [ ets:delete(?CHAN_TOKEN_TAB, index_key(ChannelId, Id))
  +      || Id <- Ids ],
  +    ok.
   
   lookup_ids_by_channel(ChannelId) when is_integer(ChannelId) ->
  -    try
  -        ets:lookup_element(?CHAN_TOKEN_TAB, ChannelId, #token_idx.id)
  -    catch
  -        error:badarg ->
  -            []
  -    end.
  +    ets:select(?CHAN_TOKEN_TAB,
  +               [{#token_idx{key = {ChannelId, '$1'}},[],['$1']}]).
   
   index_rec(#token{id = Id, channel_id = Chan}) ->
  -    #token_idx{channel_id = Chan, id = Id}.
  +    index_rec(Chan, Id).
  +
  +index_rec(Chan, Id) ->
  +    #token_idx{key = index_key(Chan, Id) }.
  +
  +index_key(Chan, Id) ->
  +    {Chan, Id}.
   
   sel_pat() ->
  -    ets:fun2ms(fun (#token{channel_id = C, id = I}) -> {C, I} end).
  +    ets:fun2ms(fun (#token{channel_id = C, id = I}) ->
  +                       {C, I}
  +               end).
   
   reindex_tokens() ->
       Step = logplex_app:config(ets_token_reindex_step_size),
  
positive.code: 
  delete(Token = #token{id = Id}) ->
      ets:delete(?TOKEN_TAB, Id),
      ets:delete_object(?CHAN_TOKEN_TAB, index_rec(Token)).
  
  delete_by_id(Id) ->
      case lookup(Id) of
  
negative.code:     ets:new(?TOKEN_TAB, [named_table, public, set, {keypos, #token.id},
                           {read_concurrency, true},
                           {write_concurrency, true}]),
      ets:new(?CHAN_TOKEN_TAB, [named_table, public, ordered_set,
                                {keypos, #token_idx.key},
                                {read_concurrency, true},
                                {write_concurrency, true}]).
  
  