public static function releaseOscLock($conn) { $lock_command = sprintf("do release_lock('%s')", self::LOCK_STRING); $lock_result = mysql_query($lock_command, $conn); if (!$lock_result) { throw new Exception("RELEASE_LOCK failed:" . mysql_error($conn)); } if ($pid = OnlineSchemaChange::isOscLockHeld($conn)) { $kill_command = sprintf("kill %s", $pid); $kill_result = mysql_query($kill_command, $conn); if (!$kill_result) { throw new Exception("RELEASE_LOCK failed:" . mysql_error($conn)); } } }
function alter_to_create($db, $table, $ddl, $conn, $socket, $scratch_schema) { global $db_admin_user, $db_admin_pass; $sql = "SET SQL_LOG_BIN = 0"; $result = query($sql, $conn); if (!$result) { return false; } $sql = "SELECT SCHEMA()"; $result = query($sql, $conn); if (!$result) { return false; } $row = mysql_fetch_array($result); $old_schema = $row[0]; $result = query("USE {$scratch_schema}", $conn); if (!$result) { return false; } $sql = "CREATE TABLE test.{$table} LIKE {$db}.{$table}"; $result = query($sql, $conn); if (!$result) { return false; } $sql = $ddl; $result = query($sql, $conn); if (!$result) { OnlineSchemaChange::dropTable($table, $conn); return false; } $create_info = show_table_schema('localhost:' . $socket, $scratch_schema, $table); OnlineSchemaChange::dropTable($table, $conn); $result = query("USE {$old_schema}", $conn); if (!$result) { return false; } return $create_info['schema']; }