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: use master's wall time(physical time) as ttl in binlog #2699

Closed
wants to merge 5 commits into from

Conversation

chejinge
Copy link
Collaborator

@chejinge chejinge commented Jun 6, 2024

image
image
image

Summary by CodeRabbit

  • New Features

    • Introduced logic time management to enhance time-related operations in the storage system.
  • Improvements

    • Enhanced protection mode to improve the robustness of time-sensitive functions.
  • Bug Fixes

    • Improved time updates and logic handling to ensure accurate time retrieval and updating.

从是不会写的 感觉一直都是保护模式?

Copy link

coderabbitai bot commented Jun 6, 2024

Walkthrough

This update introduces a LogicTime class for logical time management across various components. Key changes include adding calls to update logic time in binlog processing functions, adding conditional checks for the ProtectionMode, and modifying several classes to utilize LogicTime::Now() for retrieving time. Additionally, the protection mode is toggled based on the read-only status of the server.

Changes

File(s) Change Summary
src/pika_binlog_transverter.cc, tools/binlog_sender/binlog_transverter.cc, tools/pika-port/pika_port_3/binlog_transverter.cc Added #include "storage/storage_time.h" and logic to update logic time during binlog decoding.
src/storage/include/storage/storage_time.h, src/storage/src/storage_time.cc Introduced LogicTime class for handling logical time operations and declared a global unique pointer to LogicTime instance.
src/storage/src/base_filter.h Added a conditional check for the ProtectionMode in BaseMetaFilter::Filter method.
src/storage/src/base_value_format.h Added #include "storage/storage_time.h" and modified logic to use g_storage_logictime->Now() for retrieving unix_time in InternalValue and ParsedInternalValue classes.
src/pika_client_conn.cc Added logic to toggle the protection mode based on the server's read-only status in the DoCmd method.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PikaClientConn
    participant PikaServer
    participant LogicTime

    Client ->> PikaClientConn: Execute Command
    PikaClientConn ->> PikaServer: Check Read-Only Status
    PikaServer -->> PikaClientConn: Read-Only Status
    alt Read-Only
        PikaClientConn ->> LogicTime: Set ProtectionMode(true)
        PikaClientConn ->> LogicTime: Now()
        LogicTime -->> PikaClientConn: Current Time
        PikaClientConn ->> LogicTime: Set ProtectionMode(false)
    else
        PikaClientConn ->> LogicTime: Now()
        LogicTime -->> PikaClientConn: Current Time
    end
    PikaClientConn -->> Client: Command Result
Loading

Poem

In code's vast winding waltz,
A rabbit brings a digital pulse,
With logic time and storage rhyme,
We've made a change sublime.
Protecting modes in silent nodes,
Binlogs now dance in coded bounds,
Our systems sing in leaps and bounds.


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.

@chejinge chejinge requested a review from AlexStocks June 6, 2024 02:37
@github-actions github-actions bot added the ☢️ Bug Something isn't working label Jun 6, 2024
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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ba25b5 and a562acf.

Files selected for processing (7)
  • src/pika_binlog_transverter.cc (2 hunks)
  • src/storage/include/storage/storage_time.h (1 hunks)
  • src/storage/src/base_filter.h (1 hunks)
  • src/storage/src/base_value_format.h (2 hunks)
  • src/storage/src/storage_time.cc (1 hunks)
  • tools/binlog_sender/binlog_transverter.cc (2 hunks)
  • tools/pika-port/pika_port_3/binlog_transverter.cc (2 hunks)
Additional comments not posted (10)
src/storage/src/storage_time.cc (2)

24-26: LGTM! Simple and effective update of logic_time_.


28-30: LGTM! Proper use of std::atomic for thread-safe read.

src/storage/include/storage/storage_time.h (1)

38-39: LGTM! Proper declaration of the global unique pointer.

tools/binlog_sender/binlog_transverter.cc (1)

76-76: Verify the update of logical time occurs at the correct point in the BinlogDecode process.

Ensure that updating the logical time before parsing the binlog_str does not introduce any side effects or race conditions.

tools/pika-port/pika_port_3/binlog_transverter.cc (1)

81-81: Ensure the logical time update is correctly sequenced in the PortBinlogDecode process.

Check that the update to the logical time before processing the binlog_str does not cause unintended consequences or timing issues.

Verification successful

The logical time update in the PortBinlogDecode function is placed before extracting the exec_time_ from the binlog_str. This ensures that the logical time is updated with the correct execution time from the binlog_item.

  • The logical time update is correctly sequenced within the PortBinlogDecode function.
  • The function is used in master_conn.cc within a conditional block that handles kTypePortBinlog.

No issues were found with the placement of the logical time update.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the logical time update is correctly placed in the `PortBinlogDecode` function.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type cpp $'PortBinlogDecode'

Length of output: 456



Script:

#!/bin/bash
# Extract the implementation of PortBinlogDecode from binlog_transverter.cc
ast-grep --lang cpp --pattern $'bool PortBinlogTransverter::PortBinlogDecode($_, $_, $_) {
  $$$
}' tools/pika-port/pika_port_3/binlog_transverter.cc

# Extract the context of PortBinlogDecode usage in master_conn.cc
rg -A 10 -B 10 'PortBinlogDecode' tools/pika-port/pika_port_3/master_conn.cc

Length of output: 984



Script:

#!/bin/bash
# Extract the full implementation of PortBinlogDecode from binlog_transverter.cc
ast-grep --lang cpp --pattern $'bool PortBinlogTransverter::PortBinlogDecode(PortBinlogType type, const std::string& binlog, PortBinlogItem* binlog_item) {
  $$$
}' tools/pika-port/pika_port_3/binlog_transverter.cc

Length of output: 215



Script:

#!/bin/bash
# Search for the definition of PortBinlogDecode in binlog_transverter.cc and extract its implementation
rg -A 20 'bool PortBinlogTransverter::PortBinlogDecode' tools/pika-port/pika_port_3/binlog_transverter.cc

Length of output: 1156

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

139-139: Updated logic to use logical time instead of system time.

This change aligns with the PR's objective to use logical time for operations, enhancing consistency across different components.


18-18: Ensure the new header inclusion is necessary and correctly placed.

Verification successful

The new header inclusion #include "storage/storage_time.h" is necessary and correctly placed, as g_storage_logictime is used in the file.

  • g_storage_logictime is referenced in src/storage/src/base_value_format.h.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new header is used in this file.

# Test: Search for usage of `g_storage_logictime` in this file. Expect: At least one usage.
rg --type cpp 'g_storage_logictime' src/storage/src/base_value_format.h

Length of output: 123

src/pika_binlog_transverter.cc (2)

88-88: Updated BinlogDecode to use logical time for updating execution time.

This change ensures that the binlog processing logic is consistent with the new logical time system, potentially improving the accuracy of time-dependent operations.


17-17: Ensure the new header inclusion is necessary and correctly placed.

Verification successful

The new header inclusion #include "storage/storage_time.h" is necessary and correctly placed, as the g_storage_logictime from this header is used in the file.

  • src/pika_binlog_transverter.cc: storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new header is used in this file.

# Test: Search for usage of `g_storage_logictime` in this file. Expect: At least one usage.
rg --type cpp 'g_storage_logictime' src/pika_binlog_transverter.cc

Length of output: 141

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

30-31: Updated logic to use logical time instead of system time.

This change ensures that the compaction filter logic uses the new logical time system, which can improve the accuracy and consistency of time-dependent operations.

Comment on lines 16 to 36
class LogicTime {
public:
// Constructor
LogicTime() : logic_time_(0), protection_mode_(false) {}

// Get the current logical time or the system time
int64_t Now();

// Update the logical time
void UpdateLogicTime(int64_t time);

// Get the protection mode status
bool ProtectionMode();

// Set the protection mode
void SetProtectionMode(bool on);

private:
std::atomic<int64_t> logic_time_; // Logical time value
std::atomic<bool> protection_mode_; // Protection mode flag
};
Copy link

Choose a reason for hiding this comment

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

Ensure encapsulation and thread safety in LogicTime.

The LogicTime class uses std::atomic for logic_time_ and protection_mode_, which is good for thread safety. However, consider making the atomic variables private and providing thread-safe public methods to manipulate these values to ensure encapsulation and safety.

@AlexStocks
Copy link
Collaborator

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves multiple files and integrates a new logical time management system across various components, which requires a careful review to ensure consistency and correctness in the implementation.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The UpdateLogicTime method is called before the exec_time_ is updated from the binlog_str in all binlog transverter files. This could lead to using an outdated exec_time_ value.

🔒 Security concerns

No

Code feedback:
relevant filesrc/pika_binlog_transverter.cc
suggestion      

Consider updating the exec_time_ from binlog_str before calling UpdateLogicTime to ensure the logic time is updated with the correct value. [important]

relevant linestorage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

relevant filetools/binlog_sender/binlog_transverter.cc
suggestion      

Update the exec_time_ from binlog_str before calling UpdateLogicTime to prevent using stale execution times. [important]

relevant linestorage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

relevant filetools/pika-port/pika_port_3/binlog_transverter.cc
suggestion      

Ensure that exec_time_ is retrieved from binlog_str before updating the logic time to maintain accurate time tracking. [important]

relevant linestorage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

@AlexStocks
Copy link
Collaborator

@CodiumAI-Agent /improve

@CodiumAI-Agent
Copy link

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Possible bug
Add null pointer check before using g_storage_logictime

Consider checking if g_storage_logictime is initialized before calling UpdateLogicTime to
avoid potential null pointer dereference.

src/pika_binlog_transverter.cc [88]

-storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
+if (storage::g_storage_logictime) {
+  storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
+} else {
+  LOG(ERROR) << "Logic time storage not initialized";
+}
 
Suggestion importance[1-10]: 9

Why: This suggestion addresses a potential null pointer dereference, which is a critical issue. Adding a check ensures the code is more robust and prevents crashes.

9
Enhancement
Handle potential errors when fetching the current time

Add error handling for GetCurrentTime in LogicTime::Now to handle potential failures in
retrieving the system time.

src/storage/src/storage_time.cc [20]

-rocksdb::Env::Default()->GetCurrentTime(&t);
+if (rocksdb::Env::Default()->GetCurrentTime(&t) != rocksdb::Status::OK()) {
+  LOG(ERROR) << "Failed to get current time";
+  return -1; // or handle error appropriately
+}
 
Suggestion importance[1-10]: 8

Why: This suggestion improves the robustness of the code by handling potential errors when fetching the current time, which is important for reliability.

8
Possible issue
Ensure thread safety and initialization check for g_storage_logictime->Now()

Ensure that the Now method is thread-safe if g_storage_logictime is accessed from multiple
threads, considering the use of atomic variables inside LogicTime.

src/storage/src/base_filter.h [30]

-int64_t unix_time = g_storage_logictime->Now();
+int64_t unix_time;
+if (g_storage_logictime) {
+  unix_time = g_storage_logictime->Now();
+} else {
+  LOG(ERROR) << "Logic time storage not initialized";
+  unix_time = -1; // or handle error appropriately
+}
 
Suggestion importance[1-10]: 7

Why: This suggestion adds a check for initialization and ensures thread safety, which is important but not as critical as preventing a null pointer dereference.

7
Best practice
Use a safe wrapper function for getting the current time

Replace direct calls to g_storage_logictime->Now() with a function that checks for
initialization and handles errors, to improve code reuse and reliability.

src/storage/src/base_value_format.h [139]

-int64_t unix_time = g_storage_logictime->Now();
+int64_t unix_time = GetSafeCurrentTime(); // Implement this function to include checks and error handling
 
Suggestion importance[1-10]: 6

Why: This suggestion promotes code reuse and reliability by encapsulating error handling in a function, which is a good practice but less critical than addressing direct issues.

6

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a562acf and 3f92b76.

Files selected for processing (2)
  • src/pika_client_conn.cc (2 hunks)
  • src/storage/src/storage_time.cc (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/storage/src/storage_time.cc
Additional comments not posted (1)
src/pika_client_conn.cc (1)

189-189: Correctly resets the protection mode after command execution.

@@ -164,6 +164,7 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st
return c_ptr;
}
if (g_pika_server->readonly(current_db_) && opt != kCmdNameExec) {
storage::g_storage_logictime->SetProtectionMode(true);
Copy link

Choose a reason for hiding this comment

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

Refactor to improve clarity in setting protection mode.

- storage::g_storage_logictime->SetProtectionMode(true);
- c_ptr->res().SetRes(CmdRes::kErrOther, "READONLY You can't write against a read only replica.");
+ if (g_pika_server->readonly(current_db_)) {
+   storage::g_storage_logictime->SetProtectionMode(true);
+   c_ptr->res().SetRes(CmdRes::kErrOther, "READONLY You can't write against a read only replica.");
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
storage::g_storage_logictime->SetProtectionMode(true);
if (g_pika_server->readonly(current_db_)) {
storage::g_storage_logictime->SetProtectionMode(true);
c_ptr->res().SetRes(CmdRes::kErrOther, "READONLY You can't write against a read only replica.");
}

@@ -5,6 +5,7 @@

#include "binlog_transverter.h"
#include <glog/logging.h>
#include "storage/storage_time.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些工具就没必要改了吧,他们适配的目标是 3.0,不是 3.5 or 4.0

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3f92b76 and aebf4c8.

Files selected for processing (2)
  • src/pika_client_conn.cc (2 hunks)
  • src/storage/src/storage_time.cc (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/pika_client_conn.cc
  • src/storage/src/storage_time.cc

@AlexStocks AlexStocks changed the title fix:bin log use logic time fix: use master's wall time(physical time) as ttl Jun 7, 2024
@AlexStocks AlexStocks changed the title fix: use master's wall time(physical time) as ttl fix: use master's wall time(physical time) as ttl in binlog Jun 7, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aebf4c8 and ebeecd5.

Files selected for processing (2)
  • src/pika_client_conn.cc (1 hunks)
  • src/storage/include/storage/storage_time.h (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/pika_client_conn.cc
  • src/storage/include/storage/storage_time.h

@AlexStocks
Copy link
Collaborator

cjg 继续和邓昊 review

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


cjg continues to review with Deng Hao

@chejinge chejinge force-pushed the ttl_logic_time branch 2 times, most recently from 8824677 to 996feda Compare June 20, 2024 05:52
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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ebeecd5 and 996feda.

Files selected for processing (5)
  • src/pika_binlog_transverter.cc (3 hunks)
  • src/pika_client_conn.cc (1 hunks)
  • src/storage/src/base_filter.h (1 hunks)
  • src/storage/src/base_value_format.h (2 hunks)
  • src/storage/src/storage_time.cc (1 hunks)
Additional comments not posted (3)
src/storage/src/base_value_format.h (1)

18-18: Include statement added for storage/storage_time.h.

The inclusion of storage/storage_time.h is necessary for accessing the g_storage_logictime functionalities used in this file.

src/pika_binlog_transverter.cc (1)

17-17: Include statement added for storage/storage_time.h.

The inclusion of storage/storage_time.h is necessary for accessing the g_storage_logictime functionalities used in the binlog decoding process.

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

31-33: Use of g_storage_logictime in Filter method.

Proper use of g_storage_logictime to fetch the current time based on the protection mode. This ensures correct time comparisons during the compaction filtering process.

Comment on lines 156 to 159
if (g_pika_server->readonly(current_db_)) {
storage::g_storage_logictime->SetProtectionMode(true);
}
storage::g_storage_logictime->SetProtectionMode(false);
Copy link

Choose a reason for hiding this comment

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

Refactor the protection mode setting to prevent logical errors.

-  if (g_pika_server->readonly(current_db_)) {
-    storage::g_storage_logictime->SetProtectionMode(true);
-  }
-  storage::g_storage_logictime->SetProtectionMode(false);
+  bool is_readonly = g_pika_server->readonly(current_db_);
+  storage::g_storage_logictime->SetProtectionMode(is_readonly);

This change ensures that the protection mode is set based on the current database's read-only status in a single operation, preventing any logical inconsistencies.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (g_pika_server->readonly(current_db_)) {
storage::g_storage_logictime->SetProtectionMode(true);
}
storage::g_storage_logictime->SetProtectionMode(false);
bool is_readonly = g_pika_server->readonly(current_db_);
storage::g_storage_logictime->SetProtectionMode(is_readonly);

Comment on lines +14 to +21
int64_t LogicTime::Now() {
if (protection_mode_) {
return logic_time_;
}
int64_t t;
rocksdb::Env::Default()->GetCurrentTime(&t);
return t;
}
Copy link

Choose a reason for hiding this comment

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

Ensure thread safety when accessing logic_time_ outside of protection_mode_.

Consider using atomic operations or mutexes to ensure thread safety for logic_time_ access in non-protection mode environments.

Comment on lines +33 to +36
void LogicTime::SetProtectionMode(bool on) {
protection_mode_ = on;
LOG(INFO) << "Set protection mode to: " << on;
}
Copy link

Choose a reason for hiding this comment

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

Consider adding error handling for logging failures.

Implement error handling or fallback mechanisms for logging within SetProtectionMode to enhance reliability in case of logging system failures or initialization issues.

Comment on lines 139 to 142
if (g_storage_logictime->ProtectionMode()){
unix_time = g_storage_logictime->Now();
}
unix_time = g_storage_logictime->Now();
Copy link

Choose a reason for hiding this comment

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

Redundant call to Now() in IsStale method.

-    unix_time = g_storage_logictime->Now();
+    // Removed redundant line: unix_time is already set in the preceding lines.

Remove the redundant call to g_storage_logictime->Now() to optimize performance and avoid unnecessary logical time fetches.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (g_storage_logictime->ProtectionMode()){
unix_time = g_storage_logictime->Now();
}
unix_time = g_storage_logictime->Now();
if (g_storage_logictime->ProtectionMode()){
unix_time = g_storage_logictime->Now();
}

@@ -167,6 +169,7 @@ bool PikaBinlogTransverter::BinlogItemWithoutContentDecode(BinlogType type, cons
LOG(ERROR) << "Binlog Item type error, expect type:" << type << " actualy type: " << binlog_type;
return false;
}
storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
Copy link

Choose a reason for hiding this comment

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

Ensure logical time is updated with correct execution time.

-  storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
+  pstd::GetFixed32(&binlog_str, &binlog_item->exec_time_);
+  storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

Similar to the previous comment, update the execution time from binlog_str before updating the logical time to prevent using an outdated value.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
pstd::GetFixed32(&binlog_str, &binlog_item->exec_time_);
storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

@@ -84,6 +85,7 @@
LOG(ERROR) << "Binlog Item type error, expect type:" << type << " actualy type: " << binlog_type;
return false;
}
storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
Copy link

Choose a reason for hiding this comment

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

Update logical time before fetching execution time.

-  storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
+  pstd::GetFixed32(&binlog_str, &binlog_item->exec_time_);
+  storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

Update the execution time from binlog_str before calling UpdateLogicTime to ensure the logic time is updated with the correct value.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());
pstd::GetFixed32(&binlog_str, &binlog_item->exec_time_);
storage::g_storage_logictime->UpdateLogicTime(binlog_item->exec_time());

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 996feda and 73ec057.

Files selected for processing (6)
  • src/pika_binlog_transverter.cc (3 hunks)
  • src/pika_client_conn.cc (1 hunks)
  • src/storage/include/storage/storage_time.h (1 hunks)
  • src/storage/src/base_filter.h (1 hunks)
  • src/storage/src/base_value_format.h (2 hunks)
  • src/storage/src/storage_time.cc (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • src/pika_binlog_transverter.cc
  • src/pika_client_conn.cc
  • src/storage/src/base_filter.h
  • src/storage/src/base_value_format.h
  • src/storage/src/storage_time.cc
Additional comments not posted (4)
src/storage/include/storage/storage_time.h (4)

6-12: Header guards and necessary library inclusions are correctly implemented.


16-19: Initialization of atomic members in the constructor ensures thread safety from the start.


38-39: Ensure g_storage_logictime is initialized correctly to avoid null pointer dereferences.

Verification successful

The initialization of g_storage_logictime is correctly found in src/storage/src/storage_time.cc with the statement std::unique_ptr<LogicTime> g_storage_logictime = std::make_unique<LogicTime>();. This ensures that the pointer is properly initialized, preventing null pointer dereferences.

  • src/storage/src/storage_time.cc: std::unique_ptr<LogicTime> g_storage_logictime = std::make_unique<LogicTime>();
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the initialization of `g_storage_logictime`.

# Test: Search for the initialization in the project.
rg --type cpp $'std::unique_ptr<LogicTime> g_storage_logictime = std::make_unique<LogicTime>();'

Length of output: 97



Script:

#!/bin/bash
# Description: Verify the initialization of `g_storage_logictime` in various forms.

# Test: Search for the initialization using different possible forms.
rg --type cpp 'g_storage_logictime = std::make_unique<LogicTime>();'
rg --type cpp 'g_storage_logictime = new LogicTime'
rg --type cpp 'g_storage_logictime = std::make_shared<LogicTime>();'

# Test: Search for any function that might initialize `g_storage_logictime`.
rg --type cpp 'g_storage_logictime ='

Length of output: 347


21-31: Ensure that the implementations of these methods handle atomic operations safely and efficiently.

Verification successful

The implementations of the methods Now, UpdateLogicTime, ProtectionMode, and SetProtectionMode in the LogicTime class have been located and reviewed. The use of std::atomic for logic_time_ and protection_mode_ ensures that the operations on these variables are thread-safe and efficient.

  • The Now method returns the current logical time if protection mode is enabled; otherwise, it retrieves the system time.
  • The UpdateLogicTime method updates the logical time only if protection mode is enabled.
  • The ProtectionMode method simply returns the current state of the protection mode.
  • The SetProtectionMode method sets the protection mode and logs the change.

These implementations correctly handle atomic operations and maintain thread safety.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of methods in LogicTime class.

# Test: Search for method implementations in the project.
ast-grep --lang cpp --pattern $'class LogicTime {
  $$$
  Now($_) {
    $$$
  }
  UpdateLogicTime($_) {
    $$$
  }
  ProtectionMode() {
    $$$
  }
  SetProtectionMode($_) {
    $$$
  }
  $$$  
}'

Length of output: 543



Script:

#!/bin/bash
# Description: Locate the LogicTime class definition and its method implementations.

# Search for the LogicTime class definition in the project.
rg -t cpp 'class LogicTime' -A 20

# Search for the implementations of the methods in the LogicTime class.
rg -t cpp 'int64_t LogicTime::Now|void LogicTime::UpdateLogicTime|bool LogicTime::ProtectionMode|void LogicTime::SetProtectionMode' -A 10

Length of output: 2897

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73ec057 and d33a669.

Files selected for processing (6)
  • src/pika_binlog_transverter.cc (3 hunks)
  • src/pika_client_conn.cc (1 hunks)
  • src/storage/include/storage/storage_time.h (1 hunks)
  • src/storage/src/base_filter.h (1 hunks)
  • src/storage/src/base_value_format.h (4 hunks)
  • src/storage/src/storage_time.cc (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • src/pika_binlog_transverter.cc
  • src/pika_client_conn.cc
  • src/storage/include/storage/storage_time.h
  • src/storage/src/base_filter.h
  • src/storage/src/base_value_format.h
  • src/storage/src/storage_time.cc

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d33a669 and 5c74839.

Files selected for processing (1)
  • src/storage/src/base_value_format.h (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/storage/src/base_value_format.h

@chejinge
Copy link
Collaborator Author

这个暂时不修复

@chejinge chejinge closed this Jun 21, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


This will not be fixed for now

@chejinge chejinge deleted the ttl_logic_time branch June 24, 2024 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.5.5 4.0.0 ☢️ Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants