diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-07-02 09:41:44 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-07-02 09:41:44 +0300 |
commit | 1813d92d0c505a1c752f4a9d6e37db6bffe4efdd (patch) | |
tree | f570314890197949ae55cbbad3a94eb5893c4177 /storage | |
parent | 0fe97c20b341665058491fca4d665207406775c6 (diff) | |
parent | f347b3e0e6592329b1447fa460aca0a4b1f680b1 (diff) | |
download | mariadb-git-1813d92d0c505a1c752f4a9d6e37db6bffe4efdd.tar.gz |
Merge 10.4 into 10.5
Diffstat (limited to 'storage')
51 files changed, 446 insertions, 513 deletions
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 9da9b90d246..a282826b8de 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -1299,10 +1299,12 @@ btr_cur_search_to_nth_level_func( ut_ad(!(index->type & DICT_FTS)); ut_ad(index->page != FIL_NULL); - UNIV_MEM_INVALID(&cursor->up_match, sizeof cursor->up_match); - UNIV_MEM_INVALID(&cursor->up_bytes, sizeof cursor->up_bytes); - UNIV_MEM_INVALID(&cursor->low_match, sizeof cursor->low_match); - UNIV_MEM_INVALID(&cursor->low_bytes, sizeof cursor->low_bytes); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&cursor->up_match, sizeof cursor->up_match); + MEM_UNDEFINED(&cursor->up_bytes, sizeof cursor->up_bytes); + MEM_UNDEFINED(&cursor->low_match, sizeof cursor->low_match); + MEM_UNDEFINED(&cursor->low_bytes, sizeof cursor->low_bytes); +#endif /* HAVE_valgrind_or_MSAN */ #ifdef UNIV_DEBUG cursor->up_match = ULINT_UNDEFINED; cursor->low_match = ULINT_UNDEFINED; @@ -3365,13 +3367,12 @@ btr_cur_optimistic_insert( || (flags & BTR_CREATE_FLAG)); ut_ad(dtuple_check_typed(entry)); -#ifdef UNIV_DEBUG_VALGRIND +#ifdef HAVE_valgrind_or_MSAN if (block->page.zip.data) { - UNIV_MEM_ASSERT_RW(page, srv_page_size); - UNIV_MEM_ASSERT_RW(block->page.zip.data, - block->zip_size()); + MEM_CHECK_DEFINED(page, srv_page_size); + MEM_CHECK_DEFINED(block->page.zip.data, block->zip_size()); } -#endif /* UNIV_DEBUG_VALGRIND */ +#endif /* HAVE_valgrind_or_MSAN */ leaf = page_is_leaf(page); @@ -7263,9 +7264,7 @@ btr_store_big_rec_extern_fields( BTR_EXTERN_FIELD_REF_SIZE)); #endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */ extern_len = big_rec_vec->fields[i].len; - UNIV_MEM_ASSERT_RW(big_rec_vec->fields[i].data, - extern_len); - + MEM_CHECK_DEFINED(big_rec_vec->fields[i].data, extern_len); ut_a(extern_len > 0); prev_page_no = FIL_NULL; @@ -7878,7 +7877,7 @@ btr_copy_blob_prefix( mtr_commit(&mtr); if (page_no == FIL_NULL || copy_len != part_len) { - UNIV_MEM_ASSERT_RW(buf, copied_len); + MEM_CHECK_DEFINED(buf, copied_len); return(copied_len); } @@ -8034,7 +8033,7 @@ end_of_blob: func_exit: inflateEnd(&d_stream); mem_heap_free(heap); - UNIV_MEM_ASSERT_RW(buf, d_stream.total_out); + MEM_CHECK_DEFINED(buf, d_stream.total_out); return(d_stream.total_out); } diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index de2f58a23b4..92cb38d0a85 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -1656,7 +1656,6 @@ btr_search_build_page_hash_index( for (ulint i = 0; i < n_cached; i++) { ha_insert_for_fold(&part->table, part->heap, folds[i], block, recs[i]); - MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED); } } diff --git a/storage/innobase/buf/buf0buddy.cc b/storage/innobase/buf/buf0buddy.cc index db156ba036b..bedf00441ec 100644 --- a/storage/innobase/buf/buf0buddy.cc +++ b/storage/innobase/buf/buf0buddy.cc @@ -81,7 +81,6 @@ enum buf_buddy_state_t { are in use */ }; -#ifdef UNIV_DEBUG_VALGRIND /**********************************************************************//** Invalidate memory area that we won't access while page is free */ UNIV_INLINE @@ -91,15 +90,11 @@ buf_buddy_mem_invalid( buf_buddy_free_t* buf, /*!< in: block to check */ ulint i) /*!< in: index of zip_free[] */ { - const size_t size = BUF_BUDDY_LOW << i; - ut_ad(i <= BUF_BUDDY_SIZES); + ut_ad(i <= BUF_BUDDY_SIZES); - UNIV_MEM_ASSERT_W(buf, size); - UNIV_MEM_INVALID(buf, size); + MEM_CHECK_ADDRESSABLE(buf, BUF_BUDDY_LOW << i); + MEM_UNDEFINED(buf, BUF_BUDDY_LOW << i); } -#else /* UNIV_DEBUG_VALGRIND */ -# define buf_buddy_mem_invalid(buf, i) ut_ad((i) <= BUF_BUDDY_SIZES) -#endif /* UNIV_DEBUG_VALGRIND */ /**********************************************************************//** Check if a buddy is stamped free. @@ -333,11 +328,10 @@ static buf_buddy_free_t* buf_buddy_alloc_zip(ulint i) if (buf) { /* Trash the page other than the BUF_BUDDY_STAMP_NONFREE. */ - UNIV_MEM_TRASH((void*) buf, (int) ~i, BUF_BUDDY_STAMP_OFFSET); - UNIV_MEM_TRASH(BUF_BUDDY_STAMP_OFFSET + 4 - + buf->stamp.bytes, (int) ~i, - (BUF_BUDDY_LOW << i) - - (BUF_BUDDY_STAMP_OFFSET + 4)); + MEM_UNDEFINED(buf, BUF_BUDDY_STAMP_OFFSET); + MEM_UNDEFINED(BUF_BUDDY_STAMP_OFFSET + 4 + buf->stamp.bytes, + (BUF_BUDDY_LOW << i) + - (BUF_BUDDY_STAMP_OFFSET + 4)); ut_ad(mach_read_from_4(buf->stamp.bytes + BUF_BUDDY_STAMP_OFFSET) == BUF_BUDDY_STAMP_NONFREE); @@ -370,7 +364,9 @@ buf_buddy_block_free(void* buf) HASH_DELETE(buf_page_t, hash, &buf_pool.zip_hash, fold, bpage); ut_d(memset(buf, 0, srv_page_size)); - UNIV_MEM_INVALID(buf, srv_page_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(buf, srv_page_size); +#endif /* HAVE_valgrind_or_MSAN */ block = (buf_block_t*) bpage; buf_LRU_block_free_non_file_page(block); @@ -493,17 +489,16 @@ static bool buf_buddy_relocate(void* src, void* dst, ulint i, bool force) ut_ad(!ut_align_offset(src, size)); ut_ad(!ut_align_offset(dst, size)); ut_ad(i >= buf_buddy_get_slot(UNIV_ZIP_SIZE_MIN)); - UNIV_MEM_ASSERT_W(dst, size); + MEM_CHECK_ADDRESSABLE(dst, size); space = mach_read_from_4((const byte*) src + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID); offset = mach_read_from_4((const byte*) src + FIL_PAGE_OFFSET); - /* Suppress Valgrind warnings about conditional jump - on uninitialized value. */ - UNIV_MEM_VALID(&space, sizeof space); - UNIV_MEM_VALID(&offset, sizeof offset); + /* Suppress Valgrind or MSAN warnings. */ + MEM_MAKE_DEFINED(&space, sizeof space); + MEM_MAKE_DEFINED(&offset, sizeof offset); ut_ad(space != BUF_BUDDY_STAMP_FREE); @@ -549,7 +544,7 @@ static bool buf_buddy_relocate(void* src, void* dst, ulint i, bool force) /* The block must have been allocated, but it may contain uninitialized data. */ - UNIV_MEM_ASSERT_W(src, size); + MEM_CHECK_ADDRESSABLE(src, size); if (!bpage->can_relocate()) { return false; @@ -598,7 +593,7 @@ void buf_buddy_free_low(void* buf, ulint i) buf_pool.buddy_stat[i].used--; recombine: - UNIV_MEM_ALLOC(buf, BUF_BUDDY_LOW << i); + MEM_UNDEFINED(buf, BUF_BUDDY_LOW << i); if (i == BUF_BUDDY_SIZES) { buf_buddy_block_free(buf); diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 4aaf374da95..1e2abc2e04d 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -1295,8 +1295,6 @@ static void buf_block_init(buf_block_t* block, byte* frame) { - UNIV_MEM_DESC(frame, srv_page_size); - /* This function should only be executed at database startup or by buf_pool.resize(). Either way, adaptive hash index must not exist. */ assert_block_ahi_empty_on_init(block); @@ -1412,7 +1410,7 @@ inline bool buf_pool_t::chunk_t::create(size_t bytes) for (auto i= size; i--; ) { buf_block_init(block, frame); - UNIV_MEM_INVALID(block->frame, srv_page_size); + MEM_UNDEFINED(block->frame, srv_page_size); /* Add the block to the free list */ UT_LIST_ADD_LAST(buf_pool.free, &block->page); @@ -1704,8 +1702,6 @@ inline bool buf_pool_t::realloc(buf_block_t *block) if (block->page.zip.data != NULL) { ut_ad(block->in_unzip_LRU_list); ut_d(new_block->in_unzip_LRU_list = true); - UNIV_MEM_DESC(&new_block->page.zip.data, - page_zip_get_size(&new_block->page.zip)); buf_block_t* prev_block = UT_LIST_GET_PREV(unzip_LRU, block); UT_LIST_REMOVE(unzip_LRU, block); @@ -1740,7 +1736,9 @@ inline bool buf_pool_t::realloc(buf_block_t *block) "not perfect alignment"); memset_aligned<2>(block->frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0xff, 4); - UNIV_MEM_INVALID(block->frame, srv_page_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(block->frame, srv_page_size); +#endif /* HAVE_valgrind_or_MSAN */ block->page.set_state(BUF_BLOCK_REMOVE_HASH); /* Relocate flush_list. */ @@ -3366,9 +3364,6 @@ evict_from_pool: block->lock_hash_val = lock_rec_hash(page_id.space(), page_id.page_no()); - UNIV_MEM_DESC(&block->page.zip.data, - page_zip_get_size(&block->page.zip)); - if (!block->page.oldest_modification()) { ut_d(UT_LIST_REMOVE(buf_pool.zip_clean, &block->page)); } else { @@ -3387,7 +3382,9 @@ evict_from_pool: block->page.set_io_fix(BUF_IO_READ); rw_lock_x_lock_inline(&block->lock, 0, file, line); - UNIV_MEM_INVALID(bpage, sizeof *bpage); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(bpage, sizeof *bpage); +#endif /* HAVE_valgrind_or_MSAN */ mutex_exit(&buf_pool.mutex); hash_lock->write_unlock(); diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 1e4e5a2721c..af9302aa113 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -375,7 +375,7 @@ void buf_flush_insert_into_flush_list(buf_block_t* block, lsn_t lsn) mutex_enter(&buf_pool.flush_list_mutex); block->page.set_oldest_modification(lsn); - UNIV_MEM_ASSERT_RW(block->page.zip.data + MEM_CHECK_DEFINED(block->page.zip.data ? block->page.zip.data : block->frame, block->physical_size()); incr_flush_list_size_in_bytes(block); diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index f9189216ac0..41d1e40a730 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -626,7 +626,7 @@ buf_block_t* buf_LRU_get_free_only() assert_block_ahi_empty(block); block->page.set_state(BUF_BLOCK_MEMORY); - UNIV_MEM_ALLOC(block->frame, srv_page_size); + MEM_UNDEFINED(block->frame, srv_page_size); break; } @@ -1216,8 +1216,6 @@ func_exit: ut_ad(!buf_pool.page_hash_get_low(id, fold)); ut_ad(b->zip_size()); - UNIV_MEM_DESC(b->zip.data, b->zip_size()); - /* The field in_LRU_list of the to-be-freed block descriptor should have been cleared in @@ -1306,13 +1304,16 @@ func_exit: The page was declared uninitialized by buf_LRU_block_remove_hashed(). We need to flag the contents of the page valid (which it still is) in - order to avoid bogus Valgrind warnings.*/ + order to avoid bogus Valgrind or MSAN warnings.*/ + buf_block_t* block = reinterpret_cast<buf_block_t*>(bpage); - UNIV_MEM_VALID(((buf_block_t*) bpage)->frame, - srv_page_size); - btr_search_drop_page_hash_index((buf_block_t*) bpage); - UNIV_MEM_INVALID(((buf_block_t*) bpage)->frame, - srv_page_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_MAKE_DEFINED(block->frame, srv_page_size); +#endif /* HAVE_valgrind_or_MSAN */ + btr_search_drop_page_hash_index(block); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(block->frame, srv_page_size); +#endif /* HAVE_valgrind_or_MSAN */ if (UNIV_LIKELY_NULL(b)) { ut_ad(b->zip_size()); @@ -1320,7 +1321,7 @@ func_exit: } mutex_enter(&buf_pool.mutex); - buf_LRU_block_free_hashed_page((buf_block_t*) bpage); + buf_LRU_block_free_hashed_page(block); return(true); } @@ -1342,11 +1343,7 @@ buf_LRU_block_free_non_file_page( block->page.set_state(BUF_BLOCK_NOT_USED); - UNIV_MEM_ALLOC(block->frame, srv_page_size); -#ifdef UNIV_DEBUG - /* Wipe contents of page to reveal possible stale pointers to it */ - memset(block->frame, '\0', srv_page_size); -#else + MEM_UNDEFINED(block->frame, srv_page_size); /* Wipe page_no and space_id */ static_assert(FIL_PAGE_OFFSET % 4 == 0, "alignment"); memset_aligned<4>(block->frame + FIL_PAGE_OFFSET, 0xfe, 4); @@ -1354,7 +1351,6 @@ buf_LRU_block_free_non_file_page( "not perfect alignment"); memset_aligned<2>(block->frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0xfe, 4); -#endif /* UNIV_DEBUG */ data = block->page.zip.data; if (data != NULL) { @@ -1382,7 +1378,7 @@ buf_LRU_block_free_non_file_page( ut_d(block->page.in_free_list = true); } - UNIV_MEM_FREE(block->frame, srv_page_size); + MEM_NOACCESS(block->frame, srv_page_size); } /** Remove bpage from buf_pool.LRU and buf_pool.page_hash. @@ -1415,9 +1411,9 @@ static bool buf_LRU_block_remove_hashed(buf_page_t *bpage, const page_id_t id, switch (bpage->state()) { case BUF_BLOCK_FILE_PAGE: - UNIV_MEM_ASSERT_W(bpage, sizeof(buf_block_t)); - UNIV_MEM_ASSERT_W(((buf_block_t*) bpage)->frame, - srv_page_size); + MEM_CHECK_ADDRESSABLE(bpage, sizeof(buf_block_t)); + MEM_CHECK_ADDRESSABLE(((buf_block_t*) bpage)->frame, + srv_page_size); buf_block_modify_clock_inc((buf_block_t*) bpage); if (bpage->zip.data) { const page_t* page = ((buf_block_t*) bpage)->frame; @@ -1474,7 +1470,7 @@ static bool buf_LRU_block_remove_hashed(buf_page_t *bpage, const page_id_t id, /* fall through */ case BUF_BLOCK_ZIP_PAGE: ut_a(!bpage->oldest_modification()); - UNIV_MEM_ASSERT_W(bpage->zip.data, bpage->zip_size()); + MEM_CHECK_ADDRESSABLE(bpage->zip.data, bpage->zip_size()); break; case BUF_BLOCK_NOT_USED: case BUF_BLOCK_MEMORY: @@ -1515,8 +1511,9 @@ static bool buf_LRU_block_remove_hashed(buf_page_t *bpage, const page_id_t id, "not perfect alignment"); memset_aligned<2>(reinterpret_cast<buf_block_t*>(bpage)->frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0xff, 4); - UNIV_MEM_INVALID(((buf_block_t*) bpage)->frame, - srv_page_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(((buf_block_t*) bpage)->frame, srv_page_size); +#endif /* HAVE_valgrind_or_MSAN */ bpage->set_state(BUF_BLOCK_REMOVE_HASH); /* Question: If we release hash_lock here diff --git a/storage/innobase/buf/buf0rea.cc b/storage/innobase/buf/buf0rea.cc index 8eaf0089495..0f6e0e84e84 100644 --- a/storage/innobase/buf/buf0rea.cc +++ b/storage/innobase/buf/buf0rea.cc @@ -217,8 +217,6 @@ static buf_page_t* buf_page_init_for_read(ulint mode, const page_id_t page_id, page_zip_set_size(&bpage->zip, zip_size); bpage->zip.data = (page_zip_t*) data; - UNIV_MEM_DESC(bpage->zip.data, zip_size); - bpage->init(BUF_BLOCK_ZIP_PAGE, page_id); if (hash_page) diff --git a/storage/innobase/data/data0data.cc b/storage/innobase/data/data0data.cc index af2ea0fd198..0fb9f5e66af 100644 --- a/storage/innobase/data/data0data.cc +++ b/storage/innobase/data/data0data.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -233,41 +233,20 @@ dtuple_validate( /*============*/ const dtuple_t* tuple) /*!< in: tuple */ { - const dfield_t* field; - ulint n_fields; - ulint len; - ulint i; - ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N); +#ifdef HAVE_valgrind_or_MSAN + const ulint n_fields = dtuple_get_n_fields(tuple); - n_fields = dtuple_get_n_fields(tuple); - - /* We dereference all the data of each field to test - for memory traps */ - - for (i = 0; i < n_fields; i++) { - - field = dtuple_get_nth_field(tuple, i); - len = dfield_get_len(field); + for (ulint i = 0; i < n_fields; i++) { + const dfield_t* field = dtuple_get_nth_field(tuple, i); if (!dfield_is_null(field)) { - - const byte* data; - - data = static_cast<const byte*>(dfield_get_data(field)); -#ifndef UNIV_DEBUG_VALGRIND - ulint j; - - for (j = 0; j < len; j++) { - data++; - } -#endif /* !UNIV_DEBUG_VALGRIND */ - - UNIV_MEM_ASSERT_RW(data, len); + MEM_CHECK_DEFINED(dfield_get_data(field), + dfield_get_len(field)); } } - - ut_a(dtuple_check_typed(tuple)); +#endif /* HAVE_valgrind_or_MSAN */ + ut_ad(dtuple_check_typed(tuple)); return(TRUE); } @@ -748,14 +727,7 @@ ext_write: memcpy(data, dfield_get_data(dfield), local_prefix_len); /* Clear the extern field reference (BLOB pointer). */ memset(data + local_prefix_len, 0, BTR_EXTERN_FIELD_REF_SIZE); -#if 0 - /* The following would fail the Valgrind checks in - page_cur_insert_rec_low() and page_cur_insert_rec_zip(). - The BLOB pointers in the record will be initialized after - the record and the BLOBs have been written. */ - UNIV_MEM_ALLOC(data + local_prefix_len, - BTR_EXTERN_FIELD_REF_SIZE); -#endif + dfield_set_data(dfield, data, local_len); dfield_set_ext(dfield); diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index fc5c7fc5eb1..797f76862fa 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -409,7 +409,7 @@ dict_stats_table_clone_create( t = (dict_table_t*) mem_heap_alloc(heap, sizeof(*t)); - UNIV_MEM_ASSERT_RW_ABORT(&table->id, sizeof(table->id)); + MEM_CHECK_DEFINED(&table->id, sizeof(table->id)); t->id = table->id; t->heap = heap; @@ -437,7 +437,7 @@ dict_stats_table_clone_create( idx = (dict_index_t*) mem_heap_alloc(heap, sizeof(*idx)); - UNIV_MEM_ASSERT_RW_ABORT(&index->id, sizeof(index->id)); + MEM_CHECK_DEFINED(&index->id, sizeof(index->id)); idx->id = index->id; idx->name = mem_heap_strdup(heap, index->name); @@ -583,23 +583,23 @@ dict_stats_assert_initialized_index( /*================================*/ const dict_index_t* index) /*!< in: index */ { - UNIV_MEM_ASSERT_RW_ABORT( + MEM_CHECK_DEFINED( index->stat_n_diff_key_vals, index->n_uniq * sizeof(index->stat_n_diff_key_vals[0])); - UNIV_MEM_ASSERT_RW_ABORT( + MEM_CHECK_DEFINED( index->stat_n_sample_sizes, index->n_uniq * sizeof(index->stat_n_sample_sizes[0])); - UNIV_MEM_ASSERT_RW_ABORT( + MEM_CHECK_DEFINED( index->stat_n_non_null_key_vals, index->n_uniq * sizeof(index->stat_n_non_null_key_vals[0])); - UNIV_MEM_ASSERT_RW_ABORT( + MEM_CHECK_DEFINED( &index->stat_index_size, sizeof(index->stat_index_size)); - UNIV_MEM_ASSERT_RW_ABORT( + MEM_CHECK_DEFINED( &index->stat_n_leaf_pages, sizeof(index->stat_n_leaf_pages)); } @@ -614,32 +614,32 @@ dict_stats_assert_initialized( { ut_a(table->stat_initialized); - UNIV_MEM_ASSERT_RW_ABORT(&table->stats_last_recalc, - sizeof(table->stats_last_recalc)); + MEM_CHECK_DEFINED(&table->stats_last_recalc, + sizeof table->stats_last_recalc); - UNIV_MEM_ASSERT_RW_ABORT(&table->stat_persistent, - sizeof(table->stat_persistent)); + MEM_CHECK_DEFINED(&table->stat_persistent, + sizeof table->stat_persistent); - UNIV_MEM_ASSERT_RW_ABORT(&table->stats_auto_recalc, - sizeof(table->stats_auto_recalc)); + MEM_CHECK_DEFINED(&table->stats_auto_recalc, + sizeof table->stats_auto_recalc); - UNIV_MEM_ASSERT_RW_ABORT(&table->stats_sample_pages, - sizeof(table->stats_sample_pages)); + MEM_CHECK_DEFINED(&table->stats_sample_pages, + sizeof table->stats_sample_pages); - UNIV_MEM_ASSERT_RW_ABORT(&table->stat_n_rows, - sizeof(table->stat_n_rows)); + MEM_CHECK_DEFINED(&table->stat_n_rows, + sizeof table->stat_n_rows); - UNIV_MEM_ASSERT_RW_ABORT(&table->stat_clustered_index_size, - sizeof(table->stat_clustered_index_size)); + MEM_CHECK_DEFINED(&table->stat_clustered_index_size, + sizeof table->stat_clustered_index_size); - UNIV_MEM_ASSERT_RW_ABORT(&table->stat_sum_of_other_index_sizes, - sizeof(table->stat_sum_of_other_index_sizes)); + MEM_CHECK_DEFINED(&table->stat_sum_of_other_index_sizes, + sizeof table->stat_sum_of_other_index_sizes); - UNIV_MEM_ASSERT_RW_ABORT(&table->stat_modified_counter, - sizeof(table->stat_modified_counter)); + MEM_CHECK_DEFINED(&table->stat_modified_counter, + sizeof table->stat_modified_counter); - UNIV_MEM_ASSERT_RW_ABORT(&table->stats_bg_flag, - sizeof(table->stats_bg_flag)); + MEM_CHECK_DEFINED(&table->stats_bg_flag, + sizeof table->stats_bg_flag); for (dict_index_t* index = dict_table_get_first_index(table); index != NULL; @@ -2304,20 +2304,19 @@ dict_stats_save_index_stat( pars_info_add_str_literal(pinfo, "database_name", db_utf8); pars_info_add_str_literal(pinfo, "table_name", table_utf8); pars_info_add_str_literal(pinfo, "index_name", index->name); - UNIV_MEM_ASSERT_RW_ABORT(&last_update, 4); + MEM_CHECK_DEFINED(&last_update, 4); pars_info_add_int4_literal(pinfo, "last_update", uint32(last_update)); - UNIV_MEM_ASSERT_RW_ABORT(stat_name, strlen(stat_name)); + MEM_CHECK_DEFINED(stat_name, strlen(stat_name)); pars_info_add_str_literal(pinfo, "stat_name", stat_name); - UNIV_MEM_ASSERT_RW_ABORT(&stat_value, 8); + MEM_CHECK_DEFINED(&stat_value, 8); pars_info_add_ull_literal(pinfo, "stat_value", stat_value); if (sample_size != NULL) { - UNIV_MEM_ASSERT_RW_ABORT(sample_size, 8); + MEM_CHECK_DEFINED(sample_size, 8); pars_info_add_ull_literal(pinfo, "sample_size", *sample_size); } else { pars_info_add_literal(pinfo, "sample_size", NULL, UNIV_SQL_NULL, DATA_FIXBINARY, 0); } - UNIV_MEM_ASSERT_RW_ABORT(stat_description, strlen(stat_description)); pars_info_add_str_literal(pinfo, "stat_description", stat_description); diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 2045df354b3..34afe458687 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -4161,10 +4161,20 @@ struct Check { Check check; ut_list_validate(space->chain, check); ut_a(space->size == check.size); - ut_ad(space->id != TRX_SYS_SPACE - || space == fil_system.sys_space); - ut_ad(space->id != SRV_TMP_SPACE_ID - || space == fil_system.temp_space); + + switch (space->id) { + case TRX_SYS_SPACE: + ut_ad(fil_system.sys_space == NULL + || fil_system.sys_space == space); + break; + case SRV_TMP_SPACE_ID: + ut_ad(fil_system.temp_space == NULL + || fil_system.temp_space == space); + break; + default: + break; + } + return(check.n_open); } }; @@ -4174,24 +4184,15 @@ Checks the consistency of the tablespace cache. @return true if ok */ bool fil_validate() { - fil_space_t* space; fil_node_t* fil_node; ulint n_open = 0; mutex_enter(&fil_system.mutex); - /* Look for spaces in the hash table */ - - for (ulint i = 0; i < fil_system.spaces.n_cells; i++) { - - for (space = static_cast<fil_space_t*>( - HASH_GET_FIRST(&fil_system.spaces, i)); - space != 0; - space = static_cast<fil_space_t*>( - HASH_GET_NEXT(hash, space))) { - - n_open += Check::validate(space); - } + for (fil_space_t *space = UT_LIST_GET_FIRST(fil_system.space_list); + space != NULL; + space = UT_LIST_GET_NEXT(space_list, space)) { + n_open += Check::validate(space); } ut_a(fil_system.n_open == n_open); diff --git a/storage/innobase/fsp/fsp0sysspace.cc b/storage/innobase/fsp/fsp0sysspace.cc index f0dea8ebde2..5d381fca033 100644 --- a/storage/innobase/fsp/fsp0sysspace.cc +++ b/storage/innobase/fsp/fsp0sysspace.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2013, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2020, MariaDB Corporation. +Copyright (c) 2016, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -906,9 +906,13 @@ SysTablespace::open_or_create( } else if (is_temp) { ut_ad(!fil_system.temp_space); ut_ad(space_id() == SRV_TMP_SPACE_ID); - space = fil_system.temp_space = fil_space_create( + space = fil_space_create( name(), SRV_TMP_SPACE_ID, flags(), FIL_TYPE_TEMPORARY, NULL); + + mutex_enter(&fil_system.mutex); + fil_system.temp_space = space; + mutex_exit(&fil_system.mutex); if (!space) { return DB_ERROR; } @@ -917,9 +921,13 @@ SysTablespace::open_or_create( } else { ut_ad(!fil_system.sys_space); ut_ad(space_id() == TRX_SYS_SPACE); - space = fil_system.sys_space = fil_space_create( + space = fil_space_create( name(), TRX_SYS_SPACE, it->flags(), FIL_TYPE_TABLESPACE, NULL); + + mutex_enter(&fil_system.mutex); + fil_system.sys_space = space; + mutex_exit(&fil_system.mutex); if (!space) { return DB_ERROR; } diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 7f89a0b6f42..145f5c27e5f 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -804,6 +804,29 @@ fts_check_cached_index( return(TRUE); } +/** Clear all fts resources when there is no internal DOC_ID +and there are no new fts index to add. +@param[in,out] table table where fts is to be freed +@param[in] trx transaction to drop all fts tables */ +void fts_clear_all(dict_table_t *table, trx_t *trx) +{ + if (DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID) || + !table->fts || + !ib_vector_is_empty(table->fts->indexes)) + return; + + for (const dict_index_t *index= dict_table_get_first_index(table); + index; index= dict_table_get_next_index(index)) + if (index->type & DICT_FTS) + return; + + fts_optimize_remove_table(table); + + fts_drop_tables(trx, table); + fts_free(table); + DICT_TF2_FLAG_UNSET(table, DICT_TF2_FTS); +} + /*******************************************************************//** Drop auxiliary tables related to an FTS index @return DB_SUCCESS or error number */ @@ -820,30 +843,15 @@ fts_drop_index( ut_a(indexes); if ((ib_vector_size(indexes) == 1 - && (index == static_cast<dict_index_t*>( - ib_vector_getp(table->fts->indexes, 0)))) - || ib_vector_is_empty(indexes)) { + && (index == static_cast<dict_index_t*>( + ib_vector_getp(table->fts->indexes, 0))) + && DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID)) + || ib_vector_is_empty(indexes)) { doc_id_t current_doc_id; doc_id_t first_doc_id; DICT_TF2_FLAG_UNSET(table, DICT_TF2_FTS); - /* If Doc ID column is not added internally by FTS index, - we can drop all FTS auxiliary tables. Otherwise, we will - need to keep some common table such as CONFIG table, so - as to keep track of incrementing Doc IDs */ - if (!DICT_TF2_FLAG_IS_SET( - table, DICT_TF2_FTS_HAS_DOC_ID)) { - - err = fts_drop_tables(trx, table); - - err = fts_drop_index_tables(trx, index); - - fts_free(table); - - return(err); - } - current_doc_id = table->fts->cache->next_doc_id; first_doc_id = table->fts->cache->first_doc_id; fts_cache_clear(table->fts->cache); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index df9f52adb51..9344ec660b9 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -55,6 +55,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include <mysql/service_thd_alloc.h> #include <mysql/service_thd_wait.h> #include "field.h" +#include "scope.h" #include "srv0srv.h" // MYSQL_PLUGIN_IMPORT extern my_bool lower_case_file_system; @@ -7032,7 +7033,9 @@ build_template_field( ut_ad(clust_index->table == index->table); templ = prebuilt->mysql_template + prebuilt->n_template++; - UNIV_MEM_INVALID(templ, sizeof *templ); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(templ, sizeof *templ); +#endif /* HAVE_valgrind_or_MSAN */ templ->is_virtual = !field->stored_in_db(); if (!templ->is_virtual) { @@ -8143,7 +8146,9 @@ calc_row_difference( /* The field has changed */ ufield = uvect->fields + n_changed; - UNIV_MEM_INVALID(ufield, sizeof *ufield); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(ufield, sizeof *ufield); +#endif /* HAVE_valgrind_or_MSAN */ /* Let us use a dummy dfield to make the conversion from the MySQL column format to the InnoDB format */ @@ -10566,6 +10571,7 @@ create_table_info_t::create_table_def() } heap = mem_heap_create(1000); + auto _ = make_scope_exit([heap]() { mem_heap_free(heap); }); ut_d(bool have_vers_start = false); ut_d(bool have_vers_end = false); @@ -10602,7 +10608,6 @@ create_table_info_t::create_table_def() table->name.m_name, field->field_name.str); err_col: dict_mem_table_free(table); - mem_heap_free(heap); ut_ad(trx_state_eq(m_trx, TRX_STATE_NOT_STARTED)); DBUG_RETURN(HA_ERR_GENERIC); } @@ -10630,7 +10635,6 @@ err_col: " must be below 256." " Unsupported code " ULINTPF ".", charset_no); - mem_heap_free(heap); dict_mem_table_free(table); DBUG_RETURN(ER_CANT_CREATE_TABLE); @@ -10785,8 +10789,6 @@ err_col: DBUG_SUICIDE();); } - mem_heap_free(heap); - DBUG_EXECUTE_IF("ib_create_err_tablespace_exist", err = DB_TABLESPACE_EXISTS;); diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 97f56796e69..f878a483019 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -10383,6 +10383,7 @@ commit_cache_norebuild( dict_index_remove_from_cache(index->table, index); } + fts_clear_all(ctx->old_table, trx); trx_commit_for_mysql(trx); } diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index d2d9a546969..0f1fe0bf814 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -7036,7 +7036,7 @@ i_s_tablespaces_encryption_fill_table( RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name.str); /* deny access to user without PROCESS_ACL privilege */ - if (check_global_access(thd, SUPER_ACL)) { + if (check_global_access(thd, PROCESS_ACL)) { DBUG_RETURN(0); } diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 4e0b25c52dd..e316e1b7dab 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1156,7 +1156,7 @@ struct buf_block_t{ # define assert_block_ahi_empty(block) \ ut_a((block)->n_pointers == 0) # define assert_block_ahi_empty_on_init(block) do { \ - UNIV_MEM_VALID(&(block)->n_pointers, sizeof (block)->n_pointers); \ + MEM_MAKE_DEFINED(&(block)->n_pointers, sizeof (block)->n_pointers); \ assert_block_ahi_empty(block); \ } while (0) # define assert_block_ahi_valid(block) \ diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index c264ae07ff8..242c9cbb65d 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -185,7 +185,9 @@ buf_page_alloc_descriptor(void) bpage = (buf_page_t*) ut_zalloc_nokey(sizeof *bpage); ut_ad(bpage); - UNIV_MEM_ALLOC(bpage, sizeof *bpage); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(bpage, sizeof *bpage); +#endif /* HAVE_valgrind_or_MSAN */ return(bpage); } diff --git a/storage/innobase/include/data0data.ic b/storage/innobase/include/data0data.ic index 857ffc15d76..2d1bf5a2d50 100644 --- a/storage/innobase/include/data0data.ic +++ b/storage/innobase/include/data0data.ic @@ -51,10 +51,6 @@ dfield_set_len( ulint len) /*!< in: length or UNIV_SQL_NULL */ { ut_ad(len != UNIV_SQL_DEFAULT); -#ifdef UNIV_VALGRIND_DEBUG - if (len != UNIV_SQL_NULL) UNIV_MEM_ASSERT_RW(field->data, len); -#endif /* UNIV_VALGRIND_DEBUG */ - field->ext = 0; field->len = static_cast<unsigned int>(len); } @@ -94,9 +90,6 @@ dfield_set_data( const void* data, /*!< in: data */ ulint len) /*!< in: length or UNIV_SQL_NULL */ { -#ifdef UNIV_VALGRIND_DEBUG - if (len != UNIV_SQL_NULL) UNIV_MEM_ASSERT_RW(data, len); -#endif /* UNIV_VALGRIND_DEBUG */ field->data = (void*) data; field->ext = 0; field->len = static_cast<unsigned int>(len); @@ -111,9 +104,7 @@ dfield_write_mbr( dfield_t* field, /*!< in: field */ const double* mbr) /*!< in: data */ { -#ifdef UNIV_VALGRIND_DEBUG - if (len != UNIV_SQL_NULL) UNIV_MEM_ASSERT_RW(data, len); -#endif /* UNIV_VALGRIND_DEBUG */ + MEM_CHECK_DEFINED(mbr, sizeof *mbr); field->ext = 0; for (unsigned i = 0; i < SPDIMS * 2; i++) { @@ -175,7 +166,7 @@ dfield_dup( mem_heap_t* heap) /*!< in: memory heap where allocated */ { if (!dfield_is_null(field)) { - UNIV_MEM_ASSERT_RW(field->data, field->len); + MEM_CHECK_DEFINED(field->data, field->len); field->data = mem_heap_dup(heap, field->data, field->len); } } @@ -333,8 +324,9 @@ dtuple_create_from_mem( } } #endif - UNIV_MEM_ASSERT_W(tuple->fields, n_t_fields * sizeof *tuple->fields); - UNIV_MEM_INVALID(tuple->fields, n_t_fields * sizeof *tuple->fields); + MEM_CHECK_ADDRESSABLE(tuple->fields, n_t_fields + * sizeof *tuple->fields); + MEM_UNDEFINED(tuple->fields, n_t_fields * sizeof *tuple->fields); return(tuple); } diff --git a/storage/innobase/include/dict0stats.ic b/storage/innobase/include/dict0stats.ic index 3c24e7a8fc3..dbdbceab9ba 100644 --- a/storage/innobase/include/dict0stats.ic +++ b/storage/innobase/include/dict0stats.ic @@ -187,41 +187,40 @@ dict_stats_deinit( table->stat_initialized = FALSE; -#ifdef UNIV_DEBUG_VALGRIND - UNIV_MEM_INVALID(&table->stat_n_rows, - sizeof(table->stat_n_rows)); - UNIV_MEM_INVALID(&table->stat_clustered_index_size, - sizeof(table->stat_clustered_index_size)); - UNIV_MEM_INVALID(&table->stat_sum_of_other_index_sizes, - sizeof(table->stat_sum_of_other_index_sizes)); - UNIV_MEM_INVALID(&table->stat_modified_counter, - sizeof(table->stat_modified_counter)); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&table->stat_n_rows, sizeof table->stat_n_rows); + MEM_UNDEFINED(&table->stat_clustered_index_size, + sizeof table->stat_clustered_index_size); + MEM_UNDEFINED(&table->stat_sum_of_other_index_sizes, + sizeof table->stat_sum_of_other_index_sizes); + MEM_UNDEFINED(&table->stat_modified_counter, + sizeof table->stat_modified_counter); dict_index_t* index; for (index = dict_table_get_first_index(table); index != NULL; index = dict_table_get_next_index(index)) { - UNIV_MEM_INVALID( + MEM_UNDEFINED( index->stat_n_diff_key_vals, index->n_uniq - * sizeof(index->stat_n_diff_key_vals[0])); - UNIV_MEM_INVALID( + * sizeof index->stat_n_diff_key_vals[0]); + MEM_UNDEFINED( index->stat_n_sample_sizes, index->n_uniq - * sizeof(index->stat_n_sample_sizes[0])); - UNIV_MEM_INVALID( + * sizeof index->stat_n_sample_sizes[0]); + MEM_UNDEFINED( index->stat_n_non_null_key_vals, index->n_uniq - * sizeof(index->stat_n_non_null_key_vals[0])); - UNIV_MEM_INVALID( + * sizeof index->stat_n_non_null_key_vals[0]); + MEM_UNDEFINED( &index->stat_index_size, sizeof(index->stat_index_size)); - UNIV_MEM_INVALID( + MEM_UNDEFINED( &index->stat_n_leaf_pages, sizeof(index->stat_n_leaf_pages)); } -#endif /* UNIV_DEBUG_VALGRIND */ +#endif /* HAVE_valgrind_or_MSAN */ rw_lock_x_unlock(&table->stats_latch); } diff --git a/storage/innobase/include/fts0fts.h b/storage/innobase/include/fts0fts.h index 0f3a568a048..9e0cab12373 100644 --- a/storage/innobase/include/fts0fts.h +++ b/storage/innobase/include/fts0fts.h @@ -24,8 +24,7 @@ Full text search header file Created 2011/09/02 Sunny Bains ***********************************************************************/ -#ifndef fts0fts_h -#define fts0fts_h +#pragma once #include "data0type.h" #include "data0types.h" @@ -986,8 +985,12 @@ fts_trx_t* fts_trx_create( trx_t* trx); +/** Clear all fts resources when there is no internal DOC_ID +and there are no new fts index to add. +@param[in,out] table table where fts is to be freed +@param[in] trx transaction to drop all fts tables */ +void fts_clear_all(dict_table_t *table, trx_t *trx); + /** Sync the table during commit phase @param[in] table table to be synced */ void fts_sync_during_ddl(dict_table_t* table); - -#endif /*!< fts0fts.h */ diff --git a/storage/innobase/include/mem0mem.ic b/storage/innobase/include/mem0mem.ic index 2a88c0f1065..c1e7348a548 100644 --- a/storage/innobase/include/mem0mem.ic +++ b/storage/innobase/include/mem0mem.ic @@ -203,7 +203,7 @@ mem_heap_alloc( mem_block_set_free(block, free + MEM_SPACE_NEEDED(n)); buf = buf + REDZONE_SIZE; - UNIV_MEM_ALLOC(buf, n - REDZONE_SIZE); + MEM_UNDEFINED(buf, n - REDZONE_SIZE); return(buf); } @@ -268,7 +268,7 @@ mem_heap_free_heap_top( ulint(old_top - reinterpret_cast<byte*>(block))); ut_ad(mem_block_get_start(block) <= mem_block_get_free(block)); - UNIV_MEM_FREE(old_top, (byte*) block + block->len - old_top); + MEM_NOACCESS(old_top, (byte*) block + block->len - old_top); /* If free == start, we may free the block if it is not the first one */ @@ -342,7 +342,7 @@ mem_heap_free_top( == mem_block_get_start(block))) { mem_heap_block_free(heap, block); } else { - UNIV_MEM_FREE((byte*) block + mem_block_get_free(block), n); + MEM_NOACCESS((byte*) block + mem_block_get_free(block), n); } } diff --git a/storage/innobase/include/page0zip.ic b/storage/innobase/include/page0zip.ic index a59d880284a..ede61283f33 100644 --- a/storage/innobase/include/page0zip.ic +++ b/storage/innobase/include/page0zip.ic @@ -218,7 +218,7 @@ page_zip_get_trailer_len( ulint uncompressed_size; ut_ad(page_zip_simple_validate(page_zip)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); if (!page_is_leaf(page_zip->data)) { uncompressed_size = PAGE_ZIP_DIR_SLOT_SIZE diff --git a/storage/innobase/include/read0types.h b/storage/innobase/include/read0types.h index ff282aa1f3f..dc0ffffda1f 100644 --- a/storage/innobase/include/read0types.h +++ b/storage/innobase/include/read0types.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -290,7 +290,7 @@ public: MEM_UNDEFINED(&m_mutex, sizeof m_mutex); #endif #ifdef HAVE_valgrind - UNIV_MEM_VALID(&m_mutex, sizeof m_mutex); + MEM_MAKE_VALID(&m_mutex, sizeof m_mutex); #endif } }; diff --git a/storage/innobase/include/rem0rec.h b/storage/innobase/include/rem0rec.h index 197375b6301..c51e831fb0e 100644 --- a/storage/innobase/include/rem0rec.h +++ b/storage/innobase/include/rem0rec.h @@ -601,19 +601,17 @@ rec_offs_make_nth_extern( rec_offs* offsets, const ulint n); +MY_ATTRIBUTE((nonnull)) /** Determine the number of allocated elements for an array of offsets. @param[in] offsets offsets after rec_offs_set_n_alloc() @return number of elements */ -inline -ulint -rec_offs_get_n_alloc(const rec_offs* offsets) +inline ulint rec_offs_get_n_alloc(const rec_offs *offsets) { - ulint n_alloc; - ut_ad(offsets); - n_alloc = offsets[0]; - ut_ad(n_alloc > REC_OFFS_HEADER_SIZE); - UNIV_MEM_ASSERT_W(offsets, n_alloc * sizeof *offsets); - return(n_alloc); + ut_ad(offsets); + ulint n_alloc= offsets[0]; + ut_ad(n_alloc > REC_OFFS_HEADER_SIZE); + MEM_CHECK_ADDRESSABLE(offsets, n_alloc * sizeof *offsets); + return n_alloc; } /** Determine the number of fields for which offsets have been initialized. diff --git a/storage/innobase/include/rem0rec.ic b/storage/innobase/include/rem0rec.ic index 6d0a1771f6d..30c72a7415a 100644 --- a/storage/innobase/include/rem0rec.ic +++ b/storage/innobase/include/rem0rec.ic @@ -703,7 +703,7 @@ rec_offs_set_n_alloc( ulint n_alloc) /*!< in: number of elements */ { ut_ad(n_alloc > REC_OFFS_HEADER_SIZE); - UNIV_MEM_ALLOC(offsets, n_alloc * sizeof *offsets); + MEM_UNDEFINED(offsets, n_alloc * sizeof *offsets); offsets[0] = static_cast<rec_offs>(n_alloc); } diff --git a/storage/innobase/include/srv0mon.h b/storage/innobase/include/srv0mon.h index 8f497fa9f44..8e833642ee0 100644 --- a/storage/innobase/include/srv0mon.h +++ b/storage/innobase/include/srv0mon.h @@ -2,7 +2,7 @@ Copyright (c) 2010, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -651,14 +651,14 @@ Use MONITOR_DEC if appropriate mutex protection exists. } \ } -#ifdef UNIV_DEBUG_VALGRIND +#ifdef HAVE_valgrind_or_MSAN # define MONITOR_CHECK_DEFINED(value) do { \ mon_type_t m = value; \ - UNIV_MEM_ASSERT_RW(&m, sizeof m); \ + MEM_CHECK_DEFINED(&m, sizeof m); \ } while (0) -#else /* UNIV_DEBUG_VALGRIND */ +#else /* HAVE_valgrind_or_MSAN */ # define MONITOR_CHECK_DEFINED(value) (void) 0 -#endif /* UNIV_DEBUG_VALGRIND */ +#endif /* HAVE_valgrind_or_MSAN */ #define MONITOR_INC_VALUE(monitor, value) \ MONITOR_CHECK_DEFINED(value); \ diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index 147a6285e5c..18c228e56c3 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -170,14 +170,6 @@ using the call command. */ #define UNIV_ENABLE_UNIT_TEST_ROW_RAW_FORMAT_INT */ -#include <my_valgrind.h> - -#if defined HAVE_valgrind && defined HAVE_VALGRIND_MEMCHECK_H -# define UNIV_DEBUG_VALGRIND -#elif __has_feature(memory_sanitizer) -# define UNIV_DEBUG_VALGRIND -#endif - #ifdef DBUG_OFF # undef UNIV_DEBUG #elif !defined UNIV_DEBUG @@ -185,8 +177,6 @@ using the call command. */ #endif #if 0 -#define UNIV_DEBUG_VALGRIND /* Enable extra - Valgrind instrumentation */ #define UNIV_DEBUG_PRINT /* Enable the compilation of some debug print functions */ #define UNIV_AHI_DEBUG /* Enable adaptive hash index @@ -575,56 +565,6 @@ typedef void* os_thread_ret_t; #include "ut0ut.h" #include "sync0types.h" -/* define UNIV macros in terms of my_valgrind.h */ -#define UNIV_MEM_INVALID(addr, size) MEM_UNDEFINED(addr, size) -#define UNIV_MEM_FREE(addr, size) MEM_NOACCESS(addr, size) -#define UNIV_MEM_ALLOC(addr, size) UNIV_MEM_INVALID(addr, size) -#ifdef UNIV_DEBUG_VALGRIND -# include <valgrind/memcheck.h> -# define UNIV_MEM_VALID(addr, size) MEM_MAKE_DEFINED(addr, size) -# define UNIV_MEM_DESC(addr, size) VALGRIND_CREATE_BLOCK(addr, size, #addr) -# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b) -# define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) do { \ - const void* _p = (const void*) (ulint) \ - VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \ - if (UNIV_LIKELY_NULL(_p)) { \ - fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \ - __FILE__, __LINE__, \ - (const void*) (addr), (unsigned) (size), (long) \ - (((const char*) _p) - ((const char*) (addr)))); \ - if (should_abort) { \ - ut_error; \ - } \ - } \ -} while (0) -# define UNIV_MEM_ASSERT_RW(addr, size) \ - UNIV_MEM_ASSERT_RW_LOW(addr, size, false) -# define UNIV_MEM_ASSERT_RW_ABORT(addr, size) \ - UNIV_MEM_ASSERT_RW_LOW(addr, size, true) -# define UNIV_MEM_ASSERT_W(addr, size) do { \ - const void* _p = (const void*) (ulint) \ - VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \ - if (UNIV_LIKELY_NULL(_p)) \ - fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \ - __FILE__, __LINE__, \ - (const void*) (addr), (unsigned) (size), (long) \ - (((const char*) _p) - ((const char*) (addr)))); \ - } while (0) -# define UNIV_MEM_TRASH(addr, c, size) do { \ - ut_d(memset(addr, c, size)); \ - UNIV_MEM_INVALID(addr, size); \ - } while (0) -#else -# define UNIV_MEM_VALID(addr, size) do {} while(0) -# define UNIV_MEM_DESC(addr, size) do {} while(0) -# define UNIV_MEM_UNDESC(b) do {} while(0) -# define UNIV_MEM_ASSERT_RW_LOW(addr, size, should_abort) do {} while(0) -# define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0) -# define UNIV_MEM_ASSERT_RW_ABORT(addr, size) do {} while(0) -# define UNIV_MEM_ASSERT_W(addr, size) do {} while(0) -# define UNIV_MEM_TRASH(addr, c, size) do {} while(0) -#endif - extern ulong srv_page_size_shift; extern ulong srv_page_size; diff --git a/storage/innobase/include/ut0pool.h b/storage/innobase/include/ut0pool.h index f6006144dc4..703a07a23f2 100644 --- a/storage/innobase/include/ut0pool.h +++ b/storage/innobase/include/ut0pool.h @@ -94,7 +94,7 @@ struct Pool { #ifdef HAVE_valgrind /* Declare the contents as initialized for Valgrind; we checked this in mem_free(). */ - UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type); + MEM_MAKE_DEFINED(&elem->m_type, sizeof elem->m_type); #endif Factory::destroy(&elem->m_type); } @@ -137,13 +137,12 @@ struct Pool { MEM_UNDEFINED(&elem->m_type, sizeof elem->m_type); # endif # ifdef HAVE_valgrind - /* Declare the memory initialized for Valgrind. The trx_t that are released to the pool are actually initialized; we checked that by - UNIV_MEM_ASSERT_RW() in mem_free() below. */ - UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type); + MEM_CHECK_DEFINED() in mem_free() below. */ # endif + MEM_MAKE_DEFINED(&elem->m_type, sizeof elem->m_type); } #endif @@ -159,7 +158,7 @@ struct Pool { byte* p = reinterpret_cast<byte*>(ptr + 1); elem = reinterpret_cast<Element*>(p - sizeof(*elem)); - UNIV_MEM_ASSERT_RW(&elem->m_type, sizeof elem->m_type); + MEM_CHECK_DEFINED(&elem->m_type, sizeof elem->m_type); elem->m_pool->m_lock_strategy.enter(); diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index aa70d67c28a..2a4891f2716 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -1093,8 +1093,8 @@ create_block: ut_calc_align<uint16_t>(static_cast<uint16_t>(len), ALIGNMENT); static_assert(ut_is_2pow(ALIGNMENT), "ALIGNMENT must be a power of 2"); UT_LIST_ADD_FIRST(blocks, block); - UNIV_MEM_INVALID(block->frame, len); - UNIV_MEM_FREE(block->frame + len, srv_page_size - len); + MEM_UNDEFINED(block->frame, len); + MEM_NOACCESS(block->frame + len, srv_page_size - len); return my_assume_aligned<ALIGNMENT>(block->frame); } @@ -1113,7 +1113,7 @@ create_block: block->page.access_time= ((block->page.access_time >> 16) + 1) << 16 | ut_calc_align<uint16_t>(static_cast<uint16_t>(free_offset), ALIGNMENT); - UNIV_MEM_ALLOC(block->frame + free_offset - len, len); + MEM_UNDEFINED(block->frame + free_offset - len, len); return my_assume_aligned<ALIGNMENT>(block->frame + free_offset - len); } @@ -1758,7 +1758,7 @@ inline void recv_sys_t::add(const page_id_t page_id, { /* Use already allocated 'padding' bytes */ append: - UNIV_MEM_ALLOC(end + 1, len); + MEM_UNDEFINED(end + 1, len); /* Append to the preceding record for the page */ tail->append(l, len); return; diff --git a/storage/innobase/mem/mem0mem.cc b/storage/innobase/mem/mem0mem.cc index 261d8062bd6..6d4593e0ab4 100644 --- a/storage/innobase/mem/mem0mem.cc +++ b/storage/innobase/mem/mem0mem.cc @@ -322,8 +322,7 @@ mem_heap_create_block_func( /* Not the first allocation for the heap. This block's total_length field should be set to undefined. */ ut_d(block->total_size = ULINT_UNDEFINED); - UNIV_MEM_INVALID(&block->total_size, - sizeof block->total_size); + MEM_UNDEFINED(&block->total_size, sizeof block->total_size); heap->total_size += len; } @@ -331,7 +330,7 @@ mem_heap_create_block_func( /* Poison all available memory. Individual chunks will be unpoisoned on every mem_heap_alloc() call. */ compile_time_assert(MEM_BLOCK_HEADER_SIZE >= sizeof *block); - UNIV_MEM_FREE(block + 1, len - sizeof *block); + MEM_NOACCESS(block + 1, len - sizeof *block); ut_ad((ulint)MEM_BLOCK_HEADER_SIZE < len); diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index 2a2f61641fe..16a0ecc051c 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -354,8 +354,10 @@ struct mtr_write_log_t { /** Start a mini-transaction. */ void mtr_t::start() { - UNIV_MEM_INVALID(this, sizeof *this); - UNIV_MEM_VALID(&m_freed_pages, sizeof(m_freed_pages)); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(this, sizeof *this); + MEM_MAKE_DEFINED(&m_freed_pages, sizeof(m_freed_pages)); +#endif /* HAVE_valgrind_or_MSAN */ ut_d(m_start= true); ut_d(m_commit= false); diff --git a/storage/innobase/os/os0proc.cc b/storage/innobase/os/os0proc.cc index 32747aae3ab..819e16f2302 100644 --- a/storage/innobase/os/os0proc.cc +++ b/storage/innobase/os/os0proc.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2019, MariaDB Corporation. +Copyright (c) 2019, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc index 666f7c8d788..92e7ce5e60d 100644 --- a/storage/innobase/page/page0cur.cc +++ b/storage/innobase/page/page0cur.cc @@ -1302,7 +1302,7 @@ page_cur_insert_rec_low( /* 1. Get the size of the physical record in the page */ const ulint rec_size= rec_offs_size(offsets); -#ifdef UNIV_DEBUG_VALGRIND +#ifdef HAVE_valgrind_or_MSAN { const void *rec_start= rec - rec_offs_extra_size(offsets); ulint extra_size= rec_offs_extra_size(offsets) - @@ -1310,11 +1310,11 @@ page_cur_insert_rec_low( ? REC_N_NEW_EXTRA_BYTES : REC_N_OLD_EXTRA_BYTES); /* All data bytes of the record must be valid. */ - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); /* The variable-length header must be valid. */ - UNIV_MEM_ASSERT_RW(rec_start, extra_size); + MEM_CHECK_DEFINED(rec_start, extra_size); } -#endif /* UNIV_DEBUG_VALGRIND */ +#endif /* HAVE_valgrind_or_MSAN */ /* 2. Try to find suitable space from page memory management */ bool reuse= false; @@ -1613,7 +1613,7 @@ static inline void page_zip_dir_add_slot(buf_block_t *block, page_zip_des_t *page_zip= &block->page.zip; ut_ad(page_is_comp(page_zip->data)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); /* Read the old n_dense (n_heap has already been incremented). */ ulint n_dense= page_dir_get_n_heap(page_zip->data) - (PAGE_HEAP_NO_USER_LOW + @@ -1702,16 +1702,16 @@ page_cur_insert_rec_zip( /* 1. Get the size of the physical record in the page */ const ulint rec_size= rec_offs_size(offsets); -#ifdef UNIV_DEBUG_VALGRIND +#ifdef HAVE_valgrind_or_MSAN { const void *rec_start= rec - rec_offs_extra_size(offsets); ulint extra_size= rec_offs_extra_size(offsets) - REC_N_NEW_EXTRA_BYTES; /* All data bytes of the record must be valid. */ - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); /* The variable-length header must be valid. */ - UNIV_MEM_ASSERT_RW(rec_start, extra_size); + MEM_CHECK_DEFINED(rec_start, extra_size); } -#endif /* UNIV_DEBUG_VALGRIND */ +#endif /* HAVE_valgrind_or_MSAN */ const bool reorg_before_insert= page_has_garbage(cursor->block->frame) && rec_size > page_get_max_insert_size(cursor->block->frame, 1) && rec_size <= page_get_max_insert_size_after_reorganize(cursor->block->frame, @@ -1954,8 +1954,8 @@ use_heap: rec_set_bit_field_2(insert_rec, heap_no, REC_NEW_HEAP_NO, REC_HEAP_NO_MASK, REC_HEAP_NO_SHIFT); - UNIV_MEM_ASSERT_RW(rec_get_start(insert_rec, offsets), - rec_offs_size(offsets)); + MEM_CHECK_DEFINED(rec_get_start(insert_rec, offsets), + rec_offs_size(offsets)); /* 6. Update the last insertion info in page header */ byte *last_insert= my_assume_aligned<4>(PAGE_LAST_INSERT + PAGE_HEADER + diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 21f2e9da75a..a89ae5b3a64 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -908,9 +908,9 @@ page_zip_compress_node_ptrs( /* Only leaf nodes may contain externally stored columns. */ ut_ad(!rec_offs_any_extern(offsets)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); /* Compress the extra bytes. */ c_stream->avail_in = static_cast<uInt>( @@ -973,8 +973,8 @@ page_zip_compress_sec( - c_stream->next_in); if (UNIV_LIKELY(c_stream->avail_in != 0)) { - UNIV_MEM_ASSERT_RW(c_stream->next_in, - c_stream->avail_in); + MEM_CHECK_DEFINED(c_stream->next_in, + c_stream->avail_in); err = deflate(c_stream, Z_NO_FLUSH); if (UNIV_UNLIKELY(err != Z_OK)) { break; @@ -1016,9 +1016,9 @@ page_zip_compress_clust_ext( int err; ulint i; - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); for (i = 0; i < rec_offs_n_fields(offsets); i++) { ulint len; @@ -1156,9 +1156,9 @@ page_zip_compress_clust( ULINT_UNDEFINED, &heap); ut_ad(rec_offs_n_fields(offsets) == dict_index_get_n_fields(index)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); /* Compress the extra bytes. */ c_stream->avail_in = static_cast<uInt>( @@ -1205,9 +1205,9 @@ page_zip_compress_clust( == rec_get_nth_field(rec, offsets, trx_id_col + 1, &len)); ut_ad(len == DATA_ROLL_PTR_LEN); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); /* Compress any preceding bytes. */ c_stream->avail_in = static_cast<uInt>( @@ -1300,7 +1300,7 @@ page_zip_compress( ut_ad(dict_table_is_comp(index->table)); ut_ad(!dict_index_is_ibuf(index)); - UNIV_MEM_ASSERT_RW(page, srv_page_size); + MEM_CHECK_DEFINED(page, srv_page_size); /* Check the data that will be omitted. */ ut_a(!memcmp(page + (PAGE_NEW_INFIMUM - REC_N_NEW_EXTRA_BYTES), @@ -1463,7 +1463,7 @@ page_zip_compress( trx_id_col = ULINT_UNDEFINED; } - UNIV_MEM_ASSERT_RW(c_stream.next_in, c_stream.avail_in); + MEM_CHECK_DEFINED(c_stream.next_in, c_stream.avail_in); err = deflate(&c_stream, Z_FULL_FLUSH); if (err != Z_OK) { goto zlib_error; @@ -1517,7 +1517,7 @@ page_zip_compress( - (c_stream.next_in - page)); ut_a(c_stream.avail_in <= srv_page_size - PAGE_ZIP_START - PAGE_DIR); - UNIV_MEM_ASSERT_RW(c_stream.next_in, c_stream.avail_in); + MEM_CHECK_DEFINED(c_stream.next_in, c_stream.avail_in); err = deflate(&c_stream, Z_FINISH); if (UNIV_UNLIKELY(err != Z_STREAM_END)) { @@ -1552,9 +1552,11 @@ err_exit: ut_ad(buf + c_stream.total_out == c_stream.next_out); ut_ad((ulint) (storage - c_stream.next_out) >= c_stream.avail_out); +#ifdef HAVE_valgrind /* Valgrind believes that zlib does not initialize some bits in the last 7 or 8 bytes of the stream. Make Valgrind happy. */ - UNIV_MEM_VALID(buf, c_stream.total_out); + MEM_MAKE_DEFINED(buf, c_stream.total_out); +#endif /* HAVE_valgrind */ /* Zero out the area reserved for the modification log. Space for the end marker of the modification log is not @@ -1585,7 +1587,7 @@ err_exit: page_zip_compress_write_log(block, index, mtr); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); #ifdef PAGE_ZIP_COMPRESS_DBG if (logfile) { @@ -3026,8 +3028,8 @@ page_zip_decompress_low( rec_offs* offsets; ut_ad(page_zip_simple_validate(page_zip)); - UNIV_MEM_ASSERT_W(page, srv_page_size); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_ADDRESSABLE(page, srv_page_size); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); /* The dense directory excludes the infimum and supremum records. */ n_dense = page_dir_get_n_heap(page_zip->data) - PAGE_HEAP_NO_USER_LOW; @@ -3074,7 +3076,9 @@ page_zip_decompress_low( /* Clear the uncompressed page, except the header. */ memset(PAGE_DATA + page, 0x55, srv_page_size - PAGE_DATA); #endif /* UNIV_ZIP_DEBUG */ - UNIV_MEM_INVALID(PAGE_DATA + page, srv_page_size - PAGE_DATA); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(PAGE_DATA + page, srv_page_size - PAGE_DATA); +#endif /* HAVE_valgrind_or_MSAN */ /* Copy the page directory. */ if (UNIV_UNLIKELY(!page_zip_dir_decode(page_zip, page, recs, @@ -3205,7 +3209,7 @@ err_exit: } ut_a(page_is_comp(page)); - UNIV_MEM_ASSERT_RW(page, srv_page_size); + MEM_CHECK_DEFINED(page, srv_page_size); page_zip_fields_free(index); mem_heap_free(heap); @@ -3346,8 +3350,8 @@ page_zip_validate_low( page_t* temp_page = static_cast<byte*>(aligned_malloc(srv_page_size, srv_page_size)); - UNIV_MEM_ASSERT_RW(page, srv_page_size); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page, srv_page_size); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); temp_page_zip = *page_zip; valid = page_zip_decompress_low(&temp_page_zip, temp_page, TRUE); @@ -3570,9 +3574,9 @@ page_zip_write_rec_ext( page_zip_des_t* const page_zip = &block->page.zip; ut_ad(rec_offs_validate(rec, index, offsets)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); externs -= (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN) * (page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW); @@ -3702,10 +3706,10 @@ void page_zip_write_rec(buf_block_t *block, const byte *rec, ut_ad(page_zip_header_cmp(page_zip, page)); ut_ad(page_simple_validate_new((page_t*) page)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); slot = page_zip_dir_find(page_zip, page_offset(rec)); ut_a(slot); @@ -3891,10 +3895,10 @@ page_zip_write_blob_ptr( ut_ad(page_is_leaf(page)); ut_ad(dict_index_is_clust(index)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); blob_no = page_zip_get_n_prev_extern(page_zip, rec, index) + rec_get_n_extern_new(rec, index, n); @@ -3944,8 +3948,8 @@ page_zip_write_node_ptr( ut_ad(!page_is_leaf(page)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); - UNIV_MEM_ASSERT_RW(rec, size); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(rec, size); storage = page_zip_dir_start(page_zip) - (rec_get_heap_no_new(rec) - 1) * REC_NODE_PTR_SIZE; @@ -3993,7 +3997,7 @@ page_zip_write_trx_id_and_roll_ptr( ut_ad(page_is_leaf(page)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); constexpr ulint sys_len = DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN; const ulint heap_no = rec_get_heap_no_new(rec); @@ -4056,10 +4060,10 @@ write: ut_a(!memcmp(storage - len, field - len, sys_len)); #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); } /**********************************************************************//** @@ -4093,10 +4097,10 @@ page_zip_clear_rec( heap_no = rec_get_heap_no_new(rec); ut_ad(heap_no >= PAGE_HEAP_NO_USER_LOW); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); if (!page_is_leaf(block->frame)) { /* Clear node_ptr. On the compressed page, @@ -4191,7 +4195,7 @@ page_zip_rec_set_owned( ut_ad(page_align(rec) == block->frame); page_zip_des_t *const page_zip= &block->page.zip; byte *slot= page_zip_dir_find(page_zip, page_offset(rec)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); byte b= *slot; if (flag) b|= (PAGE_ZIP_DIR_SLOT_OWNED >> 8); @@ -4223,7 +4227,7 @@ page_zip_dir_insert( ut_ad(page_rec_get_next_const(cursor->rec) == rec); ut_ad(page_zip_simple_validate(page_zip)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); if (page_rec_is_infimum(cursor->rec)) { /* Use the first slot. */ @@ -4306,10 +4310,10 @@ void page_zip_dir_delete(buf_block_t *block, byte *rec, ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(rec_offs_comp(offsets)); - UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); - UNIV_MEM_ASSERT_RW(rec, rec_offs_data_size(offsets)); - UNIV_MEM_ASSERT_RW(rec - rec_offs_extra_size(offsets), - rec_offs_extra_size(offsets)); + MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets)); + MEM_CHECK_DEFINED(rec - rec_offs_extra_size(offsets), + rec_offs_extra_size(offsets)); mach_write_to_2(rec - REC_NEXT, free ? static_cast<uint16_t>(free - rec) : 0); @@ -4429,9 +4433,9 @@ page_zip_reorganize( ut_ad(!dict_index_is_ibuf(index)); ut_ad(!index->table->is_temporary()); /* Note that page_zip_validate(page_zip, page, index) may fail here. */ - UNIV_MEM_ASSERT_RW(page, srv_page_size); - UNIV_MEM_ASSERT_RW(buf_block_get_page_zip(block)->data, - page_zip_get_size(buf_block_get_page_zip(block))); + MEM_CHECK_DEFINED(page, srv_page_size); + MEM_CHECK_DEFINED(buf_block_get_page_zip(block)->data, + page_zip_get_size(buf_block_get_page_zip(block))); /* Disable logging */ mtr_log_t log_mode = mtr_set_log_mode(mtr, MTR_LOG_NONE); @@ -4547,10 +4551,10 @@ page_zip_copy_recs( ut_a(dict_index_is_clust(index)); } - UNIV_MEM_ASSERT_W(page, srv_page_size); - UNIV_MEM_ASSERT_W(page_zip->data, page_zip_get_size(page_zip)); - UNIV_MEM_ASSERT_RW(src, srv_page_size); - UNIV_MEM_ASSERT_RW(src_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_ADDRESSABLE(page, srv_page_size); + MEM_CHECK_ADDRESSABLE(page_zip->data, page_zip_get_size(page_zip)); + MEM_CHECK_DEFINED(src, srv_page_size); + MEM_CHECK_DEFINED(src_zip->data, page_zip_get_size(page_zip)); /* Copy those B-tree page header fields that are related to the records stored in the page. Also copy the field diff --git a/storage/innobase/row/row0ext.cc b/storage/innobase/row/row0ext.cc index 9b07727d058..b7a627603d9 100644 --- a/storage/innobase/row/row0ext.cc +++ b/storage/innobase/row/row0ext.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2006, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2019, MariaDB Corporation. +Copyright (c) 2019, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index 42188fb98b5..4698f25428c 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -888,7 +888,7 @@ loop: goto func_exit; } - UNIV_MEM_INVALID(block[t_ctx.buf_used], srv_sort_buf_size); + MEM_UNDEFINED(block[t_ctx.buf_used], srv_sort_buf_size); buf[t_ctx.buf_used] = row_merge_buf_empty(buf[t_ctx.buf_used]); mycount[t_ctx.buf_used] += t_ctx.rows_added[t_ctx.buf_used]; t_ctx.rows_added[t_ctx.buf_used] = 0; @@ -982,12 +982,14 @@ exit: goto func_exit; } - UNIV_MEM_INVALID(block[i], srv_sort_buf_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(block[i], srv_sort_buf_size); if (crypt_block[i]) { - UNIV_MEM_INVALID(crypt_block[i], - srv_sort_buf_size); + MEM_UNDEFINED(crypt_block[i], + srv_sort_buf_size); } +#endif /* HAVE_valgrind_or_MSAN */ } buf[i] = row_merge_buf_empty(buf[i]); diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 91c401cd4ba..5f3cdb4356e 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1240,8 +1240,10 @@ row_ins_foreign_check_on_constraint( update->info_bits = 0; update->n_fields = foreign->n_fields; - UNIV_MEM_INVALID(update->fields, - update->n_fields * sizeof *update->fields); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(update->fields, + update->n_fields * sizeof *update->fields); +#endif /* HAVE_valgrind_or_MSAN */ bool affects_fulltext = false; diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 1e5362180ba..78f605c373d 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -375,7 +375,9 @@ row_log_online_op( goto err_exit; } - UNIV_MEM_INVALID(log->tail.buf, sizeof log->tail.buf); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(log->tail.buf, sizeof log->tail.buf); +#endif /* HAVE_valgrind_or_MSAN */ ut_ad(log->tail.bytes < srv_sort_buf_size); avail_size = srv_sort_buf_size - log->tail.bytes; @@ -425,7 +427,7 @@ row_log_online_op( log->tail.buf, avail_size); } - UNIV_MEM_ASSERT_RW(buf, srv_sort_buf_size); + MEM_CHECK_DEFINED(buf, srv_sort_buf_size); if (row_log_tmpfile(log) == OS_FILE_CLOSED) { log->error = DB_OUT_OF_MEMORY; @@ -460,8 +462,10 @@ write_failed: index->type |= DICT_CORRUPT; } - UNIV_MEM_INVALID(log->tail.block, srv_sort_buf_size); - UNIV_MEM_INVALID(buf, srv_sort_buf_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(log->tail.block, srv_sort_buf_size); + MEM_UNDEFINED(buf, srv_sort_buf_size); +#endif /* HAVE_valgrind_or_MSAN */ memcpy(log->tail.block, log->tail.buf + avail_size, mrec_size - avail_size); @@ -471,7 +475,9 @@ write_failed: ut_ad(b == log->tail.block + log->tail.bytes); } - UNIV_MEM_INVALID(log->tail.buf, sizeof log->tail.buf); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(log->tail.buf, sizeof log->tail.buf); +#endif /* HAVE_valgrind_or_MSAN */ err_exit: mutex_exit(&log->mutex); } @@ -503,7 +509,9 @@ row_log_table_open( { mutex_enter(&log->mutex); - UNIV_MEM_INVALID(log->tail.buf, sizeof log->tail.buf); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(log->tail.buf, sizeof log->tail.buf); +#endif /* HAVE_valgrind_or_MSAN */ if (log->error != DB_SUCCESS) { err_exit: @@ -563,7 +571,7 @@ row_log_table_close_func( memcpy(buf + log->tail.bytes, log->tail.buf, avail); } - UNIV_MEM_ASSERT_RW(buf, srv_sort_buf_size); + MEM_CHECK_DEFINED(buf, srv_sort_buf_size); if (row_log_tmpfile(log) == OS_FILE_CLOSED) { log->error = DB_OUT_OF_MEMORY; @@ -595,8 +603,10 @@ row_log_table_close_func( write_failed: log->error = DB_ONLINE_LOG_TOO_BIG; } - UNIV_MEM_INVALID(log->tail.block, srv_sort_buf_size); - UNIV_MEM_INVALID(buf, srv_sort_buf_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(log->tail.block, srv_sort_buf_size); + MEM_UNDEFINED(buf, srv_sort_buf_size); +#endif /* HAVE_valgrind_or_MSAN */ memcpy(log->tail.block, log->tail.buf + avail, size - avail); log->tail.bytes = size - avail; } else { @@ -605,7 +615,9 @@ write_failed: } log->tail.total += size; - UNIV_MEM_INVALID(log->tail.buf, sizeof log->tail.buf); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(log->tail.buf, sizeof log->tail.buf); +#endif /* HAVE_valgrind_or_MSAN */ err_exit: mutex_exit(&log->mutex); @@ -2777,7 +2789,9 @@ row_log_table_apply_ops( ut_ad(new_trx_id_col > 0); ut_ad(new_trx_id_col != ULINT_UNDEFINED); - UNIV_MEM_INVALID(&mrec_end, sizeof mrec_end); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&mrec_end, sizeof mrec_end); +#endif /* HAVE_valgrind_or_MSAN */ offsets = static_cast<rec_offs*>(ut_malloc_nokey(i * sizeof *offsets)); rec_offs_set_n_alloc(offsets, i); @@ -3689,7 +3703,9 @@ row_log_apply_ops( ut_ad(!index->is_committed()); ut_ad(rw_lock_own(dict_index_get_lock(index), RW_LOCK_X)); ut_ad(index->online_log); - UNIV_MEM_INVALID(&mrec_end, sizeof mrec_end); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&mrec_end, sizeof mrec_end); +#endif /* HAVE_valgrind_or_MSAN */ offsets = static_cast<rec_offs*>(ut_malloc_nokey(i * sizeof *offsets)); rec_offs_set_n_alloc(offsets, i); diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index ac17f098292..d1074f74725 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -1021,11 +1021,11 @@ row_merge_buf_write( ut_a(b < &block[srv_sort_buf_size]); ut_a(b == &block[0] + buf->total_size); *b++ = 0; -#ifdef UNIV_DEBUG_VALGRIND +#ifdef HAVE_valgrind_or_MSAN /* The rest of the block is uninitialized. Initialize it to avoid bogus warnings. */ memset(b, 0xff, &block[srv_sort_buf_size] - b); -#endif /* UNIV_DEBUG_VALGRIND */ +#endif /* HAVE_valgrind_or_MSAN */ DBUG_LOG("ib_merge_sort", "write " << reinterpret_cast<const void*>(b) << ',' << of->fd << ',' << of->offset << " EOF"); @@ -1418,7 +1418,9 @@ row_merge_write_rec( return(NULL); } - UNIV_MEM_INVALID(&block[0], srv_sort_buf_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&block[0], srv_sort_buf_size); +#endif /* HAVE_valgrind_or_MSAN */ /* Copy the rest. */ b = &block[0]; @@ -1459,20 +1461,19 @@ row_merge_write_eof( ",fd=" << fd << ',' << *foffs); *b++ = 0; - UNIV_MEM_ASSERT_RW(&block[0], b - &block[0]); - UNIV_MEM_ASSERT_W(&block[0], srv_sort_buf_size); + MEM_CHECK_DEFINED(&block[0], b - &block[0]); + MEM_CHECK_ADDRESSABLE(&block[0], srv_sort_buf_size); -#ifdef UNIV_DEBUG_VALGRIND - /* The rest of the block is uninitialized. Initialize it - to avoid bogus warnings. */ - memset(b, 0xff, ulint(&block[srv_sort_buf_size] - b)); -#endif /* UNIV_DEBUG_VALGRIND */ + /* The rest of the block is uninitialized. Silence warnings. */ + MEM_MAKE_DEFINED(b, &block[srv_sort_buf_size] - b); if (!row_merge_write(fd, (*foffs)++, block, crypt_block, space)) { DBUG_RETURN(NULL); } - UNIV_MEM_INVALID(&block[0], srv_sort_buf_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&block[0], srv_sort_buf_size); +#endif DBUG_RETURN(&block[0]); } @@ -2660,8 +2661,10 @@ write_buffers: break; } - UNIV_MEM_INVALID( +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED( &block[0], srv_sort_buf_size); +#endif /* HAVE_valgrind_or_MSAN */ } } merge_buf[i] = row_merge_buf_empty(buf); @@ -3137,10 +3140,10 @@ row_merge( ulint n_run = 0; /*!< num of runs generated from this merge */ - UNIV_MEM_ASSERT_W(&block[0], 3 * srv_sort_buf_size); + MEM_CHECK_ADDRESSABLE(&block[0], 3 * srv_sort_buf_size); if (crypt_block) { - UNIV_MEM_ASSERT_W(&crypt_block[0], 3 * srv_sort_buf_size); + MEM_CHECK_ADDRESSABLE(&crypt_block[0], 3 * srv_sort_buf_size); } ut_ad(ihalf < file->offset); @@ -3161,7 +3164,9 @@ row_merge( foffs0 = 0; foffs1 = ihalf; - UNIV_MEM_INVALID(run_offset, *num_run * sizeof *run_offset); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(run_offset, *num_run * sizeof *run_offset); +#endif /* HAVE_valgrind_or_MSAN */ for (; foffs0 < ihalf && foffs1 < file->offset; foffs0++, foffs1++) { @@ -3242,7 +3247,9 @@ row_merge( *tmpfd = file->fd; *file = of; - UNIV_MEM_INVALID(&block[0], 3 * srv_sort_buf_size); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&block[0], 3 * srv_sort_buf_size); +#endif /* HAVE_valgrind_or_MSAN */ return(DB_SUCCESS); } @@ -3356,7 +3363,7 @@ row_merge_sort( break; } - UNIV_MEM_ASSERT_RW(run_offset, num_runs * sizeof *run_offset); + MEM_CHECK_DEFINED(run_offset, num_runs * sizeof *run_offset); } while (num_runs > 1); ut_free(run_offset); @@ -3916,6 +3923,7 @@ row_merge_drop_indexes( ut_error; } + fts_clear_all(table, trx); return; } @@ -3968,6 +3976,7 @@ row_merge_drop_indexes( } } + fts_clear_all(table, trx); table->drop_aborted = FALSE; ut_d(dict_table_check_for_dup_indexes(table, CHECK_ALL_COMPLETE)); } diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 298c2a3c879..20f06fc5444 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -294,9 +294,7 @@ row_mysql_store_geometry( { /* MySQL might assume the field is set to zero except the length and the pointer fields */ - UNIV_MEM_ASSERT_RW(src, src_len); - UNIV_MEM_ASSERT_W(dest, dest_len); - UNIV_MEM_INVALID(dest, dest_len); + MEM_CHECK_DEFINED(src, src_len); memset(dest, '\0', dest_len); diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 77a043acccc..8b46364c744 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -974,9 +974,11 @@ row_sel_get_clust_rec( switch (err) { case DB_SUCCESS: case DB_SUCCESS_LOCKED_REC: - /* Declare the variable uninitialized in Valgrind. +#ifdef HAVE_valgrind_or_MSAN + /* Declare the variable uninitialized. It should be set to DB_SUCCESS at func_exit. */ - UNIV_MEM_INVALID(&err, sizeof err); + MEM_UNDEFINED(&err, sizeof err); +#endif /* HAVE_valgrind_or_MSAN */ break; default: goto err_exit; @@ -2682,9 +2684,11 @@ row_sel_field_store_in_mysql_format_func( #endif /* UNIV_DEBUG */ ut_ad(len != UNIV_SQL_NULL); - UNIV_MEM_ASSERT_RW(data, len); - UNIV_MEM_ASSERT_W(dest, templ->mysql_col_len); - UNIV_MEM_INVALID(dest, templ->mysql_col_len); + MEM_CHECK_DEFINED(data, len); + MEM_CHECK_ADDRESSABLE(dest, templ->mysql_col_len); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(dest, templ->mysql_col_len); +#endif /* HAVE_valgrind_or_MSAN */ byte* pad = dest + len; @@ -2932,9 +2936,9 @@ row_sel_store_mysql_field( NULL value is set to the default value. */ ut_ad(templ->mysql_null_bit_mask); - UNIV_MEM_ASSERT_RW(prebuilt->default_rec - + templ->mysql_col_offset, - templ->mysql_col_len); + MEM_CHECK_DEFINED(prebuilt->default_rec + + templ->mysql_col_offset, + templ->mysql_col_len); #if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wconversion" /* GCC 5 may need this here */ @@ -3601,7 +3605,7 @@ row_sel_copy_cached_field_for_mysql( buf += templ->mysql_col_offset; cache += templ->mysql_col_offset; - UNIV_MEM_ASSERT_W(buf, templ->mysql_col_len); + MEM_CHECK_ADDRESSABLE(buf, templ->mysql_col_len); if (templ->mysql_type == DATA_MYSQL_TRUE_VARCHAR && (templ->type != DATA_INT)) { @@ -3611,7 +3615,9 @@ row_sel_copy_cached_field_for_mysql( row_mysql_read_true_varchar( &len, cache, templ->mysql_length_bytes); len += templ->mysql_length_bytes; - UNIV_MEM_INVALID(buf, templ->mysql_col_len); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(buf, templ->mysql_col_len); +#endif /* HAVE_valgrind_or_MSAN */ } else { len = templ->mysql_col_len; } @@ -3677,7 +3683,7 @@ row_sel_dequeue_cached_row_for_mysql( ut_ad(prebuilt->n_fetch_cached > 0); ut_ad(prebuilt->mysql_prefix_len <= prebuilt->mysql_row_len); - UNIV_MEM_ASSERT_W(buf, prebuilt->mysql_row_len); + MEM_CHECK_ADDRESSABLE(buf, prebuilt->mysql_row_len); cached_rec = prebuilt->fetch_cache[prebuilt->fetch_cache_first]; @@ -3687,7 +3693,9 @@ row_sel_dequeue_cached_row_for_mysql( /* The record is long. Copy it field by field, in case there are some long VARCHAR column of which only a small length is being used. */ - UNIV_MEM_INVALID(buf, prebuilt->mysql_prefix_len); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(buf, prebuilt->mysql_prefix_len); +#endif /* HAVE_valgrind_or_MSAN */ /* First copy the NULL bits. */ memcpy(buf, cached_rec, prebuilt->null_bitmap_len); @@ -3771,8 +3779,10 @@ row_sel_fetch_last_buf( } ut_ad(prebuilt->fetch_cache_first == 0); - UNIV_MEM_INVALID(prebuilt->fetch_cache[prebuilt->n_fetch_cached], - prebuilt->mysql_row_len); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(prebuilt->fetch_cache[prebuilt->n_fetch_cached], + prebuilt->mysql_row_len); +#endif /* HAVE_valgrind_or_MSAN */ return(prebuilt->fetch_cache[prebuilt->n_fetch_cached]); } diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 894ee3e1e0c..969d0017eeb 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -1542,7 +1542,9 @@ row_upd_changes_ord_field_binary_func( /* Silence a compiler warning without silencing a Valgrind error. */ dfield_len = 0; - UNIV_MEM_INVALID(&dfield_len, sizeof dfield_len); +#ifdef HAVE_valgrind_or_MSAN + MEM_UNDEFINED(&dfield_len, sizeof dfield_len); +#endif /* HAVE_valgrind_or_MSAN */ /* See if the column is stored externally. */ buf = row_ext_lookup(ext, col_no, &dfield_len); diff --git a/storage/innobase/sync/sync0arr.cc b/storage/innobase/sync/sync0arr.cc index a599ab2f644..a0203ca6bde 100644 --- a/storage/innobase/sync/sync0arr.cc +++ b/storage/innobase/sync/sync0arr.cc @@ -891,9 +891,9 @@ sync_array_print_long_waits_low( return(false); } -#ifdef UNIV_DEBUG_VALGRIND +#ifdef HAVE_valgrind /* Increase the timeouts if running under valgrind because it executes - extremely slowly. UNIV_DEBUG_VALGRIND does not necessary mean that + extremely slowly. HAVE_valgrind does not necessary mean that we are running under valgrind but we have no better way to tell. See Bug#58432 innodb.innodb_bug56143 fails under valgrind for an example */ diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index e44b4e497d1..eaf127b5a43 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -462,18 +462,18 @@ void trx_free(trx_t*& trx) MEM_UNDEFINED(&trx->state, sizeof trx->state); MEM_UNDEFINED(&trx->mysql_thd, sizeof trx->mysql_thd); #endif -#ifdef HAVE_valgrind +#ifdef HAVE_valgrind_or_MSAN /* Unpoison the memory for innodb_monitor_set_option; it is operating also on the freed transaction objects. We checked that these were initialized in trx_pools->mem_free(trx). */ - UNIV_MEM_VALID(&trx->mutex, sizeof trx->mutex); + MEM_MAKE_DEFINED(&trx->mutex, sizeof trx->mutex); /* For innobase_kill_connection() */ # ifdef WITH_WSREP - UNIV_MEM_VALID(&trx->wsrep, sizeof trx->wsrep); + MEM_MAKE_DEFINED(&trx->wsrep, sizeof trx->wsrep); # endif - UNIV_MEM_VALID(&trx->state, sizeof trx->state); - UNIV_MEM_VALID(&trx->mysql_thd, sizeof trx->mysql_thd); + MEM_MAKE_DEFINED(&trx->state, sizeof trx->state); + MEM_MAKE_DEFINED(&trx->mysql_thd, sizeof trx->mysql_thd); #endif trx = NULL; diff --git a/storage/innobase/ut/ut0crc32.cc b/storage/innobase/ut/ut0crc32.cc index 3c40a2aac7d..dabf92e875b 100644 --- a/storage/innobase/ut/ut0crc32.cc +++ b/storage/innobase/ut/ut0crc32.cc @@ -84,6 +84,7 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include <string.h> #include "ut0crc32.h" +#include "my_valgrind.h" #ifdef _MSC_VER # include <intrin.h> diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc index dfc1d62c60c..bf35e7857c5 100644 --- a/storage/innobase/ut/ut0ut.cc +++ b/storage/innobase/ut/ut0ut.cc @@ -148,8 +148,6 @@ ut_print_buf( const byte* data; ulint i; - UNIV_MEM_ASSERT_RW(buf, len); - fprintf(file, " len " ULINTPF "; hex ", len); for (data = (const byte*) buf, i = 0; i < len; i++) { @@ -184,8 +182,6 @@ ut_print_buf_hex( '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; - UNIV_MEM_ASSERT_RW(buf, len); - o << "(0x"; for (data = static_cast<const byte*>(buf), i = 0; i < len; i++) { @@ -208,8 +204,6 @@ ut_print_buf( const byte* data; ulint i; - UNIV_MEM_ASSERT_RW(buf, len); - for (data = static_cast<const byte*>(buf), i = 0; i < len; i++) { int c = static_cast<int>(*data++); o << (isprint(c) ? static_cast<char>(c) : ' '); diff --git a/storage/myisam/ftbench/Ecompare.pl b/storage/myisam/ftbench/Ecompare.pl index 07132ef9001..a97f126e64e 100755 --- a/storage/myisam/ftbench/Ecompare.pl +++ b/storage/myisam/ftbench/Ecompare.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (c) 2003, 2005 MySQL AB # Use is subject to license terms diff --git a/storage/myisam/ftbench/Ecreate.pl b/storage/myisam/ftbench/Ecreate.pl index 86af9f9c0a5..78962466c80 100755 --- a/storage/myisam/ftbench/Ecreate.pl +++ b/storage/myisam/ftbench/Ecreate.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (c) 2003, 2005 MySQL AB # Use is subject to license terms diff --git a/storage/myisam/ftbench/Ereport.pl b/storage/myisam/ftbench/Ereport.pl index d3f8961ec85..a8c7c57e1be 100755 --- a/storage/myisam/ftbench/Ereport.pl +++ b/storage/myisam/ftbench/Ereport.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (c) 2003, 2005 MySQL AB # Use is subject to license terms diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index 1b4f9aa6a17..090ababf238 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -188,9 +188,6 @@ endif() TARGET_LINK_LIBRARIES(rocksdb rocksdb_aux_lib) - FIND_LIBRARY(LZ4_LIBRARY - NAMES liblz4${PIC_EXT}.a lz4 - HINTS ${WITH_LZ4}/lib) CHECK_FUNCTION_EXISTS(sched_getcpu HAVE_SCHED_GETCPU) IF(HAVE_SCHED_GETCPU) @@ -252,13 +249,6 @@ ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Cla SET_TARGET_PROPERTIES(rocksdb_tools sst_dump mariadb-ldb PROPERTIES COMPILE_FLAGS "-Wno-error") ENDIF() -# Enable ZSTD if available. Upstream rocksdb cmake will use WITH_ZSTD and set -# defines within their code. -FIND_PACKAGE(zstd) -IF (ZSTD_FOUND) - SET(WITH_ZSTD ON) -ENDIF() - IF(GIT_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/.git) EXECUTE_PROCESS( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index 2e939587811..f7b2170978d 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -35,52 +35,47 @@ endif() # Optional compression libraries. -foreach(compression_lib LZ4 BZip2 ZSTD snappy) - FIND_PACKAGE(${compression_lib} QUIET) - - SET(WITH_ROCKSDB_${compression_lib} AUTO CACHE STRING - "Build RocksDB with ${compression_lib} compression. Possible values are 'ON', 'OFF', 'AUTO' and default is 'AUTO'") - - if(${WITH_ROCKSDB_${compression_lib}} STREQUAL "ON" AND NOT ${${compression_lib}_FOUND}) - MESSAGE(FATAL_ERROR - "${compression_lib} library was not found, but WITH_ROCKSDB${compression_lib} option is ON.\ - Either set WITH_ROCKSDB${compression_lib} to OFF, or make sure ${compression_lib} is installed") - endif() -endforeach() - -if(LZ4_FOUND AND (NOT WITH_ROCKSDB_LZ4 STREQUAL "OFF")) - add_definitions(-DLZ4) - include_directories(${LZ4_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS ${LZ4_LIBRARY}) -endif() - -if(BZIP2_FOUND AND (NOT WITH_ROCKSDB_BZip2 STREQUAL "OFF")) - add_definitions(-DBZIP2) - include_directories(${BZIP2_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS ${BZIP2_LIBRARIES}) -endif() - -if(SNAPPY_FOUND AND (NOT WITH_ROCKSDB_snappy STREQUAL "OFF")) - add_definitions(-DSNAPPY) - include_directories(${snappy_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS ${snappy_LIBRARIES}) -endif() - include(CheckFunctionExists) -if(ZSTD_FOUND AND (NOT WITH_ROCKSDB_ZSTD STREQUAL "OFF")) - SET(CMAKE_REQUIRED_LIBRARIES zstd) - CHECK_FUNCTION_EXISTS(ZDICT_trainFromBuffer ZSTD_VALID) - UNSET(CMAKE_REQUIRED_LIBRARIES) - if (WITH_ROCKSDB_ZSTD STREQUAL "ON" AND NOT ZSTD_VALID) +macro(check_lib package var) + STRING(TOUPPER ${package} PACKAGE_NAME) + SET(WITH_ROCKSDB_${package} AUTO CACHE STRING + "Build RocksDB with ${package} compression. Possible values are 'ON', 'OFF', 'AUTO' and default is 'AUTO'") + + IF (NOT ${WITH_ROCKSDB_${package}} STREQUAL "OFF") + FIND_PACKAGE(${package} QUIET) + IF (${${PACKAGE_NAME}_FOUND}) + IF(${ARGC} GREATER 2) + SET(CMAKE_REQUIRED_LIBRARIES ${${var}_LIBRARIES}) + CHECK_FUNCTION_EXISTS(${ARGV2} ${var}_VALID) + UNSET(CMAKE_REQUIRED_LIBRARIES) + ELSE() + SET(${var}_VALID TRUE) + ENDIF() + ENDIF() + ENDIF() + + IF(${${var}_VALID}) + MESSAGE_ONCE(rocksdb_${var} "Found ${package}: ${${var}_LIBRARIES}") + add_definitions(-D${PACKAGE_NAME}) + include_directories(${${var}_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${${var}_LIBRARIES}) + ELSEIF(${${PACKAGE_NAME}_FOUND}) + MESSAGE_ONCE(rocksdb_${var} "Found unusable ${package}: ${${var}_LIBRARIES} [${ARGV2}]") + ELSE() + MESSAGE_ONCE(rocksdb_${var} "Could NOT find ${package}") + ENDIF() + + IF (${WITH_ROCKSDB_${package}} STREQUAL "ON" AND NOT ${${PACKAGE_NAME}_FOUND}) MESSAGE(FATAL_ERROR - "WITH_ROCKSDB_ZSTD is ON and ZSTD library was found, but the version needs to be >= 1.1.3") + "${package} library was not found, but WITH_ROCKSDB_${package} option is ON.\ + Either set WITH_ROCKSDB_${package} to OFF, or make sure ${package} is installed") endif() - if (ZSTD_VALID) - add_definitions(-DZSTD) - include_directories(${ZSTD_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS ${ZSTD_LIBRARIES}) - endif() -endif() +endmacro() + +check_lib(LZ4 LZ4) +check_lib(BZip2 BZIP2) +check_lib(snappy snappy) # rocksdb/cmake/modules/Findsnappy.cmake violates the convention +check_lib(ZSTD ZSTD ZDICT_trainFromBuffer) add_definitions(-DZLIB) list(APPEND THIRDPARTY_LIBS ${ZLIB_LIBRARY}) |