anchor.diff:              exit({open_db_failed, Error})
       end.
   
  -spawn_vbucket_compactor(BucketName, {_, DbName} = VBucketAndDb, Options) ->
  +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),
  +              ensure_can_db_compact(Db, SizeInfo),
   
                 ?log_info("Compacting ~p", [DbName]),
   
  
positive.code:              round(FileSize * (NumVBuckets / NumSamples))}
      end.
  
  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),
      SpaceRequired = space_required(DataSize),
  
      {ok, DbDir} = ns_storage_conf:this_node_dbdir(),
  
negative.code:                           couch_db:close(Db)
                        end,
  
                    {VDataSize, VFileSize} = db_size_info(DbInfo),
                    {AccDataSize + VDataSize, AccFileSize + VFileSize}
            end, {0, 0}, SampleVBucketDbs),
  
  