mirror of
https://github.com/kopia/kopia.git
synced 2026-02-23 10:04:41 -05:00
* epoch: misc fixes and logging * blob: misc helpers * cli: removed useless 'repository upgrade', replaced by 'repository set-parameters' * content: implemented indexBlobManagerV1 which uses epoch manager * cli: commands to manipulate repository epoch parameters * cli: commands to examine epoch-based indexes * content: added test suite that uses epoch-based index manager * content: fixed a ton of test data races caused by sharing blobtesting.DataMap * cli: additional tests and validation for 'repository set-params' * testing: replaced the use of suite with our own, since suite is not parallelizable
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package epoch
|
|
|
|
import (
|
|
"github.com/kopia/kopia/repo/blob"
|
|
)
|
|
|
|
// RangeMetadata represents a range of indexes for [min,max] epoch range. Both min and max are inclusive.
|
|
type RangeMetadata struct {
|
|
MinEpoch int `json:"min"`
|
|
MaxEpoch int `json:"max"`
|
|
Blobs []blob.Metadata `json:"blobs"`
|
|
}
|
|
|
|
func findLongestRangeCheckpoint(ranges []*RangeMetadata) []*RangeMetadata {
|
|
byMin := map[int][]*RangeMetadata{}
|
|
|
|
for _, r := range ranges {
|
|
byMin[r.MinEpoch] = append(byMin[r.MinEpoch], r)
|
|
}
|
|
|
|
return findLongestRangeCheckpointStartingAt(0, byMin, make(map[int][]*RangeMetadata))
|
|
}
|
|
|
|
func findLongestRangeCheckpointStartingAt(startEpoch int, byMin, memo map[int][]*RangeMetadata) []*RangeMetadata {
|
|
l, ok := memo[startEpoch]
|
|
if ok {
|
|
return l
|
|
}
|
|
|
|
var (
|
|
longest = 0
|
|
longestMetadata []*RangeMetadata
|
|
)
|
|
|
|
for _, cp := range byMin[startEpoch] {
|
|
combined := append([]*RangeMetadata{cp}, findLongestRangeCheckpointStartingAt(cp.MaxEpoch+1, byMin, memo)...)
|
|
|
|
if max := combined[len(combined)-1].MaxEpoch; (max > longest) || (max == longest && len(combined) < len(longestMetadata)) {
|
|
longest = max
|
|
longestMetadata = combined
|
|
}
|
|
}
|
|
|
|
memo[startEpoch] = longestMetadata
|
|
|
|
return longestMetadata
|
|
}
|