anchor.diff:               round(FileSize * (NumVBuckets / NumSamples))}
       end.
   
  +db_size_info(DbInfo) ->
  +    FileSize = proplists:get_value(disk_size, DbInfo),
  +    DataSize = proplists:get_value(data_size, DbInfo, 0),
  +
  +    {DataSize, FileSize}.
  +
   check_fragmentation({FragLimit, FragSizeLimit}, Frag, FragSize) ->
       true = is_integer(FragLimit),
       true = is_integer(FragSizeLimit),
   
       (Frag >= FragLimit) orelse (FragSize >= FragSizeLimit).
   
  -ensure_can_db_compact(Db) ->
  -    {ok, DbInfo} = couch_db:get_db_info(Db),
  -    DataSize = proplists:get_value(data_size, DbInfo, 0),
  +ensure_can_db_compact(Db, {DataSize, _}) ->
       SpaceRequired = space_required(DataSize),
   
       {ok, DbDir} = ns_storage_conf:this_node_dbdir(),
  
positive.code:                           couch_db:close(Db)
                        end,
  
                    VFileSize = proplists:get_value(disk_size, DbInfo),
                    VDataSize = proplists:get_value(data_size, DbInfo, 0),
                    {AccDataSize + VDataSize, AccFileSize + VFileSize}
            end, {0, 0}, SampleVBucketDbs),
  
  
negative.code:             exit({open_db_failed, Error})
      end.
  
  vbucket_needs_compaction({DataSize, FileSize}, Config) ->
      #config{daemon=#daemon_config{min_file_size=MinFileSize},
              db_fragmentation=FragThreshold} = Config,
  
      file_needs_compaction(DataSize, FileSize, FragThreshold, MinFileSize).
  
  spawn_vbucket_compactor(BucketName, {_, DbName} = VBucketAndDb,
                          Config, Force, Options) ->
      Parent = self(),
  
      proc_lib:spawn_link(
        fun () ->
                Db = open_db_or_fail(BucketName, VBucketAndDb),
                {ok, DbInfo} = couch_db:get_db_info(Db),
                SizeInfo = db_size_info(DbInfo),
  
                case Force orelse vbucket_needs_compaction(SizeInfo, Config) of
                    true ->
                        ok;
                    false ->
                        exit(normal)
                end,
  
                %% effectful
                ensure_can_db_compact(Db, SizeInfo),
  
                ?log_info("Compacting ~p", [DbName]),
  
  