2017-05-06 02:21:12 +03:00
|
|
|
# Copyright 2017 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2015-09-18 11:35:06 +03:00
|
|
|
"""Define abstractions for various mysql flavors.
|
|
|
|
|
2016-08-16 21:26:41 +03:00
|
|
|
This module is used by mysql_db_mysqlctl.py to handle differences
|
|
|
|
between various flavors of mysql.
|
|
|
|
"""
|
2015-09-18 10:44:35 +03:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
2016-08-16 21:26:41 +03:00
|
|
|
import sys
|
2015-09-18 10:44:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
# For now, vttop is only used in this module. If other people
|
|
|
|
# need this, we should move it to environment.
|
2015-11-10 02:33:54 +03:00
|
|
|
if "VTTOP" not in os.environ:
|
2015-09-18 10:44:35 +03:00
|
|
|
sys.stderr.write(
|
2015-11-10 02:33:54 +03:00
|
|
|
"ERROR: Vitess environment not set up. "
|
2015-09-18 10:44:35 +03:00
|
|
|
'Please run "source dev.env" first.\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# vttop is the toplevel of the vitess source tree
|
2015-11-10 02:33:54 +03:00
|
|
|
vttop = os.environ["VTTOP"]
|
|
|
|
|
2015-09-18 10:44:35 +03:00
|
|
|
|
|
|
|
class MysqlFlavor(object):
|
|
|
|
"""Base class with default SQL statements."""
|
|
|
|
|
|
|
|
def my_cnf(self):
|
|
|
|
"""Returns the path to an extra my_cnf file, or None."""
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
class MariaDB(MysqlFlavor):
|
|
|
|
"""Overrides specific to MariaDB."""
|
|
|
|
|
|
|
|
def my_cnf(self):
|
|
|
|
files = [
|
|
|
|
os.path.join(vttop, "config/mycnf/default-fast.cnf"),
|
2015-11-10 02:33:54 +03:00
|
|
|
os.path.join(vttop, "config/mycnf/master_mariadb.cnf"),
|
|
|
|
]
|
2015-09-18 10:44:35 +03:00
|
|
|
return ":".join(files)
|
|
|
|
|
|
|
|
|
|
|
|
class MySQL56(MysqlFlavor):
|
2016-08-16 21:26:41 +03:00
|
|
|
"""Overrides specific to MySQL 5.6."""
|
2015-09-18 10:44:35 +03:00
|
|
|
|
|
|
|
def my_cnf(self):
|
|
|
|
files = [
|
|
|
|
os.path.join(vttop, "config/mycnf/default-fast.cnf"),
|
2015-10-08 21:50:11 +03:00
|
|
|
os.path.join(vttop, "config/mycnf/master_mysql56.cnf"),
|
2015-11-10 02:33:54 +03:00
|
|
|
]
|
2015-09-18 10:44:35 +03:00
|
|
|
return ":".join(files)
|
|
|
|
|
|
|
|
|
|
|
|
__mysql_flavor = None
|
|
|
|
|
|
|
|
|
|
|
|
# mysql_flavor is a function because we need something to import before the
|
|
|
|
# actual __mysql_flavor is initialized, since that doesn't happen until after
|
|
|
|
# the command-line options are parsed. If we make mysql_flavor a variable and
|
|
|
|
# import it before it's initialized, the module that imported it won't get the
|
|
|
|
# updated value when it's later initialized.
|
|
|
|
def mysql_flavor():
|
|
|
|
return __mysql_flavor
|
|
|
|
|
|
|
|
|
|
|
|
def set_mysql_flavor(flavor):
|
|
|
|
global __mysql_flavor
|
|
|
|
|
2016-08-17 19:34:40 +03:00
|
|
|
# Last default is there because the environment variable might be set to "".
|
2016-08-16 21:26:41 +03:00
|
|
|
flavor = flavor or os.environ.get("MYSQL_FLAVOR", "MariaDB") or "MariaDB"
|
2015-09-18 10:44:35 +03:00
|
|
|
|
|
|
|
# Set the environment variable explicitly in case we're overriding it via
|
|
|
|
# command-line flag.
|
|
|
|
os.environ["MYSQL_FLAVOR"] = flavor
|
|
|
|
|
|
|
|
if flavor == "MariaDB":
|
|
|
|
__mysql_flavor = MariaDB()
|
|
|
|
elif flavor == "MySQL56":
|
|
|
|
__mysql_flavor = MySQL56()
|
|
|
|
else:
|
|
|
|
logging.error("Unknown MYSQL_FLAVOR '%s'", flavor)
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
logging.debug("Using MYSQL_FLAVOR=%s", str(flavor))
|