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 bidirectional kvs #2898

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kmrmt
Copy link
Contributor

@kmrmt kmrmt commented Mar 19, 2025

Description

  • implement bidirectional kvs using kv

Related Issue

Versions

  • Vald Version: v1.7.16
  • Go Version: v1.24.0
  • Rust Version: v1.84.1
  • Docker Version: v27.4.0
  • Kubernetes Version: v1.32.0
  • Helm Version: v3.16.3
  • NGT Version: v2.3.5
  • Faiss Version: v1.9.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • Chores

    • Reorganized project workspace configuration for improved internal consistency.
  • New Features

    • Introduced a new key-value management module enabling bidirectional lookup.
    • Provides robust operations for adding, retrieving, removing, and iterating over entries.
    • Enhanced support for concurrent operations and improved error handling for increased reliability.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

📝 Walkthrough

Walkthrough

This pull request reorders workspace member entries in the root Cargo.toml and introduces a new package for the key-value store. The new package, located under rust/libs/kvs, includes its own Cargo.toml with package metadata, dependencies, and development dependencies. Additionally, a new Rust library is provided in rust/libs/kvs/src/lib.rs that implements a bidirectional mapping interface (BidiMap) along with its supporting struct and methods, accompanied by unit tests.

Changes

File(s) Change Summary
rust/Cargo.toml Reordered [workspace] members by moving "libs/observability" and "libs/proto" to follow "libs/kvs", without altering functionality or the libraries included.
rust/libs/kvs/Cargo.toml New package configuration for kvs with package details (name, version, edition), dependencies (anyhow, kv, serde), and development dependency (tokio).
rust/libs/kvs/src/lib.rs New Rust library implementing the BidiMap trait and its implementation via the Bidi struct, including methods for creating, getting, setting, deleting, iterating, and testing.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BidiMap as KVS_BidiMap
    Client->>BidiMap: new(path)
    Note right of BidiMap: Initialize bidirectional mapping buckets
    Client->>BidiMap: set(key, value, timestamp)
    Note right of BidiMap: Entry added to both mapping buckets
    Client->>BidiMap: get(key)
    BidiMap-->>Client: (value, timestamp)
    Client->>BidiMap: get_inverse(value)
    BidiMap-->>Client: (key, timestamp)
    Client->>BidiMap: delete(key)
    BidiMap-->>Client: confirmation
Loading

Possibly related PRs

Suggested labels

type/feature, priority/medium, size/L

Suggested reviewers

  • kpango
  • vankichi

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
rust/libs/kvs/src/lib.rs (4)

21-30: Consider adopting custom errors.

The methods in your BidiMap trait return generalized Result<_, anyhow::Error>. While it works, using a specialized error type (e.g., an enum) could enhance maintainability and clarity.


49-55: Validate store configuration and path handling.

While this function creates a new store at the given path, consider logging or validating path correctness, ensuring that any creation, permission, or concurrency issues are handled gracefully.


57-66: Enhance “key not found” error context.

Returning a generic “key not found” message could be expanded to include the missing key’s value or more context. This helps with debugging, especially in production.


105-113: Offer an iterator-based approach for range.

Using range with a closure is fine, but returning an iterator could be more flexible for callers. Iterators compose well with Rust’s standard library patterns (e.g., map, filter).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78477ef and ee2bc49.

⛔ Files ignored due to path filters (1)
  • rust/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • rust/Cargo.toml (1 hunks)
  • rust/libs/kvs/Cargo.toml (1 hunks)
  • rust/libs/kvs/src/lib.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: check-format-diff
  • GitHub Check: Run tests for Rust
  • GitHub Check: build / build
  • GitHub Check: Analyze (go)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (7)
rust/Cargo.toml (1)

24-26: Reordered workspace members successfully.

No functional changes are introduced by rearranging the workspace members, and the updated sequence appears consistent with the addition of the libs/kvs entry. All references remain intact, so this reordering is acceptable.

rust/libs/kvs/Cargo.toml (1)

1-28: Review package and dependency declarations.

  1. Your pinned versions (e.g., anyhow = "1.0.97", tokio = "1.44.1") look stable, which is beneficial for reproducible builds. Regularly check for security patches and updates.
  2. The crate name "kvs" is descriptive but may collide with potential external crates; consider a more specific name if you plan to publish.
  3. Overall, this file is well-structured, and the dependencies align with typical usage for error handling, serialization, and asynchronous programming.
rust/libs/kvs/src/lib.rs (5)

32-35: Ensure correct lifetime management of buckets.

The Bidi<'a> struct holds bucket references with 'a. Verify that the referenced store remains in scope for 'a; otherwise, dangling references might arise if the store is closed or dropped.


115-120: Good integrity check between ou and uo buckets.

Ensuring both buckets have the same length avoids silent data mismatches. The ensure! macro is a clear solution for quick validation. This is a robust touch.


127-180: Tests: Single-thread functional coverage.

  1. Cleanup strategy with teardown is solid; ephemeral directories help keep test artifacts isolated.
  2. Basic CRUD operations are thoroughly tested, ensuring correctness and verifying that store files persist on disk.

182-213: Tests: Range coverage.

Iterating through inserted items is a reliable approach for verifying that both keys and metadata (timestamps) are correct. This check ensures items are properly stored and retrieved.


215-313: Tests: Concurrent read/write coverage.

  1. The multi-threaded test thoroughly exercises read and write operations across multiple tasks, adding confidence in concurrency safety.
  2. Consider verifying partial-failure scenarios under concurrency (e.g., one thread fails to write) if you anticipate real-world usage with potential I/O errors.

Comment on lines +74 to +84
fn set(&mut self, key: &str, value: u32, timestamp: u128) -> Result<()> {
self.uo.set(&key, &Bincode(ValueUo{
value,
timestamp,
}))?;
self.ou.set(&Integer::from(value), &Bincode(ValueOu {
value: key.to_owned(),
timestamp,
}))?;
Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle partial failure for set operations.

If the first self.uo.set(...) call succeeds but the second self.ou.set(...) fails, the buckets become inconsistent. Consider a rollback or transactional approach to revert the first write if the second fails.

@kmrmt kmrmt requested review from a team, kpango and vankichi and removed request for a team March 24, 2025 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants