anchor.diff:  
       file_needs_compaction(DataSize, FileSize, FragThreshold, MinFileSize).
   
  +get_master_db_size_info(BucketName, VBucketAndDb) ->
  +    Db = open_db_or_fail(BucketName, VBucketAndDb),
  +
  +    try
  +        {ok, DbInfo} = couch_db:get_db_info(Db),
  +
  +        {proplists:get_value(data_size, DbInfo, 0),
  +         proplists:get_value(disk_size, DbInfo)}
  +    after
  +        couch_db:close(Db)
  +    end.
  +
  +get_db_size_info(Bucket, VBucket) ->
  +    {ok, Props} = ns_memcached:get_vbucket_details_stats(Bucket, VBucket),
  +
  +    {list_to_integer(proplists:get_value("db_data_size", Props)),
  +     list_to_integer(proplists:get_value("db_file_size", Props))}.
  +
   maybe_compact_vbucket(BucketName, {VBucket, DbName} = VBucketAndDb,
                         Config, Force, Options) ->
  -    Db = open_db_or_fail(BucketName, VBucketAndDb),
  -
  -    SizeInfo = try
  -                   {ok, DbInfo} = couch_db:get_db_info(Db),
  -                   db_size_info(DbInfo)
  -               after
  -                   couch_db:close(Db)
  +    Bucket = binary_to_list(BucketName),
  +
  +    SizeInfo = case VBucket of
  +                   master ->
  +                       get_master_db_size_info(BucketName, VBucketAndDb);
  +                   _ ->
  +                       get_db_size_info(Bucket, VBucket)
                  end,
   
       case Force orelse vbucket_needs_compaction(SizeInfo, Config) of
  
positive.code:             check_fragmentation(FragThreshold, Frag, FragSize)
      end.
  
  aggregated_size_info(SampleVBucketDbs, NumVBuckets) ->
      NumSamples = length(SampleVBucketDbs),
  
      {DataSize, FileSize} =
          lists:foldl(
            fun ({_VBucket, DbName}, {AccDataSize, AccFileSize}) ->
                    {ok, Db} = couch_db:open_int(DbName, []),
  
                    %% unfortunately I can't just bind this inside try block
                    %% because compiler (seemingly mistakenly) thinks that this
                    %% is unsafe
                    DbInfo =
                        try
                            {ok, Info} = couch_db:get_db_info(Db),
                            Info
                        after
                            couch_db:close(Db)
                        end,
  
                    {VDataSize, VFileSize} = db_size_info(DbInfo),
                    {AccDataSize + VDataSize, AccFileSize + VFileSize}
            end, {0, 0}, SampleVBucketDbs),
  
      %% rarely our sample selection routine can return zero samples;
      %% we need to handle it
      case NumSamples of
          0 ->
              {0, 0};
          _ ->
              {round(DataSize * (NumVBuckets / NumSamples)),
               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),
  
negative.code:                                     [BucketName]),
                            true;
                        false ->
                            bucket_needs_compaction(BucketName, Total - 1, Config)
                    end,
  
                DoCompact orelse exit(normal),
  
                ?log_info("Compacting databases for bucket ~s", [BucketName]),
  
                TriggerType = case Force of
                                  true ->
                                      manual;
  