Skip to content
Closed

demo #2014

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
25 changes: 25 additions & 0 deletions ai-output/agent-1.md
Original file line number Diff line number Diff line change
@@ -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
}
```
7 changes: 7 additions & 0 deletions ai-output/agent-2.md
Original file line number Diff line number Diff line change
@@ -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.")
}
```
60 changes: 30 additions & 30 deletions component/block_cache/block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1923,36 +1953,6 @@ func (bc *BlockCache) SyncFile(options internal.SyncFileOptions) error {
return nil
}

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
}

// ------------------------- Factory -------------------------------------------
// Pipeline will call this method to create your object, initialize your variables here
// << DO NOT DELETE ANY AUTO GENERATED CODE HERE >>
Expand Down
27 changes: 0 additions & 27 deletions component/block_cache/block_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down