/
index_blob.go
56 lines (47 loc) · 1.61 KB
/
index_blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Package indexblob manages sets of active index blobs.
package indexblob
import (
"context"
"time"
"github.com/kopia/kopia/internal/gather"
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/content/index"
)
// Manager is the API of index blob manager as used by content manager.
type Manager interface {
WriteIndexBlobs(ctx context.Context, data []gather.Bytes, suffix blob.ID) ([]blob.Metadata, error)
ListActiveIndexBlobs(ctx context.Context) ([]Metadata, time.Time, error)
Compact(ctx context.Context, opts CompactOptions) error
Invalidate()
}
// CompactOptions provides options for compaction.
type CompactOptions struct {
MaxSmallBlobs int
AllIndexes bool
DropDeletedBefore time.Time
DropContents []index.ID
DisableEventualConsistencySafety bool
}
func (co *CompactOptions) maxEventualConsistencySettleTime() time.Duration {
if co.DisableEventualConsistencySafety {
return 0
}
return defaultEventualConsistencySettleTime
}
// DefaultIndexShardSize is the maximum number of items in an index shard.
// It is less than 2^24, which lets V1 index use 24-bit/3-byte indexes.
const DefaultIndexShardSize = 16e6
const verySmallContentFraction = 20 // blobs less than 1/verySmallContentFraction of maxPackSize are considered 'very small'
func addBlobsToIndex(ndx map[blob.ID]*Metadata, blobs []blob.Metadata) {
for _, it := range blobs {
if ndx[it.BlobID] == nil {
ndx[it.BlobID] = &Metadata{
Metadata: blob.Metadata{
BlobID: it.BlobID,
Length: it.Length,
Timestamp: it.Timestamp,
},
}
}
}
}