Skip to content

Commit 6505662

Browse files
committed
MDEV-25121: innodb_flush_method=O_DIRECT fails on compressed tables
Tests with 4096-byte sector size confirm that it is safe to use O_DIRECT with page_compressed tables. That had been disabled on Linux, in an attempt to fix MDEV-21584 which had been filed for the O_DIRECT problems earlier. The fil_node_t::block_size was being set mostly correctly until commit 10dd290 (MDEV-17380) introduced a regression in MariaDB Server 10.4.4. fil_node_t::read_page0(): Initialize fil_node_t::block_size. This will probably make similar code in fil_space_extend_must_retry() redundant, but we play it safe and will not remove that code. Thanks to Vladislav Vaintroub for testing this on Microsoft Windows using an old-fashioned rotational hard disk with 4KiB sector size. Reviewed by: Vladislav Vaintroub
1 parent 00f620b commit 6505662

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

storage/innobase/fil/fil0fil.cc

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ bool fil_node_t::read_page0(bool first)
566566

567567
this->size = ulint(size_bytes / psize);
568568
space->committed_size = space->size += this->size;
569+
570+
if (block_size == 0) {
571+
block_size = os_file_get_block_size(handle, name);
572+
}
569573
} else if (space->id != TRX_SYS_SPACE || space->size_in_header) {
570574
/* If this is not the first-time open, do nothing.
571575
For the system tablespace, we always get invoked as
@@ -605,12 +609,15 @@ static bool fil_node_open_file(fil_node_t* node)
605609

606610
const bool first_time_open = node->size == 0;
607611

608-
bool o_direct_possible = !FSP_FLAGS_HAS_PAGE_COMPRESSION(space->flags);
609-
if (const ulint ssize = FSP_FLAGS_GET_ZIP_SSIZE(space->flags)) {
610-
compile_time_assert(((UNIV_ZIP_SIZE_MIN >> 1) << 3) == 4096);
611-
if (ssize < 3) {
612-
o_direct_possible = false;
613-
}
612+
ulint type;
613+
compile_time_assert(((UNIV_ZIP_SIZE_MIN >> 1) << 3) == 4096);
614+
switch (FSP_FLAGS_GET_ZIP_SSIZE(space->flags)) {
615+
case 1:
616+
case 2:
617+
type = OS_DATA_FILE_NO_O_DIRECT;
618+
break;
619+
default:
620+
type = OS_DATA_FILE;
614621
}
615622

616623
if (first_time_open
@@ -632,9 +639,7 @@ static bool fil_node_open_file(fil_node_t* node)
632639
? OS_FILE_OPEN_RAW | OS_FILE_ON_ERROR_NO_EXIT
633640
: OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
634641
OS_FILE_AIO,
635-
o_direct_possible
636-
? OS_DATA_FILE
637-
: OS_DATA_FILE_NO_O_DIRECT,
642+
type,
638643
read_only_mode,
639644
&success);
640645

@@ -668,9 +673,7 @@ static bool fil_node_open_file(fil_node_t* node)
668673
? OS_FILE_OPEN_RAW | OS_FILE_ON_ERROR_NO_EXIT
669674
: OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
670675
OS_FILE_AIO,
671-
o_direct_possible
672-
? OS_DATA_FILE
673-
: OS_DATA_FILE_NO_O_DIRECT,
676+
type,
674677
read_only_mode,
675678
&success);
676679
}
@@ -3601,11 +3604,22 @@ fil_ibd_create(
36013604
return(err);
36023605
}
36033606

3607+
ulint type;
3608+
compile_time_assert(((UNIV_ZIP_SIZE_MIN >> 1) << 3) == 4096);
3609+
switch (FSP_FLAGS_GET_ZIP_SSIZE(flags)) {
3610+
case 1:
3611+
case 2:
3612+
type = OS_DATA_FILE_NO_O_DIRECT;
3613+
break;
3614+
default:
3615+
type = OS_DATA_FILE;
3616+
}
3617+
36043618
file = os_file_create(
36053619
innodb_data_file_key, path,
36063620
OS_FILE_CREATE | OS_FILE_ON_ERROR_NO_EXIT,
36073621
OS_FILE_NORMAL,
3608-
OS_DATA_FILE,
3622+
type,
36093623
srv_read_only_mode,
36103624
&success);
36113625

0 commit comments

Comments
 (0)