Skip to content

Commit f5e4c46

Browse files
committed
post-merge changes
* remove duplicate test file * move all uuidv7 tests into plugin/type_uuid/mysql-test/type_uuid/ * remove mysys/ changes * auto my_random_bytes() fallback - removes duplicate code from uuid, and fixes all other users of my_random_bytes() that don't check the return value (because, perhaps, they don't need crypto-strong random bytes) * End of 11.6 -> 11.7 in tests * clarify the warning text * UUID_VERSION_MASK()/UUID_VARIANT_MASK() must not depend on the version * allow 4x more monotonic uuidv7 per millisecond - instead of stretching 1000 microseconds over 12 bits, let's use extra 2 bits as a counter
1 parent 89e0944 commit f5e4c46

18 files changed

+88
-127
lines changed

mysys/my_init.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
471471
key_THR_LOCK_lock, key_THR_LOCK_malloc,
472472
key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
473473
key_THR_LOCK_open, key_THR_LOCK_threads,
474-
key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_uuid_generator,
475-
key_LOCK_uuid_v7_generator;
474+
key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_uuid_generator;
476475

477476
static PSI_mutex_info all_mysys_mutexes[]=
478477
{
@@ -499,8 +498,7 @@ static PSI_mutex_info all_mysys_mutexes[]=
499498
{ &key_THR_LOCK_threads, "THR_LOCK_threads", PSI_FLAG_GLOBAL},
500499
{ &key_TMPDIR_mutex, "TMPDIR_mutex", PSI_FLAG_GLOBAL},
501500
{ &key_THR_LOCK_myisam_mmap, "THR_LOCK_myisam_mmap", PSI_FLAG_GLOBAL},
502-
{ &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL },
503-
{ &key_LOCK_uuid_v7_generator, "LOCK_uuid_v7_generator", PSI_FLAG_GLOBAL }
501+
{ &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL }
504502
};
505503

506504
PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond,

mysys/mysys_priv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
4848
key_THR_LOCK_lock, key_THR_LOCK_malloc,
4949
key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
5050
key_THR_LOCK_open, key_THR_LOCK_threads, key_LOCK_uuid_generator,
51-
key_LOCK_uuid_v7_generator, key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap,
52-
key_LOCK_timer;
51+
key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_timer;
5352

5453
extern PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond,
5554
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,

mysys_ssl/my_crypt.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
#include <my_crypt.h>
2929
#include <ssl_compat.h>
30-
#include <cstdint>
30+
31+
#include <random>
3132

3233
#define CTX_ALIGN 16
3334

@@ -359,10 +360,25 @@ unsigned int my_aes_ctx_size(enum my_aes_mode)
359360
return MY_AES_CTX_SIZE;
360361
}
361362

363+
static std::mt19937 rnd;
364+
362365
int my_random_bytes(uchar *buf, int num)
363366
{
364367
if (RAND_bytes(buf, num) != 1)
368+
{ /* shouldn't happen */
369+
uchar *end= buf + num - 3;
370+
uint r= rnd();
371+
for (; buf < end; buf+= 4, r= rnd())
372+
int4store(buf, r);
373+
switch (num % 4)
374+
{
375+
case 0: break;
376+
case 1: *buf= rnd(); break;
377+
case 2: r=rnd(); int2store(buf, r); break;
378+
case 3: r=rnd(); int3store(buf, r); break;
379+
}
365380
return MY_AES_OPENSSL_ERROR;
381+
}
366382
return MY_AES_OK;
367383
}
368384

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
SET debug_dbug="+d,simulate_uuidv4_my_random_bytes_failure";
22
#
3-
# Start of 11.6 tests
4-
#
5-
#
63
# MDEV-11339 Support UUID v4 generation
74
#
85
CREATE TABLE t1 (
@@ -12,22 +9,22 @@ unique key(u)
129
);
1310
INSERT INTO t1(a) SELECT seq FROM seq_1_to_16;
1411
Warnings:
15-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
16-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
17-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
18-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
19-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
20-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
21-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
22-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
23-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
24-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
25-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
26-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
27-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
28-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
29-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
30-
Note 1105 UUIDv4 generation failed; using a my_rnd fallback
12+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
13+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
14+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
15+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
16+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
17+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
18+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
19+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
20+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
21+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
22+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
23+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
24+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
25+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
26+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
27+
Note 1105 UUIDv4: RANDOM_BYTES() failed, using fallback
3128
SELECT COUNT(DISTINCT u) AS distinct_uuid_count FROM t1;
3229
distinct_uuid_count
3330
16
@@ -38,7 +35,5 @@ FROM t1 GROUP BY is_correct_version_and_revision;
3835
is_correct_version_and_revision COUNT(*)
3936
1 16
4037
DROP TABLE t1;
41-
#
42-
# End of 11.6 tests
43-
#
38+
# End of 11.7 tests
4439
SET debug_dbug="";

plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.test

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ SET debug_dbug="+d,simulate_uuidv4_my_random_bytes_failure";
44

55
source include/have_sequence.inc;
66

7-
--echo #
8-
--echo # Start of 11.6 tests
9-
--echo #
10-
117
--echo #
128
--echo # MDEV-11339 Support UUID v4 generation
139
--echo #
@@ -25,8 +21,6 @@ SELECT
2521
FROM t1 GROUP BY is_correct_version_and_revision;
2622
DROP TABLE t1;
2723

28-
--echo #
29-
--echo # End of 11.6 tests
30-
--echo #
24+
--echo # End of 11.7 tests
3125

3226
SET debug_dbug="";

plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#
2-
# Start of 11.6 tests
3-
#
4-
#
52
# MDEV-11339 Support UUID v4 generation
63
#
74
SELECT
@@ -30,6 +27,4 @@ PLUGIN_DESCRIPTION Function UUIDv4()
3027
PLUGIN_LICENSE GPL
3128
PLUGIN_MATURITY Experimental
3229
PLUGIN_AUTH_VERSION 1.0
33-
#
34-
# End of 11.6 tests
35-
#
30+
# End of 11.7 tests

plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
--echo #
2-
--echo # Start of 11.6 tests
3-
--echo #
4-
51
--echo #
62
--echo # MDEV-11339 Support UUID v4 generation
73
--echo #
@@ -25,6 +21,4 @@ WHERE PLUGIN_TYPE='FUNCTION'
2521
ORDER BY PLUGIN_NAME;
2622
--horizontal_results
2723

28-
--echo #
29-
--echo # End of 11.6 tests
30-
--echo #
24+
--echo # End of 11.7 tests
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#
2-
# Start of 11.6 tests
3-
#
4-
#
52
# MDEV-11339 Support UUID v4 generation
63
#
74
CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUIDv4(), unique key(u));
@@ -10,6 +7,4 @@ select count(distinct u) AS distinct_uuid_count from t1;
107
distinct_uuid_count
118
100
129
drop table t1;
13-
#
14-
# End of 11.6 tests
15-
#
10+
# End of 11.7 tests
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
source include/have_sequence.inc;
22

3-
--echo #
4-
--echo # Start of 11.6 tests
5-
--echo #
6-
73
--echo #
84
--echo # MDEV-11339 Support UUID v4 generation
95
--echo #
@@ -13,6 +9,4 @@ insert into t1(a) select seq from seq_1_to_100;
139
select count(distinct u) AS distinct_uuid_count from t1;
1410
drop table t1;
1511

16-
--echo #
17-
--echo # End of 11.6 tests
18-
--echo #
12+
--echo # End of 11.7 tests
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#
2-
# Start of 11.6 tests
3-
#
4-
#
52
# MDEV-11339 Support UUID v4 generation
63
#
74
SELECT UUIDv4() REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision;
85
is_correct_version_and_revision
96
1
10-
#
11-
# End of 11.6 tests
12-
#
7+
# End of 11.7 tests

0 commit comments

Comments
 (0)