anchor.diff:  
   
   %% @doc Generate a suitable name for the Mnesia table.
  -table_name(Node, Bucket, Period) ->
  +table(Node, Bucket, Period) ->
       list_to_atom(lists:flatten(io_lib:format("~s-~s-~s-~s",
                                                [?MODULE_STRING,
                                                 Node, Bucket, Period]))).
  +
  +
  +%% @doc Truncate a timestamp to the nearest multiple of N seconds.
  +trunc_ts(TS, N) ->
  +    TS - (TS rem (N*1000)).
   
   
   %% @doc Truncate the given table to the last N records.
  
positive.code: 
  
  handle_info({stats, Bucket, Sample}, State = #state{bucket=Bucket}) ->
      Tab = table_name(node(), Bucket, minute),
      {atomic, ok} = mnesia:transaction(fun () -> mnesia:write(Tab, Sample, write) end),
      gen_event:notify(ns_stats_event, {sample_archived, Bucket, Sample}),
      {noreply, State};
  handle_info({sample_archived, _, _}, State) ->
      {noreply, State};
  handle_info({truncate, Period, N}, #state{bucket=Bucket} = State) ->
      Tab = table_name(node(), Bucket, Period),
      truncate(Tab, N),
      {noreply, State};
  handle_info({cascade, Prev, Period, Step}, #state{bucket=Bucket} = State) ->
  
negative.code:     list_to_tuple([stat_entry, TS | List]).
  
  
  %% @doc Resample the stats in a table. Only reads the necessary number of rows.
  resample(Tab, Step, N) ->
      {atomic, Result} = mnesia:transaction(
                           fun () ->
                                   TS = mnesia:last(Tab),
                                   resample(Tab, Step, TS, trunc_ts(TS, Step), [],
                                            [], N)
                           end),
      Result.
  
  
  resample(_, _, TS, _, Acc, [], N) when TS == '$end_of_table'; N == 0 ->
      Acc;
  resample(_, _, _, _, Acc, _, 0)  ->
      Acc;
  resample(_, _, '$end_of_table', T, Acc, Chunk, _) ->
      [avg(T, Chunk)|Acc];
  resample(Tab, Step, TS, T, Acc, Chunk, N) ->
      T1 = trunc_ts(TS, Step),
      [Rec] = mnesia:read(Tab, TS),
      Prev = mnesia:prev(Tab, TS),
      case T of
          T1 ->
              resample(Tab, Step, Prev, T1, Acc, [Rec|Chunk], N);
          _ ->
              resample(Tab, Step, Prev, T1, [avg(T, Chunk)|Acc], [], N-1)
      end.
  
  
  %% @doc Generate a suitable name for the per-bucket gen_server.
  