Excessive calls to set_zookeeper_active()

Bug #1838685 reported by Adam Israel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
charm-k8s-zookeeper
New
Undecided
David

Bug Description

This is the current code in reactive/zookeeper.py:

@when('zookeeper-k8s.configured')
def set_zookeeper_active():
    """Set zookeeper status active

    Conditions:
        - zookeeper-k8s.configured
    """
    layer.status.active('configured')

The problem is that the 'zookeeper-k8s.configured' flag is always set, so every hook execution re-executes the call to layer.status.active('configured').

This has unintended side-effects, such as overwriting the state when other actions are occurring, such as sending config during relation handling.

I would suggest the following changes:

Set the 'zookeeper-k8s.active' flag once here. This will ensure set_zookeeper_active() isn't executed on every hook execution when the configured flag is set.

@when('zookeeper-k8s.configured')
@when_not('zookeeper-k8s.active')
def set_zookeeper_active():
    """Set zookeeper status active

    Conditions:
        - zookeeper-k8s.configured
    """
    layer.status.active('configured')
    set_flag('zookeeper-k8s.active')

Second, instead of checking if the configured flag is set for send_config(), check the active flag. When the relation is joined, call set_zookeeper_active explicitly to reset the status.

@when('zookeeper-k8s.active', 'zookeeper.joined')
def send_config():
    [..]
        clear_flag('zookeeper.joined')
        set_zookeeper_active()

This will make sure that a) we're resetting the state after it's been put into maintenance mode earlier in send_config().

David (davigar15)
Changed in charm-k8s-zookeeper:
assignee: nobody → David (davigar15)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.