state: replace workers package with worker.Runner #7074

Merged
merged 1 commit into from Mar 16, 2017

Conversation

Projects
None yet
4 participants
Owner

rogpeppe commented Mar 8, 2017

This fixes https://bugs.launchpad.net/juju/+bug/1669540

Instead of the custom state/workers package with, we use the existing
worker.Runner implementation. This raises the issue of what to do
when a worker cannot be acquired. The obvious solution to that is
to change the worker methods to return an error, but that turns out
to be a huge change because it means that every single Watch method
needs to return an error, and hence all the callers of those.
Instead of causing massive disruption to the code base like that, we
instead observe that watchers already have a way of returning an error -
via the Wait method. So we implement a few extra functions that can
return already-dead workers in the relevant packages (state/watcher,
state/presence and worker/lease) and use those instead.

dependencies.tsv changes look wrong

dependencies.tsv
@@ -1,56 +1,31 @@
-github.com/Azure/azure-sdk-for-go git 902d95d9f311ae585ee98cfd18f418b467d60d5a 2016-07-20T05:16:58Z
@wallyworld

wallyworld Mar 8, 2017

Owner

Woah. These deletions seem wrong.

worker/workertest/check.go
@@ -49,6 +49,8 @@ func CheckAlive(c *gc.C, w worker.Worker) {
func CheckKilled(c *gc.C, w worker.Worker) error {
wait := make(chan error, 1)
go func() {
+ c.Logf("worker %T", w)
@wallyworld

wallyworld Mar 8, 2017

Owner

Can we remove these, they seem just for debugging

Contributor

dimitern commented Mar 15, 2017

Way to go @rogpeppe -1,654 lines! ;)

Thanks! Just a few little things

+// that is already dead and always returns the given error.
+func newDeadStoreManager(err error) *storeManager {
+ var m storeManager
+ m.tomb.Kill(errors.Trace(err))
@wallyworld

wallyworld Mar 15, 2017

Owner

ISTM that the callers are passing in errors.Trace(err)
So we need to just use Kill(err) here?

@rogpeppe

rogpeppe Mar 16, 2017

Owner

I think it's good to trace the error whereever it's passed on.

+// and always returns the given error from its Err method.
+func NewDeadWatcher(err error) *Watcher {
+ var w Watcher
+ w.tomb.Kill(errors.Trace(err))
@wallyworld

wallyworld Mar 15, 2017

Owner

ditto about errors.Trace(err)

@rogpeppe

rogpeppe Mar 16, 2017

Owner

ditto about tracing everywhere.

state/resources_mongo.go
@@ -213,7 +213,7 @@ func newResolvePendingResourceOps(pending storedResource, exists bool) []txn.Op
Resource: newRes.Resource.Resource,
id: newRes.ID,
applicationID: newRes.ApplicationID,
- lastPolled: time.Now().UTC(),
+ lastPolled: time.Now().AddDate(0, 0, 0).UTC(),
@wallyworld

wallyworld Mar 15, 2017

Owner

please add comment here and elsewhere to explain the AddData() usage
maybe even a todo to fix it properly

@rogpeppe

rogpeppe Mar 16, 2017

Owner

added comment.

},
{
actionName: "juju-run",
givenPayload: map[string]interface{}{"timeout": 5 * time.Second},
- errString: `validation failed: (root) : "command" property is missing and required, given {"timeout":5e+09}`,
+ // Note: in Go 1.8 the representation of large numbers in JSON changed
@wallyworld

wallyworld Mar 15, 2017

Owner

Yes! I hit this issue but hadn't fixed it yet. Thanks!

worker/lease/manager.go
+ catacomb.Invoke(catacomb.Plan{
+ Site: &m.catacomb,
+ Work: func() error {
+ return errors.New("hello")
@wallyworld

wallyworld Mar 15, 2017

Owner

this doesn't seem to match the doc comment
shouldn't it be "return err"?

@rogpeppe

rogpeppe Mar 16, 2017

Owner

Indeed, fixed.

Owner

rogpeppe commented Mar 16, 2017

$$merge$$

Contributor

jujubot commented Mar 16, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Mar 16, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10476

Owner

rogpeppe commented Mar 16, 2017

$$merge$$

Contributor

jujubot commented Mar 16, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

state: replace workers package with worker.Runner
This fixes https://bugs.launchpad.net/juju/+bug/1669540

Instead of the custom state/workers package with, we use the existing
worker.Runner implementation. This raises the issue of what to do
when a worker cannot be acquired. The obvious solution to that is
to change the worker methods to return an error, but that turns out
to be a huge change because it means that every single Watch method
needs to return an error, and hence all the callers of those.
Instead of causing massive disruption to the code base like that, we
instead observe that watchers already have a way of returning an error -
via the Wait method. So we implement a few extra functions that can
return already-dead workers in the relevant packages (state/watcher,
state/presence and worker/lease) and use those instead.
Contributor

jujubot commented Mar 16, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10479

Owner

rogpeppe commented Mar 16, 2017

$$merge$$

Contributor

jujubot commented Mar 16, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 059183e into juju:develop Mar 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment