mirror of
https://github.com/octoleo/restic.git
synced 2024-11-27 07:16:40 +00:00
index: remove supersedes field
Using the field with its current semantics is nearly impossible to get right. Remove it as it will be replaced anyways in repository format 3.
This commit is contained in:
parent
76e6719f2e
commit
9aa0c90fb2
@ -50,10 +50,9 @@ type Index struct {
|
|||||||
byType [restic.NumBlobTypes]indexMap
|
byType [restic.NumBlobTypes]indexMap
|
||||||
packs restic.IDs
|
packs restic.IDs
|
||||||
|
|
||||||
final bool // set to true for all indexes read from the backend ("finalized")
|
final bool // set to true for all indexes read from the backend ("finalized")
|
||||||
ids restic.IDs // set to the IDs of the contained finalized indexes
|
ids restic.IDs // set to the IDs of the contained finalized indexes
|
||||||
supersedes restic.IDs
|
created time.Time
|
||||||
created time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIndex returns a new index.
|
// NewIndex returns a new index.
|
||||||
@ -197,25 +196,6 @@ func (idx *Index) LookupSize(bh restic.BlobHandle) (plaintextLength uint, found
|
|||||||
return uint(crypto.PlaintextLength(int(e.length))), true
|
return uint(crypto.PlaintextLength(int(e.length))), true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supersedes returns the list of indexes this index supersedes, if any.
|
|
||||||
func (idx *Index) Supersedes() restic.IDs {
|
|
||||||
return idx.supersedes
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddToSupersedes adds the ids to the list of indexes superseded by this
|
|
||||||
// index. If the index has already been finalized, an error is returned.
|
|
||||||
func (idx *Index) AddToSupersedes(ids ...restic.ID) error {
|
|
||||||
idx.m.Lock()
|
|
||||||
defer idx.m.Unlock()
|
|
||||||
|
|
||||||
if idx.final {
|
|
||||||
return errors.New("index already finalized")
|
|
||||||
}
|
|
||||||
|
|
||||||
idx.supersedes = append(idx.supersedes, ids...)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Each passes all blobs known to the index to the callback fn. This blocks any
|
// Each passes all blobs known to the index to the callback fn. This blocks any
|
||||||
// modification of the index.
|
// modification of the index.
|
||||||
func (idx *Index) Each(ctx context.Context, fn func(restic.PackedBlob)) error {
|
func (idx *Index) Each(ctx context.Context, fn func(restic.PackedBlob)) error {
|
||||||
@ -356,8 +336,8 @@ func (idx *Index) generatePackList() ([]packJSON, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type jsonIndex struct {
|
type jsonIndex struct {
|
||||||
Supersedes restic.IDs `json:"supersedes,omitempty"`
|
// removed: Supersedes restic.IDs `json:"supersedes,omitempty"`
|
||||||
Packs []packJSON `json:"packs"`
|
Packs []packJSON `json:"packs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode writes the JSON serialization of the index to the writer w.
|
// Encode writes the JSON serialization of the index to the writer w.
|
||||||
@ -373,8 +353,7 @@ func (idx *Index) Encode(w io.Writer) error {
|
|||||||
|
|
||||||
enc := json.NewEncoder(w)
|
enc := json.NewEncoder(w)
|
||||||
idxJSON := jsonIndex{
|
idxJSON := jsonIndex{
|
||||||
Supersedes: idx.supersedes,
|
Packs: list,
|
||||||
Packs: list,
|
|
||||||
}
|
}
|
||||||
return enc.Encode(idxJSON)
|
return enc.Encode(idxJSON)
|
||||||
}
|
}
|
||||||
@ -433,8 +412,7 @@ func (idx *Index) Dump(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outer := jsonIndex{
|
outer := jsonIndex{
|
||||||
Supersedes: idx.Supersedes(),
|
Packs: list,
|
||||||
Packs: list,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := json.MarshalIndent(outer, "", " ")
|
buf, err := json.MarshalIndent(outer, "", " ")
|
||||||
@ -495,7 +473,6 @@ func (idx *Index) merge(idx2 *Index) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
idx.ids = append(idx.ids, idx2.ids...)
|
idx.ids = append(idx.ids, idx2.ids...)
|
||||||
idx.supersedes = append(idx.supersedes, idx2.supersedes...)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -545,7 +522,6 @@ func DecodeIndex(buf []byte, id restic.ID) (idx *Index, oldFormat bool, err erro
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
idx.supersedes = idxJSON.Supersedes
|
|
||||||
idx.ids = append(idx.ids, id)
|
idx.ids = append(idx.ids, id)
|
||||||
idx.final = true
|
idx.final = true
|
||||||
|
|
||||||
|
@ -309,8 +309,6 @@ func TestIndexUnserialize(t *testing.T) {
|
|||||||
{docExampleV1, 1},
|
{docExampleV1, 1},
|
||||||
{docExampleV2, 2},
|
{docExampleV2, 2},
|
||||||
} {
|
} {
|
||||||
oldIdx := restic.IDs{restic.TestParseID("ed54ae36197f4745ebc4b54d10e0f623eaaaedd03013eb7ae90df881b7781452")}
|
|
||||||
|
|
||||||
idx, oldFormat, err := index.DecodeIndex(task.idxBytes, restic.NewRandomID())
|
idx, oldFormat, err := index.DecodeIndex(task.idxBytes, restic.NewRandomID())
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
rtest.Assert(t, !oldFormat, "new index format recognized as old format")
|
rtest.Assert(t, !oldFormat, "new index format recognized as old format")
|
||||||
@ -337,8 +335,6 @@ func TestIndexUnserialize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rtest.Equals(t, oldIdx, idx.Supersedes())
|
|
||||||
|
|
||||||
blobs := listPack(t, idx, exampleLookupTest.packID)
|
blobs := listPack(t, idx, exampleLookupTest.packID)
|
||||||
if len(blobs) != len(exampleLookupTest.blobs) {
|
if len(blobs) != len(exampleLookupTest.blobs) {
|
||||||
t.Fatalf("expected %d blobs in pack, got %d", len(exampleLookupTest.blobs), len(blobs))
|
t.Fatalf("expected %d blobs in pack, got %d", len(exampleLookupTest.blobs), len(blobs))
|
||||||
@ -446,8 +442,6 @@ func TestIndexUnserializeOld(t *testing.T) {
|
|||||||
rtest.Equals(t, test.offset, blob.Offset)
|
rtest.Equals(t, test.offset, blob.Offset)
|
||||||
rtest.Equals(t, test.length, blob.Length)
|
rtest.Equals(t, test.length, blob.Length)
|
||||||
}
|
}
|
||||||
|
|
||||||
rtest.Equals(t, 0, len(idx.Supersedes()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexPacks(t *testing.T) {
|
func TestIndexPacks(t *testing.T) {
|
||||||
|
@ -332,7 +332,7 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.SaverRemoverUnpacke
|
|||||||
debug.Log("start rebuilding index of %d indexes, excludePacks: %v", len(mi.idx), excludePacks)
|
debug.Log("start rebuilding index of %d indexes, excludePacks: %v", len(mi.idx), excludePacks)
|
||||||
|
|
||||||
newIndex := NewIndex()
|
newIndex := NewIndex()
|
||||||
obsolete := restic.NewIDSet()
|
obsolete := restic.NewIDSet(extraObsolete...)
|
||||||
|
|
||||||
// track spawned goroutines using wg, create a new context which is
|
// track spawned goroutines using wg, create a new context which is
|
||||||
// cancelled as soon as an error occurs.
|
// cancelled as soon as an error occurs.
|
||||||
@ -351,11 +351,6 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.SaverRemoverUnpacke
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug.Log("adding index ids %v to supersedes field", ids)
|
debug.Log("adding index ids %v to supersedes field", ids)
|
||||||
|
|
||||||
err = newIndex.AddToSupersedes(ids...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
obsolete.Merge(restic.NewIDSet(ids...))
|
obsolete.Merge(restic.NewIDSet(ids...))
|
||||||
} else {
|
} else {
|
||||||
debug.Log("index %d isn't final, don't add to supersedes field", i)
|
debug.Log("index %d isn't final, don't add to supersedes field", i)
|
||||||
@ -380,12 +375,6 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.SaverRemoverUnpacke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := newIndex.AddToSupersedes(extraObsolete...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
obsolete.Merge(restic.NewIDSet(extraObsolete...))
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case ch <- newIndex:
|
case ch <- newIndex:
|
||||||
case <-wgCtx.Done():
|
case <-wgCtx.Done():
|
||||||
|
Loading…
Reference in New Issue
Block a user