couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch commit: updated refs/heads/windsor-merge-tmp to 5da8b42
Date Fri, 22 Aug 2014 11:12:09 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/windsor-merge-tmp [created] 5da8b4280


Merge CouchDB's idea of data_size

This paches dbcore to include the CouchDB notion of data sizes which is
defined as the size of all live data in a database file. This number is
useful for deciding when to compact databases.

Technically speaking this measure is lacking a bit of information
because it does not currently account for headers, security objects, or
purged document information.

The new sizes are named slightly differently than either the CouchDB
version or the Cloudant version. The new names are:

     file - Total number of bytes in the file
     active - Active bytes in the current MVCC snapshot
     external - Theoretical bytes to store user data uncompressed

BugzId: 27061


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/5da8b428
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/5da8b428
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/5da8b428

Branch: refs/heads/windsor-merge-tmp
Commit: 5da8b42808f71aacbf8b94c5a6756e7bf263a584
Parents: 6d3e5b8
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Jan 28 17:43:10 2014 -0600
Committer: Robert Newson <rnewson@apache.org>
Committed: Fri Aug 22 12:05:21 2014 +0100

----------------------------------------------------------------------
 include/couch_db.hrl |  4 ++--
 src/couch_att.erl    |  2 +-
 src/couch_db.erl     | 47 +++++++++++++++++++++++++++--------------------
 3 files changed, 30 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/5da8b428/include/couch_db.hrl
----------------------------------------------------------------------
diff --git a/include/couch_db.hrl b/include/couch_db.hrl
index 8bb44a0..50eeefc 100644
--- a/include/couch_db.hrl
+++ b/include/couch_db.hrl
@@ -63,7 +63,7 @@
     update_seq = 0,
     deleted = false,
     rev_tree = [],
-    leafs_size = 0
+    sizes = {0, 0}
 }).
 
 -record(httpd, {
@@ -204,6 +204,6 @@
     deleted,
     ptr,
     seq,
-    size = nil
+    sizes = {0, 0}
 }).
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/5da8b428/src/couch_att.erl
----------------------------------------------------------------------
diff --git a/src/couch_att.erl b/src/couch_att.erl
index 232bb60..128b9d2 100644
--- a/src/couch_att.erl
+++ b/src/couch_att.erl
@@ -287,7 +287,7 @@ disk_info(ActiveFd, Atts) ->
                 [{_, Pos}, AttLen] = fetch([data, att_len], Att),
                 {Pos, AttLen}
             end, Atts),
-            {ok, Tuples, Info};
+            {ok, Tuples, lists:usort(Info)};
         true ->
             ?LOG_ERROR("MISMATCH: ~p ; ~p~n", [ActiveFd, Atts]),
             file_mismatch

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/5da8b428/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index bd250ef..cb225fc 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -325,8 +325,10 @@ get_db_info(Db) ->
         seq_tree = SeqBtree,
         local_tree = LocalBtree
     } = Db,
-    {ok, Size} = couch_file:bytes(Fd),
+    {ok, FileSize} = couch_file:bytes(Fd),
     {ok, DbReduction} = couch_btree:full_reduce(IdBtree),
+    {ActiveSize0, ExternalSize} = element(3, DbReduction),
+    ActiveSize = active_size(Db, ActiveSize0),
     DiskVersion = couch_db_header:disk_version(Header),
     Uuid = case get_uuid(Db) of
         undefined -> null;
@@ -343,8 +345,14 @@ get_db_info(Db) ->
         {update_seq, SeqNum},
         {purge_seq, couch_db:get_purge_seq(Db)},
         {compact_running, Compactor/=nil},
-        {disk_size, Size},
-        {data_size, db_data_size(DbReduction, [SeqBtree, IdBtree, LocalBtree])},
+        {disk_size, FileSize}, % legacy
+        {other, {[{data_size, ActiveSize}]}}, % legacy
+        {data_size, ActiveSize}, % legacy
+        {sizes, {[
+            {file, FileSize},
+            {active, ActiveSize},
+            {external, ExternalSize}
+        ]}},
         {instance_start_time, StartTime},
         {disk_format_version, DiskVersion},
         {committed_update_seq, CommittedUpdateSeq},
@@ -353,23 +361,22 @@ get_db_info(Db) ->
         ],
     {ok, InfoList}.
 
-db_data_size({_Count, _DelCount}, _Trees) ->
-    % pre 1.2 format, upgraded on compaction
-    null;
-db_data_size({_Count, _DelCount, nil}, _Trees) ->
-    null;
-db_data_size({_Count, _DelCount, DocAndAttsSize}, Trees) ->
-    sum_tree_sizes(DocAndAttsSize, Trees).
-
-sum_tree_sizes(Acc, []) ->
-    Acc;
-sum_tree_sizes(Acc, [T | Rest]) ->
-    case couch_btree:size(T) of
-    nil ->
-        null;
-    Sz ->
-        sum_tree_sizes(Acc + Sz, Rest)
-    end.
+active_size(#db{}=Db, DocActiveSize) ->
+    Trees = [
+        Db#db.id_tree,
+        Db#db.seq_tree,
+        Db#db.local_tree
+    ],
+    lists:foldl(fun(T, Acc) ->
+        case couch_btree:size(T) of
+            _ when Acc == null ->
+                null;
+            undefined ->
+                null;
+            Size ->
+                Acc + Size
+        end
+    end, DocActiveSize, Trees).
 
 get_design_docs(#db{name = <<"shards/", _:18/binary, DbName/binary>>}) ->
     {_, Ref} = spawn_monitor(fun() -> exit(fabric:design_docs(DbName)) end),


Mime
View raw message