Commit 5e541eb3 authored by gangwu's avatar gangwu Committed by Commit bot

Increase page size for SyncData DB from 4K to maximum

supported 32K using finch experiment.

BUG=464063

Review URL: https://codereview.chromium.org/1016563005

Cr-Commit-Position: refs/heads/master@{#321529}
parent 3fcd7d84
......@@ -39,7 +39,7 @@ bool DeferredOnDiskDirectoryBackingStore::SaveChanges(
// Reopen DB on disk.
db_.reset(new sql::Connection);
db_->set_exclusive_locking();
db_->set_page_size(4096);
db_->set_page_size(databasePageSize_);
if (!db_->Open(backing_filepath_) || !InitializeTables())
return false;
......
......@@ -10,6 +10,7 @@
#include "base/base64.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
......@@ -175,8 +176,9 @@ DirectoryBackingStore::DirectoryBackingStore(const string& dir_name)
dir_name_(dir_name),
needs_column_refresh_(false) {
db_->set_histogram_tag("SyncDirectory");
db_->set_page_size(4096);
db_->set_cache_size(32);
databasePageSize_ = IsSyncBackingDatabase32KEnabled() ? 32768 : 4096;
db_->set_page_size(databasePageSize_);
}
DirectoryBackingStore::DirectoryBackingStore(const string& dir_name,
......@@ -308,6 +310,11 @@ bool DirectoryBackingStore::SaveChanges(
}
bool DirectoryBackingStore::InitializeTables() {
int page_size = 0;
if (IsSyncBackingDatabase32KEnabled() && GetDatabasePageSize(&page_size) &&
page_size == 4096) {
IncreasePageSizeTo32K();
}
sql::Transaction transaction(db_.get());
if (!transaction.Begin())
return false;
......@@ -1592,5 +1599,35 @@ void DirectoryBackingStore::PrepareSaveEntryStatement(
base::StringPrintf(query.c_str(), "metas").c_str()));
}
// Get page size for the database.
bool DirectoryBackingStore::GetDatabasePageSize(int* page_size) {
sql::Statement s(db_->GetUniqueStatement("PRAGMA page_size"));
if (!s.Step())
return false;
*page_size = s.ColumnInt(0);
return true;
}
bool DirectoryBackingStore::IsSyncBackingDatabase32KEnabled() {
const std::string group_name =
base::FieldTrialList::FindFullName("SyncBackingDatabase32K");
return group_name == "Enabled";
}
bool DirectoryBackingStore::IncreasePageSizeTo32K() {
if (!db_->Execute("PRAGMA page_size=32768;") || !Vacuum()) {
return false;
}
return true;
}
bool DirectoryBackingStore::Vacuum() {
DCHECK_EQ(db_->transaction_nesting(), 0);
if (!db_->Execute("VACUUM;")) {
return false;
}
return true;
}
} // namespace syncable
} // namespace syncer
......@@ -44,6 +44,10 @@ struct ColumnSpec;
// in tests. The concrete class used in non-test scenarios is
// OnDiskDirectoryBackingStore.
class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe {
friend class DirectoryBackingStoreTest;
FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest,
IncreaseDatabasePageSizeFrom4KTo32K);
public:
explicit DirectoryBackingStore(const std::string& dir_name);
virtual ~DirectoryBackingStore();
......@@ -145,6 +149,12 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe {
bool SetVersion(int version);
int GetVersion();
bool GetDatabasePageSize(int* page_size);
bool IsSyncBackingDatabase32KEnabled();
bool IncreasePageSizeTo32K();
bool Vacuum();
int databasePageSize_;
bool MigrateToSpecifics(const char* old_columns,
const char* specifics_column,
void(*handler_function) (
......
......@@ -18,6 +18,7 @@
#include "sync/internal_api/public/base/node_ordinal.h"
#include "sync/protocol/bookmark_specifics.pb.h"
#include "sync/protocol/sync.pb.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/directory_backing_store.h"
#include "sync/syncable/on_disk_directory_backing_store.h"
#include "sync/syncable/syncable-inl.h"
......@@ -3966,5 +3967,33 @@ TEST_F(DirectoryBackingStoreTest, GenerateCacheGUID) {
EXPECT_NE(guid1, guid2);
}
TEST_F(DirectoryBackingStoreTest, IncreaseDatabasePageSizeFrom4KTo32K) {
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
SetUpCurrentDatabaseAndCheckVersion(&connection);
scoped_ptr<TestDirectoryBackingStore> dbs(
new TestDirectoryBackingStore(GetUsername(), &connection));
Directory::MetahandlesMap handles_map;
JournalIndex delete_journals;
MetahandleSet metahandles_to_purge;
Directory::KernelLoadInfo kernel_load_info;
STLValueDeleter<Directory::MetahandlesMap> index_deleter(&handles_map);
DirOpenResult open_result = dbs->Load(
&handles_map, &delete_journals, &metahandles_to_purge, &kernel_load_info);
EXPECT_EQ(open_result, OPENED);
// Check if update is successful.
int pageSize = 0;
dbs->GetDatabasePageSize(&pageSize);
EXPECT_TRUE(32768 != pageSize);
dbs->db_->set_page_size(32768);
dbs->IncreasePageSizeTo32K();
pageSize = 0;
dbs->GetDatabasePageSize(&pageSize);
EXPECT_EQ(32768, pageSize);
}
} // namespace syncable
} // namespace syncer
......@@ -29,7 +29,7 @@ OnDiskDirectoryBackingStore::OnDiskDirectoryBackingStore(
allow_failure_for_test_(false),
backing_filepath_(backing_filepath) {
db_->set_exclusive_locking();
db_->set_page_size(4096);
db_->set_page_size(databasePageSize_);
}
OnDiskDirectoryBackingStore::~OnDiskDirectoryBackingStore() { }
......@@ -85,7 +85,7 @@ DirOpenResult OnDiskDirectoryBackingStore::Load(
// brittle. Either have a helper to set these up (or generate a new
// connection), or add something like Reset() to sql::Connection.
db_->set_exclusive_locking();
db_->set_page_size(4096);
db_->set_page_size(databasePageSize_);
db_->set_histogram_tag("SyncDirectory");
base::DeleteFile(backing_filepath_, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment