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

Side by Side Diff: sync/syncable/directory.cc

Issue 1008103002: Sync: Avoid 3 passes over SyncDarta DB when loading the directory from the disk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "sync/syncable/directory.h" 5 #include "sync/syncable/directory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { 70 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) {
71 } 71 }
72 72
73 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() { 73 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {
74 STLDeleteElements(&dirty_metas); 74 STLDeleteElements(&dirty_metas);
75 STLDeleteElements(&delete_journals); 75 STLDeleteElements(&delete_journals);
76 } 76 }
77 77
78 Directory::Kernel::Kernel( 78 Directory::Kernel::Kernel(
79 const std::string& name, 79 const std::string& name,
80 const KernelLoadInfo& info, DirectoryChangeDelegate* delegate, 80 const KernelLoadInfo& info,
81 DirectoryChangeDelegate* delegate,
81 const WeakHandle<TransactionObserver>& transaction_observer) 82 const WeakHandle<TransactionObserver>& transaction_observer)
82 : next_write_transaction_id(0), 83 : next_write_transaction_id(0),
83 name(name), 84 name(name),
84 info_status(Directory::KERNEL_SHARE_INFO_VALID), 85 info_status(Directory::KERNEL_SHARE_INFO_VALID),
85 persisted_info(info.kernel_info), 86 persisted_info(info.kernel_info),
86 cache_guid(info.cache_guid), 87 cache_guid(info.cache_guid),
87 next_metahandle(info.max_metahandle + 1), 88 next_metahandle(info.max_metahandle + 1),
88 delegate(delegate), 89 delegate(delegate),
89 transaction_observer(transaction_observer) { 90 transaction_observer(transaction_observer) {
90 DCHECK(delegate); 91 DCHECK(delegate);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 DirectoryChangeDelegate* delegate, 172 DirectoryChangeDelegate* delegate,
172 const WeakHandle<TransactionObserver>& 173 const WeakHandle<TransactionObserver>&
173 transaction_observer) { 174 transaction_observer) {
174 KernelLoadInfo info; 175 KernelLoadInfo info;
175 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) 176 // Temporary indices before kernel_ initialized in case Load fails. We 0(1)
176 // swap these later. 177 // swap these later.
177 Directory::MetahandlesMap tmp_handles_map; 178 Directory::MetahandlesMap tmp_handles_map;
178 179
179 // Avoids mem leaks on failure. Harmlessly deletes the empty hash map after 180 // Avoids mem leaks on failure. Harmlessly deletes the empty hash map after
180 // the swap in the success case. 181 // the swap in the success case.
181 STLValueDeleter<Directory::MetahandlesMap> deleter(&tmp_handles_map); 182 STLValueDeleter<MetahandlesMap> deleter(&tmp_handles_map);
182 183
183 JournalIndex delete_journals; 184 JournalIndex delete_journals;
185 MetahandleSet metahandles_to_purge;
184 186
185 DirOpenResult result = 187 DirOpenResult result = store_->Load(&tmp_handles_map, &delete_journals,
186 store_->Load(&tmp_handles_map, &delete_journals, &info); 188 &metahandles_to_purge, &info);
187 if (OPENED != result) 189 if (OPENED != result)
188 return result; 190 return result;
189 191
190 kernel_ = new Kernel(name, info, delegate, transaction_observer); 192 kernel_ = new Kernel(name, info, delegate, transaction_observer);
191 delete_journal_.reset(new DeleteJournal(&delete_journals)); 193 delete_journal_.reset(new DeleteJournal(&delete_journals));
192 InitializeIndices(&tmp_handles_map); 194 InitializeIndices(&tmp_handles_map);
193 195
194 // Write back the share info to reserve some space in 'next_id'. This will 196 // Write back the share info to reserve some space in 'next_id'. This will
195 // prevent local ID reuse in the case of an early crash. See the comments in 197 // prevent local ID reuse in the case of an early crash. See the comments in
196 // TakeSnapshotForSaveChanges() or crbug.com/142987 for more information. 198 // TakeSnapshotForSaveChanges() or crbug.com/142987 for more information.
197 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 199 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
200
201 kernel_->metahandles_to_purge.swap(metahandles_to_purge);
198 if (!SaveChanges()) 202 if (!SaveChanges())
199 return FAILED_INITIAL_WRITE; 203 return FAILED_INITIAL_WRITE;
200 204
201 return OPENED; 205 return OPENED;
202 } 206 }
203 207
204 DeleteJournal* Directory::delete_journal() { 208 DeleteJournal* Directory::delete_journal() {
205 DCHECK(delete_journal_.get()); 209 DCHECK(delete_journal_.get());
206 return delete_journal_.get(); 210 return delete_journal_.get();
207 } 211 }
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). 1549 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203).
1546 std::set_difference(not_on_server_id_set.begin(), 1550 std::set_difference(not_on_server_id_set.begin(),
1547 not_on_server_id_set.end(), 1551 not_on_server_id_set.end(),
1548 on_server_id_set.begin(), 1552 on_server_id_set.begin(),
1549 on_server_id_set.end(), 1553 on_server_id_set.end(),
1550 std::inserter(*id_set, id_set->end())); 1554 std::inserter(*id_set, id_set->end()));
1551 } 1555 }
1552 1556
1553 } // namespace syncable 1557 } // namespace syncable
1554 } // namespace syncer 1558 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698