Skip to content

Commit

Permalink
Add strict order warning to mcap doctor (#1066)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
defunctzombie authored Apr 3, 2024
1 parent 0d2cf7c commit f3889a6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion go/cli/mcap/cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

var (
verbose bool
verbose bool
strictMessageOrder bool
)

type mcapDoctor struct {
Expand Down Expand Up @@ -182,13 +183,28 @@ 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
}

if message.LogTime > maxLogTime {
maxLogTime = message.LogTime
}

if message.LogTime > doctor.maxLogTime {
doctor.maxLogTime = message.LogTime
}

chunkMessageCount++
doctor.messageCount++

Expand Down Expand Up @@ -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")
}

0 comments on commit f3889a6

Please sign in to comment.