state: Really delete status history in Unit.Destroy #7468

Merged
merged 1 commit into from Jun 8, 2017

Conversation

Projects
None yet
3 participants
Member

babbageclunk commented Jun 8, 2017

Description of change

The deletion code expected the key to be in the statusid field, but
the status history docs were changed to have the global key stored as
globalkey, so the RemoveAll calls were never deleting anything and
always doing a full scan.

Add a test that the status history is gone and correct the deletion. Also move the eraseHistory function into status. Keeping everything that needs to know about the fields of the underlying collection in one place reduces the likelihood of them getting out of sync (although obviously tests are the final check).

QA steps

  • Bootstrap a controller
  • Deploy an application with multiple units and wait for the units to be idle
  • Check the status history for one unit contains entries
  • Remove that unit
  • Check that the status history records for that unit are gone (by looking in Mongo).

Bug reference

Fixes https://bugs.launchpad.net/juju/+bug/1696491

Member

babbageclunk commented Jun 8, 2017

I'm going through the QA steps for this now. Also I need to check that it will use the existing indexes. I'm also checking that other entities don't have the same problem (so far it looks like they don't).

Some comments, but mostly LGTM

state/status.go
+ defer closer()
+ historyW := history.Writeable()
+
+ if _, err := historyW.RemoveAll(bson.D{{"globalkey", globalKey}}); err != nil {
@jameinel

jameinel Jun 8, 2017

Owner

Sometimes I really dislike the "inject model-uuid" abstraction we put in place. Certainly is hard when you're jumping between Juju code and trying to run it live.
Having a "globalKey" string constant here feels easy to get wrong.
Maybe if we put the string next to the struct definition? It would be great if we could do something like:
type historyDoc struct {
globalKey json:$THEKEY
}
...
history.RemoveAll($THEKEY)

I believe you can do
reflect.Type(historyDoc).FieldByName("globalKey").Tag().Get("bson")
but that certainly doesn't fit the "make it easy to keep them in sync" and you still have that "globalKey" constant (though its naming the attribute rather than a database field).

Anyway, this seems ok, maybe slightly better with a string const next to the struct definition.

@babbageclunk

babbageclunk Jun 8, 2017

Member

Yeah, that makes sense - essentially the same thinking that prompted me to move eraseHistory in here, but more so. The reflection code would at least have the advantage of failing noisily if the field changed, rather than the situation here where everything seemed fine except for all of the table scans. I'll add a constant for this anyway.

+ err = s.unit.Destroy()
+ c.Assert(err, jc.ErrorIsNil)
+
+ agentInfo, err = s.unit.AgentHistory().StatusHistory(filter)
@jameinel

jameinel Jun 8, 2017

Owner

Just making sure this test failed before the change.

Member

babbageclunk commented Jun 8, 2017

$$merge$$

Contributor

jujubot commented Jun 8, 2017

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

Contributor

jujubot commented Jun 8, 2017

Build failed: Generating tarball failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/11098

Fix deleting status history in Unit.Destroy
The deletion code expected the key to be in the `statusid` field, but
the status history docs were changed to have the global key stored as
`globalkey`, so the `RemoveAll` calls were never deleting anything and
always doing a full scan.

Add a test that the status history is gone and correct the
deletion. Also delete workload version status records. Move
eraseStatusHistory to status - keeping everything that needs to know
about the fields of the underlying collection in one place reduces the
likelihood of them getting out of sync.

Fixes https://bugs.launchpad.net/juju/+bug/1696491
Member

babbageclunk commented Jun 8, 2017

I noticed a cut-n-pasto in a string, aborted the build and fixed.

$$merge$$

Contributor

jujubot commented Jun 8, 2017

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

@jujubot jujubot merged commit 818d39e into juju:2.2 Jun 8, 2017

1 check failed

github-check-merge-juju Ran tests against PR. Use !!.*!! to request another build. IE, !!build!!, !!retry!!
Details

@babbageclunk babbageclunk deleted the babbageclunk:status-history-delete branch Jun 8, 2017

jujubot added a commit that referenced this pull request Jun 8, 2017

Merge pull request #7469 from babbageclunk/status-history-delete-21
Fix deleting status history in Unit.Destroy

## Description of change

The deletion code expected the key to be in the `statusid` field, but
the status history docs were changed to have the global key stored as
`globalkey`, so the `RemoveAll` calls were never deleting anything and
always doing a full scan.

Add a test that the status history is gone and correct the deletion.
Also move eraseStatusHistory to status - keeping everything that needs
to know about the fields of the underlying collection in one place
reduces the likelihood of them getting out of sync.
(Backport from #7468)

## QA steps

* Bootstrap a controller
* Deploy an application with multiple units and wait for the units to be idle
* Check the status history for one unit contains entries
* Remove that unit
* Check that the status history records for that unit are gone (by looking in Mongo).

## Bug reference

Fixes https://bugs.launchpad.net/juju/+bug/1696491

jujubot added a commit that referenced this pull request Jun 8, 2017

Merge pull request #7472 from babbageclunk/status-history-delete-develop
state: Really delete status history in Unit.Destroy

## Description of change

The deletion code expected the key to be in the `statusid` field, but
the status history docs were changed to have the global key stored as
`globalkey`, so the `RemoveAll` calls were never deleting anything and
always doing a full scan.

Add a test that the status history is gone and correct the deletion. Also 
move the eraseHistory function into status. Keeping everything that needs 
to know about the fields of the underlying collection in one place reduces 
the likelihood of them getting out of sync (although obviously tests are the 
final check).

(Forward-ported from #7468)

## QA steps
* Bootstrap a controller
* Deploy an application with multiple units and wait for the units to be idle
* Check the status history for one unit contains entries
* Remove that unit
* Check that the status history records for that unit are gone (by looking in Mongo).

## Bug reference

Fixes https://bugs.launchpad.net/juju/+bug/1696491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment