Skip to content

Commit 3b0ac22

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
commands: invalidate cached config when node is not ctdb leader
When the `samba-container config-update --watch` command is run on a CTDB enabled server we avoid updating the local config unless the node is the ctdb leader. However, the update function was returning the current config which the watch loop assigned to the previous var, meaning that the current and previous config would be equal on future trips around the loop. Therefore once the node became the leader it would not update the config even if it differed from the config in samba. This is a problem on start up because the loop initially runs before ctdb is ready and the node leadership is not known. Change it so that when the node is not a leader it returns None and "unsets" the previous config. This could lead to extra unneeded updates but should avoid missing updates that are needed. Signed-off-by: John Mulligan <jmulligan@redhat.com>
1 parent 76646e9 commit 3b0ac22

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sambacc/commands/config.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ def _read_config(ctx: Context) -> config.InstanceConfig:
7979
).get(ctx.cli.identity)
8080

8181

82+
UpdateResult = typing.Tuple[typing.Optional[config.InstanceConfig], bool]
83+
84+
8285
def _update_config(
8386
current: config.InstanceConfig,
8487
previous: typing.Optional[config.InstanceConfig],
8588
ensure_paths: bool = True,
8689
notify_server: bool = True,
87-
) -> typing.Tuple[config.InstanceConfig, bool]:
90+
) -> UpdateResult:
8891
"""Compare the current and previous instance configurations. If they
8992
differ, ensure any new paths, update the samba config, and inform any
9093
running smbds of the new configuration. Return the current config and a
@@ -117,20 +120,20 @@ def _update_config(
117120

118121
def _exec_if_leader(
119122
ctx: Context,
120-
cond_func: typing.Callable[..., typing.Tuple[config.InstanceConfig, bool]],
121-
) -> typing.Callable[..., typing.Tuple[config.InstanceConfig, bool]]:
123+
cond_func: typing.Callable[..., UpdateResult],
124+
) -> typing.Callable[..., UpdateResult]:
122125
"""Run the cond func only on "nodes" that are the cluster leader."""
123126

124127
# CTDB status and leader detection is not changeable at runtime.
125128
# we do not need to account for it changing in the updated config file(s)
126129
@functools.wraps(cond_func)
127130
def _call_if_leader(
128131
current: config.InstanceConfig, previous: config.InstanceConfig
129-
) -> typing.Tuple[config.InstanceConfig, bool]:
132+
) -> UpdateResult:
130133
with best_leader_locator(ctx.instance_config) as ll:
131134
if not ll.is_leader():
132135
_logger.info("skipping config update. node not leader")
133-
return previous, False
136+
return None, False
134137
_logger.info("checking for update. node is leader")
135138
result = cond_func(current, previous)
136139
return result

0 commit comments

Comments
 (0)