Skip to content

Commit e41b5c5

Browse files
authored
Next release (#27)
## v3.0.1 (2017-08-16) - Fixed in config filter_var validation if 0 given - Changed if bin log and bin log file not given then use master otherwise given data will be send to master - Fixed isCheckSum mysql returns string NONE not an empty array and mariaDbGtid fix (tx to @kobi97) - Added travis mysql 5.6 and 5.7 env - Removed mariaDB support for query event - Fixed clear table map cache after rotate event
1 parent 2b0f26d commit e41b5c5

14 files changed

+57
-64
lines changed

.travis.yml

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1+
dist: trusty
2+
13
language: php
24

35
php:
46
- 5.5
57
- 5.6
68
- 7.0
7-
9+
env:
10+
- DB=mysql57
11+
- DB=mysql56
12+
813
cache:
914
apt: true
1015
bundler: true
1116
directories:
1217
- $HOME/.composer/cache
1318

14-
dist: trusty
1519
sudo: required
16-
addons:
17-
apt:
18-
packages:
19-
- mysql-server-5.6
20-
- mysql-client-core-5.6
21-
- mysql-client-5.6
2220

2321
before_script:
24-
- "sudo /etc/init.d/mysql stop || true"
22+
- "sudo /etc/init.d/mysql stop || true"
23+
- "sudo apt-get remove mysql* -y"
24+
- "if [ $DB = 'mysql57' ]; then echo deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7 | sudo tee /etc/apt/sources.list.d/mysql.list; sudo apt-get update; sudo apt-get install mysql-server -y --allow-unauthenticated; fi"
25+
- "if [ $DB = 'mysql56' ]; then echo deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.6 | sudo tee /etc/apt/sources.list.d/mysql.list; sudo apt-get update; sudo apt-get install mysql-server -y --allow-unauthenticated; fi"
26+
- "sudo mysql_upgrade"
2527

2628
# Config
2729
- "echo '[mysqld]' | sudo tee /etc/mysql/conf.d/replication.cnf"
@@ -42,18 +44,13 @@ before_script:
4244

4345
- "mysql --version"
4446
- "mysql -u root -e 'SELECT VERSION();'"
45-
- "mysql -u root -e \"GRANT ALL PRIVILEGES ON *.* TO ''@'localhost';\""
47+
- "mysql -u root -e \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';\""
4648
- "mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root mysql"
4749

48-
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root
49-
50-
env:
51-
global:
52-
- setup=basic
50+
- if [ $DB = 'mysql56' ]; then echo "USE mysql;\nUPDATE user SET password=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root; fi
51+
- if [ $DB = 'mysql57' ]; then echo "USE mysql;\nUPDATE user SET authentication_string=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root; fi
5352

5453
install:
55-
- if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-source; fi
56-
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-stable; fi
57-
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-lowest --prefer-stable; fi
54+
travis_retry composer install --no-interaction --prefer-source;
5855

5956
script: vendor/bin/phpunit

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
# Release Notes
44

5+
## v3.0.1 (2017-08-16)
6+
- Fixed in config filter_var validation if 0 given
7+
- Changed if bin log and bin log file not given then use master otherwise given data will be send to master
8+
- Fixed isCheckSum mysql returns string NONE not an empty array and mariaDbGtid fix (tx to @kobi97)
9+
- Added travis mysql 5.6 and 5.7 env
10+
- Removed mariaDB support for query event
11+
- Fixed clear table map cache after rotate event
12+
513
## v3.0.0 (2017-07-14)
614
- Added Cache interfaces for table info
715
- Changed examples to use ConfigBuilder

src/MySQLReplication/BinLog/BinLogSocketConnect.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private function setBinLogDump()
241241
{
242242
$binFilePos = Config::getBinLogPosition();
243243
$binFileName = Config::getBinLogFileName();
244-
if (0 === $binFilePos || '' === $binFileName) {
244+
if (0 === $binFilePos && '' === $binFileName) {
245245
$master = $this->repository->getMasterStatus();
246246
$binFilePos = $master['Position'];
247247
$binFileName = $master['File'];

src/MySQLReplication/Config/Config.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ public static function validate()
145145
}
146146
if (!empty(self::$host)) {
147147
$ip = gethostbyname(self::$host);
148-
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
148+
if (false === filter_var($ip, FILTER_VALIDATE_IP)) {
149149
throw new ConfigException(ConfigException::IP_ERROR_MESSAGE, ConfigException::IP_ERROR_CODE);
150150
}
151151
}
152-
if (!empty(self::$port) && !filter_var(
152+
if (!empty(self::$port) && false === filter_var(
153153
self::$port, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]
154154
)
155155
) {
@@ -171,9 +171,7 @@ public static function validate()
171171
}
172172
}
173173
}
174-
if (!empty(self::$slaveId) && !filter_var(
175-
self::$slaveId, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]
176-
)
174+
if (!empty(self::$slaveId) && false === filter_var(self::$slaveId, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])
177175
) {
178176
throw new ConfigException(ConfigException::SLAVE_ID_ERROR_MESSAGE, ConfigException::SLAVE_ID_ERROR_CODE);
179177
}
@@ -182,25 +180,23 @@ public static function validate()
182180
ConfigException::BIN_LOG_FILE_NAME_ERROR_MESSAGE, ConfigException::BIN_LOG_FILE_NAME_ERROR_CODE
183181
);
184182
}
185-
if (!empty(self::$binLogPosition) && !filter_var(
186-
self::$binLogPosition, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]
187-
)
188-
) {
183+
if (false === filter_var(self::$binLogPosition, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
189184
throw new ConfigException(
190185
ConfigException::BIN_LOG_FILE_POSITION_ERROR_MESSAGE, ConfigException::BIN_LOG_FILE_POSITION_ERROR_CODE
191186
);
192187
}
188+
193189
if (!empty(self::$mariaDbGtid) && !is_string(self::$mariaDbGtid)) {
194190
throw new ConfigException(
195191
ConfigException::MARIADBGTID_ERROR_MESSAGE, ConfigException::MARIADBGTID_ERROR_CODE
196192
);
197193
}
198-
if (!filter_var(self::$tableCacheSize, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
194+
if (false === filter_var(self::$tableCacheSize, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
199195
throw new ConfigException(
200196
ConfigException::TABLE_CACHE_SIZE_ERROR_MESSAGE, ConfigException::TABLE_CACHE_SIZE_ERROR_CODE
201197
);
202198
}
203-
if (0 !== self::$heartbeatPeriod && !filter_var(
199+
if (0 !== self::$heartbeatPeriod && false === filter_var(
204200
self::$heartbeatPeriod, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 4294967]]
205201
)
206202
) {

src/MySQLReplication/Event/Event.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use MySQLReplication\Event\RowEvent\RowEventFactory;
1616
use MySQLReplication\Exception\MySQLReplicationException;
1717
use MySQLReplication\JsonBinaryDecoder\JsonBinaryDecoderException;
18+
use Psr\SimpleCache\CacheInterface;
1819
use Psr\SimpleCache\InvalidArgumentException;
1920
use Symfony\Component\EventDispatcher\EventDispatcher;
2021

@@ -40,24 +41,31 @@ class Event
4041
* @var EventDispatcher
4142
*/
4243
private $eventDispatcher;
44+
/**
45+
* @var CacheInterface
46+
*/
47+
private $cache;
4348

4449
/**
4550
* BinLogPack constructor.
4651
* @param BinLogSocketConnect $socketConnect
4752
* @param BinaryDataReaderFactory $packageService
4853
* @param RowEventFactory $rowEventService
4954
* @param EventDispatcher $eventDispatcher
55+
* @param CacheInterface $cache
5056
*/
5157
public function __construct(
5258
BinLogSocketConnect $socketConnect,
5359
BinaryDataReaderFactory $packageService,
5460
RowEventFactory $rowEventService,
55-
EventDispatcher $eventDispatcher
61+
EventDispatcher $eventDispatcher,
62+
CacheInterface $cache
5663
) {
5764
$this->socketConnect = $socketConnect;
5865
$this->packageService = $packageService;
5966
$this->rowEventService = $rowEventService;
6067
$this->eventDispatcher = $eventDispatcher;
68+
$this->cache = $cache;
6169
}
6270

6371
/**
@@ -130,6 +138,8 @@ public function consume()
130138
(new XidEvent($eventInfo, $binaryDataReader))->makeXidDTO()
131139
);
132140
} elseif (ConstEventType::ROTATE_EVENT === $eventInfo->getType()) {
141+
$this->cache->clear();
142+
133143
$this->eventDispatcher->dispatch(
134144
ConstEventsNames::ROTATE,
135145
(new RotateEvent($eventInfo, $binaryDataReader))->makeRotateEventDTO()

src/MySQLReplication/Event/QueryEvent.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public function makeQueryDTO()
2727
$this->binaryDataReader->advance($statusVarsLength);
2828
$schema = $this->binaryDataReader->read($schemaLength);
2929
$this->binaryDataReader->advance(1);
30-
$query = $this->binaryDataReader->read(
31-
$this->eventInfo->getSize() - $this->getSizeToRemoveByVersion() - $statusVarsLength - $schemaLength - 1
32-
);
30+
$query = $this->binaryDataReader->read($this->eventInfo->getSizeNoHeader() - 13 - $statusVarsLength - $schemaLength - 1);
3331

3432
return new QueryDTO(
3533
$this->eventInfo,
@@ -38,16 +36,4 @@ public function makeQueryDTO()
3836
$query
3937
);
4038
}
41-
42-
/**
43-
* @return int
44-
*/
45-
private function getSizeToRemoveByVersion()
46-
{
47-
if (BinLogServerInfo::isMariaDb()) {
48-
return 13;
49-
}
50-
51-
return 36;
52-
}
53-
}
39+
}

src/MySQLReplication/Exception/MySQLReplicationException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class MySQLReplicationException extends \Exception
3737
const GTID_ERROR_CODE = 406;
3838
const SLAVE_ID_ERROR_MESSAGE = 'Incorrect slave id type';
3939
const SLAVE_ID_ERROR_CODE = 407;
40-
const BIN_LOG_FILE_NAME_ERROR_MESSAGE = 'Incorrect binlog name type';
40+
const BIN_LOG_FILE_NAME_ERROR_MESSAGE = 'Incorrect binlog name';
4141
const BIN_LOG_FILE_NAME_ERROR_CODE = 408;
42-
const BIN_LOG_FILE_POSITION_ERROR_MESSAGE = 'Incorrect binlog position type';
42+
const BIN_LOG_FILE_POSITION_ERROR_MESSAGE = 'Incorrect binlog position';
4343
const BIN_LOG_FILE_POSITION_ERROR_CODE = 409;
4444
const MARIADBGTID_ERROR_MESSAGE = 'Maria gtid must be string';
4545
const MARIADBGTID_ERROR_CODE = 410;

src/MySQLReplication/MySQLReplicationFactory.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,21 @@ public function __construct()
6767
]
6868
);
6969
$repository = new MySQLRepository($this->connection);
70+
$cache = new ArrayCache();
7071

7172
$rowEventService = new RowEventFactory(
7273
$repository,
7374
new JsonBinaryDecoderFactory(),
74-
new ArrayCache()
75+
$cache
7576
);
7677
$this->eventDispatcher = new EventDispatcher();
7778

7879
$this->event = new Event(
7980
new BinLogSocketConnect($repository, new Socket()),
8081
new BinaryDataReaderFactory(),
8182
$rowEventService,
82-
$this->eventDispatcher
83+
$this->eventDispatcher,
84+
$cache
8385
);
8486
}
8587

src/MySQLReplication/Repository/MySQLRepository.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,7 @@ public function isCheckSum()
7575
{
7676
$res = $this->getConnection()->fetchAssoc('SHOW GLOBAL VARIABLES LIKE "BINLOG_CHECKSUM"');
7777

78-
if (!isset($res['Value'])) {
79-
return false;
80-
}
81-
82-
$check_sum = $res['Value'];
83-
84-
return (!empty($check_sum) && strtolower($check_sum) !== 'none');
78+
return isset($res['Value']) && $res['Value'] !== 'NONE';
8579
}
8680

8781
/**

tests/Integration/BasicTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public function shouldFilterTables()
186186
$this->connection->exec('CREATE TABLE test_3 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))');
187187
$this->connection->exec('CREATE TABLE test_4 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))');
188188

189-
190189
$this->connection->exec('INSERT INTO test_4 (data) VALUES (\'foo\')');
191190
$this->connection->exec('INSERT INTO test_3 (data) VALUES (\'bar\')');
192191
$this->connection->exec('INSERT INTO test_2 (data) VALUES (\''. $expectedValue .'\')');
@@ -197,8 +196,4 @@ public function shouldFilterTables()
197196
self::assertEquals($expectedTable, $event->getTableMap()->getTable());
198197
self::assertEquals($expectedValue, $event->getValues()[0]['data']);
199198
}
200-
201-
202-
203-
204199
}

tests/Unit/BinaryDataReader/BinaryDataReaderBuilderTest.php

100755100644
File mode changed.

tests/Unit/BinaryDataReader/BinaryDataReaderServiceTest.php

100755100644
File mode changed.

tests/Unit/BinaryDataReader/BinaryDataReaderTest.php

100755100644
File mode changed.

tests/Unit/Repository/MySQLRepositoryTest.php

100755100644
+6-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ public function shouldIsCheckSum()
5353
{
5454
self::assertFalse($this->mySQLRepositoryTest->isCheckSum());
5555

56-
$this->connection->method('fetchAssoc')->willReturn(['Value' => 'CRC32']);
56+
$this->connection->method('fetchAssoc')->willReturnOnConsecutiveCalls(
57+
['Value' => 'CRC32'],
58+
['Value' => 'NONE']
59+
);
60+
5761
self::assertTrue($this->mySQLRepositoryTest->isCheckSum());
62+
self::assertFalse($this->mySQLRepositoryTest->isCheckSum());
5863
}
5964

6065
/**

0 commit comments

Comments
 (0)