SQLite

Check-in [72c4072693]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Put the statement journal in the temp-file directory since that directory is often on optimized storage such as RAM disk and because unlike the main journal, the statement journal does not need to be colocated with the database file. (CVS 4868)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 72c40726932695a2cf5c593707d098c8fb6e8875
User & Date: drh 2008-03-17 13:50:58.000
Context
2008-03-17
15:09
Modify the tableapi.test script so that it works under windows. (CVS 4869) (check-in: 89e06b4e08 user: drh tags: trunk)
13:50
Put the statement journal in the temp-file directory since that directory is often on optimized storage such as RAM disk and because unlike the main journal, the statement journal does not need to be colocated with the database file. (CVS 4868) (check-in: 72c4072693 user: drh tags: trunk)
09:36
Return an error when an xBestIndex() method indicates that it intends to use the value of an unusable constraint. Related to #2998. (CVS 4867) (check-in: ffd4702795 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pager.c.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.416 2008/03/14 19:33:06 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include <assert.h>
#include <string.h>

/*







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.417 2008/03/17 13:50:58 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include <assert.h>
#include <string.h>

/*
2079
2080
2081
2082
2083
2084
2085


2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
  int readOnly = 0;
  int useJournal = (flags & PAGER_OMIT_JOURNAL)==0;
  int noReadlock = (flags & PAGER_NO_READLOCK)!=0;
  int journalFileSize = sqlite3JournalSize(pVfs);
  int nDefaultPage = SQLITE_DEFAULT_PAGE_SIZE;
  char *zPathname;
  int nPathname;



  /* The default return is a NULL pointer */
  *ppPager = 0;

  /* Compute the full pathname */
  nPathname = pVfs->mxPathname+1;
  zPathname = sqlite3_malloc(nPathname);
  if( zPathname==0 ){
    return SQLITE_NOMEM;
  }
  if( zFilename && zFilename[0] ){
#ifndef SQLITE_OMIT_MEMORYDB
    if( strcmp(zFilename,":memory:")==0 ){
      memDb = 1;







>
>






|







2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
  int readOnly = 0;
  int useJournal = (flags & PAGER_OMIT_JOURNAL)==0;
  int noReadlock = (flags & PAGER_NO_READLOCK)!=0;
  int journalFileSize = sqlite3JournalSize(pVfs);
  int nDefaultPage = SQLITE_DEFAULT_PAGE_SIZE;
  char *zPathname;
  int nPathname;
  char *zStmtJrnl;
  int nStmtJrnl;

  /* The default return is a NULL pointer */
  *ppPager = 0;

  /* Compute the full pathname */
  nPathname = pVfs->mxPathname+1;
  zPathname = sqlite3_malloc(nPathname*2);
  if( zPathname==0 ){
    return SQLITE_NOMEM;
  }
  if( zFilename && zFilename[0] ){
#ifndef SQLITE_OMIT_MEMORYDB
    if( strcmp(zFilename,":memory:")==0 ){
      memDb = 1;
2107
2108
2109
2110
2111
2112
2113













2114
2115
2116
2117
2118
2119
2120

2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136

2137
2138
2139
2140
2141
2142
2143
    rc = sqlite3OsGetTempname(pVfs, nPathname, zPathname);
  }
  if( rc!=SQLITE_OK ){
    sqlite3_free(zPathname);
    return rc;
  }
  nPathname = strlen(zPathname);














  /* Allocate memory for the pager structure */
  pPager = sqlite3MallocZero(
    sizeof(*pPager) +           /* Pager structure */
    journalFileSize +           /* The journal file structure */ 
    pVfs->szOsFile * 3 +        /* The main db and two journal files */ 
    4*nPathname + 40            /* zFilename, zDirectory, zJournal, zStmtJrnl */

  );
  if( !pPager ){
    sqlite3_free(zPathname);
    return SQLITE_NOMEM;
  }
  pPtr = (u8 *)&pPager[1];
  pPager->vfsFlags = vfsFlags;
  pPager->fd = (sqlite3_file*)&pPtr[pVfs->szOsFile*0];
  pPager->stfd = (sqlite3_file*)&pPtr[pVfs->szOsFile*1];
  pPager->jfd = (sqlite3_file*)&pPtr[pVfs->szOsFile*2];
  pPager->zFilename = (char*)&pPtr[pVfs->szOsFile*2+journalFileSize];
  pPager->zDirectory = &pPager->zFilename[nPathname+1];
  pPager->zJournal = &pPager->zDirectory[nPathname+1];
  pPager->zStmtJrnl = &pPager->zJournal[nPathname+10];
  pPager->pVfs = pVfs;
  memcpy(pPager->zFilename, zPathname, nPathname+1);

  sqlite3_free(zPathname);

  /* Open the pager file.
  */
  if( zFilename && zFilename[0] && !memDb ){
    if( nPathname>(pVfs->mxPathname - sizeof("-journal")) ){
      rc = SQLITE_CANTOPEN;







>
>
>
>
>
>
>
>
>
>
>
>
>






|
>
















>







2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
    rc = sqlite3OsGetTempname(pVfs, nPathname, zPathname);
  }
  if( rc!=SQLITE_OK ){
    sqlite3_free(zPathname);
    return rc;
  }
  nPathname = strlen(zPathname);

  /* Put the statement journal in temporary disk space since this is
  ** sometimes RAM disk or other optimized storage.  Unlikely the main
  ** main journal file, the statement journal does not need to be 
  ** colocated with the database nor does it need to be persistent.
  */
  zStmtJrnl = &zPathname[nPathname+1];
  rc = sqlite3OsGetTempname(pVfs, pVfs->mxPathname+1, zStmtJrnl);
  if( rc!=SQLITE_OK ){
    sqlite3_free(zPathname);
    return rc;
  }
  nStmtJrnl = strlen(zStmtJrnl);

  /* Allocate memory for the pager structure */
  pPager = sqlite3MallocZero(
    sizeof(*pPager) +           /* Pager structure */
    journalFileSize +           /* The journal file structure */ 
    pVfs->szOsFile * 3 +        /* The main db and two journal files */ 
    3*nPathname + 40 +          /* zFilename, zDirectory, zJournal */
    nStmtJrnl                   /* zStmtJrnl */
  );
  if( !pPager ){
    sqlite3_free(zPathname);
    return SQLITE_NOMEM;
  }
  pPtr = (u8 *)&pPager[1];
  pPager->vfsFlags = vfsFlags;
  pPager->fd = (sqlite3_file*)&pPtr[pVfs->szOsFile*0];
  pPager->stfd = (sqlite3_file*)&pPtr[pVfs->szOsFile*1];
  pPager->jfd = (sqlite3_file*)&pPtr[pVfs->szOsFile*2];
  pPager->zFilename = (char*)&pPtr[pVfs->szOsFile*2+journalFileSize];
  pPager->zDirectory = &pPager->zFilename[nPathname+1];
  pPager->zJournal = &pPager->zDirectory[nPathname+1];
  pPager->zStmtJrnl = &pPager->zJournal[nPathname+10];
  pPager->pVfs = pVfs;
  memcpy(pPager->zFilename, zPathname, nPathname+1);
  memcpy(pPager->zStmtJrnl, zStmtJrnl, nStmtJrnl+1);
  sqlite3_free(zPathname);

  /* Open the pager file.
  */
  if( zFilename && zFilename[0] && !memDb ){
    if( nPathname>(pVfs->mxPathname - sizeof("-journal")) ){
      rc = SQLITE_CANTOPEN;
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
  IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))

  /* Fill in Pager.zDirectory[] */
  memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
  for(i=strlen(pPager->zDirectory); i>0 && pPager->zDirectory[i-1]!='/'; i--){}
  if( i>0 ) pPager->zDirectory[i-1] = 0;

  /* Fill in Pager.zJournal[] and Pager.zStmtJrnl[] */
  memcpy(pPager->zJournal, pPager->zFilename, nPathname);
  memcpy(&pPager->zJournal[nPathname], "-journal", 9);
  memcpy(pPager->zStmtJrnl, pPager->zFilename, nPathname);
  memcpy(&pPager->zStmtJrnl[nPathname], "-stmtjrnl", 10);

  /* pPager->journalOpen = 0; */
  pPager->useJournal = useJournal && !memDb;
  pPager->noReadlock = noReadlock && readOnly;
  /* pPager->stmtOpen = 0; */
  /* pPager->stmtInUse = 0; */
  /* pPager->nRef = 0; */







|


<
<







2222
2223
2224
2225
2226
2227
2228
2229
2230
2231


2232
2233
2234
2235
2236
2237
2238
  IOTRACE(("OPEN %p %s\n", pPager, pPager->zFilename))

  /* Fill in Pager.zDirectory[] */
  memcpy(pPager->zDirectory, pPager->zFilename, nPathname+1);
  for(i=strlen(pPager->zDirectory); i>0 && pPager->zDirectory[i-1]!='/'; i--){}
  if( i>0 ) pPager->zDirectory[i-1] = 0;

  /* Fill in Pager.zJournal[] */
  memcpy(pPager->zJournal, pPager->zFilename, nPathname);
  memcpy(&pPager->zJournal[nPathname], "-journal", 9);



  /* pPager->journalOpen = 0; */
  pPager->useJournal = useJournal && !memDb;
  pPager->noReadlock = noReadlock && readOnly;
  /* pPager->stmtOpen = 0; */
  /* pPager->stmtInUse = 0; */
  /* pPager->nRef = 0; */