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

*: add TTL functionality #1

Merged
merged 2 commits into from
Nov 24, 2021
Merged

*: add TTL functionality #1

merged 2 commits into from
Nov 24, 2021

Conversation

GiedriusS
Copy link
Member

Add the ability to specify TTLs for values in the codec interface. With this, the expiration timestamp is passed to the LRU. When getting values from the LRU, the timestamp is checked - if the value has expired then we discard that value and return nothing. Inspired by https://github.com/mailgun/groupcache.

Added tests to http/http_test.go to test whether the keys get regenerated properly. Improved lru_test.go with expiration tests.

More details in the commits.

Add expiration time in preparation for the TTL feature.
TTLs are based on expiration in the LRU - during getting if the value is
expired then it is removed from the LRU and we return nothing. This is
needed to have short-lived values in a distributed system. To achieve
this, expand the `valWithStat` struct with `expire time.Time`. Then,
expand all of the related interfaces:
- Codecs
- `setLRUOnEvicted`
- etc.

Since the HTTP interface returns in the body raw bytes, send the
expiration timestamp with headers. Expand the test in
`http/http_test.go` to test whether the keys are being regenerated after
the timestamp. Copy over a test from mailgun/groupcache for TTLs in the
LRU.
GiedriusS added a commit to GiedriusS/thanos that referenced this pull request Nov 22, 2021
Adds TTL support to galaxycache as per this pull request:
thanos-community/galaxycache#1

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Copy link

@akanshat akanshat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪🏻

Copy link
Member

@onprem onprem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@onprem onprem merged commit ab6f170 into master Nov 24, 2021
@GiedriusS GiedriusS deleted the add_ttl branch November 24, 2021 14:50
GiedriusS added a commit to GiedriusS/thanos that referenced this pull request Dec 13, 2021
Adds TTL support to galaxycache as per this pull request:
thanos-community/galaxycache#1

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
GiedriusS added a commit to thanos-io/thanos that referenced this pull request Jan 6, 2022
* cache: add groupcache

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* implement Cache interface on groupcache

Signed-off-by: akanshat <akanshat1999@gmail.com>

* move BucketCacheKey to a new package

Signed-off-by: akanshat <akanshat1999@gmail.com>

* add copyright to new pkg cachekey

Signed-off-by: akanshat <akanshat1999@gmail.com>

* add a fix to return partial results if Get fails

Signed-off-by: akanshat <akanshat1999@gmail.com>

* migrate from groupcache to galaxycache

Signed-off-by: akanshat <akanshat1999@gmail.com>

* instrument metrics for galaxyCache

Signed-off-by: akanshat <akanshat1999@gmail.com>

* add e2e test for store with groupcache

Signed-off-by: akanshat <akanshat1999@gmail.com>

* fix collector interface on CacheStatsCollector

Signed-off-by: akanshat <akanshat1999@gmail.com>

* cache: fix / clean up tests

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* groupcache: support IterVerb

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* groupcache: changes according to comments

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* store: fix groupcache test

Signed-off-by: akanshat <akanshat1999@gmail.com>

* cache: add TTL support

Adds TTL support to galaxycache as per this pull request:
thanos-community/galaxycache#1

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* move caching_bucket_config to pkg cache

Signed-off-by: akanshat <akanshat1999@gmail.com>

* modify groupcacheCfg

Signed-off-by: akanshat <akanshat1999@gmail.com>

* remove duplicate CachingBucketConfig

Signed-off-by: akanshat <akanshat1999@gmail.com>

* remove duplicate calls to NewCachingBucketConfig

Signed-off-by: akanshat <akanshat1999@gmail.com>

* refactor cache configuration

Signed-off-by: akanshat <akanshat1999@gmail.com>

* implement suggestions from comments

Signed-off-by: akanshat <akanshat1999@gmail.com>

* *: formatting changes

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* *: linter fixes

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

Co-authored-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Co-authored-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants