From b71623123875141f6983c2eee633c7d15172c9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 3 Oct 2017 20:14:18 +0300 Subject: [PATCH 1/5] MDEV-13901 Assertion `!space->stop_new_ops' failed in TRUNCATE TABLE with many indexes fil_space_extend_must_retry(): If the table is being truncated, do not call fil_flush_low(). The operation is covered by the truncate log. File extension during TRUNCATE only occurs if there are many indexes on the table. With smaller innodb_page_size, the file extension occurs already with fewer indexes on the table. --- .../suite/innodb/r/innodb-truncate.result | 22 ++++++++++++++---- .../suite/innodb/t/innodb-truncate.test | 23 ++++++++++++++----- storage/innobase/fil/fil0fil.cc | 3 ++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-truncate.result b/mysql-test/suite/innodb/r/innodb-truncate.result index f63e9272850..a606868ae52 100644 --- a/mysql-test/suite/innodb/r/innodb-truncate.result +++ b/mysql-test/suite/innodb/r/innodb-truncate.result @@ -47,12 +47,24 @@ SET @@SESSION.foreign_key_checks = @old_foreign_key_checks; # # Test that TRUNCATE resets auto-increment. # -CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT); -INSERT INTO t1 VALUES (NULL), (NULL); +CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT, +b INT, c INT, d INT, e INT, f INT, g INT, h INT, i INT, j INT, k INT, +l INT, m INT, n INT, o INT, p INT, q INT, r INT, s INT, t INT, u INT, +KEY(b),KEY(c),KEY(d),KEY(e),KEY(f),KEY(g),KEY(h),KEY(i),KEY(j),KEY(k), +KEY(l),KEY(m),KEY(n),KEY(o),KEY(p),KEY(q),KEY(r),KEY(s),KEY(t),KEY(u), +KEY(c,b),KEY(d,b),KEY(e,b),KEY(f,b),KEY(g,b),KEY(h,b),KEY(i,b),KEY(j,b), +KEY(k,b),KEY(l,b),KEY(m,b),KEY(n,b),KEY(o,b),KEY(p,b),KEY(q,b),KEY(r,b), +KEY(s,b),KEY(t,b),KEY(u,b), +KEY(d,c),KEY(e,c),KEY(f,c),KEY(g,c),KEY(h,c),KEY(i,c),KEY(j,c), +KEY(k,c),KEY(l,c),KEY(m,c),KEY(n,c),KEY(o,c),KEY(p,c),KEY(q,c),KEY(r,c), +KEY(s,c),KEY(t,c),KEY(u,c), +KEY(e,d),KEY(f,d),KEY(g,d),KEY(h,d),KEY(i,d),KEY(j,d) +) ENGINE=InnoDB; +INSERT INTO t1 () VALUES (), (); SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; AUTO_INCREMENT 3 -SELECT * FROM t1 ORDER BY a; +SELECT a FROM t1 ORDER BY a; a 1 2 @@ -60,8 +72,8 @@ TRUNCATE TABLE t1; SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; AUTO_INCREMENT 1 -INSERT INTO t1 VALUES (NULL), (NULL); -SELECT * FROM t1 ORDER BY a; +INSERT INTO t1 () VALUES (), (); +SELECT a FROM t1 ORDER BY a; a 1 2 diff --git a/mysql-test/suite/innodb/t/innodb-truncate.test b/mysql-test/suite/innodb/t/innodb-truncate.test index ae25aabd323..8f9b1f1f0e9 100644 --- a/mysql-test/suite/innodb/t/innodb-truncate.test +++ b/mysql-test/suite/innodb/t/innodb-truncate.test @@ -52,13 +52,24 @@ SET @@SESSION.foreign_key_checks = @old_foreign_key_checks; --echo # Test that TRUNCATE resets auto-increment. --echo # -CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT); -INSERT INTO t1 VALUES (NULL), (NULL); +CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT, + b INT, c INT, d INT, e INT, f INT, g INT, h INT, i INT, j INT, k INT, + l INT, m INT, n INT, o INT, p INT, q INT, r INT, s INT, t INT, u INT, + KEY(b),KEY(c),KEY(d),KEY(e),KEY(f),KEY(g),KEY(h),KEY(i),KEY(j),KEY(k), + KEY(l),KEY(m),KEY(n),KEY(o),KEY(p),KEY(q),KEY(r),KEY(s),KEY(t),KEY(u), + KEY(c,b),KEY(d,b),KEY(e,b),KEY(f,b),KEY(g,b),KEY(h,b),KEY(i,b),KEY(j,b), + KEY(k,b),KEY(l,b),KEY(m,b),KEY(n,b),KEY(o,b),KEY(p,b),KEY(q,b),KEY(r,b), + KEY(s,b),KEY(t,b),KEY(u,b), + KEY(d,c),KEY(e,c),KEY(f,c),KEY(g,c),KEY(h,c),KEY(i,c),KEY(j,c), + KEY(k,c),KEY(l,c),KEY(m,c),KEY(n,c),KEY(o,c),KEY(p,c),KEY(q,c),KEY(r,c), + KEY(s,c),KEY(t,c),KEY(u,c), + KEY(e,d),KEY(f,d),KEY(g,d),KEY(h,d),KEY(i,d),KEY(j,d) +) ENGINE=InnoDB; +INSERT INTO t1 () VALUES (), (); SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; -SELECT * FROM t1 ORDER BY a; +SELECT a FROM t1 ORDER BY a; TRUNCATE TABLE t1; SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; -INSERT INTO t1 VALUES (NULL), (NULL); -SELECT * FROM t1 ORDER BY a; +INSERT INTO t1 () VALUES (), (); +SELECT a FROM t1 ORDER BY a; DROP TABLE t1; - diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index e408b6d88bb..2897d5f9be8 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1223,7 +1223,8 @@ fil_space_extend_must_retry( default: ut_ad(space->purpose == FIL_TYPE_TABLESPACE || space->purpose == FIL_TYPE_IMPORT); - if (space->purpose == FIL_TYPE_TABLESPACE) { + if (space->purpose == FIL_TYPE_TABLESPACE + && !space->is_being_truncated) { fil_flush_low(space); } return(false); From 35a4591e126f8530f569debc93a1a5aa189d01e5 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 3 Oct 2017 19:38:28 +0000 Subject: [PATCH 2/5] Update C/C Fixes some warnings. --- libmariadb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmariadb b/libmariadb index ba8310e82da..931450c3f87 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit ba8310e82dac659482f04cd2e270e666da072f95 +Subproject commit 931450c3f8793f2653f6292847cbc005b30ed3b6 From 4732767981442cf2522088471ba211ecf9f542a2 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 3 Oct 2017 19:42:16 +0000 Subject: [PATCH 3/5] Fix Windows warnings : fix server_audit not to use my_win_open and Co functions. There is no reason to export IO this functionality from server, if it can be easily implemented with CRT. Note: for the sake of compatibility, we do not use _open() on Windows, but open file with CreateFile, with FILE_SHARE_DELETE flag, so it can be renamed or deleted when open. Also atomic append flag is used. --- plugin/server_audit/server_audit.c | 59 ++++++++++++++---------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 5ecacb79865..d00fc313ab8 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifndef _WIN32 #include @@ -140,7 +141,7 @@ static size_t loc_write(File Filedes, const uchar *Buffer, size_t Count) { size_t writtenbytes; #ifdef _WIN32 - writtenbytes= my_win_write(Filedes, Buffer, Count); + writtenbytes= (size_t)_write(Filedes, Buffer, (unsigned int)Count); #else writtenbytes= write(Filedes, Buffer, Count); #endif @@ -154,10 +155,29 @@ static File loc_open(const char *FileName, int Flags) /* Special flags */ { File fd; -#if defined(_WIN32) - fd= my_win_open(FileName, Flags); +#ifdef _WIN32 + HANDLE h; + /* + We could just use _open() here. but prefer to open in unix-similar way + just like my_open() does it on Windows. + This gives atomic multiprocess-safeŽappends, and possibility to rename + or even delete file while it is open, and CRT lacks this features. + */ + assert(Flags == (O_APPEND | O_CREAT | O_WRONLY)); + h= CreateFile(FileName, FILE_APPEND_DATA, + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + { + fd= -1; + my_osmaperr(GetLastError()); + } + else + { + fd= _open_osfhandle((intptr)h, O_WRONLY|O_BINARY); + } #else - fd = open(FileName, Flags, my_umask); + fd= open(FileName, Flags, my_umask); #endif my_errno= errno; return fd; @@ -173,7 +193,7 @@ static int loc_close(File fd) err= close(fd); } while (err == -1 && errno == EINTR); #else - err= my_win_close(fd); + err= close(fd); #endif my_errno=errno; return err; @@ -203,32 +223,9 @@ static int loc_rename(const char *from, const char *to) } -static my_off_t loc_seek(File fd, my_off_t pos, int whence) -{ - os_off_t newpos= -1; -#ifdef _WIN32 - newpos= my_win_lseek(fd, pos, whence); -#else - newpos= lseek(fd, pos, whence); -#endif - if (newpos == (os_off_t) -1) - { - my_errno= errno; - return MY_FILEPOS_ERROR; - } - - return (my_off_t) newpos; -} - - static my_off_t loc_tell(File fd) { - os_off_t pos; -#if defined (HAVE_TELL) && !defined (_WIN32) - pos= tell(fd); -#else - pos= loc_seek(fd, 0L, MY_SEEK_CUR); -#endif + os_off_t pos= IF_WIN(_telli64(fd),lseek(fd, 0, SEEK_CUR)); if (pos == (os_off_t) -1) { my_errno= errno; @@ -992,7 +989,7 @@ static int start_logging() if (output_type == OUTPUT_FILE) { char alt_path_buffer[FN_REFLEN+1+DEFAULT_FILENAME_LEN]; - MY_STAT *f_stat; + struct stat *f_stat= (struct stat *)alt_path_buffer; const char *alt_fname= file_path; while (*alt_fname == ' ') @@ -1007,7 +1004,7 @@ static int start_logging() { /* See if the directory exists with the name of file_path. */ /* Log file name should be [file_path]/server_audit.log then. */ - if ((f_stat= my_stat(file_path, (MY_STAT *)alt_path_buffer, MYF(0))) && + if (stat(file_path, (struct stat *)alt_path_buffer) == 0 && S_ISDIR(f_stat->st_mode)) { size_t p_len= strlen(file_path); From 8d413c32dc50469d65185d6252014ef29b7b42c2 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 3 Oct 2017 19:43:43 +0000 Subject: [PATCH 4/5] Fix several truncation and formatting warnings. --- sql/item_inetfunc.cc | 20 ++++++++++---------- sql/lock.cc | 2 +- sql/log.cc | 2 +- sql/mf_iocache_encr.cc | 4 ++-- sql/sql_parse.cc | 4 ++-- sql/sql_window.cc | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sql/item_inetfunc.cc b/sql/item_inetfunc.cc index 7f3ec3829f4..cf484d251a9 100644 --- a/sql/item_inetfunc.cc +++ b/sql/item_inetfunc.cc @@ -217,7 +217,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): " "invalid IPv4 address: too short.", - str_length, str)); + (int)str_length, str)); return false; } @@ -225,7 +225,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): " "invalid IPv4 address: too long.", - str_length, str)); + (int)str_length, str)); return false; } @@ -248,7 +248,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " "too many characters in a group.", - str_length, str)); + (int)str_length, str)); return false; } @@ -258,7 +258,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " "invalid byte value.", - str_length, str)); + (int)str_length, str)); return false; } } @@ -268,7 +268,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " "too few characters in a group.", - str_length, str)); + (int)str_length, str)); return false; } @@ -281,7 +281,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres if (dot_count > 3) { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " - "too many dots.", str_length, str)); + "too many dots.", (int)str_length, str)); return false; } } @@ -289,7 +289,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " "invalid character at pos %d.", - str_length, str, (int) (p - str))); + (int)str_length, str, (int) (p - str))); return false; } } @@ -297,7 +297,7 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres if (c == '.') { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " - "ending at '.'.", str_length, str)); + "ending at '.'.",(int)str_length, str)); return false; } @@ -305,14 +305,14 @@ static bool str_to_ipv4(const char *str, size_t str_length, in_addr *ipv4_addres { DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: " "too few groups.", - str_length, str)); + (int)str_length, str)); return false; } ipv4_bytes[3]= (unsigned char) byte_value; DBUG_PRINT("info", ("str_to_ipv4(%.*s): valid IPv4 address: %d.%d.%d.%d", - str_length, str, + (int)str_length, str, ipv4_bytes[0], ipv4_bytes[1], ipv4_bytes[2], ipv4_bytes[3])); return true; diff --git a/sql/lock.cc b/sql/lock.cc index 06cb00fe32d..79ce27b9937 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -824,7 +824,7 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) we may allocate too much, but better safe than memory overrun. And in the FLUSH case, the memory is released quickly anyway. */ - sql_lock->lock_count= locks - locks_buf; + sql_lock->lock_count= (uint)(locks - locks_buf); DBUG_ASSERT(sql_lock->lock_count <= lock_count); DBUG_PRINT("info", ("sql_lock->table_count %d sql_lock->lock_count %d", sql_lock->table_count, sql_lock->lock_count)); diff --git a/sql/log.cc b/sql/log.cc index b0115c3e480..cd7fd0f440b 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1292,7 +1292,7 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length, } /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */ - user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE, + user_host_len= (uint)(strxnmov(user_host_buff, MAX_USER_HOST_SIZE, sctx->priv_user, "[", sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), "] @ ", sctx->host ? sctx->host : "", " [", diff --git a/sql/mf_iocache_encr.cc b/sql/mf_iocache_encr.cc index 434fcd1f435..546e0fe03a0 100644 --- a/sql/mf_iocache_encr.cc +++ b/sql/mf_iocache_encr.cc @@ -92,7 +92,7 @@ static int my_b_encr_read(IO_CACHE *info, uchar *Buffer, size_t Count) DBUG_RETURN(1); } - elength= wlength - (ebuffer - wbuffer); + elength= wlength - (uint)(ebuffer - wbuffer); set_iv(iv, pos_in_file, crypt_data->inbuf_counter); if (encryption_crypt(ebuffer, elength, info->buffer, &length, @@ -184,7 +184,7 @@ static int my_b_encr_write(IO_CACHE *info, const uchar *Buffer, size_t Count) my_errno= 1; DBUG_RETURN(info->error= -1); } - wlength= elength + ebuffer - wbuffer; + wlength= elength + (uint)(ebuffer - wbuffer); if (length == info->buffer_length) { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 21f0cfd0434..ecd7d845635 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1484,8 +1484,8 @@ uint maria_multi_check(THD *thd, char *packet, uint packet_length) size_t subpacket_length= net_field_length((uchar **)&packet_start); size_t length_length= packet_start - packet; // length of command + 3 bytes where that length was stored - DBUG_PRINT("info", ("sub-packet length: %ld + %d command: %x", - (ulong)subpacket_length, length_length, + DBUG_PRINT("info", ("sub-packet length: %zu + %zu command: %x", + subpacket_length, length_length, packet_start[3])); if (subpacket_length == 0 || diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 5fae2228646..7ae967d7077 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -327,7 +327,7 @@ int compare_order_elements(ORDER *ord1, ORDER *ord2) Item *item2= (*ord2->item)->real_item(); DBUG_ASSERT(item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM); - int cmp= ((Item_field *) item1)->field - ((Item_field *) item2)->field; + ptrdiff_t cmp= ((Item_field *) item1)->field - ((Item_field *) item2)->field; if (cmp == 0) { if (ord1->direction == ord2->direction) From 6ca35c14286d7649ff3938fd54fcf9c9bee6e136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 4 Oct 2017 08:07:41 +0300 Subject: [PATCH 5/5] Replace a non-ASCII character in a comment --- plugin/server_audit/server_audit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index d00fc313ab8..87a18e47fc5 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -160,7 +160,7 @@ static File loc_open(const char *FileName, int Flags) /* We could just use _open() here. but prefer to open in unix-similar way just like my_open() does it on Windows. - This gives atomic multiprocess-safeŽappends, and possibility to rename + This gives atomic multiprocess-safe appends, and possibility to rename or even delete file while it is open, and CRT lacks this features. */ assert(Flags == (O_APPEND | O_CREAT | O_WRONLY));