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

fix: Change the maximum range of setbit's offset to fit redis #2995

Open
wants to merge 9 commits into
base: unstable
Choose a base branch
from

Conversation

Mixficsol
Copy link
Collaborator

@Mixficsol Mixficsol commented Jan 15, 2025

issue: #2983

Summary by CodeRabbit

  • New Features

    • Extended bit operation support from 21 to 32 bits
    • Improved handling of large bit offsets in various operations
  • Bug Fixes

    • Fixed potential integer overflow issues in bit position calculations
    • Enhanced accuracy of bit manipulation methods
  • Tests

    • Added comprehensive test cases for large offset bit operations
    • Verified GetRange functionality for string commands
  • Chores

    • Updated fmt library to version 10.2.1

Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces significant changes to bit operation handling across multiple files in the Pika project. The primary modifications include upgrading the fmt library to version 10.2.1, expanding the maximum bit operation input from 21 to 32 bits, and enhancing bit manipulation functions to support larger offsets and more robust type handling. These changes are implemented consistently across various components, including storage, tools, and test suites, with a focus on improving the range and precision of bit-related operations.

Changes

File Change Summary
CMakeLists.txt Upgraded fmt library from version 7.1.0 to 10.2.1 with updated URL and MD5 hash
include/pika_define.h Increased kMaxBitOpInputBit from 21 to 32
src/pika_bit.cc Removed explicit integer casting when appending bit position
src/storage/src/redis_strings.cc Changed GetBitPos return type from int32_t to int64_t
tests/integration/string_test.go Added new GetRange test case
tests/unit/type/bitops.tcl Added multiple test cases for bit operations with large offsets
Multiple pika_define.h files Updated kMaxBitOpInputBit from 21 to 32 in various tool directories

Sequence Diagram

sequenceDiagram
    participant Client
    participant BitOperations
    participant Storage
    
    Client->>BitOperations: Perform bit operation
    BitOperations->>BitOperations: Validate offset (0-32 bits)
    BitOperations->>Storage: Request/Modify bit data
    Storage-->>BitOperations: Return bit position/result
    BitOperations-->>Client: Return operation result
Loading

Poem

🐰 Bits dancing wider, no more constraint,
From twenty-one to thirty-two we paint!
Our rabbit code leaps with newfound might,
Expanding ranges, making operations bright!
Hop along, little bits, spread your wings! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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>, 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. (Beta)
  • @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.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Jan 15, 2025
@Mixficsol Mixficsol marked this pull request as ready for review January 16, 2025 09:56
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: 0

🧹 Nitpick comments (2)
src/pika_bit.cc (1)

Line range hint 28-28: Update the comment to reflect the current maximum bit offset.

The comment "value no bigger than 2^18" is outdated. Since kMaxBitOpInputBit has been updated to 32, the comment should reflect that the maximum value is now 2^32.

-  // value no bigger than 2^18
+  // value no bigger than 2^32
tests/unit/type/bitops.tcl (1)

145-154: Consider adding more edge cases.

While the test covers basic BITCOUNT functionality with large offsets, consider adding:

  • Tests for range counting near the maximum offset
  • Tests for empty ranges at large offsets
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fdcdd8f and 52b6156.

📒 Files selected for processing (10)
  • CMakeLists.txt (1 hunks)
  • include/pika_define.h (1 hunks)
  • src/pika_bit.cc (1 hunks)
  • src/storage/src/redis_strings.cc (2 hunks)
  • tests/integration/string_test.go (1 hunks)
  • tests/unit/type/bitops.tcl (1 hunks)
  • tools/manifest_generator/include/pika_define.h (1 hunks)
  • tools/pika-port/pika_port_3/pika_define.h (1 hunks)
  • tools/pika_migrate/include/pika_define.h (1 hunks)
  • tools/pika_migrate/src/pika_bit.cc (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CMakeLists.txt
🔇 Additional comments (14)
tools/pika-port/pika_port_3/pika_define.h (1)

120-120: LGTM! Constant update aligns with Redis compatibility.

The increase of kMaxBitOpInputBit from 21 to 32 allows for larger bit offsets, matching Redis's implementation which supports offsets up to 2^32.

Let's verify the constant usage across the codebase:

✅ Verification successful

✓ Constant is consistently defined and used across the codebase

The value of kMaxBitOpInputBit = 32 is uniformly defined in all header files and correctly used in bit operation validations throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all occurrences of kMaxBitOpInputBit to ensure consistent updates
rg "kMaxBitOpInputBit" -A 1

Length of output: 787

tools/pika_migrate/src/pika_bit.cc (2)

30-33: LGTM! Validation check updated for new bit offset limit.

The validation check and comment correctly reflect the new maximum value of 2^32 for bit operations.


171-171: LGTM! Integer handling preserves full range.

The direct use of pos without casting preserves the full range needed for the increased bit offset limit.

tools/manifest_generator/include/pika_define.h (1)

295-295: LGTM! Consistent update in manifest generator.

The kMaxBitOpInputBit constant is correctly updated to 32 to maintain consistency with the main implementation.

tools/pika_migrate/include/pika_define.h (1)

416-416: LGTM! Consistent update in migration tool.

The kMaxBitOpInputBit constant is correctly updated to 32 to maintain consistency across all tools.

tests/integration/string_test.go (1)

280-280: LGTM! Comprehensive test coverage for GetRange.

The test case thoroughly verifies string range retrieval with:

  • Positive indices (0 to 3)
  • Negative indices (-3 to -1)
  • Full string range (0 to -1)
  • Range exceeding string length (10 to 100)
src/storage/src/redis_strings.cc (2)

1069-1074: LGTM! Enhanced GetBitPos to handle larger bit positions.

Changed function signature and variable type to int64_t to support the increased maximum bit offset range.


1152-1152: LGTM! Proper offset calculation for large bit positions.

Correctly adds the byte offset to the calculated position without risk of integer overflow.

src/pika_bit.cc (2)

244-244: LGTM: Improved type handling for larger bit positions.

The removal of the static_cast<int> is correct as it allows handling larger bit positions, which is consistent with Redis's behavior and the PR's objective.


Line range hint 1-450: Verify Redis compatibility with larger bit offsets.

The implementation looks solid and maintains consistency with Redis's behavior. To ensure full compatibility, let's verify the changes against Redis's implementation.

Run the following script to check Redis's documentation and source code for bit operation limits:

include/pika_define.h (1)

369-369: LGTM! Verify dependent code for breaking changes.

The change from 21 to 32 bits aligns with Redis's maximum bit offset (2^32-1). This is a breaking change that expands the supported range.

Let's verify all usages of this constant in the codebase:

✅ Verification successful

Change is safe, all dependencies are aligned

The constant is used consistently for bit offset validation across the codebase. Tools already use the value 32, and the validation logic in src/pika_bit.cc remains compatible with the expanded range.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all occurrences of kMaxBitOpInputBit
rg "kMaxBitOpInputBit" -A 2 -B 2

Length of output: 1727

tests/unit/type/bitops.tcl (3)

134-143: LGTM! Comprehensive edge case testing.

The test properly verifies:

  • Setting/getting bit at maximum valid offset (2^32-1)
  • Error handling for invalid offset (2^32)

156-161: LGTM! Good boundary testing.

The test effectively verifies BITPOS functionality with maximum offset, checking both set (1) and unset (0) bit positions.


163-172: LGTM! Thorough BITOP testing.

The test properly verifies bitwise OR operation with bits set at both ends of the valid range (0 and 2^32-1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant