diff --git a/CHANGELOG.md b/CHANGELOG.md index d46393858..b49bb6679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ **Bug Fixes** - [#1237](https://github.com/Azure/azure-storage-fuse/issues/1237) Fixed the case sensitivity of content type for file extensions. +- [#1230](https://github.com/Azure/azure-storage-fuse/issues/1230) Disable deletion of files from local-cache on sync. Use `--ignore-sync` cli option to enable this. **Optimizations** - Optimized file-cache to skip download when O_TRUNC flag is provided in open call. diff --git a/component/file_cache/file_cache.go b/component/file_cache/file_cache.go index 4ea31b78f..1ffa7ceb4 100644 --- a/component/file_cache/file_cache.go +++ b/component/file_cache/file_cache.go @@ -74,6 +74,7 @@ type FileCache struct { allowOther bool offloadIO bool syncToFlush bool + syncToDelete bool maxCacheSize float64 defaultPermission os.FileMode @@ -105,6 +106,7 @@ type FileCacheOptions struct { V1Timeout uint32 `config:"file-cache-timeout-in-seconds" yaml:"-"` EmptyDirCheck bool `config:"empty-dir-check" yaml:"-"` SyncToFlush bool `config:"sync-to-flush" yaml:"sync-to-flush,omitempty"` + SyncNoOp bool `config:"ignore-sync" yaml:"ignore-sync,omitempty"` RefreshSec uint32 `config:"refresh-sec" yaml:"refresh-sec,omitempty"` } @@ -229,6 +231,7 @@ func (c *FileCache) Configure(_ bool) error { c.offloadIO = conf.OffloadIO c.maxCacheSize = conf.MaxSizeMB c.syncToFlush = conf.SyncToFlush + c.syncToDelete = !conf.SyncNoOp c.refreshSec = conf.RefreshSec c.tmpPath = common.ExpandPath(conf.TmpPath) @@ -322,6 +325,8 @@ func (c *FileCache) OnConfigChange() { c.policyTrace = conf.EnablePolicyTrace c.offloadIO = conf.OffloadIO c.maxCacheSize = conf.MaxSizeMB + c.syncToFlush = conf.SyncToFlush + c.syncToDelete = !conf.SyncNoOp _ = c.policy.UpdateConfig(c.GetPolicyConfig(conf)) } @@ -1095,7 +1100,7 @@ func (fc *FileCache) SyncFile(options internal.SyncFileOptions) error { log.Trace("FileCache::SyncFile : handle=%d, path=%s", options.Handle.ID, options.Handle.Path) if fc.syncToFlush { options.Handle.Flags.Set(handlemap.HandleFlagDirty) - } else { + } else if fc.syncToDelete { err := fc.NextComponent().SyncFile(options) if err != nil { log.Err("FileCache::SyncFile : %s failed", options.Handle.Path) @@ -1501,6 +1506,9 @@ func init() { syncToFlush := config.AddBoolFlag("sync-to-flush", false, "Sync call on file will force a upload of the file.") config.BindPFlag(compName+".sync-to-flush", syncToFlush) + ignoreSync := config.AddBoolFlag("ignore-sync", false, "Just ignore sync call and do not invalidate locally cached file.") + config.BindPFlag(compName+".ignore-sync", ignoreSync) + config.RegisterFlagCompletionFunc("tmp-path", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return nil, cobra.ShellCompDirectiveDefault }) diff --git a/setup/baseConfig.yaml b/setup/baseConfig.yaml index c1bdbce72..cd5b7cbcc 100644 --- a/setup/baseConfig.yaml +++ b/setup/baseConfig.yaml @@ -109,7 +109,8 @@ file_cache: offload-io: true|false sync-to-flush: true|false refresh-sec: - + ignore-sync: true|false + # Attribute cache related configuration attr_cache: timeout-sec: