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

Distinguish caching values and storing values persistently #606

Closed
wants to merge 1 commit into from

Conversation

svix-daniel
Copy link
Contributor

@svix-daniel svix-daniel commented Aug 2, 2022

Before these changes we had used the concept of the cache for features such as idempotency and others which have persistent data. This conflicts with the definition of caching, which is meant to work with ephemeral data. Thus these changes distinguish the concepts with a SharedStore and a Cache structure, which internally, both use a KvBackend implementor.

Note that this is not exposed in the configuration, but this split is needed as additional functionality unique to persistent storage or genuine caching is implemented.

Additionally this updates prior uses of the cache to utilize the structure most appropriate.

@svix-daniel svix-daniel force-pushed the daniel/cache-store-split branch 2 times, most recently from 27fabf1 to 42c45e1 Compare August 2, 2022 20:30
server/svix-server/config.default.toml Outdated Show resolved Hide resolved
server/svix-server/src/cfg.rs Outdated Show resolved Hide resolved
server/svix-server/src/cfg.rs Outdated Show resolved Hide resolved
server/svix-server/src/cfg.rs Outdated Show resolved Hide resolved
server/svix-server/src/cfg.rs Outdated Show resolved Hide resolved
server/svix-server/src/core/cache.rs Outdated Show resolved Hide resolved
server/svix-server/src/core/idempotency.rs Outdated Show resolved Hide resolved
server/svix-server/src/v1/endpoints/health.rs Outdated Show resolved Hide resolved
server/svix-server/src/lib.rs Outdated Show resolved Hide resolved
server/svix-server/src/lib.rs Outdated Show resolved Hide resolved
# multiple API servers running, please use the redis backend or some functionality, (e.g. Idempotency)
# may fail to work correctly.
# The memory backend is recommended if you only have one instance running, if you have multple
# services running, then pleas use the redis backend or features like idempotency will fail to work
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# services running, then pleas use the redis backend or features like idempotency will fail to work
# services running, then please use the redis backend or features like idempotency will fail to work


#[derive(Clone)]
pub struct NoCache;
pub struct NoKeyValueStore;
Copy link
Member

Choose a reason for hiding this comment

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

If you are already renaming it, please rename it to KeyValueStoreNone to be consistent with the rest.

impl AppEndpointKey {
// FIXME: Rewrite doc comment when AppEndpointValue members are known
/// Returns a key for fetching all cached endpoints for a given organization and application.
pub fn new(org: OrganizationId, app: ApplicationId) -> AppEndpointKey {
AppEndpointKey(format!("{}_APP_v3_{}_{}", Self::PREFIX_CACHE, org, app))
AppEndpointKey(format!("_APP_v3_{}_{}", org, app))
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong? Shouldn't it be:

Suggested change
AppEndpointKey(format!("_APP_v3_{}_{}", org, app))
AppEndpointKey(format!("{}_{}", org, app))

And I'm not sure where the _ between the prefix and the key go.

I gotta say, I'm not sure I'm a huge fan of having the prefix defined separately than the function, it makes it very hard to know what's going on. It's much easier to just see:

         AppEndpointKey(format!("SVIX_CACHE_APP_v3_{}_{}", org, app))

All in one place.

pub first_failure_at: DateTimeUtc,
}

kv_def!(FailureCacheKey, FailureCacheValue, "SVIX_FAILURE_CACHE");
store_kv_def!(FailureKey, FailureValue, "FAILURES_");
Copy link
Member

Choose a reason for hiding this comment

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

Missing the Svix prefix.

After seeing this, I'm 100% convinced about my other comment of splitting the prefix being confusing.

Copy link
Member

@tasn tasn left a comment

Choose a reason for hiding this comment

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

I made some comments, though I think the may problem is that this PR is just too big.

For example, I'd split the fact that cache can't be null (it's checked in idempotency) to its own PR, and just get that in.
I'd then have another PR that splits the cache and store to two, but everything will still use cache.
I'd then have another PR (or better yet, commit on the second PR) to start using the store.

It's just really really hard to understand what's going on and why a change is needed and what may be a mistake.

I'm also 95% certain we need to remove the prefix from the cache/store structs and just have the key fully defined in the new() function that we already have for each of them anyway.

@svix-jplatte svix-jplatte deleted the daniel/cache-store-split branch August 22, 2024 09:55
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