From d443bc46bc936e8d52f9af9c0f0fb5eba37807b1 Mon Sep 17 00:00:00 2001 From: Anubhuti Shruti Date: Mon, 29 Sep 2025 12:18:04 +0530 Subject: [PATCH 1/5] first --- component/block_cache/block_cache_test.go | 27 ----------------------- 1 file changed, 27 deletions(-) diff --git a/component/block_cache/block_cache_test.go b/component/block_cache/block_cache_test.go index ffd49f066f..41d164d904 100644 --- a/component/block_cache/block_cache_test.go +++ b/component/block_cache/block_cache_test.go @@ -263,33 +263,6 @@ func (suite *blockCacheTestSuite) TestStatfsMemory() { suite.assert.LessOrEqual(difference, tolerance) } -func (suite *blockCacheTestSuite) TestStatfsDisk() { - disk_cache_path := getFakeStoragePath("fake_storage") - config := fmt.Sprintf("read-only: true\n\nblock_cache:\n block-size-mb: 1\n path: %s", disk_cache_path) - tobj, err := setupPipeline(config) - defer tobj.cleanupPipeline() - - suite.assert.Nil(err) - suite.assert.Equal(tobj.blockCache.Name(), "block_cache") - - cmd := exec.Command("bash", "-c", fmt.Sprintf("df -B1 %s | awk 'NR==2{print $4}'", disk_cache_path)) - var out bytes.Buffer - cmd.Stdout = &out - err = cmd.Run() - suite.assert.Nil(err) - freeDisk, err := strconv.Atoi(strings.TrimSpace(out.String())) - suite.assert.Nil(err) - expected := uint64(0.8 * float64(freeDisk)) - stat, ret, err := tobj.blockCache.StatFs() - suite.assert.Equal(ret, true) - suite.assert.Equal(err, nil) - suite.assert.NotEqual(stat, &syscall.Statfs_t{}) - actual := tobj.blockCache.diskSize - difference := math.Abs(float64(actual) - float64(expected)) - tolerance := 0.10 * float64(math.Max(float64(actual), float64(expected))) - suite.assert.LessOrEqual(difference, tolerance) -} - func (suite *blockCacheTestSuite) TestInvalidPrefetchCount() { cfg := "read-only: true\n\nblock_cache:\n block-size-mb: 16\n mem-size-mb: 500\n prefetch: 8\n parallelism: 10\n path: abcd\n disk-size-mb: 100\n disk-timeout-sec: 5" tobj, err := setupPipeline(cfg) From 80019d54879ac9c2884b7ea84ab48f72a2a88c7b Mon Sep 17 00:00:00 2001 From: Anubhuti Shruti Date: Mon, 29 Sep 2025 12:19:52 +0530 Subject: [PATCH 2/5] first --- component/block_cache/block_cache.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/component/block_cache/block_cache.go b/component/block_cache/block_cache.go index df1da5ac5e..0709aea735 100755 --- a/component/block_cache/block_cache.go +++ b/component/block_cache/block_cache.go @@ -1923,6 +1923,17 @@ func (bc *BlockCache) SyncFile(options internal.SyncFileOptions) error { return nil } +// ------------------------- Factory ------------------------------------------- +// Pipeline will call this method to create your object, initialize your variables here +// << DO NOT DELETE ANY AUTO GENERATED CODE HERE >> +func NewBlockCacheComponent() internal.Component { + comp := &BlockCache{ + fileLocks: common.NewLockMap(), + } + comp.SetName(compName) + return comp +} + func (bc *BlockCache) StatFs() (*syscall.Statfs_t, bool, error) { var maxCacheSize uint64 if bc.diskSize > 0 { @@ -1953,17 +1964,6 @@ func (bc *BlockCache) StatFs() (*syscall.Statfs_t, bool, error) { return statfs, true, nil } -// ------------------------- Factory ------------------------------------------- -// Pipeline will call this method to create your object, initialize your variables here -// << DO NOT DELETE ANY AUTO GENERATED CODE HERE >> -func NewBlockCacheComponent() internal.Component { - comp := &BlockCache{ - fileLocks: common.NewLockMap(), - } - comp.SetName(compName) - return comp -} - // On init register this component to pipeline and supply your constructor func init() { internal.AddComponent(compName, NewBlockCacheComponent) From 12dcdf5ed712795082b966ad76a739be7718db85 Mon Sep 17 00:00:00 2001 From: Anubhuti Shruti Date: Mon, 29 Sep 2025 12:20:53 +0530 Subject: [PATCH 3/5] first --- component/block_cache/block_cache.go | 60 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/component/block_cache/block_cache.go b/component/block_cache/block_cache.go index 0709aea735..2e05739d1f 100755 --- a/component/block_cache/block_cache.go +++ b/component/block_cache/block_cache.go @@ -1810,6 +1810,36 @@ func (bc *BlockCache) checkDiskUsage() bool { return false } +func (bc *BlockCache) StatFs() (*syscall.Statfs_t, bool, error) { + var maxCacheSize uint64 + if bc.diskSize > 0 { + maxCacheSize = bc.diskSize + } else { + maxCacheSize = bc.memSize + } + + if maxCacheSize == 0 { + return nil, false, nil + } + + usage, _ := common.GetUsage(bc.tmpPath) + usage = usage * float64(_1MB) + + available := (float64)(maxCacheSize) - usage + statfs := &syscall.Statfs_t{} + err := syscall.Statfs("/", statfs) + if err != nil { + log.Debug("BlockCache::StatFs : statfs err [%s].", err.Error()) + return nil, false, err + } + statfs.Frsize = int64(bc.blockSize) + statfs.Blocks = uint64(maxCacheSize) / uint64(bc.blockSize) + statfs.Bavail = uint64(math.Max(0, available)) / uint64(bc.blockSize) + statfs.Bfree = statfs.Bavail + + return statfs, true, nil +} + // invalidateDirectory: Recursively invalidates a directory in the file cache. func (bc *BlockCache) invalidateDirectory(name string) { log.Trace("BlockCache::invalidateDirectory : %s", name) @@ -1934,36 +1964,6 @@ func NewBlockCacheComponent() internal.Component { return comp } -func (bc *BlockCache) StatFs() (*syscall.Statfs_t, bool, error) { - var maxCacheSize uint64 - if bc.diskSize > 0 { - maxCacheSize = bc.diskSize - } else { - maxCacheSize = bc.memSize - } - - if maxCacheSize == 0 { - return nil, false, nil - } - - usage, _ := common.GetUsage(bc.tmpPath) - usage = usage * float64(_1MB) - - available := (float64)(maxCacheSize) - usage - statfs := &syscall.Statfs_t{} - err := syscall.Statfs("/", statfs) - if err != nil { - log.Debug("BlockCache::StatFs : statfs err [%s].", err.Error()) - return nil, false, err - } - statfs.Frsize = int64(bc.blockSize) - statfs.Blocks = uint64(maxCacheSize) / uint64(bc.blockSize) - statfs.Bavail = uint64(math.Max(0, available)) / uint64(bc.blockSize) - statfs.Bfree = statfs.Bavail - - return statfs, true, nil -} - // On init register this component to pipeline and supply your constructor func init() { internal.AddComponent(compName, NewBlockCacheComponent) From d57eae4933a701fb0deeadf5ff0b61ede8747e96 Mon Sep 17 00:00:00 2001 From: ashruti-msft <137055338+ashruti-msft@users.noreply.github.com> Date: Mon, 29 Sep 2025 18:50:14 +0530 Subject: [PATCH 4/5] Add agent response to PR --- ai-output/agent-1.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ai-output/agent-1.md diff --git a/ai-output/agent-1.md b/ai-output/agent-1.md new file mode 100644 index 0000000000..e6d8c05159 --- /dev/null +++ b/ai-output/agent-1.md @@ -0,0 +1,25 @@ +```go +// Filename: block_cache_test.go + +func TestStatFs(t *testing.T) { + bc := &BlockCache{ + diskSize: 1024 * 1024 * 1024, // 1GB + memSize: 512 * 1024 * 1024, // 512MB + blockSize: 4096, // 4KB + tmpPath: "/tmp/test", // Placeholder path + } + + statfs, ok, err := bc.StatFs() + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if !ok { + t.Fatalf("Expected ok to be true, got false") + } + if statfs == nil { + t.Fatal("Expected statfs to be non-nil") + } + + // Add more assertions based on expected statfs values if needed +} +``` \ No newline at end of file From f00d610009dd907bcd34aa2d8ccf1f36f836d78b Mon Sep 17 00:00:00 2001 From: ashruti-msft <137055338+ashruti-msft@users.noreply.github.com> Date: Mon, 29 Sep 2025 18:50:22 +0530 Subject: [PATCH 5/5] Add agent response to PR --- ai-output/agent-2.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ai-output/agent-2.md diff --git a/ai-output/agent-2.md b/ai-output/agent-2.md new file mode 100644 index 0000000000..f5214ced96 --- /dev/null +++ b/ai-output/agent-2.md @@ -0,0 +1,7 @@ +```go +// Filename: block_cache_test.go + +func (suite *blockCacheTestSuite) TestStatfsDiskRemoved() { + suite.T().Log("TestStatfsDisk has been removed and must not be executed.") +} +``` \ No newline at end of file