Repository: influxdata/influxdb
File: coordinator/points_writer.go (Go)

Code before:
}

func (s *ShardMapping) AddDropped(p models.Point, t time.Time, b BoundType) {
	if s.MaxDropped.Point == nil || p.Time().After(s.MaxDropped.Point.Time()) {
		s.MaxDropped = DroppedPoint{Point: p, ViolatedBound: t, Reason: b}
	}
	if s.MinDropped.Point == nil || p.Time().Before(s.MinDropped.Point.Time()) {
		s.MinDropped = DroppedPoint{Point: p, ViolatedBound: t, Reason: b}
	}
	switch b {
	case RetentionPolicyBound:
		s.RetentionDropped++
	case WriteWindowLowerBound, WriteWindowUpperBound:
		s.WriteWindowDropped++
	}
}

func (s *ShardMapping) Dropped() int {
	return s.RetentionDropped + s.WriteWindowDropped
}

func (s *ShardMapping) SummariseDropped() string {
	if s.Dropped() <= 0 {
		return ""
	}
	return fmt.Sprintf("dropped %d points outside retention policy and %d points outside write window: %s to %s",
		s.RetentionDropped,
		s.WriteWindowDropped,
		s.MinDropped.String(),
		s.MaxDropped.String())
}

// MapPoint adds the point to the ShardMapping, associated with the given shardInfo.
func (s *ShardMapping) MapPoint(shardInfo *meta.ShardInfo, p models.Point) {
	if cap(s.Points[shardInfo.ID]) < s.n {
		s.Points[shardInfo.ID] = make([]models.Point, 0, s.n)
	}
	s.Points[shardInfo.ID] = append(s.Points[shardInfo.ID], p)
	s.Shards[shardInfo.ID] = shardInfo
}

type WriteWindow struct {
	before      time.Time
	checkBefore bool
	after       time.Time
	checkAfter  bool
}

func NewWriteWindow(rp *meta.RetentionPolicyInfo) *WriteWindow {
	w := &WriteWindow{checkAfter: false, checkBefore: false}


Review comment (bug):
Do we want to include the retention policy and/or write window bounds in the summary? Might make debugging customer issues easier, especially if their retention or write window is now what they think it is.

Code after:
		Shards: map[uint64]*meta.ShardInfo{},
		rpi:    rpi,
	}
}

func (s *ShardMapping) AddDropped(p models.Point, t time.Time, b BoundType) {
	if s.MaxDropped.Point == nil || p.Time().After(s.MaxDropped.Point.Time()) {
		s.MaxDropped = DroppedPoint{Point: p, ViolatedBound: t, Reason: b}
	}
	if s.MinDropped.Point == nil || p.Time().Before(s.MinDropped.Point.Time()) {
		s.MinDropped = DroppedPoint{Point: p, ViolatedBound: t, Reason: b}
	}
	switch b {
	case RetentionPolicyBound:
		s.RetentionDropped++
	case WriteWindowLowerBound, WriteWindowUpperBound:
		s.WriteWindowDropped++
	}
}

func (s *ShardMapping) Dropped() int {
	return s.RetentionDropped + s.WriteWindowDropped
}

func (s *ShardMapping) SummariseDropped() string {
	if s.Dropped() <= 0 {
		return ""
	}
	summary := strings.Builder{}
	if s.rpi.PastWriteLimit > 0 || s.rpi.FutureWriteLimit > 0 {
		summary.WriteString(fmt.Sprintf(" and %d points outside write window (", s.WriteWindowDropped))
		if s.rpi.PastWriteLimit > 0 {
			summary.WriteString("-")
			summary.WriteString(s.rpi.PastWriteLimit.String())
		}
		if s.rpi.FutureWriteLimit > 0 {
			if s.rpi.PastWriteLimit > 0 {
				summary.WriteString(" to ")
			}
			summary.WriteString(s.rpi.FutureWriteLimit.String())
		}
		summary.WriteString(")")
	}
	return fmt.Sprintf("dropped %d points outside retention policy of duration %s%s - oldest %s, newest %s",
		s.RetentionDropped,
		s.rpi.Duration.String(),
		summary.String(),
		s.MinDropped.String(),
		s.MaxDropped.String())
}