/ Check-in [6324ea81]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Use the difference between the SQLITE_IOERR_SHORT_READ and SQLITE_IOERR_READ returns from sqlite3OsRead() to make decisions about what to do with the error. (CVS 3503)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6324ea811eec1200cee89e6f377368eaf2fcda77
User & Date: drh 2006-11-06 21:20:26
Context
2006-11-07
15:02
Fix a typo in os_win.c. Ticket #2055. (CVS 3504) check-in: d309680e user: drh tags: trunk
2006-11-06
21:20
Use the difference between the SQLITE_IOERR_SHORT_READ and SQLITE_IOERR_READ returns from sqlite3OsRead() to make decisions about what to do with the error. (CVS 3503) check-in: 6324ea81 user: drh tags: trunk
15:10
Fix a bug in the optimizer that was causing it to miss an OR optimization opportunity. (CVS 3502) check-in: 9bf153b5 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.329 2006/11/01 12:08:41 drh Exp $
           12  +** $Id: btree.c,v 1.330 2006/11/06 21:20:26 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
  1545   1545     pBt = sqliteMalloc( sizeof(*pBt) );
  1546   1546     if( pBt==0 ){
  1547   1547       *ppBtree = 0;
  1548   1548       sqliteFree(p);
  1549   1549       return SQLITE_NOMEM;
  1550   1550     }
  1551   1551     rc = sqlite3pager_open(&pBt->pPager, zFilename, EXTRA_SIZE, flags);
         1552  +  if( rc==SQLITE_OK ){
         1553  +    rc = sqlite3pager_read_fileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
         1554  +  }
  1552   1555     if( rc!=SQLITE_OK ){
  1553         -    if( pBt->pPager ) sqlite3pager_close(pBt->pPager);
         1556  +    if( pBt->pPager ){
         1557  +      sqlite3pager_close(pBt->pPager);
         1558  +    }
  1554   1559       sqliteFree(pBt);
  1555   1560       sqliteFree(p);
  1556   1561       *ppBtree = 0;
  1557   1562       return rc;
  1558   1563     }
  1559   1564     p->pBt = pBt;
  1560   1565   
  1561   1566     sqlite3pager_set_destructor(pBt->pPager, pageDestructor);
  1562   1567     sqlite3pager_set_reiniter(pBt->pPager, pageReinit);
  1563   1568     pBt->pCursor = 0;
  1564   1569     pBt->pPage1 = 0;
  1565   1570     pBt->readOnly = sqlite3pager_isreadonly(pBt->pPager);
  1566         -  sqlite3pager_read_fileheader(pBt->pPager, sizeof(zDbHeader), zDbHeader);
  1567   1571     pBt->pageSize = get2byte(&zDbHeader[16]);
  1568   1572     if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
  1569   1573          || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
  1570   1574       pBt->pageSize = SQLITE_DEFAULT_PAGE_SIZE;
  1571   1575       pBt->maxEmbedFrac = 64;   /* 25% */
  1572   1576       pBt->minEmbedFrac = 32;   /* 12.5% */
  1573   1577       pBt->minLeafFrac = 32;    /* 12.5% */

Changes to src/os_os2.c.

   286    286   */
   287    287   int os2Read( OsFile *id, void *pBuf, int amt ){
   288    288     ULONG got;
   289    289     assert( id!=0 );
   290    290     SimulateIOError( return SQLITE_IOERR );
   291    291     TRACE3( "READ %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );
   292    292     DosRead( ((os2File*)id)->h, pBuf, amt, &got );
   293         -  return (got == (ULONG)amt) ? SQLITE_OK : SQLITE_IOERR;
          293  +  return (got == (ULONG)amt) ? SQLITE_OK : SQLITE_IOERR_SHORT_READ;
   294    294   }
   295    295   
   296    296   /*
   297    297   ** Write data from a buffer into a file.  Return SQLITE_OK on success
   298    298   ** or some other error code on failure.
   299    299   */
   300    300   int os2Write( OsFile *id, const void *pBuf, int amt ){

Changes to src/os_unix.c.

  1022   1022     assert( id );
  1023   1023     TIMER_START;
  1024   1024     got = seekAndRead((unixFile*)id, pBuf, amt);
  1025   1025     TIMER_END;
  1026   1026     TRACE5("READ    %-3d %5d %7d %d\n", ((unixFile*)id)->h, got,
  1027   1027             last_page, TIMER_ELAPSED);
  1028   1028     SEEK(0);
  1029         -  SimulateIOError( got=0 );
         1029  +  SimulateIOError( got = -1 );
  1030   1030     if( got==amt ){
  1031   1031       return SQLITE_OK;
  1032   1032     }else if( got<0 ){
  1033   1033       return SQLITE_IOERR_READ;
  1034   1034     }else{
  1035   1035       return SQLITE_IOERR_SHORT_READ;
  1036   1036     }

Changes to src/os_win.c.

   989    989   */
   990    990   static int winRead(OsFile *id, void *pBuf, int amt){
   991    991     DWORD got;
   992    992     assert( id!=0 );
   993    993     SimulateIOError(return SQLITE_IOERR);
   994    994     TRACE3("READ %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype);
   995    995     if( !ReadFile(((winFile*)id)->h, pBuf, amt, &got, 0) ){
   996         -    got = 0;
          996  +    got = -1;
   997    997     }
   998    998     if( got==(DWORD)amt ){
   999    999       return SQLITE_OK;
         1000  +  }else if( goc<0 ){
         1001  +    return SQLITE_IOERR_READ;
  1000   1002     }else{
  1001         -    return SQLITE_IOERR;
         1003  +    return SQLITE_IOERR_SHORT_READ;
  1002   1004     }
  1003   1005   }
  1004   1006   
  1005   1007   /*
  1006   1008   ** Write data from a buffer into a file.  Return SQLITE_OK on success
  1007   1009   ** or some other error code on failure.
  1008   1010   */

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.274 2006/10/03 19:05:19 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.275 2006/11/06 21:20:26 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
  1794   1794   **
  1795   1795   ** No error checking is done. The rational for this is that this function 
  1796   1796   ** may be called even if the file does not exist or contain a header. In 
  1797   1797   ** these cases sqlite3OsRead() will return an error, to which the correct 
  1798   1798   ** response is to zero the memory at pDest and continue.  A real IO error 
  1799   1799   ** will presumably recur and be picked up later (Todo: Think about this).
  1800   1800   */
  1801         -void sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
         1801  +int sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
         1802  +  int rc = SQLITE_OK;
  1802   1803     memset(pDest, 0, N);
  1803   1804     if( MEMDB==0 ){
  1804   1805       disable_simulated_io_errors();
  1805   1806       sqlite3OsSeek(pPager->fd, 0);
  1806         -    sqlite3OsRead(pPager->fd, pDest, N);
  1807   1807       enable_simulated_io_errors();
         1808  +    rc = sqlite3OsRead(pPager->fd, pDest, N);
         1809  +    if( rc==SQLITE_IOERR_SHORT_READ ){
         1810  +      rc = SQLITE_OK;
         1811  +    }
  1808   1812     }
         1813  +  return rc;
  1809   1814   }
  1810   1815   
  1811   1816   /*
  1812   1817   ** Return the total number of pages in the disk file associated with
  1813   1818   ** pPager. 
  1814   1819   **
  1815   1820   ** If the PENDING_BYTE lies on the page directly after the end of the
................................................................................
  2785   2790         rc = sqlite3OsSeek(pPager->fd, (pgno-1)*(i64)pPager->pageSize);
  2786   2791         if( rc==SQLITE_OK ){
  2787   2792           rc = sqlite3OsRead(pPager->fd, PGHDR_TO_DATA(pPg),
  2788   2793                                 pPager->pageSize);
  2789   2794         }
  2790   2795         TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
  2791   2796         CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
  2792         -      if( rc!=SQLITE_OK ){
  2793         -        i64 fileSize;
  2794         -        int rc2 = sqlite3OsFileSize(pPager->fd, &fileSize);
  2795         -        if( rc2!=SQLITE_OK || fileSize>=pgno*pPager->pageSize ){
  2796         -	  /* An IO error occured in one of the the sqlite3OsSeek() or
  2797         -          ** sqlite3OsRead() calls above. */
  2798         -          pPg->pgno = 0;
  2799         -          sqlite3pager_unref(PGHDR_TO_DATA(pPg));
  2800         -          return rc;
  2801         -        }else{
  2802         -          clear_simulated_io_error();
  2803         -          memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
  2804         -        }
         2797  +      if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
         2798  +        pPg->pgno = 0;
         2799  +        sqlite3pager_unref(PGHDR_TO_DATA(pPg));
         2800  +        return rc;
  2805   2801         }else{
  2806   2802           TEST_INCR(pPager->nRead);
  2807   2803         }
  2808   2804       }
  2809   2805   
  2810   2806       /* Link the page into the page hash table */
  2811   2807       h = pgno & (pPager->nHash-1);

Changes to src/pager.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite page cache
    13     13   ** subsystem.  The page cache subsystem reads and writes a file a page
    14     14   ** at a time and provides a journal for rollback.
    15     15   **
    16         -** @(#) $Id: pager.h,v 1.51 2006/08/08 13:51:43 drh Exp $
           16  +** @(#) $Id: pager.h,v 1.52 2006/11/06 21:20:26 drh Exp $
    17     17   */
    18     18   
    19     19   #ifndef _PAGER_H_
    20     20   #define _PAGER_H_
    21     21   
    22     22   /*
    23     23   ** The default size of a database page.
................................................................................
    71     71   */
    72     72   int sqlite3pager_open(Pager **ppPager, const char *zFilename,
    73     73                        int nExtra, int flags);
    74     74   void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
    75     75   void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
    76     76   void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
    77     77   int sqlite3pager_set_pagesize(Pager*, int);
    78         -void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
           78  +int sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
    79     79   void sqlite3pager_set_cachesize(Pager*, int);
    80     80   int sqlite3pager_close(Pager *pPager);
    81     81   int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage);
    82     82   void *sqlite3pager_lookup(Pager *pPager, Pgno pgno);
    83     83   int sqlite3pager_ref(void*);
    84     84   int sqlite3pager_unref(void*);
    85     85   Pgno sqlite3pager_pagenumber(void*);