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

Fix bug in cache of the index object client #10587

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

chaudum
Copy link
Contributor

@chaudum chaudum commented Sep 14, 2023

The bug could manifest in missing results when querying logs older than what is kept on ingesters.

This commit changes the behaviour of the caching in the storage client client used by the indexshipper to download indexes from object store.

The object store client maintains an internal, in-memory cache of tables (= per-day index directories) available on object storage to reduce the amount of expensive List operations. This cache gets updated in a regular interval (1m) by the table manager that uses the client. However, when the per-tenant setting query_ready_index_num_days is set the 0, which is the default (to disable index pre-fetching), the sync is only performed once on startup, but not subsequently. This leads to a stale list of table names in the cache and any new index directory added to the object storage is not added to the client cache.

This commit changes the object client to use a read-through caching strategy for listing tables. If a table is not found locally in cache, it performs a lookup against object storage. In this way, the cache is updated even without the regular sync described above.

Special notes for your reviewer:

This is a port of #10585 which was first applied on the 2.9 release branch.

The bug could manifest in missing results when querying logs older than
what is kept on ingesters.

This commit changes the behaviour of the caching in the storage client
client used by the indexshipper to download indexes from object store.

The object store client maintains an internal, in-memory cache of tables
(= per-day index directories) available on object storage to reduce the
amount of expensive List operations. This cache gets updated in a
regular interval (1m) by the table manager that uses the client.
However, when the per-tenant setting `query_ready_index_num_days` is set
the 0, which is the default (to disable index pre-fetching), the sync is
only performed once on startup, but not subsequently. This leads to a
stale list of table names in the cache and any new index directory added
to the object storage is not added to the client cache.

This commit changes the object client to use a read-through caching
strategy for listing tables. If a table is not found locally in cache,
it performs a lookup against object storage. In this way, the cache is
updated even without the regular sync described above.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
@pull-request-size pull-request-size bot added size/M and removed size/L labels Sep 14, 2023
@chaudum chaudum marked this pull request as ready for review September 14, 2023 15:12
@chaudum chaudum requested a review from a team as a code owner September 14, 2023 15:12
@chaudum chaudum enabled auto-merge (squash) September 14, 2023 15:20
@chaudum
Copy link
Contributor Author

chaudum commented Sep 14, 2023

Ooof

panic: runtime error: invalid memory address or nil pointer dereference test-target-branch chaudum/port-8c94fdd79-to-main

Maybe something went wrong when resolving conflicts after cherry picking the commit. Need to take a look

@chaudum chaudum merged commit e858779 into main Sep 14, 2023
@chaudum chaudum deleted the chaudum/port-8c94fdd79-to-main branch September 14, 2023 18:51
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
The bug could manifest in missing results when querying logs older than
what is kept on ingesters.

This commit changes the behaviour of the caching in the storage client
client used by the indexshipper to download indexes from object store.

The object store client maintains an internal, in-memory cache of tables
(= per-day index directories) available on object storage to reduce the
amount of expensive List operations. This cache gets updated in a
regular interval (1m) by the table manager that uses the client.
However, when the per-tenant setting `query_ready_index_num_days` is set
the 0, which is the default (to disable index pre-fetching), the sync is
only performed once on startup, but not subsequently. This leads to a
stale list of table names in the cache and any new index directory added
to the object storage is not added to the client cache.

This commit changes the object client to use a read-through caching
strategy for listing tables. If a table is not found locally in cache,
it performs a lookup against object storage. In this way, the cache is
updated even without the regular sync described above.

**Special notes for your reviewer**:

This is a port of grafana#10585 which was first applied on the 2.9 release
branch.

---------

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants