Make BlobHandle substruct of Blob

This commit is contained in:
Alexander Weiss
2020-11-05 21:52:34 +01:00
committed by Alexander Neumann
parent c844580e0f
commit 92bd448691
8 changed files with 67 additions and 43 deletions

View File

@@ -165,8 +165,8 @@ func (idx *Index) StorePack(id restic.ID, blobs []restic.Blob) {
func (idx *Index) toPackedBlob(e *indexEntry, typ restic.BlobType) restic.PackedBlob {
return restic.PackedBlob{
Blob: restic.Blob{
ID: e.id,
Type: typ,
BlobHandle: restic.BlobHandle{ID: e.id,
Type: typ},
Length: uint(e.length),
Offset: uint(e.offset),
},
@@ -596,8 +596,8 @@ func DecodeIndex(buf []byte, id restic.ID) (idx *Index, oldFormat bool, err erro
for _, blob := range pack.Blobs {
idx.store(packID, restic.Blob{
Type: blob.Type,
ID: blob.ID,
BlobHandle: restic.BlobHandle{Type: blob.Type,
ID: blob.ID},
Offset: blob.Offset,
Length: blob.Length,
})
@@ -640,8 +640,9 @@ func decodeOldIndex(buf []byte) (idx *Index, err error) {
for _, blob := range pack.Blobs {
idx.store(packID, restic.Blob{
Type: blob.Type,
ID: blob.ID,
BlobHandle: restic.BlobHandle{
Type: blob.Type,
ID: blob.ID},
Offset: blob.Offset,
Length: blob.Length,
})

View File

@@ -32,8 +32,10 @@ func TestIndexSerialize(t *testing.T) {
length := uint(i*100 + j)
idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: restic.DataBlob,
ID: id,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: id,
},
Offset: pos,
Length: length,
},
@@ -105,8 +107,10 @@ func TestIndexSerialize(t *testing.T) {
length := uint(i*100 + j)
idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: restic.DataBlob,
ID: id,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: id,
},
Offset: pos,
Length: length,
},
@@ -178,8 +182,10 @@ func TestIndexSize(t *testing.T) {
length := uint(i*100 + j)
idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: restic.DataBlob,
ID: id,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: id,
},
Offset: pos,
Length: length,
},
@@ -395,8 +401,10 @@ func TestIndexPacks(t *testing.T) {
packID := restic.NewRandomID()
idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: restic.DataBlob,
ID: restic.NewRandomID(),
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: restic.NewRandomID(),
},
Offset: 0,
Length: 23,
},
@@ -431,8 +439,10 @@ func createRandomIndex(rng *rand.Rand, packfiles int) (idx *repository.Index, lo
size := 2000 + rng.Intn(4*1024*1024)
id := NewRandomTestID(rng)
blobs = append(blobs, restic.Blob{
Type: restic.DataBlob,
ID: id,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: id,
},
Length: uint(size),
Offset: uint(offset),
})
@@ -511,8 +521,10 @@ func TestIndexHas(t *testing.T) {
length := uint(i*100 + j)
idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: restic.DataBlob,
ID: id,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: id,
},
Offset: pos,
Length: length,
},

View File

@@ -21,8 +21,10 @@ func TestMasterIndex(t *testing.T) {
blob1 := restic.PackedBlob{
PackID: restic.NewRandomID(),
Blob: restic.Blob{
Type: restic.DataBlob,
ID: idInIdx1,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: idInIdx1,
},
Length: uint(restic.CiphertextLength(10)),
Offset: 0,
},
@@ -31,8 +33,10 @@ func TestMasterIndex(t *testing.T) {
blob2 := restic.PackedBlob{
PackID: restic.NewRandomID(),
Blob: restic.Blob{
Type: restic.DataBlob,
ID: idInIdx2,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: idInIdx2,
},
Length: uint(restic.CiphertextLength(100)),
Offset: 10,
},
@@ -41,8 +45,10 @@ func TestMasterIndex(t *testing.T) {
blob12a := restic.PackedBlob{
PackID: restic.NewRandomID(),
Blob: restic.Blob{
Type: restic.TreeBlob,
ID: idInIdx12,
BlobHandle: restic.BlobHandle{
Type: restic.TreeBlob,
ID: idInIdx12,
},
Length: uint(restic.CiphertextLength(123)),
Offset: 110,
},
@@ -51,8 +57,10 @@ func TestMasterIndex(t *testing.T) {
blob12b := restic.PackedBlob{
PackID: restic.NewRandomID(),
Blob: restic.Blob{
Type: restic.TreeBlob,
ID: idInIdx12,
BlobHandle: restic.BlobHandle{
Type: restic.TreeBlob,
ID: idInIdx12,
},
Length: uint(restic.CiphertextLength(123)),
Offset: 50,
},
@@ -139,8 +147,10 @@ func TestMasterMergeFinalIndexes(t *testing.T) {
blob1 := restic.PackedBlob{
PackID: restic.NewRandomID(),
Blob: restic.Blob{
Type: restic.DataBlob,
ID: idInIdx1,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: idInIdx1,
},
Length: 10,
Offset: 0,
},
@@ -149,8 +159,10 @@ func TestMasterMergeFinalIndexes(t *testing.T) {
blob2 := restic.PackedBlob{
PackID: restic.NewRandomID(),
Blob: restic.Blob{
Type: restic.DataBlob,
ID: idInIdx2,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: idInIdx2,
},
Length: 100,
Offset: 10,
},

View File

@@ -296,9 +296,11 @@ func BenchmarkLoadIndex(b *testing.B) {
for i := 0; i < 5000; i++ {
idx.Store(restic.PackedBlob{
Blob: restic.Blob{
Type: restic.DataBlob,
BlobHandle: restic.BlobHandle{
Type: restic.DataBlob,
ID: restic.NewRandomID(),
},
Length: 1234,
ID: restic.NewRandomID(),
Offset: 1235,
},
PackID: restic.NewRandomID(),