From a61f2eb606d20aa4f790fe927cf31c5f96754527 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Wed, 24 Nov 2010 16:11:39 +0000 Subject: Merged revision 1038665 from trunk: Replicator DB: added _replication_state_time (a unix timestamp value) to replication documents. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1038666 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_doc.erl | 3 +++ src/couchdb/couch_rep.erl | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index b014de2d..7c64b8a9 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -256,6 +256,9 @@ transfer_fields([{<<"_deleted_conflicts">>, _} | Rest], Doc) -> transfer_fields([{<<"_replication_state">>, _} = Field | Rest], #doc{body=Fields} = Doc) -> transfer_fields(Rest, Doc#doc{body=[Field|Fields]}); +transfer_fields([{<<"_replication_state_time">>, _} = Field | Rest], + #doc{body=Fields} = Doc) -> + transfer_fields(Rest, Doc#doc{body=[Field|Fields]}); transfer_fields([{<<"_replication_id">>, _} = Field | Rest], #doc{body=Fields} = Doc) -> transfer_fields(Rest, Doc#doc{body=[Field|Fields]}); diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl index 663fd838..1b998666 100644 --- a/src/couchdb/couch_rep.erl +++ b/src/couchdb/couch_rep.erl @@ -854,8 +854,15 @@ update_rep_doc({Props} = _RepDoc, KVs) -> update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) -> NewRepDocBody = lists:foldl( - fun({K, _V} = KV, Body) -> - lists:keystore(K, 1, Body, KV) + fun({<<"_replication_state">> = K, _V} = KV, Body) -> + Body1 = lists:keystore(K, 1, Body, KV), + {Mega, Secs, _} = erlang:now(), + UnixTime = Mega * 1000000 + Secs, + lists:keystore( + <<"_replication_state_time">>, 1, + Body1, {<<"_replication_state_time">>, UnixTime}); + ({K, _V} = KV, Body) -> + lists:keystore(K, 1, Body, KV) end, RepDocBody, KVs -- cgit v1.2.3