From f3889a6f25fc73c1eef31f214b9f363821b1ce8b Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Tue, 2 Apr 2024 17:50:07 -0700 Subject: [PATCH] Add strict order warning to `mcap doctor` (#1066) doctor will surface a warning when the log time of a message is earlier than the latest known log time of messages while reading the message data in file order. A new `--strict-message-order` flag can make this warning an error. --- go/cli/mcap/cmd/doctor.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/go/cli/mcap/cmd/doctor.go b/go/cli/mcap/cmd/doctor.go index 118f519771..c9681b389a 100644 --- a/go/cli/mcap/cmd/doctor.go +++ b/go/cli/mcap/cmd/doctor.go @@ -19,7 +19,8 @@ import ( ) var ( - verbose bool + verbose bool + strictMessageOrder bool ) type mcapDoctor struct { @@ -182,6 +183,16 @@ func (doctor *mcapDoctor) examineChunk(chunk *mcap.Chunk) { doctor.error("Got a Message record for channel: %d before a channel info.", message.ChannelID) } + if message.LogTime < doctor.maxLogTime { + errStr := fmt.Sprintf("Message.log_time %d on %s is less than the latest log time %d", + message.LogTime, channel.Topic, doctor.maxLogTime) + if strictMessageOrder { + doctor.error(errStr) + } else { + doctor.warn(errStr) + } + } + if message.LogTime < minLogTime { minLogTime = message.LogTime } @@ -189,6 +200,11 @@ func (doctor *mcapDoctor) examineChunk(chunk *mcap.Chunk) { if message.LogTime > maxLogTime { maxLogTime = message.LogTime } + + if message.LogTime > doctor.maxLogTime { + doctor.maxLogTime = message.LogTime + } + chunkMessageCount++ doctor.messageCount++ @@ -556,4 +572,6 @@ func init() { rootCmd.AddCommand(doctorCommand) rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output") + rootCmd.PersistentFlags().BoolVarP(&strictMessageOrder, "strict-message-order", "", + false, "Require that messages have a monotonic log time") }