Skip to content

Add Caching #6

Closed
Closed

Description

@c-thiel

Currently we issue a lot of DB requests. In many places, we would benefit greatly from Caching. A bit of motivation:

  • signing requests typically sign requests for many files at once in very short timeframes
  • Table-Identifier to ID conversion is required by AuthZ and typically called multiple times, as clients first create and then commit multiple changes to a table.
  • Signing depends on a very expensive query: Searching for a query based on its location - the location of a table is almost static.

Good places to implement caching serve slowly changing data and are queried often.
However, we must always assume that we run in a distributed environment. Thus, we should never cache the full TableMetadata that can change frequently for a table. In contrast, location & uuid can be considered slowly changing.

Some calls that I think should be cached:

I am not sure yet what would be the best place to add caching. Ideally, its not implementation specific, so it shouldn't be part of postgres, so not in this folder: https://github.com/hansetag/iceberg-rest-server/tree/main/crates/iceberg-rest-server/src/implementations/postgres

We also have to make the choice of distributed vs. local caching. I currently prefer local caching due to less dependencies. Postgres and most other DBs cache as well.

Activity

  1. added this to the Release 0.1.0 milestone on May 14, 2024
  2. added
    good first issue
    enhancement
    big
    on May 14, 2024
  3. removed this from the Release 0.1.0 milestone on Jun 3, 2024
  4. twuebi commented on Jul 24, 2024

    @twuebi
    Collaborator

    What are your thoughts regarding cache invalidation? Tables may be dropped or staged tables may be overwritten, in both cases the cached name -> uuid mapping becomes stale.

    I can see a cache work for the location mapping, here we could simply store the full location based on previous lookups, if this gets stale we still have the same behavior, a 404 upon fetching from pg using the full location. We'd get rid of the prefix based lookup this way.

    For all other caches, I only see them working with some fallback logic that retries and cleans the cache executed from the respective handler fn which sounds boilerplatey.

  5. twuebi commented on Sep 18, 2024

    @twuebi
    Collaborator

    We've implemented caching in #334 and then decided to revert the change again in #335. Caching static data such as table locations also proved problematic since a table location may get reused by a new table.
    This can cause issues when:

    1. sign access to old table, cache now has an entry
    2. drop old table
    3. create new table at old location
    4. sign access to new table would resolve to the old table id

    In theory, we could work around this by removing the entry from cache upon not found in db and issuing a single retry.

    We may also want to consider a distributed cache solution with proper invalidation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bigenhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions