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

feat: add new hash expire cmd to pika #2883

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

Conversation

bigdaronlee163
Copy link
Contributor

@bigdaronlee163 bigdaronlee163 commented Aug 27, 2024

  1. pkhget pkhset
  2. pkhexpire pkhexpireat
  3. pkhexpiretime pkhpersist
  4. pkhttl

Summary by CodeRabbit

  • New Features

    • Introduced a new enumerator PKHASH to enhance access control functionality.
    • Added multiple command constants for PKHash operations, including PKHSet, PKHGet, and expiration commands.
    • Implemented new command classes for managing PKHashes with expiration and persistence features.
    • Enhanced Redis functionality with new methods for PKHash management, including expiration and TTL features.
  • Bug Fixes

    • Improved error handling for PKHash commands to ensure proper responses based on metadata validity.
  • Documentation

    • Updated documentation to reflect new methods and functionalities related to PKHashes.

1. pkhget pkhset
2. pkhexpire pkhexpireat
3. pkhexpiretime pkhpersist
4. pkhttl
@github-actions github-actions bot added the ✏️ Feature New feature or request label Aug 27, 2024
Copy link

coderabbitai bot commented Aug 27, 2024

Walkthrough

The changes introduce a new "PKHash" data type and associated commands in the access control and storage systems. Key modifications include the addition of enumerators, command constants, and methods for managing PKHashes, enhancing the functionality of both the command processing framework and the storage backend. Formatting improvements and organizational adjustments are also made across various files for clarity and readability.

Changes

Files Change Summary
include/acl.h, include/pika_command.h, include/pika_pkhash.h Added new enumerator PKHASH and multiple command constants related to PKHash functionality.
src/pika_client_conn.cc Minor formatting change for improved readability.
src/pika_command.cc Updated command initialization to include new PKHash commands and refined formatting.
src/pika_pkhash.cc, src/pika_pkhash.h Implemented command classes for PKHash operations, managing key-value pairs with expiration.
src/storage/include/.../storage.h Added new methods for PKHash operations and refined formatting.
src/storage/include/.../storage_define.h Added enumerator kPKHashDataCF to ColumnFamilyIndex.
src/storage/src/base_filter.h Expanded filtering capabilities to include kPKHashes data type.
src/storage/src/base_value_format.h Updated DataType enum to include kPKHashes.
src/storage/src/pkhash_data_value_format.h Introduced classes for encoding and parsing PKHash data format.
src/storage/src/redis.cc, src/storage/src/redis.h Added methods for managing PKHash operations in Redis, enhancing data handling capabilities.
src/storage/src/redis_hashes.cc, src/storage/src/redis_pkhashes.cc Implemented methods for PKHashes management, including retrieval and expiration features.
src/storage/src/storage.cc Added PKHash methods to the Storage class and refined method signatures for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommandHandler
    participant Storage

    User->>CommandHandler: PKHSet(key, field, value)
    CommandHandler->>Storage: Store key, field, value
    Storage-->>CommandHandler: Confirmation
    CommandHandler-->>User: Success
Loading
sequenceDiagram
    participant User
    participant CommandHandler
    participant Storage

    User->>CommandHandler: PKHGet(key, field)
    CommandHandler->>Storage: Retrieve key, field
    Storage-->>CommandHandler: Value, metadata
    CommandHandler-->>User: Value or error
Loading

🐰 In fields of code, where rabbits play,
New PKHashes hop and sway.
Commands added, all in line,
A dance of data, oh so fine!
With every change, we leap and cheer,
For better storage, year by year!
🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link

@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: 2

Outside diff range, codebase verification and nitpick comments (14)
src/storage/src/redis_pkhashes.cc (7)

23-63: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.


66-142: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.


144-205: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.


207-274: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.


276-333: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.


335-394: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.


397-452: Consider adding logging for better debugging and monitoring.

The function is correctly implemented with proper error handling and validation checks. Adding logging can help in better debugging and monitoring.

Consider adding logging statements at key points in the function.

src/storage/src/storage.cc (6)

480-484: Review Error Handling in GetDBInstance

The PKHExpire function includes error handling for invalid TTL values, which is appropriate. However, the GetDBInstance function lacks explicit error handling, which might be a concern if the slot index retrieval or instance access could fail. Consider adding error handling to GetDBInstance to ensure robustness.

  • GetDBInstance: No explicit error handling observed.
  • PKHExpire: Handles invalid TTL values correctly.
Analysis chain

LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHExpire handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `GetDBInstance` and `PKHExpire`.

# Test: Search for the function implementations. Expect: Proper error handling.
rg --type cpp -A 5 $'std::unique_ptr<Redis>& Storage::GetDBInstance'
rg --type cpp -A 5 $'Status Redis::PKHExpire'

Length of output: 2096


486-490: Potential Issue: Lack of Error Handling in GetDBInstance

The GetDBInstance function does not have explicit error handling, which could lead to issues if an invalid instance is returned. Consider adding error handling to ensure robustness. The PKHExpireat function in Redis correctly handles invalid timestamps.

  • Review the GetDBInstance function for potential error handling improvements.
Analysis chain

LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHExpireat handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `GetDBInstance` and `PKHExpireat`.

# Test: Search for the function implementations. Expect: Proper error handling.
rg --type cpp -A 5 $'std::unique_ptr<Redis>& Storage::GetDBInstance'
rg --type cpp -A 5 $'Status Redis::PKHExpireat'

Length of output: 1159


Script:

#!/bin/bash
# Description: Check for error handling related to `GetDBInstance`.

# Search for any error handling or checks related to `GetDBInstance`.
rg --type cpp 'GetDBInstance' -A 3 | grep -i 'if\|try\|catch\|error\|exception'

Length of output: 1873


504-508: Improve Error Handling in GetDBInstance

The GetDBInstance function lacks explicit error handling, which could lead to issues if an invalid index is accessed. Consider adding error checks to handle such cases. The PKHTTL function in Redis has partial error handling for specific conditions, which is a positive aspect.

  • File: src/storage/src/storage.cc
  • Function: GetDBInstance
Analysis chain

LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHTTL handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `GetDBInstance` and `PKHTTL`.

# Test: Search for the function implementations. Expect: Proper error handling.
rg --type cpp -A 5 $'std::unique_ptr<Redis>& Storage::GetDBInstance'
rg --type cpp -A 5 $'Status Redis::PKHTTL'

Length of output: 1084


Script:

#!/bin/bash
# Description: Gather more information on error handling in `GetDBInstance` and `PKHTTL`.

# Check for error handling in `GetDBInstance`.
rg --type cpp -A 10 'std::unique_ptr<Redis>& Storage::GetDBInstance' 

# Check for error handling in `PKHTTL`.
rg --type cpp -A 20 'Status Redis::PKHTTL'

Length of output: 2518


510-513: Ensure Robust Error Handling in GetDBInstance

The PKHGet function in Redis has appropriate error handling for type and existence checks. However, GetDBInstance lacks explicit error handling, which could lead to issues if the instance retrieval fails. Consider adding error handling to ensure robustness.

  • GetDBInstance in src/storage/src/storage.cc lacks error handling.
  • PKHGet in src/storage/src/redis_pkhashes.cc has adequate error handling.
Analysis chain

LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHGet handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `GetDBInstance` and `PKHGet`.

# Test: Search for the function implementations. Expect: Proper error handling.
rg --type cpp -A 5 $'std::unique_ptr<Redis>& Storage::GetDBInstance'
rg --type cpp -A 5 $'Status Redis::PKHGet'

Length of output: 1049


Script:

#!/bin/bash
# Description: Gather more context around `GetDBInstance` and `PKHGet` for error handling.

# Search for the full implementation of `GetDBInstance` to check for error handling.
rg --type cpp -A 20 'std::unique_ptr<Redis>& Storage::GetDBInstance'

# Search for the full implementation of `PKHGet` to check for error handling.
rg --type cpp -A 20 'Status Redis::PKHGet'

Length of output: 3083


498-502: Improve Error Handling in GetDBInstance

The GetDBInstance function lacks explicit error handling, which could lead to issues if an invalid index is accessed. Consider adding checks to ensure the index is valid before accessing the instance. The PKHPersist function has some error handling mechanisms in place, which is good practice.

  • File: src/storage/src/storage.cc
  • Function: GetDBInstance
Analysis chain

LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHPersist handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `GetDBInstance` and `PKHPersist`.

# Test: Search for the function implementations. Expect: Proper error handling.
rg --type cpp -A 5 $'std::unique_ptr<Redis>& Storage::GetDBInstance'
rg --type cpp -A 5 $'Status Redis::PKHPersist'

Length of output: 1096


Script:

#!/bin/bash
# Description: Retrieve complete implementations to verify error handling in `GetDBInstance` and `PKHPersist`.

# Search for the complete implementation of `GetDBInstance` to check for error handling.
rg --type cpp -A 20 $'std::unique_ptr<Redis>& Storage::GetDBInstance'

# Search for the complete implementation of `PKHPersist` to check for error handling.
rg --type cpp -A 20 $'Status Redis::PKHPersist'

Length of output: 3101


515-518: Add Error Handling to GetDBInstance and Verify Redis::PKHSet

  • GetDBInstance should include error handling to manage invalid instance indices.
  • Ensure comprehensive error handling in Redis::PKHSet to cover all possible error conditions.

Please review and address these points to improve the robustness of the code.

Analysis chain

LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHSet handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `GetDBInstance` and `PKHSet`.

# Test: Search for the function implementations. Expect: Proper error handling.
rg --type cpp -A 5 $'std::unique_ptr<Redis>& Storage::GetDBInstance'
rg --type cpp -A 5 $'Status Redis::PKHSet'

Length of output: 1054


Script:

#!/bin/bash
# Description: Gather more lines to verify error handling in `GetDBInstance` and `Redis::PKHSet`.

# Get additional context for `GetDBInstance`
rg --type cpp -A 10 $'std::unique_ptr<Redis>& Storage::GetDBInstance(const std::string& key)'

# Get additional context for `Redis::PKHSet`
rg --type cpp -A 10 $'Status Redis::PKHSet(const Slice& key, const Slice& field, const Slice& value, int32_t* res)'

Length of output: 211


Script:

#!/bin/bash
# Description: Refine search to verify error handling in `GetDBInstance` and `Redis::PKHSet`.

# Search for `GetDBInstance` with more context
rg --type cpp -A 15 'std::unique_ptr<Redis>& Storage::GetDBInstance'

# Search for `Redis::PKHSet` with more context
rg --type cpp -A 15 'Status Redis::PKHSet'

Length of output: 2388

src/pika_command.cc (1)

19-19: Add include guard for pika_pkhash.h.

Ensure that the header file pika_pkhash.h is included only once to prevent potential redefinition errors.

Consider adding an include guard in pika_pkhash.h if it doesn't already exist.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4bfb5e7 and 8d150b6.

Files selected for processing (16)
  • include/acl.h (1 hunks)
  • include/pika_command.h (6 hunks)
  • include/pika_pkhash.h (1 hunks)
  • src/pika_client_conn.cc (1 hunks)
  • src/pika_command.cc (10 hunks)
  • src/pika_pkhash.cc (1 hunks)
  • src/storage/include/storage/storage.h (18 hunks)
  • src/storage/include/storage/storage_define.h (2 hunks)
  • src/storage/src/base_filter.h (6 hunks)
  • src/storage/src/base_value_format.h (5 hunks)
  • src/storage/src/pkhash_data_value_format.h (1 hunks)
  • src/storage/src/redis.cc (12 hunks)
  • src/storage/src/redis.h (17 hunks)
  • src/storage/src/redis_hashes.cc (37 hunks)
  • src/storage/src/redis_pkhashes.cc (1 hunks)
  • src/storage/src/storage.cc (36 hunks)
Files skipped from review due to trivial changes (2)
  • src/pika_client_conn.cc
  • src/storage/src/redis_hashes.cc
Additional comments not posted (147)
src/storage/include/storage/storage_define.h (2)

47-47: LGTM!

The addition of the new enumerator kPKHashDataCF is correct and consistent with the existing enumerators.

The code changes are approved.


124-132: LGTM!

The formatting changes improve readability without altering the logic of the function.

The code changes are approved.

src/storage/src/base_value_format.h (3)

21-31: LGTM!

The addition of the new enumerators kPKHashes and kNones is correct and consistent with the existing enumerators.

The code changes are approved.


34-35: LGTM!

The update to the DataTypeStrings array ensures that all enumerators have corresponding string values.

The code changes are approved.


52-53: LGTM!

The formatting changes improve readability without altering the logic of the code.

The code changes are approved.

Also applies to: 100-101, 153-153, 163-167

include/pika_pkhash.h (7)

14-38: LGTM!

The class PKHExpireCmd is correctly implemented.

The code changes are approved.


40-64: LGTM!

The class PKHExpireatCmd is correctly implemented.

The code changes are approved.


65-89: LGTM!

The class PKHExpiretimeCmd is correctly implemented.

The code changes are approved.


91-115: LGTM!

The class PKHPersistCmd is correctly implemented.

The code changes are approved.


117-141: LGTM!

The class PKHTTLCmd is correctly implemented.

The code changes are approved.


143-164: LGTM!

The class PKHGetCmd is correctly implemented.

The code changes are approved.


166-187: LGTM!

The class PKHSetCmd is correctly implemented.

The code changes are approved.

src/pika_pkhash.cc (14)

16-38: LGTM!

The method PKHExpireCmd::DoInitial is correctly implemented.

The code changes are approved.


40-53: LGTM!

The method PKHExpireCmd::Do is correctly implemented.

The code changes are approved.


55-80: LGTM!

The method PKHExpireatCmd::DoInitial is correctly implemented.

The code changes are approved.


81-94: LGTM!

The method PKHExpireatCmd::Do is correctly implemented.

The code changes are approved.


96-116: LGTM!

The method PKHExpiretimeCmd::DoInitial is correctly implemented.

The code changes are approved.


117-130: LGTM!

The method PKHExpiretimeCmd::Do is correctly implemented.

The code changes are approved.


132-150: LGTM!

The method PKHPersistCmd::DoInitial is correctly implemented.

The code changes are approved.


151-164: LGTM!

The method PKHPersistCmd::Do is correctly implemented.

The code changes are approved.


166-184: LGTM!

The method PKHTTLCmd::DoInitial is correctly implemented.

The code changes are approved.


185-198: LGTM!

The method PKHTTLCmd::Do is correctly implemented.

The code changes are approved.


200-207: LGTM!

The method PKHGetCmd::DoInitial is correctly implemented.

The code changes are approved.


209-222: LGTM!

The method PKHGetCmd::Do is correctly implemented.

The code changes are approved.


244-252: LGTM!

The method PKHSetCmd::DoInitial is correctly implemented.

The code changes are approved.


254-265: LGTM!

The method PKHSetCmd::Do is correctly implemented.

The code changes are approved.

src/storage/src/base_filter.h (5)

Line range hint 21-74: LGTM!

The class BaseMetaFilter is correctly implemented.

The code changes are approved.


Line range hint 114-228: LGTM!

The class BaseDataFilter is correctly implemented. The constructor reformatting improves readability.

The code changes are approved.


250-250: LGTM!

The type alias PKHashesMetaFilter is correctly implemented.

The code changes are approved.


251-251: LGTM!

The type alias PKHashesMetaFilterFactory is correctly implemented.

The code changes are approved.


252-252: LGTM!

The type alias PKHashesDataFilter is correctly implemented.

The code changes are approved.

include/acl.h (1)

55-55: LGTM!

The addition of the PKHASH enumerator to the AclCategory enum is consistent with the PR objectives and summary.

The code changes are approved.

include/pika_command.h (14)

141-141: LGTM!

The addition of the kCmdNamePKHSet constant is consistent with the PR objectives and summary.

The code changes are approved.


142-142: LGTM!

The addition of the kCmdNamePKHSetex constant is consistent with the PR objectives and summary.

The code changes are approved.


143-143: LGTM!

The addition of the kCmdNamePKHExpire constant is consistent with the PR objectives and summary.

The code changes are approved.


144-144: LGTM!

The addition of the kCmdNamePKHExpireat constant is consistent with the PR objectives and summary.

The code changes are approved.


145-145: LGTM!

The addition of the kCmdNamePKHExpiretime constant is consistent with the PR objectives and summary.

The code changes are approved.


146-146: LGTM!

The addition of the kCmdNamePKHTTL constant is consistent with the PR objectives and summary.

The code changes are approved.


147-147: LGTM!

The addition of the kCmdNamePKHPersist constant is consistent with the PR objectives and summary.

The code changes are approved.


148-148: LGTM!

The addition of the kCmdNamePKHGet constant is consistent with the PR objectives and summary.

The code changes are approved.


149-149: LGTM!

The addition of the kCmdNamePKHExists constant is consistent with the PR objectives and summary.

The code changes are approved.


150-150: LGTM!

The addition of the kCmdNamePKHDel constant is consistent with the PR objectives and summary.

The code changes are approved.


151-151: LGTM!

The addition of the kCmdNamePKHLen constant is consistent with the PR objectives and summary.

The code changes are approved.


152-152: LGTM!

The addition of the kCmdNamePKHStrlen constant is consistent with the PR objectives and summary.

The code changes are approved.


153-153: LGTM!

The addition of the kCmdNamePKHIncrby constant is consistent with the PR objectives and summary.

The code changes are approved.


154-154: LGTM!

The addition of the kCmdNamePKHIncrbyfloat constant is consistent with the PR objectives and summary.

The code changes are approved.

src/storage/src/redis.cc (3)

Line range hint 30-42: LGTM!

The constructor is correctly initializing the new column family options for pika_hash_data_cf.

The code changes are approved.


102-111: LGTM!

The function is correctly setting up the new column family options for pika_hash_data_cf.

The code changes are approved.


218-218: LGTM!

The function is correctly including kPKHashDataCF in the list of column families to compact.

The code changes are approved.

src/storage/src/redis.h (8)

246-248: LGTM!

The function is correctly implemented to retrieve column family handles for PK Hashes.

The code changes are approved.


253-254: LGTM!

The function is correctly implemented to set expiration time for PK Hash fields.

The code changes are approved.


255-256: LGTM!

The function is correctly implemented to set expiration time for PK Hash fields based on a timestamp.

The code changes are approved.


257-258: LGTM!

The function is correctly implemented to retrieve expiration times for PK Hash fields.

The code changes are approved.


259-260: LGTM!

The function is correctly implemented to retrieve TTL for PK Hash fields.

The code changes are approved.


261-262: LGTM!

The function is correctly implemented to make PK Hash fields persistent by removing their expiration.

The code changes are approved.


263-263: LGTM!

The function is correctly implemented to retrieve the value of a PK Hash field.

The code changes are approved.


264-264: LGTM!

The function is correctly implemented to set the value of a PK Hash field.

The code changes are approved.

src/storage/include/storage/storage.h (16)

26-26: LGTM!

The reordering of include statements is acceptable.

The code changes are approved.


28-28: LGTM!

The inclusion of the new header file is necessary for the new functionality.

The code changes are approved.


Line range hint 98-104: LGTM!

The addition of the operator+ method for KeyInfo struct is correct and useful for combining key information.

The code changes are approved.


111-113: LGTM!

The addition of the ttl field to ValueStatus struct is necessary for managing time-to-live information.

The code changes are approved.


157-159: LGTM!

The addition of the Operation enum is useful for defining various operations in the background task.

The code changes are approved.


171-173: LGTM!

The addition of the constructor and destructor for the Storage class is necessary for proper initialization and cleanup.

The code changes are approved.


256-257: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


262-263: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


272-273: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


482-483: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


506-507: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


516-517: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


590-591: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


753-754: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


1000-1001: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.


1035-1036: LGTM!

The method signature update ensures consistent formatting and clarity.

The code changes are approved.

src/storage/src/storage.cc (1)

492-496: LGTM! Verify error handling.

The function is correctly implemented. Ensure that GetDBInstance and PKHExpiretime handle errors correctly.

The code changes are approved.

Run the following script to verify error handling:

src/pika_command.cc (73)

486-487: Correct initialization of PKHSetCmd.

The command PKHSetCmd is correctly initialized and inserted into the command table.

The code changes are approved.


490-492: Correct initialization of PKHExpireCmd.

The command PKHExpireCmd is correctly initialized and inserted into the command table.

The code changes are approved.


494-496: Correct initialization of PKHExpireatCmd.

The command PKHExpireatCmd is correctly initialized and inserted into the command table.

The code changes are approved.


498-500: Correct initialization of PKHExpiretimeCmd.

The command PKHExpiretimeCmd is correctly initialized and inserted into the command table.

The code changes are approved.


502-503: Correct initialization of PKHTTLCmd.

The command PKHTTLCmd is correctly initialized and inserted into the command table.

The code changes are approved.


506-508: Correct initialization of PKHPersistCmd.

The command PKHPersistCmd is correctly initialized and inserted into the command table.

The code changes are approved.


510-511: Correct initialization of PKHGetCmd.

The command PKHGetCmd is correctly initialized and inserted into the command table.

The code changes are approved.


56-57: Consistent formatting for CompactCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


60-61: Consistent formatting for CompactRangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


80-81: Consistent formatting for FlushallCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


85-86: Consistent formatting for FlushdbCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


159-160: Consistent formatting for ClearCacheCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


162-163: Consistent formatting for LastsaveCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


247-248: Consistent formatting for SetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


251-253: Consistent formatting for GetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


256-258: Consistent formatting for DelCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


264-265: Consistent formatting for IncrCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


269-269: Consistent formatting for IncrbyCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


273-274: Consistent formatting for IncrbyfloatCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


277-278: Consistent formatting for DecrCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


282-282: Consistent formatting for DecrbyCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


286-286: Consistent formatting for GetsetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


290-290: Consistent formatting for AppendCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


293-295: Consistent formatting for MgetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


303-303: Consistent formatting for SetnxCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


306-307: Consistent formatting for SetexCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


310-311: Consistent formatting for PsetexCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


315-315: Consistent formatting for DelvxCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


318-319: Consistent formatting for MsetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


322-323: Consistent formatting for MsetnxCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


327-328: Consistent formatting for GetrangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


332-332: Consistent formatting for SetrangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


335-337: Consistent formatting for StrlenCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


340-342: Consistent formatting for ExistsCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


346-347: Consistent formatting for ExpireCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


351-352: Consistent formatting for PexpireCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


355-357: Consistent formatting for ExpireatCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


360-362: Consistent formatting for PexpireatCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


365-366: Consistent formatting for TtlCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


369-370: Consistent formatting for PttlCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


373-375: Consistent formatting for PersistCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


378-379: Consistent formatting for TypeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


391-391: Consistent formatting for PKSetexAtCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


394-395: Consistent formatting for PKScanRangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


398-399: Consistent formatting for PKRScanRangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


404-405: Consistent formatting for HDelCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


408-409: Consistent formatting for HSetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


412-414: Consistent formatting for HGetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


417-419: Consistent formatting for HGetallCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


422-424: Consistent formatting for HExistsCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


427-428: Consistent formatting for HIncrbyCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


431-433: Consistent formatting for HIncrbyfloatCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


436-438: Consistent formatting for HKeysCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


441-443: Consistent formatting for HLenCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


446-448: Consistent formatting for HMgetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


451-452: Consistent formatting for HMsetCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


455-456: Consistent formatting for HSetnxCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


459-461: Consistent formatting for HStrlenCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


464-466: Consistent formatting for HValsCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


469-470: Consistent formatting for HScanCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


473-474: Consistent formatting for HScanxCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


477-478: Consistent formatting for PKHScanRangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


481-482: Consistent formatting for PKHRScanRangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


514-516: Consistent formatting for LIndexCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


518-519: Consistent formatting for LInsertCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


522-524: Consistent formatting for LLenCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


526-527: Consistent formatting for BLPopCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


530-531: Consistent formatting for LPopCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


535-535: Consistent formatting for LPushCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


538-539: Consistent formatting for LPushxCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


543-544: Consistent formatting for LRangeCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


546-547: Consistent formatting for LRemCmd.

The formatting change improves readability by aligning parameters across multiple lines.

The code changes are approved.


549-550: **Consistent formatting for

Comment on lines +25 to +53
class PKHashDataValue : public InternalValue {
public:
/*
* The header of the Value field is initially initialized to knulltype
*/
explicit PKHashDataValue(const rocksdb::Slice& user_value) : InternalValue(DataType::kNones, user_value) {}
virtual ~PKHashDataValue() {}

virtual rocksdb::Slice Encode() {
size_t usize = user_value_.size();
size_t needed = usize + kSuffixReserveLength + kTimestampLength * 2;
char* dst = ReAllocIfNeeded(needed);
char* start_pos = dst;

memcpy(dst, user_value_.data(), user_value_.size());
dst += user_value_.size();
memcpy(dst, reserve_, kSuffixReserveLength);
dst += kSuffixReserveLength;
EncodeFixed64(dst, ctime_);
dst += kTimestampLength;
EncodeFixed64(dst, etime_);
dst += kTimestampLength; // todo(DDD) 待确认,看这个是否需要。

return rocksdb::Slice(start_pos, needed);
}

private:
const size_t kDefaultValueSuffixLength = kSuffixReserveLength + kTimestampLength * 2;
};
Copy link

Choose a reason for hiding this comment

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

LGTM! But address the TODO comment.

The PKHashDataValue class is correctly implemented. However, the TODO comment in the Encode method needs to be addressed.

The code changes are approved.

Do you want me to help address the TODO comment or open a GitHub issue to track this task?

Comment on lines +55 to +121
class ParsedPKHashDataValue : public ParsedInternalValue {
public:
// Use this constructor after rocksdb::DB::Get(), since we use this in
// the implement of user interfaces and may need to modify the
// original value suffix, so the value_ must point to the string
explicit ParsedPKHashDataValue(std::string* value) : ParsedInternalValue(value) {
if (value_->size() >= kPKHashDataValueSuffixLength) {
user_value_ = rocksdb::Slice(value_->data(), value_->size() - kPKHashDataValueSuffixLength);
memcpy(reserve_, value_->data() + user_value_.size(), kSuffixReserveLength);
ctime_ = DecodeFixed64(value_->data() + user_value_.size() + kSuffixReserveLength);
etime_ = DecodeFixed64(value_->data() + user_value_.size() + kSuffixReserveLength + kTimestampLength);
}
}

// Use this constructor in rocksdb::CompactionFilter::Filter(),
// since we use this in Compaction process, all we need to do is parsing
// the rocksdb::Slice, so don't need to modify the original value, value_ can be
// set to nullptr
explicit ParsedPKHashDataValue(const rocksdb::Slice& value) : ParsedInternalValue(value) {
if (value.size() >= kPKHashDataValueSuffixLength) {
user_value_ = rocksdb::Slice(value.data(), value.size() - kPKHashDataValueSuffixLength);
memcpy(reserve_, value.data() + user_value_.size(), kSuffixReserveLength);
ctime_ = DecodeFixed64(value.data() + user_value_.size() + kSuffixReserveLength);
etime_ = DecodeFixed64(value_->data() + user_value_.size() + kSuffixReserveLength + kTimestampLength);
}
}

virtual ~ParsedPKHashDataValue() = default;

void SetEtimeToValue() override {
if (value_) {
char* dst = const_cast<char*>(value_->data()) + value_->size() - kTimestampLength;
EncodeFixed64(dst, etime_);
}
}

void SetCtimeToValue() override {
if (value_) {
char* dst = const_cast<char*>(value_->data()) + value_->size() - kTimestampLength - kTimestampLength;
EncodeFixed64(dst, ctime_);
}
}

void SetReserveToValue() {
if (value_) {
char* dst = const_cast<char*>(value_->data()) + value_->size() - kPKHashDataValueSuffixLength;
memcpy(dst, reserve_, kSuffixReserveLength);
}
}

virtual void StripSuffix() override {
if (value_) {
value_->erase(value_->size() - kPKHashDataValueSuffixLength, kPKHashDataValueSuffixLength);
}
}

void SetTimestamp(int64_t timestamp) {
etime_ = timestamp;
SetEtimeToValue();
}

protected:
virtual void SetVersionToValue() override {};

private:
const size_t kPKHashDataValueSuffixLength = kSuffixReserveLength + kTimestampLength * 2;
};
Copy link

Choose a reason for hiding this comment

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

LGTM! But address the empty SetVersionToValue method.

The ParsedPKHashDataValue class is correctly implemented. However, the SetVersionToValue method is empty and might need to be implemented.

The code changes are approved.

Do you want me to help implement the SetVersionToValue method or open a GitHub issue to track this task?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant