Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: sync/syncable/directory.h

Issue 11441026: [Sync] Add support for loading, updating and querying delete journals in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sync/syncable/directory.cc » ('j') | sync/syncable/directory.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/directory.h
diff --git a/sync/syncable/directory.h b/sync/syncable/directory.h
index 42475305c2952ee7608194050e7e0c5e301e8cb7..6e17b46a356f306aa3190663fc96a838f233217a 100644
--- a/sync/syncable/directory.h
+++ b/sync/syncable/directory.h
@@ -17,6 +17,7 @@
#include "sync/syncable/entry_kernel.h"
#include "sync/syncable/metahandle_set.h"
#include "sync/syncable/scoped_kernel_lock.h"
+#include "sync/syncable/syncable-inl.h"
namespace syncer {
@@ -114,13 +115,14 @@ enum UnlinkReason {
class EntryKernelLessByMetaHandle {
public:
- inline bool operator()(const EntryKernel& a,
- const EntryKernel& b) const {
- return a.ref(META_HANDLE) < b.ref(META_HANDLE);
+ inline bool operator()(const EntryKernel* a,
+ const EntryKernel* b) const {
+ return a->ref(META_HANDLE) < b->ref(META_HANDLE);
}
};
-typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet;
+typedef std::set<const EntryKernel*, EntryKernelLessByMetaHandle>
+ EntryKernelSet;
enum InvariantCheckLevel {
OFF = 0, // No checking.
@@ -138,6 +140,7 @@ class Directory {
friend class ScopedKernelUnlock;
friend class WriteTransaction;
friend class SyncableDirectoryTest;
+ FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals);
FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
TakeSnapshotGetsAllDirtyHandlesTest);
FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
@@ -212,6 +215,8 @@ class Directory {
PersistedKernelInfo kernel_info;
EntryKernelSet dirty_metas;
MetahandleSet metahandles_to_purge;
+ EntryKernelSet delete_journals;
+ MetahandleSet delete_journals_to_purge;
};
// Does not take ownership of |encryptor|.
@@ -314,6 +319,29 @@ class Directory {
const tracked_objects::Location& location,
const std::string & message);
+ // Add/remove |entry| to/from |delete_journals_| according to its
+ // SERVER_IS_DEL field and |was_deleted|.
+ void UpdateDeleteJournalForServerDelete(BaseTransaction* trans,
+ bool was_deleted,
+ const EntryKernel& entry);
+
+ // Return entries of specified type in |delete_journals_|. This should be
+ // called ONCE in model association. |deleted_entries| can be used to
+ // detect deleted sync data that's not persisted in native model to
+ // prevent back-from-dead problem. |deleted_entries| are only valid during
+ // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to
+ // enable periodically saving/clearing of delete journals of |type| because
+ // new journals added later are not needed until next model association.
+ void GetDeleteJournals(BaseTransaction* trans, ModelType type,
+ EntryKernelSet* deleted_entries);
+
+ // Purge entries of specified type in |delete_journals_| if their handles are
+ // in |to_purge|. This should be called after model association and
+ // |to_purge| should contain handles of the entries whose deletions are
+ // confirmed in native model.
+ void PurgeDeleteJournals(BaseTransaction* trans,
+ const MetahandleSet& to_purge);
+
protected: // for friends, mainly used by Entry constructors
virtual EntryKernel* GetEntryByHandle(int64 handle);
virtual EntryKernel* GetEntryByHandle(int64 metahandle,
@@ -591,6 +619,16 @@ class Directory {
// The transaction observer.
const WeakHandle<TransactionObserver> transaction_observer;
+
+ // Contains deleted entries that may not be persisted in native models. And
+ // in case of unrecoverable error, all purged entries are moved here for
+ // bookkeeping to prevent back-from-dead entries that are deleted elsewhere
+ // when sync's down.
+ IdsIndex* delete_journals_;
+
+ // Contains meta handles of deleted entries that have been persisted or
+ // undeleted, thus can be removed from database.
+ MetahandleSet* const delete_journals_to_purge_;
};
// Helper method used to do searches on |parent_id_child_index|.
@@ -623,6 +661,9 @@ class Directory {
EntryKernel* GetPossibleFirstChild(
const ScopedKernelLock& lock, const Id& parent_id);
+ // Return true if delete journals of |type| are maintained.
+ static bool IsDeleteJournalEnabled(ModelType type);
+
Kernel* kernel_;
scoped_ptr<DirectoryBackingStore> store_;
@@ -635,6 +676,10 @@ class Directory {
NigoriHandler* const nigori_handler_;
Cryptographer* const cryptographer_;
+ // Delete journals of these types can be cleared from memory after being
+ // saved to database.
+ ModelTypeSet passive_delete_journal_types_;
+
InvariantCheckLevel invariant_check_level_;
};
« no previous file with comments | « no previous file | sync/syncable/directory.cc » ('j') | sync/syncable/directory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698