From f12cd5da498eac29e33d3d401e0cbcc04f0d35c3 Mon Sep 17 00:00:00 2001 From: karthick udayakumar Date: Fri, 26 Jun 2026 13:51:45 -0400 Subject: [PATCH] fix: move live Statfs to RemainingResources; use *uint64 for min-free config - TotalResources reverts to static startup value to keep total-remaining arithmetic consistent for BBS metrics - RemainingResources caps reported DiskMB at live partition free space (syscall.Statfs), so schedulers see reduced capacity when disk fills - MinCachePartitionFreeBytes changed to *uint64: nil means use the 5 GB default, 0 explicitly disables the check (previously impossible) ai-assisted=yes TNZ-111552 --- depot/depot.go | 21 +++++++++++-------- depot/depot_test.go | 34 ++++++++++++++----------------- initializer/initializer.go | 2 +- initializer/initializer_garden.go | 6 +++--- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/depot/depot.go b/depot/depot.go index 4c3e046a..4c1f583a 100644 --- a/depot/depot.go +++ b/depot/depot.go @@ -220,7 +220,17 @@ func (c *client) DeleteContainer(logger lager.Logger, traceID string, guid strin func (c *client) RemainingResources(logger lager.Logger) (executor.ExecutorResources, error) { logger = logger.Session("remaining-resources") - return c.containerStore.RemainingResources(logger), nil + remaining := c.containerStore.RemainingResources(logger) + if c.diskPath != "" { + var stat syscall.Statfs_t + if err := syscall.Statfs(c.diskPath, &stat); err == nil { + liveDiskMB := int(int64(stat.Bavail) * int64(stat.Bsize) / (1024 * 1024)) + if liveDiskMB < remaining.DiskMB { + remaining.DiskMB = liveDiskMB + } + } + } + return remaining, nil } func (c *client) Ping(logger lager.Logger) error { @@ -228,16 +238,9 @@ func (c *client) Ping(logger lager.Logger) error { } func (c *client) TotalResources(logger lager.Logger) (executor.ExecutorResources, error) { - diskMB := c.totalCapacity.DiskMB - if c.diskPath != "" { - var stat syscall.Statfs_t - if err := syscall.Statfs(c.diskPath, &stat); err == nil { - diskMB = int(int64(stat.Bavail) * int64(stat.Bsize) / (1024 * 1024)) - } - } return executor.ExecutorResources{ MemoryMB: c.totalCapacity.MemoryMB, - DiskMB: diskMB, + DiskMB: c.totalCapacity.DiskMB, Containers: c.totalCapacity.Containers, }, nil } diff --git a/depot/depot_test.go b/depot/depot_test.go index 1ad42db8..2044da79 100644 --- a/depot/depot_test.go +++ b/depot/depot_test.go @@ -699,53 +699,49 @@ var _ = Describe("Depot", func() { }) Describe("RemainingResources", func() { - var resources executor.ExecutorResources + var remainingResources executor.ExecutorResources BeforeEach(func() { - resources = executor.NewExecutorResources(1024, 1024, 3) - containerStore.RemainingResourcesReturns(resources) + remainingResources = executor.NewExecutorResources(1024, 1024, 3) + containerStore.RemainingResourcesReturns(remainingResources) }) It("should reduce resources used by allocated and running containers", func() { actualResources, err := depotClient.RemainingResources(logger) Expect(err).NotTo(HaveOccurred()) - Expect(actualResources).To(Equal(resources)) - }) - }) - - Describe("TotalResources", func() { - Context("when no disk path is configured", func() { - It("returns the frozen startup resources", func() { - Expect(depotClient.TotalResources(logger)).To(Equal(resources)) - }) + Expect(actualResources).To(Equal(remainingResources)) }) - Context("when disk path is configured", func() { + Context("when disk path is configured and partition has less space than the store reports", func() { var tmpDir string BeforeEach(func() { var err error - tmpDir, err = os.MkdirTemp("", "depot-disk-test") + tmpDir, err = os.MkdirTemp("", "depot-remaining-disk-test") Expect(err).NotTo(HaveOccurred()) diskPath = tmpDir - resources.DiskMB = math.MaxInt32 + containerStore.RemainingResourcesReturns(executor.NewExecutorResources(1024, math.MaxInt32, 3)) }) AfterEach(func() { os.RemoveAll(tmpDir) }) - It("returns live disk capacity from syscall.Statfs instead of frozen startup value", func() { - result, err := depotClient.TotalResources(logger) + It("caps remaining disk at the live partition free space from syscall.Statfs", func() { + result, err := depotClient.RemainingResources(logger) Expect(err).NotTo(HaveOccurred()) - Expect(result.MemoryMB).To(Equal(resources.MemoryMB)) - Expect(result.Containers).To(Equal(resources.Containers)) Expect(result.DiskMB).NotTo(Equal(math.MaxInt32)) Expect(result.DiskMB).To(BeNumerically(">", 0)) }) }) }) + Describe("TotalResources", func() { + It("returns the static startup resources", func() { + Expect(depotClient.TotalResources(logger)).To(Equal(resources)) + }) + }) + Describe("VolumeDrivers", func() { Context("when getting volume drivers succeeds", func() { BeforeEach(func() { diff --git a/initializer/initializer.go b/initializer/initializer.go index d0ef0cf8..57fecdbe 100644 --- a/initializer/initializer.go +++ b/initializer/initializer.go @@ -86,7 +86,7 @@ type ExecutorConfig struct { InstanceIdentityPrivateKeyPath string `json:"instance_identity_private_key_path,omitempty"` InstanceIdentityValidityPeriod durationjson.Duration `json:"instance_identity_validity_period,omitempty"` MaxCacheSizeInBytes uint64 `json:"max_cache_size_in_bytes,omitempty"` - MinCachePartitionFreeBytes uint64 `json:"min_cache_partition_free_bytes,omitempty"` + MinCachePartitionFreeBytes *uint64 `json:"min_cache_partition_free_bytes,omitempty"` MaxConcurrentDownloads int `json:"max_concurrent_downloads,omitempty"` MaxLogLinesPerSecond int `json:"max_log_lines_per_second"` MemoryMB string `json:"memory_mb,omitempty"` diff --git a/initializer/initializer_garden.go b/initializer/initializer_garden.go index 0bf9ae35..982d9705 100644 --- a/initializer/initializer_garden.go +++ b/initializer/initializer_garden.go @@ -132,9 +132,9 @@ func Initialize( downloader := cacheddownloader.NewDownloader(10*time.Minute, math.MaxInt8, assetTLSConfig) uploader := uploader.New(logger, 10*time.Minute, assetTLSConfig) - minFree := int64(config.MinCachePartitionFreeBytes) - if minFree == 0 { - minFree = defaultMinCachePartitionFreeBytes + minFree := int64(defaultMinCachePartitionFreeBytes) + if config.MinCachePartitionFreeBytes != nil { + minFree = int64(*config.MinCachePartitionFreeBytes) } cache := cacheddownloader.NewCache(config.CachePath, int64(config.MaxCacheSizeInBytes), minFree) cachedDownloader, err := cacheddownloader.New(