Skip to content

Commit 6b4f34e

Browse files
--read-only option to add mcs node add
1 parent 28fe520 commit 6b4f34e

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

cmapi/cmapi_server/handlers/cluster.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def process_shutdown():
196196
@staticmethod
197197
def add_node(
198198
node: str, config: str = DEFAULT_MCS_CONF_PATH,
199-
logger: logging.Logger = logging.getLogger('cmapi_server')
199+
logger: logging.Logger = logging.getLogger('cmapi_server'),
200+
read_only: bool = False,
200201
) -> dict:
201202
"""Method to add node to MCS CLuster.
202203
@@ -207,6 +208,8 @@ def add_node(
207208
:type config: str, optional
208209
:param logger: logger, defaults to logging.getLogger('cmapi_server')
209210
:type logger: logging.Logger, optional
211+
:param read_only: add node in read-only mode, defaults to False
212+
:type read_only: bool, optional
210213
:raises CMAPIBasicError: on exception while starting transaction
211214
:raises CMAPIBasicError: if transaction start isn't successful
212215
:raises CMAPIBasicError: on exception while adding node
@@ -238,13 +241,18 @@ def add_node(
238241
try:
239242
add_node(
240243
node, input_config_filename=config,
241-
output_config_filename=config
244+
output_config_filename=config,
245+
read_only=read_only,
242246
)
243247
if not get_dbroots(node, config):
244-
add_dbroot(
245-
host=node, input_config_filename=config,
246-
output_config_filename=config
247-
)
248+
if not read_only: # Read-only nodes don't own dbroots
249+
add_dbroot(
250+
host=node, input_config_filename=config,
251+
output_config_filename=config
252+
)
253+
else:
254+
logger.debug("Node %s is read-only, skipping dbroot addition", node)
255+
248256
except Exception as err:
249257
rollback_transaction(transaction_id, cs_config_filename=config)
250258
raise CMAPIBasicError('Error while adding node.') from err

cmapi/cmapi_server/node_manipulation.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ def switch_node_maintenance(
5555
maintenance_element = etree.SubElement(config_root, 'Maintenance')
5656
maintenance_element.text = str(maintenance_state).lower()
5757
node_config.write_config(config_root, filename=output_config_filename)
58-
# TODO: probably move publishing to cherrypy.emgine failover channel here?
58+
# TODO: probably move publishing to cherrypy.engine failover channel here?
5959

6060

6161
def add_node(
6262
node: str, input_config_filename: str = DEFAULT_MCS_CONF_PATH,
6363
output_config_filename: Optional[str] = None,
64-
rebalance_dbroots: bool = True
64+
rebalance_dbroots: bool = True,
65+
read_only: bool = False,
6566
):
6667
"""Add node to a cluster.
6768
@@ -96,14 +97,16 @@ def add_node(
9697
if not _replace_localhost(c_root, node):
9798
pm_num = _add_node_to_PMS(c_root, node)
9899

99-
if not node_config.is_read_only():
100+
if not read_only:
100101
_add_WES(c_root, pm_num, node)
102+
else:
103+
_add_read_only_node(c_root, node)
101104

102105
_add_DBRM_Worker(c_root, node)
103106
_add_Module_entries(c_root, node)
104107
_add_active_node(c_root, node)
105108
_add_node_to_ExeMgrs(c_root, node)
106-
if rebalance_dbroots:
109+
if rebalance_dbroots and not read_only:
107110
_rebalance_dbroots(c_root)
108111
_move_primary_node(c_root)
109112
except Exception:
@@ -368,7 +371,7 @@ def _remove_node(root, node):
368371
remove node from DesiredNodes, InactiveNodes, and ActiveNodes
369372
'''
370373

371-
for n in (root.find("./DesiredNodes"), root.find("./InactiveNodes"), root.find("./ActiveNodes")):
374+
for n in (root.find("./DesiredNodes"), root.find("./InactiveNodes"), root.find("./ActiveNodes"), root.find("./ReadOnlyNodes")):
372375
__remove_helper(n, node)
373376

374377

@@ -978,6 +981,15 @@ def _add_WES(root, pm_num, node):
978981
etree.SubElement(wes_node, "Port").text = "8630"
979982

980983

984+
def _add_read_only_node(root, node) -> None:
985+
"""Add node name to ReadOnlyNodes if it's not already there"""
986+
read_only_nodes = root.find("./ReadOnlyNodes")
987+
for n in read_only_nodes.findall("./Node"):
988+
if n.text == node:
989+
return
990+
etree.SubElement(read_only_nodes, "Node").text = node
991+
992+
981993
def _add_DBRM_Worker(root, node):
982994
'''
983995
find the highest numbered DBRM_Worker entry, or one that isn't used atm

cmapi/mcs_cluster_tool/cluster_app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,17 @@ def add(
190190
'node IP, name or FQDN. '
191191
'Can be used multiple times to add several nodes at a time.'
192192
)
193+
),
194+
read_only: bool = typer.Option(
195+
False,
196+
'--read-only',
197+
help='Add node (or nodes, if more than one is passed) in read-only mode.'
193198
)
194199
):
195200
"""Add nodes to the Columnstore cluster."""
196201
result = []
197202
for node in nodes:
198-
result.append(ClusterHandler.add_node(node, logger=logger))
203+
result.append(ClusterHandler.add_node(node, logger=logger, read_only=read_only))
199204
return result
200205

201206

0 commit comments

Comments
 (0)