anchor.diff:      list_to_tuple([stat_entry, TS | List]).
   
   
  -%% @doc Pass received stats to the archiver.
  -received(Pid, Stats) ->
  -    gen_server:cast(Pid, {stats, Stats}).
  +%% @doc Truncate the table if necessary.
  +maybe_truncate(#state{table=Tab, samples_since_truncate=?TRUNC_FREQ} = State) ->
  +    truncate(Tab, 60),
  +    State#state{samples_since_truncate=1};
  +maybe_truncate(#state{samples_since_truncate=N} = State) when N < ?TRUNC_FREQ ->
  +    State#state{samples_since_truncate=N+1}.
   
   
   %% @doc Convert a stat entry to a list of values.
  
positive.code:     {TS, L}.
  
  
  %% @doc Truncate a timestamp to a multiple of the given number of seconds.
  ts_trunc(Resolution, TS) ->
      {MegaSecs, Secs, _} = TS,
      MegaSecs * 1000000 + trunc(Secs / Resolution) * Resolution.
  
  
  %% @doc Generate a suitable name for the per-bucket gen_server.
  server(Bucket) ->
      list_to_atom(?MODULE_STRING ++ "-" ++ Bucket).
  
  %% @doc Generate a suitable name for the Mnesia table.
  table_name(Bucket) ->
      list_to_atom(lists:flatten(io_lib:format("~s-~s-~s", [?MODULE_STRING,
                                                            node(), Bucket]))).
  
negative.code: 
  init(Bucket) ->
      TableName = create_table(Bucket),
      ns_pubsub:subscribe(ns_stats_event),
      {ok, #state{bucket=Bucket, table=TableName}}.
  
  
  handle_call(unhandled, unhandled, unhandled) ->
      unhandled.
  
  
  handle_cast(unhandled, unhandled) ->
      unhandled.
  
  
  handle_info({stats, Bucket, Sample}, State = #state{bucket=Bucket, table=Tab}) ->
      {atomic, ok} = mnesia:transaction(fun () -> mnesia:write(Tab, Sample, write) end),
      gen_event:notify(ns_stats_event, {sample_archived, Bucket, Sample}),
      {noreply, maybe_truncate(State)};
  handle_info({sample_archived, _, _}, State) ->
      {noreply, State}.
  
  
  terminate(_Reason, _State) ->
  