SQLite

Check-in [61a6ccbe3c]
Login

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

Overview
Comment:Fix a benign inaccuracy in the os_unix.c SQLITE_FCNTL_SIZE_HINT code.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 61a6ccbe3c9c3ad5f35fb325e3c327cb19409925
User & Date: dan 2011-04-06 19:15:45.675
Context
2011-04-06
22:05
Fix a performance regression: Keep two btree masks in each prepared statement; one for btrees used and another for btrees that require locks. Only try to lock the btrees identified by the second mask. (check-in: 614de91a50 user: drh tags: trunk)
19:15
Fix a benign inaccuracy in the os_unix.c SQLITE_FCNTL_SIZE_HINT code. (check-in: 61a6ccbe3c user: dan tags: trunk)
17:54
Changes to support building with various SQLITE_OMIT_XXX options defined. (check-in: 2039ed952a user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/os_unix.c.
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412


3413
3414
3415
3416
3417
3418
3419
      ** ftruncate() to set the file size, then write a single byte to
      ** the last byte in each block within the extended region. This
      ** is the same technique used by glibc to implement posix_fallocate()
      ** on systems that do not have a real fallocate() system call.
      */
      int nBlk = buf.st_blksize;  /* File-system block size */
      i64 iWrite;                 /* Next offset to write to */
      int nWrite;                 /* Return value from seekAndWrite() */

      if( robust_ftruncate(pFile->h, nSize) ){
        pFile->lastErrno = errno;
        return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
      }
      iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
      do {
        nWrite = seekAndWrite(pFile, iWrite, "", 1);
        iWrite += nBlk;
      } while( nWrite==1 && iWrite<nSize );
      if( nWrite!=1 ) return SQLITE_IOERR_WRITE;


#endif
    }
  }

  return SQLITE_OK;
}








<






|
|
<
<
|
>
>







3394
3395
3396
3397
3398
3399
3400

3401
3402
3403
3404
3405
3406
3407
3408


3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
      ** ftruncate() to set the file size, then write a single byte to
      ** the last byte in each block within the extended region. This
      ** is the same technique used by glibc to implement posix_fallocate()
      ** on systems that do not have a real fallocate() system call.
      */
      int nBlk = buf.st_blksize;  /* File-system block size */
      i64 iWrite;                 /* Next offset to write to */


      if( robust_ftruncate(pFile->h, nSize) ){
        pFile->lastErrno = errno;
        return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
      }
      iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
      while( iWrite<nSize ){
        int nWrite = seekAndWrite(pFile, iWrite, "", 1);


        if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
        iWrite += nBlk;
      }
#endif
    }
  }

  return SQLITE_OK;
}

Changes to test/syscall.test.
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250




















251
252
253
254
255
256
257
forcedelete test.db test.db2

do_test 8.1 {
  sqlite3 db test.db
  file_control_chunksize_test db main 4096
  file size test.db
} {0}

foreach {tn hint size} {
  1  1000    4096 
  2  1000    4096 
  3  3000    4096 
  4  4096    4096 
  5  4197    8192 
} {
  do_test 8.2.$tn {




















    file_control_sizehint_test db main $hint
    file size test.db
  } $size
}

test_syscall reset
finish_test







<








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







235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
forcedelete test.db test.db2

do_test 8.1 {
  sqlite3 db test.db
  file_control_chunksize_test db main 4096
  file size test.db
} {0}

foreach {tn hint size} {
  1  1000    4096 
  2  1000    4096 
  3  3000    4096 
  4  4096    4096 
  5  4197    8192 
} {
  do_test 8.2.$tn {
    file_control_sizehint_test db main $hint
    file size test.db
  } $size
}

do_test 8.3 {
  db close
  forcedelete test.db test.db2
  sqlite3 db test.db
  file_control_chunksize_test db main 16
  file size test.db
} {0}
foreach {tn hint size} {
  1  5       16 
  2  13      16 
  3  45      48 
  4  48      48 
  5  49      64 
} {
  do_test 8.4.$tn {
    file_control_sizehint_test db main $hint
    file size test.db
  } $size
}

test_syscall reset
finish_test
Changes to test/wal.test.
1526
1527
1528
1529
1530
1531
1532
1533

1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
    CREATE TABLE t1(x);
    INSERT INTO t1 VALUES(randomblob(5000));
    INSERT INTO t1 SELECT * FROM t1;
    INSERT INTO t1 SELECT * FROM t1;
    INSERT INTO t1 SELECT * FROM t1;
    INSERT INTO t1 SELECT * FROM t1;
  } {wal}
  do_execsql_test 24.2 { 

    DELETE FROM t1;
    PRAGMA wal_checkpoint;
  } {0 109 109}
  do_test 24.3 {

    db close
    sqlite3 db test.db
    file exists test.db-wal
  } 0
  do_test 24.4 {
    file size test.db
  } [expr 84 * 1024]
  do_test 24.5 {
    execsql { 
      PRAGMA incremental_vacuum;
      PRAGMA wal_checkpoint;
    }
    file size test.db
  } [expr 3 * 1024]
  do_test 24.6 {
    file size test.db-wal
  } 2128
}

db close
sqlite3_shutdown
test_sqlite3_log







|
>
|
|
<
<
>




|


|






|







1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536


1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
    CREATE TABLE t1(x);
    INSERT INTO t1 VALUES(randomblob(5000));
    INSERT INTO t1 SELECT * FROM t1;
    INSERT INTO t1 SELECT * FROM t1;
    INSERT INTO t1 SELECT * FROM t1;
    INSERT INTO t1 SELECT * FROM t1;
  } {wal}
  do_test 24.2 { 
    execsql {
      DELETE FROM t1;
      PRAGMA wal_checkpoint;


    }
    db close
    sqlite3 db test.db
    file exists test.db-wal
  } 0
  do_test 24.3 {
    file size test.db
  } [expr 84 * 1024]
  do_test 24.4 {
    execsql { 
      PRAGMA incremental_vacuum;
      PRAGMA wal_checkpoint;
    }
    file size test.db
  } [expr 3 * 1024]
  do_test 24.5 {
    file size test.db-wal
  } 2128
}

db close
sqlite3_shutdown
test_sqlite3_log