Skip to content

Commit 996525f

Browse files
authored
Revert #3075 fix(orchestrator): seed legacy-ancestor... (#3141)
1 parent 1ce64f8 commit 996525f

2 files changed

Lines changed: 8 additions & 69 deletions

File tree

packages/shared/pkg/storage/header/diff_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ package header
33
import (
44
"testing"
55

6-
"github.com/google/uuid"
76
"github.com/stretchr/testify/assert"
8-
"github.com/stretchr/testify/require"
9-
10-
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
117
)
128

139
func TestIsZero(t *testing.T) {
@@ -26,51 +22,3 @@ func TestIsZero(t *testing.T) {
2622
buf[RootfsBlockSize-2] = 0xFF
2723
assert.False(t, IsZero(buf), "non-zero just before the last sampled byte")
2824
}
29-
30-
// newDiffHeader must carry forward ancestors the source knows about and
31-
// backfill the uncompressed sentinel for ones it lacks, so a legacy ancestor
32-
// resolves via GetBuildFrameData (no doomed proactive header load) while the
33-
// still-unuploaded self build stays absent.
34-
func TestNewDiffHeaderBackfillsAncestors(t *testing.T) {
35-
t.Parallel()
36-
37-
const bs = 4096
38-
self := uuid.New()
39-
knownAncestor := uuid.New()
40-
legacyAncestor := uuid.New()
41-
42-
mapping := []BuildMap{
43-
{Offset: 0, Length: bs, BuildId: self, BuildStorageOffset: 0},
44-
{Offset: bs, Length: bs, BuildId: knownAncestor, BuildStorageOffset: 0},
45-
{Offset: 2 * bs, Length: bs, BuildId: legacyAncestor, BuildStorageOffset: 0},
46-
{Offset: 3 * bs, Length: bs, BuildId: uuid.Nil, BuildStorageOffset: 0},
47-
}
48-
49-
// Parent header carries only knownAncestor; legacyAncestor predates per-build
50-
// headers and is absent from the source.
51-
sourceBuilds := map[uuid.UUID]BuildData{knownAncestor: {Size: 123}}
52-
53-
meta := &Metadata{Version: MetadataVersionV4, BlockSize: bs, Size: 4 * bs, BuildId: self, BaseBuildId: legacyAncestor}
54-
h, err := newDiffHeader(meta, mapping, sourceBuilds)
55-
require.NoError(t, err)
56-
57-
// Self is excluded: its data isn't uploaded yet.
58-
_, hasSelf := h.Builds[self]
59-
require.False(t, hasSelf)
60-
61-
// Known ancestor carried forward verbatim (not clobbered by the sentinel).
62-
require.Equal(t, BuildData{Size: 123}, h.Builds[knownAncestor])
63-
64-
// Legacy ancestor gets the uncompressed sentinel, so GetBuildFrameData
65-
// returns a non-nil table and the read path never proactively refreshes it.
66-
bd, hasLegacy := h.Builds[legacyAncestor]
67-
require.True(t, hasLegacy)
68-
require.Equal(t, BuildData{}, bd)
69-
require.Equal(t, storage.UncompressedFrameTable, h.GetBuildFrameData(legacyAncestor))
70-
71-
// Empty (uuid.Nil) regions don't create entries.
72-
_, hasNil := h.Builds[uuid.Nil]
73-
require.False(t, hasNil)
74-
75-
require.True(t, h.IncompletePendingUpload)
76-
}

packages/shared/pkg/storage/header/header.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,14 @@ func newDiffHeader(metadata *Metadata, mapping []BuildMap, sourceBuilds map[uuid
109109
return nil, err
110110
}
111111

112-
// Carry every still-referenced ancestor forward, backfilling the uncompressed
113-
// sentinel (zero BuildData) for the ones the source lacks — the same gap
114-
// LoadHeader closes for stored headers. Without it a legacy (pre-header)
115-
// ancestor is absent from Builds, so the read path issues a doomed proactive
116-
// header load for it before falling back to uncompressed. Self is left out: a
117-
// pending header carries no self entry by design (its data is still local and
118-
// served from the cache), and the finalized header swapped in at upload
119-
// carries the real self entry — never a zero sentinel.
120-
h.Builds = make(map[uuid.UUID]BuildData, len(h.Mapping.Builds()))
121-
for _, id := range h.Mapping.Builds() {
122-
if id == metadata.BuildId || id == uuid.Nil {
123-
continue
124-
}
125-
if bd, ok := sourceBuilds[id]; ok {
126-
h.Builds[id] = bd
127-
} else {
128-
h.Builds[id] = BuildData{}
112+
if sourceBuilds != nil {
113+
// h.Mapping.Builds() is already deduped at NewMapping construction;
114+
// no need for an oversized temp set keyed by len(mapping).
115+
h.Builds = make(map[uuid.UUID]BuildData, len(sourceBuilds))
116+
for _, id := range h.Mapping.Builds() {
117+
if bd, ok := sourceBuilds[id]; ok {
118+
h.Builds[id] = bd
119+
}
129120
}
130121
}
131122

0 commit comments

Comments
 (0)