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

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

Issue 1016563005: Increase page size for SyncData DB from 4K to maximum supported 32K (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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "sync/syncable/directory_backing_store.h" 5 #include "sync/syncable/directory_backing_store.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/field_trial.h"
13 #include "base/rand_util.h" 14 #include "base/rand_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
17 #include "sql/connection.h" 18 #include "sql/connection.h"
18 #include "sql/statement.h" 19 #include "sql/statement.h"
19 #include "sql/transaction.h" 20 #include "sql/transaction.h"
20 #include "sync/internal_api/public/base/node_ordinal.h" 21 #include "sync/internal_api/public/base/node_ordinal.h"
21 #include "sync/protocol/bookmark_specifics.pb.h" 22 #include "sync/protocol/bookmark_specifics.pb.h"
22 #include "sync/protocol/sync.pb.h" 23 #include "sync/protocol/sync.pb.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } // namespace 169 } // namespace
169 170
170 /////////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////////
171 // DirectoryBackingStore implementation. 172 // DirectoryBackingStore implementation.
172 173
173 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name) 174 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name)
174 : db_(new sql::Connection()), 175 : db_(new sql::Connection()),
175 dir_name_(dir_name), 176 dir_name_(dir_name),
176 needs_column_refresh_(false) { 177 needs_column_refresh_(false) {
177 db_->set_histogram_tag("SyncDirectory"); 178 db_->set_histogram_tag("SyncDirectory");
178 db_->set_page_size(4096);
179 db_->set_cache_size(32); 179 db_->set_cache_size(32);
180 databasePageSize_ = IsSyncBackingDatabase32KEnabled() ? 32768 : 4096;
181 db_->set_page_size(databasePageSize_);
180 } 182 }
181 183
182 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name, 184 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name,
183 sql::Connection* db) 185 sql::Connection* db)
184 : db_(db), 186 : db_(db),
185 dir_name_(dir_name), 187 dir_name_(dir_name),
186 needs_column_refresh_(false) { 188 needs_column_refresh_(false) {
187 } 189 }
188 190
189 DirectoryBackingStore::~DirectoryBackingStore() { 191 DirectoryBackingStore::~DirectoryBackingStore() {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 return false; 303 return false;
302 DCHECK_EQ(db_->GetLastChangeCount(), 1); 304 DCHECK_EQ(db_->GetLastChangeCount(), 1);
303 s2.Reset(true); 305 s2.Reset(true);
304 } 306 }
305 } 307 }
306 308
307 return transaction.Commit(); 309 return transaction.Commit();
308 } 310 }
309 311
310 bool DirectoryBackingStore::InitializeTables() { 312 bool DirectoryBackingStore::InitializeTables() {
313 int page_size = 0;
314 if (IsSyncBackingDatabase32KEnabled() && GetDatabasePageSize(&page_size) &&
315 page_size == 4096) {
316 IncreasePageSizeTo32K();
317 }
311 sql::Transaction transaction(db_.get()); 318 sql::Transaction transaction(db_.get());
312 if (!transaction.Begin()) 319 if (!transaction.Begin())
313 return false; 320 return false;
314 321
315 int version_on_disk = GetVersion(); 322 int version_on_disk = GetVersion();
316 323
317 // Upgrade from version 67. Version 67 was widely distributed as the original 324 // Upgrade from version 67. Version 67 was widely distributed as the original
318 // Bookmark Sync release. Version 68 removed unique naming. 325 // Bookmark Sync release. Version 68 removed unique naming.
319 if (version_on_disk == 67) { 326 if (version_on_disk == 67) {
320 if (MigrateVersion67To68()) 327 if (MigrateVersion67To68())
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 query.append(ColumnName(i)); 1592 query.append(ColumnName(i));
1586 values.append("?"); 1593 values.append("?");
1587 } 1594 }
1588 query.append(" ) "); 1595 query.append(" ) ");
1589 values.append(" )"); 1596 values.append(" )");
1590 query.append(values); 1597 query.append(values);
1591 save_statement->Assign(db_->GetUniqueStatement( 1598 save_statement->Assign(db_->GetUniqueStatement(
1592 base::StringPrintf(query.c_str(), "metas").c_str())); 1599 base::StringPrintf(query.c_str(), "metas").c_str()));
1593 } 1600 }
1594 1601
1602 // Get page size for the database.
1603 bool DirectoryBackingStore::GetDatabasePageSize(int* page_size) {
1604 sql::Statement s(db_->GetUniqueStatement("PRAGMA page_size"));
1605 if (!s.Step())
1606 return false;
1607 *page_size = s.ColumnInt(0);
1608 return true;
1609 }
1610
1611 bool DirectoryBackingStore::IsSyncBackingDatabase32KEnabled() {
1612 const std::string group_name =
1613 base::FieldTrialList::FindFullName("SyncBackingDatabase32K");
1614 return group_name == "Enabled";
1615 }
1616
1617 bool DirectoryBackingStore::IncreasePageSizeTo32K() {
1618 if (!db_->Execute("PRAGMA page_size=32768;") || !Vacuum()) {
1619 return false;
1620 }
1621 return true;
1622 }
1623
1624 bool DirectoryBackingStore::Vacuum() {
1625 DCHECK_EQ(db_->transaction_nesting(), 0);
1626 if (!db_->Execute("VACUUM;")) {
1627 return false;
1628 }
1629 return true;
1630 }
1631
1595 } // namespace syncable 1632 } // namespace syncable
1596 } // namespace syncer 1633 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698