anchor.diff:           get_meta/2, update_meta/3]).	 
   
   % @type riak_ring(). The opaque data type used for partition ownership.
  --record(hstate, {nodename, % the Node responsible for this hstate
  -		 vclock, % for this hstate object, entries are {Node, Ctr}
  -		 ring, % chash ring of {IndexAsInt, Node} mappings
  -                 meta}). % dict of cluster-wide other data
  -                         % (primarily bucket N-value, etc)
  +-record(hstate, {
  +    nodename, % the Node responsible for this hstate
  +	vclock,   % for this hstate object, entries are {Node, Ctr}
  +	ring,     % chash ring of {IndexAsInt, Node} mappings
  +    meta      % dict of cluster-wide other data (primarily bucket N-value, etc)
  +}). 
  +
  +% @type meta_entry(). Record for each entry in #hstate.meta
  +-record(meta_entry, {
  +    value,    % The value stored under this entry
  +    lastmod   % The last modified time of this entry, 
  +              % from calendar:datetime_to_gregorian_seconds(calendar:universal_time()), 
  +}).
   
   % @doc This is used only when this node is creating a brand new cluster.
   % @spec fresh() -> hstate()
  
positive.code: merge_meta(M1,M2) ->
      dict:merge(fun(_,D1,D2) -> pick_val(D1,D2) end, M1, M2).
  
  pick_val(D1,D2) ->
      {ok, L1} = dict:find(lastmod, D1),
      {ok, L2} = dict:find(lastmod, D2),
      case L1 > L2 of
          true -> D1;
          false -> D2
      end.
  
  % @doc Return a value from the cluster metadata dict
  % @spec get_meta(Key :: term(), State :: hstate()) -> 
  
negative.code: get_meta(Key, State) -> 
      case dict:find(Key, State#hstate.meta) of
          error -> undefined;
          {ok, M} -> {ok, M#meta_entry.value}
      end.
  
                  
  % @doc Set a key in the cluster metadata dict
  % @spec update_meta(Key :: term(), Val :: term(), State :: hstate()) ->
  %     State :: hstate() | error
  update_meta(Key, Val, State) ->
      M = #meta_entry { 
          lastmod = calendar:datetime_to_gregorian_seconds(calendar:universal_time()),
          value = Val
      },    
      VClock = vclock:increment(State#hstate.nodename, State#hstate.vclock),
      State#hstate{vclock=VClock, meta=dict:store(Key, M, State#hstate.meta)}.
  
  
  sequence_test() ->
      I1 = 365375409332725729550921208179070754913983135744,
  