repository: hide MasterIndex.FinalizeFullIndexes / FinalizeNotFinalIndexes

This commit is contained in:
Michael Eischer 2022-05-26 15:43:04 +02:00
parent ef53ca4a5a
commit 1974ad7ce2
3 changed files with 8 additions and 13 deletions

View file

@ -188,9 +188,9 @@ func (mi *MasterIndex) StorePack(id restic.ID, blobs []restic.Blob) {
mi.idx = append(mi.idx, newIdx) mi.idx = append(mi.idx, newIdx)
} }
// FinalizeNotFinalIndexes finalizes all indexes that // finalizeNotFinalIndexes finalizes all indexes that
// have not yet been saved and returns that list // have not yet been saved and returns that list
func (mi *MasterIndex) FinalizeNotFinalIndexes() []*Index { func (mi *MasterIndex) finalizeNotFinalIndexes() []*Index {
mi.idxMutex.Lock() mi.idxMutex.Lock()
defer mi.idxMutex.Unlock() defer mi.idxMutex.Unlock()
@ -207,8 +207,8 @@ func (mi *MasterIndex) FinalizeNotFinalIndexes() []*Index {
return list return list
} }
// FinalizeFullIndexes finalizes all indexes that are full and returns that list. // finalizeFullIndexes finalizes all indexes that are full and returns that list.
func (mi *MasterIndex) FinalizeFullIndexes() []*Index { func (mi *MasterIndex) finalizeFullIndexes() []*Index {
mi.idxMutex.Lock() mi.idxMutex.Lock()
defer mi.idxMutex.Unlock() defer mi.idxMutex.Unlock()
@ -217,7 +217,6 @@ func (mi *MasterIndex) FinalizeFullIndexes() []*Index {
debug.Log("checking %d indexes", len(mi.idx)) debug.Log("checking %d indexes", len(mi.idx))
for _, idx := range mi.idx { for _, idx := range mi.idx {
if idx.Final() { if idx.Final() {
debug.Log("index %p is final", idx)
continue continue
} }
@ -425,12 +424,12 @@ func (mi *MasterIndex) saveIndex(ctx context.Context, r restic.SaverUnpacked, in
// SaveIndex saves all new indexes in the backend. // SaveIndex saves all new indexes in the backend.
func (mi *MasterIndex) SaveIndex(ctx context.Context, r restic.SaverUnpacked) error { func (mi *MasterIndex) SaveIndex(ctx context.Context, r restic.SaverUnpacked) error {
return mi.saveIndex(ctx, r, mi.FinalizeNotFinalIndexes()...) return mi.saveIndex(ctx, r, mi.finalizeNotFinalIndexes()...)
} }
// SaveFullIndex saves all full indexes in the backend. // SaveFullIndex saves all full indexes in the backend.
func (mi *MasterIndex) SaveFullIndex(ctx context.Context, r restic.SaverUnpacked) error { func (mi *MasterIndex) SaveFullIndex(ctx context.Context, r restic.SaverUnpacked) error {
return mi.saveIndex(ctx, r, mi.FinalizeFullIndexes()...) return mi.saveIndex(ctx, r, mi.finalizeFullIndexes()...)
} }
// ListPacks returns the blobs of the specified pack files grouped by pack file. // ListPacks returns the blobs of the specified pack files grouped by pack file.

View file

@ -209,11 +209,7 @@ func createRandomMasterIndex(t testing.TB, rng *rand.Rand, num, size int) (*repo
idx1, lookupBh := createRandomIndex(rng, size) idx1, lookupBh := createRandomIndex(rng, size)
mIdx.Insert(idx1) mIdx.Insert(idx1)
mIdx.FinalizeNotFinalIndexes() repository.TestMergeIndex(t, mIdx)
err := mIdx.MergeFinalIndexes()
if err != nil {
t.Fatal(err)
}
return mIdx, lookupBh return mIdx, lookupBh
} }

View file

@ -134,7 +134,7 @@ func BenchmarkAllVersions(b *testing.B, bench VersionedBenchmark) {
} }
func TestMergeIndex(t testing.TB, mi *MasterIndex) ([]*Index, int) { func TestMergeIndex(t testing.TB, mi *MasterIndex) ([]*Index, int) {
finalIndexes := mi.FinalizeNotFinalIndexes() finalIndexes := mi.finalizeNotFinalIndexes()
for _, idx := range finalIndexes { for _, idx := range finalIndexes {
test.OK(t, idx.SetID(restic.NewRandomID())) test.OK(t, idx.SetID(restic.NewRandomID()))
} }