Skip to content

Commit f4818d7

Browse files
committed
Bug#30567054 - INNOBASE/DICT: REFINE DICT_TEMP_FILE_NUM WITH C++11 ATOMICS
- This bug is a contribution by Mr. Yibo Cai. - The contribution proposes replacing the built-in atomic operations with the std::atomic calls in dict0mem. - WL#14235 already replaced the old atomic increment with the std::atomic calls. - However, the contribution also proposes relaxed memory order for the initial store operation, as well as the fetch_add. I believe this is fine since this variable is not used as part of some synchronization mechanism, it is only a counter which needs to be incrmented atomically from different threads. RB#25338 Approved by Elzbieta Babij<[email protected]>
1 parent 29c0bb6 commit f4818d7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

storage/innobase/dict/dict0mem.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
3131
Created 1/8/1996 Heikki Tuuri
3232
***********************************************************************/
3333

34+
#include <atomic>
3435
#ifndef UNIV_HOTBACKUP
3536
#include <mysql_com.h>
3637

@@ -756,14 +757,14 @@ char *dict_mem_create_temporary_tablename(mem_heap_t *heap, const char *dbtab,
756757
size_t dblen = dbend - dbtab + 1;
757758

758759
/* Increment a randomly initialized number for each temp file. */
759-
dict_temp_file_num.fetch_add(1);
760+
auto file_num =
761+
dict_temp_file_num.fetch_add(1, std::memory_order_relaxed) + 1;
760762

761763
size = dblen + (sizeof(TEMP_FILE_PREFIX) + 3 + 20 + 1 + 10);
762764
name = static_cast<char *>(mem_heap_alloc(heap, size));
763765
memcpy(name, dbtab, dblen);
764766
snprintf(name + dblen, size - dblen,
765-
TEMP_FILE_PREFIX_INNODB UINT64PF "-" UINT32PF, id,
766-
dict_temp_file_num.load());
767+
TEMP_FILE_PREFIX_INNODB UINT64PF "-" UINT32PF, id, file_num);
767768

768769
return (name);
769770
}
@@ -774,11 +775,11 @@ void dict_mem_init(void) {
774775
ib_uint32_t now = static_cast<ib_uint32_t>(ut_time());
775776

776777
const byte *buf = reinterpret_cast<const byte *>(&now);
778+
auto file_num = ut_crc32(buf, sizeof(now));
779+
dict_temp_file_num.store(file_num, std::memory_order_relaxed);
777780

778-
dict_temp_file_num = ut_crc32(buf, sizeof(now));
779-
780-
DBUG_PRINT("dict_mem_init", ("Starting Temporary file number is " UINT32PF,
781-
dict_temp_file_num.load()));
781+
DBUG_PRINT("dict_mem_init",
782+
("Starting Temporary file number is " UINT32PF, file_num));
782783
}
783784

784785
/** Validate the search order in the foreign key set.

0 commit comments

Comments
 (0)