func()

in component/file_cache/file_cache.go [224:357]


func (c *FileCache) Configure(_ bool) error {
	log.Trace("FileCache::Configure : %s", c.Name())

	conf := FileCacheOptions{}
	err := config.UnmarshalKey(compName, &conf)
	if err != nil {
		log.Err("FileCache: config error [invalid config attributes]")
		return fmt.Errorf("config error in %s [%s]", c.Name(), err.Error())
	}

	c.createEmptyFile = conf.CreateEmptyFile
	if config.IsSet(compName + ".file-cache-timeout-in-seconds") {
		c.cacheTimeout = float64(conf.V1Timeout)
	} else if config.IsSet(compName + ".timeout-sec") {
		c.cacheTimeout = float64(conf.Timeout)
	} else {
		c.cacheTimeout = float64(defaultFileCacheTimeout)
	}

	directIO := false
	_ = config.UnmarshalKey("direct-io", &directIO)

	if directIO {
		c.cacheTimeout = 0
		log.Crit("FileCache::Configure : Direct IO mode enabled, cache timeout is set to 0")
	}

	if config.IsSet(compName + ".empty-dir-check") {
		c.allowNonEmpty = !conf.EmptyDirCheck
	} else {
		c.allowNonEmpty = conf.AllowNonEmpty
	}
	c.cleanupOnStart = conf.CleanupOnStart
	c.policyTrace = conf.EnablePolicyTrace
	c.offloadIO = conf.OffloadIO
	c.syncToFlush = conf.SyncToFlush
	c.syncToDelete = !conf.SyncNoOp
	c.refreshSec = conf.RefreshSec
	c.hardLimit = conf.HardLimit

	err = config.UnmarshalKey("lazy-write", &c.lazyWrite)
	if err != nil {
		log.Err("FileCache: config error [unable to obtain lazy-write]")
		return fmt.Errorf("config error in %s [%s]", c.Name(), err.Error())
	}

	c.tmpPath = common.ExpandPath(conf.TmpPath)
	if c.tmpPath == "" {
		log.Err("FileCache: config error [tmp-path not set]")
		return fmt.Errorf("config error in %s error [tmp-path not set]", c.Name())
	}

	err = config.UnmarshalKey("mount-path", &c.mountPath)
	if err != nil {
		log.Err("FileCache: config error [unable to obtain Mount Path]")
		return fmt.Errorf("config error in %s [%s]", c.Name(), err.Error())
	}
	if c.mountPath == c.tmpPath {
		log.Err("FileCache: config error [tmp-path is same as mount path]")
		return fmt.Errorf("config error in %s error [tmp-path is same as mount path]", c.Name())
	}

	// Extract values from 'conf' and store them as you wish here
	_, err = os.Stat(c.tmpPath)
	if os.IsNotExist(err) {
		log.Err("FileCache: config error [tmp-path does not exist. attempting to create tmp-path.]")
		err := os.MkdirAll(c.tmpPath, os.FileMode(0755))
		if err != nil {
			log.Err("FileCache: config error creating directory after clean [%s]", err.Error())
			return fmt.Errorf("config error in %s [%s]", c.Name(), err.Error())
		}
	}

	var stat syscall.Statfs_t
	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
	} else {
		c.maxCacheSize = (0.8 * float64(stat.Bavail) * float64(stat.Bsize)) / (MB)
	}

	if config.IsSet(compName+".max-size-mb") && conf.MaxSizeMB != 0 {
		c.maxCacheSize = conf.MaxSizeMB
	}

	if !isLocalDirEmpty(c.tmpPath) && !c.allowNonEmpty {
		log.Err("FileCache: config error %s directory is not empty", c.tmpPath)
		return fmt.Errorf("config error in %s [%s]", c.Name(), "temp directory not empty")
	}

	err = config.UnmarshalKey("allow-other", &c.allowOther)
	if err != nil {
		log.Err("FileCache::Configure : config error [unable to obtain allow-other]")
		return fmt.Errorf("config error in %s [%s]", c.Name(), err.Error())
	}

	if c.allowOther {
		c.defaultPermission = common.DefaultAllowOtherPermissionBits
	} else {
		c.defaultPermission = common.DefaultFilePermissionBits
	}

	cacheConfig := c.GetPolicyConfig(conf)
	c.policy = NewLRUPolicy(cacheConfig)

	if c.policy == nil {
		log.Err("FileCache::Configure : failed to create cache eviction policy")
		return fmt.Errorf("config error in %s [%s]", c.Name(), "failed to create cache policy")
	}

	if config.IsSet(compName + ".background-download") {
		log.Warn("unsupported v1 CLI parameter: background-download is not supported in blobfuse2. Consider using the streaming component.")
	}
	if config.IsSet(compName + ".cache-poll-timeout-msec") {
		log.Warn("unsupported v1 CLI parameter: cache-poll-timeout-msec is not supported in blobfuse2. Polling occurs every timeout interval.")
	}
	if config.IsSet(compName + ".upload-modified-only") {
		log.Warn("unsupported v1 CLI parameter: upload-modified-only is always true in blobfuse2.")
	}
	if config.IsSet(compName + ".sync-to-flush") {
		log.Warn("Sync will upload current contents of file.")
	}

	c.diskHighWaterMark = 0
	if conf.HardLimit && conf.MaxSizeMB != 0 {
		c.diskHighWaterMark = (((conf.MaxSizeMB * MB) * float64(cacheConfig.highThreshold)) / 100)
	}

	log.Crit("FileCache::Configure : create-empty %t, cache-timeout %d, tmp-path %s, max-size-mb %d, high-mark %d, low-mark %d, refresh-sec %v, max-eviction %v, hard-limit %v, policy %s, allow-non-empty-temp %t, cleanup-on-start %t, policy-trace %t, offload-io %t, sync-to-flush %t, ignore-sync %t, defaultPermission %v, diskHighWaterMark %v, maxCacheSize %v, mountPath %v",
		c.createEmptyFile, int(c.cacheTimeout), c.tmpPath, int(cacheConfig.maxSizeMB), int(cacheConfig.highThreshold), int(cacheConfig.lowThreshold), c.refreshSec, cacheConfig.maxEviction, c.hardLimit, conf.Policy, c.allowNonEmpty, c.cleanupOnStart, c.policyTrace, c.offloadIO, c.syncToFlush, c.syncToDelete, c.defaultPermission, c.diskHighWaterMark, c.maxCacheSize, c.mountPath)

	return nil
}