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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sync/syncable/directory.cc » ('j') | sync/syncable/directory.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SYNC_SYNCABLE_DIRECTORY_H_ 5 #ifndef SYNC_SYNCABLE_DIRECTORY_H_
6 #define SYNC_SYNCABLE_DIRECTORY_H_ 6 #define SYNC_SYNCABLE_DIRECTORY_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" 14 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
15 #include "sync/internal_api/public/util/weak_handle.h" 15 #include "sync/internal_api/public/util/weak_handle.h"
16 #include "sync/syncable/dir_open_result.h" 16 #include "sync/syncable/dir_open_result.h"
17 #include "sync/syncable/entry_kernel.h" 17 #include "sync/syncable/entry_kernel.h"
18 #include "sync/syncable/metahandle_set.h" 18 #include "sync/syncable/metahandle_set.h"
19 #include "sync/syncable/scoped_kernel_lock.h" 19 #include "sync/syncable/scoped_kernel_lock.h"
20 #include "sync/syncable/syncable-inl.h"
20 21
21 namespace syncer { 22 namespace syncer {
22 23
23 class Cryptographer; 24 class Cryptographer;
24 class UnrecoverableErrorHandler; 25 class UnrecoverableErrorHandler;
25 26
26 namespace syncable { 27 namespace syncable {
27 28
28 class BaseTransaction; 29 class BaseTransaction;
29 class DirectoryChangeDelegate; 30 class DirectoryChangeDelegate;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 // Reason for unlinking. 109 // Reason for unlinking.
109 enum UnlinkReason { 110 enum UnlinkReason {
110 NODE_MANIPULATION, // To be used by any operation manipulating the linked 111 NODE_MANIPULATION, // To be used by any operation manipulating the linked
111 // list. 112 // list.
112 DATA_TYPE_PURGE // To be used when purging a dataype. 113 DATA_TYPE_PURGE // To be used when purging a dataype.
113 }; 114 };
114 115
115 class EntryKernelLessByMetaHandle { 116 class EntryKernelLessByMetaHandle {
116 public: 117 public:
117 inline bool operator()(const EntryKernel& a, 118 inline bool operator()(const EntryKernel* a,
118 const EntryKernel& b) const { 119 const EntryKernel* b) const {
119 return a.ref(META_HANDLE) < b.ref(META_HANDLE); 120 return a->ref(META_HANDLE) < b->ref(META_HANDLE);
120 } 121 }
121 }; 122 };
122 123
123 typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet; 124 typedef std::set<const EntryKernel*, EntryKernelLessByMetaHandle>
125 EntryKernelSet;
124 126
125 enum InvariantCheckLevel { 127 enum InvariantCheckLevel {
126 OFF = 0, // No checking. 128 OFF = 0, // No checking.
127 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check hierarchy. 129 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check hierarchy.
128 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive. 130 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive.
129 }; 131 };
130 132
131 class Directory { 133 class Directory {
132 friend class BaseTransaction; 134 friend class BaseTransaction;
133 friend class Entry; 135 friend class Entry;
134 friend class MutableEntry; 136 friend class MutableEntry;
135 friend class ReadTransaction; 137 friend class ReadTransaction;
136 friend class ReadTransactionWithoutDB; 138 friend class ReadTransactionWithoutDB;
137 friend class ScopedKernelLock; 139 friend class ScopedKernelLock;
138 friend class ScopedKernelUnlock; 140 friend class ScopedKernelUnlock;
139 friend class WriteTransaction; 141 friend class WriteTransaction;
140 friend class SyncableDirectoryTest; 142 friend class SyncableDirectoryTest;
143 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals);
141 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, 144 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
142 TakeSnapshotGetsAllDirtyHandlesTest); 145 TakeSnapshotGetsAllDirtyHandlesTest);
143 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, 146 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
144 TakeSnapshotGetsOnlyDirtyHandlesTest); 147 TakeSnapshotGetsOnlyDirtyHandlesTest);
145 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, 148 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
146 TakeSnapshotGetsMetahandlesToPurge); 149 TakeSnapshotGetsMetahandlesToPurge);
147 150
148 public: 151 public:
149 static const FilePath::CharType kSyncDatabaseFilename[]; 152 static const FilePath::CharType kSyncDatabaseFilename[];
150 153
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // constructed and forms a consistent snapshot of what needs to be sent to 208 // constructed and forms a consistent snapshot of what needs to be sent to
206 // the backing store. 209 // the backing store.
207 struct SaveChangesSnapshot { 210 struct SaveChangesSnapshot {
208 SaveChangesSnapshot(); 211 SaveChangesSnapshot();
209 ~SaveChangesSnapshot(); 212 ~SaveChangesSnapshot();
210 213
211 KernelShareInfoStatus kernel_info_status; 214 KernelShareInfoStatus kernel_info_status;
212 PersistedKernelInfo kernel_info; 215 PersistedKernelInfo kernel_info;
213 EntryKernelSet dirty_metas; 216 EntryKernelSet dirty_metas;
214 MetahandleSet metahandles_to_purge; 217 MetahandleSet metahandles_to_purge;
218 EntryKernelSet delete_journals;
219 MetahandleSet delete_journals_to_purge;
215 }; 220 };
216 221
217 // Does not take ownership of |encryptor|. 222 // Does not take ownership of |encryptor|.
218 // |report_unrecoverable_error_function| may be NULL. 223 // |report_unrecoverable_error_function| may be NULL.
219 // Takes ownership of |store|. 224 // Takes ownership of |store|.
220 Directory( 225 Directory(
221 DirectoryBackingStore* store, 226 DirectoryBackingStore* store,
222 UnrecoverableErrorHandler* unrecoverable_error_handler, 227 UnrecoverableErrorHandler* unrecoverable_error_handler,
223 ReportUnrecoverableErrorFunction 228 ReportUnrecoverableErrorFunction
224 report_unrecoverable_error_function, 229 report_unrecoverable_error_function,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 report_unrecoverable_error_function_(); 312 report_unrecoverable_error_function_();
308 } 313 }
309 } 314 }
310 315
311 // Called to set the unrecoverable error on the directory and to propagate 316 // Called to set the unrecoverable error on the directory and to propagate
312 // the error to upper layers. 317 // the error to upper layers.
313 void OnUnrecoverableError(const BaseTransaction* trans, 318 void OnUnrecoverableError(const BaseTransaction* trans,
314 const tracked_objects::Location& location, 319 const tracked_objects::Location& location,
315 const std::string & message); 320 const std::string & message);
316 321
322 // Add/remove |entry| to/from |delete_journals_| according to its
323 // SERVER_IS_DEL field and |was_deleted|.
324 void UpdateDeleteJournals(BaseTransaction* trans, bool was_deleted,
325 const EntryKernel& entry);
326
327 // Return entries of specified type in |delete_journals_|. This should be
328 // called ONCE in model association. |deleted_entries| can be used to
329 // detect deleted sync data that's not persisted in native model to
330 // prevent back-from-dead problem. |deleted_entries| are only valid during
331 // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to
332 // enable periodically saving/clearing of delete journals of |type| because
333 // new journals added later are not needed until next model association.
334 void GetDeleteJournals(BaseTransaction* trans, ModelType type,
335 EntryKernelSet* deleted_entries);
336
337 // Purge entries of specified type in |delete_journals_| if their handles are
338 // in |to_purge|. This should be called after model association and
339 // |to_purge| should contain handles of the entries whose deletions are
340 // confirmed in native model.
341 void PurgeDeleteJournals(BaseTransaction* trans,
tim (not reviewing) 2012/12/13 23:41:30 Where is this called?
haitaol1 2012/12/14 19:22:38 It's called from delete_journal.cc in the other pa
342 const MetahandleSet& to_purge);
343
317 protected: // for friends, mainly used by Entry constructors 344 protected: // for friends, mainly used by Entry constructors
318 virtual EntryKernel* GetEntryByHandle(int64 handle); 345 virtual EntryKernel* GetEntryByHandle(int64 handle);
319 virtual EntryKernel* GetEntryByHandle(int64 metahandle, 346 virtual EntryKernel* GetEntryByHandle(int64 metahandle,
320 ScopedKernelLock* lock); 347 ScopedKernelLock* lock);
321 virtual EntryKernel* GetEntryById(const Id& id); 348 virtual EntryKernel* GetEntryById(const Id& id);
322 EntryKernel* GetEntryByServerTag(const std::string& tag); 349 EntryKernel* GetEntryByServerTag(const std::string& tag);
323 virtual EntryKernel* GetEntryByClientTag(const std::string& tag); 350 virtual EntryKernel* GetEntryByClientTag(const std::string& tag);
324 EntryKernel* GetRootEntry(); 351 EntryKernel* GetRootEntry();
325 bool ReindexId(WriteTransaction* trans, EntryKernel* const entry, 352 bool ReindexId(WriteTransaction* trans, EntryKernel* const entry,
326 const Id& new_id); 353 const Id& new_id);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 base::Lock save_changes_mutex; 611 base::Lock save_changes_mutex;
585 612
586 // The next metahandle is protected by kernel mutex. 613 // The next metahandle is protected by kernel mutex.
587 int64 next_metahandle; 614 int64 next_metahandle;
588 615
589 // The delegate for directory change events. Must not be NULL. 616 // The delegate for directory change events. Must not be NULL.
590 DirectoryChangeDelegate* const delegate; 617 DirectoryChangeDelegate* const delegate;
591 618
592 // The transaction observer. 619 // The transaction observer.
593 const WeakHandle<TransactionObserver> transaction_observer; 620 const WeakHandle<TransactionObserver> transaction_observer;
621
622 // Contains deleted entries that may not be persisted in native models. And
623 // in case of unrecoverable error, all purged entries are moved here for
624 // bookkeeping to prevent back-from-dead entries that are deleted elsewhere
625 // when sync's down.
626 IdsIndex* delete_journals_;
627
628 // Contains meta handles of deleted entries that have been persisted or
629 // undeleted, thus can be removed from database.
630 MetahandleSet* const delete_journals_to_purge_;
tim (not reviewing) 2012/12/14 20:12:38 I have one somewhat significant but honest suggest
haitaol1 2012/12/14 23:15:36 Working on it. On 2012/12/14 20:12:38, timsteele
594 }; 631 };
595 632
596 // Helper method used to do searches on |parent_id_child_index|. 633 // Helper method used to do searches on |parent_id_child_index|.
597 ParentIdChildIndex::iterator LocateInParentChildIndex( 634 ParentIdChildIndex::iterator LocateInParentChildIndex(
598 const ScopedKernelLock& lock, 635 const ScopedKernelLock& lock,
599 const Id& parent_id, 636 const Id& parent_id,
600 int64 position_in_parent, 637 int64 position_in_parent,
601 const Id& item_id_for_tiebreaking); 638 const Id& item_id_for_tiebreaking);
602 639
603 // Return an iterator to the beginning of the range of the children of 640 // Return an iterator to the beginning of the range of the children of
(...skipping 12 matching lines...) Expand all
616 void AppendChildHandles( 653 void AppendChildHandles(
617 const ScopedKernelLock& lock, 654 const ScopedKernelLock& lock,
618 const Id& parent_id, Directory::ChildHandles* result); 655 const Id& parent_id, Directory::ChildHandles* result);
619 656
620 // Return a pointer to what is probably (but not certainly) the 657 // Return a pointer to what is probably (but not certainly) the
621 // first child of |parent_id|, or NULL if |parent_id| definitely has 658 // first child of |parent_id|, or NULL if |parent_id| definitely has
622 // no children. 659 // no children.
623 EntryKernel* GetPossibleFirstChild( 660 EntryKernel* GetPossibleFirstChild(
624 const ScopedKernelLock& lock, const Id& parent_id); 661 const ScopedKernelLock& lock, const Id& parent_id);
625 662
663 // Return true if delete journals of |type| are maintained.
664 static bool IsDeleteJournalEnabled(ModelType type);
665
626 Kernel* kernel_; 666 Kernel* kernel_;
627 667
628 scoped_ptr<DirectoryBackingStore> store_; 668 scoped_ptr<DirectoryBackingStore> store_;
629 669
630 UnrecoverableErrorHandler* const unrecoverable_error_handler_; 670 UnrecoverableErrorHandler* const unrecoverable_error_handler_;
631 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; 671 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
632 bool unrecoverable_error_set_; 672 bool unrecoverable_error_set_;
633 673
634 // Not owned. 674 // Not owned.
635 NigoriHandler* const nigori_handler_; 675 NigoriHandler* const nigori_handler_;
636 Cryptographer* const cryptographer_; 676 Cryptographer* const cryptographer_;
637 677
678 // Delete journals of these types can be cleared from memory after being
679 // saved to database.
680 ModelTypeSet passive_delete_journal_types_;
681
638 InvariantCheckLevel invariant_check_level_; 682 InvariantCheckLevel invariant_check_level_;
639 }; 683 };
640 684
641 } // namespace syncable 685 } // namespace syncable
642 } // namespace syncer 686 } // namespace syncer
643 687
644 #endif // SYNC_SYNCABLE_DIRECTORY_H_ 688 #endif // SYNC_SYNCABLE_DIRECTORY_H_
OLDNEW
« 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