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: panic while reading information_schema. KEY_COLUMN_USAGE #4318

Merged

Conversation

killme2008
Copy link
Contributor

@killme2008 killme2008 commented Jul 8, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#4305

What's changed and what's your intention?

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Added functionality to display indexes from tables, including new test and existing system_metrics.
    • Introduced a new table test with columns and indexes, and commands to show and drop these indexes.
  • Bug Fixes

    • Adjusted control flow to handle cases where tables might be dropped during iteration, preventing potential crashes.

@killme2008 killme2008 marked this pull request as ready for review July 8, 2024 20:28
Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

This update introduces a refined control flow in the key column usage logic to safely skip dropped tables during iteration. Additionally, new tests demonstrate the functionality by creating, querying, and dropping tables to verify index display correctness.

Changes

Files Change Summary
src/catalog/src/information_schema/key_column_usage.rs Replaced unreachable!(); with a comment and a continue; statement to handle tables dropped during iteration.
tests/cases/standalone/common/show/show_index.result Added tests for SHOW INDEX FROM test and SHOW INDEX FROM system_metrics, along with creating/dropping of a new table.
tests/cases/standalone/common/show/show_index.sql Added SQL statements to create, show indexes, and drop the test and system_metrics tables.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SQLClient
    participant Catalog

    User->>+SQLClient: Create `test` table
    SQLClient->>+Catalog: Execute CREATE TABLE
    Catalog-->>-SQLClient: Table created
    
    User->>+SQLClient: Show indexes from `test`
    SQLClient->>+Catalog: Execute SHOW INDEX FROM test
    Catalog-->>-SQLClient: Return index details
    
    User->>+SQLClient: Drop `test` table
    SQLClient->>+Catalog: Execute DROP TABLE
    Catalog-->>-SQLClient: Table dropped
    
    User->>+SQLClient: Show indexes from `system_metrics`
    SQLClient->>+Catalog: Execute SHOW INDEX FROM system_metrics
    Catalog-->>-SQLClient: Return index details
Loading

Poem

Crafting code with careful might,
Tables rise and fade from sight.
Indices showcase structure clear,
Through tests we journey, never fear.
Skip the drops, continue the quest,
In this schema, find the best.


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 Configration 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.

@killme2008 killme2008 requested a review from a team as a code owner July 8, 2024 20:28
@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 8, 2024
@killme2008 killme2008 requested a review from tisonkun July 8, 2024 20:32
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81308b9 and a678db7.

Files selected for processing (1)
  • src/catalog/src/information_schema/key_column_usage.rs (1 hunks)
Additional comments not posted (1)
src/catalog/src/information_schema/key_column_usage.rs (1)

259-260: LGTM! But verify the handling of dropped tables.

The change replaces unreachable!() with a comment and a continue statement to handle cases where a table might be dropped during iteration. This prevents a panic and allows the iteration to continue, which is a crucial fix for stability.

However, ensure that the logic correctly handles the cases where tables are dropped during iteration.

Verification successful

Handling of dropped tables during iteration is correctly implemented.

The change replaces unreachable!() with a comment and a continue statement to handle cases where a table might be dropped during iteration. This prevents a panic and allows the iteration to continue, which is a crucial fix for stability. The implementation correctly skips the dropped table and proceeds with the next one.

  • The continue statement ensures smooth iteration without panics.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of dropped tables during iteration.

# Test: Search for the usage of the `make_key_column_usage` method. Expect: Proper handling of dropped tables.
rg --type rust $'make_key_column_usage'

Length of output: 411


Script:

#!/bin/bash
# Extract the full implementation of the `make_key_column_usage` method for detailed analysis.
ast-grep --lang rust --pattern $'async fn make_key_column_usage(&mut self, request: Option<ScanRequest>) -> Result<RecordBatch> {
  $$$
}'

Length of output: 7645

@killme2008 killme2008 requested a review from evenyag July 8, 2024 20:43
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 41 lines in your changes missing coverage. Please review.

Project coverage is 84.89%. Comparing base (d1f1fad) to head (0c348e4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4318      +/-   ##
==========================================
- Coverage   85.15%   84.89%   -0.27%     
==========================================
  Files        1061     1061              
  Lines      188255   188247       -8     
==========================================
- Hits       160313   159803     -510     
- Misses      27942    28444     +502     

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a678db7 and 2bb4b90.

Files selected for processing (3)
  • src/catalog/src/information_schema/key_column_usage.rs (2 hunks)
  • tests/cases/standalone/common/show/show_index.result (2 hunks)
  • tests/cases/standalone/common/show/show_index.sql (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/catalog/src/information_schema/key_column_usage.rs
Additional comments not posted (8)
tests/cases/standalone/common/show/show_index.sql (4)

12-19: LGTM!

The creation of the test table with specified columns, primary key, and time index follows the correct pattern.


23-23: LGTM!

The command to show indexes from the test table is syntactically correct.


24-24: Duplicate command.

This command already exists in the file and does not need to be added again.


35-35: LGTM!

The command to drop the test table is syntactically correct.

tests/cases/standalone/common/show/show_index.result (4)

14-24: LGTM!

The result of creating the test table shows 0 affected rows, which is as expected.


29-37: LGTM!

The result correctly displays the index details for the test table, including the primary key and time index.


38-38: LGTM!

The result correctly displays the index details for the system_metrics table.


75-78: LGTM!

The result of dropping the test table shows 0 affected rows, which is as expected.

Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

LGTM

@killme2008 killme2008 added this pull request to the merge queue Jul 9, 2024
Merged via the queue into GreptimeTeam:main with commit f1d17a8 Jul 9, 2024
53 checks passed
@killme2008 killme2008 deleted the fix/information-schema-panic branch July 9, 2024 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants