anchor.diff:      terminate/2,
       code_change/3
   ]).
  +%% Private spawn exports
  +-export([
  +         buffer_converter/2
  +        ]).
   
   -record(state, { 
       root,
  
positive.code:     {ok, RolloverSize} = application:get_env(merge_index, buffer_rollover_size),
      case mi_buffer:filesize(CurrentBuffer) > RolloverSize of
          true ->
              #state { root=Root, next_id=NextID } = NewState,
              
              %% Close the buffer filehandle. Needs to be done in the owner process.
              mi_buffer:close_filehandle(CurrentBuffer),
              Pid = self(),
              
              spawn_link(fun() ->
                  %% Calculate the segment filename, open the segment, and convert.
                  SNum  = get_id_number(mi_buffer:filename(CurrentBuffer)),
                  SName = join(Root, "segment." ++ integer_to_list(SNum)),
                  set_deleteme_flag(SName),
                  SegmentWO = mi_segment:open_write(SName),
                  mi_segment:from_buffer(CurrentBuffer, SegmentWO),
                  gen_server:call(Pid, {buffer_to_segment, CurrentBuffer, SegmentWO}, infinity)
              end),
              
              %% Create a new empty buffer...
              BName = join(NewState, "buffer." ++ integer_to_list(NextID)),
  
negative.code:         segments = Segments,
          next_id  = NextID,
          scheduled_compaction = false,
          is_compacting = false,
          buffer_converter = Converter
      },
  
      %% Return.
      {ok, State}.
  
  %% Return {Buffers, Segments}, after cleaning up/repairing any partially merged buffers.
  read_buf_and_seg(Root) ->
      %% Delete any files that have a ?DELETEME_FLAG flag. This means that
      %% the system stopped before proper cleanup.
      io:format("Cleaning up...~n"),
      F1 = fun(Filename) ->
          Basename = filename:basename(Filename, ?DELETEME_FLAG),
          Basename1 = filename:join(Root, Basename ++ ".*"),
          io:format("Deleting '~s'~n", [Basename1]),
          io:format("~p~n", [filelib:wildcard(Basename1)]),
  