@@ -2107,6 +2107,21 @@ os_file_create_directory(
2107
2107
return (true );
2108
2108
}
2109
2109
2110
+ /* * Get disk sector size for a file. */
2111
+ size_t get_sector_size (HANDLE file)
2112
+ {
2113
+ FILE_STORAGE_INFO fsi;
2114
+ ULONG s= 4096 ;
2115
+ if (GetFileInformationByHandleEx (file, FileStorageInfo, &fsi, sizeof fsi))
2116
+ {
2117
+ s= fsi.PhysicalBytesPerSectorForPerformance ;
2118
+ if (s > 4096 || s < 64 || !ut_is_2pow (s))
2119
+ {
2120
+ return 4096 ;
2121
+ }
2122
+ }
2123
+ return s;
2124
+ }
2110
2125
2111
2126
/* * NOTE! Use the corresponding macro os_file_create(), not directly
2112
2127
this function!
@@ -2205,27 +2220,22 @@ os_file_create_func(
2205
2220
? FILE_FLAG_OVERLAPPED : 0 ;
2206
2221
2207
2222
if (type == OS_LOG_FILE) {
2208
- attributes |= FILE_FLAG_NO_BUFFERING;
2223
+ if (srv_flush_log_at_trx_commit != 2 && !log_sys.is_opened ())
2224
+ attributes|= FILE_FLAG_NO_BUFFERING;
2225
+ if (srv_file_flush_method == SRV_O_DSYNC)
2226
+ attributes|= FILE_FLAG_WRITE_THROUGH;
2209
2227
}
2210
-
2211
- switch (srv_file_flush_method) {
2212
- case SRV_O_DSYNC:
2213
- if (type == OS_LOG_FILE) {
2214
- attributes |= FILE_FLAG_WRITE_THROUGH;
2215
- }
2216
- /* fall through */
2217
- case SRV_O_DIRECT_NO_FSYNC:
2218
- case SRV_O_DIRECT:
2219
- case SRV_ALL_O_DIRECT_FSYNC:
2220
- if (type != OS_DATA_FILE_NO_O_DIRECT) {
2221
- attributes |= FILE_FLAG_NO_BUFFERING;
2228
+ else if (type == OS_DATA_FILE)
2229
+ {
2230
+ switch (srv_file_flush_method)
2231
+ {
2232
+ case SRV_FSYNC:
2233
+ case SRV_LITTLESYNC:
2234
+ case SRV_NOSYNC:
2235
+ break ;
2236
+ default :
2237
+ attributes|= FILE_FLAG_NO_BUFFERING;
2222
2238
}
2223
- break ;
2224
-
2225
- case SRV_FSYNC:
2226
- case SRV_LITTLESYNC:
2227
- case SRV_NOSYNC:
2228
- break ;
2229
2239
}
2230
2240
2231
2241
DWORD access = GENERIC_READ;
@@ -2243,41 +2253,17 @@ os_file_create_func(
2243
2253
create_flag, attributes, NULL );
2244
2254
2245
2255
if (file != INVALID_HANDLE_VALUE && type == OS_LOG_FILE
2246
- && (attributes & FILE_FLAG_NO_BUFFERING)) {
2247
- if (log_sys.is_opened ()) {
2248
- /* If we are upgrading from multiple log files,
2249
- never disable buffering on other than the
2250
- first file. We only keep track of the block
2251
- size of the first file. */
2252
- no_o_direct:
2253
- ut_a (CloseHandle (file));
2256
+ && (attributes & FILE_FLAG_NO_BUFFERING)) {
2257
+ uint32 s= (uint32_t ) get_sector_size (file);
2258
+ log_sys.set_block_size (uint32_t (s));
2259
+ /* FIXME! remove it when backup is fixed, so that it
2260
+ does not produce redo with irregular sizes.*/
2261
+ if (os_file_get_size (file) % s) {
2254
2262
attributes &= ~FILE_FLAG_NO_BUFFERING;
2255
2263
create_flag = OPEN_ALWAYS;
2264
+ CloseHandle (file);
2256
2265
continue ;
2257
2266
}
2258
-
2259
- /* If FILE_FLAG_NO_BUFFERING was set on the log file,
2260
- check if this can work at all, for the expected sizes.
2261
- Reopen without the flag, if it won't work. */
2262
- DWORD high, low= GetFileSize (file, &high);
2263
- if (low & 4095 ) {
2264
- /* mariadb-backup creates odd-sized files that
2265
- will be resized before the log is being
2266
- written to */
2267
- skip_o_direct:
2268
- log_sys.set_block_size (0 );
2269
- goto no_o_direct;
2270
- }
2271
- FILE_STORAGE_INFO i;
2272
- if (!GetFileInformationByHandleEx (file, FileStorageInfo,
2273
- &i, sizeof i)) {
2274
- goto skip_o_direct;
2275
- }
2276
- const ULONG s = i.PhysicalBytesPerSectorForPerformance ;
2277
- if (s > 4096 || s < 64 || !ut_is_2pow (s)) {
2278
- goto skip_o_direct;
2279
- }
2280
- log_sys.set_block_size (uint32_t (s));
2281
2267
}
2282
2268
2283
2269
*success = (file != INVALID_HANDLE_VALUE);
@@ -2576,18 +2562,12 @@ bool os_file_close_func(os_file_t file)
2576
2562
/* * Gets a file size.
2577
2563
@param[in] file Handle to a file
2578
2564
@return file size, or (os_offset_t) -1 on failure */
2579
- os_offset_t
2580
- os_file_get_size (
2581
- os_file_t file)
2565
+ os_offset_t os_file_get_size (os_file_t file)
2582
2566
{
2583
- DWORD high;
2584
- DWORD low = GetFileSize (file, &high);
2585
-
2586
- if (low == 0xFFFFFFFF && GetLastError () != NO_ERROR) {
2587
- return ((os_offset_t ) -1 );
2588
- }
2589
-
2590
- return (os_offset_t (low | (os_offset_t (high) << 32 )));
2567
+ LARGE_INTEGER li;
2568
+ if (GetFileSizeEx (file, &li))
2569
+ return li.QuadPart ;
2570
+ return ((os_offset_t ) -1 );
2591
2571
}
2592
2572
2593
2573
/* * Gets a file size.
0 commit comments