anchor.diff:  open_writer_fd(false, FileName) ->
     {ok, Fd} = file:open(FileName, [write, read, raw, binary]),
     %% read two bytes instead of 1
  -  case file:pread(Fd, 0, 2) of
  -    {ok, <<_Version:8>>} ->
  -      %% only the fist version byte was written
  -      %% re-open it as a new to ensure latest version
  -      ok = file:close(Fd),
  -      open_writer_fd(true, FileName);
  -    {ok, <<Version:8, _:8>>} ->
  -      %% more than the version byte
  -      {ok, Position} = file:position(Fd, eof),
  -      %% Hopefully, this assertion never fails,
  -      %% In case it happens, add a function to resect the corrupted tail.
  -      0 = (Position - 1) rem file_entry_bytes(Version), %% assert
  -      {Version, Fd}
  -  end.
  +  {ok, <<Version:8>>} = file:read(Fd, 1),
  +  %% more than the version byte
  +  {ok, Position} = file:position(Fd, eof),
  +  %% Hopefully, this assertion never fails,
  +  %% In case it happens, add a function to resect the corrupted tail.
  +  0 = (Position - 1) rem file_entry_bytes(Version), %% assert
  +  {Version, Fd}.
   
   %% @private Get per-version file entry bytes.
   -spec file_entry_bytes(logvsn()) -> bytecnt().
  
positive.code: -spec switch(dirname(), index(), logid()) -> index().
  switch(Dir, #idx{fd = Fd} = Idx, NextLogId) ->
    NewSegId = NextLogId,
    {?LOGVSN, NewFd} = open_writer_fd(_IsNew = true, mk_name(Dir, NewSegId)),
    ok = file_sync_close(Fd),
    Idx#idx{segid = NewSegId, fd = NewFd}.
  
  %% @doc Switch to a new log segment, append new index entry.
  
negative.code:     file:close(Fd)
    end.
  
  %% @doc Delete given log entry (logid) from index.
  %% Return new index.
  %% NB! Refuse to delete the first log entry of each segment (i.e. when segid = logid).
  %% @end
  -spec delete_from_cache(index() | cache(), logid()) -> cache() | index().
  delete_from_cache(#idx{tid = Tid} = Idx, LogId) ->
    Tid = delete_from_cache(Tid, LogId),
    Idx;
  delete_from_cache(Tid, LogId) ->
    LatestLogId = get_latest_logid(Tid),
    case LogId =:= LatestLogId of
      true ->
        false; %% never delete the latest to keep a correect boundary check
      false ->
        case ets:lookup(Tid, LogId) of
          [] ->
            false; %% either out of range, or already deleted
          [?ETS_ENTRY(SegId, SegId, _Pos)] ->
            false; %% refuse to delete
          [?ETS_ENTRY(_SegId, LogId, _Pos)] ->
            ets:delete(Tid, LogId)
        end
    end,
    Tid.
  
  %%%*_ PRIVATE FUNCTIONS ========================================================
  
  %% @private Scan the index file to locate the log position in segment file
  