summaryrefslogtreecommitdiffstats
path: root/third_party/sqlite/preload-cache.patch
diff options
context:
space:
mode:
authoraa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-30 01:36:02 +0000
committeraa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-30 01:36:02 +0000
commit0daa4fc8d2809bb42f93f1a348e43924608ff7fe (patch)
tree9aae73bbe8dd7589669b539710380cf8facbdb76 /third_party/sqlite/preload-cache.patch
parent0d5e0eb4b86a87924db2317a869971cdad53c4f6 (diff)
downloadchromium_src-0daa4fc8d2809bb42f93f1a348e43924608ff7fe.zip
chromium_src-0daa4fc8d2809bb42f93f1a348e43924608ff7fe.tar.gz
chromium_src-0daa4fc8d2809bb42f93f1a348e43924608ff7fe.tar.bz2
Move SQLite from src/chrome/third_party to src/third_party
since it will be shared with WebCore and Gears in the future. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/sqlite/preload-cache.patch')
-rw-r--r--third_party/sqlite/preload-cache.patch246
1 files changed, 246 insertions, 0 deletions
diff --git a/third_party/sqlite/preload-cache.patch b/third_party/sqlite/preload-cache.patch
new file mode 100644
index 0000000..3601a4b
--- /dev/null
+++ b/third_party/sqlite/preload-cache.patch
@@ -0,0 +1,246 @@
+Index: build.c
+===================================================================
+--- build.c (revision 12588)
++++ build.c (working copy)
+@@ -27,6 +27,9 @@
+ #include "sqliteInt.h"
+ #include <ctype.h>
+
++#include "pager.h"
++#include "btree.h"
++
+ /*
+ ** This routine is called when a new SQL statement is beginning to
+ ** be parsed. Initialize the pParse structure as needed.
+@@ -3359,3 +3362,28 @@
+ }
+ return pKey;
+ }
++
++/* See declaration in sqlite3.h for information */
++int sqlite3Preload(sqlite3 *db)
++{
++ Pager *pPager;
++ Btree *pBt;
++ int rc;
++ int i;
++ int dbsLoaded = 0;
++
++ for(i=0; i<db->nDb; i++) {
++ pBt = db->aDb[i].pBt;
++ if( !pBt )
++ continue;
++ pPager = sqlite3BtreePager(pBt);
++ if( pPager ) {
++ rc = sqlite3PagerLoadall(pPager);
++ if (rc == SQLITE_OK)
++ dbsLoaded++;
++ }
++ }
++ if (dbsLoaded == 0)
++ return SQLITE_ERROR;
++ return SQLITE_OK;
++}
+Index: sqlite3.h
+===================================================================
+--- sqlite3.h (revision 12588)
++++ sqlite3.h (working copy)
+@@ -2696,6 +2696,19 @@
+ int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
+
+ /*
++** Preload the databases into the pager cache, up to the maximum size of the
++** pager cache.
++**
++** For a database to be loaded successfully, the pager must be active. That is,
++** there must be an open statement on that database. See sqlite3pager_loadall
++**
++** There might be many databases attached to the given connection. We iterate
++** them all and try to load them. If none are loadable successfully, we return
++** an error. Otherwise, we return OK.
++*/
++int sqlite3Preload(sqlite3 *db);
++
++/*
+ ** Undo the hack that converts floating point types to integer for
+ ** builds on processors without floating point support.
+ */
+Index: pager.c
+===================================================================
+--- pager.c (revision 12588)
++++ pager.c (working copy)
+@@ -453,6 +453,14 @@
+ */
+ #define PAGER_MAX_PGNO 2147483647
+
++/* See comments above the definition. */
++int sqlite3PagerAcquire2(
++ Pager *pPager,
++ Pgno pgno,
++ DbPage **ppPage,
++ int noContent,
++ unsigned char *pDataToFill);
++
+ /*
+ ** Enable reference count tracking (for debugging) here:
+ */
+@@ -2000,14 +2008,14 @@
+ }
+ if( pPager->dbSize>=0 ){
+ n = pPager->dbSize;
+- } else {
++ }else{
+ if( (rc = sqlite3OsFileSize(pPager->fd, &n))!=SQLITE_OK ){
+ pager_error(pPager, rc);
+ return 0;
+ }
+ if( n>0 && n<pPager->pageSize ){
+ n = 1;
+- }else{
++ } else {
+ n /= pPager->pageSize;
+ }
+ if( pPager->state!=PAGER_UNLOCK ){
+@@ -3101,6 +3109,25 @@
+ DbPage **ppPage, /* Write a pointer to the page here */
+ int noContent /* Do not bother reading content from disk if true */
+ ){
++ /* This just passes through to our modified version with NULL data. */
++ return sqlite3PagerAcquire2(pPager, pgno, ppPage, noContent, 0);
++}
++
++/*
++** This is an internal version of sqlite3PagerAcquire that takes an extra
++** parameter of data to use to fill the page with. This allows more efficient
++** filling for preloaded data. If this extra parameter is NULL, we'll go to
++** the file.
++**
++** See sqlite3PagerLoadall which uses this function.
++*/
++int sqlite3PagerAcquire2(
++ Pager *pPager, /* The pager open on the database file */
++ Pgno pgno, /* Page number to fetch */
++ DbPage **ppPage, /* Write a pointer to the page here */
++ int noContent, /* Do not bother reading content from disk if true */
++ unsigned char* pDataToFill
++){
+ PgHdr *pPg;
+ int rc;
+
+@@ -3181,11 +3208,18 @@
+ pPg->needRead = noContent && !pPager->alwaysRollback;
+ IOTRACE(("ZERO %p %d\n", pPager, pgno));
+ }else{
+- rc = readDbPage(pPager, pPg, pgno);
+- if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
+- pPg->pgno = 0;
+- sqlite3PagerUnref(pPg);
+- return rc;
++ if (pDataToFill) {
++ /* Just copy from the given memory. */
++ memcpy(PGHDR_TO_DATA(pPg), pDataToFill, pPager->pageSize);
++ CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
++ } else {
++ /* Load from disk (old regular sqlite code path). */
++ rc = readDbPage(pPager, pPg, pgno);
++ if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
++ pPg->pgno = 0;
++ sqlite3PagerUnref(pPg);
++ return rc;
++ }
+ }
+ pPg->needRead = 0;
+ }
+@@ -4416,6 +4450,68 @@
+ }
+ #endif
+
++/**
++** Addition: This will attempt to populate the database cache with
++** the first N bytes of the file, where N is the total size of the cache.
++** Because we can load this as one chunk from the disk, this is much faster
++** than loading a subset of the pages one at a time in random order.
++**
++** The pager must be initialized before this function is called. This means a
++** statement must be open that has initialized the pager and is keeping the
++** cache in memory.
++**/
++int sqlite3PagerLoadall(Pager* pPager)
++{
++ int i;
++ int rc;
++ int loadSize;
++ int loadPages;
++ unsigned char *fileData;
++
++ if (pPager->dbSize < 0 || pPager->pageSize < 0) {
++ /* pager not initialized, this means a statement is not open */
++ return SQLITE_MISUSE;
++ }
++
++ /* compute sizes */
++ if (pPager->mxPage < pPager->dbSize)
++ loadPages = pPager->mxPage;
++ else
++ loadPages = pPager->dbSize;
++ loadSize = loadPages * pPager->pageSize;
++
++ rc = sqlite3OsSeek(pPager->fd, 0);
++ if (rc != SQLITE_OK)
++ return rc;
++
++ /* load the file as one chunk */
++ fileData = sqliteMallocRaw(loadSize);
++ if (! fileData)
++ return SQLITE_NOMEM;
++ rc = sqlite3OsRead(pPager->fd, fileData, loadSize);
++ if (rc != SQLITE_OK) {
++ sqliteFree(fileData);
++ return rc;
++ }
++
++ /* Copy the data to each page. Note that the page numbers we pass to _get
++ * are one-based, 0 is a marker for no page. We also need to check that we
++ * haven't loaded more pages than the cache can hold total. There may have
++ * already been a few pages loaded before, so we may fill the cache before
++ * loading all of the pages we want to.
++ */
++ for(i=1; i <= loadPages && pPager->nPage < pPager->mxPage; i++) {
++ DbPage *pPage;
++ rc = sqlite3PagerAcquire2(pPager, i, &pPage, 0,
++ &fileData[(i-1)*(i64)pPager->pageSize]);
++ if (rc != SQLITE_OK)
++ break;
++ sqlite3PagerUnref(pPage);
++ }
++ sqliteFree(fileData);
++ return SQLITE_OK;
++}
++
+ /*
+ ** Return a pointer to the data for the specified page.
+ */
+Index: pager.h
+===================================================================
+--- pager.h (revision 12588)
++++ pager.h (working copy)
+@@ -93,6 +93,7 @@
+ void *sqlite3PagerGetData(DbPage *);
+ void *sqlite3PagerGetExtra(DbPage *);
+ int sqlite3PagerLockingMode(Pager *, int);
++int sqlite3PagerLoadall(Pager*);
+
+ #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
+ int sqlite3PagerReleaseMemory(int);
++Index: pager.h
++===================================================================
++--- pager.h (revision 12588)
+++++ pager.h (working copy)
++@@ -93,6 +93,7 @@
++ void *sqlite3PagerGetData(DbPage *);
++ void *sqlite3PagerGetExtra(DbPage *);
++ int sqlite3PagerLockingMode(Pager *, int);
+++int sqlite3PagerLoadall(Pager*);
++
++ #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
++ int sqlite3PagerReleaseMemory(int);