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

Side by Side Diff: sync/syncable/directory_backing_store.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
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_BACKING_STORE_H_ 5 #ifndef SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_
6 #define SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ 6 #define SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
12 #include "sql/connection.h" 12 #include "sql/connection.h"
13 #include "sql/statement.h" 13 #include "sql/statement.h"
14 #include "sync/internal_api/public/base/model_type.h" 14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/syncable/dir_open_result.h" 15 #include "sync/syncable/dir_open_result.h"
16 #include "sync/syncable/directory.h" 16 #include "sync/syncable/directory.h"
17 #include "sync/syncable/metahandle_set.h" 17 #include "sync/syncable/metahandle_set.h"
18 18
19 namespace sync_pb { 19 namespace sync_pb {
20 class EntitySpecifics; 20 class EntitySpecifics;
21 } 21 }
22 22
23 namespace syncer { 23 namespace syncer {
24 namespace syncable { 24 namespace syncable {
25 25
26 struct ColumnSpec; 26 struct ColumnSpec;
27 typedef Directory::MetahandlesIndex MetahandlesIndex; 27 typedef Directory::MetahandlesIndex MetahandlesIndex;
28 typedef Directory::IdsIndex IdsIndex;
28 29
29 // Interface that provides persistence for a syncable::Directory object. You can 30 // Interface that provides persistence for a syncable::Directory object. You can
30 // load all the persisted data to prime a syncable::Directory on startup by 31 // load all the persisted data to prime a syncable::Directory on startup by
31 // invoking Load. The only other thing you (or more correctly, a Directory) can 32 // invoking Load. The only other thing you (or more correctly, a Directory) can
32 // do here is save any changes that have occurred since calling Load, which can 33 // do here is save any changes that have occurred since calling Load, which can
33 // be done periodically as often as desired. 34 // be done periodically as often as desired.
34 // 35 //
35 // The DirectoryBackingStore will own an sqlite lock on its database for most of 36 // The DirectoryBackingStore will own an sqlite lock on its database for most of
36 // its lifetime. You must not have two DirectoryBackingStore objects accessing 37 // its lifetime. You must not have two DirectoryBackingStore objects accessing
37 // the database simultaneously. Because the lock exists at the database level, 38 // the database simultaneously. Because the lock exists at the database level,
(...skipping 11 matching lines...) Expand all
49 // Loads and drops all currently persisted meta entries into |entry_bucket| 50 // Loads and drops all currently persisted meta entries into |entry_bucket|
50 // and loads appropriate persisted kernel info into |info_bucket|. 51 // and loads appropriate persisted kernel info into |info_bucket|.
51 // 52 //
52 // This function can perform some cleanup tasks behind the scenes. It will 53 // This function can perform some cleanup tasks behind the scenes. It will
53 // clean up unused entries from the database and migrate to the latest 54 // clean up unused entries from the database and migrate to the latest
54 // database version. The caller can safely ignore these details. 55 // database version. The caller can safely ignore these details.
55 // 56 //
56 // NOTE: On success (return value of OPENED), the buckets are populated with 57 // NOTE: On success (return value of OPENED), the buckets are populated with
57 // newly allocated items, meaning ownership is bestowed upon the caller. 58 // newly allocated items, meaning ownership is bestowed upon the caller.
58 virtual DirOpenResult Load(MetahandlesIndex* entry_bucket, 59 virtual DirOpenResult Load(MetahandlesIndex* entry_bucket,
60 IdsIndex* delete_journals,
59 Directory::KernelLoadInfo* kernel_load_info) = 0; 61 Directory::KernelLoadInfo* kernel_load_info) = 0;
60 62
61 // Updates the on-disk store with the input |snapshot| as a database 63 // Updates the on-disk store with the input |snapshot| as a database
62 // transaction. Does NOT open any syncable transactions as this would cause 64 // transaction. Does NOT open any syncable transactions as this would cause
63 // opening transactions elsewhere to block on synchronous I/O. 65 // opening transactions elsewhere to block on synchronous I/O.
64 // DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread 66 // DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread
65 // calls SaveChanges *must* be the thread that owns/destroys |this|. 67 // calls SaveChanges *must* be the thread that owns/destroys |this|.
66 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot); 68 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot);
67 69
68 protected: 70 protected:
69 // For test classes. 71 // For test classes.
70 DirectoryBackingStore(const std::string& dir_name, 72 DirectoryBackingStore(const std::string& dir_name,
71 sql::Connection* connection); 73 sql::Connection* connection);
72 74
73 // General Directory initialization and load helpers. 75 // General Directory initialization and load helpers.
74 bool InitializeTables(); 76 bool InitializeTables();
75 bool CreateTables(); 77 bool CreateTables();
76 78
77 // Create 'share_info' or 'temp_share_info' depending on value of 79 // Create 'share_info' or 'temp_share_info' depending on value of
78 // is_temporary. Returns an sqlite 80 // is_temporary. Returns an sqlite
79 bool CreateShareInfoTable(bool is_temporary); 81 bool CreateShareInfoTable(bool is_temporary);
80 82
81 bool CreateShareInfoTableVersion71(bool is_temporary); 83 bool CreateShareInfoTableVersion71(bool is_temporary);
82 // Create 'metas' or 'temp_metas' depending on value of is_temporary. 84 // Create 'metas' or 'temp_metas' depending on value of is_temporary. Also
85 // create a 'deleted_metas' table using same schema.
83 bool CreateMetasTable(bool is_temporary); 86 bool CreateMetasTable(bool is_temporary);
84 bool CreateModelsTable(); 87 bool CreateModelsTable();
85 bool CreateV71ModelsTable(); 88 bool CreateV71ModelsTable();
86 89
87 // We don't need to load any synced and applied deleted entries, we can 90 // We don't need to load any synced and applied deleted entries, we can
88 // in fact just purge them forever on startup. 91 // in fact just purge them forever on startup.
89 bool DropDeletedEntries(); 92 bool DropDeletedEntries();
90 // Drops a table if it exists, harmless if the table did not already exist. 93 // Drops a table if it exists, harmless if the table did not already exist.
91 bool SafeDropTable(const char* table_name); 94 bool SafeDropTable(const char* table_name);
92 95
93 // Load helpers for entries and attributes. 96 // Load helpers for entries and attributes.
94 bool LoadEntries(MetahandlesIndex* entry_bucket); 97 bool LoadEntries(MetahandlesIndex* entry_bucket);
98 bool LoadDeleteJournals(IdsIndex* delete_journals);
95 bool LoadInfo(Directory::KernelLoadInfo* info); 99 bool LoadInfo(Directory::KernelLoadInfo* info);
96 100
97 // Save/update helpers for entries. Return false if sqlite commit fails. 101 // Save/update helpers for entries. Return false if sqlite commit fails.
98 bool SaveEntryToDB(const EntryKernel& entry); 102 static bool SaveEntryToDB(sql::Statement* save_statement,
103 const EntryKernel& entry);
99 bool SaveNewEntryToDB(const EntryKernel& entry); 104 bool SaveNewEntryToDB(const EntryKernel& entry);
100 bool UpdateEntryToDB(const EntryKernel& entry); 105 bool UpdateEntryToDB(const EntryKernel& entry);
101 106
102 DirOpenResult DoLoad(MetahandlesIndex* entry_bucket, 107 DirOpenResult DoLoad(MetahandlesIndex* entry_bucket,
103 Directory::KernelLoadInfo* kernel_load_info); 108 Directory::KernelLoadInfo* kernel_load_info);
104 109
105 // Close save_dbhandle_. Broken out for testing. 110 // Close save_dbhandle_. Broken out for testing.
106 void EndSave(); 111 void EndSave();
107 112
108 // Removes each entry whose metahandle is in |handles| from the database. 113 // Removes each entry whose metahandle is in |handles| from metas table if
114 // |meta_delete| is true, or from delete journals table if it's false.
109 // Does synchronous I/O. Returns false on error. 115 // Does synchronous I/O. Returns false on error.
110 bool DeleteEntries(const MetahandleSet& handles); 116 bool DeleteEntries(bool meta_delete, const MetahandleSet& handles);
tim (not reviewing) 2012/12/13 23:41:30 Can you make this an enum with DELETE_FROM_METAS a
haitaol1 2012/12/14 19:22:38 Done.
111 117
112 // Drop all tables in preparation for reinitialization. 118 // Drop all tables in preparation for reinitialization.
113 void DropAllTables(); 119 void DropAllTables();
114 120
115 // Serialization helpers for ModelType. These convert between 121 // Serialization helpers for ModelType. These convert between
116 // the ModelType enum and the values we persist in the database to identify 122 // the ModelType enum and the values we persist in the database to identify
117 // a model. We persist a default instance of the specifics protobuf as the 123 // a model. We persist a default instance of the specifics protobuf as the
118 // ID, rather than the enum value. 124 // ID, rather than the enum value.
119 static ModelType ModelIdToModelTypeEnum(const void* data, int length); 125 static ModelType ModelIdToModelTypeEnum(const void* data, int length);
120 static std::string ModelTypeEnumToModelId(ModelType model_type); 126 static std::string ModelTypeEnumToModelId(ModelType model_type);
(...skipping 30 matching lines...) Expand all
151 bool MigrateVersion73To74(); 157 bool MigrateVersion73To74();
152 bool MigrateVersion74To75(); 158 bool MigrateVersion74To75();
153 bool MigrateVersion75To76(); 159 bool MigrateVersion75To76();
154 bool MigrateVersion76To77(); 160 bool MigrateVersion76To77();
155 bool MigrateVersion77To78(); 161 bool MigrateVersion77To78();
156 bool MigrateVersion78To79(); 162 bool MigrateVersion78To79();
157 bool MigrateVersion79To80(); 163 bool MigrateVersion79To80();
158 bool MigrateVersion80To81(); 164 bool MigrateVersion80To81();
159 bool MigrateVersion81To82(); 165 bool MigrateVersion81To82();
160 bool MigrateVersion82To83(); 166 bool MigrateVersion82To83();
167 bool MigrateVersion83To84();
161 168
162 scoped_ptr<sql::Connection> db_; 169 scoped_ptr<sql::Connection> db_;
163 sql::Statement save_entry_statement_; 170 sql::Statement save_meta_statment_;
171 sql::Statement save_delete_journal_statment_;
164 std::string dir_name_; 172 std::string dir_name_;
165 173
166 // Set to true if migration left some old columns around that need to be 174 // Set to true if migration left some old columns around that need to be
167 // discarded. 175 // discarded.
168 bool needs_column_refresh_; 176 bool needs_column_refresh_;
169 177
178 private:
179 // Helper function for loading entries from specified table.
180 template<class T>
181 bool LoadEntriesInternal(const std::string& table, T* bucket);
182
183 // Prepares |save_statement| for saving entries in |table|.
184 void PrepareSaveEntryStatement(const std::string& table,
185 sql::Statement* save_statement);
186
170 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore); 187 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore);
171 }; 188 };
172 189
173 } // namespace syncable 190 } // namespace syncable
174 } // namespace syncer 191 } // namespace syncer
175 192
176 #endif // SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ 193 #endif // SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698