I've been reading through this script and think that there may be some mismanagement around slave databases.
A quote from #2763135: Specify databases to convert; Do not convert all databases by default:
> In addition, if you have a slave database connection setup, you don't want to convert that because it supposed to be replicated from master (although the slave db connection should be read only to begin with).
This sounds like what is supposed to happen, you'd only update the master database and the slaves would just replicate.
Here's the current code:
public function convert(array $databases) {
$success = FALSE;
foreach ($databases as $database_key => $database_values) {
foreach ($database_values as $target => $database) {
// mysql, mysqli, etc.
if (strpos($database['driver'], 'mysql') === 0) {
drush_print('Target MySQL database: ' . $database['database'] . '@' . $database['host'] . ' (' . $database_key . ':' . $target . ')' );
// Connect to next database.
db_set_active($database_key);
$connection = Database::getConnection();
// Check the database type is mysql.
$db_type = $connection->databaseType();
// Skip if not MySQL.
if ($db_type !== 'mysql') {
continue;
}
if ($this->charset == 'utf8mb4' && !$connection->utf8mb4IsSupported()) {
drush_print('The ' . $database_key . ':' . $target . ' MySQL database does not support UTF8MB4! Ensure that the conditions listed in settings.php related to innodb_large_prefix, the server version, and the MySQL driver version are met. See https://www.drupal.org/node/2754539 for more information.');
continue;
}
// For each database:
$this->convertDatabase($database['database']);
// For each table in the database.
$this->convertTables();
$success = TRUE;
drush_print('Finished converting the ' . $database_key . ':' . $target . ' MySQL database!');
}
}
}
// Reset connection to default.
db_set_active();
return $success;
}
This loop can get into a bit of trouble if you have slave databases specified. This assumes that the array is structured as $database = $databases[$key][$target], but slaves are specified as a child array of arrays. From https://www.drupal.org/developing/api/database/configuration:
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'drupaldb1',
'username' => 'username',
'password' => 'secret',
'host' => 'dbserver1',
);
$databases['default']['slave'][] = array(
'driver' => 'mysql',
'database' => 'drupaldb2',
'username' => 'username',
'password' => 'secret',
'host' => 'dbserver2',
);
$databases['default']['slave'][] = array(
'driver' => 'mysql',
'database' => 'drupaldb3',
'username' => 'username',
'password' => 'secret',
'host' => 'dbserver3',
);
But even if you had slaves specified right now, it wouldn't cause a problem because there isn't any specification of a target in any of the queries. This means that if you have multiple targets (including slaves), the updates are just run on the default target multiple times.
But for this issue, I think the right thing to do here is simply skip any "slave" entry and let the database replication do the job anyway (as those connections would likely be read-only anyway).
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | utf8mb4_convert-2787233-5.patch | 3.13 KB | quicksketch |
| #3 | utf8mb4_convert-2787233.patch | 3.11 KB | quicksketch |
Comments
Comment #2
stefan.r commentedSounds good, can anyone post a patch?
Comment #3
quicksketchI would put this at the top of the
convert()method:Here's a patch as well, but it will conflict with the patch in #2787239: A connection with multiple targets just updates the first target repeatedly.
Comment #4
quicksketchOh wow, you already committed #2787239! I'll reroll.
Comment #5
quicksketchHere's a new one. Mostly indentation changing, as I found that to be a little easier to read, especially with two other
continuestatements in that loop already.Comment #7
stefan.r commentedOnce again looks great -- committed, thanks!
Comment #8
stefan.r commented