github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/persist/fs/segments.go (about) 1 // Copyright (c) 2020 Uber Technologies, Inc 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE 20 21 package fs 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/dbnode/generated/proto/index" 27 "github.com/m3db/m3/src/dbnode/storage/bootstrap/result" 28 idxpersist "github.com/m3db/m3/src/m3ninx/persist" 29 xtime "github.com/m3db/m3/src/x/time" 30 ) 31 32 type segments struct { 33 absoluteFilepaths []string 34 shardRanges result.ShardTimeRanges 35 volumeType idxpersist.IndexVolumeType 36 volumeIndex int 37 blockStart xtime.UnixNano 38 } 39 40 // NewSegments returns an on disk segments for an index info file. 41 func NewSegments( 42 info index.IndexVolumeInfo, 43 volumeIndex int, 44 absoluteFilepaths []string, 45 ) Segments { 46 sr := result.NewShardTimeRanges() 47 indexBlockStart := xtime.UnixNano(info.BlockStart) 48 indexBlockRange := xtime.Range{ 49 Start: indexBlockStart, 50 End: indexBlockStart.Add(time.Duration(info.BlockSize)), 51 } 52 for _, shard := range info.Shards { 53 ranges, ok := sr.Get(shard) 54 if !ok { 55 ranges = xtime.NewRanges() 56 sr.Set(shard, ranges) 57 } 58 ranges.AddRange(indexBlockRange) 59 } 60 volumeType := idxpersist.DefaultIndexVolumeType 61 if info.IndexVolumeType != nil { 62 volumeType = idxpersist.IndexVolumeType(info.IndexVolumeType.Value) 63 } 64 return &segments{ 65 shardRanges: sr, 66 volumeType: volumeType, 67 volumeIndex: volumeIndex, 68 absoluteFilepaths: absoluteFilepaths, 69 blockStart: indexBlockStart, 70 } 71 } 72 73 func (o *segments) ShardTimeRanges() result.ShardTimeRanges { 74 return o.shardRanges 75 } 76 77 func (o *segments) VolumeType() idxpersist.IndexVolumeType { 78 return o.volumeType 79 } 80 81 func (o *segments) AbsoluteFilePaths() []string { 82 return o.absoluteFilepaths 83 } 84 85 func (o *segments) VolumeIndex() int { 86 return o.volumeIndex 87 } 88 89 func (o *segments) BlockStart() xtime.UnixNano { 90 return o.blockStart 91 }