···324324 return
325325}
326326327327+type FlushReason uint8
328328+329329+const (
330330+ FlushReasonTimerExpired FlushReason = 1 << iota
331331+ FlushReasonFinalFlush
332332+ FlushReasonMaxSize
333333+)
334334+335335+var FlushReasonStrings = map[FlushReason]string{
336336+ FlushReasonTimerExpired: "timer_expired",
337337+ FlushReasonFinalFlush: "final_flush",
338338+ FlushReasonMaxSize: "max_size_reached",
339339+}
340340+341341+func (fr FlushReason) String() string {
342342+ if v, ok := FlushReasonStrings[fr]; ok {
343343+ return v
344344+ }
345345+346346+ return "none"
347347+}
348348+327349// Stats contains interesting numbers on the search
328350type Stats struct {
329351 // Amount of I/O for reading contents.
···376398377399 // Number of times regexp was called on files that we evaluated.
378400 RegexpsConsidered int
401401+402402+ // FlushReason explains why results were flushed.
403403+ FlushReason FlushReason
379404}
380405381381-func (s *Stats) sizeBytes() uint64 {
382382- // This assumes we are running on a 64-bit architecture.
383383- return 16 * 8
406406+func (s *Stats) sizeBytes() (sz uint64) {
407407+ sz = 16 * 8 // This assumes we are running on a 64-bit architecture
408408+ sz += 1 // FlushReason
409409+410410+ return
384411}
385412386413func (s *Stats) Add(o Stats) {
···399426 s.ShardsSkippedFilter += o.ShardsSkippedFilter
400427 s.Wait += o.Wait
401428 s.RegexpsConsidered += o.RegexpsConsidered
429429+430430+ // We want the first non-zero FlushReason to be sticky. This is a useful
431431+ // property when aggregating stats from several Zoekts.
432432+ if s.FlushReason == 0 {
433433+ s.FlushReason = o.FlushReason
434434+ }
402435}
403436404437// Zero returns true if stats is empty.