Created
April 17, 2019 22:42
-
-
Save altmannmarcelo/b41dac9d64276b292ec884cdf6f18334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('UTC'); | |
$mysqli = new mysqli('127.0.0.1', 'root', 'sekret', 'test', 6033); | |
if ($mysqli->connect_error) { | |
die('Connect Error (' . $mysqli->connect_errno . ') ' | |
. $mysqli->connect_error); | |
} | |
/* Setup */ | |
echo date('Y-m-d H:i:s') . " Starting to SETUP the test\n"; | |
$mysqli->query("DROP TABLE IF EXISTS joinit"); | |
$mysqli->query("CREATE TABLE IF NOT EXISTS `test`.`joinit` ( | |
`i` bigint(11) NOT NULL AUTO_INCREMENT, | |
`s` char(255) DEFAULT NULL, | |
`t` datetime NOT NULL, | |
`g` bigint(11) NOT NULL, | |
KEY(`i`, `t`), | |
PRIMARY KEY(`i`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); | |
$date1=date('Y-m-d H:i:s'); | |
$mysqli->query("INSERT INTO test.joinit VALUES (NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )));"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
$mysqli->query("INSERT INTO test.joinit SELECT NULL, uuid(), time('$date1'), (FLOOR( 1 + RAND( ) *60 )) FROM test.joinit;"); | |
echo date('Y-m-d H:i:s') . " Starting to RUN the test\n"; | |
$result = $mysqli->query("SELECT MAX(i) FROM joinit"); | |
$row = $result->fetch_row(); | |
sleep(2); | |
$date2=date('Y-m-d H:i:s'); | |
for ($i=1; $i<$row[0]; $i++) | |
{ | |
$result = $mysqli->query("SELECT i FROM joinit WHERE i = $i"); | |
if($result->num_rows == 0) | |
continue; | |
$mysqli->query("UPDATE joinit SET t = '$date2' WHERE i = $i"); | |
$result = $mysqli->query("SELECT i FROM joinit WHERE t = '$date2' AND i = $i"); | |
if($result->num_rows == 0) | |
{ | |
echo date('Y-m-d H:i:s') . " Dirty Read Detected on i $i . . ."; | |
usleep(500000); | |
$result = $mysqli->query("SELECT i FROM joinit WHERE t = '$date2' AND i = $i"); | |
echo " After 500ms rows found $result->num_rows \n"; | |
} else { | |
echo date('Y-m-d H:i:s') . " i $i is ok\n"; | |
} | |
} | |
$mysqli->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment