Skip to content

Commit 81f74c8

Browse files
kobi97krowinski
authored andcommitted
fix sending more than 16MB <2> (#47)
* patch sending_more_than_16mbyte <2> * add test shouldBeLongerTextThan16Mb * test error patch
1 parent e1f7c1a commit 81f74c8

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ before_script:
3232
- "echo '[mysqld]' | sudo tee /etc/mysql/conf.d/replication.cnf"
3333
- "echo 'log-bin=mysql-bin' | sudo tee -a /etc/mysql/conf.d/replication.cnf"
3434
- "echo 'server-id=1' | sudo tee -a /etc/mysql/conf.d/replication.cnf"
35-
- "echo 'binlog-format = row' | sudo tee -a /etc/mysql/conf.d/replication.cnf"
35+
- "echo 'binlog-format= row' | sudo tee -a /etc/mysql/conf.d/replication.cnf"
36+
- "echo 'max_allowed_packet= 64M' | sudo tee -a /etc/mysql/conf.d/replication.cnf"
37+
- "echo 'innodb_log_file_size= 250M' | sudo tee -a /etc/mysql/conf.d/replication.cnf"
3638
- "cat /etc/mysql/conf.d/replication.cnf"
3739

3840
# Enable GTID (only for mysql 5.*)

src/MySQLReplication/BinLog/BinLogSocketConnect.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getResponse($checkResponse = true)
8585

8686
$result = $this->socket->readFromSocket($dataLength);
8787
if (true === $checkResponse) {
88-
$this->isWriteSuccessful($result, $isMaxDataLength);
88+
$this->isWriteSuccessful($result);
8989
}
9090

9191
//https://dev.mysql.com/doc/internals/en/sending-more-than-16mbyte.html
@@ -96,11 +96,7 @@ public function getResponse($checkResponse = true)
9696
}
9797
$dataLength = unpack('L', $header[0] . $header[1] . $header[2] . chr(0))[1];
9898
$isMaxDataLength = $dataLength === $this->binaryDataMaxLength;
99-
10099
$next_result = $this->socket->readFromSocket($dataLength);
101-
if (true === $checkResponse) {
102-
$this->isWriteSuccessful($next_result, $isMaxDataLength);
103-
}
104100
$result .= $next_result;
105101
}
106102

@@ -109,15 +105,11 @@ public function getResponse($checkResponse = true)
109105

110106
/**
111107
* @param string $data
112-
* @param bool $isMaxDataLength
113108
*
114109
* @throws BinLogException
115110
*/
116-
private function isWriteSuccessful($data, $isMaxDataLength = false)
111+
private function isWriteSuccessful($data)
117112
{
118-
if ($isMaxDataLength) {
119-
return;
120-
}
121113
$head = ord($data[0]);
122114
if (!in_array($head, $this->packageOkHeader, true)) {
123115
$errorCode = unpack('v', $data[1] . $data[2])[1];

tests/Integration/TypesTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,24 @@ public function shouldBeLongBlob()
613613
self::assertEquals('World', $event->getValues()[0]['test2']);
614614
}
615615

616+
/**
617+
* https://dev.mysql.com/doc/internals/en/mysql-packet.html
618+
* https://dev.mysql.com/doc/internals/en/sending-more-than-16mbyte.html
619+
* @test
620+
*/
621+
public function shouldBeLongerTextThan16Mb()
622+
{
623+
$long_text_data = '';
624+
for ($i = 0; $i < 40000000; $i++) {
625+
$long_text_data .= 'a';
626+
}
627+
$create_query = "CREATE TABLE test (data LONGTEXT);";
628+
$insert_query = "INSERT INTO test (data) VALUES ('{$long_text_data}')";
629+
$event = $this->createAndInsertValue($create_query, $insert_query);
630+
631+
self::assertEquals(strlen($long_text_data), strlen($event->getValues()[0]['data']));
632+
}
633+
616634
/**
617635
* @test
618636
*/
@@ -815,4 +833,4 @@ public function shouldBeJson()
815833
self::assertEquals('{"bool":false}', $results[26]['j']);
816834
self::assertEquals('{"null":null}', $results[27]['j']);
817835
}
818-
}
836+
}

0 commit comments

Comments
 (0)