From 09cbd0a51d5e6713f652bbe956f55b652b4cd1f9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 2 Nov 2016 01:01:27 -0400 Subject: [PATCH] remove deprecated disk_io_thread operations (#1284) --- include/libtorrent/disk_interface.hpp | 7 - include/libtorrent/disk_io_job.hpp | 4 - include/libtorrent/disk_io_thread.hpp | 11 -- include/libtorrent/performance_counters.hpp | 1 - include/libtorrent/storage.hpp | 18 --- src/block_cache.cpp | 4 - src/disk_io_thread.cpp | 138 -------------------- src/session_stats.cpp | 1 - src/storage.cpp | 4 - test/test_block_cache.cpp | 3 - tools/parse_disk_log.py | 2 +- 11 files changed, 1 insertion(+), 192 deletions(-) diff --git a/include/libtorrent/disk_interface.hpp b/include/libtorrent/disk_interface.hpp index 427fd9b7b..c6e09d52d 100644 --- a/include/libtorrent/disk_interface.hpp +++ b/include/libtorrent/disk_interface.hpp @@ -67,13 +67,6 @@ namespace libtorrent , add_torrent_params const* resume_data , std::vector& links , std::function handler) = 0; -#ifndef TORRENT_NO_DEPRECATE - virtual void async_cache_piece(piece_manager* storage, int piece - , std::function handler) = 0; - virtual void async_finalize_file(piece_manager*, int file - , std::function handler - = std::function()) = 0; -#endif virtual void async_flush_piece(piece_manager* storage, int piece , std::function handler = std::function()) = 0; diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index 6cb87ff5e..9aa7dae9b 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -86,10 +86,6 @@ namespace libtorrent , check_fastresume , rename_file , stop_torrent -#ifndef TORRENT_NO_DEPRECATE - , cache_piece - , finalize_file -#endif , flush_piece , flush_hashed , flush_storage diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index dfdc84514..af229c7f5 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -311,13 +311,6 @@ namespace libtorrent , std::function handler) override; void async_stop_torrent(piece_manager* storage , std::function handler) override; -#ifndef TORRENT_NO_DEPRECATE - void async_cache_piece(piece_manager* storage, int piece - , std::function handler) override; - void async_finalize_file(piece_manager* storage, int file - , std::function handler - = std::function()) override; -#endif void async_flush_piece(piece_manager* storage, int piece , std::function handler = std::function()) override; @@ -402,10 +395,6 @@ namespace libtorrent int do_rename_file(disk_io_job* j, jobqueue_t& completed_jobs); int do_stop_torrent(disk_io_job* j, jobqueue_t& completed_jobs); int do_read_and_hash(disk_io_job* j, jobqueue_t& completed_jobs); -#ifndef TORRENT_NO_DEPRECATE - int do_cache_piece(disk_io_job* j, jobqueue_t& completed_jobs); - int do_finalize_file(disk_io_job* j, jobqueue_t& completed_jobs); -#endif int do_flush_piece(disk_io_job* j, jobqueue_t& completed_jobs); int do_flush_hashed(disk_io_job* j, jobqueue_t& completed_jobs); int do_flush_storage(disk_io_job* j, jobqueue_t& completed_jobs); diff --git a/include/libtorrent/performance_counters.hpp b/include/libtorrent/performance_counters.hpp index 152dd5ba9..aca8cbc55 100644 --- a/include/libtorrent/performance_counters.hpp +++ b/include/libtorrent/performance_counters.hpp @@ -384,7 +384,6 @@ namespace libtorrent num_fenced_save_resume_data, num_fenced_rename_file, num_fenced_stop_torrent, - num_fenced_cache_piece, num_fenced_flush_piece, num_fenced_flush_hashed, num_fenced_flush_storage, diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index a56d61796..aece68ca8 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -338,21 +338,6 @@ namespace libtorrent // virtual void delete_files(int options, storage_error& ec) = 0; -#ifndef TORRENT_NO_DEPRECATE - // This function is called each time a file is completely downloaded. The - // storage implementation can perform last operations on a file. The file - // will not be opened for writing after this. - // - // ``index`` is the index of the file that completed. - // - // On windows the default storage implementation clears the sparse file - // flag on the specified file. - // - // If an error occurs, ``storage_error`` should be set to reflect it. - // - virtual void finalize_file(int, storage_error&) {} -#endif - // called periodically (useful for deferred flushing). When returning // false, it means no more ticks are necessary. Any disk job submitted // will re-enable ticking. The default will always turn ticking back @@ -393,9 +378,6 @@ namespace libtorrent // hidden ~default_storage(); -#ifndef TORRENT_NO_DEPRECATE - void finalize_file(int file, storage_error& ec) override; -#endif virtual bool has_any_file(storage_error& ec) override; virtual void set_file_priority(std::vector const& prio , storage_error& ec) override; diff --git a/src/block_cache.cpp b/src/block_cache.cpp index d1d9fdd1e..5634fa42c 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -195,10 +195,6 @@ const char* const job_action_name[] = "check_fastresume", "rename_file", "stop_torrent", -#ifndef TORRENT_NO_DEPRECATE - "cache_piece", - "finalize_file", -#endif "flush_piece", "flush_hashed", "flush_storage", diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index b8243ee98..36017d562 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1023,10 +1023,6 @@ namespace libtorrent &disk_io_thread::do_check_fastresume, &disk_io_thread::do_rename_file, &disk_io_thread::do_stop_torrent, -#ifndef TORRENT_NO_DEPRECATE - &disk_io_thread::do_cache_piece, - &disk_io_thread::do_finalize_file, -#endif &disk_io_thread::do_flush_piece, &disk_io_thread::do_flush_hashed, &disk_io_thread::do_flush_storage, @@ -1905,30 +1901,6 @@ namespace libtorrent add_completed_jobs(completed_jobs); } -#ifndef TORRENT_NO_DEPRECATE - void disk_io_thread::async_cache_piece(piece_manager* storage, int piece - , std::function handler) - { - disk_io_job* j = allocate_job(disk_io_job::cache_piece); - j->storage = storage->shared_from_this(); - j->piece = piece; - j->callback = std::move(handler); - - add_job(j); - } - - void disk_io_thread::async_finalize_file(piece_manager* storage, int file - , std::function handler) - { - disk_io_job* j = allocate_job(disk_io_job::finalize_file); - j->storage = storage->shared_from_this(); - j->piece = file; - j->callback = std::move(handler); - - add_job(j); - } -#endif // TORRENT_NO_DEPRECATE - void disk_io_thread::async_flush_piece(piece_manager* storage, int piece , std::function handler) { @@ -2528,116 +2500,6 @@ namespace libtorrent return j->error ? -1 : 0; } -#ifndef TORRENT_NO_DEPRECATE - int disk_io_thread::do_cache_piece(disk_io_job* j, jobqueue_t& /* completed_jobs */ ) - { - INVARIANT_CHECK; - TORRENT_ASSERT(j->buffer.disk_block == nullptr); - - if (m_settings.get_int(settings_pack::cache_size) == 0 - || m_settings.get_bool(settings_pack::use_read_cache) == false) - return 0; - - int const file_flags = file_flags_for_job(j - , m_settings.get_bool(settings_pack::coalesce_reads)); - - std::unique_lock l(m_cache_mutex); - - cached_piece_entry* pe = m_disk_cache.find_piece(j); - if (pe == nullptr) - { - int cache_state = (j->flags & disk_io_job::volatile_read) - ? cached_piece_entry::volatile_read_lru - : cached_piece_entry::read_lru1; - pe = m_disk_cache.allocate_piece(j, cache_state); - } - if (pe == nullptr) - { - j->error.ec = error::no_memory; - j->error.operation = storage_error::alloc_cache_piece; - return -1; - } - -#if TORRENT_USE_ASSERTS - pe->piece_log.push_back(piece_log_t(j->action)); -#endif - TORRENT_PIECE_ASSERT(pe->cache_state <= cached_piece_entry::read_lru1 - || pe->cache_state == cached_piece_entry::read_lru2, pe); - - piece_refcount_holder refcount_holder(pe); - - int block_size = m_disk_cache.block_size(); - int piece_size = j->storage->files()->piece_size(j->piece); - int blocks_in_piece = (piece_size + block_size - 1) / block_size; - - file::iovec_t iov; - int ret = 0; - int offset = 0; - - // TODO: it would be nice to not have to lock the std::mutex every - // turn through this loop - for (int i = 0; i < blocks_in_piece; ++i) - { - iov.iov_len = (std::min)(block_size, piece_size - offset); - - // is the block already in the cache? - if (pe->blocks[i].buf) continue; - l.unlock(); - - iov.iov_base = m_disk_cache.allocate_buffer("read cache"); - - if (iov.iov_base == nullptr) - { - refcount_holder.release(); - m_disk_cache.maybe_free_piece(pe); - j->error.ec = errors::no_memory; - j->error.operation = storage_error::alloc_cache_piece; - return -1; - } - - DLOG("do_cache_piece: reading (piece: %d block: %d)\n" - , int(pe->piece), i); - - time_point start_time = clock_type::now(); - - ret = j->storage->get_storage_impl()->readv(iov, j->piece - , offset, file_flags, j->error); - - if (ret < 0) - { - l.lock(); - break; - } - - if (!j->error.ec) - { - std::uint32_t read_time = total_microseconds(clock_type::now() - start_time); - m_read_time.add_sample(read_time); - - m_stats_counters.inc_stats_counter(counters::num_blocks_read); - m_stats_counters.inc_stats_counter(counters::num_read_ops); - m_stats_counters.inc_stats_counter(counters::disk_read_time, read_time); - m_stats_counters.inc_stats_counter(counters::disk_job_time, read_time); - } - - offset += block_size; - - l.lock(); - m_disk_cache.insert_blocks(pe, i, iov, j); - } - - refcount_holder.release(); - m_disk_cache.maybe_free_piece(pe); - return 0; - } - - int disk_io_thread::do_finalize_file(disk_io_job* j, jobqueue_t& /* completed_jobs */) - { - j->storage->get_storage_impl()->finalize_file(j->piece, j->error); - return j->error ? -1 : 0; - } -#endif // TORRENT_NO_DEPRECATE - namespace { void get_cache_info_impl(cached_piece_info& info, cached_piece_entry const* i diff --git a/src/session_stats.cpp b/src/session_stats.cpp index 414dcd60d..5252204cd 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -384,7 +384,6 @@ namespace libtorrent METRIC(disk, num_fenced_save_resume_data) METRIC(disk, num_fenced_rename_file) METRIC(disk, num_fenced_stop_torrent) - METRIC(disk, num_fenced_cache_piece) METRIC(disk, num_fenced_flush_piece) METRIC(disk, num_fenced_flush_hashed) METRIC(disk, num_fenced_flush_storage) diff --git a/src/storage.cpp b/src/storage.cpp index 928e187f2..1dff77f6c 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -592,10 +592,6 @@ namespace libtorrent #endif } -#ifndef TORRENT_NO_DEPRECATE - void default_storage::finalize_file(int, storage_error&) {} -#endif - bool default_storage::has_any_file(storage_error& ec) { m_stat_cache.reserve(files().num_files()); diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index bbae11c95..963173665 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -71,9 +71,6 @@ struct test_storage_impl : storage_interface void rename_file(int index, std::string const& new_filename , storage_error& ec) override {} void delete_files(int, storage_error& ec) override {} -#ifndef TORRENT_NO_DEPRECATE - void finalize_file(int, storage_error&) override {} -#endif }; static void nop() {} diff --git a/tools/parse_disk_log.py b/tools/parse_disk_log.py index f0987467c..b122c5752 100755 --- a/tools/parse_disk_log.py +++ b/tools/parse_disk_log.py @@ -14,7 +14,7 @@ if len(sys.argv) < 2: keys = ['write', 'read', 'read-cache-hit', 'hash', 'move', 'release', 'idle', \ 'delete', 'check_fastresume', 'check_files', 'clear-cache', \ 'abort_thread', 'abort_torrent', 'save_resume_data', 'rename_file', \ - 'flushing', 'update_settings', 'finalize_file', 'sorting_job', \ + 'flushing', 'update_settings', 'sorting_job', \ 'check_cache_hit'] throughput_keys = ['write', 'read', 'read-cache-hit']