Describe memory cleanup errors

This commit is contained in:
Andrea Cavalli 2021-03-13 11:58:58 +01:00
parent 3e53ba98d3
commit 2bcb81bec0
2 changed files with 19 additions and 2 deletions

View File

@ -88,6 +88,13 @@ bool MemoryManager::can_manage_memory() const {
if (!(td_->auth_manager_->is_authorized() && !G()->close_flag())) { if (!(td_->auth_manager_->is_authorized() && !G()->close_flag())) {
return false; return false;
} }
if (!do_session_settings_allow_for_memory_management()) {
return false;
}
return true;
}
bool MemoryManager::do_session_settings_allow_for_memory_management() {
if (G()->parameters().use_message_db || G()->parameters().use_chat_info_db || G()->parameters().use_file_db) { if (G()->parameters().use_message_db || G()->parameters().use_chat_info_db || G()->parameters().use_file_db) {
return false; return false;
} }
@ -96,7 +103,9 @@ bool MemoryManager::can_manage_memory() const {
void MemoryManager::get_memory_stats(bool full, Promise<MemoryStats> promise) const { void MemoryManager::get_memory_stats(bool full, Promise<MemoryStats> promise) const {
if (!can_manage_memory()) { if (!can_manage_memory()) {
promise.set_error(Status::Error(500, "Request aborted")); auto value = MemoryStats("{}");
promise.set_value(std::move(value));
return; return;
} }
@ -202,7 +211,13 @@ void MemoryManager::get_memory_stats(bool full, Promise<MemoryStats> promise) co
void MemoryManager::clean_memory(bool full, Promise<Unit> promise) const { void MemoryManager::clean_memory(bool full, Promise<Unit> promise) const {
if (!can_manage_memory()) { if (!can_manage_memory()) {
promise.set_error(Status::Error(500, "Request aborted")); if (!do_session_settings_allow_for_memory_management()) {
promise.set_error(Status::Error(405, "MEMORY_STATS_DISALLOWED"
" Session settings don't allow memory optimization."
" If you want to optimize memory, you should completely disable all databases."));
} else {
promise.set_error(Status::Error(405, "Can't manage memory now"));
}
return; return;
} }

View File

@ -50,6 +50,8 @@ class MemoryManager : public Actor {
bool can_manage_memory() const; bool can_manage_memory() const;
static bool do_session_settings_allow_for_memory_management();
void get_memory_stats(bool full, Promise<MemoryStats> promise) const; void get_memory_stats(bool full, Promise<MemoryStats> promise) const;
void clean_memory(bool full, Promise<Unit> promise) const; void clean_memory(bool full, Promise<Unit> promise) const;