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

Added statfs for block-cache #1470

Merged
merged 48 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c30ba14
spell check
May 7, 2024
08707ce
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
May 8, 2024
0852969
merge
May 10, 2024
4afd00b
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft May 15, 2024
5006528
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft May 16, 2024
0628e9e
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft May 19, 2024
ed3729e
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jun 19, 2024
fa04d94
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jun 21, 2024
95447ff
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jun 24, 2024
6052556
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 10, 2024
c24b669
fix
ashruti-msft Jul 10, 2024
7e5001a
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 11, 2024
551b9b1
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 15, 2024
e033855
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 16, 2024
009047b
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 17, 2024
6e53a10
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 23, 2024
70f1d12
removed the extra multiplying of maxcachesize during statfs in fc
Jul 24, 2024
4053fe6
Added statfs for blockcache
Jul 24, 2024
962e1c2
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 26, 2024
51648df
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 30, 2024
6333d32
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Jul 31, 2024
cfc27fa
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Aug 1, 2024
7f09150
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Aug 2, 2024
fc9a481
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Aug 5, 2024
23d6002
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Aug 5, 2024
480175d
Merge branch 'main' into ashruti/disk
ashruti-msft Aug 5, 2024
8699f6f
disk
Aug 6, 2024
50faa49
fix
ashruti-msft Aug 23, 2024
65a09ee
MErge
Aug 23, 2024
73677f2
fixed block size for bc
Aug 23, 2024
a584a0f
final
Aug 23, 2024
66f925a
added tests
Aug 23, 2024
435c57a
fix lint
Aug 26, 2024
aa265f6
fix
Aug 27, 2024
9553c28
change
ashruti-msft Oct 11, 2024
6d2b2a2
Delete config
ashruti-msft Oct 11, 2024
56429e5
Sync with main
vibhansa-msft Nov 12, 2024
05ff270
Merge remote-tracking branch 'origin/main' into ashruti/disk
vibhansa-msft Nov 12, 2024
544813f
Sync with main
vibhansa-msft Nov 12, 2024
c7ca1d3
Merge remote-tracking branch 'origin/main' into ashruti/disk
vibhansa-msft Nov 12, 2024
ab6279a
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
ashruti-msft Nov 22, 2024
1212bbe
changelog
ashruti-msft Nov 22, 2024
5e85617
removed repeat code to fix ci
ashruti-msft Nov 22, 2024
430e383
Merge branch 'main' into ashruti/disk
vibhansa-msft Nov 25, 2024
485b26f
sync with main
vibhansa-msft Jan 13, 2025
a63201b
Corrected
vibhansa-msft Jan 13, 2025
11d1017
Merge branch 'blobfuse/2.4.1' into ashruti/disk
vibhansa-msft Jan 15, 2025
05af19b
Updateing changelog
vibhansa-msft Jan 15, 2025
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
- [#1547](https://github.com/Azure/azure-storage-fuse/issues/1547) Truncate logic of file cache is modified to prevent downloading and uploading the entire file.

**Features**
- Added 'gen-config' command to auto generate blobfuse2 config file.
- Added 'gen-config' command to auto generate Blobfuse2 config file.

**Other Changes**
- Stream config will be converted to block-cache config implicitly and 'stream' component is no longer used from this release onwards.
- MSI login with object-id will not rely on azcli anymore, rather it will be supported by 'azidentity' SDK.
- Version check is now moved to a static website hosted on a public container.
- 'df' command output will present memory availability in case of block-cache if disk is not configured.

## 2.3.2 (2024-09-03)
**Bug Fixes**
Expand Down
35 changes: 35 additions & 0 deletions component/block_cache/block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,41 @@ func (bc *BlockCache) SyncFile(options internal.SyncFileOptions) error {
return nil
}

func (bc *BlockCache) StatFs() (*syscall.Statfs_t, bool, error) {
// cache_size = f_blocks * f_frsize/1024
// cache_size - used = f_frsize * f_bavail/1024
// cache_size - used = vfs.f_bfree * vfs.f_frsize / 1024
// if cache size is set to 0 then we have the root mount usage

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
54 changes: 54 additions & 0 deletions component/block_cache/block_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -236,6 +237,58 @@ func (suite *blockCacheTestSuite) TestFreeDiskSpace() {
suite.assert.LessOrEqual(difference, tolerance)
}

func (suite *blockCacheTestSuite) TestStatfsMemory() {
emptyConfig := "read-only: true\n\nblock_cache:\n block-size-mb: 16\n"
tobj, err := setupPipeline(emptyConfig)
defer tobj.cleanupPipeline()

suite.assert.Nil(err)
suite.assert.Equal(tobj.blockCache.Name(), "block_cache")
cmd := exec.Command("bash", "-c", "free -b | grep Mem | awk '{print $4}'")
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
suite.assert.Nil(err)
free, err := strconv.Atoi(strings.TrimSpace(out.String()))
suite.assert.Nil(err)
expected := uint64(0.8 * float64(free))
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.memSize
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) 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 Expand Up @@ -2632,4 +2685,5 @@ func TestBlockCacheTestSuite(t *testing.T) {
_, _ = r.Read(dataBuff)

suite.Run(t, new(blockCacheTestSuite))
suite.Run(t, new(blockCacheTestSuite))
}
4 changes: 2 additions & 2 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ func (c *FileCache) Configure(_ bool) error {
err = syscall.Statfs(c.tmpPath, &stat)
if err != nil {
log.Err("FileCache::Configure : config error %s [%s]. Assigning a default value of 4GB or if any value is assigned to .disk-size-mb in config.", c.Name(), err.Error())
c.maxCacheSize = 4192 * MB
c.maxCacheSize = 4192
} else {
c.maxCacheSize = 0.8 * float64(stat.Bavail) * float64(stat.Bsize)
c.maxCacheSize = (0.8 * float64(stat.Bavail) * float64(stat.Bsize)) / (MB)
}

if config.IsSet(compName+".max-size-mb") && conf.MaxSizeMB != 0 {
Expand Down
2 changes: 1 addition & 1 deletion component/file_cache/file_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (suite *fileCacheTestSuite) TestDefaultCacheSize() {
freeDisk, err := strconv.Atoi(strings.TrimSpace(out.String()))
suite.assert.Nil(err)
expected := uint64(0.8 * float64(freeDisk))
actual := suite.fileCache.maxCacheSize
actual := suite.fileCache.maxCacheSize * MB
difference := math.Abs(float64(actual) - float64(expected))
tolerance := 0.10 * float64(math.Max(float64(actual), float64(expected)))
suite.assert.LessOrEqual(difference, tolerance, "mssg:", actual, expected)
Expand Down
Loading