Skip to content

Commit

Permalink
fix:Revise the value check for max-rsync-parallel-num to prevent a co…
Browse files Browse the repository at this point in the history
…re dump when it is set to a value greater than 4 (OpenAtomFoundation#2595)

* revised value check of max-rsync-parallel-num to avoid core dump when it's value greater than 4

* avoid fixed num, use kMaxRsyncParallelNum instead

* use kMaxRsyncParallelNum to replace another two fixed num 4

---------

Co-authored-by: cjh <[email protected]>
  • Loading branch information
2 people authored and chenbt-hz committed Apr 15, 2024
1 parent 4072213 commit d0e4e3b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ default-slot-num : 1024

# Rsync Rate limiting configuration 200MB/s
throttle-bytes-per-second : 207200000

# The valid range for max-rsync-parallel-num is [1, 4].
# If an invalid value is provided, max-rsync-parallel-num will automatically be reset to 4.
max-rsync-parallel-num : 4

# The synchronization mode of Pika primary/secondary replication is determined by ReplicationID. ReplicationID in one replication_cluster are the same
Expand Down
2 changes: 1 addition & 1 deletion include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ class PikaConf : public pstd::BaseConf {

// Rsync Rate limiting configuration
int throttle_bytes_per_second_ = 207200000;
int max_rsync_parallel_num_ = 4;
int max_rsync_parallel_num_ = kMaxRsyncParallelNum;
};

#endif
2 changes: 1 addition & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,7 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
g_pika_conf->SetThrottleBytesPerSecond(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "max-rsync-parallel-num") {
if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival > kMaxRsyncParallelNum) {
if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival > kMaxRsyncParallelNum || ival <= 0) {
res_.AppendStringRaw( "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-rsync-parallel-num'\r\n");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ int PikaConf::Load() {
}

GetConfInt("max-rsync-parallel-num", &max_rsync_parallel_num_);
if (max_rsync_parallel_num_ <= 0) {
max_rsync_parallel_num_ = 4;
if (max_rsync_parallel_num_ <= 0 || max_rsync_parallel_num_ > kMaxRsyncParallelNum) {
max_rsync_parallel_num_ = kMaxRsyncParallelNum;
}

return ret;
Expand Down

0 comments on commit d0e4e3b

Please sign in to comment.