Skip to content

feat(meta-client): add cache crate for databend-meta service #17766

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

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Apr 12, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

feat(meta-client): add cache crate for databend-meta service

Crate databend-common-meta-cache provide a process-wide in memory
cache for databend-meta service.
It stores a continous range of key values locally and watches the
updates on a remote databend-meta and continously apply new changes to
local store.

The cache may be obsolete if the connection to the datbend-meta service
is unstable. Although in the background it keep trying to re-connecting.

This cache requires at least databend-meta 1.2.677; if the server is
older the cache returns a Unsupported error when accessing it.

Usage:

let client = MetaGrpcClient::try_create(/*..*/);
let cache = Cache::new(
        client,
        "your/cache/key/space/in/meta/service",
        "your-app-name-for-logging",
).await;

let value = cache.try_get("key").await?;

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Other

Related Issues


This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Apr 12, 2025
@drmingdrmer drmingdrmer force-pushed the 207-meta-cache branch 4 times, most recently from aa5b422 to 5da20fc Compare April 12, 2025 12:16
@drmingdrmer drmingdrmer requested a review from TCeason April 12, 2025 12:16
@drmingdrmer drmingdrmer marked this pull request as ready for review April 12, 2025 15:45
@BohuTANG
Copy link
Member

BohuTANG commented Apr 13, 2025

Can we integrate this into the MetaClient? Like:

let client = MetaGrpcClient::try_create(/*..*/).with_cache("your/cache/key/space/in/meta/service","your-app-name-for-logging",);
let value = client.xx(...).await?; -- using the cache in the client internal function

@drmingdrmer
Copy link
Member Author

Can we integrate this into the MetaClient? Like:

let client = MetaGrpcClient::try_create(/*..*/).with_cache("your/cache/key/space/in/meta/service","your-app-name-for-logging",);
let value = client.xx(...).await?; -- using the cache in the client internal function

I don't want to encourage such usage. While providing a transparent cache layer may seem convenient, it actually hides network layer errors and could significantly complicate troubleshooting.

@drmingdrmer drmingdrmer force-pushed the 207-meta-cache branch 2 times, most recently from 87f85a5 to cb7f555 Compare April 14, 2025 03:31
@TCeason
Copy link
Collaborator

TCeason commented Apr 14, 2025

I see this pr and I think it's a cache impl inside meta. So we can merge this pr.

When we actually cache some kv with it, we can talk about the actual problem again, right?

@drmingdrmer
Copy link
Member Author

I see this pr and I think it's a cache impl inside meta. So we can merge this pr.

When we actually cache some kv with it, we can talk about the actual problem again, right?

Yes. Then I'll just merge it.

Crate `databend-common-meta-cache` provide a process-wide in memory
cache for databend-meta service.
It stores a continous range of key values locally and watches the
updates on a remote databend-meta and continously apply new changes to
local store.

The cache may be obsolete if the connection to the datbend-meta service
is unstable. Although in the background it keep trying to re-connecting.

This cache requires at least databend-meta 1.2.677; if the server is
older the cache returns a `Unsupported` error when accessing it.

Usage:

```rust
let client = MetaGrpcClient::try_create(/*..*/);
let cache = Cache::new(
        client,
        "your/cache/key/space/in/meta/service",
        "your-app-name-for-logging",
).await;

let value = cache.try_get("key").await?;
```
@drmingdrmer drmingdrmer merged commit 4c7b63b into databendlabs:main Apr 14, 2025
74 of 75 checks passed
@drmingdrmer drmingdrmer deleted the 207-meta-cache branch April 14, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants