Debian Codegraph @

cmd/influx-tools/export/bucket.go

raw symbols SCIP
1 package export
2
3 import (
4 "time"
5
6 "github.com/influxdata/influxdb/services/meta"
7 )
8
9 func makeShardGroupsForDuration(min, max time.Time, d time.Duration) meta.ShardGroupInfos {
10 start := min.Truncate(d).UTC()
11 end := max.Truncate(d).Add(d).UTC()
12
13 groups := make(meta.ShardGroupInfos, end.Sub(start)/d)
14 var i uint64
15 for start.Before(end) {
16 groups[i] = meta.ShardGroupInfo{
17 ID: i,
18 StartTime: start,
19 EndTime: start.Add(d),
20 }
21 i++
22 start = start.Add(d)
23 }
24 return groups[:i]
25 }
26
27 // PlanShardGroups creates a new ShardGroup set using a shard group duration of d, for the time spanning min to max.
28 func planShardGroups(sourceShards []meta.ShardGroupInfo, min, max time.Time, d time.Duration) meta.ShardGroupInfos {
29 groups := makeShardGroupsForDuration(min, max, d)
30 var target []meta.ShardGroupInfo
31 for i := 0; i < len(groups); i++ {
32 g := groups[i]
33 // NOTE: EndTime.Add(-1) matches the Contains interval of [start, end)
34 if hasShardsGroupForTimeRange(sourceShards, g.StartTime, g.EndTime.Add(-1)) {
35 target = append(target, g)
36 }
37 }
38 return target
39 }
40
41 func hasShardsGroupForTimeRange(groups []meta.ShardGroupInfo, min, max time.Time) bool {
42 for _, g := range groups {
43 if g.Overlaps(min, max) {
44 return true
45 }
46 }
47 return false
48 }