Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/orchestrator/pkg/sandbox/upload_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ func uploadRatioBp(compressed, uncompressed int64) int64 {
}

func storeHeaderWithMetrics(ctx context.Context, store storage.StorageProvider, path, fileType, useCase string, h *headers.Header) error {
if err := headers.StoreHeader(ctx, store, path, h); err != nil {
return err
}

data, err := headers.SerializeHeader(h)
size, err := headers.StoreHeader(ctx, store, path, h)
if err != nil {
return err
}

size := int64(len(data))
recordUploadCompression(ctx, uploadArtifactHeader, fileType, useCase, storage.CompressConfig{}, size, size)

return nil
Expand Down
21 changes: 15 additions & 6 deletions packages/shared/pkg/storage/header/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package header

import (
"context"
"errors"
"fmt"

"github.com/e2b-dev/infra/packages/shared/pkg/storage"
Expand Down Expand Up @@ -56,25 +57,33 @@ func LoadHeader(ctx context.Context, s storage.StorageProvider, path string) (*H
return DeserializeBytes(data)
}

// StoreHeader serializes a header and uploads it to long-term storage.
// StoreHeader serializes a header, uploads it, and returns the stored byte count.
// Refuses to persist a header still flagged as in-flight — the upload pipeline
// must clear IncompletePendingUpload before reaching here.
func StoreHeader(ctx context.Context, s storage.StorageProvider, path string, h *Header) error {
func StoreHeader(ctx context.Context, s storage.StorageProvider, path string, h *Header) (int64, error) {
if h == nil {
return 0, errors.New("header is nil")
}

if h.IncompletePendingUpload {
Comment thread
ValentaTomas marked this conversation as resolved.
return fmt.Errorf("refusing to persist incomplete header for %s", path)
return 0, fmt.Errorf("refusing to persist incomplete header for %s", path)
}

data, err := SerializeHeader(h)
if err != nil {
return fmt.Errorf("serialize header: %w", err)
return 0, fmt.Errorf("serialize header: %w", err)
}

blob, err := s.OpenBlob(ctx, path, storage.MetadataObjectType)
if err != nil {
return fmt.Errorf("open blob %s: %w", path, err)
return 0, fmt.Errorf("open blob %s: %w", path, err)
}

if err := blob.Put(ctx, data); err != nil {
return 0, fmt.Errorf("put blob %s: %w", path, err)
}
Comment thread
ValentaTomas marked this conversation as resolved.

return blob.Put(ctx, data)
return int64(len(data)), nil
}

// Deserialize reads a header from a storage Blob (legacy API).
Expand Down
Loading