diff --git a/databases/mariadb103-server/files/patch-MDEV-26537 b/databases/mariadb103-server/files/patch-MDEV-26537 new file mode 100644 index 000000000000..05cf0f5a4ebc --- /dev/null +++ b/databases/mariadb103-server/files/patch-MDEV-26537 @@ -0,0 +1,126 @@ +From d09426f9e60fd93296464ec9eb5f9d85566437d3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= +Date: Fri, 10 Sep 2021 19:15:41 +0300 +Subject: [PATCH] MDEV-26537 InnoDB corrupts files due to incorrect st_blksize + calculation + +The st_blksize returned by fstat(2) is not documented to be +a power of 2, like we assumed in +commit 58252fff15acfe7c7b0452a87e202e3f8e454e19 (MDEV-26040). +While on Linux, the st_blksize appears to report the file system +block size (which hopefully is not smaller than the sector size +of the underlying block device), on FreeBSD we observed +st_blksize values that might have been something similar to st_size. + +Also IBM AIX was affected by this. A simple test case would +lead to a crash when using the minimum innodb_buffer_pool_size=5m +on both FreeBSD and AIX: + +seq -f 'create table t%g engine=innodb select * from seq_1_to_200000;' \ +1 100|mysql test& +seq -f 'create table u%g engine=innodb select * from seq_1_to_200000;' \ +1 100|mysql test& + +We will fix this by not trusting st_blksize at all, and assuming that +the smallest allowed write size (for O_DIRECT) is 4096 bytes. We hope +that no storage systems with larger block size exist. Anything larger +than 4096 bytes should be unlikely, given that it is the minimum +virtual memory page size of many contemporary processors. + +MariaDB Server on Microsoft Windows was not affected by this. + +While the 512-byte sector size of the venerable Seagate ST-225 is still +in widespread use, the minimum innodb_page_size is 4096 bytes, and +innodb_log_file_size can be set in integer multiples of 65536 bytes. + +The only occasion where InnoDB uses smaller data file block sizes than +4096 bytes is with ROW_FORMAT=COMPRESSED tables with KEY_BLOCK_SIZE=1 +or KEY_BLOCK_SIZE=2 (or innodb_page_size=4096). For such tables, +we will from now on preallocate space in integer multiples of 4096 bytes +and let regular writes extend the file by 1024, 2048, or 3072 bytes. + +The view INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES.FS_BLOCK_SIZE +should report the raw st_blksize. + +For page_compressed tables, the function fil_space_get_block_size() +will map to 512 any st_blksize value that is larger than 4096. + +os_file_set_size(): Assume that the file system block size is 4096 bytes, +and only support extending files to integer multiples of 4096 bytes. + +fil_space_extend_must_retry(): Round down the preallocation size to +an integer multiple of 4096 bytes. +--- mysql-test/suite/innodb/t/check_ibd_filesize.test.orig 2021-08-02 10:58:56 UTC ++++ mysql-test/suite/innodb/t/check_ibd_filesize.test +@@ -46,6 +46,12 @@ perl; + print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; + EOF + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; ++# Ensure that the file will be extended with the last 1024-byte page ++# after the file was pre-extended in 4096-byte increments. ++--disable_query_log ++FLUSH TABLE t1 FOR EXPORT; ++UNLOCK TABLES; ++--enable_query_log + perl; + print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; + EOF + mysql-test/suite/innodb/t/check_ibd_filesize.test | 6 ++++++ + storage/innobase/fil/fil0fil.cc | 13 +++++++++---- + storage/innobase/os/os0file.cc | 7 ++++--- + 3 files changed, 19 insertions(+), 7 deletions(-) + +--- storage/innobase/fil/fil0fil.cc.orig 2021-08-02 10:58:57 UTC ++++ storage/innobase/fil/fil0fil.cc +@@ -942,11 +942,17 @@ fil_space_extend_must_retry( + const page_size_t pageSize(space->flags); + const ulint page_size = pageSize.physical(); + +- /* fil_read_first_page() expects srv_page_size bytes. +- fil_node_open_file() expects at least 4 * srv_page_size bytes.*/ +- os_offset_t new_size = std::max( +- os_offset_t(size - file_start_page_no) * page_size, ++ /* fil_read_first_page() expects innodb_page_size bytes. ++ fil_node_open_file() expects at least 4 * innodb_page_size bytes. ++ os_file_set_size() expects multiples of 4096 bytes. ++ For ROW_FORMAT=COMPRESSED tables using 1024-byte or 2048-byte ++ pages, we will preallocate up to an integer multiple of 4096 bytes, ++ and let normal writes append 1024, 2048, or 3072 bytes to the file. */ ++ os_offset_t new_size = std::max( ++ (os_offset_t(size - file_start_page_no) * page_size) ++ & ~os_offset_t(4095), + os_offset_t(FIL_IBD_FILE_INITIAL_SIZE << srv_page_size_shift)); ++ + + *success = os_file_set_size(node->name, node->handle, new_size, + FSP_FLAGS_HAS_PAGE_COMPRESSION(space->flags)); +--- storage/innobase/os/os0file.cc.orig 2021-08-02 10:58:57 UTC ++++ storage/innobase/os/os0file.cc +@@ -5351,6 +5351,8 @@ os_file_set_size( + os_offset_t size, + bool is_sparse) + { ++ ut_ad(!(size & 4095)); ++ + #ifdef _WIN32 + /* On Windows, changing file size works well and as expected for both + sparse and normal files. +@@ -5392,7 +5394,7 @@ fallback: + if (current_size >= size) { + return true; + } +- current_size &= ~os_offset_t(statbuf.st_blksize - 1); ++ current_size &= ~4095ULL; + err = posix_fallocate(file, current_size, + size - current_size); + } +@@ -5432,8 +5434,7 @@ fallback: + if (fstat(file, &statbuf)) { + return false; + } +- os_offset_t current_size = statbuf.st_size +- & ~os_offset_t(statbuf.st_blksize - 1); ++ os_offset_t current_size = statbuf.st_size & ~4095ULL; + #endif + if (current_size >= size) { + return true; diff --git a/databases/mariadb104-server/Makefile b/databases/mariadb104-server/Makefile index df85b463fda6..eef8cc75b7de 100644 --- a/databases/mariadb104-server/Makefile +++ b/databases/mariadb104-server/Makefile @@ -1,263 +1,264 @@ # Created by: Bernard Spil PORTNAME?= mariadb PORTVERSION= 10.4.21 +PORTREVISION?= 1 CATEGORIES= databases MASTER_SITES= http://mirrors.supportex.net/${SITESDIR}/ \ http://mirror2.hs-esslingen.de/pub/Mirrors/${SITESDIR}/ \ http://gd.tuwien.ac.at/db/${SITESDIR}/ \ http://mirrors.fe.up.pt/pub/${SITESDIR}/ \ http://mirror.de.gsnw.de:56431/${SITESDIR}/ \ http://mirror.layerjet.com/${SITESDIR}/ \ http://mirror.switch.ch/mirror/${SITESDIR}/ \ http://ftp.osuosl.org/pub/${SITESDIR}/ PKGNAMESUFFIX?= 104-server MAINTAINER= brnrd@FreeBSD.org COMMENT?= Multithreaded SQL database (server) LICENSE= GPLv2 LICENSE_FILE= ${WRKSRC}/COPYING USES= bison:build cmake:insource,noninja compiler:c++11-lib cpe iconv:translit libedit ncurses shebangfix ssl SUB_FILES= pkg-message PKGMESSAGE= ${WRKDIR}/pkg-message USE_LDCONFIG= ${PREFIX}/lib/mysql SHEBANG_FILES= scripts/*.sh SITESDIR= mariadb/mariadb-${PORTVERSION}/source DOCSDIR= ${PREFIX}/share/doc/mysql ETCDIR= ${PREFIX}/etc/mysql MARIADB_USER?= mysql MARIADB_GROUP?= mysql MARIADB_RUNDIR?= /var/run/mysql MARIADB_SOCK?= mysql.sock MARIADB_LOGDIR?= /var/log/mysql OPTIONS_SINGLE= GSSAPI OPTIONS_SINGLE_GSSAPI= GSSAPI_BASE GSSAPI_HEIMDAL GSSAPI_MIT GSSAPI_NONE OPTIONS_DEFAULT= GSSAPI_BASE .if ${PKGNAMESUFFIX:M*-server} # MySQL-Server options OPTIONS_DEFAULT+= CONNECT_EXTRA INNOBASE SPHINX SPIDER WSREP OPTIONS_GROUP= COMPRESSION ENGINES GROONGA OPTIONS_DEFINE= CONNECT_EXTRA DOCS OPTIONS_DEFINE_amd64= WSREP OPTIONS_GROUP_COMPRESSION= LZ4 LZO SNAPPY ZSTD OPTIONS_GROUP_ENGINES= INNOBASE MROONGA OQGRAPH ROCKSDB SPHINX SPIDER TOKUDB OPTIONS_GROUP_GROONGA= ZMQ MSGPACK OPTIONS_EXCLUDE_i386= ROCKSDB TOKUDB CONNECT_EXTRA_DESC= Enable ODBC and XML in CONNECT engine COMPRESSION_DESC= Optional page compression ENGINES_DESC= Optional MariaDB storage engines GROONGA_DESC= Optional Mroonga features INNOBASE_DESC= InnoDB default engine MROONGA_DESC= Mroonga Full Text Search engine MSGPACK_DESC= MsgPack support OQGRAPH_DESC= Open Query Graph Computation engine ROCKSDB_DESC= RocksDB LSM engine (Alpha) SPHINX_DESC= SphinxSE engine SPIDER_DESC= Partitioning and XA-transactions engine TOKUDB_DESC= Fractal tree index tree data structure engine WSREP_DESC= Build wsrep clustering ZMQ_DESC= ZeroMQ support ZSTD_DESC+= Zstandard compression support (RocksDB only) .endif CMAKE_ARGS+= -DINSTALL_DOCDIR="share/doc/mysql" \ -DINSTALL_DOCREADMEDIR="share/doc/mysql" \ -DINSTALL_INCLUDEDIR="include/mysql" \ -DINSTALL_INFODIR="info" \ -DINSTALL_LIBDIR="lib/mysql" \ -DINSTALL_MANDIR="man" \ -DINSTALL_MYSQLDATADIR="/var/db/mysql" \ -DINSTALL_MYSQLSHAREDIR="share/mysql" \ -DINSTALL_MYSQLTESTDIR= \ -DINSTALL_PLUGINDIR="lib/mysql/plugin" \ -DINSTALL_SBINDIR="libexec" \ -DINSTALL_SCRIPTDIR="bin" \ -DINSTALL_SHAREDIR="share" \ -DINSTALL_SQLBENCHDIR= \ -DINSTALL_SUPPORTFILESDIR="share/mysql" \ -DDEFAULT_SYSCONFDIR="${PREFIX}/etc" \ -DDEFAULT_SYSCONF2DIR="${ETCDIR}/conf.d" \ -DINSTALL_UNIX_ADDRDIR="${MARIADB_RUNDIR}/${MARIADB_SOCK}" \ -DWITH_SSL="${OPENSSLBASE}" \ -DCURSES_CURSES_LIBRARY="/usr/lib/libcurses.so" \ -DCURSES_FORM_LIBRARY="/usr/lib/libform.so" \ -DCURSES_CURSES_LIBRARY="/usr/lib/libncurses.so" \ -DKRB5_CONFIG="${KRB5CONFIG}" \ -DCURSES_NCURSES_LIBRARY="${NCURSESLIB}/libncurses.so" \ -DCOMPILATION_COMMENT="FreeBSD Ports" \ -DCMAKE_PREFIX_PATH=${PREFIX} CMAKE_OFF+= CONC_WITH_UNIT_TESTS CONNECT_WITH_MONGO WITH_UNIT_TESTS CMAKE_ON+= WITH_LIBWRAP WITHOUT_DOCS DISABLED_PLUGINS+= AUTH_TEST_PLUGIN DAEMON_EXAMPLE DIALOG_EXAMPLES \ EXAMPLE EXAMPLE_KEY_MANAGEMENT FTEXAMPLE DATADIR= ${PREFIX}/share/mysql ETCDIR= ${PREFIX}/etc/mysql CONFLICTS_INSTALL= mariadb10[0-24-9]-${PKGNAMESUFFIX:C/^[0-9]*-//}-* \ mysql[0-9]*-${PKGNAMESUFFIX:C/^[0-9]*-//}-* \ mysqlwsrep* \ percona[0-9]*-${PKGNAMESUFFIX:C/^[0-9]*-//}-* FASTMTX_CMAKE_BOOL= WITH_FAST_MUTEXES GSSAPI_BASE_USES= gssapi GSSAPI_HEIMDAL_USES= gssapi:heimdal GSSAPI_MIT_USES= gssapi:mit GSSAPI_NONE_CMAKE_ON= -DPLUGIN_AUTH_GSSAPI_CLIENT=OFF OPTIONS_SUB= yes SUB_LIST+= MARIADB_USER="${MARIADB_USER}" \ MARIADB_RUNDIR="${MARIADB_RUNDIR}" \ MARIADB_SOCK="${MARIADB_SOCK}" PLIST_SUB+= MARIADB_USER="${MARIADB_USER}" \ MARIADB_GROUP="${MARIADB_GROUP}" .if ${PKGNAMESUFFIX:M*-client} # MySQL-Client part CMAKE_ON+= CONC_WITH_MYSQLCOMPAT WITHOUT_SERVER CMAKE_OFF+= WITH_WSREP USES+= readline USE_LDCONFIG= ${PREFIX}/lib/mysql SUB_FILES+= my.cnf.sample client.cnf.sample PLIST_SUB+= MARIADB_RUNDIR="${MARIADB_RUNDIR}" .else # ! ${PKGNAMESUFFIX:M*-client} # MySQL-Server part USES+= mysql:104m USE_LDCONFIG+= ${PREFIX}/lib/mysql/plugin USE_RC_SUBR= mysql-server USERS= ${MARIADB_USER} GROUPS= ${MARIADB_GROUP} CMAKE_ON+= CMAKE_SKIP_BUILD_RPATH WITH_EMBEDDED_SERVER CMAKE_OFF+= WITH_CLIENT SUB_FILES+= server.cnf.sample SUB_LIST+= MARIADB_LOGDIR="${MARIADB_LOGDIR}" PLIST_SUB+= MARIADB_LOGDIR="${MARIADB_LOGDIR}" .for ENGINE in ${OPTIONS_GROUP_ENGINES:NINNOBASE} ${ENGINE}_CMAKE_OFF= -DPLUGIN_${ENGINE}=NO ${ENGINE}_CMAKE_ON= -DPLUGIN_${ENGINE}=DYNAMIC .endfor INNOBASE_VARS_OFF= disabled_plugins+=INNOBASE CONNECT_EXTRA_LIB_DEPENDS= libodbc.so:databases/unixODBC CONNECT_EXTRA_USE= gnome=libxml2 CONNECT_EXTRA_USES= gnome CONNECT_EXTRA_CMAKE_BOOL= CONNECT_WITH_LIBXML2 CONNECT_WITH_ODBC GSSAPI_NONE_VARS= disabled_plugins+=AUTH_GSSAPI LZ4_CMAKE_ON= -DGRN_WITH_LZ4=ON -DWITH_INNODB_LZ4=ON -DWITH_ROCKSDB_LZ4=ON LZ4_CMAKE_OFF= -DGRN_WITH_LZ4=OFF -DWITH_INNODB_LZ4=OFF -DWITH_ROCKSDB_LZ4=OFF LZ4_LIB_DEPENDS= liblz4.so:archivers/liblz4 LZO_CMAKE_ON= -DWITH_INNODB_LZO=ON LZO_CMAKE_OFF= -DWITH_INNODB_LZO=OFF LZO_LIB_DEPENDS= liblzo2.so:archivers/lzo2 MROONGA_IMPLIES= LZ4 MSGPACK_LIB_DEPENDS= libmsgpackc.so:devel/msgpack OQGRAPH_LIB_DEPENDS= libboost_system.so:devel/boost-libs \ libJudy.so:devel/judy ROCKSDB_USES= python ROCKSDB_CMAKE_ON= -DPYTHON_SHEBANG=${PYTHON_CMD} SNAPPY_CMAKE_ON= -DWITH_INNODB_SNAPPY=ON -DWITH_ROCKSDB_snappy=ON SNAPPY_CMAKE_OFF= -DWITH_INNODB_SNAPPY=OFF -DWITH_ROCKSDB_snappy=OFF SNAPPY_LIB_DEPENDS= libsnappy.so:archivers/snappy TOKUDB_IMPLIES= SNAPPY TOKUDB_PORTDOCS= README.md WSREP_CMAKE_BOOL= WITH_WSREP WSREP_LIB_DEPENDS= libgalera.so:databases/galera26 WSREP_RUN_DEPENDS= bash:shells/bash \ rsync:net/rsync \ #stunnel:security/stunnel WSREP_SHEBANG_FILES= bin/wsrep_sst_rsync ZMQ_LIB_DEPENDS= libzmq.so:net/libzmq4 ZSTD_CMAKE_ON= -DWITH_ROCKSDB_zstd=ON ZSTD_CMAKE_OFF= -DWITH_ROCKSDB_zstd=OFF ZSTD_LIB_DEPENDS= libzstd.so:archivers/zstd .for PLUGIN in ${DISABLED_PLUGINS} CMAKE_ARGS+= -DPLUGIN_${PLUGIN}=NO .endfor .endif # ${PKGNAMESUFFIX:M*-client} .include .if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200057 SUB_LIST+= LEGACY_LIMITS="@comment " MODERN_LIMITS="" .else SUB_LIST+= LEGACY_LIMITS="" MODERN_LIMITS="@comment " .endif .if ${SSL_DEFAULT} != base && ${PORT_OPTIONS:MGSSAPI_BASE} GSSAPI_BASE_IGNORE= BASE_GSSAPI is not compatible with OpenSSL from ports. Use other GSSAPI options or OpenSSL from base system .endif .include .if ${ARCH} != amd64 PLIST_SUB+= WSREP="@comment " .endif .if ${ARCH} == i386 USE_GCC= yes CFLAGS+= -latomic -fasynchronous-unwind-tables .endif .if ${OPSYS} == DragonFly CMAKE_OFF+= WITH_TOKUDB .endif post-patch: ${REINPLACE_CMD} 's|%%LOCALBASE%%|${LOCALBASE}|g' \ ${WRKSRC}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake ${REINPLACE_CMD} 's|%%PREFIX%%|${PREFIX}|' ${WRKSRC}/mysys/my_default.c .if ${OPSYS} == DragonFly ${CP} ${WRKSRC}/cmake/os/FreeBSD.cmake \ ${WRKSRC}/cmake/os/DragonFly.cmake .endif post-configure: ${REINPLACE_CMD} -Ee 's|(#define INCLUDE.*)"$$|\1 -I${PREFIX}/include"|' \ -e 's|(#define LIBS .*)"$$|\1 -L${PREFIX}/lib"|' \ ${WRKSRC}/libmariadb/mariadb_config/mariadb_config.c pre-install: ${MKDIR} ${STAGEDIR}${ETCDIR}/conf.d .if ${PKGNAMESUFFIX:M*-client} post-install: ${INSTALL_DATA} ${WRKDIR}/my.cnf.sample ${STAGEDIR}${ETCDIR}/my.cnf.sample ${INSTALL_DATA} ${WRKDIR}/client.cnf.sample \ ${STAGEDIR}${ETCDIR}/conf.d/client.cnf.sample ${RM} -r ${STAGEDIR}${DATADIR} \ ${STAGEDIR}${PREFIX}/include/mysql/server ${MV} ${STAGEDIR}${PREFIX}/lib/mysql/pkgconfig/mariadb.pc \ ${STAGEDIR}${PREFIX}/libdata/pkgconfig/mariadb.pc ${RMDIR} ${STAGEDIR}${PREFIX}/lib/mysql/pkgconfig ${MKDIR} ${STAGEDIR}/${MARIADB_RUNDIR} post-install-GSSAPI_NONE-off: ${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/mysql/plugin/auth_gssapi_client.so .else # ! ${PKGNAMESUFFIX:M*-client} post-install: ${INSTALL_DATA} ${WRKDIR}/server.cnf.sample \ ${STAGEDIR}${ETCDIR}/conf.d/server.cnf.sample ${RM} -r ${STAGEDIR}${PREFIX}/share/mysql/policy \ ${STAGEDIR}${PREFIX}/include/mysql/server/private \ ${STAGEDIR}${PREFIX}/lib/mysql/pkgconfig ${MV} ${STAGEDIR}${PREFIX}/etc/mysql/user_map.conf \ ${STAGEDIR}${PREFIX}/etc/mysql/user_map.conf.sample ${MV} ${STAGEDIR}${DATADIR}/wsrep.cnf \ ${STAGEDIR}${ETCDIR}/conf.d/wsrep.cnf.sample || true ${MKDIR} ${STAGEDIR}/${MARIADB_LOGDIR} .endif # ${PKGNAMESUFFIX:M*-client} .include diff --git a/databases/mariadb104-server/files/patch-MDEV-26537 b/databases/mariadb104-server/files/patch-MDEV-26537 new file mode 100644 index 000000000000..05cf0f5a4ebc --- /dev/null +++ b/databases/mariadb104-server/files/patch-MDEV-26537 @@ -0,0 +1,126 @@ +From d09426f9e60fd93296464ec9eb5f9d85566437d3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= +Date: Fri, 10 Sep 2021 19:15:41 +0300 +Subject: [PATCH] MDEV-26537 InnoDB corrupts files due to incorrect st_blksize + calculation + +The st_blksize returned by fstat(2) is not documented to be +a power of 2, like we assumed in +commit 58252fff15acfe7c7b0452a87e202e3f8e454e19 (MDEV-26040). +While on Linux, the st_blksize appears to report the file system +block size (which hopefully is not smaller than the sector size +of the underlying block device), on FreeBSD we observed +st_blksize values that might have been something similar to st_size. + +Also IBM AIX was affected by this. A simple test case would +lead to a crash when using the minimum innodb_buffer_pool_size=5m +on both FreeBSD and AIX: + +seq -f 'create table t%g engine=innodb select * from seq_1_to_200000;' \ +1 100|mysql test& +seq -f 'create table u%g engine=innodb select * from seq_1_to_200000;' \ +1 100|mysql test& + +We will fix this by not trusting st_blksize at all, and assuming that +the smallest allowed write size (for O_DIRECT) is 4096 bytes. We hope +that no storage systems with larger block size exist. Anything larger +than 4096 bytes should be unlikely, given that it is the minimum +virtual memory page size of many contemporary processors. + +MariaDB Server on Microsoft Windows was not affected by this. + +While the 512-byte sector size of the venerable Seagate ST-225 is still +in widespread use, the minimum innodb_page_size is 4096 bytes, and +innodb_log_file_size can be set in integer multiples of 65536 bytes. + +The only occasion where InnoDB uses smaller data file block sizes than +4096 bytes is with ROW_FORMAT=COMPRESSED tables with KEY_BLOCK_SIZE=1 +or KEY_BLOCK_SIZE=2 (or innodb_page_size=4096). For such tables, +we will from now on preallocate space in integer multiples of 4096 bytes +and let regular writes extend the file by 1024, 2048, or 3072 bytes. + +The view INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES.FS_BLOCK_SIZE +should report the raw st_blksize. + +For page_compressed tables, the function fil_space_get_block_size() +will map to 512 any st_blksize value that is larger than 4096. + +os_file_set_size(): Assume that the file system block size is 4096 bytes, +and only support extending files to integer multiples of 4096 bytes. + +fil_space_extend_must_retry(): Round down the preallocation size to +an integer multiple of 4096 bytes. +--- mysql-test/suite/innodb/t/check_ibd_filesize.test.orig 2021-08-02 10:58:56 UTC ++++ mysql-test/suite/innodb/t/check_ibd_filesize.test +@@ -46,6 +46,12 @@ perl; + print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; + EOF + INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; ++# Ensure that the file will be extended with the last 1024-byte page ++# after the file was pre-extended in 4096-byte increments. ++--disable_query_log ++FLUSH TABLE t1 FOR EXPORT; ++UNLOCK TABLES; ++--enable_query_log + perl; + print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n"; + EOF + mysql-test/suite/innodb/t/check_ibd_filesize.test | 6 ++++++ + storage/innobase/fil/fil0fil.cc | 13 +++++++++---- + storage/innobase/os/os0file.cc | 7 ++++--- + 3 files changed, 19 insertions(+), 7 deletions(-) + +--- storage/innobase/fil/fil0fil.cc.orig 2021-08-02 10:58:57 UTC ++++ storage/innobase/fil/fil0fil.cc +@@ -942,11 +942,17 @@ fil_space_extend_must_retry( + const page_size_t pageSize(space->flags); + const ulint page_size = pageSize.physical(); + +- /* fil_read_first_page() expects srv_page_size bytes. +- fil_node_open_file() expects at least 4 * srv_page_size bytes.*/ +- os_offset_t new_size = std::max( +- os_offset_t(size - file_start_page_no) * page_size, ++ /* fil_read_first_page() expects innodb_page_size bytes. ++ fil_node_open_file() expects at least 4 * innodb_page_size bytes. ++ os_file_set_size() expects multiples of 4096 bytes. ++ For ROW_FORMAT=COMPRESSED tables using 1024-byte or 2048-byte ++ pages, we will preallocate up to an integer multiple of 4096 bytes, ++ and let normal writes append 1024, 2048, or 3072 bytes to the file. */ ++ os_offset_t new_size = std::max( ++ (os_offset_t(size - file_start_page_no) * page_size) ++ & ~os_offset_t(4095), + os_offset_t(FIL_IBD_FILE_INITIAL_SIZE << srv_page_size_shift)); ++ + + *success = os_file_set_size(node->name, node->handle, new_size, + FSP_FLAGS_HAS_PAGE_COMPRESSION(space->flags)); +--- storage/innobase/os/os0file.cc.orig 2021-08-02 10:58:57 UTC ++++ storage/innobase/os/os0file.cc +@@ -5351,6 +5351,8 @@ os_file_set_size( + os_offset_t size, + bool is_sparse) + { ++ ut_ad(!(size & 4095)); ++ + #ifdef _WIN32 + /* On Windows, changing file size works well and as expected for both + sparse and normal files. +@@ -5392,7 +5394,7 @@ fallback: + if (current_size >= size) { + return true; + } +- current_size &= ~os_offset_t(statbuf.st_blksize - 1); ++ current_size &= ~4095ULL; + err = posix_fallocate(file, current_size, + size - current_size); + } +@@ -5432,8 +5434,7 @@ fallback: + if (fstat(file, &statbuf)) { + return false; + } +- os_offset_t current_size = statbuf.st_size +- & ~os_offset_t(statbuf.st_blksize - 1); ++ os_offset_t current_size = statbuf.st_size & ~4095ULL; + #endif + if (current_size >= size) { + return true;