Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Ensure logTailer returns records in time order #6612
Merged
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6e28e3
Ensure logTailer returns records in time order
babbageclunk e3bacfe
Add upgrade step to drop the old e,t logs index
babbageclunk 2a0cfd0
Update test to match new indexes
babbageclunk 59dea03
Added 2.1.0 to the upgrade test
babbageclunk 15de4d9
Don't check the error code, apparently it changes
babbageclunk f60acab
Belt-and suspenders check in the test
babbageclunk
Jump to file or symbol
Failed to load files and symbols.
| @@ -9,6 +9,7 @@ import ( | ||
| "github.com/juju/errors" | ||
| "github.com/juju/loggo" | ||
| "gopkg.in/juju/names.v2" | ||
| + "gopkg.in/mgo.v2" | ||
| "gopkg.in/mgo.v2/bson" | ||
| "gopkg.in/mgo.v2/txn" | ||
| ) | ||
| @@ -220,3 +221,20 @@ func stripLocalFromFields(st *State, collName string, fields ...string) ([]txn.O | ||
| } | ||
| return ops, nil | ||
| } | ||
| + | ||
| +func DropOldLogIndex(st *State) error { | ||
| + // If the log collection still has the old e,t index, remove it. | ||
| + key := []string{"e", "t"} | ||
| + db := st.MongoSession().DB(logsDB) | ||
| + collection := db.C(logsC) | ||
| + err := collection.DropIndex(key...) | ||
| + if err == nil { | ||
| + return nil | ||
| + } | ||
| + if queryErr, ok := err.(*mgo.QueryError); ok { | ||
babbageclunk
Member
|
||
| + if strings.HasPrefix(queryErr.Message, "index not found") { | ||
| + return nil | ||
| + } | ||
| + } | ||
| + return errors.Trace(err) | ||
| +} | ||
| @@ -0,0 +1,21 @@ | ||
| +// Copyright 2016 Canonical Ltd. | ||
| +// Licensed under the AGPLv3, see LICENCE file for details. | ||
| + | ||
| +package upgrades | ||
| + | ||
| +import ( | ||
| + "github.com/juju/juju/state" | ||
| +) | ||
| + | ||
| +// stateStepsFor21 returns upgrade steps for Juju 2.1 that manipulate state directly. | ||
| +func stateStepsFor21() []Step { | ||
| + return []Step{ | ||
| + &upgradeStep{ | ||
| + description: "drop old log index", | ||
| + targets: []Target{DatabaseMaster}, | ||
| + run: func(context Context) error { | ||
| + return state.DropOldLogIndex(context.State()) | ||
| + }, | ||
| + }, | ||
| + } | ||
| +} |
I was thinking you could check the output of Indexes() and then decide whether to drop, but this is fine too.