diff options
| author | Shreyas Siravara <sshreyas@fb.com> | 2017-07-14 18:36:54 -0700 | 
|---|---|---|
| committer | Shreyas Siravara <sshreyas@fb.com> | 2017-09-08 04:53:00 +0000 | 
| commit | f4bfd49009d3b5aa4a6d960f795f2e3f8e9d2762 (patch) | |
| tree | 554e247ea8043e816dcb3015eea67fab3c77c022 | |
| parent | 732544d5b43d1e49299cd359f1754058ec10f5a9 (diff) | |
md-cache: Allow custom per-directory timeouts
Summary:
- This diff looks for a custom xattr on a directory or file called 'trusted.glusterfs.md-cache-timeout' and uses that timeout if it finds it instead of the default timeout value for the cache.
- For example, if we know that a customer has a fixed set of directories that never change, we can set that attribute on all their directories and cache directory metadata for the lifetime of the client (NFS or FUSE) process.
- Port of D5430395 to 3.8
Reviewed By: jdarcy
Change-Id: Ieb232bc1365c59dd7c396c7a617f12973cc8ea01
Reviewed-on: https://review.gluster.org/18241
Reviewed-by: Shreyas Siravara <sshreyas@fb.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
| -rw-r--r-- | xlators/performance/md-cache/src/md-cache.c | 76 | 
1 files changed, 62 insertions, 14 deletions
diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c index 1dcf2354634..165bc73ecdb 100644 --- a/xlators/performance/md-cache/src/md-cache.c +++ b/xlators/performance/md-cache/src/md-cache.c @@ -92,6 +92,11 @@ static struct mdc_key {  		.check = 1,  	},          { +                .name = "trusted.glusterfs.md-cache-timeout", +                .load = 0, +                .check = 1, +        }, +        {                  .name = NULL,                  .load = 0,                  .check = 0, @@ -327,46 +332,88 @@ unlock:  } +static uint32_t __get_mdc_timeout (xlator_t *this, struct md_cache *mdc) +{ +        struct mdc_conf *conf = NULL; +        int32_t ret = 0; +        uint32_t timeout = 0; + +        conf = this->private; + +        // Check the dictionary for a custom timeout, and if non exists, +        // then just return the default timeout +        ret = dict_get_uint32 (mdc->xattr, "trusted.glusterfs.md-cache-timeout", +                                &timeout); + +        if (ret != 0) { +                timeout = conf->timeout; +        } else { +                gf_log (this->name, GF_LOG_DEBUG, "Found custom timeout of %u", +                                timeout); +        } +        return timeout; +} + +  static gf_boolean_t  is_md_cache_iatt_valid (xlator_t *this, struct md_cache *mdc)  { -	struct mdc_conf *conf = NULL;  	time_t           now = 0; -        gf_boolean_t     ret = _gf_true; -	conf = this->private; +        gf_boolean_t     valid = _gf_true; +        uint32_t         timeout = 0;  	time (&now);          LOCK (&mdc->lock);          { -                if (now >= (mdc->ia_time + conf->timeout)) -                        ret = _gf_false; +                timeout = __get_mdc_timeout (this, mdc); +                if (timeout == 0) { +                        gf_log (this->name, GF_LOG_DEBUG, +                                "Assuming custom timeout of %u" +                                " means infinity!", timeout); +                                valid = _gf_true; +                                goto unlock; +                } + +                if (now >= (mdc->ia_time + timeout)) { +                        valid = _gf_false; +                }          } +unlock:          UNLOCK (&mdc->lock); -	return ret; +	return valid;  }  static gf_boolean_t  is_md_cache_xatt_valid (xlator_t *this, struct md_cache *mdc)  { -	struct mdc_conf *conf = NULL;  	time_t           now = 0; -        gf_boolean_t     ret = _gf_true; - -	conf = this->private; +        gf_boolean_t     valid = _gf_true; +        uint32_t         timeout = 0;  	time (&now);          LOCK (&mdc->lock);          { -                if (now >= (mdc->xa_time + conf->timeout)) -                        ret = _gf_false; +                timeout = __get_mdc_timeout (this, mdc); +                if (timeout == 0) { +                        gf_log (this->name, GF_LOG_DEBUG, +                                "Assuming custom timeout of %u" +                                " means infinity!", timeout); +                                valid = _gf_true; +                                goto unlock; +                } + +                if (now >= (mdc->xa_time + timeout)) { +                        valid = _gf_false; +                }          } +unlock:          UNLOCK (&mdc->lock); -	return ret; +	return valid;  } @@ -2658,7 +2705,8 @@ struct volume_options options[] = {            .min = 0,            .max = 300,            .default_value = "1", -          .description = "Time period after which cache has to be refreshed", +          .description = "Time period after which cache has to be refreshed. " +                         "A default value of 0 means infinity.",          },          { .key = {"md-cache-statfs"},            .type = GF_OPTION_TYPE_BOOL,  | 
