Skip to content

Commit 9d93b51

Browse files
committed
MDEV-14425 fix inadverent changes on Windows
innodb_flush_log_on_trx_commit=2 means we want to write redo using filesystem buffering, and not flushing each time. Also simplify code, remove gotos, and comment on a bug in mariabackup that produces redo of odd sizes, that must be worked around by forcing file to be buffered.
1 parent 93756c9 commit 9d93b51

File tree

1 file changed

+41
-61
lines changed

1 file changed

+41
-61
lines changed

storage/innobase/os/os0file.cc

Lines changed: 41 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,21 @@ os_file_create_directory(
21072107
return(true);
21082108
}
21092109

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+
}
21102125

21112126
/** NOTE! Use the corresponding macro os_file_create(), not directly
21122127
this function!
@@ -2205,27 +2220,22 @@ os_file_create_func(
22052220
? FILE_FLAG_OVERLAPPED : 0;
22062221

22072222
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;
22092227
}
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;
22222238
}
2223-
break;
2224-
2225-
case SRV_FSYNC:
2226-
case SRV_LITTLESYNC:
2227-
case SRV_NOSYNC:
2228-
break;
22292239
}
22302240

22312241
DWORD access = GENERIC_READ;
@@ -2243,41 +2253,17 @@ os_file_create_func(
22432253
create_flag, attributes, NULL);
22442254

22452255
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) {
22542262
attributes &= ~FILE_FLAG_NO_BUFFERING;
22552263
create_flag = OPEN_ALWAYS;
2264+
CloseHandle(file);
22562265
continue;
22572266
}
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));
22812267
}
22822268

22832269
*success = (file != INVALID_HANDLE_VALUE);
@@ -2576,18 +2562,12 @@ bool os_file_close_func(os_file_t file)
25762562
/** Gets a file size.
25772563
@param[in] file Handle to a file
25782564
@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)
25822566
{
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);
25912571
}
25922572

25932573
/** Gets a file size.

0 commit comments

Comments
 (0)