You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement PITR management for cluster, account, database, and table levels
Add comprehensive test coverage for PITR operations
Extend SQL parser with INTERNAL keyword support
Changes diagram
flowchart LR
A["SQL Parser"] --> B["Plan Builder"]
B --> C["Compile Engine"]
C --> D["PITR Operations"]
D --> E["mo_catalog.mo_pitr"]
D --> F["sys_mo_catalog_pitr"]
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 Security concerns
SQL injection: The code constructs SQL queries using fmt.Sprintf with user-provided input (pitr names, database names, table names) without proper sanitization or parameterized queries. This is particularly concerning in functions like CreatePitr and DropPitr where user input is directly interpolated into SQL strings. For example, line 3745-3771 shows direct string interpolation of user-controlled values like pitrName, createPitr.GetAccountName(), createPitr.GetDatabaseName(), etc. into SQL INSERT statements.
The CreatePitr and DropPitr functions construct SQL queries using string formatting with user-provided input without proper sanitization. This creates potential SQL injection vulnerabilities.
The error messages in CreatePitr function are inconsistent and potentially misleading. Some error conditions return incorrect error messages that don't match the actual validation being performed.
switchpitrLevel {
casetree.PITRLEVELCLUSTER:
returnmoerr.NewInternalError(c.proc.Ctx, "cluster level pitr already exists")
casetree.PITRLEVELACCOUNT:
returnmoerr.NewInternalErrorf(c.proc.Ctx, "account %s does not exist", createPitr.AccountName)
casetree.PITRLEVELDATABASE:
returnmoerr.NewInternalErrorf(c.proc.Ctx, "database `%s` already has a pitr", createPitr.DatabaseName)
casetree.PITRLEVELTABLE:
returnmoerr.NewInternalErrorf(c.proc.Ctx, "table %s.%s does not exist", createPitr.DatabaseName, createPitr.TableName)
}
}
The result sets from SQL queries are not consistently closed, which could lead to resource leaks. Some defer statements are missing for proper cleanup.
sysPitrSql:="select pitr_length, pitr_unit from mo_catalog.mo_pitr where pitr_name = '"+sysMoCatalogPitr+"'"sysRes, err:=c.runSqlWithResult(sysPitrSql, sysAccountId)
iferr!=nil {
returnerr
}
defersysRes.Close()
The SQL query is vulnerable to SQL injection attacks because user-controlled values are directly interpolated into the query string. Use parameterized queries or proper escaping to prevent SQL injection vulnerabilities.
Why: The suggestion correctly identifies a critical SQL injection vulnerability by using fmt.Sprintf with user-provided data and proposes the standard, secure practice of using parameterized queries.
High
Possible issue
Fix resource leak issue
The result set res is not properly closed, which can lead to resource leaks. Always ensure database result sets are closed using defer res.Close() immediately after checking for errors.
Why: The suggestion correctly identifies a resource leak where the result set res is not closed on all execution paths, which could lead to resource exhaustion.
Medium
General
Fix inconsistent error messages
The error messages are inconsistent with the actual condition being checked. When a PITR already exists, the messages should indicate "already exists" rather than "does not exist" for account and table levels.
case tree.PITRLEVELACCOUNT:
- return moerr.NewInternalErrorf(c.proc.Ctx, "account %s does not exist", createPitr.AccountName)+ return moerr.NewInternalErrorf(c.proc.Ctx, "account level pitr for %s already exists", createPitr.AccountName)
case tree.PITRLEVELDATABASE:
return moerr.NewInternalErrorf(c.proc.Ctx, "database `%s` already has a pitr", createPitr.DatabaseName)
case tree.PITRLEVELTABLE:
- return moerr.NewInternalErrorf(c.proc.Ctx, "table %s.%s does not exist", createPitr.DatabaseName, createPitr.TableName)+ return moerr.NewInternalErrorf(c.proc.Ctx, "table level pitr for %s.%s already exists", createPitr.DatabaseName, createPitr.TableName)
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies misleading error messages for PITRLEVELACCOUNT and PITRLEVELTABLE, improving clarity and correctness for developers and users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
What type of PR is this?
Which issue(s) this PR fixes:
issue #21914
What this PR does / why we need it:
create/drop pitr internal
PR Type
Enhancement
Description
Add CREATE/DROP PITR internal commands support
Implement PITR management for cluster, account, database, and table levels
Add comprehensive test coverage for PITR operations
Extend SQL parser with INTERNAL keyword support
Changes diagram
Changes walkthrough 📝
14 files
Add CreatePitr and DropPitr implementationAdd PITR plan building functionsAdd PITR operation routingAdd Internal flag to PITR structuresUpdate PITR statement kind handlingAdd CreatePitr and DropPitr typesAdd PITR statement routingAdd GetAccountName interface methodAdd INTERNAL keyword supportImplement GetAccountName methodAdd GetAccountName stub implementationAdd GetAccountName stub implementationAdd INTERNAL keyword and grammar rulesAdd CreatePitr and DropPitr protobuf messages3 files
Add comprehensive PITR operation testsAdd GetAccountName mock methodAdd GetAccountName mock implementation2 files