Created
May 11, 2017 22:35
-
-
Save dasl-/876a5f125f5eec62dd20cadfba5660d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
commit b8c989c251bb3d67e587ddbe0b9223e147cbd76e | |
Author: dleibovic <[email protected]> | |
Date: Thu May 11 18:32:58 2017 -0400 | |
add a slave_of whitelist for creating connectors. this will be helpful for creating connectors for a subset of the comboshards as the gtid rollout progresses on the multishards (the comboshards are slaves of the multishards). | |
diff --git a/create-or-update-connectors.php b/create-or-update-connectors.php | |
index fd8f71f..7c95d34 100755 | |
--- a/create-or-update-connectors.php | |
+++ b/create-or-update-connectors.php | |
@@ -24,11 +24,12 @@ new class { | |
" -o <role> Create connectors for dbs with this mysql_role\n" . | |
" -k <csv> CSV of Kafka broker host:ports\n" . | |
" -s <id> Base server_id (default: " . self::DEFAULT_BASE_SERVER_ID . ")\n" . | |
- " -t Create DDL topic (default: disabled)\n"; | |
+ " -t Create DDL topic (default: disabled)\n" . | |
+ " -F <csv> comma separated slave_of whitelist regexes\n"; | |
} | |
private function parseOpts() { | |
- $opt = getopt('c:d:hk:Lo:p:r:s:tu:z:B:W:v'); | |
+ $opt = getopt('c:d:hk:Lo:p:r:s:tu:z:B:W:F:'); | |
$this->connect_url = $opt['c'] ?? self::DEFAULT_KAFKA_CONNECT_URL; | |
$this->db_class = $opt['d'] ?? ''; | |
$this->show_help = isset($opt['h']); | |
@@ -43,6 +44,12 @@ new class { | |
$this->zk_url = $opt['z'] ?? self::DEFAULT_ZK_URL; | |
$this->db_whitelist = isset($opt['W']) ? '@' . preg_quote($opt['W'], '@') . '@' : null; | |
$this->db_blacklist = isset($opt['B']) ? '@' . preg_quote($opt['B'], '@') . '@' : null; | |
+ if (isset($opt['F'])) { | |
+ $this->slave_of_whitelist_regexes = explode(",", $opt['F']); | |
+ foreach ($slave_of_whitelist_regexes as $key => $slave_of_whitelist_regex) { | |
+ $this->slave_of_whitelist_regexes[$key] = '@' . preg_quote($slave_of_whitelist_regex, '@') . '@'; | |
+ } | |
+ } | |
} | |
public function __construct() { | |
@@ -60,13 +67,27 @@ new class { | |
$host_port = $mysqld['host_port']; | |
$dbs_json = json_encode($mysqld['dbs']); | |
if ($this->db_blacklist && preg_match($this->db_blacklist, $dbs_json)) { | |
- echo "Blacklisted: {$host_port} {$dbs_json}\n"; | |
+ echo "Blacklisted by db blacklist: {$host_port} {$dbs_json}\n"; | |
continue; | |
} | |
if ($this->db_whitelist && !preg_match($this->db_whitelist, $dbs_json)) { | |
- echo "Not whitelisted: {$host_port} {$dbs_json}\n"; | |
+ echo "Not whitelisted by db whitelist: {$host_port} {$dbs_json}\n"; | |
continue; | |
} | |
+ if ($this->slave_of_whitelist_regexes) { | |
+ $is_slave_of_whitelisted = false; | |
+ foreach ($slave_of_whitelist_regexes as $slave_of_whitelist_regex) { | |
+ if (preg_match($slave_of_whitelist_regex, $mysqld['slave_of'])) { | |
+ $is_slave_of_whitelisted = true; | |
+ break; | |
+ } | |
+ } | |
+ if (!$is_slave_of_whitelisted) { | |
+ echo "Not whitelisted by slave_of whitelist: {$host_port} {$mysqld['slave_of']}\n"; | |
+ continue; | |
+ } | |
+ } | |
+ | |
$connector_name = $this->getConnectorName($host_port); | |
$ddl_topic = $this->getDdlTopicName($connector_name); | |
$server_uuid = $this->getMasterServerUuid($host_port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment