Skip to content

Commit c0154c0

Browse files
commands: add ctdb-monitor-nodes command
Add a `ctdb-monitor-nodes` command - this command will monitor the cluster meta and update the containers/ctdb when/if it changes. The `--write-nodes` parameter is used to instruct the command to write the ctdb nodes file on changes. The `--reload` option is used to control what "nodes" issue `ctdb reloadnodes` commands: leader (only the cluster leader), all (all nodes that see the cluster meta change), and never (never issue reloadnodes commands). Signed-off-by: John Mulligan <[email protected]>
1 parent 6f19de6 commit c0154c0

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

sambacc/commands/ctdb.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from sambacc import samba_cmds
3030
from sambacc.simple_waiter import Sleeper, Waiter
3131

32-
from .cli import best_waiter, commands, Context, Fail
32+
from .cli import best_leader_locator, best_waiter, commands, Context, Fail
3333

3434
_logger = logging.getLogger(__name__)
3535

@@ -323,6 +323,48 @@ def ctdb_manage_nodes(ctx: Context) -> None:
323323
)
324324

325325

326+
def _ctdb_monitor_nodes_args(parser: argparse.ArgumentParser) -> None:
327+
_ctdb_must_have_node_args(parser)
328+
parser.add_argument(
329+
"--reload",
330+
choices=("leader", "never", "all"),
331+
default="leader",
332+
help="Specify which nodes can command CTDB to reload nodes",
333+
)
334+
335+
336+
@commands.command(name="ctdb-monitor-nodes", arg_func=_ctdb_monitor_nodes_args)
337+
def ctdb_monitor_nodes(ctx: Context) -> None:
338+
"""Run a long lived process to monitor the cluster metadata.
339+
Unlike ctdb_manage_nodes this function assumes that the node state
340+
file is externally managed and primarily exists to reflect any changes
341+
to the cluster meta into CTDB.
342+
"""
343+
_ctdb_ok()
344+
np = NodeParams(ctx)
345+
waiter = np.cluster_meta_waiter()
346+
leader_locator = None
347+
if ctx.cli.reload == "leader":
348+
leader_locator = best_leader_locator(ctx.instance_config)
349+
reload_all = ctx.cli.reload == "all"
350+
nodes_file_path = np.persistent_path if ctx.cli.write_nodes else None
351+
352+
_logger.info("monitoring cluster meta changes")
353+
_logger.debug(
354+
"reload_all=%s leader_locator=%r", reload_all, leader_locator
355+
)
356+
limiter = ErrorLimiter("ctdb_monitor_nodes", 10, pause_func=waiter.wait)
357+
while True:
358+
with limiter.catch():
359+
ctdb.monitor_cluster_meta_changes(
360+
cmeta=np.cluster_meta(),
361+
pause_func=waiter.wait,
362+
nodes_file_path=nodes_file_path,
363+
leader_locator=leader_locator,
364+
reload_all=reload_all,
365+
)
366+
367+
326368
def _ctdb_must_have_node_args(parser: argparse.ArgumentParser) -> None:
327369
_ctdb_general_node_args(parser)
328370
parser.add_argument(

0 commit comments

Comments
 (0)