You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
MCOL-4069 mcs-loadbrm now loads EM from the primary node in a multi-node cluster.
This commit is contained in:
@ -1,35 +1,48 @@
|
|||||||
${PYTHON_SHEBANG}
|
#!/usr/bin/env python3
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
import configparser
|
||||||
import ConfigParser
|
|
||||||
else:
|
|
||||||
import configparser
|
api_config_file = '/etc/columnstore/cmapi_server.conf'
|
||||||
|
|
||||||
|
|
||||||
|
def get_key():
|
||||||
|
cmapi_config = configparser.ConfigParser()
|
||||||
|
try:
|
||||||
|
cmapi_config.read(api_config_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if 'Authentication' not in cmapi_config.sections():
|
||||||
|
return ''
|
||||||
|
return cmapi_config['Authentication'].get('x-api-key', '')
|
||||||
|
|
||||||
|
|
||||||
|
def get_version():
|
||||||
|
return '0.4.0'
|
||||||
|
|
||||||
|
|
||||||
|
def get_port():
|
||||||
|
return '8640'
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if sys.version_info < (3,0):
|
sm_config = configparser.ConfigParser()
|
||||||
sm_config = ConfigParser.ConfigParser()
|
|
||||||
else:
|
|
||||||
sm_config = configparser.ConfigParser()
|
|
||||||
|
|
||||||
sm_config.read('/etc/columnstore/storagemanager.cnf')
|
sm_config.read('/etc/columnstore/storagemanager.cnf')
|
||||||
cs_config = ET.parse('/etc/columnstore/Columnstore.xml')
|
cs_config = ET.parse('/etc/columnstore/Columnstore.xml')
|
||||||
config_root = cs_config.getroot()
|
config_root = cs_config.getroot()
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
storage = sm_config.get('ObjectStorage', 'service')
|
||||||
storage = sm_config.get('ObjectStorage', 'service')
|
if storage is None:
|
||||||
if storage is None:
|
storage = 'LocalStorage'
|
||||||
storage = 'LocalStorage'
|
bucket = sm_config.get('S3', 'bucket')
|
||||||
bucket = sm_config.get('S3', 'bucket')
|
if bucket is None:
|
||||||
if bucket is None:
|
bucket = 'some_bucket'
|
||||||
bucket = 'some_bucket'
|
|
||||||
else:
|
|
||||||
storage = sm_config.get('ObjectStorage', 'service', fallback='LocalStorage')
|
|
||||||
bucket = sm_config.get('S3', 'bucket', fallback='some_bucket')
|
|
||||||
|
|
||||||
dbrmroot = config_root.find('./SystemConfig/DBRMRoot').text
|
dbrmroot = config_root.find('./SystemConfig/DBRMRoot').text
|
||||||
loadbrm = '/usr/bin/load_brm'
|
loadbrm = '/usr/bin/load_brm'
|
||||||
@ -60,14 +73,41 @@ if __name__ == '__main__':
|
|||||||
if pmCount > 1:
|
if pmCount > 1:
|
||||||
# load multinode dbrm
|
# load multinode dbrm
|
||||||
try:
|
try:
|
||||||
brm_saves_current = subprocess.check_output(['cat', brm])
|
import requests
|
||||||
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
except ImportError as e:
|
||||||
|
print('requests Python module does not exist. \
|
||||||
|
Please install CMAPI first.', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
|
primary_address = config_root.find('./DBRM_Controller/IPAddr').text
|
||||||
|
api_key = get_key()
|
||||||
|
if len(api_key) == 0:
|
||||||
|
print('Failed to find API key in {}.'.format(api_config_file), \
|
||||||
|
file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
headers = {'x-api-key': api_key}
|
||||||
|
api_version = get_version()
|
||||||
|
api_port = get_port()
|
||||||
|
elems = ['em', 'journal', 'vbbm', 'vss']
|
||||||
|
for e in elems:
|
||||||
|
print("Pulling {} from the primary node.".format(e))
|
||||||
|
url = "https://{}:{}/cmapi/{}/node/meta/{}".format(primary_address, \
|
||||||
|
api_port, api_version, e)
|
||||||
|
r = requests.get(url, verify=False, headers=headers, timeout=2)
|
||||||
|
if (r.status_code != 200):
|
||||||
|
raise RuntimeError("Error requesting {} from the primary \
|
||||||
|
node.".format(e))
|
||||||
|
current_name = '{}_{}'.format(dbrmroot, e)
|
||||||
|
print ("Saving {} to {}".format(e, current_name))
|
||||||
|
path = Path(current_name)
|
||||||
|
path.write_bytes(r.content)
|
||||||
|
except:
|
||||||
|
print('Failed to load meta data from the primary \
|
||||||
|
node {}.'.format(primary_address), file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not brm_saves_current:
|
brm_saves_current = b"BRM_saves\n"
|
||||||
# local dbrm empty, need to pull from main node
|
|
||||||
pass
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
# will happen when brm file does not exist
|
|
||||||
print('{} does not exist.'.format(brm), file=sys.stderr)
|
|
||||||
else:
|
else:
|
||||||
# load local dbrm
|
# load local dbrm
|
||||||
try:
|
try:
|
||||||
@ -82,7 +122,7 @@ brm_saves_current.decode("utf-8").replace("BRM_saves", ""))
|
|||||||
try:
|
try:
|
||||||
retcode = subprocess.call(cmd, shell=True)
|
retcode = subprocess.call(cmd, shell=True)
|
||||||
if retcode < 0:
|
if retcode < 0:
|
||||||
pass
|
print('{} exits with {}.'.format(cmd, retcode))
|
||||||
|
sys.exit(1)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
pass
|
sys.exit(1)
|
||||||
|
Reference in New Issue
Block a user