/ Check-in [7fdc78a6]
Login

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

Overview
Comment:Add the --fsync flag to kvtest, and document the --nosync flag.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7fdc78a672b2ea6187dcb5fdf32f809bb8e4d501e2434f2233edc3bc2e3acc7c
User & Date: drh 2017-06-02 23:32:17
Context
2017-06-03
15:17
Add the --nocheckpoint and --multitrans options to kvtest. check-in: 5828633c user: drh tags: trunk
2017-06-02
23:44
Merge all recent trunk enhancements. check-in: 1d23294d user: drh tags: lsm-vtab
23:32
Add the --fsync flag to kvtest, and document the --nosync flag. check-in: 7fdc78a6 user: drh tags: trunk
19:31
Work toward enhancing kvtest to measure write performance. check-in: fc73e7d2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/kvtest.c.

    86     86   "        database or a directory containing sample files.  Options:\n"
    87     87   "\n"
    88     88   "           --asc                  Read blobs in ascending order\n"
    89     89   "           --blob-api             Use the BLOB API\n"
    90     90   "           --cache-size N         Database cache size\n"
    91     91   "           --count N              Read N blobs\n"
    92     92   "           --desc                 Read blobs in descending order\n"
    93         -"           --integrity-check      Run 'PRAGMA integrity_check' after test\n"
           93  +"           --fsync                Synchronous file writes\n"
           94  +"           --integrity-check      Run \"PRAGMA integrity_check\" after test\n"
    94     95   "           --max-id N             Maximum blob key to use\n"
    95     96   "           --mmap N               Mmap as much as N bytes of DBFILE\n"
           97  +"           --nosync               Set \"PRAGMA synchronous=OFF\"\n"
    96     98   "           --jmode MODE           Set MODE journal mode prior to starting\n"
    97     99   "           --random               Read blobs in a random order\n"
    98    100   "           --start N              Start reading with this blob key\n"
    99    101   "           --stats                Output operating stats before exiting\n"
   100    102   "           --update               To an overwrite test\n"
   101    103   ;
   102    104   
................................................................................
   537    539     return pBuf;
   538    540   }
   539    541   
   540    542   /*
   541    543   ** Overwrite a file with randomness.  Do not change the size of the
   542    544   ** file.
   543    545   */
   544         -static void updateFile(const char *zName, int *pnByte){
          546  +static void updateFile(const char *zName, int *pnByte, int doFsync){
   545    547     FILE *out;              /* FILE from which to read content of zName */
   546    548     sqlite3_int64 sz;       /* Size of zName in bytes */
   547    549     size_t nWritten;        /* Number of bytes actually read */
   548    550     unsigned char *pBuf;    /* Content to store on disk */
          551  +  const char *zMode = "wb";   /* Mode for fopen() */
   549    552   
   550    553     sz = fileSize(zName);
   551    554     if( sz<0 ){
   552    555       fatalError("No such file: \"%s\"", zName);
   553    556     }
   554    557     *pnByte = (int)sz;
   555    558     if( sz==0 ) return;
   556    559     pBuf = sqlite3_malloc64( sz );
   557    560     if( pBuf==0 ){
   558    561       fatalError("Cannot allocate %lld bytes\n", sz);
   559    562     }
   560    563     sqlite3_randomness((int)sz, pBuf); 
   561         -  out = fopen(zName, "wb");
          564  +#if defined(_WIN32)
          565  +  if( doFsync ) zMode = "wbc";
          566  +#endif
          567  +  out = fopen(zName, zMode);
   562    568     if( out==0 ){
   563    569       fatalError("Cannot open \"%s\" for writing\n", zName);
   564    570     }
   565    571     nWritten = fwrite(pBuf, 1, (size_t)sz, out);
          572  +  if( doFsync ){
          573  +#if defined(_WIN32)
          574  +    fflush(out);
          575  +#else
          576  +    fsync(fileno(out));
          577  +#endif
          578  +  }
   566    579     fclose(out);
   567    580     if( nWritten!=(size_t)sz ){
   568    581       fatalError("Wrote only %d of %d bytes to \"%s\"\n",
   569    582                  (int)nWritten, (int)sz, zName);
   570    583     }
   571    584     sqlite3_free(pBuf);
   572    585   }
................................................................................
   724    737     int iCache = 1000;          /* Database cache size in kibibytes */
   725    738     int bBlobApi = 0;           /* Use the incremental blob I/O API */
   726    739     int bStats = 0;             /* Print stats before exiting */
   727    740     int eOrder = ORDER_ASC;     /* Access order */
   728    741     int isUpdateTest = 0;       /* Do in-place updates rather than reads */
   729    742     int doIntegrityCk = 0;      /* Run PRAGMA integrity_check after the test */
   730    743     int noSync = 0;             /* Disable synchronous mode */
          744  +  int doFsync = 0;            /* Update disk files synchronously */
   731    745     sqlite3 *db = 0;            /* Database connection */
   732    746     sqlite3_stmt *pStmt = 0;    /* Prepared statement for SQL access */
   733    747     sqlite3_blob *pBlob = 0;    /* Handle for incremental Blob I/O */
   734    748     sqlite3_int64 tmStart;      /* Start time */
   735    749     sqlite3_int64 tmElapsed;    /* Elapsed time */
   736    750     int mmapSize = 0;           /* --mmap N argument */
   737    751     int nData = 0;              /* Bytes of data */
................................................................................
   811    825       if( strcmp(z, "-integrity-check")==0 ){
   812    826         doIntegrityCk = 1;
   813    827         continue;
   814    828       }
   815    829       if( strcmp(z, "-nosync")==0 ){
   816    830         noSync = 1;
   817    831         continue;
          832  +    }
          833  +    if( strcmp(z, "-fsync")==0 ){
          834  +      doFsync = 1;
          835  +      continue;
   818    836       }
   819    837       fatalError("unknown option: \"%s\"", argv[i]);
   820    838     }
   821    839     if( eType==PATH_DB ){
   822    840       /* Recover any prior crashes prior to starting the timer */
   823    841       sqlite3_open(zDb, &db);
   824    842       sqlite3_exec(db, "SELECT rowid FROM sqlite_master LIMIT 1", 0, 0, 0);
................................................................................
   880    898     for(i=0; i<nCount; i++){
   881    899       if( eType==PATH_DIR ){
   882    900         /* CASE 1: Reading blobs out of separate files */
   883    901         char *zKey;
   884    902         zKey = sqlite3_mprintf("%s/%06d", zDb, iKey);
   885    903         nData = 0;
   886    904         if( isUpdateTest ){
   887         -        updateFile(zKey, &nData);
          905  +        updateFile(zKey, &nData, doFsync);
   888    906         }else{
   889    907           pData = readFile(zKey, &nData);
   890    908           sqlite3_free(pData);
   891    909         }
   892    910         sqlite3_free(zKey);
   893    911       }else if( bBlobApi ){
   894    912         /* CASE 2: Reading from database using the incremental BLOB I/O API */