rita
rita copied to clipboard
Gracefully handle out of sync MetaDatabase
One user manually transferred databases between MongoDB instances. They transferred their MetaDatabase, however did not transfer all the databases referenced in the MetaDatabase. This caused rita to error when run, specifically when running rita html-report
. I'm not certain if this causes issues with show-*
or import
commands as well. Below is the sample error output.
rita html-report
[-] Writing: /data01/rita/reports/2017/12/03/rita-html-report1/rita-int-09-19
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5c54da]
goroutine 1 [running]:
gopkg.in/mgo%2ev2.(*Iter).Next(0x0, 0x8ae120, 0xc42024e700, 0x8ae120)
/home/thealy/go/src/gopkg.in/mgo.v2/session.go:3684 +0x3a
gopkg.in/mgo%2ev2.(*Iter).All(0x0, 0x8a9ea0, 0xc4201e08e0, 0x0, 0x0)
/home/thealy/go/src/gopkg.in/mgo.v2/session.go:3800 +0x2b6
github.com/ocmdev/rita/reporting.printBeacons(0xc4201d0a50, 0xe, 0xc4201cc320, 0x0, 0x0)
/home/thealy/go/src/github.com/ocmdev/rita/reporting/report-beacons.go:29 +0x370
github.com/ocmdev/rita/reporting.writeDB(0xc4201d0a50, 0xe, 0xc4201a2e80, 0x31, 0xc4201cc320, 0x11, 0x4)
/home/thealy/go/src/github.com/ocmdev/rita/reporting/report.go:170 +0x291
github.com/ocmdev/rita/reporting.PrintHTML(0xc420066d80, 0x5, 0x8, 0xc4201cc320, 0x0, 0x0)
/home/thealy/go/src/github.com/ocmdev/rita/reporting/report.go:83 +0x6e2
github.com/ocmdev/rita/commands.init.4.func1(0xc4200c91e0, 0x0, 0xc4200c91e0)
/home/thealy/go/src/github.com/ocmdev/rita/commands/reporting.go:31 +0x129
github.com/urfave/cli.HandleAction(0x8d7360, 0x99fc90, 0xc4200c91e0, 0xc4200b3000, 0x0)
/home/thealy/go/src/github.com/urfave/cli/app.go:501 +0xd4
github.com/urfave/cli.Command.Run(0x9831e1, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9942aa, 0x29, 0x0, ...)
/home/thealy/go/src/github.com/urfave/cli/command.go:200 +0x93f
github.com/urfave/cli.(*App).Run(0xc4200e81c0, 0xc42000c3a0, 0x2, 0x2, 0x0, 0x0)
/home/thealy/go/src/github.com/urfave/cli/app.go:259 +0x7b7
main.main()
/home/thealy/go/src/github.com/ocmdev/rita/rita.go:26 +0x110
The suggestion is to more gracefully handle this situation. Suggestions include:
- Catch this error or detect this out of sync scenario and print a more useful error message.
- Ignore "missing" databases even if they are referenced by the Metadatabase.
- Detect an out of sync Metadatabase and offer to fix it by removing the entries.
Personally, I like option (1) the best. If we're in this situation it's definitely unexpected and likely something the user did to cause it. We should let the user know something is wrong rather than trying to silently handle things. It is up to the user to fix but a more useful error message could at least put them on the right track.
Possibly related issue: #97
@ethack do we want to do a combo of 1 and 3? Maybe print an error message that the given database/a database listed in the MetaDB doesn't exist, then ask if the user would like to remove that entry from the MetaDB? Maybe add a little note than when deleting a database the safest/best way to do it is to use rita's delete-database?
When I try recreating this issue by manually dropping a collection but leaving it in the MetaDatabase instead of the above output I get
No results were found for <collection>
and it just won't finish for any other collections that come after. I can easily change that so it'll finish other collections, but is there something else we want? Message or functionality wise?
It seems like some changes have been made and this might not be an issue anymore, thoughts?
A partial fix was introduced in #484, however the fix was not amended after PR review. I have closed #484, but the changes there will likely be helpful for anyone taking a look into this issue in the future.