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

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 if (IsSyncBackingDatabase32KEnabled()) {
stanisc 2015/03/18 15:10:45 Consider ternary "? :" operator here instead of "i
Gang Wu 2015/05/21 18:38:17 Done.
181 databasePageSize = 32768;
182 } else {
183 databasePageSize = 4096;
184 }
185 db_->set_page_size(databasePageSize);
180 } 186 }
181 187
182 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name, 188 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name,
183 sql::Connection* db) 189 sql::Connection* db)
184 : db_(db), 190 : db_(db),
185 dir_name_(dir_name), 191 dir_name_(dir_name),
186 needs_column_refresh_(false) { 192 needs_column_refresh_(false) {
187 } 193 }
188 194
189 DirectoryBackingStore::~DirectoryBackingStore() { 195 DirectoryBackingStore::~DirectoryBackingStore() {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 return false; 307 return false;
302 DCHECK_EQ(db_->GetLastChangeCount(), 1); 308 DCHECK_EQ(db_->GetLastChangeCount(), 1);
303 s2.Reset(true); 309 s2.Reset(true);
304 } 310 }
305 } 311 }
306 312
307 return transaction.Commit(); 313 return transaction.Commit();
308 } 314 }
309 315
310 bool DirectoryBackingStore::InitializeTables() { 316 bool DirectoryBackingStore::InitializeTables() {
317 int page_size = 0;
318 if (IsSyncBackingDatabase32KEnabled() &&
319 GetDatabasePageSize(&page_size) &&
320 page_size == 4096) {
321 IncreasePageSizeTo32K();
322 }
311 sql::Transaction transaction(db_.get()); 323 sql::Transaction transaction(db_.get());
312 if (!transaction.Begin()) 324 if (!transaction.Begin())
313 return false; 325 return false;
314 326
315 int version_on_disk = GetVersion(); 327 int version_on_disk = GetVersion();
316 328
317 // Upgrade from version 67. Version 67 was widely distributed as the original 329 // Upgrade from version 67. Version 67 was widely distributed as the original
318 // Bookmark Sync release. Version 68 removed unique naming. 330 // Bookmark Sync release. Version 68 removed unique naming.
319 if (version_on_disk == 67) { 331 if (version_on_disk == 67) {
320 if (MigrateVersion67To68()) 332 if (MigrateVersion67To68())
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 query.append(ColumnName(i)); 1598 query.append(ColumnName(i));
1587 values.append("?"); 1599 values.append("?");
1588 } 1600 }
1589 query.append(" ) "); 1601 query.append(" ) ");
1590 values.append(" )"); 1602 values.append(" )");
1591 query.append(values); 1603 query.append(values);
1592 save_statement->Assign(db_->GetUniqueStatement( 1604 save_statement->Assign(db_->GetUniqueStatement(
1593 base::StringPrintf(query.c_str(), "metas").c_str())); 1605 base::StringPrintf(query.c_str(), "metas").c_str()));
1594 } 1606 }
1595 1607
1608 // Get page size for the database.
1609 bool DirectoryBackingStore::GetDatabasePageSize(int* page_size) {
1610 sql::Statement s(db_->GetUniqueStatement("PRAGMA page_size"));
1611 if (!s.Step())
1612 return false;
1613 *page_size = s.ColumnInt(0);
1614 return true;
1615 }
1616
1617 bool DirectoryBackingStore::IsSyncBackingDatabase32KEnabled() {
1618 const std::string group_name =
1619 base::FieldTrialList::FindFullName("SyncBackingDatabase32K");
1620 return group_name == "Enabled";
1621 }
1622
1623 bool DirectoryBackingStore::IncreasePageSizeTo32K() {
1624 if (!db_->Execute("PRAGMA page_size=32768;") ||
1625 !Vacuum()) {
1626 return false;
1627 }
1628 return true;
1629 }
1630
1631 bool DirectoryBackingStore::Vacuum() {
1632 DCHECK_EQ(db_->transaction_nesting(), 0);
1633 if (!db_->Execute("VACUUM;")) {
1634 return false;
1635 }
1636 return true;
1637 }
1638
1596 } // namespace syncable 1639 } // namespace syncable
1597 } // namespace syncer 1640 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698