/ Check-in [df204049]
Login

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

Overview
Comment:When syncing a memory mapped file on Windows, flush the mapped view as well.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | winViewFlush
Files: files | file ages | folders
SHA1: df204049b9ec8dd3e43ed7dc251eaecedc05af4b
User & Date: mistachkin 2015-03-26 23:36:35
Context
2015-03-27
18:22
Merge updates from trunk. Closed-Leaf check-in: 45acf6a8 user: mistachkin tags: winViewFlush
2015-03-26
23:36
When syncing a memory mapped file on Windows, flush the mapped view as well. check-in: df204049 user: mistachkin tags: winViewFlush
18:24
Revise Win32 locking test to account for recent log message changes. check-in: 1bc76339 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

   193    193           DWORD, DWORD, DWORD, LPCWSTR);
   194    194   #endif /* defined(SQLITE_WIN32_HAS_WIDE) */
   195    195   
   196    196   WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
   197    197   #endif /* SQLITE_OS_WINRT */
   198    198   
   199    199   /*
   200         -** This file mapping API is common to both Win32 and WinRT.
          200  +** These file mapping APIs are common to both Win32 and WinRT.
   201    201   */
          202  +
          203  +WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T);
   202    204   WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
   203    205   #endif /* SQLITE_WIN32_FILEMAPPING_API */
   204    206   
   205    207   /*
   206    208   ** Some Microsoft compilers lack this definition.
   207    209   */
   208    210   #ifndef INVALID_FILE_ATTRIBUTES
................................................................................
  1079   1081   #else
  1080   1082     { "UuidCreateSequential",     (SYSCALL)0,                      0 },
  1081   1083   #endif
  1082   1084   
  1083   1085   #define osUuidCreateSequential \
  1084   1086           ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
  1085   1087   
         1088  +#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
         1089  +  { "FlushViewOfFile",          (SYSCALL)FlushViewOfFile,        0 },
         1090  +#else
         1091  +  { "FlushViewOfFile",          (SYSCALL)0,                      0 },
         1092  +#endif
         1093  +
         1094  +#define osFlushViewOfFile \
         1095  +        ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
         1096  +
  1086   1097   }; /* End of the overrideable system calls */
  1087   1098   
  1088   1099   /*
  1089   1100   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
  1090   1101   ** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
  1091   1102   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
  1092   1103   ** system call named zName.
................................................................................
  2749   2760     );
  2750   2761   
  2751   2762     /* Unix cannot, but some systems may return SQLITE_FULL from here. This
  2752   2763     ** line is to test that doing so does not cause any problems.
  2753   2764     */
  2754   2765     SimulateDiskfullError( return SQLITE_FULL );
  2755   2766   
  2756         -  OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n",
  2757         -           pFile->h, flags, pFile->locktype));
         2767  +  OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n",
         2768  +           osGetCurrentProcessId(), pFile, pFile->h, flags,
         2769  +           pFile->locktype));
  2758   2770   
  2759   2771   #ifndef SQLITE_TEST
  2760   2772     UNUSED_PARAMETER(flags);
  2761   2773   #else
  2762   2774     if( (flags&0x0F)==SQLITE_SYNC_FULL ){
  2763   2775       sqlite3_fullsync_count++;
  2764   2776     }
................................................................................
  2765   2777     sqlite3_sync_count++;
  2766   2778   #endif
  2767   2779   
  2768   2780     /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
  2769   2781     ** no-op
  2770   2782     */
  2771   2783   #ifdef SQLITE_NO_SYNC
  2772         -  OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h));
         2784  +  OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2785  +           osGetCurrentProcessId(), pFile, pFile->h));
  2773   2786     return SQLITE_OK;
  2774   2787   #else
         2788  +#if SQLITE_MAX_MMAP_SIZE>0
         2789  +  if( pFile->pMapRegion ){
         2790  +    if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
         2791  +      OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
         2792  +               "rc=SQLITE_OK\n", osGetCurrentProcessId(),
         2793  +               pFile, pFile->pMapRegion));
         2794  +    }else{
         2795  +      pFile->lastErrno = osGetLastError();
         2796  +      OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
         2797  +               "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(),
         2798  +               pFile, pFile->pMapRegion));
         2799  +      return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
         2800  +                         "winSync1", pFile->zPath);
         2801  +    }
         2802  +  }
         2803  +#endif
  2775   2804     rc = osFlushFileBuffers(pFile->h);
  2776   2805     SimulateIOError( rc=FALSE );
  2777   2806     if( rc ){
  2778         -    OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h));
         2807  +    OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2808  +             osGetCurrentProcessId(), pFile, pFile->h));
  2779   2809       return SQLITE_OK;
  2780   2810     }else{
  2781   2811       pFile->lastErrno = osGetLastError();
  2782         -    OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h));
         2812  +    OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n",
         2813  +             osGetCurrentProcessId(), pFile, pFile->h));
  2783   2814       return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
  2784         -                       "winSync", pFile->zPath);
         2815  +                       "winSync2", pFile->zPath);
  2785   2816     }
  2786   2817   #endif
  2787   2818   }
  2788   2819   
  2789   2820   /*
  2790   2821   ** Determine the current size of a file in bytes
  2791   2822   */
................................................................................
  5551   5582       winGetSystemCall,    /* xGetSystemCall */
  5552   5583       winNextSystemCall,   /* xNextSystemCall */
  5553   5584     };
  5554   5585   #endif
  5555   5586   
  5556   5587     /* Double-check that the aSyscall[] array has been constructed
  5557   5588     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  5558         -  assert( ArraySize(aSyscall)==79 );
         5589  +  assert( ArraySize(aSyscall)==80 );
  5559   5590   
  5560   5591     /* get memory map allocation granularity */
  5561   5592     memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  5562   5593   #if SQLITE_OS_WINRT
  5563   5594     osGetNativeSystemInfo(&winSysInfo);
  5564   5595   #else
  5565   5596     osGetSystemInfo(&winSysInfo);