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

Side by Side Diff: sql/connection.cc

Issue 2728543008: [sql] Experiment to enable smart-vacuum on Android.
Patch Set: cl feature suggestion, and test it. Created 3 years, 8 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
« no previous file with comments | « no previous file | sql/connection_unittest.cc » ('j') | sql/connection_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "sql/connection.h" 5 #include "sql/connection.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/debug/alias.h" 15 #include "base/debug/alias.h"
16 #include "base/debug/dump_without_crashing.h" 16 #include "base/debug/dump_without_crashing.h"
17 #include "base/feature_list.h"
17 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
19 #include "base/format_macros.h" 20 #include "base/format_macros.h"
20 #include "base/json/json_file_value_serializer.h" 21 #include "base/json/json_file_value_serializer.h"
21 #include "base/lazy_instance.h" 22 #include "base/lazy_instance.h"
22 #include "base/location.h" 23 #include "base/location.h"
23 #include "base/logging.h" 24 #include "base/logging.h"
24 #include "base/metrics/histogram_macros.h" 25 #include "base/metrics/histogram_macros.h"
25 #include "base/metrics/sparse_histogram.h" 26 #include "base/metrics/sparse_histogram.h"
26 #include "base/single_thread_task_runner.h" 27 #include "base/single_thread_task_runner.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 222 }
222 223
223 std::string AsUTF8ForSQL(const base::FilePath& path) { 224 std::string AsUTF8ForSQL(const base::FilePath& path) {
224 #if defined(OS_WIN) 225 #if defined(OS_WIN)
225 return base::WideToUTF8(path.value()); 226 return base::WideToUTF8(path.value());
226 #elif defined(OS_POSIX) 227 #elif defined(OS_POSIX)
227 return path.value(); 228 return path.value();
228 #endif 229 #endif
229 } 230 }
230 231
232 // http://crbug.com/698010
233 //
234 // The feature enables a SQLite patch which causes SQLite to leverage
235 // SQLITE_FCNTL_CHUNK_SIZE when making auto-vacuum decisions. This should lower
236 // write load (histogram Sqlite.Vfs_Write in vfs_wrapper.cc). Only Android
237 // enables auto-vacuum under Chromium.
238 const base::Feature kSqliteSmartAutoVacuumEnabled{
239 "SqliteSmartAutoVacuum", base::FEATURE_DISABLED_BY_DEFAULT};
240
231 } // namespace 241 } // namespace
232 242
233 namespace sql { 243 namespace sql {
234 244
235 // static 245 // static
236 Connection::ErrorExpecterCallback* Connection::current_expecter_cb_ = NULL; 246 Connection::ErrorExpecterCallback* Connection::current_expecter_cb_ = NULL;
237 247
238 // static 248 // static
239 bool Connection::IsExpectedSqliteError(int error) { 249 bool Connection::IsExpectedSqliteError(int error) {
240 if (!current_expecter_cb_) 250 if (!current_expecter_cb_)
(...skipping 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 // databases (<20k) while other clients have a broad distribution of sizes 1854 // databases (<20k) while other clients have a broad distribution of sizes
1845 // (hundreds of kilobytes to many megabytes). 1855 // (hundreds of kilobytes to many megabytes).
1846 sqlite3_file* file = NULL; 1856 sqlite3_file* file = NULL;
1847 sqlite3_int64 db_size = 0; 1857 sqlite3_int64 db_size = 0;
1848 int rc = GetSqlite3FileAndSize(db_, &file, &db_size); 1858 int rc = GetSqlite3FileAndSize(db_, &file, &db_size);
1849 if (rc == SQLITE_OK && db_size > 16 * 1024) { 1859 if (rc == SQLITE_OK && db_size > 16 * 1024) {
1850 int chunk_size = 4 * 1024; 1860 int chunk_size = 4 * 1024;
1851 if (db_size > 128 * 1024) 1861 if (db_size > 128 * 1024)
1852 chunk_size = 32 * 1024; 1862 chunk_size = 32 * 1024;
1853 sqlite3_file_control(db_, NULL, SQLITE_FCNTL_CHUNK_SIZE, &chunk_size); 1863 sqlite3_file_control(db_, NULL, SQLITE_FCNTL_CHUNK_SIZE, &chunk_size);
1864 if (base::FeatureList::IsEnabled(kSqliteSmartAutoVacuumEnabled)) {
1865 // TODO(shess): The default page size is now 4096. Before committing to
1866 // this long-term, fix that. Meanwhile, this should be fine, it might
1867 // leave a few databases using a bit more disk space than expected.
1868 const int page_size = page_size_ ? page_size_ : 1024;
Maria 2017/03/28 22:14:59 The 1024 constant here for page_size, is this just
Scott Hess - ex-Googler 2017/03/29 03:28:46 Maybe I'll elaborate the comment. SQLite's defaul
Scott Hess - ex-Googler 2017/03/29 21:11:24 Bah, I just went with fetching the page-size from
1869 std::string slack_sql = base::StringPrintf(
1870 "PRAGMA auto_vacuum_slack_pages = %d", chunk_size / page_size);
1871 ignore_result(Execute(slack_sql.c_str()));
1872 }
1854 } 1873 }
1855 1874
1856 // Enable memory-mapped access. The explicit-disable case is because SQLite 1875 // Enable memory-mapped access. The explicit-disable case is because SQLite
1857 // can be built to default-enable mmap. GetAppropriateMmapSize() calculates a 1876 // can be built to default-enable mmap. GetAppropriateMmapSize() calculates a
1858 // safe range to memory-map based on past regular I/O. This value will be 1877 // safe range to memory-map based on past regular I/O. This value will be
1859 // capped by SQLITE_MAX_MMAP_SIZE, which could be different between 32-bit and 1878 // capped by SQLITE_MAX_MMAP_SIZE, which could be different between 32-bit and
1860 // 64-bit platforms. 1879 // 64-bit platforms.
1861 size_t mmap_size = mmap_disabled_ ? 0 : GetAppropriateMmapSize(); 1880 size_t mmap_size = mmap_disabled_ ? 0 : GetAppropriateMmapSize();
1862 std::string mmap_sql = 1881 std::string mmap_sql =
1863 base::StringPrintf("PRAGMA mmap_size = %" PRIuS, mmap_size); 1882 base::StringPrintf("PRAGMA mmap_size = %" PRIuS, mmap_size);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 const std::string& dump_name) { 2074 const std::string& dump_name) {
2056 return memory_dump_provider_ && 2075 return memory_dump_provider_ &&
2057 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); 2076 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name);
2058 } 2077 }
2059 2078
2060 base::TimeTicks TimeSource::Now() { 2079 base::TimeTicks TimeSource::Now() {
2061 return base::TimeTicks::Now(); 2080 return base::TimeTicks::Now();
2062 } 2081 }
2063 2082
2064 } // namespace sql 2083 } // namespace sql
OLDNEW
« no previous file with comments | « no previous file | sql/connection_unittest.cc » ('j') | sql/connection_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698