couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [12/50] couch commit: updated refs/heads/master to 9d0ac7d
Date Thu, 28 Aug 2014 12:11:48 GMT
Remember compacted_seq

BugzID: 22917


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

Branch: refs/heads/master
Commit: 58381aadc8e579a7e2f18209194e1ce61cb016f8
Parents: 5776751
Author: Robert Newson <robert.newson@cloudant.com>
Authored: Mon Sep 9 21:40:33 2013 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Aug 28 13:00:00 2014 +0100

----------------------------------------------------------------------
 src/couch_db.erl         | 10 +++++++++-
 src/couch_db_header.erl  | 25 +++++++++++++++++++++----
 src/couch_db_updater.erl |  5 ++++-
 3 files changed, 34 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/58381aad/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 4adb128..836b468 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -21,7 +21,7 @@
 -export([open_doc/2,open_doc/3,open_doc_revs/4]).
 -export([set_revs_limit/2,get_revs_limit/1]).
 -export([get_missing_revs/2,name/1,get_update_seq/1,get_committed_update_seq/1]).
--export([get_uuid/1, get_epochs/1]).
+-export([get_uuid/1, get_epochs/1, get_compacted_seq/1]).
 -export([enum_docs/4,enum_docs_since/5]).
 -export([enum_docs_since_reduce_to_count/1,enum_docs_reduce_to_count/1]).
 -export([increment_update_seq/1,get_purge_seq/1,purge_docs/2,get_last_purged/1]).
@@ -304,6 +304,9 @@ get_uuid(#db{}=Db) ->
 get_epochs(#db{}=Db) ->
     couch_db_header:epochs(Db#db.header).
 
+get_compacted_seq(#db{}=Db) ->
+    couch_db_header:compacted_seq(Db#db.header).
+
 get_db_info(Db) ->
     #db{fd=Fd,
         header=Header,
@@ -323,6 +326,10 @@ get_db_info(Db) ->
         undefined -> null;
         Uuid0 -> Uuid0
     end,
+    CompactedSeq = case get_compacted_seq(Db) of
+        undefined -> null;
+        Else1 -> Else1
+    end,
     InfoList = [
         {db_name, Name},
         {doc_count, element(1, DbReduction)},
@@ -335,6 +342,7 @@ get_db_info(Db) ->
         {instance_start_time, StartTime},
         {disk_format_version, DiskVersion},
         {committed_update_seq, CommittedUpdateSeq},
+        {compacted_seq, CompactedSeq},
         {uuid, Uuid}
         ],
     {ok, InfoList}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/58381aad/src/couch_db_header.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_header.erl b/src/couch_db_header.erl
index c23cf38..b7c93d9 100644
--- a/src/couch_db_header.erl
+++ b/src/couch_db_header.erl
@@ -32,7 +32,8 @@
     security_ptr/1,
     revs_limit/1,
     uuid/1,
-    epochs/1
+    epochs/1,
+    compacted_seq/1
 ]).
 
 
@@ -60,7 +61,8 @@
     security_ptr = nil,
     revs_limit = 1000,
     uuid,
-    epochs
+    epochs,
+    compacted_seq
 }).
 
 
@@ -75,7 +77,8 @@ from(Header0) ->
     Header = upgrade(Header0),
     #db_header{
         uuid = Header#db_header.uuid,
-        epochs = Header#db_header.epochs
+        epochs = Header#db_header.epochs,
+        compacted_seq = Header#db_header.compacted_seq
     }.
 
 
@@ -93,7 +96,8 @@ upgrade(Header) ->
         fun upgrade_tuple/1,
         fun upgrade_disk_version/1,
         fun upgrade_uuid/1,
-        fun upgrade_epochs/1
+        fun upgrade_epochs/1,
+        fun upgrade_compacted_seq/1
     ],
     lists:foldl(fun(F, HdrAcc) ->
         F(HdrAcc)
@@ -154,6 +158,10 @@ epochs(Header) ->
     get_field(Header, epochs).
 
 
+compacted_seq(Header) ->
+    get_field(Header, compacted_seq).
+
+
 get_field(Header, Field) ->
     Idx = index(Field),
     case Idx > tuple_size(Header) of
@@ -267,6 +275,15 @@ remove_dup_epochs([{N1, S1}, {N2, S2} | Rest]) ->
     remove_dup_epochs([{N1, S1} | remove_dup_epochs([{N2, S2} | Rest])]).
 
 
+upgrade_compacted_seq(#db_header{}=Header) ->
+    case Header#db_header.compacted_seq of
+        undefined ->
+            Header#db_header{compacted_seq=0};
+        _ ->
+            Header
+    end.
+
+
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/58381aad/src/couch_db_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_updater.erl b/src/couch_db_updater.erl
index e01df83..6979256 100644
--- a/src/couch_db_updater.erl
+++ b/src/couch_db_updater.erl
@@ -212,7 +212,10 @@ handle_cast(start_compact, Db) ->
     end;
 handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
     {ok, NewFd} = couch_file:open(CompactFilepath),
-    {ok, NewHeader} = couch_file:read_header(NewFd),
+    {ok, NewHeader0} = couch_file:read_header(NewFd),
+    NewHeader = couch_db_header:set(NewHeader0, [
+        {compacted_seq, Db#db.update_seq}
+    ]),
     #db{update_seq=NewSeq} = NewDb =
         init_db(Db#db.name, Filepath, NewFd, NewHeader, Db#db.options),
     unlink(NewFd),


Mime
View raw message