-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 2 commits
a562acf
aebf4c8
ebeecd5
d33a669
5c74839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||
c_ptr->res().SetRes(CmdRes::kErrOther, "READONLY You can't write against a read only replica."); | ||||||||||||
return c_ptr; | ||||||||||||
} | ||||||||||||
|
@@ -185,6 +186,7 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st | |||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
storage::g_storage_logictime->SetProtectionMode(false); | ||||||||||||
|
||||||||||||
// Process Command | ||||||||||||
c_ptr->Execute(); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2024-present The storage Authors. All rights reserved. | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. An additional grant | ||
// of patent rights can be found in the PATENTS file in the same directory. | ||
|
||
#ifndef STORAGE_TIME_H | ||
#define STORAGE_TIME_H | ||
|
||
#include <atomic> | ||
#include <memory> | ||
#include <cstdint> | ||
#include <rocksdb/env.h> // Assuming you're using RocksDB for time functions | ||
|
||
namespace storage { | ||
|
||
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 | ||
AlexStocks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::atomic<bool> protection_mode_; // Protection mode flag | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure encapsulation and thread safety in The |
||
|
||
// Global unique pointer to LogicTime instance | ||
extern std::unique_ptr<LogicTime> g_storage_logictime; | ||
|
||
} // namespace storage | ||
|
||
#endif // STORAGE_TIME_H | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2024-present, Qihoo, Inc. All rights reserved. | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. An additional grant | ||
// of patent rights can be found in the PATENTS file in the same directory. | ||
|
||
#include <memory> | ||
#include "storage/storage_time.h" | ||
#include <glog/logging.h> | ||
|
||
namespace storage { | ||
|
||
std::unique_ptr<LogicTime> g_storage_logictime = std::make_unique<LogicTime>(); | ||
|
||
int64_t LogicTime::Now() { | ||
if (protection_mode_) { | ||
chejinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return logic_time_; | ||
} | ||
int64_t t; | ||
rocksdb::Env::Default()->GetCurrentTime(&t); | ||
return t; | ||
} | ||
Comment on lines
+14
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure thread safety when accessing Consider using atomic operations or mutexes to ensure thread safety for |
||
|
||
void LogicTime::UpdateLogicTime(int64_t time) { | ||
logic_time_ = time; | ||
} | ||
|
||
bool LogicTime::ProtectionMode() { | ||
return protection_mode_; | ||
} | ||
|
||
void LogicTime::SetProtectionMode(bool on) { | ||
protection_mode_ = on; | ||
LOG(INFO) << "Set protection mode to: " << on; | ||
} | ||
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
} // namespace storage | ||
|
There was a problem hiding this comment.
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.
Update the execution time from
binlog_str
before callingUpdateLogicTime
to ensure the logic time is updated with the correct value.Committable suggestion