Add LogInterface::get_file_paths method.
GitOrigin-RevId: 5cb749915b181b33250f56eb5d441d0c22c35800
This commit is contained in:
parent
b6f4249221
commit
5bf92283b6
@ -133,14 +133,18 @@ int64 StorageManager::get_db_size() {
|
||||
int64 size = 0;
|
||||
auto add_path = [&](CSlice path) {
|
||||
TRY_RESULT(info, stat(path));
|
||||
|
||||
LOG(DEBUG) << "Add database file \"" << path << "\" of size " << info.size_
|
||||
<< " to database storage size statistics";
|
||||
size += info.size_;
|
||||
|
||||
return Status::OK();
|
||||
};
|
||||
|
||||
G()->td_db()->with_db_path([&](CSlice path) { add_path(path).ignore(); });
|
||||
add_path(PSLICE() << G()->parameters().database_directory << "log").ignore();
|
||||
add_path(PSLICE() << G()->parameters().database_directory << "log.old").ignore();
|
||||
for (auto &log_path : log_interface->get_file_paths()) {
|
||||
add_path(log_path).ignore();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -369,6 +369,7 @@ static Status check_mtime(std::string &conversion, CSlice original_path) {
|
||||
auto r_stat = stat(original_path);
|
||||
uint64 actual_mtime = r_stat.is_ok() ? r_stat.ok().mtime_nsec_ : 0;
|
||||
if (expected_mtime == actual_mtime) {
|
||||
LOG(DEBUG) << "File \"" << original_path << "\" modification time " << actual_mtime << " matches";
|
||||
return Status::OK();
|
||||
}
|
||||
return Status::Error(PSLICE() << "FILE_GENERATE_LOCATION_INVALID: File \"" << original_path
|
||||
|
@ -22,6 +22,9 @@ Status FileLog::init(string path, int64 rotate_threshold) {
|
||||
set_rotate_threshold(rotate_threshold);
|
||||
return Status::OK();
|
||||
}
|
||||
if (path.empty()) {
|
||||
return Status::Error("Log file path can't be empty");
|
||||
}
|
||||
|
||||
TRY_RESULT(fd, FileFd::open(path, FileFd::Create | FileFd::Write | FileFd::Append));
|
||||
|
||||
@ -31,7 +34,12 @@ Status FileLog::init(string path, int64 rotate_threshold) {
|
||||
fd_.get_native_fd().duplicate(Stderr().get_native_fd()).ignore();
|
||||
}
|
||||
|
||||
auto r_path = realpath(path, true);
|
||||
if (r_path.is_error()) {
|
||||
path_ = std::move(path);
|
||||
} else {
|
||||
path_ = r_path.move_as_ok();
|
||||
}
|
||||
size_ = fd_.get_size();
|
||||
rotate_threshold_ = rotate_threshold;
|
||||
return Status::OK();
|
||||
@ -41,6 +49,15 @@ Slice FileLog::get_path() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
vector<string> FileLog::get_file_paths() {
|
||||
vector<string> result;
|
||||
if (!path_.empty()) {
|
||||
result.push_back(path_);
|
||||
result.push_back(PSTRING() << path_ << ".old");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void FileLog::set_rotate_threshold(int64 rotate_threshold) {
|
||||
rotate_threshold_ = rotate_threshold;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ class FileLog : public LogInterface {
|
||||
|
||||
Slice get_path() const;
|
||||
|
||||
vector<string> get_file_paths() override;
|
||||
|
||||
void set_rotate_threshold(int64 rotate_threshold);
|
||||
|
||||
int64 get_rotate_threshold() const;
|
||||
|
@ -158,6 +158,9 @@ class LogInterface {
|
||||
}
|
||||
virtual void rotate() {
|
||||
}
|
||||
virtual vector<string> get_file_paths() {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
class NullLog : public LogInterface {
|
||||
@ -288,6 +291,12 @@ class TsLog : public LogInterface {
|
||||
log_->rotate();
|
||||
exit_critical();
|
||||
}
|
||||
vector<string> get_file_paths() override {
|
||||
enter_critical();
|
||||
auto result = log_->get_file_paths();
|
||||
exit_critical();
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
LogInterface *log_ = nullptr;
|
||||
|
Reference in New Issue
Block a user