set_state not setting the state immediately

Marco Ceppi marco.ceppi at canonical.com
Wed Oct 4 12:59:13 UTC 2017


So, I've not actually checked the logs in a while, but if visibility is an
issue, it seems reasonable that the reactive framework should print in the
log that X flags are being reset due to hook failure. Things like
set_flag_immediate has farther reaching consequences than simply stating
that flags only get set on success of a hook run.

I know there are further reaching initiatives to alleviate this by
decoupling the reactive state engine from the juju hooks system. In this
case each successive loop of the reactive runtime could better snapshot
state and make failures more granular.

* state is being renamed to flag in the next major version of reactive.

On Wed, Oct 4, 2017 at 8:52 AM Mike Wilson <mike.wilson at canonical.com>
wrote:

> So as a new charm writer coming to Juju I would first do this:
>
> def get_ready():
>     func0()
>     func1_fails()
>
> Then I would, hopefully, test and notice issues. I would investigate and
> see that I needed to be idempotent. My next attempt would be to wrap those
> functions inside state checks with sets after they complete. This would
> also fail and now the charm creator is left with nothing in the api that
> can help. They are now off to their own devices to start doing random
> things to attempt to make this work the way they want it to work.
> Hopefully, the solution is as straight-forward as touching random files,
> but we just never know.
>
> I would expect the name of set_state to be something like
> set_state_on_success and I would further expect some sort of immediate
> state thing like set_state or set_state_immediate. This would give the user
> the tools we know that they need in order to create bug-free charms.
>
> Now to compound that confusion, we have the issue of a hook can call
> multiple functions inside the charm code and if any of those functions have
> something that fails the whole thing is unwrapped. I understand from a Juju
> perspective why this is the case, but as a user, I would be completely
> taken by surprise here. The only real fix here is documentation so that we
> can set expectations, but people will most likely look at examples instead
> of documentation. This means that we need to make sure to call out any
> potential issues like this in the example charms we release.
>
>
> On Wed, Oct 4, 2017 at 6:34 AM Stuart Bishop <stuart.bishop at canonical.com>
> wrote:
>
>> On 4 October 2017 at 00:51, Mike Wilson <mike.wilson at canonical.com>
>> wrote:
>> > So the best practice here is to touch a file and test for the existence
>> of
>> > that file before running must_be_called_exactly_once()?
>> >
>> > I think part of the issue here is that without knowing the extent of the
>> > hook it is hard to enforce idempotency as a charm writer. It's easy to
>> look
>> > at the code above and say that is it idempotent since the init function
>> is
>> > wrapped in a when_not and the initialized state is set at the bottom of
>> > init.
>>
>> Individual handlers should be idempotent, so it doesn't matter about
>> the extent of the hook, or even if the chained handlers being triggers
>> are running in the same hook. Assume your handlers get called multiple
>> times, because they may be. Yes, it looks idempotent but it isn't. An
>> assumption is being made that the state changes get committed
>> immediately, but these changes are actually transactional and
>> following the same transactional behaviour as the Juju hook
>> environment [1]. I think this can certainly be explained better in the
>> docs, but I can't think of a way to stop this being an easy error to
>> make.
>>
>> [1] spot the DBA
>>
>> --
>> Stuart Bishop <stuart.bishop at canonical.com>
>>
> --
> Juju mailing list
> Juju at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/juju
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20171004/ce3041cc/attachment.html>


More information about the Juju mailing list