Skip to content

Commit d0dbc74

Browse files
authored
fix: avoid mutating resource name in copyFile (#11602)
1 parent fdb6c81 commit d0dbc74

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

enterprise/server/backends/distributed/distributed.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ func (c *Cache) copyFile(ctx context.Context, rn *rspb.ResourceName, source stri
921921
// If the file is large enough and we support ZSTD, then the source will
922922
// have it compressed, and we want to store it compressed. 100 is the
923923
// default value of --cache.pebble.min_bytes_auto_zstd_compression.
924+
rn = rn.CloneVT()
924925
rn.Compressor = repb.Compressor_ZSTD
925926
}
926927
// Don't use [Cache.remoteReader] here, because we don't want to check the

enterprise/server/backends/distributed/distributed_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,45 @@ func TestBackfill(t *testing.T) {
700700
}
701701
}
702702

703+
func TestCopyFileDoesNotMutateResourceNameCompressor(t *testing.T) {
704+
env, _, ctx := getEnvAuthAndCtx(t)
705+
singleCacheSizeBytes := int64(1000000)
706+
peer1 := fmt.Sprintf("localhost:%d", testport.FindFree(t))
707+
peer2 := fmt.Sprintf("localhost:%d", testport.FindFree(t))
708+
baseConfig := Options{
709+
ReplicationFactor: 2,
710+
Nodes: []string{peer1, peer2},
711+
DisableLocalLookup: true,
712+
EnableLocalCompressionLookup: true,
713+
}
714+
715+
sourceCache := &testcompression.CompressionCache{Cache: newMemoryCache(t, singleCacheSizeBytes)}
716+
config1 := baseConfig
717+
config1.ListenAddr = peer1
718+
dc1 := startNewDCache(t, env, config1, sourceCache)
719+
720+
destCache := &testcompression.CompressionCache{Cache: newMemoryCache(t, singleCacheSizeBytes)}
721+
config2 := baseConfig
722+
config2.ListenAddr = peer2
723+
_ = startNewDCache(t, env, config2, destCache)
724+
725+
waitForReady(t, config1.ListenAddr)
726+
waitForReady(t, config2.ListenAddr)
727+
728+
// Note: the value `200` here is intentionally greater than
729+
// cache.pebble.min_bytes_auto_zstd_compression
730+
rn, buf := testdigest.RandomCASResourceBuf(t, 200)
731+
require.Equal(t, repb.Compressor_IDENTITY, rn.GetCompressor())
732+
require.NoError(t, sourceCache.Set(ctx, rn, buf))
733+
734+
require.NoError(t, dc1.copyFile(ctx, rn, peer1, peer2))
735+
require.Equal(t, repb.Compressor_IDENTITY, rn.GetCompressor(), "copyFile should not mutate the caller's resource name")
736+
737+
got, err := destCache.Get(ctx, rn)
738+
require.NoError(t, err)
739+
require.Equal(t, buf, got)
740+
}
741+
703742
func TestContainsMulti(t *testing.T) {
704743
env, _, ctx := getEnvAuthAndCtx(t)
705744
singleCacheSizeBytes := int64(1000000)

0 commit comments

Comments
 (0)