Commits

benoitc  committed 8526d80

add modified time of a db in db headers. first bits, need to handle the
upgrade.

Eg.

{"db_name":"testdb","doc_count":0,"doc_del_count":1,"update_seq":3,"modified":"1253540241479553","purge_seq":0,"compact_running":false,"disk_size":12398,"instance_start_time":"1253540874651249","disk_format_version":5}

  • Participants
  • Parent commits bde3b68
  • Branches modified

Comments (0)

Files changed (3)

File src/couchdb/couch_db.erl

         header=#db_header{disk_version=DiskVersion},
         compactor_pid=Compactor,
         update_seq=SeqNum,
+        modified=ModifiedTime,
         name=Name,
         fulldocinfo_by_id_btree=FullDocBtree,
         instance_start_time=StartTime} = Db,
         {doc_count, Count},
         {doc_del_count, DelCount},
         {update_seq, SeqNum},
+        {modified, ModifiedTime},
         {purge_seq, couch_db:get_purge_seq(Db)},
         {compact_running, Compactor/=nil},
         {disk_size, Size},

File src/couchdb/couch_db.hrl

 % if the disk revision is incremented, then new upgrade logic will need to be
 % added to couch_db_updater:init_db.
 
--define(LATEST_DISK_VERSION, 4).
+-define(LATEST_DISK_VERSION, 5).
 
 -record(db_header,
     {disk_version = ?LATEST_DISK_VERSION,
      update_seq = 0,
+     modified = 0,
      unused = 0,
      fulldocinfo_by_id_btree_state = nil,
      docinfo_by_seq_btree_state = nil,
     docinfo_by_seq_btree,
     local_docs_btree,
     update_seq,
+    modified,
     name,
     filepath,
     validate_doc_funs = [],

File src/couchdb/couch_db_updater.erl

 handle_call(full_commit, _From,  Db) ->
     {reply, ok, commit_data(Db)}; % commit the data and return ok
 handle_call(increment_update_seq, _From, Db) ->
-    Db2 = commit_data(Db#db{update_seq=Db#db.update_seq+1}),
+    Db2 = commit_data(Db#db{update_seq=Db#db.update_seq+1,modified=modified_time()}),
     ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
     couch_db_update_notifier:notify({updated, Db#db.name}),
     {reply, {ok, Db2#db.update_seq}, Db2};
 handle_call({set_admins, NewAdmins}, _From, Db) ->
     {ok, Ptr} = couch_file:append_term(Db#db.fd, NewAdmins),
     Db2 = commit_data(Db#db{admins=NewAdmins, admins_ptr=Ptr,
-            update_seq=Db#db.update_seq+1}),
+            update_seq=Db#db.update_seq+1,
+            modified=modified_time()}),
     ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
     {reply, ok, Db2};
 
 handle_call({set_revs_limit, Limit}, _From, Db) ->
     Db2 = commit_data(Db#db{revs_limit=Limit,
-            update_seq=Db#db.update_seq+1}),
+            update_seq=Db#db.update_seq+1,
+            modified=modified_time()}),
     ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
     {reply, ok, Db2};
 
             fulldocinfo_by_id_btree = DocInfoByIdBTree2,
             docinfo_by_seq_btree = DocInfoBySeqBTree2,
             update_seq = NewSeq + 1,
+            modified = modified_time(),
             header=Header#db_header{purge_seq=PurgeSeq+1, purged_docs=Pointer}}),
 
     ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
     Header1 = simple_upgrade_record(Header0, #db_header{}),
     Header =
     case element(2, Header1) of
-    1 -> Header1#db_header{unused = 0}; % 0.9
-    2 -> Header1#db_header{unused = 0}; % post 0.9 and pre 0.10
-    3 -> Header1; % post 0.9 and pre 0.10
+    1 -> Header1#db_header{unused = 0, modified = 0}; % 0.9
+    2 -> Header1#db_header{unused = 0, modified = 0}; % post 0.9 and pre 0.10
+    3 -> Header1#db_header{modified = 0}; % post 0.9 and pre 0.10
+    4 -> Header1#db_header{modified = 0}; % post 0.10 and pre 0.11
     ?LATEST_DISK_VERSION -> Header1;
     _ -> throw({database_disk_version_error, "Incorrect disk header version"})
     end,
         local_docs_btree = LocalDocsBtree,
         committed_update_seq = Header#db_header.update_seq,
         update_seq = Header#db_header.update_seq,
+        modified = Header#db_header.modified,
         name = DbName,
         filepath = Filepath,
         admins = Admins,
     % and the indexes
     {ok, DocInfoByIdBTree2} = couch_btree:add_remove(DocInfoByIdBTree, IndexFullDocInfos, []),
     {ok, DocInfoBySeqBTree2} = couch_btree:add_remove(DocInfoBySeqBTree, IndexDocInfos, RemoveSeqs),
-
+            
     Db3 = Db2#db{
         fulldocinfo_by_id_btree = DocInfoByIdBTree2,
         docinfo_by_seq_btree = DocInfoBySeqBTree2,
-        update_seq = NewSeq},
+        update_seq = NewSeq,
+        modified = modified_time()},
 
     % Check if we just updated any design documents, and update the validation
     % funs if we did.
 db_to_header(Db, Header) ->
     Header#db_header{
         update_seq = Db#db.update_seq,
+        modified = Db#db.modified,
         docinfo_by_seq_btree_state = couch_btree:get_state(Db#db.docinfo_by_seq_btree),
         fulldocinfo_by_id_btree_state = couch_btree:get_state(Db#db.fulldocinfo_by_id_btree),
         local_docs_btree_state = couch_btree:get_state(Db#db.local_docs_btree),
         if TotalCopied rem 1000 == 0 ->
             NewDb2 = copy_docs(Db, AccNewDb, lists:reverse([DocInfo | AccUncopied]), Retry),
             if TotalCopied rem 10000 == 0 ->
-                {ok, {commit_data(NewDb2#db{update_seq=Seq}), [], TotalCopied + 1}};
+                {ok, {commit_data(NewDb2#db{update_seq=Seq,modified=modified_time()}), [], TotalCopied + 1}};
             true ->
-                {ok, {NewDb2#db{update_seq=Seq}, [], TotalCopied + 1}}
+                {ok, {NewDb2#db{update_seq=Seq,modified=modified_time()}, [], TotalCopied + 1}}
             end;
         true ->
             {ok, {AccNewDb, [DocInfo | AccUncopied], TotalCopied + 1}}
         NewDb4 = NewDb3
     end,
 
-    commit_data(NewDb4#db{update_seq=Db#db.update_seq}).
+    commit_data(NewDb4#db{update_seq=Db#db.update_seq,modified=Db#db.modified}).
 
 start_copy_compact(#db{name=Name,filepath=Filepath}=Db) ->
     CompactFile = Filepath ++ ".compact",
     gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}),
     close_db(NewDb2).
 
+modified_time() ->
+    {MegaSecs, Secs, MicroSecs} = now(),
+    ?l2b(io_lib:format("~p",
+            [(MegaSecs*1000000*1000000) + (Secs*1000000) + MicroSecs])).