-
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: Add a layer of logic to check whether the hard disk is executed #1822
Changes from all commits
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include <ifaddrs.h> | ||
#include <netinet/in.h> | ||
#include <sys/resource.h> | ||
#include <sys/statvfs.h> | ||
#include <algorithm> | ||
#include <ctime> | ||
#include <fstream> | ||
|
@@ -1519,10 +1520,10 @@ void PikaServer::AutoKeepAliveRSync() { | |
} | ||
|
||
void PikaServer::AutoResumeDB() { | ||
struct statfs disk_info; | ||
int ret = statfs(g_pika_conf->db_path().c_str(), &disk_info); | ||
struct statvfs disk_info; | ||
int ret = statvfs(g_pika_conf->db_path().c_str(), &disk_info); | ||
if (ret == -1) { | ||
LOG(WARNING) << "statfs error: " << strerror(errno); | ||
LOG(WARNING) << "statvfs error: " << strerror(errno); | ||
return; | ||
} | ||
|
||
|
@@ -1536,7 +1537,7 @@ void PikaServer::AutoResumeDB() { | |
struct timeval now; | ||
gettimeofday(&now, nullptr); | ||
// first check or time interval between now and last check is larger than variable "interval" | ||
if (last_check_resume_time_.tv_sec == 0 || now.tv_sec - last_check_resume_time_.tv_sec >= interval) { | ||
if (disk_use_ratio > min_check_resume_ratio && (last_check_resume_time_.tv_sec == 0 || now.tv_sec - last_check_resume_time_.tv_sec >= interval)) { | ||
gettimeofday(&last_check_resume_time_, nullptr); | ||
if (disk_use_ratio < min_check_resume_ratio || free_size < least_free_size){ | ||
return; | ||
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. The provided code patch seems to be a part of a larger codebase, so I can only review the specific changes you've shared. In terms of code review, here are some observations and suggestions for improvement:
Without additional context and the full codebase, it is difficult to assess the presence of bugs or potential risks. It is always a good practice to carefully test the changes in different scenarios and analyze edge cases before deploying them to production. Remember, code reviews are best done by individuals who are familiar with the codebase and its requirements in detail. 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. From the code patch you provided, here are some observations and suggestions for improvement:
Overall, the code changes appear to be reasonable, but to provide a more accurate and comprehensive review, it would be helpful to have a larger context of the codebase and its requirements. 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. The code looks fine overall, but there are a few suggestions for improvement:
Other than these suggestions, it's challenging to identify any potential bugs or risks without more context or knowledge about the rest of the codebase. |
||
|
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.
The code patch you provided seems to be a modification in the
PikaServer::AutoResumeDB()
function. The changes involve an additional condition in theif
statement.Here's the summary of the code changes:
if
statement:disk_use_ratio > min_check_resume_ratio
.last_check_resume_time_.tv_sec == 0 || now.tv_sec - last_check_resume_time_.tv_sec >= interval
remains unchanged.if
block will execute; otherwise, it will return early from the function.Code review:
The modified code appears to be checking the disk usage ratio before performing automatic resumption of the database. This suggests that the database resumption is now dependent on both the time interval and the disk usage ratio being above a certain threshold (
min_check_resume_ratio
).It is difficult to provide specific bug risks or improvement suggestions without understanding the larger context of the code and the purpose of this function. However, here are a few general suggestions:
disk_use_ratio
,min_check_resume_ratio
,interval
,free_size
, andleast_free_size
are properly defined and initialized before this code section.min_check_resume_ratio
is reasonable and appropriate for your application's requirements.Remember to review the complete codebase thoroughly, including how these changes interact with other parts of the program, to identify any potential issues or further areas of improvement.