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

Side by Side Diff: sql/connection.h

Issue 1349863003: [sql] Use memory-mapped I/O for sql::Connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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.cc » ('j') | sql/connection.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 #ifndef SQL_CONNECTION_H_ 5 #ifndef SQL_CONNECTION_H_
6 #define SQL_CONNECTION_H_ 6 #define SQL_CONNECTION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // decision. Preloading should almost always improve later performance 255 // decision. Preloading should almost always improve later performance
256 // numbers for this database simply because it pulls operations forward, but 256 // numbers for this database simply because it pulls operations forward, but
257 // if the data isn't actually used soon then preloading just slows down 257 // if the data isn't actually used soon then preloading just slows down
258 // everything else. 258 // everything else.
259 void Preload(); 259 void Preload();
260 260
261 // Try to trim the cache memory used by the database. If |aggressively| is 261 // Try to trim the cache memory used by the database. If |aggressively| is
262 // true, this function will try to free all of the cache memory it can. If 262 // true, this function will try to free all of the cache memory it can. If
263 // |aggressively| is false, this function will try to cut cache memory 263 // |aggressively| is false, this function will try to cut cache memory
264 // usage by half. 264 // usage by half.
265 // NOTE(shess): See also ReleaseCacheMemory().
265 void TrimMemory(bool aggressively); 266 void TrimMemory(bool aggressively);
266 267
267 // Raze the database to the ground. This approximates creating a 268 // Raze the database to the ground. This approximates creating a
268 // fresh database from scratch, within the constraints of SQLite's 269 // fresh database from scratch, within the constraints of SQLite's
269 // locking protocol (locks and open handles can make doing this with 270 // locking protocol (locks and open handles can make doing this with
270 // filesystem operations problematic). Returns true if the database 271 // filesystem operations problematic). Returns true if the database
271 // was razed. 272 // was razed.
272 // 273 //
273 // false is returned if the database is locked by some other 274 // false is returned if the database is locked by some other
274 // process. RazeWithTimeout() may be used if appropriate. 275 // process. RazeWithTimeout() may be used if appropriate.
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 // true, autocommit time if the database is not in a transaction, or update 632 // true, autocommit time if the database is not in a transaction, or update
632 // time if the database is in a transaction. Also records change count to 633 // time if the database is in a transaction. Also records change count to
633 // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT. 634 // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT.
634 void RecordTimeAndChanges(const base::TimeDelta& delta, bool read_only); 635 void RecordTimeAndChanges(const base::TimeDelta& delta, bool read_only);
635 636
636 // Helper to return the current time from the time source. 637 // Helper to return the current time from the time source.
637 base::TimeTicks Now() { 638 base::TimeTicks Now() {
638 return clock_->Now(); 639 return clock_->Now();
639 } 640 }
640 641
642 // Release page-cache memory if memory-mapped I/O is enabled and the database
643 // was changed. Passing true for |assume_changed| allows overriding the
644 // change detection for cases like DDL (CREATE, DROP, etc), which do not
645 // participate in the total-rows-changed tracking.
646 void ReleaseCacheMemoryIfNeeded(bool assume_changed);
647
641 // The actual sqlite database. Will be NULL before Init has been called or if 648 // The actual sqlite database. Will be NULL before Init has been called or if
642 // Init resulted in an error. 649 // Init resulted in an error.
643 sqlite3* db_; 650 sqlite3* db_;
644 651
645 // Parameters we'll configure in sqlite before doing anything else. Zero means 652 // Parameters we'll configure in sqlite before doing anything else. Zero means
646 // use the default value. 653 // use the default value.
647 int page_size_; 654 int page_size_;
648 int cache_size_; 655 int cache_size_;
649 bool exclusive_locking_; 656 bool exclusive_locking_;
650 bool restrict_to_user_; 657 bool restrict_to_user_;
(...skipping 21 matching lines...) Expand all
672 // True if database is open with OpenInMemory(), False if database is open 679 // True if database is open with OpenInMemory(), False if database is open
673 // with Open(). 680 // with Open().
674 bool in_memory_; 681 bool in_memory_;
675 682
676 // |true| if the connection was closed using RazeAndClose(). Used 683 // |true| if the connection was closed using RazeAndClose(). Used
677 // to enable diagnostics to distinguish calls to never-opened 684 // to enable diagnostics to distinguish calls to never-opened
678 // databases (incorrect use of the API) from calls to once-valid 685 // databases (incorrect use of the API) from calls to once-valid
679 // databases. 686 // databases.
680 bool poisoned_; 687 bool poisoned_;
681 688
689 // |true| if SQLite memory-mapped I/O is enabled for this connection.
690 // Used by ReleaseCacheMemoryIfNeeded().
691 bool mmap_enabled_;
692
693 // Used by ReleaseCacheMemoryIfNeeded() to track if new changes have happened
694 // since memory was last released.
695 int total_changes_;
696
682 ErrorCallback error_callback_; 697 ErrorCallback error_callback_;
683 698
684 // Tag for auxiliary histograms. 699 // Tag for auxiliary histograms.
685 std::string histogram_tag_; 700 std::string histogram_tag_;
686 701
687 // Linear histogram for RecordEvent(). 702 // Linear histogram for RecordEvent().
688 base::HistogramBase* stats_histogram_; 703 base::HistogramBase* stats_histogram_;
689 704
690 // Histogram for tracking time taken in commit. 705 // Histogram for tracking time taken in commit.
691 base::HistogramBase* commit_time_histogram_; 706 base::HistogramBase* commit_time_histogram_;
(...skipping 11 matching lines...) Expand all
703 // Source for timing information, provided to allow tests to inject time 718 // Source for timing information, provided to allow tests to inject time
704 // changes. 719 // changes.
705 scoped_ptr<TimeSource> clock_; 720 scoped_ptr<TimeSource> clock_;
706 721
707 DISALLOW_COPY_AND_ASSIGN(Connection); 722 DISALLOW_COPY_AND_ASSIGN(Connection);
708 }; 723 };
709 724
710 } // namespace sql 725 } // namespace sql
711 726
712 #endif // SQL_CONNECTION_H_ 727 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698