mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-19 15:46:17 +00:00
Cleaned up changes to session manager.
This commit is contained in:
+3
-2
@@ -139,10 +139,11 @@ Control::handle_shutdown() {
|
|||||||
scgi_thread::thread()->stop_thread_wait();
|
scgi_thread::thread()->stop_thread_wait();
|
||||||
|
|
||||||
if (!m_shutdown_session_saved) {
|
if (!m_shutdown_session_saved) {
|
||||||
// Flush the latest state before stopped announces can consume the timeout.
|
// Flush the latest state before stopped announces can consume the timeout. A shutdown hook may
|
||||||
// A shutdown hook may already have queued these resume builds.
|
// already have queued these resume builds.
|
||||||
m_core->download_list()->session_save();
|
m_core->download_list()->session_save();
|
||||||
session_thread::manager()->flush_shutdown_saves();
|
session_thread::manager()->flush_shutdown_saves();
|
||||||
|
|
||||||
m_shutdown_session_saved = true;
|
m_shutdown_session_saved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -112,9 +112,10 @@ private:
|
|||||||
|
|
||||||
int m_clear_requests_count{};
|
int m_clear_requests_count{};
|
||||||
|
|
||||||
|
bool m_shutdown_session_saved{};
|
||||||
|
|
||||||
align_cacheline
|
align_cacheline
|
||||||
|
|
||||||
bool m_shutdown_session_saved{};
|
|
||||||
std::atomic<bool> m_shutdown_received{};
|
std::atomic<bool> m_shutdown_received{};
|
||||||
std::atomic<bool> m_shutdown_quick{};
|
std::atomic<bool> m_shutdown_quick{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -413,26 +413,26 @@ SessionManager::process_finished_saves() {
|
|||||||
callback_save_request();
|
callback_save_request();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage errors share a five-minute log limit and count what they suppress.
|
// Returns true when a storage error was suppressed.
|
||||||
// Returns true when this one was suppressed. Callers hold m_mutex.
|
|
||||||
bool
|
bool
|
||||||
SessionManager::report_storage_error_unsafe(const std::string& what) {
|
SessionManager::report_storage_error_unsafe(const std::string& msg) {
|
||||||
if (m_last_storage_error_message + std::chrono::minutes(5) > torrent::this_thread::cached_time()) {
|
if (m_last_storage_error_message + std::chrono::minutes(5) > torrent::this_thread::cached_time()) {
|
||||||
m_ignored_storage_error_count++;
|
m_ignored_storage_error_count++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
lt_log_print(torrent::LOG_ERRORS, "Storage errors saving session data for download: ignored:%u : %s", m_ignored_storage_error_count, what.c_str());
|
lt_log_print(torrent::LOG_ERRORS, "Storage errors saving session data for download: ignored:%u : %s", m_ignored_storage_error_count, msg.c_str());
|
||||||
|
|
||||||
m_last_storage_error_message = torrent::this_thread::cached_time();
|
m_last_storage_error_message = torrent::this_thread::cached_time();
|
||||||
m_ignored_storage_error_count = 0;
|
m_ignored_storage_error_count = 0;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The one policy for a finished save, on the session thread and in shutdown
|
// The one policy for a finished save, on the session thread and in shutdown flushes: storage errors
|
||||||
// flushes: storage errors go to report_storage_error_unsafe(), internal and
|
// go to report_storage_error_unsafe(), internal and unknown errors propagate.
|
||||||
// unknown errors propagate. Callers hold m_mutex. Returns true when a storage
|
//
|
||||||
// error was suppressed.
|
// Returns true when a storage error was suppressed.
|
||||||
bool
|
bool
|
||||||
SessionManager::consume_finished_save_unsafe(ProcessingSave& request) {
|
SessionManager::consume_finished_save_unsafe(ProcessingSave& request) {
|
||||||
try {
|
try {
|
||||||
@@ -458,8 +458,11 @@ SessionManager::consume_finished_save_unsafe(ProcessingSave& request) {
|
|||||||
void
|
void
|
||||||
SessionManager::flush_shutdown_saves() {
|
SessionManager::flush_shutdown_saves() {
|
||||||
assert(torrent::this_thread::thread() == torrent::main_thread::thread());
|
assert(torrent::this_thread::thread() == torrent::main_thread::thread());
|
||||||
|
|
||||||
flush_all_pending_builds();
|
flush_all_pending_builds();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
flush_all_and_wait_unsafe(lock);
|
flush_all_and_wait_unsafe(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,16 +485,16 @@ SessionManager::flush_all_and_wait_unsafe(std::unique_lock<std::mutex>& lock) {
|
|||||||
m_finished_condition.wait(lock);
|
m_finished_condition.wait(lock);
|
||||||
|
|
||||||
unsigned int suppressed = 0;
|
unsigned int suppressed = 0;
|
||||||
|
|
||||||
for (auto& request : m_finished_saves)
|
for (auto& request : m_finished_saves)
|
||||||
suppressed += consume_finished_save_unsafe(request) ? 1 : 0;
|
suppressed += consume_finished_save_unsafe(request) ? 1 : 0;
|
||||||
|
|
||||||
m_finished_saves.clear();
|
m_finished_saves.clear();
|
||||||
|
|
||||||
// Report and reset here; a later session-thread pass would otherwise fold
|
|
||||||
// these into its own count. Name the two counts apart.
|
|
||||||
if (m_ignored_storage_error_count != 0) {
|
if (m_ignored_storage_error_count != 0) {
|
||||||
lt_log_print(torrent::LOG_ERRORS, "Storage errors flushing session data: ignored:%u, earlier ignored:%u",
|
lt_log_print(torrent::LOG_ERRORS, "Storage errors flushing session data: ignored:%u previous:%u",
|
||||||
suppressed, m_ignored_storage_error_count - suppressed);
|
suppressed, m_ignored_storage_error_count - suppressed);
|
||||||
|
|
||||||
m_ignored_storage_error_count = 0;
|
m_ignored_storage_error_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ protected:
|
|||||||
void flush_shutdown_saves();
|
void flush_shutdown_saves();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void callback_pending_builds();
|
void callback_pending_builds();
|
||||||
void callback_save_request();
|
void callback_save_request();
|
||||||
void callback_finished_saves();
|
void callback_finished_saves();
|
||||||
@@ -94,7 +95,7 @@ private:
|
|||||||
using ProcessingSave = std::pair<std::future<void>, SaveRequest>;
|
using ProcessingSave = std::pair<std::future<void>, SaveRequest>;
|
||||||
|
|
||||||
bool consume_finished_save_unsafe(ProcessingSave& request);
|
bool consume_finished_save_unsafe(ProcessingSave& request);
|
||||||
bool report_storage_error_unsafe(const std::string& what);
|
bool report_storage_error_unsafe(const std::string& msg);
|
||||||
|
|
||||||
torrent::system::Thread* m_thread;
|
torrent::system::Thread* m_thread;
|
||||||
torrent::system::callback_id m_callback_id;
|
torrent::system::callback_id m_callback_id;
|
||||||
|
|||||||
Reference in New Issue
Block a user