Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SS] Log compressed bytes written to the remote cache #8404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions enterprise/server/remote_execution/snaploader/snaploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,10 @@ func (l *FileCacheLoader) CacheSnapshot(ctx context.Context, key *fcpb.SnapshotK
}
}
out.Digest = d
return snaputil.Cache(ctx, l.env.GetFileCache(), l.env.GetByteStreamClient(), opts.Remote, d, key.InstanceName, filePath, fileType)
if _, err := snaputil.Cache(ctx, l.env.GetFileCache(), l.env.GetByteStreamClient(), opts.Remote, d, key.InstanceName, filePath, fileType); err != nil {
return err
}
return nil
})
}
for name, cow := range opts.ChunkedFiles {
Expand Down Expand Up @@ -839,10 +842,10 @@ func (l *FileCacheLoader) unpackCOW(ctx context.Context, file *fcpb.ChunkedFile,
func (l *FileCacheLoader) cacheCOW(ctx context.Context, name string, remoteInstanceName string, cow *copy_on_write.COWStore, cacheOpts *CacheSnapshotOptions) (*repb.Digest, error) {
ctx, span := tracing.StartSpan(ctx)
defer span.End()
var dirtyBytes, dirtyChunkCount, emptyBytes, emptyChunkCount int64
var dirtyBytes, dirtyChunkCount, emptyBytes, emptyChunkCount, compressedBytesWritten int64
start := time.Now()
defer func() {
log.CtxDebugf(ctx, "Cached %q in %s - %d MB (%d chunks) dirty, %d MB (%d chunks) empty", name, time.Since(start), dirtyBytes/(1024*1024), dirtyChunkCount, emptyBytes/(1024*1024), emptyChunkCount)
log.CtxDebugf(ctx, "Cached %q in %s - %d MB (%d chunks) dirty, %d MB (%d chunks) empty, %d MB compressed data written to the cache", name, time.Since(start), dirtyBytes/(1024*1024), dirtyChunkCount, emptyBytes/(1024*1024), emptyChunkCount, compressedBytesWritten/(1024*1024))
}()

size, err := cow.SizeBytes()
Expand Down Expand Up @@ -935,9 +938,11 @@ func (l *FileCacheLoader) cacheCOW(ctx context.Context, name string, remoteInsta
shouldCache := dirty || (chunkSrc == snaputil.ChunkSourceLocalFile)
if shouldCache {
path := filepath.Join(cow.DataDir(), copy_on_write.ChunkName(c.Offset, cow.Dirty(c.Offset)))
if err := snaputil.Cache(ctx, l.env.GetFileCache(), l.env.GetByteStreamClient(), cacheOpts.Remote, d, remoteInstanceName, path, name); err != nil {
bytesWritten, err := snaputil.Cache(ctx, l.env.GetFileCache(), l.env.GetByteStreamClient(), cacheOpts.Remote, d, remoteInstanceName, path, name)
if err != nil {
return status.WrapError(err, "write chunk to cache")
}
atomic.AddInt64(&compressedBytesWritten, bytesWritten)
} else if *snaputil.VerboseLogging {
log.CtxDebugf(ctx, "Not caching snapshot artifact: dirty=%t src=%s file=%s hash=%s", dirty, chunkSrc, snaputil.StripChroot(cow.DataDir()), d.GetHash())
}
Expand Down
11 changes: 6 additions & 5 deletions enterprise/server/remote_execution/snaputil/snaputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ func GetBytes(ctx context.Context, localCache interfaces.FileCache, bsClient byt

// Cache saves a file written to `path` to the local cache, and the remote cache
// if remote snapshot sharing is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document that the returned value is just the bytes uploaded remotely, and not locally.

func Cache(ctx context.Context, localCache interfaces.FileCache, bsClient bytestream.ByteStreamClient, remoteEnabled bool, d *repb.Digest, remoteInstanceName string, path string, fileTypeLabel string) error {
func Cache(ctx context.Context, localCache interfaces.FileCache, bsClient bytestream.ByteStreamClient, remoteEnabled bool, d *repb.Digest, remoteInstanceName string, path string, fileTypeLabel string) (int64, error) {
localCacheErr := cacheLocally(ctx, localCache, d, path)
if !*EnableRemoteSnapshotSharing || *RemoteSnapshotReadonly || !remoteEnabled {
return localCacheErr
return 0, localCacheErr
}

if *VerboseLogging {
Expand All @@ -143,7 +143,7 @@ func Cache(ctx context.Context, localCache interfaces.FileCache, bsClient bytest
rn.SetCompressor(repb.Compressor_ZSTD)
file, err := os.Open(path)
if err != nil {
return err
return 0, err
}
defer file.Close()
_, bytesUploaded, err := cachetools.UploadFromReader(ctx, bsClient, rn, file)
Expand All @@ -152,7 +152,7 @@ func Cache(ctx context.Context, localCache interfaces.FileCache, bsClient bytest
metrics.FileName: fileTypeLabel,
}).Add(float64(bytesUploaded))
}
return err
return bytesUploaded, err
}

// CacheBytes saves bytes to the cache.
Expand All @@ -173,7 +173,8 @@ func CacheBytes(ctx context.Context, localCache interfaces.FileCache, bsClient b
}
}()

return Cache(ctx, localCache, bsClient, remoteEnabled, d, remoteInstanceName, tmpPath, fileTypeLabel)
_, err = Cache(ctx, localCache, bsClient, remoteEnabled, d, remoteInstanceName, tmpPath, fileTypeLabel)
return err
}

var chrootPrefix = regexp.MustCompile("^.*/firecracker/[^/]+/root/")
Expand Down