From 042ce41c9a6929e73cd63a591905c237222687bf Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 00:17:14 +0800 Subject: [PATCH 1/7] refactor(storage): move temporary spill files to Rust --- Cargo.lock | 10 + MODULE.bazel.lock | 7 +- rust/modules.bzl | 1 + rust/seekdb-rust/BUILD.bazel | 1 + rust/seekdb-rust/Cargo.toml | 1 + rust/seekdb-rust/src/lib.rs | 1 + rust/tmp-file/BUILD.bazel | 25 + rust/tmp-file/Cargo.toml | 10 + rust/tmp-file/src/bridge.rs | 382 +++ rust/tmp-file/src/lib.rs | 908 +++++ rust/tmp-file/src/tests.rs | 447 +++ .../api/data_plane/tmp_file/ob_tmp_file.h | 13 +- src/observer/ob_server.cpp | 39 +- src/observer/ob_server_reload_config.cpp | 4 + src/observer/ob_service.cpp | 8 + .../omt/ob_server_runtime_controller.cpp | 5 +- ..._all_virtual_macro_block_marker_status.cpp | 2 +- .../virtual_table/ob_all_virtual_tmp_file.cpp | 291 +- .../virtual_table/ob_all_virtual_tmp_file.h | 16 +- src/sql/engine/basic/ob_chunk_datum_store.cpp | 2 +- src/sql/engine/basic/ob_chunk_row_store.cpp | 2 +- src/sql/engine/basic/ob_temp_block_store.cpp | 17 +- src/sql/engine/basic/ob_temp_block_store.h | 10 +- src/storage/BUILD.bazel | 1 + .../index_block/ob_macro_meta_temp_store.cpp | 14 +- .../index_block/ob_macro_meta_temp_store.h | 8 +- src/storage/blocksstable/ob_block_manager.cpp | 37 - src/storage/blocksstable/ob_block_manager.h | 8 - .../blocksstable/ob_block_sstable_struct.cpp | 2 - .../blocksstable/ob_block_sstable_struct.h | 2 - src/storage/ob_disk_usage_reporter.cpp | 2 +- src/storage/ob_parallel_external_sort.h | 23 +- src/storage/storage_header_inventory.bzl | 22 +- src/storage/storage_source_inventory.bzl | 22 +- .../tmp_file/ob_shared_nothing_tmp_file.cpp | 2045 ----------- .../tmp_file/ob_shared_nothing_tmp_file.h | 480 --- .../tmp_file/ob_tmp_file_block_manager.cpp | 821 ----- .../tmp_file/ob_tmp_file_block_manager.h | 223 -- src/storage/tmp_file/ob_tmp_file_cache.cpp | 745 ---- src/storage/tmp_file/ob_tmp_file_cache.h | 323 -- .../tmp_file/ob_tmp_file_eviction_manager.cpp | 198 -- .../tmp_file/ob_tmp_file_eviction_manager.h | 60 - .../tmp_file/ob_tmp_file_flush_ctx.cpp | 456 --- src/storage/tmp_file/ob_tmp_file_flush_ctx.h | 363 -- .../ob_tmp_file_flush_list_iterator.cpp | 717 ---- .../ob_tmp_file_flush_list_iterator.h | 111 - .../tmp_file/ob_tmp_file_flush_manager.cpp | 1107 ------ .../tmp_file/ob_tmp_file_flush_manager.h | 145 - .../ob_tmp_file_flush_priority_manager.cpp | 375 -- .../ob_tmp_file_flush_priority_manager.h | 82 - src/storage/tmp_file/ob_tmp_file_global.cpp | 37 - src/storage/tmp_file/ob_tmp_file_global.h | 83 - src/storage/tmp_file/ob_tmp_file_io.cpp | 1017 ------ src/storage/tmp_file/ob_tmp_file_io_ctx.cpp | 487 --- src/storage/tmp_file/ob_tmp_file_io_ctx.h | 265 -- .../tmp_file/ob_tmp_file_io_handle.cpp | 195 -- src/storage/tmp_file/ob_tmp_file_io_handle.h | 69 - src/storage/tmp_file/ob_tmp_file_io_info.cpp | 61 - src/storage/tmp_file/ob_tmp_file_io_info.h | 49 - src/storage/tmp_file/ob_tmp_file_manager.cpp | 886 ----- src/storage/tmp_file/ob_tmp_file_manager.h | 113 - .../tmp_file/ob_tmp_file_meta_tree.cpp | 3030 ----------------- src/storage/tmp_file/ob_tmp_file_meta_tree.h | 551 --- .../ob_tmp_file_page_cache_controller.cpp | 181 - .../ob_tmp_file_page_cache_controller.h | 87 - .../tmp_file/ob_tmp_file_thread_job.cpp | 197 -- src/storage/tmp_file/ob_tmp_file_thread_job.h | 118 - .../tmp_file/ob_tmp_file_thread_wrapper.cpp | 1210 ------- .../tmp_file/ob_tmp_file_thread_wrapper.h | 178 - src/storage/tmp_file/ob_tmp_file_types.h | 197 -- .../ob_tmp_file_write_buffer_index_cache.cpp | 688 ---- .../ob_tmp_file_write_buffer_index_cache.h | 154 - .../ob_tmp_file_write_buffer_pool.cpp | 1419 -------- .../tmp_file/ob_tmp_file_write_buffer_pool.h | 274 -- ...tmp_file_write_buffer_pool_entry_array.cpp | 165 - ...b_tmp_file_write_buffer_pool_entry_array.h | 183 - src/storage/tmp_file/tmp_file_service.cpp | 371 ++ src/storage/tmp_file/tmp_file_service.h | 65 + tests/mysqltest/cases/r/tmp_file_spill.result | 7 + tests/mysqltest/cases/t/tmp_file_spill.test | 31 + 80 files changed, 2376 insertions(+), 20586 deletions(-) create mode 100644 rust/tmp-file/BUILD.bazel create mode 100644 rust/tmp-file/Cargo.toml create mode 100644 rust/tmp-file/src/bridge.rs create mode 100644 rust/tmp-file/src/lib.rs create mode 100644 rust/tmp-file/src/tests.rs delete mode 100644 src/storage/tmp_file/ob_shared_nothing_tmp_file.cpp delete mode 100644 src/storage/tmp_file/ob_shared_nothing_tmp_file.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_block_manager.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_block_manager.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_cache.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_cache.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_eviction_manager.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_eviction_manager.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_ctx.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_ctx.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_list_iterator.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_list_iterator.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_manager.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_manager.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_priority_manager.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_flush_priority_manager.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_global.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_global.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_io.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_io_ctx.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_io_ctx.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_io_handle.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_io_handle.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_io_info.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_io_info.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_manager.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_manager.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_meta_tree.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_meta_tree.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_page_cache_controller.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_page_cache_controller.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_thread_job.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_thread_job.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_thread_wrapper.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_thread_wrapper.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_types.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_write_buffer_pool.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_write_buffer_pool.h delete mode 100644 src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.cpp delete mode 100644 src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h create mode 100644 src/storage/tmp_file/tmp_file_service.cpp create mode 100644 src/storage/tmp_file/tmp_file_service.h create mode 100644 tests/mysqltest/cases/r/tmp_file_spill.result create mode 100644 tests/mysqltest/cases/t/tmp_file_spill.test diff --git a/Cargo.lock b/Cargo.lock index e515457ca4..1bd62ed858 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1667,6 +1667,7 @@ dependencies = [ "sql-parser", "standby-rpc", "storage-io", + "tmp-file", "uuid-generator", "vector-kernels", "wal", @@ -2078,6 +2079,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tmp-file" +version = "0.1.0" +dependencies = [ + "cxx", + "file-io", + "tokio", +] + [[package]] name = "tokio" version = "1.52.3" diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 1260579b1d..761a3708c3 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -509,11 +509,11 @@ "REPO_MAPPING:rules_rust+,bazel_tools bazel_tools", "REPO_MAPPING:rules_rust+,rules_cc rules_cc+", "REPO_MAPPING:rules_rust+,rules_rust rules_rust+", - "FILE:@@//Cargo.lock fc34f23ad84a865457f5ce47a73699a63bd544d46681e9e2cdce1c140003f227", + "FILE:@@//Cargo.lock c6a14b8f8773442091f01d71b515b7d5298b70c87033a0bcb0b4e9a1693eb656", "FILE:@@//bazel/rust_cargo_config.toml ff15707954031fbc938be84c1024f7cbc7a4e5d6aae92de8cfa3c5365477910f", "FILE:@@//Cargo.toml 7a7487f94a57ddc6e9f6a2affd0902a2d821b1746a4bbc1583afc5b791dcef6a", "FILE:@@//bazel/cxx_runtime.BUILD.bazel 5fb17c151863631008e8e309b48bb19d4877db1efaf3ff6ff81c249467c03123", - "FILE:@@//rust/seekdb-rust/Cargo.toml 22aba19c857c4ef56262b798bda4f0de0c06592d866984e12f791eb76f9b3376", + "FILE:@@//rust/seekdb-rust/Cargo.toml 6fc8556e6dc8a25b1e7c598e434881b3c9ac48ed64a9129e4c41f3cbf55cc1b0", "FILE:@@//rust/compression/Cargo.toml a7882629dd72892c90eeddc8a343654c46c0b66a25fd905c3f5387ed6001d367", "FILE:@@//rust/config/Cargo.toml 47f11c6f488733e4dcbef6422b17d6105d8d8033106ed7295db1c87fe9f3d608", "FILE:@@//rust/kv/Cargo.toml 5809208ef82926506725474b1922ad70b04ed73e193fbca801a5232864e657ef", @@ -531,6 +531,7 @@ "FILE:@@//rust/sql-nio/Cargo.toml f98d086e2d91a415e634d687d1bf8c966f8e05c03bc13540cbfff9013cca9097", "FILE:@@//rust/sql-parser/Cargo.toml dccab06a8046f4114db170517acd663c51870692996fa57dc16a79f6377cbe98", "FILE:@@//rust/storage-io/Cargo.toml fce0dd3eca429ee1f2b179606d40b0ca6fe5c123fa6274f5b96a3461040e94cf", + "FILE:@@//rust/tmp-file/Cargo.toml ce421aae7fc6bee8aea13995ef023455a74acc205f0b04c1b8e36c052a7465a0", "FILE:@@//rust/uuid-generator/Cargo.toml 103e0399d33b028e5dd74b556be6c6c2efb954113468b5a06556f01402e58f6b", "FILE:@@//rust/wal/Cargo.toml 9d11a16d127014391e008fb45a0cc39789a2f5f905bbcb9d73d4e4f0acaeeb45", "FILE:@@//rust/xml-parser/Cargo.toml 4f07ad6e1f8b39e358f0b374435a167779fd39048d40aaf9598c8a4ce71fcd13", @@ -550,7 +551,7 @@ "contents": { "BUILD.bazel": "###############################################################################\n# @generated\n# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To \n# regenerate this file, run the following:\n#\n# bazel mod show_repo 'seekdb'\n###############################################################################\n\npackage(default_visibility = [\"//visibility:public\"])\n\nexports_files(\n [\n \"cargo-bazel.json\",\n \"crates.bzl\",\n \"defs.bzl\",\n ] + glob(\n allow_empty = True,\n include = [\"*.bazel\"],\n ),\n)\n\nfilegroup(\n name = \"srcs\",\n srcs = glob(\n allow_empty = True,\n include = [\n \"*.bazel\",\n \"*.bzl\",\n ],\n ),\n)\n\n# Workspace Member Dependencies\nalias(\n name = \"chrono-0.4.45\",\n actual = \"@rust_crates__chrono-0.4.45//:chrono\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"chrono\",\n actual = \"@rust_crates__chrono-0.4.45//:chrono\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"cxx-1.0.202\",\n actual = \"@rust_crates__cxx-1.0.202//:cxx\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"cxx\",\n actual = \"@rust_crates__cxx-1.0.202//:cxx\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"cxx_cc\",\n actual = \"@rust_crates__cxx-1.0.202//:cxx_cc\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"fancy-regex-0.20.0\",\n actual = \"@rust_crates__fancy-regex-0.20.0//:fancy_regex\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"fancy-regex\",\n actual = \"@rust_crates__fancy-regex-0.20.0//:fancy_regex\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"fast-float2-0.2.4\",\n actual = \"@rust_crates__fast-float2-0.2.4//:fast_float2\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"fast-float2\",\n actual = \"@rust_crates__fast-float2-0.2.4//:fast_float2\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"getrandom-0.4.3\",\n actual = \"@rust_crates__getrandom-0.4.3//:getrandom\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"getrandom\",\n actual = \"@rust_crates__getrandom-0.4.3//:getrandom\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"globset-0.4.18\",\n actual = \"@rust_crates__globset-0.4.18//:globset\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"globset\",\n actual = \"@rust_crates__globset-0.4.18//:globset\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"libc-0.2.189\",\n actual = \"@rust_crates__libc-0.2.189//:libc\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"libc\",\n actual = \"@rust_crates__libc-0.2.189//:libc\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"libm-0.2.16\",\n actual = \"@rust_crates__libm-0.2.16//:libm\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"libm\",\n actual = \"@rust_crates__libm-0.2.16//:libm\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"log-0.4.34\",\n actual = \"@rust_crates__log-0.4.34//:log\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"log\",\n actual = \"@rust_crates__log-0.4.34//:log\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"memchr-2.8.3\",\n actual = \"@rust_crates__memchr-2.8.3//:memchr\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"memchr\",\n actual = \"@rust_crates__memchr-2.8.3//:memchr\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"mio-1.2.3\",\n actual = \"@rust_crates__mio-1.2.3//:mio\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"mio\",\n actual = \"@rust_crates__mio-1.2.3//:mio\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"peg-0.8.6\",\n actual = \"@rust_crates__peg-0.8.6//:peg\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"peg\",\n actual = \"@rust_crates__peg-0.8.6//:peg\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"prost-0.14.3\",\n actual = \"@rust_crates__prost-0.14.3//:prost\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"prost\",\n actual = \"@rust_crates__prost-0.14.3//:prost\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"prost-build-0.14.3\",\n actual = \"@rust_crates__prost-build-0.14.3//:prost_build\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"prost-build\",\n actual = \"@rust_crates__prost-build-0.14.3//:prost_build\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"prost-types-0.14.3\",\n actual = \"@rust_crates__prost-types-0.14.3//:prost_types\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"prost-types\",\n actual = \"@rust_crates__prost-types-0.14.3//:prost_types\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"protox-0.9.1\",\n actual = \"@rust_crates__protox-0.9.1//:protox\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"protox\",\n actual = \"@rust_crates__protox-0.9.1//:protox\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"psm-0.1.24\",\n actual = \"@rust_crates__psm-0.1.24//:psm\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"psm\",\n actual = \"@rust_crates__psm-0.1.24//:psm\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"quick-xml-0.41.0\",\n actual = \"@rust_crates__quick-xml-0.41.0//:quick_xml\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"quick-xml\",\n actual = \"@rust_crates__quick-xml-0.41.0//:quick_xml\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"rustls-0.23.46\",\n actual = \"@rust_crates__rustls-0.23.46//:rustls\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"rustls\",\n actual = \"@rust_crates__rustls-0.23.46//:rustls\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"rustls-pki-types-1.15.1\",\n actual = \"@rust_crates__rustls-pki-types-1.15.1//:rustls_pki_types\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"rustls-pki-types\",\n actual = \"@rust_crates__rustls-pki-types-1.15.1//:rustls_pki_types\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"ryu-1.0.23\",\n actual = \"@rust_crates__ryu-1.0.23//:ryu\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"ryu\",\n actual = \"@rust_crates__ryu-1.0.23//:ryu\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"s2rst-0.5.1\",\n actual = \"@rust_crates__s2rst-0.5.1//:s2rst\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"s2rst\",\n actual = \"@rust_crates__s2rst-0.5.1//:s2rst\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"serde-1.0.229\",\n actual = \"@rust_crates__serde-1.0.229//:serde\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"serde\",\n actual = \"@rust_crates__serde-1.0.229//:serde\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"serde_json-1.0.151\",\n actual = \"@rust_crates__serde_json-1.0.151//:serde_json\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"serde_json\",\n actual = \"@rust_crates__serde_json-1.0.151//:serde_json\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"simsimd-6.5.16\",\n actual = \"@rust_crates__simsimd-6.5.16//:simsimd\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"simsimd\",\n actual = \"@rust_crates__simsimd-6.5.16//:simsimd\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"slab-0.4.12\",\n actual = \"@rust_crates__slab-0.4.12//:slab\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"slab\",\n actual = \"@rust_crates__slab-0.4.12//:slab\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"socket2-0.6.5\",\n actual = \"@rust_crates__socket2-0.6.5//:socket2\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"socket2\",\n actual = \"@rust_crates__socket2-0.6.5//:socket2\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"spdlog-rs-0.5.3\",\n actual = \"@rust_crates__spdlog-rs-0.5.3//:spdlog\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"spdlog-rs\",\n actual = \"@rust_crates__spdlog-rs-0.5.3//:spdlog\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tokio-1.52.3\",\n actual = \"@rust_crates__tokio-1.52.3//:tokio\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tokio\",\n actual = \"@rust_crates__tokio-1.52.3//:tokio\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tokio-stream-0.1.18\",\n actual = \"@rust_crates__tokio-stream-0.1.18//:tokio_stream\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tokio-stream\",\n actual = \"@rust_crates__tokio-stream-0.1.18//:tokio_stream\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tonic-0.14.6\",\n actual = \"@rust_crates__tonic-0.14.6//:tonic\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tonic\",\n actual = \"@rust_crates__tonic-0.14.6//:tonic\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tonic-prost-0.14.6\",\n actual = \"@rust_crates__tonic-prost-0.14.6//:tonic_prost\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tonic-prost\",\n actual = \"@rust_crates__tonic-prost-0.14.6//:tonic_prost\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tonic-prost-build-0.14.6\",\n actual = \"@rust_crates__tonic-prost-build-0.14.6//:tonic_prost_build\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"tonic-prost-build\",\n actual = \"@rust_crates__tonic-prost-build-0.14.6//:tonic_prost_build\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"uuid-1.29.0\",\n actual = \"@rust_crates__uuid-1.29.0//:uuid\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"uuid\",\n actual = \"@rust_crates__uuid-1.29.0//:uuid\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"walkdir-2.5.0\",\n actual = \"@rust_crates__walkdir-2.5.0//:walkdir\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"walkdir\",\n actual = \"@rust_crates__walkdir-2.5.0//:walkdir\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"windows-sys-0.61.2\",\n actual = \"@rust_crates__windows-sys-0.61.2//:windows_sys\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"windows-sys\",\n actual = \"@rust_crates__windows-sys-0.61.2//:windows_sys\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"x509-parser-0.18.1\",\n actual = \"@rust_crates__x509-parser-0.18.1//:x509_parser\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"x509-parser\",\n actual = \"@rust_crates__x509-parser-0.18.1//:x509_parser\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"zlib-rs-0.6.8\",\n actual = \"@rust_crates__zlib-rs-0.6.8//:zlib_rs\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"zlib-rs\",\n actual = \"@rust_crates__zlib-rs-0.6.8//:zlib_rs\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"zstd-safe-8.2.0\",\n actual = \"@rust_crates__zstd-safe-8.2.0//:zstd_safe\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"zstd-safe\",\n actual = \"@rust_crates__zstd-safe-8.2.0//:zstd_safe\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"zstd-sys-2.1.2+zstd.1.5.7\",\n actual = \"@rust_crates__zstd-sys-2.1.2-zstd.1.5.7//:zstd_sys\",\n tags = [\"manual\"],\n)\n\nalias(\n name = \"zstd-sys\",\n actual = \"@rust_crates__zstd-sys-2.1.2-zstd.1.5.7//:zstd_sys\",\n tags = [\"manual\"],\n)\n", "alias_rules.bzl": "\"\"\"Alias that transitions its target to `compilation_mode=opt`. Use `transition_alias=\"opt\"` to enable.\"\"\"\n\nload(\"@rules_cc//cc:defs.bzl\", \"CcInfo\")\nload(\"@rules_rust//rust:rust_common.bzl\", \"COMMON_PROVIDERS\")\n\ndef _transition_alias_impl(ctx):\n # `ctx.attr.actual` is a list of 1 item due to the transition\n providers = [ctx.attr.actual[0][provider] for provider in COMMON_PROVIDERS]\n if CcInfo in ctx.attr.actual[0]:\n providers.append(ctx.attr.actual[0][CcInfo])\n return providers\n\ndef _change_compilation_mode(compilation_mode):\n def _change_compilation_mode_impl(_settings, _attr):\n return {\n \"//command_line_option:compilation_mode\": compilation_mode,\n }\n\n return transition(\n implementation = _change_compilation_mode_impl,\n inputs = [],\n outputs = [\n \"//command_line_option:compilation_mode\",\n ],\n )\n\ndef _transition_alias_rule(compilation_mode):\n return rule(\n implementation = _transition_alias_impl,\n provides = COMMON_PROVIDERS,\n attrs = {\n \"actual\": attr.label(\n mandatory = True,\n doc = \"`rust_library()` target to transition to `compilation_mode=opt`.\",\n providers = COMMON_PROVIDERS,\n cfg = _change_compilation_mode(compilation_mode),\n ),\n \"_allowlist_function_transition\": attr.label(\n default = \"@bazel_tools//tools/allowlists/function_transition_allowlist\",\n ),\n },\n doc = \"Transitions a Rust library crate to the `compilation_mode=opt`.\",\n )\n\ntransition_alias_dbg = _transition_alias_rule(\"dbg\")\ntransition_alias_fastbuild = _transition_alias_rule(\"fastbuild\")\ntransition_alias_opt = _transition_alias_rule(\"opt\")\n", - "crates.bzl": "###############################################################################\n# @generated\n# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To \n# regenerate this file, run the following:\n#\n# bazel mod show_repo 'seekdb'\n###############################################################################\n\"\"\"\n# `crates_repository` API\n\n- [aliases](#aliases)\n- [crate_edition](#crate_edition)\n- [crate_deps](#crate_deps)\n- [all_crate_deps](#all_crate_deps)\n- [crate_repositories](#crate_repositories)\n\n\"\"\"\n\nload(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\nload(\"@bazel_tools//tools/build_defs/repo:utils.bzl\", \"maybe\")\nload(\"@bazel_skylib//lib:selects.bzl\", \"selects\")\nload(\"@rules_rust//crate_universe:defs.bzl\", \"crates_vendor_remote_repository\", \"local_crate_mirror\")\n\n###############################################################################\n# MACROS API\n###############################################################################\n\n# An identifier that represent common dependencies (unconditional).\n_COMMON_CONDITION = \"\"\n\ndef _flatten_dependency_maps(all_dependency_maps):\n \"\"\"Flatten a list of dependency maps into one dictionary.\n\n Dependency maps have the following structure:\n\n ```python\n DEPENDENCIES_MAP = {\n # The first key in the map is a Bazel package\n # name of the workspace this file is defined in.\n \"workspace_member_package\": {\n\n # Not all dependencies are supported for all platforms.\n # the condition key is the condition required to be true\n # on the host platform.\n \"condition\": {\n\n # An alias to a crate target. # The label of the crate target the\n # Aliases are only crate names. # package name refers to.\n \"package_name\": \"@full//:label\",\n }\n }\n }\n ```\n\n Args:\n all_dependency_maps (list): A list of dicts as described above\n\n Returns:\n dict: A dictionary as described above\n \"\"\"\n dependencies = {}\n\n for workspace_deps_map in all_dependency_maps:\n for pkg_name, conditional_deps_map in workspace_deps_map.items():\n if pkg_name not in dependencies:\n non_frozen_map = dict()\n for key, values in conditional_deps_map.items():\n non_frozen_map.update({key: dict(values.items())})\n dependencies.setdefault(pkg_name, non_frozen_map)\n continue\n\n for condition, deps_map in conditional_deps_map.items():\n # If the condition has not been recorded, do so and continue\n if condition not in dependencies[pkg_name]:\n dependencies[pkg_name].setdefault(condition, dict(deps_map.items()))\n continue\n\n # Alert on any miss-matched dependencies\n inconsistent_entries = []\n for crate_name, crate_label in deps_map.items():\n existing = dependencies[pkg_name][condition].get(crate_name)\n if existing and existing != crate_label:\n inconsistent_entries.append((crate_name, existing, crate_label))\n dependencies[pkg_name][condition].update({crate_name: crate_label})\n\n return dependencies\n\ndef crate_deps(deps, package_name = None):\n \"\"\"Finds the fully qualified label of the requested crates for the package where this macro is called.\n\n Args:\n deps (list): The desired list of crate targets.\n package_name (str, optional): The package name of the set of dependencies to look up.\n Defaults to `native.package_name()`.\n\n Returns:\n list: A list of labels to generated rust targets (str)\n \"\"\"\n\n if not deps:\n return []\n\n if package_name == None:\n package_name = native.package_name()\n\n # Join both sets of dependencies\n dependencies = _flatten_dependency_maps([\n _NORMAL_DEPENDENCIES,\n _NORMAL_DEV_DEPENDENCIES,\n _PROC_MACRO_DEPENDENCIES,\n _PROC_MACRO_DEV_DEPENDENCIES,\n _BUILD_DEPENDENCIES,\n _BUILD_PROC_MACRO_DEPENDENCIES,\n ]).pop(package_name, {})\n\n # Combine all conditional packages so we can easily index over a flat list\n # TODO: Perhaps this should actually return select statements and maintain\n # the conditionals of the dependencies\n flat_deps = {}\n for deps_set in dependencies.values():\n for crate_name, crate_label in deps_set.items():\n flat_deps.update({crate_name: crate_label})\n\n missing_crates = []\n crate_targets = []\n for crate_target in deps:\n if crate_target not in flat_deps:\n missing_crates.append(crate_target)\n else:\n crate_targets.append(flat_deps[crate_target])\n\n if missing_crates:\n fail(\"Could not find crates `{}` among dependencies of `{}`. Available dependencies were `{}`\".format(\n missing_crates,\n package_name,\n dependencies,\n ))\n\n return crate_targets\n\ndef crate_edition(package_name = None):\n \"\"\"Finds the Rust edition for the package where this macro is called.\n\n Args:\n package_name (str, optional): The package name whose edition should be\n looked up. Defaults to `native.package_name()` when unset.\n\n Returns:\n str: The Rust edition declared by the package's Cargo.toml file.\n \"\"\"\n if package_name == None:\n package_name = native.package_name()\n\n if package_name not in _CRATE_EDITIONS:\n fail(\"Tried to get crate_edition for package \" + package_name + \" but that package had no Cargo.toml file\")\n\n return _CRATE_EDITIONS[package_name]\n\ndef all_crate_deps(\n normal = False, \n normal_dev = False, \n proc_macro = False, \n proc_macro_dev = False,\n build = False,\n build_proc_macro = False,\n package_name = None):\n \"\"\"Finds the fully qualified label of all requested direct crate dependencies \\\n for the package where this macro is called.\n\n If no parameters are set, all normal dependencies are returned. Setting any one flag will\n otherwise impact the contents of the returned list.\n\n Args:\n normal (bool, optional): If True, normal dependencies are included in the\n output list.\n normal_dev (bool, optional): If True, normal dev dependencies will be\n included in the output list.\n proc_macro (bool, optional): If True, proc_macro dependencies are included\n in the output list.\n proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are\n included in the output list.\n build (bool, optional): If True, build dependencies are included\n in the output list.\n build_proc_macro (bool, optional): If True, build proc_macro dependencies are\n included in the output list.\n package_name (str, optional): The package name of the set of dependencies to look up.\n Defaults to `native.package_name()` when unset.\n\n Returns:\n list: A list of labels to generated rust targets (str)\n \"\"\"\n\n if package_name == None:\n package_name = native.package_name()\n\n # Determine the relevant maps to use\n all_dependency_maps = []\n if normal:\n all_dependency_maps.append(_NORMAL_DEPENDENCIES)\n if normal_dev:\n all_dependency_maps.append(_NORMAL_DEV_DEPENDENCIES)\n if proc_macro:\n all_dependency_maps.append(_PROC_MACRO_DEPENDENCIES)\n if proc_macro_dev:\n all_dependency_maps.append(_PROC_MACRO_DEV_DEPENDENCIES)\n if build:\n all_dependency_maps.append(_BUILD_DEPENDENCIES)\n if build_proc_macro:\n all_dependency_maps.append(_BUILD_PROC_MACRO_DEPENDENCIES)\n\n # Default to always using normal dependencies\n if not all_dependency_maps:\n all_dependency_maps.append(_NORMAL_DEPENDENCIES)\n\n dependencies = _flatten_dependency_maps(all_dependency_maps).pop(package_name, None)\n\n if not dependencies:\n if dependencies == None:\n fail(\"Tried to get all_crate_deps for package \" + package_name + \" but that package had no Cargo.toml file\")\n else:\n return []\n\n crate_deps = list(dependencies.pop(_COMMON_CONDITION, {}).values())\n for condition, deps in dependencies.items():\n crate_deps += selects.with_or({\n tuple(_CONDITIONS[condition]): deps.values(),\n \"//conditions:default\": [],\n })\n\n return crate_deps\n\ndef aliases(\n normal = False,\n normal_dev = False,\n proc_macro = False,\n proc_macro_dev = False,\n build = False,\n build_proc_macro = False,\n package_name = None):\n \"\"\"Produces a map of Crate alias names to their original label\n\n If no dependency kinds are specified, `normal` and `proc_macro` are used by default.\n Setting any one flag will otherwise determine the contents of the returned dict.\n\n Args:\n normal (bool, optional): If True, normal dependencies are included in the\n output list.\n normal_dev (bool, optional): If True, normal dev dependencies will be\n included in the output list..\n proc_macro (bool, optional): If True, proc_macro dependencies are included\n in the output list.\n proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are\n included in the output list.\n build (bool, optional): If True, build dependencies are included\n in the output list.\n build_proc_macro (bool, optional): If True, build proc_macro dependencies are\n included in the output list.\n package_name (str, optional): The package name of the set of dependencies to look up.\n Defaults to `native.package_name()` when unset.\n\n Returns:\n dict: The aliases of all associated packages\n \"\"\"\n if package_name == None:\n package_name = native.package_name()\n\n # Determine the relevant maps to use\n all_aliases_maps = []\n if normal:\n all_aliases_maps.append(_NORMAL_ALIASES)\n if normal_dev:\n all_aliases_maps.append(_NORMAL_DEV_ALIASES)\n if proc_macro:\n all_aliases_maps.append(_PROC_MACRO_ALIASES)\n if proc_macro_dev:\n all_aliases_maps.append(_PROC_MACRO_DEV_ALIASES)\n if build:\n all_aliases_maps.append(_BUILD_ALIASES)\n if build_proc_macro:\n all_aliases_maps.append(_BUILD_PROC_MACRO_ALIASES)\n\n # Default to always using normal aliases\n if not all_aliases_maps:\n all_aliases_maps.append(_NORMAL_ALIASES)\n all_aliases_maps.append(_PROC_MACRO_ALIASES)\n\n aliases = _flatten_dependency_maps(all_aliases_maps).pop(package_name, None)\n\n if not aliases:\n return dict()\n\n common_items = aliases.pop(_COMMON_CONDITION, {}).items()\n\n # If there are only common items in the dictionary, immediately return them\n if not len(aliases.keys()) == 1:\n return dict(common_items)\n\n # Build a single select statement where each conditional has accounted for the\n # common set of aliases.\n crate_aliases = {\"//conditions:default\": dict(common_items)}\n for condition, deps in aliases.items():\n condition_triples = _CONDITIONS[condition]\n for triple in condition_triples:\n if triple in crate_aliases:\n crate_aliases[triple].update(deps)\n else:\n crate_aliases.update({triple: dict(deps.items() + common_items)})\n\n return select(crate_aliases)\n\n###############################################################################\n# WORKSPACE MEMBER DEPS, ALIASES, AND EDITIONS\n###############################################################################\n\n_CRATE_EDITIONS = {\n \"rust/compression\": \"2021\",\n \"rust/config\": \"2021\",\n \"rust/crypto\": \"2021\",\n \"rust/file-io\": \"2021\",\n \"rust/http-client\": \"2021\",\n \"rust/in-process\": \"2021\",\n \"rust/json\": \"2021\",\n \"rust/kv\": \"2021\",\n \"rust/local\": \"2021\",\n \"rust/logger\": \"2021\",\n \"rust/math\": \"2021\",\n \"rust/mvt\": \"2021\",\n \"rust/number-parser\": \"2021\",\n \"rust/path-utils\": \"2021\",\n \"bazel/prost-codegen\": \"2021\",\n \"rust/regex-engine\": \"2021\",\n \"rust/rpc\": \"2021\",\n \"rust/seekdb-rust\": \"2021\",\n \"rust/spatial-covering\": \"2024\",\n \"rust/sql-nio\": \"2021\",\n \"rust/sql-parser\": \"2021\",\n \"rust/standby-rpc\": \"2021\",\n \"rust/storage-io\": \"2021\",\n \"rust/uuid-generator\": \"2021\",\n \"rust/vector-kernels\": \"2021\",\n \"rust/wal\": \"2021\",\n \"rust/xml-parser\": \"2021\",\n}\n\n_NORMAL_DEPENDENCIES = {\n \"rust/compression\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"zlib-rs\": Label(\"@rust_crates//zlib-rs-0.6.8\"),\n \"zstd-safe\": Label(\"@rust_crates//zstd-safe-8.2.0\"),\n \"zstd-sys\": Label(\"@rust_crates//zstd-sys-2.1.2+zstd.1.5.7\"),\n },\n },\n \"rust/config\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/crypto\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/file-io\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n },\n \"cfg(windows)\": {\n \"windows-sys\": Label(\"@rust_crates//windows-sys-0.61.2\"),\n },\n },\n \"rust/http-client\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/in-process\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n },\n },\n \"rust/json\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"memchr\": Label(\"@rust_crates//memchr-2.8.3\"),\n \"ryu\": Label(\"@rust_crates//ryu-1.0.23\"),\n \"serde\": Label(\"@rust_crates//serde-1.0.229\"),\n \"serde_json\": Label(\"@rust_crates//serde_json-1.0.151\"),\n },\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n \"chrono\": Label(\"@rust_crates//chrono-0.4.45\"),\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"log\": Label(\"@rust_crates//log-0.4.34\"),\n \"spdlog-rs\": Label(\"@rust_crates//spdlog-rs-0.5.3\"),\n },\n },\n \"rust/math\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libm\": Label(\"@rust_crates//libm-0.2.16\"),\n },\n },\n \"rust/mvt\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"prost\": Label(\"@rust_crates//prost-0.14.3\"),\n },\n },\n \"rust/number-parser\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"fast-float2\": Label(\"@rust_crates//fast-float2-0.2.4\"),\n },\n },\n \"rust/path-utils\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"globset\": Label(\"@rust_crates//globset-0.4.18\"),\n \"walkdir\": Label(\"@rust_crates//walkdir-2.5.0\"),\n },\n },\n \"bazel/prost-codegen\": {\n _COMMON_CONDITION: {\n \"prost-build\": Label(\"@rust_crates//prost-build-0.14.3\"),\n \"prost-types\": Label(\"@rust_crates//prost-types-0.14.3\"),\n \"protox\": Label(\"@rust_crates//protox-0.9.1\"),\n \"tonic-prost-build\": Label(\"@rust_crates//tonic-prost-build-0.14.6\"),\n },\n },\n \"rust/regex-engine\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"fancy-regex\": Label(\"@rust_crates//fancy-regex-0.20.0\"),\n },\n },\n \"rust/rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n \"rustls-pki-types\": Label(\"@rust_crates//rustls-pki-types-1.15.1\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n \"tokio-stream\": Label(\"@rust_crates//tokio-stream-0.1.18\"),\n \"tonic\": Label(\"@rust_crates//tonic-0.14.6\"),\n \"x509-parser\": Label(\"@rust_crates//x509-parser-0.18.1\"),\n },\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"s2rst\": Label(\"@rust_crates//s2rst-0.5.1\"),\n },\n },\n \"rust/sql-nio\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"rustls\": Label(\"@rust_crates//rustls-0.23.46\"),\n \"rustls-pki-types\": Label(\"@rust_crates//rustls-pki-types-1.15.1\"),\n \"slab\": Label(\"@rust_crates//slab-0.4.12\"),\n \"x509-parser\": Label(\"@rust_crates//x509-parser-0.18.1\"),\n },\n \"aarch64-apple-darwin\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-apple-ios\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-apple-ios-sim\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-linux-android\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-pc-windows-msvc\": {\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n \"windows-sys\": Label(\"@rust_crates//windows-sys-0.61.2\"),\n },\n \"aarch64-unknown-linux-gnu\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"x86_64-apple-darwin\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"x86_64-pc-windows-msvc\": {\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n \"windows-sys\": Label(\"@rust_crates//windows-sys-0.61.2\"),\n },\n \"x86_64-unknown-linux-gnu\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n },\n \"rust/sql-parser\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"peg\": Label(\"@rust_crates//peg-0.8.6\"),\n },\n \"cfg(any(target_arch = \\\"x86_64\\\", target_arch = \\\"aarch64\\\"))\": {\n \"psm\": Label(\"@rust_crates//psm-0.1.24\"),\n },\n },\n \"rust/standby-rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"prost\": Label(\"@rust_crates//prost-0.14.3\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n \"tokio-stream\": Label(\"@rust_crates//tokio-stream-0.1.18\"),\n \"tonic\": Label(\"@rust_crates//tonic-0.14.6\"),\n \"tonic-prost\": Label(\"@rust_crates//tonic-prost-0.14.6\"),\n },\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n },\n },\n \"rust/uuid-generator\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"getrandom\": Label(\"@rust_crates//getrandom-0.4.3\"),\n \"uuid\": Label(\"@rust_crates//uuid-1.29.0\"),\n },\n },\n \"rust/vector-kernels\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"simsimd\": Label(\"@rust_crates//simsimd-6.5.16\"),\n },\n },\n \"rust/wal\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"log\": Label(\"@rust_crates//log-0.4.34\"),\n },\n },\n \"rust/xml-parser\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"quick-xml\": Label(\"@rust_crates//quick-xml-0.41.0\"),\n },\n },\n}\n\n\n_NORMAL_ALIASES = {\n \"rust/compression\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/config\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/crypto\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/file-io\": {\n _COMMON_CONDITION: {\n },\n \"cfg(windows)\": {\n },\n },\n \"rust/http-client\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/in-process\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/json\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/math\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/mvt\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/number-parser\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/path-utils\": {\n _COMMON_CONDITION: {\n },\n },\n \"bazel/prost-codegen\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/regex-engine\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n },\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/sql-nio\": {\n _COMMON_CONDITION: {\n },\n \"aarch64-apple-darwin\": {\n },\n \"aarch64-apple-ios\": {\n },\n \"aarch64-apple-ios-sim\": {\n },\n \"aarch64-linux-android\": {\n },\n \"aarch64-pc-windows-msvc\": {\n },\n \"aarch64-unknown-linux-gnu\": {\n },\n \"x86_64-apple-darwin\": {\n },\n \"x86_64-pc-windows-msvc\": {\n },\n \"x86_64-unknown-linux-gnu\": {\n },\n },\n \"rust/sql-parser\": {\n _COMMON_CONDITION: {\n },\n \"cfg(any(target_arch = \\\"x86_64\\\", target_arch = \\\"aarch64\\\"))\": {\n },\n },\n \"rust/standby-rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n },\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/uuid-generator\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/vector-kernels\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/wal\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/xml-parser\": {\n _COMMON_CONDITION: {\n },\n },\n}\n\n\n_NORMAL_DEV_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n \"cfg(not(target_os = \\\"emscripten\\\"))\": {\n \"rustls\": Label(\"@rust_crates//rustls-0.23.46\"),\n },\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n },\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n },\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_NORMAL_DEV_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n \"cfg(not(target_os = \\\"emscripten\\\"))\": {\n },\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_DEV_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_DEV_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n \"cfg(not(target_os = \\\"emscripten\\\"))\": {\n },\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_PROC_MACRO_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_PROC_MACRO_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_CONDITIONS = {\n \"aarch64-apple-darwin\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\"],\n \"aarch64-apple-ios\": [\"@rules_rust//rust/platform:aarch64-apple-ios\"],\n \"aarch64-apple-ios-sim\": [\"@rules_rust//rust/platform:aarch64-apple-ios-sim\"],\n \"aarch64-linux-android\": [\"@rules_rust//rust/platform:aarch64-linux-android\"],\n \"aarch64-pc-windows-gnullvm\": [],\n \"aarch64-pc-windows-msvc\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\"],\n \"aarch64-unknown-linux-gnu\": [\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\"],\n \"cfg(all(all(target_arch = \\\"aarch64\\\", target_endian = \\\"little\\\"), target_os = \\\"windows\\\"))\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\"],\n \"cfg(all(all(target_arch = \\\"aarch64\\\", target_endian = \\\"little\\\"), target_vendor = \\\"apple\\\", any(target_os = \\\"ios\\\", target_os = \\\"macos\\\", target_os = \\\"tvos\\\", target_os = \\\"visionos\\\", target_os = \\\"watchos\\\")))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\"],\n \"cfg(all(any(all(target_arch = \\\"aarch64\\\", target_endian = \\\"little\\\"), all(target_arch = \\\"arm\\\", target_endian = \\\"little\\\")), any(target_os = \\\"android\\\", target_os = \\\"linux\\\")))\": [\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\"],\n \"cfg(all(any(target_arch = \\\"x86_64\\\", target_arch = \\\"arm64ec\\\"), target_env = \\\"msvc\\\", not(windows_raw_dylib)))\": [\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"cfg(all(any(target_os = \\\"linux\\\", target_os = \\\"android\\\"), any(rustix_use_libc, miri, not(all(target_os = \\\"linux\\\", any(target_endian = \\\"little\\\", any(target_arch = \\\"s390x\\\", target_arch = \\\"powerpc\\\")), any(target_arch = \\\"arm\\\", all(target_arch = \\\"aarch64\\\", target_pointer_width = \\\"64\\\"), target_arch = \\\"riscv64\\\", all(rustix_use_experimental_asm, target_arch = \\\"powerpc\\\"), all(rustix_use_experimental_asm, target_arch = \\\"powerpc64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"s390x\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips32r6\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64r6\\\"), target_arch = \\\"x86\\\", all(target_arch = \\\"x86_64\\\", target_pointer_width = \\\"64\\\")))))))\": [\"@rules_rust//rust/platform:aarch64-linux-android\"],\n \"cfg(all(any(target_os = \\\"linux\\\", target_os = \\\"android\\\"), not(any(all(target_os = \\\"linux\\\", target_env = \\\"\\\"), getrandom_backend = \\\"custom\\\", getrandom_backend = \\\"linux_raw\\\", getrandom_backend = \\\"rdrand\\\", getrandom_backend = \\\"rndr\\\"))))\": [\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(all(not(rustix_use_libc), not(miri), target_os = \\\"linux\\\", any(target_endian = \\\"little\\\", any(target_arch = \\\"s390x\\\", target_arch = \\\"powerpc\\\")), any(target_arch = \\\"arm\\\", all(target_arch = \\\"aarch64\\\", target_pointer_width = \\\"64\\\"), target_arch = \\\"riscv64\\\", all(rustix_use_experimental_asm, target_arch = \\\"powerpc\\\"), all(rustix_use_experimental_asm, target_arch = \\\"powerpc64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"s390x\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips32r6\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64r6\\\"), target_arch = \\\"x86\\\", all(target_arch = \\\"x86_64\\\", target_pointer_width = \\\"64\\\"))))\": [\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = \\\"linux\\\", any(target_endian = \\\"little\\\", any(target_arch = \\\"s390x\\\", target_arch = \\\"powerpc\\\")), any(target_arch = \\\"arm\\\", all(target_arch = \\\"aarch64\\\", target_pointer_width = \\\"64\\\"), target_arch = \\\"riscv64\\\", all(rustix_use_experimental_asm, target_arch = \\\"powerpc\\\"), all(rustix_use_experimental_asm, target_arch = \\\"powerpc64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"s390x\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips32r6\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64r6\\\"), target_arch = \\\"x86\\\", all(target_arch = \\\"x86_64\\\", target_pointer_width = \\\"64\\\")))))))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"cfg(all(target_arch = \\\"aarch64\\\", target_env = \\\"msvc\\\", not(windows_raw_dylib)))\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\"],\n \"cfg(all(target_arch = \\\"wasm32\\\", target_os = \\\"unknown\\\"))\": [],\n \"cfg(all(target_arch = \\\"x86\\\", target_env = \\\"gnu\\\", not(target_abi = \\\"llvm\\\"), not(windows_raw_dylib)))\": [],\n \"cfg(all(target_arch = \\\"x86\\\", target_env = \\\"msvc\\\", not(windows_raw_dylib)))\": [],\n \"cfg(all(target_arch = \\\"x86_64\\\", target_env = \\\"gnu\\\", not(target_abi = \\\"llvm\\\"), not(windows_raw_dylib)))\": [\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(all(target_os = \\\"uefi\\\", getrandom_backend = \\\"efi_rng\\\"))\": [],\n \"cfg(any())\": [],\n \"cfg(any(target_arch = \\\"x86_64\\\", target_arch = \\\"aarch64\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(any(target_os = \\\"dragonfly\\\", target_os = \\\"freebsd\\\", target_os = \\\"hurd\\\", target_os = \\\"illumos\\\", target_os = \\\"cygwin\\\", all(target_os = \\\"horizon\\\", target_arch = \\\"arm\\\")))\": [],\n \"cfg(any(target_os = \\\"haiku\\\", target_os = \\\"redox\\\", target_os = \\\"nto\\\", target_os = \\\"aix\\\"))\": [],\n \"cfg(any(target_os = \\\"ios\\\", target_os = \\\"visionos\\\", target_os = \\\"watchos\\\", target_os = \\\"tvos\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\"],\n \"cfg(any(target_os = \\\"macos\\\", target_os = \\\"openbsd\\\", target_os = \\\"vita\\\", target_os = \\\"emscripten\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"cfg(any(unix, target_os = \\\"hermit\\\", target_os = \\\"wasi\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(any(unix, target_os = \\\"wasi\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(not(target_family = \\\"wasm\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(not(target_os = \\\"emscripten\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(target_os = \\\"android\\\")\": [\"@rules_rust//rust/platform:aarch64-linux-android\"],\n \"cfg(target_os = \\\"haiku\\\")\": [],\n \"cfg(target_os = \\\"hermit\\\")\": [],\n \"cfg(target_os = \\\"netbsd\\\")\": [],\n \"cfg(target_os = \\\"redox\\\")\": [],\n \"cfg(target_os = \\\"solaris\\\")\": [],\n \"cfg(target_os = \\\"vxworks\\\")\": [],\n \"cfg(target_os = \\\"wasi\\\")\": [],\n \"cfg(target_os = \\\"windows\\\")\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"cfg(target_vendor = \\\"apple\\\")\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"cfg(unix)\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(windows)\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"i686-pc-windows-gnu\": [],\n \"i686-pc-windows-gnullvm\": [],\n \"wasm32-unknown-emscripten\": [\"@rules_rust//rust/platform:wasm32-unknown-emscripten\"],\n \"x86_64-apple-darwin\": [\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"x86_64-pc-windows-gnu\": [],\n \"x86_64-pc-windows-gnullvm\": [],\n \"x86_64-pc-windows-msvc\": [\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"x86_64-unknown-linux-gnu\": [\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n}\n\n###############################################################################\n\ndef crate_repositories():\n \"\"\"A macro for defining repositories for all generated crates.\n\n Returns:\n A list of repos visible to the module through the module extension.\n \"\"\"\n maybe(\n crates_vendor_remote_repository,\n name = \"rust_crates\",\n # Lean interface: just point at `crates.bzl`; the repo rule\n # derives the sibling `BUILD.bazel` and `defs.bzl`.\n crates_module = Label(\"@rust_crates//rust_crates:crates.bzl\"),\n )\n maybe(\n http_archive,\n name = \"rust_crates__aho-corasick-1.1.5\",\n sha256 = \"c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/aho-corasick/1.1.5/download\"],\n strip_prefix = \"aho-corasick-1.1.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.aho-corasick-1.1.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__android_system_properties-0.1.6\",\n sha256 = \"ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/android_system_properties/0.1.6/download\"],\n strip_prefix = \"android_system_properties-0.1.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.android_system_properties-0.1.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__anyhow-1.0.103\",\n sha256 = \"2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/anyhow/1.0.103/download\"],\n strip_prefix = \"anyhow-1.0.103\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.anyhow-1.0.103.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__arc-swap-1.9.2\",\n sha256 = \"c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/arc-swap/1.9.2/download\"],\n strip_prefix = \"arc-swap-1.9.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.arc-swap-1.9.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__asn1-rs-0.7.2\",\n sha256 = \"b7f43a50ac4fdca5df8e885c21b835997f0a1cdee65494a6847694a98652d9d8\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/asn1-rs/0.7.2/download\"],\n strip_prefix = \"asn1-rs-0.7.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.asn1-rs-0.7.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__asn1-rs-derive-0.6.0\",\n sha256 = \"3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/asn1-rs-derive/0.6.0/download\"],\n strip_prefix = \"asn1-rs-derive-0.6.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.asn1-rs-derive-0.6.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__asn1-rs-impl-0.2.0\",\n sha256 = \"7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/asn1-rs-impl/0.2.0/download\"],\n strip_prefix = \"asn1-rs-impl-0.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.asn1-rs-impl-0.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__async-trait-0.1.89\",\n sha256 = \"9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/async-trait/0.1.89/download\"],\n strip_prefix = \"async-trait-0.1.89\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.async-trait-0.1.89.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__atomic-0.6.1\",\n sha256 = \"a89cbf775b137e9b968e67227ef7f775587cde3fd31b0d8599dbd0f598a48340\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/atomic/0.6.1/download\"],\n strip_prefix = \"atomic-0.6.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.atomic-0.6.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__atomic-waker-1.1.2\",\n sha256 = \"1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/atomic-waker/1.1.2/download\"],\n strip_prefix = \"atomic-waker-1.1.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.atomic-waker-1.1.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__autocfg-1.5.1\",\n sha256 = \"f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/autocfg/1.5.1/download\"],\n strip_prefix = \"autocfg-1.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.autocfg-1.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__axum-0.8.9\",\n sha256 = \"31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/axum/0.8.9/download\"],\n strip_prefix = \"axum-0.8.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.axum-0.8.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__axum-core-0.5.6\",\n sha256 = \"08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/axum-core/0.5.6/download\"],\n strip_prefix = \"axum-core-0.5.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.axum-core-0.5.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__base64-0.22.1\",\n sha256 = \"72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/base64/0.22.1/download\"],\n strip_prefix = \"base64-0.22.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.base64-0.22.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__beef-0.5.2\",\n sha256 = \"3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/beef/0.5.2/download\"],\n strip_prefix = \"beef-0.5.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.beef-0.5.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bit-set-0.8.0\",\n sha256 = \"08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bit-set/0.8.0/download\"],\n strip_prefix = \"bit-set-0.8.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bit-set-0.8.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bit-vec-0.8.0\",\n sha256 = \"5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bit-vec/0.8.0/download\"],\n strip_prefix = \"bit-vec-0.8.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bit-vec-0.8.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bitflags-2.13.2\",\n sha256 = \"3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bitflags/2.13.2/download\"],\n strip_prefix = \"bitflags-2.13.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bitflags-2.13.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bstr-1.13.1\",\n sha256 = \"6bb31b46c14244e20ee9984b11bf5c992b91fb6939fea616e3512c8baecdbe5f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bstr/1.13.1/download\"],\n strip_prefix = \"bstr-1.13.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bstr-1.13.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bumpalo-3.20.3\",\n sha256 = \"72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bumpalo/3.20.3/download\"],\n strip_prefix = \"bumpalo-3.20.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bumpalo-3.20.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bytemuck-1.25.2\",\n sha256 = \"95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bytemuck/1.25.2/download\"],\n strip_prefix = \"bytemuck-1.25.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bytemuck-1.25.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bytemuck_derive-1.12.1\",\n sha256 = \"6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bytemuck_derive/1.12.1/download\"],\n strip_prefix = \"bytemuck_derive-1.12.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bytemuck_derive-1.12.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bytes-1.11.1\",\n sha256 = \"1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bytes/1.11.1/download\"],\n strip_prefix = \"bytes-1.11.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bytes-1.11.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cc-1.5.1\",\n sha256 = \"f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cc/1.5.1/download\"],\n strip_prefix = \"cc-1.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cc-1.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cfg-if-1.0.5\",\n sha256 = \"4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cfg-if/1.0.5/download\"],\n strip_prefix = \"cfg-if-1.0.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cfg-if-1.0.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__chrono-0.4.45\",\n sha256 = \"1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/chrono/0.4.45/download\"],\n strip_prefix = \"chrono-0.4.45\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.chrono-0.4.45.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__codespan-reporting-0.13.1\",\n sha256 = \"af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/codespan-reporting/0.13.1/download\"],\n strip_prefix = \"codespan-reporting-0.13.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.codespan-reporting-0.13.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__core-foundation-sys-0.8.7\",\n sha256 = \"773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/core-foundation-sys/0.8.7/download\"],\n strip_prefix = \"core-foundation-sys-0.8.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.core-foundation-sys-0.8.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-0.8.5\",\n sha256 = \"e71406cd8807725f7ac2f999a4cdd32e98f829fdf65f528343cebf945e41df1e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam/0.8.5/download\"],\n strip_prefix = \"crossbeam-0.8.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-0.8.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-channel-0.5.17\",\n sha256 = \"98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-channel/0.5.17/download\"],\n strip_prefix = \"crossbeam-channel-0.5.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-channel-0.5.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-deque-0.8.8\",\n sha256 = \"622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-deque/0.8.8/download\"],\n strip_prefix = \"crossbeam-deque-0.8.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-deque-0.8.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-epoch-0.9.21\",\n sha256 = \"dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-epoch/0.9.21/download\"],\n strip_prefix = \"crossbeam-epoch-0.9.21\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-epoch-0.9.21.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-queue-0.3.14\",\n sha256 = \"03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-queue/0.3.14/download\"],\n strip_prefix = \"crossbeam-queue-0.3.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-queue-0.3.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-utils-0.8.23\",\n sha256 = \"a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-utils/0.8.23/download\"],\n strip_prefix = \"crossbeam-utils-0.8.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-utils-0.8.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxx-1.0.202\",\n sha256 = \"13f6de320895f42e6e081abb5c7983bedcf0b6d0ff9323de0d33f620c8ac1199\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxx/1.0.202/download\"],\n strip_prefix = \"cxx-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxx-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxx-build-1.0.202\",\n sha256 = \"4fde53ca86b9704a943fef0f1e1d836239a6aedca5de3c65fa9f97ec0bd46d39\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxx-build/1.0.202/download\"],\n strip_prefix = \"cxx-build-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxx-build-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxxbridge-flags-1.0.202\",\n sha256 = \"49045042e5fced01b80742aba5508de82aa4f13677ed3fa2b4cda709c40c5918\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxxbridge-flags/1.0.202/download\"],\n strip_prefix = \"cxxbridge-flags-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxxbridge-flags-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxxbridge-macro-1.0.202\",\n sha256 = \"b181252e2e3d3b5d183afbdc033a3958b445eb3e1a0ae65fc3d4f5259f5da6fd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxxbridge-macro/1.0.202/download\"],\n strip_prefix = \"cxxbridge-macro-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxxbridge-macro-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__data-encoding-2.11.1\",\n sha256 = \"4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/data-encoding/2.11.1/download\"],\n strip_prefix = \"data-encoding-2.11.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.data-encoding-2.11.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__der-parser-10.0.0\",\n sha256 = \"07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/der-parser/10.0.0/download\"],\n strip_prefix = \"der-parser-10.0.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.der-parser-10.0.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__deranged-0.5.8\",\n sha256 = \"7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/deranged/0.5.8/download\"],\n strip_prefix = \"deranged-0.5.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.deranged-0.5.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__displaydoc-0.2.7\",\n sha256 = \"c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/displaydoc/0.2.7/download\"],\n strip_prefix = \"displaydoc-0.2.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.displaydoc-0.2.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__dyn-clone-1.0.20\",\n sha256 = \"d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/dyn-clone/1.0.20/download\"],\n strip_prefix = \"dyn-clone-1.0.20\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.dyn-clone-1.0.20.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__either-1.15.0\",\n sha256 = \"48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/either/1.15.0/download\"],\n strip_prefix = \"either-1.15.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.either-1.15.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__equivalent-1.0.2\",\n sha256 = \"877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/equivalent/1.0.2/download\"],\n strip_prefix = \"equivalent-1.0.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.equivalent-1.0.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__erased-serde-0.4.10\",\n sha256 = \"d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/erased-serde/0.4.10/download\"],\n strip_prefix = \"erased-serde-0.4.10\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.erased-serde-0.4.10.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__errno-0.3.14\",\n sha256 = \"39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/errno/0.3.14/download\"],\n strip_prefix = \"errno-0.3.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.errno-0.3.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fancy-regex-0.20.0\",\n sha256 = \"20ed7f62ce0ae0da1a8b93c3c7104ab7e0760a74491e097c701fff966e945390\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fancy-regex/0.20.0/download\"],\n strip_prefix = \"fancy-regex-0.20.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fancy-regex-0.20.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fast-float2-0.2.4\",\n sha256 = \"c6e8948ce679d00a02a94739ea185595dca7118ed04feb991127e443bd3d761f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fast-float2/0.2.4/download\"],\n strip_prefix = \"fast-float2-0.2.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fast-float2-0.2.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fastrand-2.5.0\",\n sha256 = \"da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fastrand/2.5.0/download\"],\n strip_prefix = \"fastrand-2.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fastrand-2.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__find-msvc-tools-0.1.14\",\n sha256 = \"aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/find-msvc-tools/0.1.14/download\"],\n strip_prefix = \"find-msvc-tools-0.1.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.find-msvc-tools-0.1.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fixedbitset-0.5.7\",\n sha256 = \"1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fixedbitset/0.5.7/download\"],\n strip_prefix = \"fixedbitset-0.5.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fixedbitset-0.5.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fnv-1.0.7\",\n sha256 = \"3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fnv/1.0.7/download\"],\n strip_prefix = \"fnv-1.0.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fnv-1.0.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__foldhash-0.1.3\",\n sha256 = \"f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/foldhash/0.1.3/download\"],\n strip_prefix = \"foldhash-0.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.foldhash-0.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__foldhash-0.2.0\",\n sha256 = \"77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/foldhash/0.2.0/download\"],\n strip_prefix = \"foldhash-0.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.foldhash-0.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-channel-0.3.32\",\n sha256 = \"07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-channel/0.3.32/download\"],\n strip_prefix = \"futures-channel-0.3.32\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-channel-0.3.32.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-core-0.3.34\",\n sha256 = \"92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-core/0.3.34/download\"],\n strip_prefix = \"futures-core-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-core-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-sink-0.3.32\",\n sha256 = \"c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-sink/0.3.32/download\"],\n strip_prefix = \"futures-sink-0.3.32\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-sink-0.3.32.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-task-0.3.34\",\n sha256 = \"cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-task/0.3.34/download\"],\n strip_prefix = \"futures-task-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-task-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-util-0.3.34\",\n sha256 = \"0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-util/0.3.34/download\"],\n strip_prefix = \"futures-util-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-util-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__getrandom-0.2.17\",\n sha256 = \"ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/getrandom/0.2.17/download\"],\n strip_prefix = \"getrandom-0.2.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.getrandom-0.2.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__getrandom-0.4.3\",\n sha256 = \"300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/getrandom/0.4.3/download\"],\n strip_prefix = \"getrandom-0.4.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.getrandom-0.4.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__globset-0.4.18\",\n sha256 = \"52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/globset/0.4.18/download\"],\n strip_prefix = \"globset-0.4.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.globset-0.4.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__h2-0.4.16\",\n sha256 = \"a9f37a958b41b3b19ee2707c06439c0e9e547e847223eb791ecb0cb821c65e27\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/h2/0.4.16/download\"],\n strip_prefix = \"h2-0.4.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.h2-0.4.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hashbrown-0.15.2\",\n sha256 = \"bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hashbrown/0.15.2/download\"],\n strip_prefix = \"hashbrown-0.15.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hashbrown-0.15.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hashbrown-0.17.1\",\n sha256 = \"ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hashbrown/0.17.1/download\"],\n strip_prefix = \"hashbrown-0.17.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hashbrown-0.17.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__heck-0.5.0\",\n sha256 = \"2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/heck/0.5.0/download\"],\n strip_prefix = \"heck-0.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.heck-0.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__http-1.4.0\",\n sha256 = \"e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/http/1.4.0/download\"],\n strip_prefix = \"http-1.4.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.http-1.4.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__http-body-1.0.1\",\n sha256 = \"1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/http-body/1.0.1/download\"],\n strip_prefix = \"http-body-1.0.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.http-body-1.0.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__http-body-util-0.1.3\",\n sha256 = \"b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/http-body-util/0.1.3/download\"],\n strip_prefix = \"http-body-util-0.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.http-body-util-0.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__httparse-1.10.1\",\n sha256 = \"6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/httparse/1.10.1/download\"],\n strip_prefix = \"httparse-1.10.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.httparse-1.10.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__httpdate-1.0.3\",\n sha256 = \"df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/httpdate/1.0.3/download\"],\n strip_prefix = \"httpdate-1.0.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.httpdate-1.0.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hyper-1.9.0\",\n sha256 = \"6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hyper/1.9.0/download\"],\n strip_prefix = \"hyper-1.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hyper-1.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hyper-timeout-0.5.2\",\n sha256 = \"2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hyper-timeout/0.5.2/download\"],\n strip_prefix = \"hyper-timeout-0.5.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hyper-timeout-0.5.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hyper-util-0.1.20\",\n sha256 = \"96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hyper-util/0.1.20/download\"],\n strip_prefix = \"hyper-util-0.1.20\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hyper-util-0.1.20.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__iana-time-zone-0.1.65\",\n sha256 = \"e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/iana-time-zone/0.1.65/download\"],\n strip_prefix = \"iana-time-zone-0.1.65\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.iana-time-zone-0.1.65.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__iana-time-zone-haiku-0.1.2\",\n sha256 = \"f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/iana-time-zone-haiku/0.1.2/download\"],\n strip_prefix = \"iana-time-zone-haiku-0.1.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.iana-time-zone-haiku-0.1.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__indexmap-2.14.2\",\n sha256 = \"cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/indexmap/2.14.2/download\"],\n strip_prefix = \"indexmap-2.14.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.indexmap-2.14.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__itertools-0.14.0\",\n sha256 = \"2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/itertools/0.14.0/download\"],\n strip_prefix = \"itertools-0.14.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.itertools-0.14.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__itoa-1.0.18\",\n sha256 = \"8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/itoa/1.0.18/download\"],\n strip_prefix = \"itoa-1.0.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.itoa-1.0.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__jobserver-0.1.35\",\n sha256 = \"1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/jobserver/0.1.35/download\"],\n strip_prefix = \"jobserver-0.1.35\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.jobserver-0.1.35.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__js-sys-0.3.106\",\n sha256 = \"7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/js-sys/0.3.106/download\"],\n strip_prefix = \"js-sys-0.3.106\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.js-sys-0.3.106.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__lazy_static-1.5.0\",\n sha256 = \"bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/lazy_static/1.5.0/download\"],\n strip_prefix = \"lazy_static-1.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.lazy_static-1.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__libc-0.2.189\",\n sha256 = \"3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/libc/0.2.189/download\"],\n strip_prefix = \"libc-0.2.189\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.libc-0.2.189.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__libm-0.2.16\",\n sha256 = \"b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/libm/0.2.16/download\"],\n strip_prefix = \"libm-0.2.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.libm-0.2.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__link-cplusplus-1.0.12\",\n sha256 = \"7f78c730aaa7d0b9336a299029ea49f9ee53b0ed06e9202e8cb7db9bae7b8c82\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/link-cplusplus/1.0.12/download\"],\n strip_prefix = \"link-cplusplus-1.0.12\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.link-cplusplus-1.0.12.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__linux-raw-sys-0.12.1\",\n sha256 = \"32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/linux-raw-sys/0.12.1/download\"],\n strip_prefix = \"linux-raw-sys-0.12.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.linux-raw-sys-0.12.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__lock_api-0.4.14\",\n sha256 = \"224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/lock_api/0.4.14/download\"],\n strip_prefix = \"lock_api-0.4.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.lock_api-0.4.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__log-0.4.34\",\n sha256 = \"f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/log/0.4.34/download\"],\n strip_prefix = \"log-0.4.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.log-0.4.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-0.15.1\",\n sha256 = \"ff472f899b4ec2d99161c51f60ff7075eeb3097069a36050d8037a6325eb8154\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos/0.15.1/download\"],\n strip_prefix = \"logos-0.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-0.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-0.16.1\",\n sha256 = \"eb2c55a318a87600ea870ff8c2012148b44bf18b74fad48d0f835c38c7d07c5f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos/0.16.1/download\"],\n strip_prefix = \"logos-0.16.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-0.16.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-codegen-0.15.1\",\n sha256 = \"192a3a2b90b0c05b27a0b2c43eecdb7c415e29243acc3f89cc8247a5b693045c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-codegen/0.15.1/download\"],\n strip_prefix = \"logos-codegen-0.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-codegen-0.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-codegen-0.16.1\",\n sha256 = \"58b3ffaa284e1350d017a57d04ada118c4583cf260c8fb01e0fe28a2e9cf8970\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-codegen/0.16.1/download\"],\n strip_prefix = \"logos-codegen-0.16.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-codegen-0.16.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-derive-0.15.1\",\n sha256 = \"605d9697bcd5ef3a42d38efc51541aa3d6a4a25f7ab6d1ed0da5ac632a26b470\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-derive/0.15.1/download\"],\n strip_prefix = \"logos-derive-0.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-derive-0.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-derive-0.16.1\",\n sha256 = \"52d3a9855747c17eaf4383823f135220716ab49bea5fbea7dd42cc9a92f8aa31\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-derive/0.16.1/download\"],\n strip_prefix = \"logos-derive-0.16.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-derive-0.16.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__matchit-0.8.4\",\n sha256 = \"47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/matchit/0.8.4/download\"],\n strip_prefix = \"matchit-0.8.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.matchit-0.8.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__memchr-2.8.3\",\n sha256 = \"cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/memchr/2.8.3/download\"],\n strip_prefix = \"memchr-2.8.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.memchr-2.8.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__miette-7.6.0\",\n sha256 = \"5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/miette/7.6.0/download\"],\n strip_prefix = \"miette-7.6.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.miette-7.6.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__miette-derive-7.6.0\",\n sha256 = \"db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/miette-derive/7.6.0/download\"],\n strip_prefix = \"miette-derive-7.6.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.miette-derive-7.6.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__mime-0.3.17\",\n sha256 = \"6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/mime/0.3.17/download\"],\n strip_prefix = \"mime-0.3.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.mime-0.3.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__minimal-lexical-0.2.1\",\n sha256 = \"68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/minimal-lexical/0.2.1/download\"],\n strip_prefix = \"minimal-lexical-0.2.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.minimal-lexical-0.2.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__mio-1.2.3\",\n sha256 = \"4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/mio/1.2.3/download\"],\n strip_prefix = \"mio-1.2.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.mio-1.2.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__multimap-0.10.1\",\n sha256 = \"1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/multimap/0.10.1/download\"],\n strip_prefix = \"multimap-0.10.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.multimap-0.10.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__nom-7.1.3\",\n sha256 = \"d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/nom/7.1.3/download\"],\n strip_prefix = \"nom-7.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.nom-7.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__nom-8.0.0\",\n sha256 = \"df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/nom/8.0.0/download\"],\n strip_prefix = \"nom-8.0.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.nom-8.0.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-bigint-0.4.8\",\n sha256 = \"c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-bigint/0.4.8/download\"],\n strip_prefix = \"num-bigint-0.4.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-bigint-0.4.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-conv-0.2.2\",\n sha256 = \"521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-conv/0.2.2/download\"],\n strip_prefix = \"num-conv-0.2.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-conv-0.2.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-integer-0.1.47\",\n sha256 = \"7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-integer/0.1.47/download\"],\n strip_prefix = \"num-integer-0.1.47\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-integer-0.1.47.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-traits-0.2.19\",\n sha256 = \"071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-traits/0.2.19/download\"],\n strip_prefix = \"num-traits-0.2.19\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-traits-0.2.19.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__oid-registry-0.8.1\",\n sha256 = \"12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/oid-registry/0.8.1/download\"],\n strip_prefix = \"oid-registry-0.8.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.oid-registry-0.8.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__once_cell-1.21.4\",\n sha256 = \"9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/once_cell/1.21.4/download\"],\n strip_prefix = \"once_cell-1.21.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.once_cell-1.21.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__parking_lot-0.12.5\",\n sha256 = \"93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/parking_lot/0.12.5/download\"],\n strip_prefix = \"parking_lot-0.12.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.parking_lot-0.12.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__parking_lot_core-0.9.12\",\n sha256 = \"2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/parking_lot_core/0.9.12/download\"],\n strip_prefix = \"parking_lot_core-0.9.12\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.parking_lot_core-0.9.12.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__peg-0.8.6\",\n sha256 = \"0aad070be5b63aa72103f2fcdd70a83adbd5e90112ce5b574171ff1c65501773\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/peg/0.8.6/download\"],\n strip_prefix = \"peg-0.8.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.peg-0.8.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__peg-macros-0.8.6\",\n sha256 = \"ddd8ef6825cae95355031ae26a99b616a2a21f22ba2de0197c43dfb05acbe7ee\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/peg-macros/0.8.6/download\"],\n strip_prefix = \"peg-macros-0.8.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.peg-macros-0.8.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__peg-runtime-0.8.6\",\n sha256 = \"7011d97b484a5ebdc4b1fdb3b12d5e4bbbea56e9d22b688f2e79e04b65a7d8a6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/peg-runtime/0.8.6/download\"],\n strip_prefix = \"peg-runtime-0.8.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.peg-runtime-0.8.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__percent-encoding-2.3.2\",\n sha256 = \"9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/percent-encoding/2.3.2/download\"],\n strip_prefix = \"percent-encoding-2.3.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.percent-encoding-2.3.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__petgraph-0.8.3\",\n sha256 = \"8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/petgraph/0.8.3/download\"],\n strip_prefix = \"petgraph-0.8.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.petgraph-0.8.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pin-project-1.1.13\",\n sha256 = \"2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pin-project/1.1.13/download\"],\n strip_prefix = \"pin-project-1.1.13\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pin-project-1.1.13.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pin-project-internal-1.1.13\",\n sha256 = \"c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pin-project-internal/1.1.13/download\"],\n strip_prefix = \"pin-project-internal-1.1.13\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pin-project-internal-1.1.13.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pin-project-lite-0.2.17\",\n sha256 = \"a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pin-project-lite/0.2.17/download\"],\n strip_prefix = \"pin-project-lite-0.2.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pin-project-lite-0.2.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pkg-config-0.3.34\",\n sha256 = \"f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pkg-config/0.3.34/download\"],\n strip_prefix = \"pkg-config-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pkg-config-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__powerfmt-0.2.0\",\n sha256 = \"439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/powerfmt/0.2.0/download\"],\n strip_prefix = \"powerfmt-0.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.powerfmt-0.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prettyplease-0.2.37\",\n sha256 = \"479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prettyplease/0.2.37/download\"],\n strip_prefix = \"prettyplease-0.2.37\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prettyplease-0.2.37.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__proc-macro2-1.0.107\",\n sha256 = \"985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/proc-macro2/1.0.107/download\"],\n strip_prefix = \"proc-macro2-1.0.107\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.proc-macro2-1.0.107.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-0.14.3\",\n sha256 = \"d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost/0.14.3/download\"],\n strip_prefix = \"prost-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-build-0.14.3\",\n sha256 = \"343d3bd7056eda839b03204e68deff7d1b13aba7af2b2fd16890697274262ee7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-build/0.14.3/download\"],\n strip_prefix = \"prost-build-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-build-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-derive-0.14.3\",\n sha256 = \"27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-derive/0.14.3/download\"],\n strip_prefix = \"prost-derive-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-derive-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-reflect-0.16.5\",\n sha256 = \"01b80ea363c31af2de2b92e3c07ed1156628f7838c4afb4df75ee78a37fedbd1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-reflect/0.16.5/download\"],\n strip_prefix = \"prost-reflect-0.16.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-reflect-0.16.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-types-0.14.3\",\n sha256 = \"8991c4cbdb8bc5b11f0b074ffe286c30e523de90fee5ba8132f1399f23cb3dd7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-types/0.14.3/download\"],\n strip_prefix = \"prost-types-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-types-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__protox-0.9.1\",\n sha256 = \"4f25a07a73c6717f0b9bbbd685918f5df9815f7efba450b83d9c9dea41f0e3a1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/protox/0.9.1/download\"],\n strip_prefix = \"protox-0.9.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.protox-0.9.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__protox-parse-0.9.0\",\n sha256 = \"072eee358134396a4643dff81cfff1c255c9fbd3fb296be14bdb6a26f9156366\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/protox-parse/0.9.0/download\"],\n strip_prefix = \"protox-parse-0.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.protox-parse-0.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__psm-0.1.24\",\n sha256 = \"200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/psm/0.1.24/download\"],\n strip_prefix = \"psm-0.1.24\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.psm-0.1.24.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__quick-xml-0.41.0\",\n sha256 = \"e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/quick-xml/0.41.0/download\"],\n strip_prefix = \"quick-xml-0.41.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.quick-xml-0.41.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__quote-1.0.47\",\n sha256 = \"1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/quote/1.0.47/download\"],\n strip_prefix = \"quote-1.0.47\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.quote-1.0.47.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__r-efi-6.0.0\",\n sha256 = \"f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/r-efi/6.0.0/download\"],\n strip_prefix = \"r-efi-6.0.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.r-efi-6.0.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__redox_syscall-0.5.18\",\n sha256 = \"ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/redox_syscall/0.5.18/download\"],\n strip_prefix = \"redox_syscall-0.5.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.redox_syscall-0.5.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__regex-1.12.3\",\n sha256 = \"e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/regex/1.12.3/download\"],\n strip_prefix = \"regex-1.12.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.regex-1.12.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__regex-automata-0.4.18\",\n sha256 = \"ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/regex-automata/0.4.18/download\"],\n strip_prefix = \"regex-automata-0.4.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.regex-automata-0.4.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__regex-syntax-0.8.11\",\n sha256 = \"d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/regex-syntax/0.8.11/download\"],\n strip_prefix = \"regex-syntax-0.8.11\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.regex-syntax-0.8.11.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__ring-0.17.14\",\n sha256 = \"a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/ring/0.17.14/download\"],\n strip_prefix = \"ring-0.17.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.ring-0.17.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustc_version-0.4.1\",\n sha256 = \"cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustc_version/0.4.1/download\"],\n strip_prefix = \"rustc_version-0.4.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustc_version-0.4.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rusticata-macros-4.1.0\",\n sha256 = \"faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rusticata-macros/4.1.0/download\"],\n strip_prefix = \"rusticata-macros-4.1.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rusticata-macros-4.1.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustix-1.1.5\",\n sha256 = \"891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustix/1.1.5/download\"],\n strip_prefix = \"rustix-1.1.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustix-1.1.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustls-0.23.46\",\n sha256 = \"48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustls/0.23.46/download\"],\n strip_prefix = \"rustls-0.23.46\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustls-0.23.46.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustls-pki-types-1.15.1\",\n sha256 = \"2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustls-pki-types/1.15.1/download\"],\n strip_prefix = \"rustls-pki-types-1.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustls-pki-types-1.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustls-webpki-0.103.16\",\n sha256 = \"4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustls-webpki/0.103.16/download\"],\n strip_prefix = \"rustls-webpki-0.103.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustls-webpki-0.103.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustversion-1.0.23\",\n sha256 = \"cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustversion/1.0.23/download\"],\n strip_prefix = \"rustversion-1.0.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustversion-1.0.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__ryu-1.0.23\",\n sha256 = \"9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/ryu/1.0.23/download\"],\n strip_prefix = \"ryu-1.0.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.ryu-1.0.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__s2rst-0.5.1\",\n sha256 = \"32427bddb68a5cc8b2ff1f697ad92a97658a7bbdd9c9dd50604bd228634ea261\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/s2rst/0.5.1/download\"],\n strip_prefix = \"s2rst-0.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.s2rst-0.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__same-file-1.0.6\",\n sha256 = \"93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/same-file/1.0.6/download\"],\n strip_prefix = \"same-file-1.0.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.same-file-1.0.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__scopeguard-1.2.0\",\n sha256 = \"94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/scopeguard/1.2.0/download\"],\n strip_prefix = \"scopeguard-1.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.scopeguard-1.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__scratch-1.0.9\",\n sha256 = \"d68f2ec51b097e4c1a75b681a8bec621909b5e91f15bb7b840c4f2f7b01148b2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/scratch/1.0.9/download\"],\n strip_prefix = \"scratch-1.0.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.scratch-1.0.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__semver-1.0.28\",\n sha256 = \"8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/semver/1.0.28/download\"],\n strip_prefix = \"semver-1.0.28\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.semver-1.0.28.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde-1.0.229\",\n sha256 = \"4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde/1.0.229/download\"],\n strip_prefix = \"serde-1.0.229\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde-1.0.229.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_buf-0.1.3\",\n sha256 = \"58b57892601430298e96ce14d68f61dff758b648da87f3d491fbe5ec523e749e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_buf/0.1.3/download\"],\n strip_prefix = \"serde_buf-0.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_buf-0.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_core-1.0.229\",\n sha256 = \"67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_core/1.0.229/download\"],\n strip_prefix = \"serde_core-1.0.229\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_core-1.0.229.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_derive-1.0.229\",\n sha256 = \"e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_derive/1.0.229/download\"],\n strip_prefix = \"serde_derive-1.0.229\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_derive-1.0.229.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_fmt-1.1.0\",\n sha256 = \"6e497af288b3b95d067a23a4f749f2861121ffcb2f6d8379310dcda040c345ed\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_fmt/1.1.0/download\"],\n strip_prefix = \"serde_fmt-1.1.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_fmt-1.1.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_json-1.0.151\",\n sha256 = \"c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_json/1.0.151/download\"],\n strip_prefix = \"serde_json-1.0.151\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_json-1.0.151.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__shlex-2.0.1\",\n sha256 = \"f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/shlex/2.0.1/download\"],\n strip_prefix = \"shlex-2.0.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.shlex-2.0.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__simsimd-6.5.16\",\n sha256 = \"f4fb3bc3cdce07a7d7d4caa4c54f8aa967f6be41690482b54b24100a2253fa70\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/simsimd/6.5.16/download\"],\n strip_prefix = \"simsimd-6.5.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.simsimd-6.5.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__slab-0.4.12\",\n sha256 = \"0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/slab/0.4.12/download\"],\n strip_prefix = \"slab-0.4.12\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.slab-0.4.12.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__smallvec-1.16.2\",\n sha256 = \"f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/smallvec/1.16.2/download\"],\n strip_prefix = \"smallvec-1.16.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.smallvec-1.16.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__socket2-0.6.5\",\n sha256 = \"c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/socket2/0.6.5/download\"],\n strip_prefix = \"socket2-0.6.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.socket2-0.6.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__spdlog-internal-0.2.1\",\n sha256 = \"6eb988bafd6393bd840d78ba07826c857060bb1ba473bd57e8ae4d10a77eb276\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/spdlog-internal/0.2.1/download\"],\n strip_prefix = \"spdlog-internal-0.2.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.spdlog-internal-0.2.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__spdlog-macros-0.3.1\",\n sha256 = \"b9a23693b67ee8c1515d2043ddd01ea3561872cf1f19bc00947857c0184a62aa\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/spdlog-macros/0.3.1/download\"],\n strip_prefix = \"spdlog-macros-0.3.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.spdlog-macros-0.3.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__spdlog-rs-0.5.3\",\n patch_args = [\n \"-p1\",\n ],\n patches = [\n \"@@//bazel:spdlog-rs-emscripten.diff\",\n ],\n sha256 = \"7415ec666ebcaa1d92c5d9fba5d0b44e1a9fdddc8df6c0b2c45e89af8b830b6d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/spdlog-rs/0.5.3/download\"],\n strip_prefix = \"spdlog-rs-0.5.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.spdlog-rs-0.5.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__subtle-2.6.1\",\n sha256 = \"13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/subtle/2.6.1/download\"],\n strip_prefix = \"subtle-2.6.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.subtle-2.6.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval-2.22.0\",\n sha256 = \"b81b254da21fe1fcc4e3a74fe39b46e25e3a863078f8b71c954d47f84889dbc6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval/2.22.0/download\"],\n strip_prefix = \"sval-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_buffer-2.22.0\",\n sha256 = \"50be352d2822ffafb59e3e2ddac9d5ee60f2eeadbb7b5a2a951b9f3651e87a6f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_buffer/2.22.0/download\"],\n strip_prefix = \"sval_buffer-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_buffer-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_dynamic-2.22.0\",\n sha256 = \"b048ca293b998d9a45659159f94a64063791e74cdc670164943dbb434405573d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_dynamic/2.22.0/download\"],\n strip_prefix = \"sval_dynamic-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_dynamic-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_fmt-2.22.0\",\n sha256 = \"e6b5888e40f80568733217f27b7317b845f463400ced36c424b1a804730e53b2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_fmt/2.22.0/download\"],\n strip_prefix = \"sval_fmt-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_fmt-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_json-2.22.0\",\n sha256 = \"e17664d6bb6b74947afaab9d7c991caa9bf5638d4dee16fcbef637f440796049\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_json/2.22.0/download\"],\n strip_prefix = \"sval_json-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_json-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_nested-2.22.0\",\n sha256 = \"07c059969ca5ca163ea7fef6c9661758973d17691aba92abdcf5c428f4ec122c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_nested/2.22.0/download\"],\n strip_prefix = \"sval_nested-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_nested-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_ref-2.22.0\",\n sha256 = \"42d6b29ff568c85c87561807f51d2adfff4b6016c6363133f7cd1652a12548f3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_ref/2.22.0/download\"],\n strip_prefix = \"sval_ref-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_ref-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_serde-2.22.0\",\n sha256 = \"8f33ec9edc42b12764d5c90ca0a1d84189c6bde81ed27507f1e661c6e4e05853\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_serde/2.22.0/download\"],\n strip_prefix = \"sval_serde-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_serde-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__syn-2.0.119\",\n sha256 = \"872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/syn/2.0.119/download\"],\n strip_prefix = \"syn-2.0.119\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.syn-2.0.119.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__syn-3.0.6\",\n sha256 = \"8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/syn/3.0.6/download\"],\n strip_prefix = \"syn-3.0.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.syn-3.0.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sync_wrapper-1.0.2\",\n sha256 = \"0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sync_wrapper/1.0.2/download\"],\n strip_prefix = \"sync_wrapper-1.0.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sync_wrapper-1.0.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__synstructure-0.13.2\",\n sha256 = \"728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/synstructure/0.13.2/download\"],\n strip_prefix = \"synstructure-0.13.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.synstructure-0.13.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tempfile-3.27.0\",\n sha256 = \"32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tempfile/3.27.0/download\"],\n strip_prefix = \"tempfile-3.27.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tempfile-3.27.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__termcolor-1.4.1\",\n sha256 = \"06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/termcolor/1.4.1/download\"],\n strip_prefix = \"termcolor-1.4.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.termcolor-1.4.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__thiserror-2.0.21\",\n sha256 = \"09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/thiserror/2.0.21/download\"],\n strip_prefix = \"thiserror-2.0.21\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.thiserror-2.0.21.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__thiserror-impl-2.0.21\",\n sha256 = \"fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/thiserror-impl/2.0.21/download\"],\n strip_prefix = \"thiserror-impl-2.0.21\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.thiserror-impl-2.0.21.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__time-0.3.55\",\n sha256 = \"cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/time/0.3.55/download\"],\n strip_prefix = \"time-0.3.55\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.time-0.3.55.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__time-core-0.1.9\",\n sha256 = \"9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/time-core/0.1.9/download\"],\n strip_prefix = \"time-core-0.1.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.time-core-0.1.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__time-macros-0.2.32\",\n sha256 = \"7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/time-macros/0.2.32/download\"],\n strip_prefix = \"time-macros-0.2.32\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.time-macros-0.2.32.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-1.52.3\",\n sha256 = \"8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio/1.52.3/download\"],\n strip_prefix = \"tokio-1.52.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-1.52.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-macros-2.7.0\",\n sha256 = \"385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-macros/2.7.0/download\"],\n strip_prefix = \"tokio-macros-2.7.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-macros-2.7.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-rustls-0.26.4\",\n sha256 = \"1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-rustls/0.26.4/download\"],\n strip_prefix = \"tokio-rustls-0.26.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-rustls-0.26.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-stream-0.1.18\",\n sha256 = \"32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-stream/0.1.18/download\"],\n strip_prefix = \"tokio-stream-0.1.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-stream-0.1.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-util-0.7.18\",\n sha256 = \"9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-util/0.7.18/download\"],\n strip_prefix = \"tokio-util-0.7.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-util-0.7.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-0.14.6\",\n sha256 = \"ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic/0.14.6/download\"],\n strip_prefix = \"tonic-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-build-0.14.6\",\n sha256 = \"c68f61875ac5293cf72e6c8cf0158086428c82c37229e98c840878f1706b0322\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic-build/0.14.6/download\"],\n strip_prefix = \"tonic-build-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-build-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-prost-0.14.6\",\n sha256 = \"50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic-prost/0.14.6/download\"],\n strip_prefix = \"tonic-prost-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-prost-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-prost-build-0.14.6\",\n sha256 = \"654e5643eff75d7f8c99197ce1440ed19a3474eada74c12bbac488b2cafdae27\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic-prost-build/0.14.6/download\"],\n strip_prefix = \"tonic-prost-build-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-prost-build-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tower-0.5.3\",\n sha256 = \"ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tower/0.5.3/download\"],\n strip_prefix = \"tower-0.5.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tower-0.5.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tower-layer-0.3.3\",\n sha256 = \"121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tower-layer/0.3.3/download\"],\n strip_prefix = \"tower-layer-0.3.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tower-layer-0.3.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tower-service-0.3.3\",\n sha256 = \"8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tower-service/0.3.3/download\"],\n strip_prefix = \"tower-service-0.3.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tower-service-0.3.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tracing-0.1.44\",\n sha256 = \"63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tracing/0.1.44/download\"],\n strip_prefix = \"tracing-0.1.44\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tracing-0.1.44.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tracing-attributes-0.1.31\",\n sha256 = \"7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tracing-attributes/0.1.31/download\"],\n strip_prefix = \"tracing-attributes-0.1.31\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tracing-attributes-0.1.31.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tracing-core-0.1.36\",\n sha256 = \"db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tracing-core/0.1.36/download\"],\n strip_prefix = \"tracing-core-0.1.36\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tracing-core-0.1.36.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__try-lock-0.2.5\",\n sha256 = \"e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/try-lock/0.2.5/download\"],\n strip_prefix = \"try-lock-0.2.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.try-lock-0.2.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__typeid-1.0.3\",\n sha256 = \"bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/typeid/1.0.3/download\"],\n strip_prefix = \"typeid-1.0.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.typeid-1.0.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__unicode-ident-1.0.26\",\n sha256 = \"d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/unicode-ident/1.0.26/download\"],\n strip_prefix = \"unicode-ident-1.0.26\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.unicode-ident-1.0.26.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__unicode-width-0.1.14\",\n sha256 = \"7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/unicode-width/0.1.14/download\"],\n strip_prefix = \"unicode-width-0.1.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.unicode-width-0.1.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__unicode-width-0.2.2\",\n sha256 = \"b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/unicode-width/0.2.2/download\"],\n strip_prefix = \"unicode-width-0.2.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.unicode-width-0.2.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__untrusted-0.9.0\",\n sha256 = \"8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/untrusted/0.9.0/download\"],\n strip_prefix = \"untrusted-0.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.untrusted-0.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__uuid-1.29.0\",\n sha256 = \"4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/uuid/1.29.0/download\"],\n strip_prefix = \"uuid-1.29.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.uuid-1.29.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__value-bag-1.14.1\",\n sha256 = \"2799ffb329a792ecfd902b71306c8a815a6ef1c0470fa9953a6aa4d4cecbe511\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/value-bag/1.14.1/download\"],\n strip_prefix = \"value-bag-1.14.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.value-bag-1.14.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__value-bag-serde1-1.14.1\",\n sha256 = \"0941feceafbe7a8f59ea1096d45b97002884a41306315ad797b3684b63a81d8c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/value-bag-serde1/1.14.1/download\"],\n strip_prefix = \"value-bag-serde1-1.14.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.value-bag-serde1-1.14.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__value-bag-sval2-1.14.1\",\n sha256 = \"839752af8179287d27eb2b94164641b1ede9e60ab7424163388dc21ebd0508cd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/value-bag-sval2/1.14.1/download\"],\n strip_prefix = \"value-bag-sval2-1.14.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.value-bag-sval2-1.14.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__walkdir-2.5.0\",\n sha256 = \"29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/walkdir/2.5.0/download\"],\n strip_prefix = \"walkdir-2.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.walkdir-2.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__want-0.3.1\",\n sha256 = \"bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/want/0.3.1/download\"],\n strip_prefix = \"want-0.3.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.want-0.3.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasi-0.11.1-wasi-snapshot-preview1\",\n sha256 = \"ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasi/0.11.1+wasi-snapshot-preview1/download\"],\n strip_prefix = \"wasi-0.11.1+wasi-snapshot-preview1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasi-0.11.1+wasi-snapshot-preview1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-0.2.129\",\n sha256 = \"9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-macro-0.2.129\",\n sha256 = \"2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen-macro/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-macro-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-macro-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-macro-support-0.2.129\",\n sha256 = \"6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen-macro-support/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-macro-support-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-macro-support-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-shared-0.2.129\",\n sha256 = \"23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen-shared/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-shared-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-shared-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-0.3.9\",\n sha256 = \"5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi/0.3.9/download\"],\n strip_prefix = \"winapi-0.3.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-0.3.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-i686-pc-windows-gnu-0.4.0\",\n sha256 = \"ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi-i686-pc-windows-gnu/0.4.0/download\"],\n strip_prefix = \"winapi-i686-pc-windows-gnu-0.4.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-util-0.1.11\",\n sha256 = \"c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi-util/0.1.11/download\"],\n strip_prefix = \"winapi-util-0.1.11\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-util-0.1.11.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-x86_64-pc-windows-gnu-0.4.0\",\n sha256 = \"712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi-x86_64-pc-windows-gnu/0.4.0/download\"],\n strip_prefix = \"winapi-x86_64-pc-windows-gnu-0.4.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-core-0.62.2\",\n sha256 = \"b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-core/0.62.2/download\"],\n strip_prefix = \"windows-core-0.62.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-core-0.62.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-implement-0.60.2\",\n sha256 = \"053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-implement/0.60.2/download\"],\n strip_prefix = \"windows-implement-0.60.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-implement-0.60.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-interface-0.59.3\",\n sha256 = \"3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-interface/0.59.3/download\"],\n strip_prefix = \"windows-interface-0.59.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-interface-0.59.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-link-0.2.1\",\n sha256 = \"f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-link/0.2.1/download\"],\n strip_prefix = \"windows-link-0.2.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-link-0.2.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-result-0.4.1\",\n sha256 = \"7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-result/0.4.1/download\"],\n strip_prefix = \"windows-result-0.4.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-result-0.4.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-strings-0.5.1\",\n sha256 = \"7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-strings/0.5.1/download\"],\n strip_prefix = \"windows-strings-0.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-strings-0.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-sys-0.52.0\",\n sha256 = \"282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-sys/0.52.0/download\"],\n strip_prefix = \"windows-sys-0.52.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-sys-0.52.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-sys-0.61.2\",\n sha256 = \"ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-sys/0.61.2/download\"],\n strip_prefix = \"windows-sys-0.61.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-sys-0.61.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-targets-0.52.6\",\n sha256 = \"9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-targets/0.52.6/download\"],\n strip_prefix = \"windows-targets-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-targets-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_aarch64_gnullvm-0.52.6\",\n sha256 = \"32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_aarch64_gnullvm/0.52.6/download\"],\n strip_prefix = \"windows_aarch64_gnullvm-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_aarch64_gnullvm-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_aarch64_msvc-0.52.6\",\n sha256 = \"09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_aarch64_msvc/0.52.6/download\"],\n strip_prefix = \"windows_aarch64_msvc-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_aarch64_msvc-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_i686_gnu-0.52.6\",\n sha256 = \"8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_i686_gnu/0.52.6/download\"],\n strip_prefix = \"windows_i686_gnu-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_i686_gnu-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_i686_gnullvm-0.52.6\",\n sha256 = \"0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_i686_gnullvm/0.52.6/download\"],\n strip_prefix = \"windows_i686_gnullvm-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_i686_gnullvm-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_i686_msvc-0.52.6\",\n sha256 = \"240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_i686_msvc/0.52.6/download\"],\n strip_prefix = \"windows_i686_msvc-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_i686_msvc-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_x86_64_gnu-0.52.6\",\n sha256 = \"147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_x86_64_gnu/0.52.6/download\"],\n strip_prefix = \"windows_x86_64_gnu-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_x86_64_gnu-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_x86_64_gnullvm-0.52.6\",\n sha256 = \"24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_x86_64_gnullvm/0.52.6/download\"],\n strip_prefix = \"windows_x86_64_gnullvm-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_x86_64_gnullvm-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_x86_64_msvc-0.52.6\",\n sha256 = \"589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_x86_64_msvc/0.52.6/download\"],\n strip_prefix = \"windows_x86_64_msvc-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_x86_64_msvc-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__x509-parser-0.18.1\",\n sha256 = \"d43b0f71ce057da06bc0851b23ee24f3f86190b07203dd8f567d0b706a185202\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/x509-parser/0.18.1/download\"],\n strip_prefix = \"x509-parser-0.18.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.x509-parser-0.18.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zerocopy-0.8.58\",\n sha256 = \"c17e8fafad82b542ff3717217ecdc736231b59e387768c9630123b4ce4d2db44\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zerocopy/0.8.58/download\"],\n strip_prefix = \"zerocopy-0.8.58\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zerocopy-0.8.58.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zerocopy-derive-0.8.58\",\n sha256 = \"595f56e044df4f46a0c9a626f65c3d99eb8488f7e8a8baa12dd76326d9710bf2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zerocopy-derive/0.8.58/download\"],\n strip_prefix = \"zerocopy-derive-0.8.58\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zerocopy-derive-0.8.58.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zeroize-1.9.0\",\n sha256 = \"e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zeroize/1.9.0/download\"],\n strip_prefix = \"zeroize-1.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zeroize-1.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zlib-rs-0.6.8\",\n sha256 = \"b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zlib-rs/0.6.8/download\"],\n strip_prefix = \"zlib-rs-0.6.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zlib-rs-0.6.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zmij-1.0.23\",\n sha256 = \"29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zmij/1.0.23/download\"],\n strip_prefix = \"zmij-1.0.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zmij-1.0.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zstd-safe-8.2.0\",\n sha256 = \"ded520f16b29e1a9b771c722221b2b0a0398c2316d9bb3c42b458a5414d7434b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zstd-safe/8.2.0/download\"],\n strip_prefix = \"zstd-safe-8.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zstd-safe-8.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zstd-sys-2.1.2-zstd.1.5.7\",\n sha256 = \"481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zstd-sys/2.1.2+zstd.1.5.7/download\"],\n strip_prefix = \"zstd-sys-2.1.2+zstd.1.5.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zstd-sys-2.1.2+zstd.1.5.7.bazel\"),\n )\n\n return [\n struct(repo = \"rust_crates\", is_dev_dep = False),\n struct(repo=\"rust_crates__chrono-0.4.45\", is_dev_dep = False),\n struct(repo=\"rust_crates__cxx-1.0.202\", is_dev_dep = False),\n struct(repo=\"rust_crates__fancy-regex-0.20.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__fast-float2-0.2.4\", is_dev_dep = False),\n struct(repo=\"rust_crates__getrandom-0.4.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__globset-0.4.18\", is_dev_dep = False),\n struct(repo=\"rust_crates__libc-0.2.189\", is_dev_dep = False),\n struct(repo=\"rust_crates__libm-0.2.16\", is_dev_dep = False),\n struct(repo=\"rust_crates__log-0.4.34\", is_dev_dep = False),\n struct(repo=\"rust_crates__memchr-2.8.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__mio-1.2.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__peg-0.8.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__prost-0.14.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__prost-build-0.14.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__prost-types-0.14.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__protox-0.9.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__psm-0.1.24\", is_dev_dep = False),\n struct(repo=\"rust_crates__quick-xml-0.41.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__rustls-0.23.46\", is_dev_dep = False),\n struct(repo=\"rust_crates__rustls-pki-types-1.15.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__ryu-1.0.23\", is_dev_dep = False),\n struct(repo=\"rust_crates__s2rst-0.5.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__serde-1.0.229\", is_dev_dep = False),\n struct(repo=\"rust_crates__serde_json-1.0.151\", is_dev_dep = False),\n struct(repo=\"rust_crates__simsimd-6.5.16\", is_dev_dep = False),\n struct(repo=\"rust_crates__slab-0.4.12\", is_dev_dep = False),\n struct(repo=\"rust_crates__socket2-0.6.5\", is_dev_dep = False),\n struct(repo=\"rust_crates__spdlog-rs-0.5.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__tokio-1.52.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__tokio-stream-0.1.18\", is_dev_dep = False),\n struct(repo=\"rust_crates__tonic-0.14.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__tonic-prost-0.14.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__tonic-prost-build-0.14.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__uuid-1.29.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__walkdir-2.5.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__windows-sys-0.61.2\", is_dev_dep = False),\n struct(repo=\"rust_crates__x509-parser-0.18.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__zlib-rs-0.6.8\", is_dev_dep = False),\n struct(repo=\"rust_crates__zstd-safe-8.2.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__zstd-sys-2.1.2-zstd.1.5.7\", is_dev_dep = False),\n ]\n", + "crates.bzl": "###############################################################################\n# @generated\n# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To \n# regenerate this file, run the following:\n#\n# bazel mod show_repo 'seekdb'\n###############################################################################\n\"\"\"\n# `crates_repository` API\n\n- [aliases](#aliases)\n- [crate_edition](#crate_edition)\n- [crate_deps](#crate_deps)\n- [all_crate_deps](#all_crate_deps)\n- [crate_repositories](#crate_repositories)\n\n\"\"\"\n\nload(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\nload(\"@bazel_tools//tools/build_defs/repo:utils.bzl\", \"maybe\")\nload(\"@bazel_skylib//lib:selects.bzl\", \"selects\")\nload(\"@rules_rust//crate_universe:defs.bzl\", \"crates_vendor_remote_repository\", \"local_crate_mirror\")\n\n###############################################################################\n# MACROS API\n###############################################################################\n\n# An identifier that represent common dependencies (unconditional).\n_COMMON_CONDITION = \"\"\n\ndef _flatten_dependency_maps(all_dependency_maps):\n \"\"\"Flatten a list of dependency maps into one dictionary.\n\n Dependency maps have the following structure:\n\n ```python\n DEPENDENCIES_MAP = {\n # The first key in the map is a Bazel package\n # name of the workspace this file is defined in.\n \"workspace_member_package\": {\n\n # Not all dependencies are supported for all platforms.\n # the condition key is the condition required to be true\n # on the host platform.\n \"condition\": {\n\n # An alias to a crate target. # The label of the crate target the\n # Aliases are only crate names. # package name refers to.\n \"package_name\": \"@full//:label\",\n }\n }\n }\n ```\n\n Args:\n all_dependency_maps (list): A list of dicts as described above\n\n Returns:\n dict: A dictionary as described above\n \"\"\"\n dependencies = {}\n\n for workspace_deps_map in all_dependency_maps:\n for pkg_name, conditional_deps_map in workspace_deps_map.items():\n if pkg_name not in dependencies:\n non_frozen_map = dict()\n for key, values in conditional_deps_map.items():\n non_frozen_map.update({key: dict(values.items())})\n dependencies.setdefault(pkg_name, non_frozen_map)\n continue\n\n for condition, deps_map in conditional_deps_map.items():\n # If the condition has not been recorded, do so and continue\n if condition not in dependencies[pkg_name]:\n dependencies[pkg_name].setdefault(condition, dict(deps_map.items()))\n continue\n\n # Alert on any miss-matched dependencies\n inconsistent_entries = []\n for crate_name, crate_label in deps_map.items():\n existing = dependencies[pkg_name][condition].get(crate_name)\n if existing and existing != crate_label:\n inconsistent_entries.append((crate_name, existing, crate_label))\n dependencies[pkg_name][condition].update({crate_name: crate_label})\n\n return dependencies\n\ndef crate_deps(deps, package_name = None):\n \"\"\"Finds the fully qualified label of the requested crates for the package where this macro is called.\n\n Args:\n deps (list): The desired list of crate targets.\n package_name (str, optional): The package name of the set of dependencies to look up.\n Defaults to `native.package_name()`.\n\n Returns:\n list: A list of labels to generated rust targets (str)\n \"\"\"\n\n if not deps:\n return []\n\n if package_name == None:\n package_name = native.package_name()\n\n # Join both sets of dependencies\n dependencies = _flatten_dependency_maps([\n _NORMAL_DEPENDENCIES,\n _NORMAL_DEV_DEPENDENCIES,\n _PROC_MACRO_DEPENDENCIES,\n _PROC_MACRO_DEV_DEPENDENCIES,\n _BUILD_DEPENDENCIES,\n _BUILD_PROC_MACRO_DEPENDENCIES,\n ]).pop(package_name, {})\n\n # Combine all conditional packages so we can easily index over a flat list\n # TODO: Perhaps this should actually return select statements and maintain\n # the conditionals of the dependencies\n flat_deps = {}\n for deps_set in dependencies.values():\n for crate_name, crate_label in deps_set.items():\n flat_deps.update({crate_name: crate_label})\n\n missing_crates = []\n crate_targets = []\n for crate_target in deps:\n if crate_target not in flat_deps:\n missing_crates.append(crate_target)\n else:\n crate_targets.append(flat_deps[crate_target])\n\n if missing_crates:\n fail(\"Could not find crates `{}` among dependencies of `{}`. Available dependencies were `{}`\".format(\n missing_crates,\n package_name,\n dependencies,\n ))\n\n return crate_targets\n\ndef crate_edition(package_name = None):\n \"\"\"Finds the Rust edition for the package where this macro is called.\n\n Args:\n package_name (str, optional): The package name whose edition should be\n looked up. Defaults to `native.package_name()` when unset.\n\n Returns:\n str: The Rust edition declared by the package's Cargo.toml file.\n \"\"\"\n if package_name == None:\n package_name = native.package_name()\n\n if package_name not in _CRATE_EDITIONS:\n fail(\"Tried to get crate_edition for package \" + package_name + \" but that package had no Cargo.toml file\")\n\n return _CRATE_EDITIONS[package_name]\n\ndef all_crate_deps(\n normal = False, \n normal_dev = False, \n proc_macro = False, \n proc_macro_dev = False,\n build = False,\n build_proc_macro = False,\n package_name = None):\n \"\"\"Finds the fully qualified label of all requested direct crate dependencies \\\n for the package where this macro is called.\n\n If no parameters are set, all normal dependencies are returned. Setting any one flag will\n otherwise impact the contents of the returned list.\n\n Args:\n normal (bool, optional): If True, normal dependencies are included in the\n output list.\n normal_dev (bool, optional): If True, normal dev dependencies will be\n included in the output list.\n proc_macro (bool, optional): If True, proc_macro dependencies are included\n in the output list.\n proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are\n included in the output list.\n build (bool, optional): If True, build dependencies are included\n in the output list.\n build_proc_macro (bool, optional): If True, build proc_macro dependencies are\n included in the output list.\n package_name (str, optional): The package name of the set of dependencies to look up.\n Defaults to `native.package_name()` when unset.\n\n Returns:\n list: A list of labels to generated rust targets (str)\n \"\"\"\n\n if package_name == None:\n package_name = native.package_name()\n\n # Determine the relevant maps to use\n all_dependency_maps = []\n if normal:\n all_dependency_maps.append(_NORMAL_DEPENDENCIES)\n if normal_dev:\n all_dependency_maps.append(_NORMAL_DEV_DEPENDENCIES)\n if proc_macro:\n all_dependency_maps.append(_PROC_MACRO_DEPENDENCIES)\n if proc_macro_dev:\n all_dependency_maps.append(_PROC_MACRO_DEV_DEPENDENCIES)\n if build:\n all_dependency_maps.append(_BUILD_DEPENDENCIES)\n if build_proc_macro:\n all_dependency_maps.append(_BUILD_PROC_MACRO_DEPENDENCIES)\n\n # Default to always using normal dependencies\n if not all_dependency_maps:\n all_dependency_maps.append(_NORMAL_DEPENDENCIES)\n\n dependencies = _flatten_dependency_maps(all_dependency_maps).pop(package_name, None)\n\n if not dependencies:\n if dependencies == None:\n fail(\"Tried to get all_crate_deps for package \" + package_name + \" but that package had no Cargo.toml file\")\n else:\n return []\n\n crate_deps = list(dependencies.pop(_COMMON_CONDITION, {}).values())\n for condition, deps in dependencies.items():\n crate_deps += selects.with_or({\n tuple(_CONDITIONS[condition]): deps.values(),\n \"//conditions:default\": [],\n })\n\n return crate_deps\n\ndef aliases(\n normal = False,\n normal_dev = False,\n proc_macro = False,\n proc_macro_dev = False,\n build = False,\n build_proc_macro = False,\n package_name = None):\n \"\"\"Produces a map of Crate alias names to their original label\n\n If no dependency kinds are specified, `normal` and `proc_macro` are used by default.\n Setting any one flag will otherwise determine the contents of the returned dict.\n\n Args:\n normal (bool, optional): If True, normal dependencies are included in the\n output list.\n normal_dev (bool, optional): If True, normal dev dependencies will be\n included in the output list..\n proc_macro (bool, optional): If True, proc_macro dependencies are included\n in the output list.\n proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are\n included in the output list.\n build (bool, optional): If True, build dependencies are included\n in the output list.\n build_proc_macro (bool, optional): If True, build proc_macro dependencies are\n included in the output list.\n package_name (str, optional): The package name of the set of dependencies to look up.\n Defaults to `native.package_name()` when unset.\n\n Returns:\n dict: The aliases of all associated packages\n \"\"\"\n if package_name == None:\n package_name = native.package_name()\n\n # Determine the relevant maps to use\n all_aliases_maps = []\n if normal:\n all_aliases_maps.append(_NORMAL_ALIASES)\n if normal_dev:\n all_aliases_maps.append(_NORMAL_DEV_ALIASES)\n if proc_macro:\n all_aliases_maps.append(_PROC_MACRO_ALIASES)\n if proc_macro_dev:\n all_aliases_maps.append(_PROC_MACRO_DEV_ALIASES)\n if build:\n all_aliases_maps.append(_BUILD_ALIASES)\n if build_proc_macro:\n all_aliases_maps.append(_BUILD_PROC_MACRO_ALIASES)\n\n # Default to always using normal aliases\n if not all_aliases_maps:\n all_aliases_maps.append(_NORMAL_ALIASES)\n all_aliases_maps.append(_PROC_MACRO_ALIASES)\n\n aliases = _flatten_dependency_maps(all_aliases_maps).pop(package_name, None)\n\n if not aliases:\n return dict()\n\n common_items = aliases.pop(_COMMON_CONDITION, {}).items()\n\n # If there are only common items in the dictionary, immediately return them\n if not len(aliases.keys()) == 1:\n return dict(common_items)\n\n # Build a single select statement where each conditional has accounted for the\n # common set of aliases.\n crate_aliases = {\"//conditions:default\": dict(common_items)}\n for condition, deps in aliases.items():\n condition_triples = _CONDITIONS[condition]\n for triple in condition_triples:\n if triple in crate_aliases:\n crate_aliases[triple].update(deps)\n else:\n crate_aliases.update({triple: dict(deps.items() + common_items)})\n\n return select(crate_aliases)\n\n###############################################################################\n# WORKSPACE MEMBER DEPS, ALIASES, AND EDITIONS\n###############################################################################\n\n_CRATE_EDITIONS = {\n \"rust/compression\": \"2021\",\n \"rust/config\": \"2021\",\n \"rust/crypto\": \"2021\",\n \"rust/file-io\": \"2021\",\n \"rust/http-client\": \"2021\",\n \"rust/in-process\": \"2021\",\n \"rust/json\": \"2021\",\n \"rust/kv\": \"2021\",\n \"rust/local\": \"2021\",\n \"rust/logger\": \"2021\",\n \"rust/math\": \"2021\",\n \"rust/mvt\": \"2021\",\n \"rust/number-parser\": \"2021\",\n \"rust/path-utils\": \"2021\",\n \"bazel/prost-codegen\": \"2021\",\n \"rust/regex-engine\": \"2021\",\n \"rust/rpc\": \"2021\",\n \"rust/seekdb-rust\": \"2021\",\n \"rust/spatial-covering\": \"2024\",\n \"rust/sql-nio\": \"2021\",\n \"rust/sql-parser\": \"2021\",\n \"rust/standby-rpc\": \"2021\",\n \"rust/storage-io\": \"2021\",\n \"rust/tmp-file\": \"2021\",\n \"rust/uuid-generator\": \"2021\",\n \"rust/vector-kernels\": \"2021\",\n \"rust/wal\": \"2021\",\n \"rust/xml-parser\": \"2021\",\n}\n\n_NORMAL_DEPENDENCIES = {\n \"rust/compression\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"zlib-rs\": Label(\"@rust_crates//zlib-rs-0.6.8\"),\n \"zstd-safe\": Label(\"@rust_crates//zstd-safe-8.2.0\"),\n \"zstd-sys\": Label(\"@rust_crates//zstd-sys-2.1.2+zstd.1.5.7\"),\n },\n },\n \"rust/config\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/crypto\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/file-io\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n },\n \"cfg(windows)\": {\n \"windows-sys\": Label(\"@rust_crates//windows-sys-0.61.2\"),\n },\n },\n \"rust/http-client\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/in-process\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n },\n },\n \"rust/json\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"memchr\": Label(\"@rust_crates//memchr-2.8.3\"),\n \"ryu\": Label(\"@rust_crates//ryu-1.0.23\"),\n \"serde\": Label(\"@rust_crates//serde-1.0.229\"),\n \"serde_json\": Label(\"@rust_crates//serde_json-1.0.151\"),\n },\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n },\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n \"chrono\": Label(\"@rust_crates//chrono-0.4.45\"),\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"log\": Label(\"@rust_crates//log-0.4.34\"),\n \"spdlog-rs\": Label(\"@rust_crates//spdlog-rs-0.5.3\"),\n },\n },\n \"rust/math\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"libm\": Label(\"@rust_crates//libm-0.2.16\"),\n },\n },\n \"rust/mvt\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"prost\": Label(\"@rust_crates//prost-0.14.3\"),\n },\n },\n \"rust/number-parser\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"fast-float2\": Label(\"@rust_crates//fast-float2-0.2.4\"),\n },\n },\n \"rust/path-utils\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"globset\": Label(\"@rust_crates//globset-0.4.18\"),\n \"walkdir\": Label(\"@rust_crates//walkdir-2.5.0\"),\n },\n },\n \"bazel/prost-codegen\": {\n _COMMON_CONDITION: {\n \"prost-build\": Label(\"@rust_crates//prost-build-0.14.3\"),\n \"prost-types\": Label(\"@rust_crates//prost-types-0.14.3\"),\n \"protox\": Label(\"@rust_crates//protox-0.9.1\"),\n \"tonic-prost-build\": Label(\"@rust_crates//tonic-prost-build-0.14.6\"),\n },\n },\n \"rust/regex-engine\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"fancy-regex\": Label(\"@rust_crates//fancy-regex-0.20.0\"),\n },\n },\n \"rust/rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n \"rustls-pki-types\": Label(\"@rust_crates//rustls-pki-types-1.15.1\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n \"tokio-stream\": Label(\"@rust_crates//tokio-stream-0.1.18\"),\n \"tonic\": Label(\"@rust_crates//tonic-0.14.6\"),\n \"x509-parser\": Label(\"@rust_crates//x509-parser-0.18.1\"),\n },\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"s2rst\": Label(\"@rust_crates//s2rst-0.5.1\"),\n },\n },\n \"rust/sql-nio\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"rustls\": Label(\"@rust_crates//rustls-0.23.46\"),\n \"rustls-pki-types\": Label(\"@rust_crates//rustls-pki-types-1.15.1\"),\n \"slab\": Label(\"@rust_crates//slab-0.4.12\"),\n \"x509-parser\": Label(\"@rust_crates//x509-parser-0.18.1\"),\n },\n \"aarch64-apple-darwin\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-apple-ios\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-apple-ios-sim\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-linux-android\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"aarch64-pc-windows-msvc\": {\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n \"windows-sys\": Label(\"@rust_crates//windows-sys-0.61.2\"),\n },\n \"aarch64-unknown-linux-gnu\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"x86_64-apple-darwin\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n \"x86_64-pc-windows-msvc\": {\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n \"windows-sys\": Label(\"@rust_crates//windows-sys-0.61.2\"),\n },\n \"x86_64-unknown-linux-gnu\": {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n \"socket2\": Label(\"@rust_crates//socket2-0.6.5\"),\n },\n },\n \"rust/sql-parser\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"peg\": Label(\"@rust_crates//peg-0.8.6\"),\n },\n \"cfg(any(target_arch = \\\"x86_64\\\", target_arch = \\\"aarch64\\\"))\": {\n \"psm\": Label(\"@rust_crates//psm-0.1.24\"),\n },\n },\n \"rust/standby-rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"prost\": Label(\"@rust_crates//prost-0.14.3\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n \"tokio-stream\": Label(\"@rust_crates//tokio-stream-0.1.18\"),\n \"tonic\": Label(\"@rust_crates//tonic-0.14.6\"),\n \"tonic-prost\": Label(\"@rust_crates//tonic-prost-0.14.6\"),\n },\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n },\n },\n \"rust/tmp-file\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"tokio\": Label(\"@rust_crates//tokio-1.52.3\"),\n },\n },\n \"rust/uuid-generator\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"getrandom\": Label(\"@rust_crates//getrandom-0.4.3\"),\n \"uuid\": Label(\"@rust_crates//uuid-1.29.0\"),\n },\n },\n \"rust/vector-kernels\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"simsimd\": Label(\"@rust_crates//simsimd-6.5.16\"),\n },\n },\n \"rust/wal\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"log\": Label(\"@rust_crates//log-0.4.34\"),\n },\n },\n \"rust/xml-parser\": {\n _COMMON_CONDITION: {\n \"cxx\": Label(\"@rust_crates//cxx-1.0.202\"),\n \"quick-xml\": Label(\"@rust_crates//quick-xml-0.41.0\"),\n },\n },\n}\n\n\n_NORMAL_ALIASES = {\n \"rust/compression\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/config\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/crypto\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/file-io\": {\n _COMMON_CONDITION: {\n },\n \"cfg(windows)\": {\n },\n },\n \"rust/http-client\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/in-process\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/json\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/math\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/mvt\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/number-parser\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/path-utils\": {\n _COMMON_CONDITION: {\n },\n },\n \"bazel/prost-codegen\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/regex-engine\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n },\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/sql-nio\": {\n _COMMON_CONDITION: {\n },\n \"aarch64-apple-darwin\": {\n },\n \"aarch64-apple-ios\": {\n },\n \"aarch64-apple-ios-sim\": {\n },\n \"aarch64-linux-android\": {\n },\n \"aarch64-pc-windows-msvc\": {\n },\n \"aarch64-unknown-linux-gnu\": {\n },\n \"x86_64-apple-darwin\": {\n },\n \"x86_64-pc-windows-msvc\": {\n },\n \"x86_64-unknown-linux-gnu\": {\n },\n },\n \"rust/sql-parser\": {\n _COMMON_CONDITION: {\n },\n \"cfg(any(target_arch = \\\"x86_64\\\", target_arch = \\\"aarch64\\\"))\": {\n },\n },\n \"rust/standby-rpc\": {\n \"cfg(not(target_family = \\\"wasm\\\"))\": {\n },\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/tmp-file\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/uuid-generator\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/vector-kernels\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/wal\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/xml-parser\": {\n _COMMON_CONDITION: {\n },\n },\n}\n\n\n_NORMAL_DEV_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n \"cfg(not(target_os = \\\"emscripten\\\"))\": {\n \"rustls\": Label(\"@rust_crates//rustls-0.23.46\"),\n },\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n \"mio\": Label(\"@rust_crates//mio-1.2.3\"),\n },\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n \"libc\": Label(\"@rust_crates//libc-0.2.189\"),\n },\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_NORMAL_DEV_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n \"cfg(not(target_os = \\\"emscripten\\\"))\": {\n },\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_DEV_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_PROC_MACRO_DEV_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n \"cfg(not(target_os = \\\"emscripten\\\"))\": {\n },\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n _COMMON_CONDITION: {\n },\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_PROC_MACRO_DEPENDENCIES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_BUILD_PROC_MACRO_ALIASES = {\n \"rust/compression\": {\n },\n \"rust/config\": {\n },\n \"rust/crypto\": {\n },\n \"rust/file-io\": {\n },\n \"rust/http-client\": {\n },\n \"rust/in-process\": {\n },\n \"rust/json\": {\n },\n \"rust/kv\": {\n },\n \"rust/local\": {\n },\n \"rust/logger\": {\n },\n \"rust/math\": {\n },\n \"rust/mvt\": {\n },\n \"rust/number-parser\": {\n },\n \"rust/path-utils\": {\n },\n \"bazel/prost-codegen\": {\n },\n \"rust/regex-engine\": {\n },\n \"rust/rpc\": {\n },\n \"rust/seekdb-rust\": {\n },\n \"rust/spatial-covering\": {\n },\n \"rust/sql-nio\": {\n },\n \"rust/sql-parser\": {\n },\n \"rust/standby-rpc\": {\n },\n \"rust/storage-io\": {\n },\n \"rust/tmp-file\": {\n },\n \"rust/uuid-generator\": {\n },\n \"rust/vector-kernels\": {\n },\n \"rust/wal\": {\n },\n \"rust/xml-parser\": {\n },\n}\n\n\n_CONDITIONS = {\n \"aarch64-apple-darwin\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\"],\n \"aarch64-apple-ios\": [\"@rules_rust//rust/platform:aarch64-apple-ios\"],\n \"aarch64-apple-ios-sim\": [\"@rules_rust//rust/platform:aarch64-apple-ios-sim\"],\n \"aarch64-linux-android\": [\"@rules_rust//rust/platform:aarch64-linux-android\"],\n \"aarch64-pc-windows-gnullvm\": [],\n \"aarch64-pc-windows-msvc\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\"],\n \"aarch64-unknown-linux-gnu\": [\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\"],\n \"cfg(all(all(target_arch = \\\"aarch64\\\", target_endian = \\\"little\\\"), target_os = \\\"windows\\\"))\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\"],\n \"cfg(all(all(target_arch = \\\"aarch64\\\", target_endian = \\\"little\\\"), target_vendor = \\\"apple\\\", any(target_os = \\\"ios\\\", target_os = \\\"macos\\\", target_os = \\\"tvos\\\", target_os = \\\"visionos\\\", target_os = \\\"watchos\\\")))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\"],\n \"cfg(all(any(all(target_arch = \\\"aarch64\\\", target_endian = \\\"little\\\"), all(target_arch = \\\"arm\\\", target_endian = \\\"little\\\")), any(target_os = \\\"android\\\", target_os = \\\"linux\\\")))\": [\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\"],\n \"cfg(all(any(target_arch = \\\"x86_64\\\", target_arch = \\\"arm64ec\\\"), target_env = \\\"msvc\\\", not(windows_raw_dylib)))\": [\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"cfg(all(any(target_os = \\\"linux\\\", target_os = \\\"android\\\"), any(rustix_use_libc, miri, not(all(target_os = \\\"linux\\\", any(target_endian = \\\"little\\\", any(target_arch = \\\"s390x\\\", target_arch = \\\"powerpc\\\")), any(target_arch = \\\"arm\\\", all(target_arch = \\\"aarch64\\\", target_pointer_width = \\\"64\\\"), target_arch = \\\"riscv64\\\", all(rustix_use_experimental_asm, target_arch = \\\"powerpc\\\"), all(rustix_use_experimental_asm, target_arch = \\\"powerpc64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"s390x\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips32r6\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64r6\\\"), target_arch = \\\"x86\\\", all(target_arch = \\\"x86_64\\\", target_pointer_width = \\\"64\\\")))))))\": [\"@rules_rust//rust/platform:aarch64-linux-android\"],\n \"cfg(all(any(target_os = \\\"linux\\\", target_os = \\\"android\\\"), not(any(all(target_os = \\\"linux\\\", target_env = \\\"\\\"), getrandom_backend = \\\"custom\\\", getrandom_backend = \\\"linux_raw\\\", getrandom_backend = \\\"rdrand\\\", getrandom_backend = \\\"rndr\\\"))))\": [\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(all(not(rustix_use_libc), not(miri), target_os = \\\"linux\\\", any(target_endian = \\\"little\\\", any(target_arch = \\\"s390x\\\", target_arch = \\\"powerpc\\\")), any(target_arch = \\\"arm\\\", all(target_arch = \\\"aarch64\\\", target_pointer_width = \\\"64\\\"), target_arch = \\\"riscv64\\\", all(rustix_use_experimental_asm, target_arch = \\\"powerpc\\\"), all(rustix_use_experimental_asm, target_arch = \\\"powerpc64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"s390x\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips32r6\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64r6\\\"), target_arch = \\\"x86\\\", all(target_arch = \\\"x86_64\\\", target_pointer_width = \\\"64\\\"))))\": [\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = \\\"linux\\\", any(target_endian = \\\"little\\\", any(target_arch = \\\"s390x\\\", target_arch = \\\"powerpc\\\")), any(target_arch = \\\"arm\\\", all(target_arch = \\\"aarch64\\\", target_pointer_width = \\\"64\\\"), target_arch = \\\"riscv64\\\", all(rustix_use_experimental_asm, target_arch = \\\"powerpc\\\"), all(rustix_use_experimental_asm, target_arch = \\\"powerpc64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"s390x\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips32r6\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64\\\"), all(rustix_use_experimental_asm, target_arch = \\\"mips64r6\\\"), target_arch = \\\"x86\\\", all(target_arch = \\\"x86_64\\\", target_pointer_width = \\\"64\\\")))))))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"cfg(all(target_arch = \\\"aarch64\\\", target_env = \\\"msvc\\\", not(windows_raw_dylib)))\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\"],\n \"cfg(all(target_arch = \\\"wasm32\\\", target_os = \\\"unknown\\\"))\": [],\n \"cfg(all(target_arch = \\\"x86\\\", target_env = \\\"gnu\\\", not(target_abi = \\\"llvm\\\"), not(windows_raw_dylib)))\": [],\n \"cfg(all(target_arch = \\\"x86\\\", target_env = \\\"msvc\\\", not(windows_raw_dylib)))\": [],\n \"cfg(all(target_arch = \\\"x86_64\\\", target_env = \\\"gnu\\\", not(target_abi = \\\"llvm\\\"), not(windows_raw_dylib)))\": [\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(all(target_os = \\\"uefi\\\", getrandom_backend = \\\"efi_rng\\\"))\": [],\n \"cfg(any())\": [],\n \"cfg(any(target_arch = \\\"x86_64\\\", target_arch = \\\"aarch64\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(any(target_os = \\\"dragonfly\\\", target_os = \\\"freebsd\\\", target_os = \\\"hurd\\\", target_os = \\\"illumos\\\", target_os = \\\"cygwin\\\", all(target_os = \\\"horizon\\\", target_arch = \\\"arm\\\")))\": [],\n \"cfg(any(target_os = \\\"haiku\\\", target_os = \\\"redox\\\", target_os = \\\"nto\\\", target_os = \\\"aix\\\"))\": [],\n \"cfg(any(target_os = \\\"ios\\\", target_os = \\\"visionos\\\", target_os = \\\"watchos\\\", target_os = \\\"tvos\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\"],\n \"cfg(any(target_os = \\\"macos\\\", target_os = \\\"openbsd\\\", target_os = \\\"vita\\\", target_os = \\\"emscripten\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"cfg(any(unix, target_os = \\\"hermit\\\", target_os = \\\"wasi\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(any(unix, target_os = \\\"wasi\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(not(target_family = \\\"wasm\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(not(target_os = \\\"emscripten\\\"))\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(target_os = \\\"android\\\")\": [\"@rules_rust//rust/platform:aarch64-linux-android\"],\n \"cfg(target_os = \\\"haiku\\\")\": [],\n \"cfg(target_os = \\\"hermit\\\")\": [],\n \"cfg(target_os = \\\"netbsd\\\")\": [],\n \"cfg(target_os = \\\"redox\\\")\": [],\n \"cfg(target_os = \\\"solaris\\\")\": [],\n \"cfg(target_os = \\\"vxworks\\\")\": [],\n \"cfg(target_os = \\\"wasi\\\")\": [],\n \"cfg(target_os = \\\"windows\\\")\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"cfg(target_vendor = \\\"apple\\\")\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"cfg(unix)\": [\"@rules_rust//rust/platform:aarch64-apple-darwin\",\"@rules_rust//rust/platform:aarch64-apple-ios\",\"@rules_rust//rust/platform:aarch64-apple-ios-sim\",\"@rules_rust//rust/platform:aarch64-linux-android\",\"@rules_rust//rust/platform:aarch64-unknown-linux-gnu\",\"@rules_rust//rust/platform:wasm32-unknown-emscripten\",\"@rules_rust//rust/platform:x86_64-apple-darwin\",\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n \"cfg(windows)\": [\"@rules_rust//rust/platform:aarch64-pc-windows-msvc\",\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"i686-pc-windows-gnu\": [],\n \"i686-pc-windows-gnullvm\": [],\n \"wasm32-unknown-emscripten\": [\"@rules_rust//rust/platform:wasm32-unknown-emscripten\"],\n \"x86_64-apple-darwin\": [\"@rules_rust//rust/platform:x86_64-apple-darwin\"],\n \"x86_64-pc-windows-gnu\": [],\n \"x86_64-pc-windows-gnullvm\": [],\n \"x86_64-pc-windows-msvc\": [\"@rules_rust//rust/platform:x86_64-pc-windows-msvc\"],\n \"x86_64-unknown-linux-gnu\": [\"@rules_rust//rust/platform:x86_64-unknown-linux-gnu\"],\n}\n\n###############################################################################\n\ndef crate_repositories():\n \"\"\"A macro for defining repositories for all generated crates.\n\n Returns:\n A list of repos visible to the module through the module extension.\n \"\"\"\n maybe(\n crates_vendor_remote_repository,\n name = \"rust_crates\",\n # Lean interface: just point at `crates.bzl`; the repo rule\n # derives the sibling `BUILD.bazel` and `defs.bzl`.\n crates_module = Label(\"@rust_crates//rust_crates:crates.bzl\"),\n )\n maybe(\n http_archive,\n name = \"rust_crates__aho-corasick-1.1.5\",\n sha256 = \"c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/aho-corasick/1.1.5/download\"],\n strip_prefix = \"aho-corasick-1.1.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.aho-corasick-1.1.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__android_system_properties-0.1.6\",\n sha256 = \"ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/android_system_properties/0.1.6/download\"],\n strip_prefix = \"android_system_properties-0.1.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.android_system_properties-0.1.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__anyhow-1.0.103\",\n sha256 = \"2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/anyhow/1.0.103/download\"],\n strip_prefix = \"anyhow-1.0.103\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.anyhow-1.0.103.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__arc-swap-1.9.2\",\n sha256 = \"c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/arc-swap/1.9.2/download\"],\n strip_prefix = \"arc-swap-1.9.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.arc-swap-1.9.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__asn1-rs-0.7.2\",\n sha256 = \"b7f43a50ac4fdca5df8e885c21b835997f0a1cdee65494a6847694a98652d9d8\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/asn1-rs/0.7.2/download\"],\n strip_prefix = \"asn1-rs-0.7.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.asn1-rs-0.7.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__asn1-rs-derive-0.6.0\",\n sha256 = \"3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/asn1-rs-derive/0.6.0/download\"],\n strip_prefix = \"asn1-rs-derive-0.6.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.asn1-rs-derive-0.6.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__asn1-rs-impl-0.2.0\",\n sha256 = \"7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/asn1-rs-impl/0.2.0/download\"],\n strip_prefix = \"asn1-rs-impl-0.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.asn1-rs-impl-0.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__async-trait-0.1.89\",\n sha256 = \"9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/async-trait/0.1.89/download\"],\n strip_prefix = \"async-trait-0.1.89\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.async-trait-0.1.89.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__atomic-0.6.1\",\n sha256 = \"a89cbf775b137e9b968e67227ef7f775587cde3fd31b0d8599dbd0f598a48340\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/atomic/0.6.1/download\"],\n strip_prefix = \"atomic-0.6.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.atomic-0.6.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__atomic-waker-1.1.2\",\n sha256 = \"1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/atomic-waker/1.1.2/download\"],\n strip_prefix = \"atomic-waker-1.1.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.atomic-waker-1.1.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__autocfg-1.5.1\",\n sha256 = \"f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/autocfg/1.5.1/download\"],\n strip_prefix = \"autocfg-1.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.autocfg-1.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__axum-0.8.9\",\n sha256 = \"31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/axum/0.8.9/download\"],\n strip_prefix = \"axum-0.8.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.axum-0.8.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__axum-core-0.5.6\",\n sha256 = \"08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/axum-core/0.5.6/download\"],\n strip_prefix = \"axum-core-0.5.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.axum-core-0.5.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__base64-0.22.1\",\n sha256 = \"72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/base64/0.22.1/download\"],\n strip_prefix = \"base64-0.22.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.base64-0.22.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__beef-0.5.2\",\n sha256 = \"3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/beef/0.5.2/download\"],\n strip_prefix = \"beef-0.5.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.beef-0.5.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bit-set-0.8.0\",\n sha256 = \"08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bit-set/0.8.0/download\"],\n strip_prefix = \"bit-set-0.8.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bit-set-0.8.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bit-vec-0.8.0\",\n sha256 = \"5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bit-vec/0.8.0/download\"],\n strip_prefix = \"bit-vec-0.8.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bit-vec-0.8.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bitflags-2.13.2\",\n sha256 = \"3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bitflags/2.13.2/download\"],\n strip_prefix = \"bitflags-2.13.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bitflags-2.13.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bstr-1.13.1\",\n sha256 = \"6bb31b46c14244e20ee9984b11bf5c992b91fb6939fea616e3512c8baecdbe5f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bstr/1.13.1/download\"],\n strip_prefix = \"bstr-1.13.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bstr-1.13.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bumpalo-3.20.3\",\n sha256 = \"72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bumpalo/3.20.3/download\"],\n strip_prefix = \"bumpalo-3.20.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bumpalo-3.20.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bytemuck-1.25.2\",\n sha256 = \"95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bytemuck/1.25.2/download\"],\n strip_prefix = \"bytemuck-1.25.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bytemuck-1.25.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bytemuck_derive-1.12.1\",\n sha256 = \"6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bytemuck_derive/1.12.1/download\"],\n strip_prefix = \"bytemuck_derive-1.12.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bytemuck_derive-1.12.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__bytes-1.11.1\",\n sha256 = \"1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/bytes/1.11.1/download\"],\n strip_prefix = \"bytes-1.11.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.bytes-1.11.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cc-1.5.1\",\n sha256 = \"f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cc/1.5.1/download\"],\n strip_prefix = \"cc-1.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cc-1.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cfg-if-1.0.5\",\n sha256 = \"4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cfg-if/1.0.5/download\"],\n strip_prefix = \"cfg-if-1.0.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cfg-if-1.0.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__chrono-0.4.45\",\n sha256 = \"1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/chrono/0.4.45/download\"],\n strip_prefix = \"chrono-0.4.45\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.chrono-0.4.45.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__codespan-reporting-0.13.1\",\n sha256 = \"af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/codespan-reporting/0.13.1/download\"],\n strip_prefix = \"codespan-reporting-0.13.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.codespan-reporting-0.13.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__core-foundation-sys-0.8.7\",\n sha256 = \"773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/core-foundation-sys/0.8.7/download\"],\n strip_prefix = \"core-foundation-sys-0.8.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.core-foundation-sys-0.8.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-0.8.5\",\n sha256 = \"e71406cd8807725f7ac2f999a4cdd32e98f829fdf65f528343cebf945e41df1e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam/0.8.5/download\"],\n strip_prefix = \"crossbeam-0.8.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-0.8.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-channel-0.5.17\",\n sha256 = \"98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-channel/0.5.17/download\"],\n strip_prefix = \"crossbeam-channel-0.5.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-channel-0.5.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-deque-0.8.8\",\n sha256 = \"622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-deque/0.8.8/download\"],\n strip_prefix = \"crossbeam-deque-0.8.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-deque-0.8.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-epoch-0.9.21\",\n sha256 = \"dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-epoch/0.9.21/download\"],\n strip_prefix = \"crossbeam-epoch-0.9.21\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-epoch-0.9.21.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-queue-0.3.14\",\n sha256 = \"03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-queue/0.3.14/download\"],\n strip_prefix = \"crossbeam-queue-0.3.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-queue-0.3.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__crossbeam-utils-0.8.23\",\n sha256 = \"a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/crossbeam-utils/0.8.23/download\"],\n strip_prefix = \"crossbeam-utils-0.8.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.crossbeam-utils-0.8.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxx-1.0.202\",\n sha256 = \"13f6de320895f42e6e081abb5c7983bedcf0b6d0ff9323de0d33f620c8ac1199\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxx/1.0.202/download\"],\n strip_prefix = \"cxx-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxx-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxx-build-1.0.202\",\n sha256 = \"4fde53ca86b9704a943fef0f1e1d836239a6aedca5de3c65fa9f97ec0bd46d39\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxx-build/1.0.202/download\"],\n strip_prefix = \"cxx-build-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxx-build-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxxbridge-flags-1.0.202\",\n sha256 = \"49045042e5fced01b80742aba5508de82aa4f13677ed3fa2b4cda709c40c5918\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxxbridge-flags/1.0.202/download\"],\n strip_prefix = \"cxxbridge-flags-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxxbridge-flags-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__cxxbridge-macro-1.0.202\",\n sha256 = \"b181252e2e3d3b5d183afbdc033a3958b445eb3e1a0ae65fc3d4f5259f5da6fd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/cxxbridge-macro/1.0.202/download\"],\n strip_prefix = \"cxxbridge-macro-1.0.202\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.cxxbridge-macro-1.0.202.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__data-encoding-2.11.1\",\n sha256 = \"4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/data-encoding/2.11.1/download\"],\n strip_prefix = \"data-encoding-2.11.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.data-encoding-2.11.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__der-parser-10.0.0\",\n sha256 = \"07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/der-parser/10.0.0/download\"],\n strip_prefix = \"der-parser-10.0.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.der-parser-10.0.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__deranged-0.5.8\",\n sha256 = \"7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/deranged/0.5.8/download\"],\n strip_prefix = \"deranged-0.5.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.deranged-0.5.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__displaydoc-0.2.7\",\n sha256 = \"c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/displaydoc/0.2.7/download\"],\n strip_prefix = \"displaydoc-0.2.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.displaydoc-0.2.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__dyn-clone-1.0.20\",\n sha256 = \"d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/dyn-clone/1.0.20/download\"],\n strip_prefix = \"dyn-clone-1.0.20\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.dyn-clone-1.0.20.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__either-1.15.0\",\n sha256 = \"48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/either/1.15.0/download\"],\n strip_prefix = \"either-1.15.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.either-1.15.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__equivalent-1.0.2\",\n sha256 = \"877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/equivalent/1.0.2/download\"],\n strip_prefix = \"equivalent-1.0.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.equivalent-1.0.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__erased-serde-0.4.10\",\n sha256 = \"d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/erased-serde/0.4.10/download\"],\n strip_prefix = \"erased-serde-0.4.10\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.erased-serde-0.4.10.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__errno-0.3.14\",\n sha256 = \"39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/errno/0.3.14/download\"],\n strip_prefix = \"errno-0.3.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.errno-0.3.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fancy-regex-0.20.0\",\n sha256 = \"20ed7f62ce0ae0da1a8b93c3c7104ab7e0760a74491e097c701fff966e945390\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fancy-regex/0.20.0/download\"],\n strip_prefix = \"fancy-regex-0.20.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fancy-regex-0.20.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fast-float2-0.2.4\",\n sha256 = \"c6e8948ce679d00a02a94739ea185595dca7118ed04feb991127e443bd3d761f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fast-float2/0.2.4/download\"],\n strip_prefix = \"fast-float2-0.2.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fast-float2-0.2.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fastrand-2.5.0\",\n sha256 = \"da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fastrand/2.5.0/download\"],\n strip_prefix = \"fastrand-2.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fastrand-2.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__find-msvc-tools-0.1.14\",\n sha256 = \"aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/find-msvc-tools/0.1.14/download\"],\n strip_prefix = \"find-msvc-tools-0.1.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.find-msvc-tools-0.1.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fixedbitset-0.5.7\",\n sha256 = \"1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fixedbitset/0.5.7/download\"],\n strip_prefix = \"fixedbitset-0.5.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fixedbitset-0.5.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__fnv-1.0.7\",\n sha256 = \"3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/fnv/1.0.7/download\"],\n strip_prefix = \"fnv-1.0.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.fnv-1.0.7.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__foldhash-0.1.3\",\n sha256 = \"f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/foldhash/0.1.3/download\"],\n strip_prefix = \"foldhash-0.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.foldhash-0.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__foldhash-0.2.0\",\n sha256 = \"77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/foldhash/0.2.0/download\"],\n strip_prefix = \"foldhash-0.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.foldhash-0.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-channel-0.3.32\",\n sha256 = \"07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-channel/0.3.32/download\"],\n strip_prefix = \"futures-channel-0.3.32\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-channel-0.3.32.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-core-0.3.34\",\n sha256 = \"92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-core/0.3.34/download\"],\n strip_prefix = \"futures-core-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-core-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-sink-0.3.32\",\n sha256 = \"c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-sink/0.3.32/download\"],\n strip_prefix = \"futures-sink-0.3.32\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-sink-0.3.32.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-task-0.3.34\",\n sha256 = \"cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-task/0.3.34/download\"],\n strip_prefix = \"futures-task-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-task-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__futures-util-0.3.34\",\n sha256 = \"0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/futures-util/0.3.34/download\"],\n strip_prefix = \"futures-util-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.futures-util-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__getrandom-0.2.17\",\n sha256 = \"ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/getrandom/0.2.17/download\"],\n strip_prefix = \"getrandom-0.2.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.getrandom-0.2.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__getrandom-0.4.3\",\n sha256 = \"300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/getrandom/0.4.3/download\"],\n strip_prefix = \"getrandom-0.4.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.getrandom-0.4.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__globset-0.4.18\",\n sha256 = \"52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/globset/0.4.18/download\"],\n strip_prefix = \"globset-0.4.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.globset-0.4.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__h2-0.4.16\",\n sha256 = \"a9f37a958b41b3b19ee2707c06439c0e9e547e847223eb791ecb0cb821c65e27\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/h2/0.4.16/download\"],\n strip_prefix = \"h2-0.4.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.h2-0.4.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hashbrown-0.15.2\",\n sha256 = \"bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hashbrown/0.15.2/download\"],\n strip_prefix = \"hashbrown-0.15.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hashbrown-0.15.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hashbrown-0.17.1\",\n sha256 = \"ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hashbrown/0.17.1/download\"],\n strip_prefix = \"hashbrown-0.17.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hashbrown-0.17.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__heck-0.5.0\",\n sha256 = \"2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/heck/0.5.0/download\"],\n strip_prefix = \"heck-0.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.heck-0.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__http-1.4.0\",\n sha256 = \"e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/http/1.4.0/download\"],\n strip_prefix = \"http-1.4.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.http-1.4.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__http-body-1.0.1\",\n sha256 = \"1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/http-body/1.0.1/download\"],\n strip_prefix = \"http-body-1.0.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.http-body-1.0.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__http-body-util-0.1.3\",\n sha256 = \"b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/http-body-util/0.1.3/download\"],\n strip_prefix = \"http-body-util-0.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.http-body-util-0.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__httparse-1.10.1\",\n sha256 = \"6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/httparse/1.10.1/download\"],\n strip_prefix = \"httparse-1.10.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.httparse-1.10.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__httpdate-1.0.3\",\n sha256 = \"df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/httpdate/1.0.3/download\"],\n strip_prefix = \"httpdate-1.0.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.httpdate-1.0.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hyper-1.9.0\",\n sha256 = \"6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hyper/1.9.0/download\"],\n strip_prefix = \"hyper-1.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hyper-1.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hyper-timeout-0.5.2\",\n sha256 = \"2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hyper-timeout/0.5.2/download\"],\n strip_prefix = \"hyper-timeout-0.5.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hyper-timeout-0.5.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__hyper-util-0.1.20\",\n sha256 = \"96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/hyper-util/0.1.20/download\"],\n strip_prefix = \"hyper-util-0.1.20\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.hyper-util-0.1.20.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__iana-time-zone-0.1.65\",\n sha256 = \"e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/iana-time-zone/0.1.65/download\"],\n strip_prefix = \"iana-time-zone-0.1.65\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.iana-time-zone-0.1.65.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__iana-time-zone-haiku-0.1.2\",\n sha256 = \"f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/iana-time-zone-haiku/0.1.2/download\"],\n strip_prefix = \"iana-time-zone-haiku-0.1.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.iana-time-zone-haiku-0.1.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__indexmap-2.14.2\",\n sha256 = \"cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/indexmap/2.14.2/download\"],\n strip_prefix = \"indexmap-2.14.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.indexmap-2.14.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__itertools-0.14.0\",\n sha256 = \"2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/itertools/0.14.0/download\"],\n strip_prefix = \"itertools-0.14.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.itertools-0.14.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__itoa-1.0.18\",\n sha256 = \"8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/itoa/1.0.18/download\"],\n strip_prefix = \"itoa-1.0.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.itoa-1.0.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__jobserver-0.1.35\",\n sha256 = \"1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/jobserver/0.1.35/download\"],\n strip_prefix = \"jobserver-0.1.35\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.jobserver-0.1.35.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__js-sys-0.3.106\",\n sha256 = \"7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/js-sys/0.3.106/download\"],\n strip_prefix = \"js-sys-0.3.106\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.js-sys-0.3.106.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__lazy_static-1.5.0\",\n sha256 = \"bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/lazy_static/1.5.0/download\"],\n strip_prefix = \"lazy_static-1.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.lazy_static-1.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__libc-0.2.189\",\n sha256 = \"3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/libc/0.2.189/download\"],\n strip_prefix = \"libc-0.2.189\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.libc-0.2.189.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__libm-0.2.16\",\n sha256 = \"b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/libm/0.2.16/download\"],\n strip_prefix = \"libm-0.2.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.libm-0.2.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__link-cplusplus-1.0.12\",\n sha256 = \"7f78c730aaa7d0b9336a299029ea49f9ee53b0ed06e9202e8cb7db9bae7b8c82\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/link-cplusplus/1.0.12/download\"],\n strip_prefix = \"link-cplusplus-1.0.12\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.link-cplusplus-1.0.12.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__linux-raw-sys-0.12.1\",\n sha256 = \"32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/linux-raw-sys/0.12.1/download\"],\n strip_prefix = \"linux-raw-sys-0.12.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.linux-raw-sys-0.12.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__lock_api-0.4.14\",\n sha256 = \"224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/lock_api/0.4.14/download\"],\n strip_prefix = \"lock_api-0.4.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.lock_api-0.4.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__log-0.4.34\",\n sha256 = \"f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/log/0.4.34/download\"],\n strip_prefix = \"log-0.4.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.log-0.4.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-0.15.1\",\n sha256 = \"ff472f899b4ec2d99161c51f60ff7075eeb3097069a36050d8037a6325eb8154\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos/0.15.1/download\"],\n strip_prefix = \"logos-0.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-0.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-0.16.1\",\n sha256 = \"eb2c55a318a87600ea870ff8c2012148b44bf18b74fad48d0f835c38c7d07c5f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos/0.16.1/download\"],\n strip_prefix = \"logos-0.16.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-0.16.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-codegen-0.15.1\",\n sha256 = \"192a3a2b90b0c05b27a0b2c43eecdb7c415e29243acc3f89cc8247a5b693045c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-codegen/0.15.1/download\"],\n strip_prefix = \"logos-codegen-0.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-codegen-0.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-codegen-0.16.1\",\n sha256 = \"58b3ffaa284e1350d017a57d04ada118c4583cf260c8fb01e0fe28a2e9cf8970\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-codegen/0.16.1/download\"],\n strip_prefix = \"logos-codegen-0.16.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-codegen-0.16.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-derive-0.15.1\",\n sha256 = \"605d9697bcd5ef3a42d38efc51541aa3d6a4a25f7ab6d1ed0da5ac632a26b470\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-derive/0.15.1/download\"],\n strip_prefix = \"logos-derive-0.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-derive-0.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__logos-derive-0.16.1\",\n sha256 = \"52d3a9855747c17eaf4383823f135220716ab49bea5fbea7dd42cc9a92f8aa31\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/logos-derive/0.16.1/download\"],\n strip_prefix = \"logos-derive-0.16.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.logos-derive-0.16.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__matchit-0.8.4\",\n sha256 = \"47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/matchit/0.8.4/download\"],\n strip_prefix = \"matchit-0.8.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.matchit-0.8.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__memchr-2.8.3\",\n sha256 = \"cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/memchr/2.8.3/download\"],\n strip_prefix = \"memchr-2.8.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.memchr-2.8.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__miette-7.6.0\",\n sha256 = \"5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/miette/7.6.0/download\"],\n strip_prefix = \"miette-7.6.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.miette-7.6.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__miette-derive-7.6.0\",\n sha256 = \"db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/miette-derive/7.6.0/download\"],\n strip_prefix = \"miette-derive-7.6.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.miette-derive-7.6.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__mime-0.3.17\",\n sha256 = \"6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/mime/0.3.17/download\"],\n strip_prefix = \"mime-0.3.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.mime-0.3.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__minimal-lexical-0.2.1\",\n sha256 = \"68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/minimal-lexical/0.2.1/download\"],\n strip_prefix = \"minimal-lexical-0.2.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.minimal-lexical-0.2.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__mio-1.2.3\",\n sha256 = \"4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/mio/1.2.3/download\"],\n strip_prefix = \"mio-1.2.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.mio-1.2.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__multimap-0.10.1\",\n sha256 = \"1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/multimap/0.10.1/download\"],\n strip_prefix = \"multimap-0.10.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.multimap-0.10.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__nom-7.1.3\",\n sha256 = \"d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/nom/7.1.3/download\"],\n strip_prefix = \"nom-7.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.nom-7.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__nom-8.0.0\",\n sha256 = \"df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/nom/8.0.0/download\"],\n strip_prefix = \"nom-8.0.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.nom-8.0.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-bigint-0.4.8\",\n sha256 = \"c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-bigint/0.4.8/download\"],\n strip_prefix = \"num-bigint-0.4.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-bigint-0.4.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-conv-0.2.2\",\n sha256 = \"521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-conv/0.2.2/download\"],\n strip_prefix = \"num-conv-0.2.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-conv-0.2.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-integer-0.1.47\",\n sha256 = \"7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-integer/0.1.47/download\"],\n strip_prefix = \"num-integer-0.1.47\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-integer-0.1.47.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__num-traits-0.2.19\",\n sha256 = \"071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/num-traits/0.2.19/download\"],\n strip_prefix = \"num-traits-0.2.19\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.num-traits-0.2.19.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__oid-registry-0.8.1\",\n sha256 = \"12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/oid-registry/0.8.1/download\"],\n strip_prefix = \"oid-registry-0.8.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.oid-registry-0.8.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__once_cell-1.21.4\",\n sha256 = \"9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/once_cell/1.21.4/download\"],\n strip_prefix = \"once_cell-1.21.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.once_cell-1.21.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__parking_lot-0.12.5\",\n sha256 = \"93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/parking_lot/0.12.5/download\"],\n strip_prefix = \"parking_lot-0.12.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.parking_lot-0.12.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__parking_lot_core-0.9.12\",\n sha256 = \"2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/parking_lot_core/0.9.12/download\"],\n strip_prefix = \"parking_lot_core-0.9.12\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.parking_lot_core-0.9.12.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__peg-0.8.6\",\n sha256 = \"0aad070be5b63aa72103f2fcdd70a83adbd5e90112ce5b574171ff1c65501773\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/peg/0.8.6/download\"],\n strip_prefix = \"peg-0.8.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.peg-0.8.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__peg-macros-0.8.6\",\n sha256 = \"ddd8ef6825cae95355031ae26a99b616a2a21f22ba2de0197c43dfb05acbe7ee\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/peg-macros/0.8.6/download\"],\n strip_prefix = \"peg-macros-0.8.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.peg-macros-0.8.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__peg-runtime-0.8.6\",\n sha256 = \"7011d97b484a5ebdc4b1fdb3b12d5e4bbbea56e9d22b688f2e79e04b65a7d8a6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/peg-runtime/0.8.6/download\"],\n strip_prefix = \"peg-runtime-0.8.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.peg-runtime-0.8.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__percent-encoding-2.3.2\",\n sha256 = \"9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/percent-encoding/2.3.2/download\"],\n strip_prefix = \"percent-encoding-2.3.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.percent-encoding-2.3.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__petgraph-0.8.3\",\n sha256 = \"8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/petgraph/0.8.3/download\"],\n strip_prefix = \"petgraph-0.8.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.petgraph-0.8.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pin-project-1.1.13\",\n sha256 = \"2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pin-project/1.1.13/download\"],\n strip_prefix = \"pin-project-1.1.13\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pin-project-1.1.13.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pin-project-internal-1.1.13\",\n sha256 = \"c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pin-project-internal/1.1.13/download\"],\n strip_prefix = \"pin-project-internal-1.1.13\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pin-project-internal-1.1.13.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pin-project-lite-0.2.17\",\n sha256 = \"a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pin-project-lite/0.2.17/download\"],\n strip_prefix = \"pin-project-lite-0.2.17\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pin-project-lite-0.2.17.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__pkg-config-0.3.34\",\n sha256 = \"f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/pkg-config/0.3.34/download\"],\n strip_prefix = \"pkg-config-0.3.34\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.pkg-config-0.3.34.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__powerfmt-0.2.0\",\n sha256 = \"439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/powerfmt/0.2.0/download\"],\n strip_prefix = \"powerfmt-0.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.powerfmt-0.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prettyplease-0.2.37\",\n sha256 = \"479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prettyplease/0.2.37/download\"],\n strip_prefix = \"prettyplease-0.2.37\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prettyplease-0.2.37.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__proc-macro2-1.0.107\",\n sha256 = \"985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/proc-macro2/1.0.107/download\"],\n strip_prefix = \"proc-macro2-1.0.107\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.proc-macro2-1.0.107.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-0.14.3\",\n sha256 = \"d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost/0.14.3/download\"],\n strip_prefix = \"prost-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-build-0.14.3\",\n sha256 = \"343d3bd7056eda839b03204e68deff7d1b13aba7af2b2fd16890697274262ee7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-build/0.14.3/download\"],\n strip_prefix = \"prost-build-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-build-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-derive-0.14.3\",\n sha256 = \"27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-derive/0.14.3/download\"],\n strip_prefix = \"prost-derive-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-derive-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-reflect-0.16.5\",\n sha256 = \"01b80ea363c31af2de2b92e3c07ed1156628f7838c4afb4df75ee78a37fedbd1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-reflect/0.16.5/download\"],\n strip_prefix = \"prost-reflect-0.16.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-reflect-0.16.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__prost-types-0.14.3\",\n sha256 = \"8991c4cbdb8bc5b11f0b074ffe286c30e523de90fee5ba8132f1399f23cb3dd7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/prost-types/0.14.3/download\"],\n strip_prefix = \"prost-types-0.14.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.prost-types-0.14.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__protox-0.9.1\",\n sha256 = \"4f25a07a73c6717f0b9bbbd685918f5df9815f7efba450b83d9c9dea41f0e3a1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/protox/0.9.1/download\"],\n strip_prefix = \"protox-0.9.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.protox-0.9.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__protox-parse-0.9.0\",\n sha256 = \"072eee358134396a4643dff81cfff1c255c9fbd3fb296be14bdb6a26f9156366\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/protox-parse/0.9.0/download\"],\n strip_prefix = \"protox-parse-0.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.protox-parse-0.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__psm-0.1.24\",\n sha256 = \"200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/psm/0.1.24/download\"],\n strip_prefix = \"psm-0.1.24\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.psm-0.1.24.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__quick-xml-0.41.0\",\n sha256 = \"e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/quick-xml/0.41.0/download\"],\n strip_prefix = \"quick-xml-0.41.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.quick-xml-0.41.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__quote-1.0.47\",\n sha256 = \"1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/quote/1.0.47/download\"],\n strip_prefix = \"quote-1.0.47\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.quote-1.0.47.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__r-efi-6.0.0\",\n sha256 = \"f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/r-efi/6.0.0/download\"],\n strip_prefix = \"r-efi-6.0.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.r-efi-6.0.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__redox_syscall-0.5.18\",\n sha256 = \"ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/redox_syscall/0.5.18/download\"],\n strip_prefix = \"redox_syscall-0.5.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.redox_syscall-0.5.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__regex-1.12.3\",\n sha256 = \"e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/regex/1.12.3/download\"],\n strip_prefix = \"regex-1.12.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.regex-1.12.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__regex-automata-0.4.18\",\n sha256 = \"ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/regex-automata/0.4.18/download\"],\n strip_prefix = \"regex-automata-0.4.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.regex-automata-0.4.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__regex-syntax-0.8.11\",\n sha256 = \"d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/regex-syntax/0.8.11/download\"],\n strip_prefix = \"regex-syntax-0.8.11\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.regex-syntax-0.8.11.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__ring-0.17.14\",\n sha256 = \"a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/ring/0.17.14/download\"],\n strip_prefix = \"ring-0.17.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.ring-0.17.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustc_version-0.4.1\",\n sha256 = \"cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustc_version/0.4.1/download\"],\n strip_prefix = \"rustc_version-0.4.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustc_version-0.4.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rusticata-macros-4.1.0\",\n sha256 = \"faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rusticata-macros/4.1.0/download\"],\n strip_prefix = \"rusticata-macros-4.1.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rusticata-macros-4.1.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustix-1.1.5\",\n sha256 = \"891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustix/1.1.5/download\"],\n strip_prefix = \"rustix-1.1.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustix-1.1.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustls-0.23.46\",\n sha256 = \"48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustls/0.23.46/download\"],\n strip_prefix = \"rustls-0.23.46\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustls-0.23.46.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustls-pki-types-1.15.1\",\n sha256 = \"2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustls-pki-types/1.15.1/download\"],\n strip_prefix = \"rustls-pki-types-1.15.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustls-pki-types-1.15.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustls-webpki-0.103.16\",\n sha256 = \"4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustls-webpki/0.103.16/download\"],\n strip_prefix = \"rustls-webpki-0.103.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustls-webpki-0.103.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__rustversion-1.0.23\",\n sha256 = \"cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/rustversion/1.0.23/download\"],\n strip_prefix = \"rustversion-1.0.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.rustversion-1.0.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__ryu-1.0.23\",\n sha256 = \"9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/ryu/1.0.23/download\"],\n strip_prefix = \"ryu-1.0.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.ryu-1.0.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__s2rst-0.5.1\",\n sha256 = \"32427bddb68a5cc8b2ff1f697ad92a97658a7bbdd9c9dd50604bd228634ea261\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/s2rst/0.5.1/download\"],\n strip_prefix = \"s2rst-0.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.s2rst-0.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__same-file-1.0.6\",\n sha256 = \"93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/same-file/1.0.6/download\"],\n strip_prefix = \"same-file-1.0.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.same-file-1.0.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__scopeguard-1.2.0\",\n sha256 = \"94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/scopeguard/1.2.0/download\"],\n strip_prefix = \"scopeguard-1.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.scopeguard-1.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__scratch-1.0.9\",\n sha256 = \"d68f2ec51b097e4c1a75b681a8bec621909b5e91f15bb7b840c4f2f7b01148b2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/scratch/1.0.9/download\"],\n strip_prefix = \"scratch-1.0.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.scratch-1.0.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__semver-1.0.28\",\n sha256 = \"8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/semver/1.0.28/download\"],\n strip_prefix = \"semver-1.0.28\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.semver-1.0.28.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde-1.0.229\",\n sha256 = \"4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde/1.0.229/download\"],\n strip_prefix = \"serde-1.0.229\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde-1.0.229.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_buf-0.1.3\",\n sha256 = \"58b57892601430298e96ce14d68f61dff758b648da87f3d491fbe5ec523e749e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_buf/0.1.3/download\"],\n strip_prefix = \"serde_buf-0.1.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_buf-0.1.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_core-1.0.229\",\n sha256 = \"67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_core/1.0.229/download\"],\n strip_prefix = \"serde_core-1.0.229\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_core-1.0.229.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_derive-1.0.229\",\n sha256 = \"e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_derive/1.0.229/download\"],\n strip_prefix = \"serde_derive-1.0.229\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_derive-1.0.229.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_fmt-1.1.0\",\n sha256 = \"6e497af288b3b95d067a23a4f749f2861121ffcb2f6d8379310dcda040c345ed\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_fmt/1.1.0/download\"],\n strip_prefix = \"serde_fmt-1.1.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_fmt-1.1.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__serde_json-1.0.151\",\n sha256 = \"c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/serde_json/1.0.151/download\"],\n strip_prefix = \"serde_json-1.0.151\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.serde_json-1.0.151.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__shlex-2.0.1\",\n sha256 = \"f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/shlex/2.0.1/download\"],\n strip_prefix = \"shlex-2.0.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.shlex-2.0.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__simsimd-6.5.16\",\n sha256 = \"f4fb3bc3cdce07a7d7d4caa4c54f8aa967f6be41690482b54b24100a2253fa70\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/simsimd/6.5.16/download\"],\n strip_prefix = \"simsimd-6.5.16\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.simsimd-6.5.16.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__slab-0.4.12\",\n sha256 = \"0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/slab/0.4.12/download\"],\n strip_prefix = \"slab-0.4.12\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.slab-0.4.12.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__smallvec-1.16.2\",\n sha256 = \"f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/smallvec/1.16.2/download\"],\n strip_prefix = \"smallvec-1.16.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.smallvec-1.16.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__socket2-0.6.5\",\n sha256 = \"c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/socket2/0.6.5/download\"],\n strip_prefix = \"socket2-0.6.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.socket2-0.6.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__spdlog-internal-0.2.1\",\n sha256 = \"6eb988bafd6393bd840d78ba07826c857060bb1ba473bd57e8ae4d10a77eb276\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/spdlog-internal/0.2.1/download\"],\n strip_prefix = \"spdlog-internal-0.2.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.spdlog-internal-0.2.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__spdlog-macros-0.3.1\",\n sha256 = \"b9a23693b67ee8c1515d2043ddd01ea3561872cf1f19bc00947857c0184a62aa\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/spdlog-macros/0.3.1/download\"],\n strip_prefix = \"spdlog-macros-0.3.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.spdlog-macros-0.3.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__spdlog-rs-0.5.3\",\n patch_args = [\n \"-p1\",\n ],\n patches = [\n \"@@//bazel:spdlog-rs-emscripten.diff\",\n ],\n sha256 = \"7415ec666ebcaa1d92c5d9fba5d0b44e1a9fdddc8df6c0b2c45e89af8b830b6d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/spdlog-rs/0.5.3/download\"],\n strip_prefix = \"spdlog-rs-0.5.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.spdlog-rs-0.5.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__subtle-2.6.1\",\n sha256 = \"13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/subtle/2.6.1/download\"],\n strip_prefix = \"subtle-2.6.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.subtle-2.6.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval-2.22.0\",\n sha256 = \"b81b254da21fe1fcc4e3a74fe39b46e25e3a863078f8b71c954d47f84889dbc6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval/2.22.0/download\"],\n strip_prefix = \"sval-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_buffer-2.22.0\",\n sha256 = \"50be352d2822ffafb59e3e2ddac9d5ee60f2eeadbb7b5a2a951b9f3651e87a6f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_buffer/2.22.0/download\"],\n strip_prefix = \"sval_buffer-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_buffer-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_dynamic-2.22.0\",\n sha256 = \"b048ca293b998d9a45659159f94a64063791e74cdc670164943dbb434405573d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_dynamic/2.22.0/download\"],\n strip_prefix = \"sval_dynamic-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_dynamic-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_fmt-2.22.0\",\n sha256 = \"e6b5888e40f80568733217f27b7317b845f463400ced36c424b1a804730e53b2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_fmt/2.22.0/download\"],\n strip_prefix = \"sval_fmt-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_fmt-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_json-2.22.0\",\n sha256 = \"e17664d6bb6b74947afaab9d7c991caa9bf5638d4dee16fcbef637f440796049\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_json/2.22.0/download\"],\n strip_prefix = \"sval_json-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_json-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_nested-2.22.0\",\n sha256 = \"07c059969ca5ca163ea7fef6c9661758973d17691aba92abdcf5c428f4ec122c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_nested/2.22.0/download\"],\n strip_prefix = \"sval_nested-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_nested-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_ref-2.22.0\",\n sha256 = \"42d6b29ff568c85c87561807f51d2adfff4b6016c6363133f7cd1652a12548f3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_ref/2.22.0/download\"],\n strip_prefix = \"sval_ref-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_ref-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sval_serde-2.22.0\",\n sha256 = \"8f33ec9edc42b12764d5c90ca0a1d84189c6bde81ed27507f1e661c6e4e05853\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sval_serde/2.22.0/download\"],\n strip_prefix = \"sval_serde-2.22.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sval_serde-2.22.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__syn-2.0.119\",\n sha256 = \"872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/syn/2.0.119/download\"],\n strip_prefix = \"syn-2.0.119\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.syn-2.0.119.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__syn-3.0.6\",\n sha256 = \"8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/syn/3.0.6/download\"],\n strip_prefix = \"syn-3.0.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.syn-3.0.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__sync_wrapper-1.0.2\",\n sha256 = \"0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/sync_wrapper/1.0.2/download\"],\n strip_prefix = \"sync_wrapper-1.0.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.sync_wrapper-1.0.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__synstructure-0.13.2\",\n sha256 = \"728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/synstructure/0.13.2/download\"],\n strip_prefix = \"synstructure-0.13.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.synstructure-0.13.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tempfile-3.27.0\",\n sha256 = \"32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tempfile/3.27.0/download\"],\n strip_prefix = \"tempfile-3.27.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tempfile-3.27.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__termcolor-1.4.1\",\n sha256 = \"06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/termcolor/1.4.1/download\"],\n strip_prefix = \"termcolor-1.4.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.termcolor-1.4.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__thiserror-2.0.21\",\n sha256 = \"09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/thiserror/2.0.21/download\"],\n strip_prefix = \"thiserror-2.0.21\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.thiserror-2.0.21.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__thiserror-impl-2.0.21\",\n sha256 = \"fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/thiserror-impl/2.0.21/download\"],\n strip_prefix = \"thiserror-impl-2.0.21\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.thiserror-impl-2.0.21.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__time-0.3.55\",\n sha256 = \"cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/time/0.3.55/download\"],\n strip_prefix = \"time-0.3.55\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.time-0.3.55.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__time-core-0.1.9\",\n sha256 = \"9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/time-core/0.1.9/download\"],\n strip_prefix = \"time-core-0.1.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.time-core-0.1.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__time-macros-0.2.32\",\n sha256 = \"7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/time-macros/0.2.32/download\"],\n strip_prefix = \"time-macros-0.2.32\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.time-macros-0.2.32.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-1.52.3\",\n sha256 = \"8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio/1.52.3/download\"],\n strip_prefix = \"tokio-1.52.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-1.52.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-macros-2.7.0\",\n sha256 = \"385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-macros/2.7.0/download\"],\n strip_prefix = \"tokio-macros-2.7.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-macros-2.7.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-rustls-0.26.4\",\n sha256 = \"1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-rustls/0.26.4/download\"],\n strip_prefix = \"tokio-rustls-0.26.4\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-rustls-0.26.4.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-stream-0.1.18\",\n sha256 = \"32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-stream/0.1.18/download\"],\n strip_prefix = \"tokio-stream-0.1.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-stream-0.1.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tokio-util-0.7.18\",\n sha256 = \"9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tokio-util/0.7.18/download\"],\n strip_prefix = \"tokio-util-0.7.18\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tokio-util-0.7.18.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-0.14.6\",\n sha256 = \"ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic/0.14.6/download\"],\n strip_prefix = \"tonic-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-build-0.14.6\",\n sha256 = \"c68f61875ac5293cf72e6c8cf0158086428c82c37229e98c840878f1706b0322\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic-build/0.14.6/download\"],\n strip_prefix = \"tonic-build-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-build-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-prost-0.14.6\",\n sha256 = \"50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic-prost/0.14.6/download\"],\n strip_prefix = \"tonic-prost-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-prost-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tonic-prost-build-0.14.6\",\n sha256 = \"654e5643eff75d7f8c99197ce1440ed19a3474eada74c12bbac488b2cafdae27\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tonic-prost-build/0.14.6/download\"],\n strip_prefix = \"tonic-prost-build-0.14.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tonic-prost-build-0.14.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tower-0.5.3\",\n sha256 = \"ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tower/0.5.3/download\"],\n strip_prefix = \"tower-0.5.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tower-0.5.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tower-layer-0.3.3\",\n sha256 = \"121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tower-layer/0.3.3/download\"],\n strip_prefix = \"tower-layer-0.3.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tower-layer-0.3.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tower-service-0.3.3\",\n sha256 = \"8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tower-service/0.3.3/download\"],\n strip_prefix = \"tower-service-0.3.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tower-service-0.3.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tracing-0.1.44\",\n sha256 = \"63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tracing/0.1.44/download\"],\n strip_prefix = \"tracing-0.1.44\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tracing-0.1.44.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tracing-attributes-0.1.31\",\n sha256 = \"7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tracing-attributes/0.1.31/download\"],\n strip_prefix = \"tracing-attributes-0.1.31\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tracing-attributes-0.1.31.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__tracing-core-0.1.36\",\n sha256 = \"db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/tracing-core/0.1.36/download\"],\n strip_prefix = \"tracing-core-0.1.36\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.tracing-core-0.1.36.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__try-lock-0.2.5\",\n sha256 = \"e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/try-lock/0.2.5/download\"],\n strip_prefix = \"try-lock-0.2.5\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.try-lock-0.2.5.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__typeid-1.0.3\",\n sha256 = \"bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/typeid/1.0.3/download\"],\n strip_prefix = \"typeid-1.0.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.typeid-1.0.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__unicode-ident-1.0.26\",\n sha256 = \"d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/unicode-ident/1.0.26/download\"],\n strip_prefix = \"unicode-ident-1.0.26\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.unicode-ident-1.0.26.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__unicode-width-0.1.14\",\n sha256 = \"7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/unicode-width/0.1.14/download\"],\n strip_prefix = \"unicode-width-0.1.14\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.unicode-width-0.1.14.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__unicode-width-0.2.2\",\n sha256 = \"b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/unicode-width/0.2.2/download\"],\n strip_prefix = \"unicode-width-0.2.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.unicode-width-0.2.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__untrusted-0.9.0\",\n sha256 = \"8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/untrusted/0.9.0/download\"],\n strip_prefix = \"untrusted-0.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.untrusted-0.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__uuid-1.29.0\",\n sha256 = \"4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/uuid/1.29.0/download\"],\n strip_prefix = \"uuid-1.29.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.uuid-1.29.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__value-bag-1.14.1\",\n sha256 = \"2799ffb329a792ecfd902b71306c8a815a6ef1c0470fa9953a6aa4d4cecbe511\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/value-bag/1.14.1/download\"],\n strip_prefix = \"value-bag-1.14.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.value-bag-1.14.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__value-bag-serde1-1.14.1\",\n sha256 = \"0941feceafbe7a8f59ea1096d45b97002884a41306315ad797b3684b63a81d8c\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/value-bag-serde1/1.14.1/download\"],\n strip_prefix = \"value-bag-serde1-1.14.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.value-bag-serde1-1.14.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__value-bag-sval2-1.14.1\",\n sha256 = \"839752af8179287d27eb2b94164641b1ede9e60ab7424163388dc21ebd0508cd\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/value-bag-sval2/1.14.1/download\"],\n strip_prefix = \"value-bag-sval2-1.14.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.value-bag-sval2-1.14.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__walkdir-2.5.0\",\n sha256 = \"29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/walkdir/2.5.0/download\"],\n strip_prefix = \"walkdir-2.5.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.walkdir-2.5.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__want-0.3.1\",\n sha256 = \"bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/want/0.3.1/download\"],\n strip_prefix = \"want-0.3.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.want-0.3.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasi-0.11.1-wasi-snapshot-preview1\",\n sha256 = \"ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasi/0.11.1+wasi-snapshot-preview1/download\"],\n strip_prefix = \"wasi-0.11.1+wasi-snapshot-preview1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasi-0.11.1+wasi-snapshot-preview1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-0.2.129\",\n sha256 = \"9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-macro-0.2.129\",\n sha256 = \"2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen-macro/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-macro-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-macro-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-macro-support-0.2.129\",\n sha256 = \"6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen-macro-support/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-macro-support-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-macro-support-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__wasm-bindgen-shared-0.2.129\",\n sha256 = \"23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/wasm-bindgen-shared/0.2.129/download\"],\n strip_prefix = \"wasm-bindgen-shared-0.2.129\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.wasm-bindgen-shared-0.2.129.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-0.3.9\",\n sha256 = \"5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi/0.3.9/download\"],\n strip_prefix = \"winapi-0.3.9\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-0.3.9.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-i686-pc-windows-gnu-0.4.0\",\n sha256 = \"ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi-i686-pc-windows-gnu/0.4.0/download\"],\n strip_prefix = \"winapi-i686-pc-windows-gnu-0.4.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-util-0.1.11\",\n sha256 = \"c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi-util/0.1.11/download\"],\n strip_prefix = \"winapi-util-0.1.11\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-util-0.1.11.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__winapi-x86_64-pc-windows-gnu-0.4.0\",\n sha256 = \"712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/winapi-x86_64-pc-windows-gnu/0.4.0/download\"],\n strip_prefix = \"winapi-x86_64-pc-windows-gnu-0.4.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-core-0.62.2\",\n sha256 = \"b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-core/0.62.2/download\"],\n strip_prefix = \"windows-core-0.62.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-core-0.62.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-implement-0.60.2\",\n sha256 = \"053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-implement/0.60.2/download\"],\n strip_prefix = \"windows-implement-0.60.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-implement-0.60.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-interface-0.59.3\",\n sha256 = \"3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-interface/0.59.3/download\"],\n strip_prefix = \"windows-interface-0.59.3\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-interface-0.59.3.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-link-0.2.1\",\n sha256 = \"f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-link/0.2.1/download\"],\n strip_prefix = \"windows-link-0.2.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-link-0.2.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-result-0.4.1\",\n sha256 = \"7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-result/0.4.1/download\"],\n strip_prefix = \"windows-result-0.4.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-result-0.4.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-strings-0.5.1\",\n sha256 = \"7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-strings/0.5.1/download\"],\n strip_prefix = \"windows-strings-0.5.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-strings-0.5.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-sys-0.52.0\",\n sha256 = \"282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-sys/0.52.0/download\"],\n strip_prefix = \"windows-sys-0.52.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-sys-0.52.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-sys-0.61.2\",\n sha256 = \"ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-sys/0.61.2/download\"],\n strip_prefix = \"windows-sys-0.61.2\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-sys-0.61.2.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows-targets-0.52.6\",\n sha256 = \"9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows-targets/0.52.6/download\"],\n strip_prefix = \"windows-targets-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows-targets-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_aarch64_gnullvm-0.52.6\",\n sha256 = \"32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_aarch64_gnullvm/0.52.6/download\"],\n strip_prefix = \"windows_aarch64_gnullvm-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_aarch64_gnullvm-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_aarch64_msvc-0.52.6\",\n sha256 = \"09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_aarch64_msvc/0.52.6/download\"],\n strip_prefix = \"windows_aarch64_msvc-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_aarch64_msvc-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_i686_gnu-0.52.6\",\n sha256 = \"8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_i686_gnu/0.52.6/download\"],\n strip_prefix = \"windows_i686_gnu-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_i686_gnu-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_i686_gnullvm-0.52.6\",\n sha256 = \"0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_i686_gnullvm/0.52.6/download\"],\n strip_prefix = \"windows_i686_gnullvm-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_i686_gnullvm-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_i686_msvc-0.52.6\",\n sha256 = \"240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_i686_msvc/0.52.6/download\"],\n strip_prefix = \"windows_i686_msvc-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_i686_msvc-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_x86_64_gnu-0.52.6\",\n sha256 = \"147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_x86_64_gnu/0.52.6/download\"],\n strip_prefix = \"windows_x86_64_gnu-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_x86_64_gnu-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_x86_64_gnullvm-0.52.6\",\n sha256 = \"24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_x86_64_gnullvm/0.52.6/download\"],\n strip_prefix = \"windows_x86_64_gnullvm-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_x86_64_gnullvm-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__windows_x86_64_msvc-0.52.6\",\n sha256 = \"589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/windows_x86_64_msvc/0.52.6/download\"],\n strip_prefix = \"windows_x86_64_msvc-0.52.6\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.windows_x86_64_msvc-0.52.6.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__x509-parser-0.18.1\",\n sha256 = \"d43b0f71ce057da06bc0851b23ee24f3f86190b07203dd8f567d0b706a185202\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/x509-parser/0.18.1/download\"],\n strip_prefix = \"x509-parser-0.18.1\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.x509-parser-0.18.1.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zerocopy-0.8.58\",\n sha256 = \"c17e8fafad82b542ff3717217ecdc736231b59e387768c9630123b4ce4d2db44\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zerocopy/0.8.58/download\"],\n strip_prefix = \"zerocopy-0.8.58\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zerocopy-0.8.58.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zerocopy-derive-0.8.58\",\n sha256 = \"595f56e044df4f46a0c9a626f65c3d99eb8488f7e8a8baa12dd76326d9710bf2\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zerocopy-derive/0.8.58/download\"],\n strip_prefix = \"zerocopy-derive-0.8.58\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zerocopy-derive-0.8.58.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zeroize-1.9.0\",\n sha256 = \"e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zeroize/1.9.0/download\"],\n strip_prefix = \"zeroize-1.9.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zeroize-1.9.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zlib-rs-0.6.8\",\n sha256 = \"b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zlib-rs/0.6.8/download\"],\n strip_prefix = \"zlib-rs-0.6.8\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zlib-rs-0.6.8.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zmij-1.0.23\",\n sha256 = \"29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zmij/1.0.23/download\"],\n strip_prefix = \"zmij-1.0.23\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zmij-1.0.23.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zstd-safe-8.2.0\",\n sha256 = \"ded520f16b29e1a9b771c722221b2b0a0398c2316d9bb3c42b458a5414d7434b\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zstd-safe/8.2.0/download\"],\n strip_prefix = \"zstd-safe-8.2.0\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zstd-safe-8.2.0.bazel\"),\n )\n\n maybe(\n http_archive,\n name = \"rust_crates__zstd-sys-2.1.2-zstd.1.5.7\",\n sha256 = \"481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3\",\n type = \"tar.gz\",\n urls = [\"https://rsproxy.cn/api/v1/crates/zstd-sys/2.1.2+zstd.1.5.7/download\"],\n strip_prefix = \"zstd-sys-2.1.2+zstd.1.5.7\",\n build_file = Label(\"@rust_crates//rust_crates:BUILD.zstd-sys-2.1.2+zstd.1.5.7.bazel\"),\n )\n\n return [\n struct(repo = \"rust_crates\", is_dev_dep = False),\n struct(repo=\"rust_crates__chrono-0.4.45\", is_dev_dep = False),\n struct(repo=\"rust_crates__cxx-1.0.202\", is_dev_dep = False),\n struct(repo=\"rust_crates__fancy-regex-0.20.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__fast-float2-0.2.4\", is_dev_dep = False),\n struct(repo=\"rust_crates__getrandom-0.4.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__globset-0.4.18\", is_dev_dep = False),\n struct(repo=\"rust_crates__libc-0.2.189\", is_dev_dep = False),\n struct(repo=\"rust_crates__libm-0.2.16\", is_dev_dep = False),\n struct(repo=\"rust_crates__log-0.4.34\", is_dev_dep = False),\n struct(repo=\"rust_crates__memchr-2.8.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__mio-1.2.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__peg-0.8.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__prost-0.14.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__prost-build-0.14.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__prost-types-0.14.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__protox-0.9.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__psm-0.1.24\", is_dev_dep = False),\n struct(repo=\"rust_crates__quick-xml-0.41.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__rustls-0.23.46\", is_dev_dep = False),\n struct(repo=\"rust_crates__rustls-pki-types-1.15.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__ryu-1.0.23\", is_dev_dep = False),\n struct(repo=\"rust_crates__s2rst-0.5.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__serde-1.0.229\", is_dev_dep = False),\n struct(repo=\"rust_crates__serde_json-1.0.151\", is_dev_dep = False),\n struct(repo=\"rust_crates__simsimd-6.5.16\", is_dev_dep = False),\n struct(repo=\"rust_crates__slab-0.4.12\", is_dev_dep = False),\n struct(repo=\"rust_crates__socket2-0.6.5\", is_dev_dep = False),\n struct(repo=\"rust_crates__spdlog-rs-0.5.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__tokio-1.52.3\", is_dev_dep = False),\n struct(repo=\"rust_crates__tokio-stream-0.1.18\", is_dev_dep = False),\n struct(repo=\"rust_crates__tonic-0.14.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__tonic-prost-0.14.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__tonic-prost-build-0.14.6\", is_dev_dep = False),\n struct(repo=\"rust_crates__uuid-1.29.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__walkdir-2.5.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__windows-sys-0.61.2\", is_dev_dep = False),\n struct(repo=\"rust_crates__x509-parser-0.18.1\", is_dev_dep = False),\n struct(repo=\"rust_crates__zlib-rs-0.6.8\", is_dev_dep = False),\n struct(repo=\"rust_crates__zstd-safe-8.2.0\", is_dev_dep = False),\n struct(repo=\"rust_crates__zstd-sys-2.1.2-zstd.1.5.7\", is_dev_dep = False),\n ]\n", "defs.bzl": "###############################################################################\n# @generated\n# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To \n# regenerate this file, run the following:\n#\n# bazel mod show_repo 'seekdb'\n###############################################################################\n\"\"\"Deprecated: re-exports the crate_universe macros from `:crates.bzl`.\"\"\"\n\nload(\n \":crates.bzl\",\n _aliases = \"aliases\",\n _all_crate_deps = \"all_crate_deps\",\n _crate_deps = \"crate_deps\",\n _crate_edition = \"crate_edition\",\n _crate_repositories = \"crate_repositories\",\n)\n\naliases = _aliases\nall_crate_deps = _all_crate_deps\ncrate_deps = _crate_deps\ncrate_edition = _crate_edition\ncrate_repositories = _crate_repositories\n", "chrono-0.4.45/BUILD.bazel": "###############################################################################\n# @generated\n# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To \n# regenerate this file, run the following:\n#\n# bazel mod show_repo 'seekdb'\n###############################################################################\n\npackage(default_visibility = [\"//visibility:public\"])\n\nalias(\n name = \"chrono-0.4.45\",\n actual = \"@rust_crates__chrono-0.4.45//:chrono\",\n tags = [\"manual\"],\n)\n", "chrono/BUILD.bazel": "###############################################################################\n# @generated\n# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To \n# regenerate this file, run the following:\n#\n# bazel mod show_repo 'seekdb'\n###############################################################################\n\npackage(default_visibility = [\"//visibility:public\"])\n\nalias(\n name = \"chrono\",\n actual = \"@rust_crates__chrono-0.4.45//:chrono\",\n tags = [\"manual\"],\n)\n", diff --git a/rust/modules.bzl b/rust/modules.bzl index 4f6e14fddf..4997ad4d55 100644 --- a/rust/modules.bzl +++ b/rust/modules.bzl @@ -11,6 +11,7 @@ MODULES = { "deps": [":file_io_headers"], "features": IO_FEATURES, }, + "tmp-file": {"bridge": "src/bridge.rs"}, "wal": {"bridge": "src/bridge.rs", "headers": ["include/callbacks.h"]}, "mvt": {"bridge": "src/bridge.rs"}, "standby-rpc": { diff --git a/rust/seekdb-rust/BUILD.bazel b/rust/seekdb-rust/BUILD.bazel index 69a9e0cf3f..758b3581c2 100644 --- a/rust/seekdb-rust/BUILD.bazel +++ b/rust/seekdb-rust/BUILD.bazel @@ -14,6 +14,7 @@ rust_static_library( }), deps = all_crate_deps(normal = True) + [ "//rust/wal", + "//rust/tmp-file:tmp_file", "//rust/mvt", "//rust/file-io:file_io", "//rust/storage-io:storage_io", diff --git a/rust/seekdb-rust/Cargo.toml b/rust/seekdb-rust/Cargo.toml index eeb427f52a..3eaaeda803 100644 --- a/rust/seekdb-rust/Cargo.toml +++ b/rust/seekdb-rust/Cargo.toml @@ -13,6 +13,7 @@ native-network = ["sql-nio/native-network"] native-http = ["dep:http-client"] [dependencies] +tmp-file = { path = "../tmp-file", features = ["cxx"] } wal = { path = "../wal" } mvt = { path = "../mvt" } file-io = { path = "../file-io", features = ["cxx"] } diff --git a/rust/seekdb-rust/src/lib.rs b/rust/seekdb-rust/src/lib.rs index 62986e453f..11f1f8f3ce 100644 --- a/rust/seekdb-rust/src/lib.rs +++ b/rust/seekdb-rust/src/lib.rs @@ -37,4 +37,5 @@ pub use uuid_generator; pub use xml_parser; pub use math; pub use vector_kernels; +pub use tmp_file; pub use wal; diff --git a/rust/tmp-file/BUILD.bazel b/rust/tmp-file/BUILD.bazel new file mode 100644 index 0000000000..fffa1d416a --- /dev/null +++ b/rust/tmp-file/BUILD.bazel @@ -0,0 +1,25 @@ +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") +load("@rust_crates//:crates.bzl", "aliases", "all_crate_deps", "crate_edition") + +package(default_visibility = ["//rust:__subpackages__"]) + +exports_files(["src/bridge.rs"], visibility = ["//rust:__pkg__"]) + +rust_library( + name = "tmp_file", + crate_root = "src/lib.rs", + srcs = glob(["src/**/*.rs"]), + edition = crate_edition(), + version = "0.1.0", + crate_features = ["cxx"], + deps = all_crate_deps(normal = True) + ["//rust/file-io:file_io"], + proc_macro_deps = all_crate_deps(proc_macro = True), + aliases = aliases(), + tags = ["no-remote"], +) + +rust_test( + name = "tmp_file_test", + crate = ":tmp_file", + tags = ["no-remote"], +) diff --git a/rust/tmp-file/Cargo.toml b/rust/tmp-file/Cargo.toml new file mode 100644 index 0000000000..2bdb3d686d --- /dev/null +++ b/rust/tmp-file/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "tmp-file" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +file-io = { path = "../file-io" } +tokio = { version = "=1.52.3", default-features = false, features = ["rt"] } +cxx = { version = "=1.0.202", optional = true } diff --git a/rust/tmp-file/src/bridge.rs b/rust/tmp-file/src/bridge.rs new file mode 100644 index 0000000000..b88a9e49cd --- /dev/null +++ b/rust/tmp-file/src/bridge.rs @@ -0,0 +1,382 @@ +// Copyright (c) 2026 OceanBase. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::time::{Duration, Instant}; + +use crate::{Buffer, Engine, Error, FileId, Options, Request}; + +#[cxx::bridge(namespace = "oceanbase::tmp_file::rust_io")] +mod ffi { + #[derive(Clone, Copy)] + enum Code { + Ok, + Invalid, + Closed, + Sealed, + Busy, + End, + Timeout, + Canceled, + DiskQuota, + DiskFull, + BufferQuota, + Io, + } + + #[derive(Clone, Copy)] + struct Status { + code: Code, + os_error: i32, + } + + struct Snapshot { + len: u64, + prefix: u64, + sealed: bool, + group: i64, + writes: u64, + reads: u64, + read_bytes: u64, + } + + struct Usage { + disk_bytes: u64, + buffer_bytes: u64, + cache_bytes: u64, + disk_limit: u64, + } + + extern "Rust" { + type Service; + type IoRequest; + + fn new_service( + data_dir: &str, + disk_limit: u64, + buffer_limit: u64, + status: &mut Status, + ) -> Box; + fn new_group(self: &Service, id: &mut i64) -> Status; + fn open(self: &Service, group: i64, id: &mut i64) -> Status; + fn close(self: &Service, id: i64) -> Status; + fn seal(self: &Service, id: i64) -> Status; + fn reclaim(self: &Service, id: i64, offset: i64) -> Status; + fn snapshot(self: &Service, id: i64, snapshot: &mut Snapshot) -> Status; + fn files(self: &Service) -> Vec; + fn usage(self: &Service) -> Usage; + fn shutdown(self: &Service) -> Status; + fn configure(self: &Service, disk_limit: u64, buffer_limit: u64); + fn append( + self: &Service, + id: i64, + data: &[u8], + timeout_ms: u64, + status: &mut Status, + ) -> Box; + fn read( + self: &Service, + id: i64, + offset: i64, + size: usize, + timeout_ms: u64, + status: &mut Status, + ) -> Box; + + fn read_at( + self: &Service, + id: i64, + offset: u64, + dst: &mut [u8], + timeout_ms: u64, + status: &mut Status, + ) -> Box; + + fn wait(self: &mut IoRequest) -> Status; + fn is_finished(self: &IoRequest) -> bool; + fn done(self: &IoRequest) -> usize; + fn copy_read(self: &mut IoRequest, dst: &mut [u8]) -> Status; + } +} + +use ffi::{Code, Snapshot, Status, Usage}; + +impl From> for Status { + fn from(result: crate::Result<()>) -> Self { + let mut os_error = 0; + let code = match result { + Ok(()) => Code::Ok, + Err(Error::Invalid) => Code::Invalid, + Err(Error::Closed) => Code::Closed, + Err(Error::Sealed) => Code::Sealed, + Err(Error::Busy) => Code::Busy, + Err(Error::End) => Code::End, + Err(Error::Timeout) => Code::Timeout, + Err(Error::Canceled) => Code::Canceled, + Err(Error::DiskQuota) => Code::DiskQuota, + Err(Error::DiskFull) => Code::DiskFull, + Err(Error::BufferQuota) => Code::BufferQuota, + Err(Error::Io(error)) => { + os_error = error.raw_os_error().unwrap_or_default(); + match error.kind() { + std::io::ErrorKind::StorageFull | std::io::ErrorKind::QuotaExceeded => { + Code::DiskFull + } + _ => Code::Io, + } + } + }; + Status { code, os_error } + } +} + +pub struct Service(Option); + +fn new_service( + data_dir: &str, + disk_limit: u64, + buffer_limit: u64, + status: &mut Status, +) -> Box { + let root = std::path::Path::new(data_dir).join("spill"); + let options = Options { + segment_size: 8 * 1024 * 1024, + disk_limit: effective_disk_limit(disk_limit), + buffer_limit, + max_requests: 512, + workers: 4, + // Leave bounded headroom on the shared data volume for persistent writes. + min_free_space: file_io::space(&root) + .or_else(|_| file_io::space(std::path::Path::new(data_dir))) + .map_or(0, |space| (space.capacity / 20).min(1024 * 1024 * 1024)), + }; + match Engine::new(&root, options) { + Ok(engine) => { + *status = Ok(()).into(); + Box::new(Service(Some(engine))) + } + Err(error) => { + *status = Err(error).into(); + Box::new(Service(None)) + } + } +} + +fn effective_disk_limit(limit: u64) -> u64 { + if limit == 0 { + i64::MAX as u64 + } else { + limit + } +} + +impl Service { + fn engine(&self) -> &Engine { + // C++ retains the service only after successful initialization. + self.0.as_ref().unwrap() + } + + fn new_group(&self, id: &mut i64) -> Status { + self.engine().new_group().map(|group| *id = group).into() + } + + fn open(&self, group: i64, id: &mut i64) -> Status { + self.engine() + .open(group) + .map(|opened| *id = opened.as_raw() as i64) + .into() + } + + fn close(&self, id: i64) -> Status { + self.engine().close(FileId::from_raw(id as u64)).into() + } + + fn seal(&self, id: i64) -> Status { + self.engine().seal(FileId::from_raw(id as u64)).into() + } + + fn reclaim(&self, id: i64, offset: i64) -> Status { + self.engine() + .reclaim_prefix(FileId::from_raw(id as u64), offset as u64) + .into() + } + + fn snapshot(&self, id: i64, out: &mut Snapshot) -> Status { + self.engine() + .snapshot(FileId::from_raw(id as u64)) + .map(|snapshot| { + *out = Snapshot { + len: snapshot.len, + prefix: snapshot.prefix, + sealed: snapshot.sealed, + group: snapshot.group, + writes: snapshot.writes, + reads: snapshot.reads, + read_bytes: snapshot.read_bytes, + }; + }) + .into() + } + + fn files(&self) -> Vec { + self.engine() + .files() + .into_iter() + .map(|id| id.as_raw() as i64) + .collect() + } + + fn usage(&self) -> Usage { + let usage = self.engine().usage(); + Usage { + disk_bytes: usage.disk_bytes, + buffer_bytes: usage.buffer_bytes, + cache_bytes: usage.cache_bytes, + disk_limit: usage.disk_limit, + } + } + + fn shutdown(&self) -> Status { + self.engine().shutdown().into() + } + + fn configure(&self, disk_limit: u64, buffer_limit: u64) { + self.engine() + .configure(effective_disk_limit(disk_limit), buffer_limit); + } + + fn append(&self, id: i64, data: &[u8], timeout_ms: u64, status: &mut Status) -> Box { + IoRequest::submitted( + self.engine() + .append(FileId::from_raw(id as u64), data, deadline(timeout_ms)) + .map(Pending::Write), + status, + ) + } + + fn read_at( + &self, + id: i64, + offset: u64, + dst: &mut [u8], + timeout_ms: u64, + status: &mut Status, + ) -> Box { + let result = self.engine().read_at( + FileId::from_raw(id as u64), + offset, + dst, + deadline(timeout_ms), + ); + let mut done = 0; + *status = result.map(|len| done = len).into(); + Box::new(IoRequest { + pending: None, + buffer: None, + done, + status: *status, + }) + } + + fn read( + &self, + id: i64, + offset: i64, + size: usize, + timeout_ms: u64, + status: &mut Status, + ) -> Box { + let offset = u64::try_from(offset).ok(); + IoRequest::submitted( + self.engine() + .read( + FileId::from_raw(id as u64), + offset, + size, + deadline(timeout_ms), + ) + .map(Pending::Read), + status, + ) + } +} + +fn deadline(timeout_ms: u64) -> Instant { + Instant::now() + Duration::from_millis(timeout_ms.min(i64::MAX as u64 / 1000)) +} + +enum Pending { + Read(Request), + Write(Request), +} + +pub struct IoRequest { + pending: Option, + buffer: Option, + done: usize, + status: Status, +} + +impl IoRequest { + fn submitted(result: crate::Result, status: &mut Status) -> Box { + let pending = match result { + Ok(request) => { + *status = Ok(()).into(); + Some(request) + } + Err(error) => { + *status = Err(error).into(); + None + } + }; + Box::new(Self { + pending, + buffer: None, + done: 0, + status: *status, + }) + } + + fn wait(&mut self) -> Status { + if let Some(pending) = self.pending.take() { + self.status = match pending { + Pending::Read(read) => read.wait().map(|buffer| { + self.done = buffer.as_ref().len(); + self.buffer = Some(buffer); + }), + Pending::Write(write) => write.wait().map(|done| self.done = done), + } + .into(); + } + self.status + } + + fn is_finished(&self) -> bool { + self.pending.is_none() + } + + fn done(&self) -> usize { + self.done + } + + fn copy_read(&mut self, dst: &mut [u8]) -> Status { + if let Some(buffer) = self.buffer.take() { + let bytes = buffer.as_ref(); + let Some(dst) = dst.get_mut(..bytes.len()) else { + return Err(Error::Invalid).into(); + }; + dst.copy_from_slice(bytes); + } + Ok(()).into() + } +} diff --git a/rust/tmp-file/src/lib.rs b/rust/tmp-file/src/lib.rs new file mode 100644 index 0000000000..6d259335b9 --- /dev/null +++ b/rust/tmp-file/src/lib.rs @@ -0,0 +1,908 @@ +// Copyright (c) 2026 OceanBase. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::collections::{BTreeMap, HashMap, VecDeque}; +use std::fs::{self, File, OpenOptions}; +use std::io; +use std::path::{Path, PathBuf}; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::{Arc, Condvar, Mutex, RwLock, RwLockReadGuard}; +use std::time::Instant; + +use tokio::runtime::{Builder, Runtime}; + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub struct FileId(u64); + +// IDs remain unique when an embedded instance is torn down and reopened. +static NEXT_FILE_ID: AtomicU64 = AtomicU64::new(0); + +impl FileId { + pub fn from_raw(id: u64) -> Self { + Self(id) + } + + pub fn as_raw(self) -> u64 { + self.0 + } +} + +#[derive(Debug)] +pub enum Error { + Invalid, + Closed, + Sealed, + Busy, + End, + Timeout, + Canceled, + DiskQuota, + DiskFull, + BufferQuota, + Io(io::Error), +} + +impl From for Error { + fn from(error: io::Error) -> Self { + Self::Io(error) + } +} + +type Result = std::result::Result; + +pub struct Options { + pub segment_size: u64, + pub disk_limit: u64, + pub buffer_limit: u64, + pub max_requests: u64, + pub workers: usize, + pub min_free_space: u64, +} + +struct Quota { + used: AtomicU64, + limit: AtomicU64, +} + +impl Quota { + fn new(limit: u64) -> Self { + Self { + used: AtomicU64::new(0), + limit: AtomicU64::new(limit), + } + } + + fn reserve(&self, bytes: u64) -> bool { + self.used + .try_update(Ordering::AcqRel, Ordering::Acquire, |used| { + used.checked_add(bytes) + .filter(|&next| next <= self.limit.load(Ordering::Acquire)) + }) + .is_ok() + } + + fn release(&self, bytes: u64) { + self.used.fetch_sub(bytes, Ordering::AcqRel); + } + + fn used(&self) -> u64 { + self.used.load(Ordering::Acquire) + } +} + +struct Charge { + quota: Arc, + amount: u64, +} + +impl Drop for Charge { + fn drop(&mut self) { + self.quota.release(self.amount); + } +} + +struct Directory { + path: PathBuf, + _lock: file_io::ExclusiveFile, + disk: Quota, + min_free_space: u64, +} + +impl Drop for Directory { + fn drop(&mut self) { + // If removal fails, the next owner of the lock retries on startup. + let _ = fs::remove_dir_all(&self.path); + } +} + +struct Segment { + path: PathBuf, + directory: Arc, + charged: AtomicU64, +} + +impl Segment { + // Only the file's single admitted append can grow any of its segments. + fn reserve_through(&self, end: u64) -> Result<()> { + let charged = self.charged.load(Ordering::Relaxed); + if end > charged { + if !self.directory.disk.reserve(end - charged) { + return Err(Error::DiskQuota); + } + if self.directory.min_free_space > 0 { + let available = file_io::space(&self.directory.path).map(|space| space.available); + match available { + Ok(bytes) + if bytes >= self.directory.min_free_space.saturating_add(end - charged) => { + } + other => { + self.directory.disk.release(end - charged); + return Err(other.err().map_or(Error::DiskFull, Error::Io)); + } + } + } + self.charged.store(end, Ordering::Relaxed); + } + Ok(()) + } + + fn rollback_to(&self, len: u64) { + let charged = self.charged.load(Ordering::Relaxed); + if charged > len + && OpenOptions::new() + .write(true) + .open(&self.path) + .and_then(|file| file.set_len(len)) + .is_ok() + { + self.charged.store(len, Ordering::Relaxed); + self.directory.disk.release(charged - len); + } + } +} + +impl Drop for Segment { + fn drop(&mut self) { + // Keep the charge when deletion fails. The directory owner will retry. + match fs::remove_file(&self.path) { + Ok(()) => self + .directory + .disk + .release(self.charged.load(Ordering::Relaxed)), + Err(error) if error.kind() == io::ErrorKind::NotFound => { + self.directory + .disk + .release(self.charged.load(Ordering::Relaxed)); + } + Err(_) => (), + } + } +} + +const READ_CACHE_ENTRIES: usize = 4; +const MIN_CACHED_READ: usize = 128 * 1024; +const MAX_CACHED_READ: usize = 512 * 1024; + +struct CachedRead { + offset: u64, + data: Arc, +} + +#[derive(Default)] +struct FileState { + segments: BTreeMap>, + read_cache: VecDeque, + end: u64, + prefix: u64, + cursor: u64, + appending: bool, + sealed: bool, + writes: u64, + reads: u64, + read_bytes: u64, +} + +impl FileState { + fn lookup_read(&mut self, offset: u64, len: usize) -> Option> { + let index = self + .read_cache + .iter() + .position(|entry| entry.offset == offset && entry.data.bytes.len() == len)?; + let entry = self.read_cache.remove(index).unwrap(); + let data = entry.data.clone(); + self.read_cache.push_back(entry); + Some(data) + } + + fn cache_read(&mut self, offset: u64, bytes: &[u8], quota: &Arc) { + if offset < self.prefix || self.lookup_read(offset, bytes.len()).is_some() { + return; + } + if self.read_cache.len() == READ_CACHE_ENTRIES { + self.read_cache.pop_front(); + } + if let Ok(mut data) = Buffer::new(quota, bytes.len()) { + data.bytes.extend_from_slice(bytes); + self.read_cache.push_back(CachedRead { + offset, + data: Arc::new(data), + }); + } + } +} + +struct SpillFile { + id: FileId, + group: i64, + state: Mutex, +} + +impl SpillFile { + fn record_read(&self, len: usize) { + let mut state = self.state.lock().unwrap(); + state.reads = state.reads.saturating_add(1); + state.read_bytes = state.read_bytes.saturating_add(len as u64); + } +} + +struct ReadPlan { + start: u64, + data_start: u64, + end: u64, + segment_size: u64, + segments: Vec>, +} + +impl ReadPlan { + fn new(state: &FileState, start: u64, size: usize, segment_size: u64) -> Result { + if size == 0 { + return Err(Error::Invalid); + } + if start >= state.end { + return Err(Error::End); + } + let end = start + (state.end - start).min(size as u64); + let data_start = start.max(state.prefix).min(end); + let segments = if data_start < end { + let first = data_start / segment_size; + let last = (end - 1) / segment_size; + let segments: Vec<_> = state + .segments + .range(first..=last) + .map(|(_, segment)| segment.clone()) + .collect(); + if segments.len() as u64 != last - first + 1 { + return Err(Error::Invalid); + } + segments + } else { + Vec::new() + }; + Ok(Self { + start, + data_start, + end, + segment_size, + segments, + }) + } + + fn len(&self) -> usize { + (self.end - self.start) as usize + } + + fn read_into(&self, dst: &mut [u8], check: impl Fn() -> Result<()>) -> Result<()> { + // Reads of the discarded prefix retain their original zero-fill semantics. + dst[..(self.data_start - self.start) as usize].fill(0); + let mut pos = self.data_start; + for segment in &self.segments { + check()?; + let offset = pos % self.segment_size; + let size = (self.end - pos).min(self.segment_size - offset); + let first = (pos - self.start) as usize; + let source = File::open(&segment.path)?; + file_io::read_exact_at(&source, &mut dst[first..first + size as usize], offset)?; + pos += size; + } + check() + } +} + +pub struct Engine { + directory: Arc, + segment_size: u64, + buffer: Arc, + read_cache: Arc, + requests: Arc, + files: Mutex>>, + next_group: AtomicU64, + runtime: RwLock>, +} + +#[derive(Debug, Eq, PartialEq)] +pub struct FileSnapshot { + pub len: u64, + pub prefix: u64, + pub sealed: bool, + pub group: i64, + pub writes: u64, + pub reads: u64, + pub read_bytes: u64, +} + +#[derive(Debug)] +pub struct Usage { + pub disk_bytes: u64, + pub buffer_bytes: u64, + pub cache_bytes: u64, + pub disk_limit: u64, +} + +impl Engine { + pub fn new(root: &Path, options: Options) -> Result { + if options.segment_size == 0 || options.max_requests == 0 || options.workers == 0 { + return Err(Error::Invalid); + } + fs::create_dir_all(root)?; + let lock = OpenOptions::new() + .read(true) + .write(true) + .create(true) + .truncate(false) + .open(root.join("lock"))?; + let lock = file_io::ExclusiveFile::try_new(lock).map_err(|error| { + if error.kind() == io::ErrorKind::WouldBlock { + Error::Busy + } else { + Error::Io(error) + } + })?; + let path = root.join("segments"); + match fs::remove_dir_all(&path) { + Ok(()) => (), + Err(error) if error.kind() == io::ErrorKind::NotFound => (), + Err(error) => return Err(error.into()), + } + create_segment_directory(&path)?; + let directory = Arc::new(Directory { + path, + _lock: lock, + disk: Quota::new(options.disk_limit), + min_free_space: options.min_free_space, + }); + let runtime = Builder::new_current_thread() + .thread_name("tmp-file-io") + .max_blocking_threads(options.workers) + .build()?; + Ok(Self { + directory, + segment_size: options.segment_size, + buffer: Arc::new(Quota::new(options.buffer_limit)), + read_cache: Arc::new(Quota::new(cache_limit(options.buffer_limit))), + requests: Arc::new(Quota::new(options.max_requests)), + files: Mutex::new(HashMap::new()), + next_group: AtomicU64::new(1), + runtime: RwLock::new(Some(runtime)), + }) + } + + pub fn new_group(&self) -> Result { + let _runtime = self.active()?; + next_id(&self.next_group).map(|id| id as i64) + } + + pub fn open(&self, group: i64) -> Result { + let _runtime = self.active()?; + let id = FileId(next_id(&NEXT_FILE_ID)?); + self.files.lock().unwrap().insert( + id, + Arc::new(SpillFile { + id, + group, + state: Mutex::default(), + }), + ); + Ok(id) + } + + pub fn close(&self, id: FileId) -> Result<()> { + let removed = self.files.lock().unwrap().remove(&id); + drop(removed); + Ok(()) + } + + fn file(&self, id: FileId) -> Result> { + self.files + .lock() + .unwrap() + .get(&id) + .cloned() + .ok_or(Error::Closed) + } + + pub fn files(&self) -> Vec { + self.files.lock().unwrap().keys().copied().collect() + } + + pub fn snapshot(&self, id: FileId) -> Result { + let file = self.file(id)?; + let state = file.state.lock().unwrap(); + Ok(FileSnapshot { + len: state.end, + prefix: state.prefix, + sealed: state.sealed, + group: file.group, + writes: state.writes, + reads: state.reads, + read_bytes: state.read_bytes, + }) + } + + pub fn usage(&self) -> Usage { + Usage { + disk_bytes: self.directory.disk.used(), + buffer_bytes: self.buffer.used(), + cache_bytes: self.read_cache.used(), + disk_limit: self.directory.disk.limit.load(Ordering::Acquire), + } + } + + pub fn configure(&self, disk_limit: u64, buffer_limit: u64) { + self.directory + .disk + .limit + .store(disk_limit, Ordering::Release); + self.buffer.limit.store(buffer_limit, Ordering::Release); + let cache_limit = cache_limit(buffer_limit); + self.read_cache.limit.store(cache_limit, Ordering::Release); + if self.read_cache.used() > cache_limit { + for file in self.files.lock().unwrap().values() { + file.state.lock().unwrap().read_cache.clear(); + } + } + } + + pub fn seal(&self, id: FileId) -> Result<()> { + let file = self.file(id)?; + let mut state = file.state.lock().unwrap(); + if state.appending { + return Err(Error::Busy); + } + state.sealed = true; + if state.prefix == state.end { + let removed = std::mem::take(&mut state.segments); + drop(state); + drop(removed); + } + Ok(()) + } + + pub fn reclaim_prefix(&self, id: FileId, offset: u64) -> Result<()> { + let file = self.file(id)?; + let mut state = file.state.lock().unwrap(); + if offset > state.end { + return Err(Error::Invalid); + } + state.prefix = state.prefix.max(offset); + let prefix = state.prefix; + state.cursor = state.cursor.max(prefix); + state.read_cache.retain(|entry| entry.offset >= prefix); + let keep = state.prefix / self.segment_size; + let remaining = if state.sealed && state.prefix == state.end { + BTreeMap::new() + } else { + state.segments.split_off(&keep) + }; + let removed = std::mem::replace(&mut state.segments, remaining); + drop(state); + drop(removed); + Ok(()) + } + + pub fn append(&self, id: FileId, bytes: &[u8], deadline: Instant) -> Result> { + if bytes.is_empty() { + return Err(Error::Invalid); + } + let runtime = self.active()?; + let slot = self.request_slot(deadline)?; + let file = self.file(id)?; + let mut buffer = Buffer::new(&self.buffer, bytes.len())?; + buffer.bytes.extend_from_slice(bytes); + let segment_size = self.segment_size; + let directory = self.directory.clone(); + let mut state = file.state.lock().unwrap(); + if state.sealed { + return Err(Error::Sealed); + } + if state.appending { + return Err(Error::Busy); + } + let start = state.end; + let end = start + .checked_add(bytes.len() as u64) + .filter(|&end| end <= i64::MAX as u64) + .ok_or(Error::Invalid)?; + state.appending = true; + drop(state); + Ok(Self::submit( + runtime.as_ref().unwrap(), + slot, + deadline, + move |completion, slot| { + let result = (|| { + let mut pos = start; + while pos < end { + completion.control.check()?; + let index = pos / segment_size; + let offset = pos % segment_size; + let size = (end - pos).min(segment_size - offset); + let segment = file + .state + .lock() + .unwrap() + .segments + .entry(index) + .or_insert_with(|| { + Arc::new(Segment { + path: directory.path.join(format!("{}-{index}", file.id.0)), + directory: directory.clone(), + charged: AtomicU64::new(0), + }) + }) + .clone(); + segment.reserve_through(offset + size)?; + let target = OpenOptions::new() + .write(true) + .create(true) + .truncate(false) + .open(&segment.path)?; + let first = (pos - start) as usize; + file_io::write_all_at( + &target, + &buffer.bytes[first..first + size as usize], + offset, + )?; + pos += size; + } + Ok(buffer.bytes.len()) + })(); + drop(buffer); + let error = { + let mut ready = completion.result.lock().unwrap(); + match completion.control.check().and(result) { + Ok(written) => { + let mut state = file.state.lock().unwrap(); + state.end = end; + state.writes = state.writes.saturating_add(1); + state.appending = false; + drop(slot); + *ready = Some(Ok(written)); + completion.ready.notify_all(); + return; + } + Err(error) => error, + } + }; + + // Keep append admission closed while the abandoned suffix is removed. + // The completion mutex remains free so timeout and cancellation can return. + let (abandoned, tail) = { + let mut state = file.state.lock().unwrap(); + let abandoned = state.segments.split_off(&start.div_ceil(segment_size)); + let tail = state.segments.get(&(start / segment_size)).cloned(); + (abandoned, tail) + }; + drop(abandoned); + if let Some(tail) = tail { + tail.rollback_to(start % segment_size); + } + file.state.lock().unwrap().appending = false; + drop(slot); + completion.publish(Err(error), |_| {}); + }, + )) + } + + /// None reserves a range at the sequential cursor. Explicit offsets leave it unchanged. + pub fn read( + &self, + id: FileId, + offset: Option, + len: usize, + deadline: Instant, + ) -> Result> { + let runtime = self.active()?; + let slot = self.request_slot(deadline)?; + let file = self.file(id)?; + let mut state = file.state.lock().unwrap(); + let plan = ReadPlan::new( + &state, + offset.unwrap_or(state.cursor), + len, + self.segment_size, + )?; + let mut buffer = Buffer::new(&self.buffer, plan.len())?; + buffer.bytes.resize(plan.len(), 0); + if offset.is_none() { + state.cursor = plan.end; + } + drop(state); + Ok(Self::submit( + runtime.as_ref().unwrap(), + slot, + deadline, + move |completion, slot| { + let len = plan.len(); + let result = plan + .read_into(&mut buffer.bytes, || completion.control.check()) + .map(|()| buffer); + drop(plan); + drop(slot); + completion.publish(result, |completed| { + if completed { + file.record_read(len); + } + }); + }, + )) + } + + /// Synchronous positioned read. The destination is borrowed only for this call. + /// A blocking filesystem call can finish after the deadline, in which case the + /// caller receives a timeout with the destination still in its possession. + pub fn read_at( + &self, + id: FileId, + offset: u64, + dst: &mut [u8], + deadline: Instant, + ) -> Result { + let _runtime = self.active()?; + let _slot = self.request_slot(deadline)?; + let file = self.file(id)?; + let check_deadline = || { + if Instant::now() >= deadline { + Err(Error::Timeout) + } else { + Ok(()) + } + }; + let mut state = file.state.lock().unwrap(); + let requested = (state.end.saturating_sub(offset)).min(dst.len() as u64) as usize; + let cacheable = + offset >= state.prefix && (MIN_CACHED_READ..=MAX_CACHED_READ).contains(&requested); + if cacheable { + if let Some(data) = state.lookup_read(offset, requested) { + drop(state); + dst[..requested].copy_from_slice(data.as_ref().as_ref()); + check_deadline()?; + file.record_read(requested); + return Ok(requested); + } + } + let plan = ReadPlan::new(&state, offset, dst.len(), self.segment_size)?; + drop(state); + let len = plan.len(); + plan.read_into(&mut dst[..len], check_deadline)?; + if cacheable { + file.state + .lock() + .unwrap() + .cache_read(offset, &dst[..len], &self.read_cache); + } + file.record_read(len); + Ok(len) + } + + fn active(&self) -> Result>> { + let runtime = self.runtime.read().unwrap(); + if runtime.is_some() { + Ok(runtime) + } else { + Err(Error::Closed) + } + } + + /// Stops admission, joins accepted I/O, and removes this instance's segments. + /// The directory lock remains held until the engine is dropped. + pub fn shutdown(&self) -> Result<()> { + let mut runtime = self.runtime.write().unwrap(); + if let Some(runtime) = runtime.take() { + if tokio::runtime::Handle::try_current().is_ok() { + // Runtime drop blocks, so do it outside the calling Tokio context. + let thread = std::thread::spawn(move || drop(runtime)); + let _ = thread.join(); + } else { + drop(runtime); + } + } + self.files.lock().unwrap().clear(); + match fs::remove_dir_all(&self.directory.path) { + Ok(()) => Ok(()), + Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(()), + Err(error) => Err(error.into()), + } + } + + fn request_slot(&self, deadline: Instant) -> Result { + if Instant::now() >= deadline { + return Err(Error::Timeout); + } + if !self.requests.reserve(1) { + return Err(Error::Busy); + } + Ok(Charge { + quota: self.requests.clone(), + amount: 1, + }) + } + + fn submit( + runtime: &Runtime, + slot: Charge, + deadline: Instant, + run: impl FnOnce(&Completion, Charge) + Send + 'static, + ) -> Request { + let state = Arc::new(Completion { + control: Control { + deadline, + canceled: AtomicBool::new(false), + }, + result: Mutex::new(None), + ready: Condvar::new(), + }); + let worker = state.clone(); + runtime.spawn_blocking(move || { + run(&worker, slot); + }); + Request(state) + } +} + +#[cfg(unix)] +fn create_segment_directory(path: &Path) -> io::Result<()> { + use std::os::unix::fs::DirBuilderExt; + fs::DirBuilder::new().mode(0o700).create(path) +} + +#[cfg(not(unix))] +fn create_segment_directory(path: &Path) -> io::Result<()> { + fs::create_dir(path) +} + +fn next_id(counter: &AtomicU64) -> Result { + counter + .try_update(Ordering::Relaxed, Ordering::Relaxed, |id| { + id.checked_add(1).filter(|&next| next <= i64::MAX as u64) + }) + .map_err(|_| Error::Invalid) +} + +impl Drop for Engine { + fn drop(&mut self) { + let _ = self.shutdown(); + } +} + +pub struct Buffer { + bytes: Vec, + _charge: Charge, +} + +impl Buffer { + fn new(quota: &Arc, len: usize) -> Result { + let amount = len as u64; + if !quota.reserve(amount) { + return Err(Error::BufferQuota); + } + let charge = Charge { + quota: quota.clone(), + amount, + }; + let mut bytes = Vec::new(); + bytes + .try_reserve_exact(len) + .map_err(|_| Error::BufferQuota)?; + Ok(Self { + bytes, + _charge: charge, + }) + } +} + +fn cache_limit(buffer_limit: u64) -> u64 { + (buffer_limit / 8).min(8 * 1024 * 1024) +} + +impl AsRef<[u8]> for Buffer { + fn as_ref(&self) -> &[u8] { + &self.bytes + } +} + +struct Control { + deadline: Instant, + canceled: AtomicBool, +} + +impl Control { + fn check(&self) -> Result<()> { + if Instant::now() >= self.deadline { + Err(Error::Timeout) + } else if self.canceled.load(Ordering::Acquire) { + Err(Error::Canceled) + } else { + Ok(()) + } + } +} + +struct Completion { + control: Control, + result: Mutex>>, + ready: Condvar, +} + +impl Completion { + fn publish(&self, result: Result, finish: impl FnOnce(bool)) { + let mut ready = self.result.lock().unwrap(); + let result = self.control.check().and(result); + finish(result.is_ok()); + *ready = Some(result); + self.ready.notify_all(); + } +} + +pub struct Request(Arc>); + +impl Request { + pub fn cancel(&self) { + let _result = self.0.result.lock().unwrap(); + self.0.control.canceled.store(true, Ordering::Release); + self.0.ready.notify_all(); + } + + pub fn is_ready(&self) -> bool { + self.0.result.lock().unwrap().is_some() + } + + pub fn wait(self) -> Result { + let mut result = self.0.result.lock().unwrap(); + loop { + if let Some(result) = result.take() { + return result; + } + self.0.control.check()?; + let remaining = self + .0 + .control + .deadline + .saturating_duration_since(Instant::now()); + let (next, _) = self.0.ready.wait_timeout(result, remaining).unwrap(); + result = next; + } + } +} + +impl Drop for Request { + fn drop(&mut self) { + self.cancel(); + } +} + +#[cfg(feature = "cxx")] +pub mod bridge; + +#[cfg(test)] +mod tests; diff --git a/rust/tmp-file/src/tests.rs b/rust/tmp-file/src/tests.rs new file mode 100644 index 0000000000..b598ab1e11 --- /dev/null +++ b/rust/tmp-file/src/tests.rs @@ -0,0 +1,447 @@ +// Copyright (c) 2026 OceanBase. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; +use std::time::Duration; + +struct TestDir(PathBuf); + +impl TestDir { + fn new() -> Self { + let root = std::env::temp_dir().join(format!( + "tmp-file-tests-{}-{}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos(), + )); + fs::create_dir(&root).unwrap(); + Self(root) + } +} + +impl Drop for TestDir { + fn drop(&mut self) { + fs::remove_dir_all(&self.0).unwrap(); + } +} + +fn options() -> Options { + Options { + segment_size: 4096, + disk_limit: 32 * 1024, + buffer_limit: 16 * 1024, + max_requests: 10, + workers: 2, + min_free_space: 0, + } +} + +fn deadline() -> Instant { + Instant::now() + Duration::from_secs(10) +} + +#[test] +fn seal_and_reclaim_preserve_logical_offsets() { + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()).unwrap(); + let id = engine.open(0).unwrap(); + let bytes: Vec<_> = (0..12500).map(|i| (i % 251) as u8).collect(); + for chunk in bytes.chunks(1800) { + assert_eq!( + engine + .append(id, chunk, deadline()) + .unwrap() + .wait() + .unwrap(), + chunk.len() + ); + } + engine.seal(id).unwrap(); + assert!(matches!( + engine.append(id, b"x", deadline()), + Err(Error::Sealed) + )); + assert_eq!( + fs::read_dir(engine.directory.path.clone()).unwrap().count(), + 4 + ); + engine.reclaim_prefix(id, 8200).unwrap(); + assert_eq!(engine.usage().disk_bytes, 12500 - 8192); + assert_eq!( + fs::read_dir(engine.directory.path.clone()).unwrap().count(), + 2 + ); + assert_eq!( + engine.snapshot(id).unwrap(), + FileSnapshot { + len: 12500, + prefix: 8200, + sealed: true, + group: 0, + writes: 7, + reads: 0, + read_bytes: 0, + } + ); + assert_eq!( + engine + .read(id, Some(8199), 4, deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &[0, bytes[8200], bytes[8201], bytes[8202]] + ); + assert_eq!( + engine + .read(id, Some(12287), 9, deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &bytes[12287..12296] + ); + assert_eq!( + engine + .read(id, None, 9000, deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &bytes[8200..] + ); + assert!(matches!( + engine.read(id, None, 1, deadline()), + Err(Error::End) + )); + engine.reclaim_prefix(id, 12500).unwrap(); + assert_eq!(engine.usage().disk_bytes, 0); + assert_eq!( + fs::read_dir(engine.directory.path.clone()).unwrap().count(), + 0 + ); +} + +#[test] +fn quota_failure_can_be_retried_after_another_file_closes() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + disk_limit: 9000, + ..options() + }, + ) + .unwrap(); + let first = engine.open(0).unwrap(); + let second = engine.open(0).unwrap(); + engine + .append(first, &[1; 1024], deadline()) + .unwrap() + .wait() + .unwrap(); + engine + .append(second, &[2; 1000], deadline()) + .unwrap() + .wait() + .unwrap(); + assert!(matches!( + engine + .append(second, &[3; 7100], deadline()) + .unwrap() + .wait(), + Err(Error::DiskQuota) + )); + assert_eq!(engine.snapshot(second).unwrap().len, 1000); + assert_eq!( + engine + .read(second, None, 4096, deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &[2; 1000] + ); + engine.close(first).unwrap(); + engine + .append(second, &[3; 7100], deadline()) + .unwrap() + .wait() + .unwrap(); + assert_eq!(engine.usage().disk_bytes, 8100); + assert_eq!( + engine + .read(second, Some(1000), 7100, deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &[3; 7100] + ); +} + +#[test] +fn close_and_prefix_reclaim_keep_admitted_reads_alive() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + workers: 1, + ..options() + }, + ) + .unwrap(); + let id = engine.open(0).unwrap(); + engine + .append(id, &[2; 8192], deadline()) + .unwrap() + .wait() + .unwrap(); + let (send, receive) = std::sync::mpsc::channel(); + let gate = engine + .runtime + .read() + .unwrap() + .as_ref() + .unwrap() + .spawn_blocking(move || receive.recv().unwrap()); + let read_a = engine.read(id, None, 4096, deadline()).unwrap(); + let read_b = engine.read(id, None, 4096, deadline()).unwrap(); + engine.reclaim_prefix(id, 8192).unwrap(); + engine.close(id).unwrap(); + assert_eq!(engine.usage().disk_bytes, 8192); + assert!(matches!( + engine.read(id, None, 1, deadline()), + Err(Error::Closed) + )); + send.send(()).unwrap(); + drop(gate); + assert_eq!(read_a.wait().unwrap().as_ref(), &[2; 4096]); + assert_eq!(read_b.wait().unwrap().as_ref(), &[2; 4096]); + assert_eq!(engine.usage().disk_bytes, 0); + assert_eq!(engine.usage().buffer_bytes, 0); +} + +#[test] +fn timeout_and_cancel_do_not_commit_queued_appends() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + workers: 1, + ..options() + }, + ) + .unwrap(); + let first = engine.open(0).unwrap(); + let second = engine.open(0).unwrap(); + let (send, receive) = std::sync::mpsc::channel(); + let gate = engine + .runtime + .read() + .unwrap() + .as_ref() + .unwrap() + .spawn_blocking(move || receive.recv().unwrap()); + let timed = engine + .append( + first, + &[1; 2000], + Instant::now() + Duration::from_millis(100), + ) + .unwrap(); + let canceled = engine.append(second, &[2; 2000], deadline()).unwrap(); + canceled.cancel(); + assert!(matches!(canceled.wait(), Err(Error::Canceled))); + assert!(matches!(timed.wait(), Err(Error::Timeout))); + assert_eq!(engine.usage().buffer_bytes, 4000); + send.send(()).unwrap(); + drop(gate); + drop(engine); + assert!(!root.0.join("segments").exists()); +} + +#[test] +fn startup_owns_and_cleans_only_the_reserved_directory() { + let root = TestDir::new(); + fs::create_dir(root.0.join("segments")).unwrap(); + fs::write(root.0.join("segments/stale"), b"stale").unwrap(); + fs::write(root.0.join("keep"), b"persistent").unwrap(); + let engine = Engine::new(&root.0, options()).unwrap(); + assert!(matches!(Engine::new(&root.0, options()), Err(Error::Busy))); + assert_eq!(fs::read_dir(root.0.join("segments")).unwrap().count(), 0); + drop(engine); + assert!(!root.0.join("segments").exists()); + assert_eq!(fs::read(root.0.join("keep")).unwrap(), b"persistent"); +} + +#[cfg(target_os = "linux")] +#[test] +fn enospc_does_not_commit_or_leak_reserved_disk_bytes() { + use std::os::unix::fs::symlink; + + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()).unwrap(); + let file = engine.open(0).unwrap(); + let path = engine.directory.path.join(format!("{}-0", file.as_raw())); + symlink("/dev/full", &path).unwrap(); + assert!(matches!( + engine.append(file, b"spill", deadline()).unwrap().wait(), + Err(Error::Io(error)) if error.kind() == io::ErrorKind::StorageFull + )); + assert_eq!(engine.snapshot(file).unwrap().len, 0); + assert_eq!(engine.usage().disk_bytes, 0); + assert!(!path.exists()); + engine + .append(file, b"retry", deadline()) + .unwrap() + .wait() + .unwrap(); +} + +#[test] +fn growing_and_consuming_a_file_reuses_a_fixed_quota() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + disk_limit: 8192, + ..options() + }, + ) + .unwrap(); + let file = engine.open(0).unwrap(); + for index in 0..256 { + let data = [index as u8; 4096]; + engine + .append(file, &data, deadline()) + .unwrap() + .wait() + .unwrap(); + let offset = index * 4096; + assert_eq!( + engine + .read(file, Some(offset), data.len(), deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &data + ); + engine + .reclaim_prefix(file, offset + data.len() as u64) + .unwrap(); + assert_eq!(engine.usage().disk_bytes, 0); + assert_eq!(fs::read_dir(&engine.directory.path).unwrap().count(), 0); + } + assert_eq!(engine.snapshot(file).unwrap().len, 1024 * 1024); +} + +#[test] +fn runtime_quota_changes_apply_to_subsequent_reservations() { + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()).unwrap(); + let file = engine.open(0).unwrap(); + engine + .append(file, b"row", deadline()) + .unwrap() + .wait() + .unwrap(); + engine.configure(3, 8192); + assert!(matches!( + engine.append(file, b"x", deadline()).unwrap().wait(), + Err(Error::DiskQuota) + )); + engine.configure(8192, 3); + assert!(matches!( + engine.append(file, b"1234", deadline()), + Err(Error::BufferQuota) + )); + engine + .append(file, b"abc", deadline()) + .unwrap() + .wait() + .unwrap(); + assert_eq!(engine.snapshot(file).unwrap().len, 6); +} + +#[test] +fn synchronous_reads_borrow_the_destination_and_preserve_the_cursor() { + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()).unwrap(); + let id = engine.open(0).unwrap(); + engine + .append(id, &[5; 8192], deadline()) + .unwrap() + .wait() + .unwrap(); + engine.reclaim_prefix(id, 4096).unwrap(); + let mut dst = [99; 12]; + assert_eq!(engine.read_at(id, 4090, &mut dst, deadline()).unwrap(), 12); + assert_eq!(dst, [0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5]); + assert_eq!(engine.read_at(id, 8190, &mut dst, deadline()).unwrap(), 2); + assert_eq!(&dst[..3], &[5, 5, 0]); + assert_eq!( + engine + .read(id, None, 1, deadline()) + .unwrap() + .wait() + .unwrap() + .as_ref(), + &[5] + ); + assert_eq!(engine.usage().buffer_bytes, 0); +} + +#[test] +fn cached_positioned_reads_respect_prefix_reclamation_and_close() { + let root = TestDir::new(); + let len = MIN_CACHED_READ; + let engine = Engine::new( + &root.0, + Options { + segment_size: len as u64, + disk_limit: 2 * len as u64, + buffer_limit: 8 * len as u64, + ..options() + }, + ) + .unwrap(); + let file = engine.open(0).unwrap(); + let src = vec![7; 2 * len]; + engine + .append(file, &src, deadline()) + .unwrap() + .wait() + .unwrap(); + let mut dst = vec![0; len]; + engine.read_at(file, 0, &mut dst, deadline()).unwrap(); + assert_eq!(engine.usage().cache_bytes, len as u64); + assert_eq!(engine.usage().buffer_bytes, 0); + engine.read_at(file, 0, &mut dst, deadline()).unwrap(); + assert_eq!(&dst, &src[..len]); + engine.reclaim_prefix(file, len as u64).unwrap(); + assert_eq!(engine.usage().cache_bytes, 0); + engine.read_at(file, 0, &mut dst, deadline()).unwrap(); + assert!(dst.iter().all(|&byte| byte == 0)); + engine + .read_at(file, len as u64, &mut dst, deadline()) + .unwrap(); + assert_eq!(engine.usage().cache_bytes, len as u64); + engine.close(file).unwrap(); + assert_eq!(engine.usage().cache_bytes, 0); + assert_eq!(engine.usage().disk_bytes, 0); +} diff --git a/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h b/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h index aa2b512917..c4124a5adb 100644 --- a/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h +++ b/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h @@ -36,17 +36,12 @@ struct ObTmpFileIOInfo final bool is_valid() const; TO_STRING_KV(K(fd_), K(dir_id_), KP(buf_), K(size_), - K(disable_page_cache_), K(disable_block_cache_), K(prefetch_), - K(io_timeout_ms_), K(io_desc_)); + K(io_timeout_ms_)); int64_t fd_; int64_t dir_id_; char *buf_; int64_t size_; - bool disable_page_cache_; - bool disable_block_cache_; - bool prefetch_; - common::ObIOFlag io_desc_; int64_t io_timeout_ms_; }; @@ -64,7 +59,6 @@ class ObTmpFileIOHandle final bool is_valid() const; char *get_buffer(); int64_t get_done_size() const; - int64_t get_buf_size() const; bool is_finished() const; TO_STRING_KV(KP_(impl)); @@ -74,10 +68,13 @@ class ObTmpFileIOHandle final ObTmpFileIOHandle(const ObTmpFileIOHandle &) = delete; ObTmpFileIOHandle &operator=(const ObTmpFileIOHandle &) = delete; void *impl_; + char *buf_; + int64_t size_; + int64_t fd_; }; int tmp_file_alloc_dir(int64_t &dir_id); -int tmp_file_open(int64_t &fd, int64_t dir_id, const char *label = nullptr); +int tmp_file_open(int64_t &fd, int64_t dir_id); int tmp_file_remove(int64_t fd); int tmp_file_aio_read(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle); int tmp_file_aio_pread(const ObTmpFileIOInfo &io_info, diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index 8a34cbb7cd..324592c98e 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -72,8 +72,8 @@ namespace oceanbase { namespace observer { common::ObILobReadService * ObServer: #include "storage/tx_storage/ob_memstore_freezer.h" #include "storage/memtable/ob_lock_wait_mgr.h" #include "storage/multi_data_source/ob_mds_event_buffer.h" -#include "storage/tmp_file/ob_tmp_file_cache.h" #include "storage/meta_store/storage_meta_service.h" +#include "storage/tmp_file/tmp_file_service.h" #include "storage/meta_store/ob_local_storage_meta_service.h" #include "storage/tablet/ob_mds_schema_helper.h" #include "observer/schema/ob_schema_service_sql_impl.h" @@ -894,10 +894,6 @@ int ObServer::init(const ObServerOptions &opts) if (OB_SUCC(ret)) { if (OB_FAIL(init_tx_data_cache())) { LOG_ERROR("init tx data cache failed", KR(ret)); - } else if (OB_FAIL(tmp_file::ObTmpBlockCache::get_instance().init("tmp_block_cache"))) { - LOG_ERROR("init tmp block cache failed", KR(ret)); - } else if (OB_FAIL(tmp_file::ObTmpPageCache::get_instance().init("tmp_page_cache"))) { - LOG_ERROR("init tmp page cache failed", KR(ret)); } else if (OB_FAIL(ObLogAllocatorMgr::get_instance().init())) { LOG_ERROR("init ObLogAllocatorMgr failed", KR(ret)); } else if (OB_FAIL(startup_accel_handler_.init())) { @@ -1091,14 +1087,6 @@ void ObServer::destroy() OB_TX_DATA_KV_CACHE.destroy(); FLOG_INFO("tx data kv cache destroyed"); - FLOG_INFO("begin to destroy tmp block cache"); - tmp_file::ObTmpBlockCache::get_instance().destroy(); - FLOG_INFO("tmp block cache destroyed"); - - FLOG_INFO("begin to destroy tmp page cache"); - tmp_file::ObTmpPageCache::get_instance().destroy(); - FLOG_INFO("tmp page cache destroyed"); - FLOG_INFO("begin to release I/O service"); const int io_error = io_service_->shutdown_service(); if (io_error != 0) { @@ -1695,26 +1683,24 @@ int ObServer::wait_no_client() int ret = OB_SUCCESS; #ifdef _WIN32 OVERLAPPED ov = {}; - if (LockFileEx(clients_h_, - LOCKFILE_EXCLUSIVE_LOCK, - 0, MAXDWORD, MAXDWORD, &ov)) { - FLOG_INFO("no clients remaining, exiting"); - net_frame_.sql_nio_stop(); - _Exit(0); - } else { + if (!LockFileEx(clients_h_, LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, MAXDWORD, &ov)) { ret = OB_ERROR; LOG_ERROR("LockFileEx failed", "last_error", (int)GetLastError()); } #else - if (flock(clients_fd_, LOCK_EX) == 0) { - FLOG_INFO("no clients remaining, exiting"); - net_frame_.sql_nio_stop(); - _Exit(0); - } else { + if (flock(clients_fd_, LOCK_EX) != 0) { ret = OB_ERROR; LOG_ERROR("flock failed", K(errno)); } #endif + if (OB_SUCC(ret)) { + FLOG_INFO("no clients remaining, exiting"); + net_frame_.sql_nio_stop(); + if (OB_NOT_NULL(mods_tmp_file_manager_)) { + mods_tmp_file_manager_->shutdown(); + } + _Exit(0); + } return ret; } @@ -1749,6 +1735,9 @@ int ObServer::wait() if (in_process_) { return stop(); } + if (OB_NOT_NULL(mods_tmp_file_manager_)) { + mods_tmp_file_manager_->shutdown(); + } _Exit(0); return ret; #endif diff --git a/src/observer/ob_server_reload_config.cpp b/src/observer/ob_server_reload_config.cpp index d674ad4123..b0f2c7ad49 100644 --- a/src/observer/ob_server_reload_config.cpp +++ b/src/observer/ob_server_reload_config.cpp @@ -26,6 +26,7 @@ #include "storage/allocator/ob_shared_memory_allocator_mgr.h" #include "storage/compaction/ob_tablet_scheduler.h" #include "storage/meta_store/storage_meta_service.h" +#include "storage/tmp_file/tmp_file_service.h" #include @@ -63,6 +64,9 @@ int ObServerReloadConfig::operator()() } { GMEMCONF.reload_config(); + if (auto *tmp_files = OBSERVER.tmp_file_manager(); OB_NOT_NULL(tmp_files)) { + tmp_files->reload_config(); + } OB_LOGGER.set_info_as_wdiag(false); // Reload log configuration after applying the latest configuration values. if (OB_TMP_FAIL(ObReloadConfig::operator()())) { diff --git a/src/observer/ob_service.cpp b/src/observer/ob_service.cpp index aa502b1c6e..12609c1fc5 100644 --- a/src/observer/ob_service.cpp +++ b/src/observer/ob_service.cpp @@ -46,6 +46,7 @@ #include "share/ob_merge_info.h" #include "share/ob_column_checksum_error_operator.h" #include "storage/meta_store/storage_meta_service.h" +#include "storage/tmp_file/tmp_file_service.h" #include "share/ob_server_struct.h" // GCTX #include "storage/tx_storage/ob_ls_service.h" // ObLSService #include "storage/ls/ob_ls.h" @@ -721,6 +722,13 @@ int ObService::get_server_resource_info(share::ObServerResourceInfo &resource_in = OB_STORAGE_OBJECT_MGR.get_max_macro_block_count(reserved_size) * OB_STORAGE_OBJECT_MGR.get_macro_block_size(); resource_info.data_disk_in_use_ = OB_STORAGE_OBJECT_MGR.get_used_macro_block_count() * OB_STORAGE_OBJECT_MGR.get_macro_block_size(); + if (auto *tmp_files = share::server_service(); OB_NOT_NULL(tmp_files)) { + int64_t tmp_data_bytes = 0; + int64_t tmp_occupied_bytes = 0; + if (OB_SUCCESS == tmp_files->get_tmp_file_disk_usage(tmp_data_bytes, tmp_occupied_bytes)) { + resource_info.data_disk_in_use_ += tmp_occupied_bytes; + } + } } } return ret; diff --git a/src/observer/omt/ob_server_runtime_controller.cpp b/src/observer/omt/ob_server_runtime_controller.cpp index fb1fe74abe..d721e0da47 100644 --- a/src/observer/omt/ob_server_runtime_controller.cpp +++ b/src/observer/omt/ob_server_runtime_controller.cpp @@ -45,7 +45,7 @@ #include "storage/compaction/ob_tablet_scheduler.h" #include "storage/ddl/ob_direct_load_struct.h" #include "storage/tx_storage/ob_checkpoint_service.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" +#include "storage/tmp_file/tmp_file_service.h" #include "storage/tx_storage/ob_memory_printer.h" #include "storage/compaction/ob_compaction_progress.h" #include "storage/compaction/ob_server_compaction_event_history.h" @@ -1364,7 +1364,6 @@ int ObServer::obs_start_modules() if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_trans_service_))) { SERVER_LOG(WARN, "mods_trans_service_ fail", KR(ret)); } if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_log_service_))) { SERVER_LOG(WARN, "mods_log_service_ fail", KR(ret)); } if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_ls_service_))) { SERVER_LOG(WARN, "mods_ls_service_ fail", KR(ret)); } - if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_tmp_file_manager_))) { SERVER_LOG(WARN, "mods_tmp_file_manager_ fail", KR(ret)); } if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_lock_wait_mgr_))) { SERVER_LOG(WARN, "mods_lock_wait_mgr_ fail", KR(ret)); } if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_table_lock_service_))) { SERVER_LOG(WARN, "mods_table_lock_service_ fail", KR(ret)); } if (OB_SUCC(ret) && OB_FAIL(server_module_start_default(mods_primary_major_freeze_service_))) { SERVER_LOG(WARN, "mods_primary_major_freeze_service_ fail", KR(ret)); } @@ -1421,7 +1420,6 @@ void ObServer::obs_stop_modules() server_module_stop_default(mods_table_lock_service_); server_module_stop_default(mods_lock_wait_mgr_); server_module_stop_default(mods_tablet_stat_mgr_); - server_module_stop_default(mods_tmp_file_manager_); server_module_stop_default(mods_ls_service_); server_module_stop_default(mods_log_service_); server_module_stop_default(mods_trans_service_); @@ -1460,7 +1458,6 @@ void ObServer::obs_wait_modules() server_module_wait_default(mods_table_lock_service_); server_module_wait_default(mods_lock_wait_mgr_); server_module_wait_default(mods_tablet_stat_mgr_); - server_module_wait_default(mods_tmp_file_manager_); // Deferred memtable GC reads the LS log handler until all metadata is released. // Drain it before ObLSService::wait() frees the LS and its log handler. server_module_wait_default(mods_storage_meta_mem_mgr_); diff --git a/src/observer/virtual_table/ob_all_virtual_macro_block_marker_status.cpp b/src/observer/virtual_table/ob_all_virtual_macro_block_marker_status.cpp index a56bb6a3fd..5d65efe187 100644 --- a/src/observer/virtual_table/ob_all_virtual_macro_block_marker_status.cpp +++ b/src/observer/virtual_table/ob_all_virtual_macro_block_marker_status.cpp @@ -88,7 +88,7 @@ int ObAllVirtualMacroBlockMarkerStatus::inner_get_next_row(common::ObNewRow *&ro } case OB_APP_MIN_COLUMN_ID + 3: { // tmp_file_block_count - cur_row_.cells_[i].set_int(marker_status_.tmp_file_count_); + cur_row_.cells_[i].set_int(0); break; } case OB_APP_MIN_COLUMN_ID + 4: { diff --git a/src/observer/virtual_table/ob_all_virtual_tmp_file.cpp b/src/observer/virtual_table/ob_all_virtual_tmp_file.cpp index b0e639e6e1..1561b3115f 100644 --- a/src/observer/virtual_table/ob_all_virtual_tmp_file.cpp +++ b/src/observer/virtual_table/ob_all_virtual_tmp_file.cpp @@ -15,13 +15,11 @@ */ #include "share/ob_server_struct.h" -#include #include "observer/virtual_table/ob_all_virtual_tmp_file.h" -#include "observer/ob_server.h" +#include "storage/tmp_file/tmp_file_service.h" #include "share/rc/ob_server_runtime.h" using namespace oceanbase::common; -using namespace oceanbase::transaction; namespace oceanbase { @@ -43,280 +41,71 @@ ObAllVirtualTmpFileInfo::~ObAllVirtualTmpFileInfo() void ObAllVirtualTmpFileInfo::reset() { - ip_buffer_[0] = '\0'; - trace_id_buffer_[0] = '\0'; - file_ptr_buffer_[0] = '\0'; - file_label_buffer_[0] = '\0'; fd_arr_.reset(); is_ready_ = false; fd_idx_ = -1; ObVirtualTableScannerIterator::reset(); } -int ObAllVirtualTmpFileInfo::get_next_tmp_file_info_(tmp_file::ObTmpFileInfo *tmp_file_info) +int ObAllVirtualTmpFileInfo::get_next_tmp_file_info_(tmp_file::FileInfo &info) { - int ret = OB_SUCCESS; - if (OB_UNLIKELY(0 > fd_idx_)) { - ret = OB_ERR_UNEXPECTED; - SERVER_LOG(WARN, "unexpected fd_idx_", KR(ret), K(fd_idx_)); - } else if (OB_ISNULL(tmp_file_info)) { - ret = OB_INVALID_ARGUMENT; - SERVER_LOG(WARN, "invalid argument", KR(ret), KP(tmp_file_info)); - } else { - bool has_get = false; - while (OB_SUCC(ret) - && !has_get) { - if (fd_idx_ >= fd_arr_.count()) { - ret = OB_ITER_END; - SERVER_LOG(INFO, "iterate temporary files reach end", K(fd_idx_), K(fd_arr_.count())); - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->get_tmp_file_info(fd_arr_.at(fd_idx_), tmp_file_info))) { - if (OB_ENTRY_NOT_EXIST == ret || OB_TIMEOUT == ret) { - SERVER_LOG(INFO, "tmp file does not exist or is locked by others", KR(ret), K(fd_arr_.at(fd_idx_))); - ret = OB_SUCCESS; - } else { - SERVER_LOG(WARN, "fail to get tmp file info", KR(ret), K(fd_idx_), K(fd_arr_), K(fd_arr_.at(fd_idx_))); - } - } else { - has_get = true; - } - if (OB_SUCC(ret)) { - fd_idx_++; - } - } - } - return ret; -} - -int ObAllVirtualTmpFileInfo::fill_columns_(tmp_file::ObTmpFileInfo *tmp_file_info) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(tmp_file_info)) { - ret = OB_INVALID_ARGUMENT; - SERVER_LOG(WARN, "invalid argument", KR(ret), KP(tmp_file_info)); - } else { - const int64_t col_count = output_column_ids_.count(); - for (int64_t i = 0; OB_SUCC(ret) && i < col_count; ++i) { - uint64_t col_id = output_column_ids_.at(i); - switch (col_id) { - case FILE_ID: - cur_row_.cells_[i].set_int(tmp_file_info->fd_); - break; - case TRACE_ID: - MEMSET(trace_id_buffer_, '\0', OB_MAX_TRACE_ID_BUFFER_SIZE); - if (!tmp_file_info->trace_id_.is_invalid()) { - tmp_file_info->trace_id_.to_string(trace_id_buffer_, OB_MAX_TRACE_ID_BUFFER_SIZE); - } - cur_row_.cells_[i].set_varchar(trace_id_buffer_); - cur_row_.cells_[i].set_default_collation_type(); - break; - case DIR_ID: - cur_row_.cells_[i].set_int(tmp_file_info->dir_id_); - break; - case DATA_BYTES: - cur_row_.cells_[i].set_int(tmp_file_info->file_size_); - break; - case START_OFFSET: - cur_row_.cells_[i].set_int(tmp_file_info->truncated_offset_); - break; - case IS_DELETING: - cur_row_.cells_[i].set_bool(tmp_file_info->is_deleting_); - break; - case CACHED_DATA_PAGE_NUM: - cur_row_.cells_[i].set_int(tmp_file_info->cached_data_page_num_); - break; - case WRITE_BACK_DATA_PAGE_NUM: - cur_row_.cells_[i].set_int(tmp_file_info->write_back_data_page_num_); - break; - case FLUSHED_DATA_PAGE_NUM: - cur_row_.cells_[i].set_int(tmp_file_info->flushed_data_page_num_); - break; - case REF_CNT: - cur_row_.cells_[i].set_int(tmp_file_info->ref_cnt_); - break; - case TOTAL_WRITES: - cur_row_.cells_[i].set_int(tmp_file_info->write_info_.write_req_cnt_); - break; - case UNALIGNED_WRITES: - cur_row_.cells_[i].set_int(tmp_file_info->write_info_.unaligned_write_req_cnt_); - break; - case TOTAL_READS: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.read_req_cnt_); - break; - case UNALIGNED_READS: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.unaligned_read_req_cnt_); - break; - case TOTAL_READ_BYTES: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.total_read_size_); - break; - case LAST_ACCESS_TIME: - cur_row_.cells_[i].set_timestamp(tmp_file_info->read_info_.last_access_ts_); - break; - case LAST_MODIFY_TIME: - cur_row_.cells_[i].set_timestamp(tmp_file_info->write_info_.last_modify_ts_); - break; - case BIRTH_TIME: - cur_row_.cells_[i].set_timestamp(tmp_file_info->birth_ts_); - break; - case TMP_FILE_PTR: - if (NULL != tmp_file_info->tmp_file_ptr_) { - MEMSET(file_ptr_buffer_, '\0', 20); - snprintf(file_ptr_buffer_, 18, "0x%" PRIx64, (uint64_t)tmp_file_info->tmp_file_ptr_); - cur_row_.cells_[i].set_varchar(file_ptr_buffer_); - } else { - cur_row_.cells_[i].set_varchar(ObString::make_string("nullptr")); - } - cur_row_.cells_[i].set_default_collation_type(); - break; - case LABEL: - MEMSET(file_label_buffer_, '\0', OB_MAX_FILE_LABEL_SIZE); - if (!tmp_file_info->label_.is_empty()) { - tmp_file_info->label_.to_string(file_label_buffer_, OB_MAX_FILE_LABEL_SIZE); - } - cur_row_.cells_[i].set_varchar(file_label_buffer_); - cur_row_.cells_[i].set_default_collation_type(); - break; - case TYPE: - break; - case COMPRESSIBLE_FD: - break; - case PERSISTED_TAIL_PAGE_WRITES: - cur_row_.cells_[i].set_int(tmp_file_info->write_info_.write_persisted_tail_page_cnt_); - break; - case LACK_PAGE_CNT: - cur_row_.cells_[i].set_int(tmp_file_info->write_info_.lack_page_cnt_); - break; - case TOTAL_TRUNCATED_PAGE_READ_CNT: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.total_truncated_page_read_cnt_); - break; - case TRUNCATED_PAGE_HITS: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.truncated_page_read_hits_); - break; - case TOTAL_KV_CACHE_PAGE_READ_CNT: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.total_kv_cache_page_read_cnt_); - break; - case KV_CACHE_PAGE_HITS: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.kv_cache_page_read_hits_); - break; - case TOTAL_UNCACHED_PAGE_READ_CNT: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.total_uncached_page_read_cnt_); - break; - case UNCACHED_PAGE_HITS: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.uncached_page_read_hits_); - break; - case TOTAL_WBP_PAGE_READ_CNT: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.total_wbp_page_read_cnt_); - break; - case WBP_PAGE_HITS: - cur_row_.cells_[i].set_int(tmp_file_info->read_info_.wbp_page_read_hits_); - break; - /* columns in ss modes begin */ - case AGGREGATE_READ_IO_CNT: - break; - /* columns in ss modes end */ - /* columns in sn modes begin */ - case META_TREE_EPOCH: - case META_TREE_LEVELS: - case META_BYTES: - case CACHED_META_PAGE_NUM: - case WRITE_BACK_META_PAGE_NUM: - case PAGE_FLUSH_CNT: { - tmp_file::ObSNTmpFileInfo *sn_tmp_file_info = static_cast(tmp_file_info); - if (OB_FAIL(fill_sn_column_(i, sn_tmp_file_info))) { - } - } - break; - /* columns in sn modes end */ - default: - ret = OB_ERR_UNEXPECTED; - SERVER_LOG(WARN, "invalid column_id", KR(ret), K(col_id)); - break; - } + auto *manager = share::server_service(); + while (OB_NOT_NULL(manager) && fd_idx_ < fd_arr_.count()) { + const int ret = manager->get_tmp_file_info(fd_arr_.at(fd_idx_++), info); + if (OB_ENTRY_NOT_EXIST != ret) { + return ret; } } - return ret; + return OB_ITER_END; } -int ObAllVirtualTmpFileInfo::fill_sn_column_(const uint64_t col_index, tmp_file::ObSNTmpFileInfo *tmp_file_info) +int ObAllVirtualTmpFileInfo::fill_columns_(const tmp_file::FileInfo &info) { - int ret = OB_SUCCESS; - if (OB_ISNULL(tmp_file_info)) { - ret = OB_INVALID_ARGUMENT; - SERVER_LOG(WARN, "invalid argument", KR(ret), KP(tmp_file_info)); - } else { - uint64_t col_id = output_column_ids_.at(col_index); - switch (col_id) { - case META_TREE_EPOCH: - cur_row_.cells_[col_index].set_int(tmp_file_info->meta_tree_epoch_); - break; - case META_TREE_LEVELS: - cur_row_.cells_[col_index].set_int(tmp_file_info->meta_tree_level_cnt_); - break; - case META_BYTES: - cur_row_.cells_[col_index].set_int(tmp_file_info->meta_size_); - break; - case CACHED_META_PAGE_NUM: - cur_row_.cells_[col_index].set_int(tmp_file_info->cached_meta_page_num_); - break; - case WRITE_BACK_META_PAGE_NUM: - cur_row_.cells_[col_index].set_int(tmp_file_info->write_back_meta_page_num_); - break; - case PAGE_FLUSH_CNT: - cur_row_.cells_[col_index].set_int(tmp_file_info->all_type_page_flush_cnt_); - break; - default: - ret = OB_ERR_UNEXPECTED; - SERVER_LOG(WARN, "invalid column_id", KR(ret), K(col_id)); - break; + for (int64_t i = 0; i < output_column_ids_.count(); ++i) { + auto &cell = cur_row_.cells_[i]; + switch (output_column_ids_.at(i)) { + case FILE_ID: cell.set_int(info.fd_); break; + case DIR_ID: cell.set_int(info.dir_id_); break; + case DATA_BYTES: cell.set_int(info.size_); break; + case START_OFFSET: cell.set_int(info.prefix_); break; + case TOTAL_WRITES: cell.set_int(info.writes_); break; + case TOTAL_READS: cell.set_int(info.reads_); break; + case TOTAL_READ_BYTES: cell.set_int(info.read_bytes_); break; + case IS_DELETING: cell.set_bool(false); break; + default: cell.set_null(); break; } } - return ret; + return OB_SUCCESS; } int ObAllVirtualTmpFileInfo::inner_get_next_row(common::ObNewRow *&row) { int ret = OB_SUCCESS; - - if (nullptr == allocator_) { + if (OB_ISNULL(allocator_)) { ret = OB_NOT_INIT; - SERVER_LOG(WARN, "allocator_ shouldn't be nullptr", K(allocator_), KR(ret)); - } else if (FALSE_IT(start_to_read_ = true)) { - } else if (!is_ready_) { - if (OB_UNLIKELY(!fd_arr_.empty())) { - ret = OB_ERR_UNEXPECTED; - SERVER_LOG(WARN, "unexpected fd_arr_", KR(ret), K(fd_arr_)); - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->get_tmp_file_fds(fd_arr_))) { - SERVER_LOG(WARN, "fail to get tmp file fd arr", KR(ret)); - if (OB_NOT_INIT == ret) { - ret = OB_SUCCESS; + } else { + start_to_read_ = true; + if (!is_ready_) { + auto *manager = share::server_service(); + if (OB_ISNULL(manager)) { + ret = OB_ITER_END; + } else if (OB_FAIL(manager->get_tmp_file_fds(fd_arr_))) { + } else { + is_ready_ = true; + fd_idx_ = 0; } } - if (OB_SUCC(ret)) { - is_ready_ = true; - fd_idx_ = 0; - } } - if (OB_SUCC(ret)) { - ObMemAttr attr("TmpFileInfo"); - tmp_file::ObTmpFileInfo *tmp_file_info = OB_NEW(tmp_file::ObSNTmpFileInfo, attr); - if (OB_FAIL(get_next_tmp_file_info_(tmp_file_info))) { - if (OB_ITER_END != ret) { - SERVER_LOG(WARN, "fail to get next tmp file info", KR(ret)); - } - } else if (OB_FAIL(fill_columns_(tmp_file_info))) { - } - - if (OB_NOT_NULL(tmp_file_info)) { - tmp_file_info->~ObTmpFileInfo(); - ob_free(tmp_file_info); - tmp_file_info = NULL; + tmp_file::FileInfo info{}; + if (OB_FAIL(get_next_tmp_file_info_(info))) { + } else if (OB_FAIL(fill_columns_(info))) { + } else { + row = &cur_row_; } } - if (OB_SUCC(ret)) { - row = &cur_row_; - } return ret; } -} -} +} // namespace observer +} // namespace oceanbase diff --git a/src/observer/virtual_table/ob_all_virtual_tmp_file.h b/src/observer/virtual_table/ob_all_virtual_tmp_file.h index 65265a5dd8..12757dd1e0 100644 --- a/src/observer/virtual_table/ob_all_virtual_tmp_file.h +++ b/src/observer/virtual_table/ob_all_virtual_tmp_file.h @@ -18,16 +18,12 @@ #define OB_ALL_VIRTUAL_TMP_FILE_H_ #include "observer/virtual_table/ob_virtual_table_scanner_iterator.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" -#include "lib/time/ob_clock_generator.h" -#include "lib/time/ob_clock_generator.h" namespace oceanbase { namespace tmp_file { -class ObTmpFileInfo; -class ObTmpFileGlobal; +struct FileInfo; } namespace observer { @@ -43,9 +39,8 @@ class ObAllVirtualTmpFileInfo: public common::ObVirtualTableScannerIterator virtual void reset(); private: - int get_next_tmp_file_info_(tmp_file::ObTmpFileInfo *tmp_file_info); - int fill_columns_(tmp_file::ObTmpFileInfo *tmp_file_info); - int fill_sn_column_(const uint64_t col_index, tmp_file::ObSNTmpFileInfo *tmp_file_info); + int get_next_tmp_file_info_(tmp_file::FileInfo &info); + int fill_columns_(const tmp_file::FileInfo &info); private: enum @@ -90,11 +85,6 @@ class ObAllVirtualTmpFileInfo: public common::ObVirtualTableScannerIterator TOTAL_WBP_PAGE_READ_CNT, WBP_PAGE_HITS }; - static const int64_t OB_MAX_FILE_LABEL_SIZE = tmp_file::ObTmpFileGlobal::TMP_FILE_MAX_LABEL_SIZE + 1; - char ip_buffer_[common::OB_IP_STR_BUFF]; - char trace_id_buffer_[common::OB_MAX_TRACE_ID_BUFFER_SIZE]; - char file_ptr_buffer_[20]; - char file_label_buffer_[OB_MAX_FILE_LABEL_SIZE]; ObArray fd_arr_; bool is_ready_; int64_t fd_idx_; diff --git a/src/sql/engine/basic/ob_chunk_datum_store.cpp b/src/sql/engine/basic/ob_chunk_datum_store.cpp index 1cb19ffe36..32c8d2d0ce 100644 --- a/src/sql/engine/basic/ob_chunk_datum_store.cpp +++ b/src/sql/engine/basic/ob_chunk_datum_store.cpp @@ -1658,7 +1658,6 @@ int ObChunkDatumStore::write_file(void *buf, int64_t size) } else if (OB_FAIL(data_plane::tmp_file_open(io_.fd_, io_.dir_id_))) { } else { file_size_ = 0; - io_.io_timeout_ms_ = timeout_ms; LOG_INFO("open file success", K_(io_.fd), K_(io_.dir_id)); } } @@ -1666,6 +1665,7 @@ int ObChunkDatumStore::write_file(void *buf, int64_t size) } if (OB_SUCC(ret) && size > 0) { set_io(size, static_cast(buf)); + io_.io_timeout_ms_ = timeout_ms; if (aio_write_handle_.is_valid() && OB_FAIL(aio_write_handle_.wait())) { } else if (OB_FAIL(data_plane::tmp_file_aio_write(io_, aio_write_handle_))) { } diff --git a/src/sql/engine/basic/ob_chunk_row_store.cpp b/src/sql/engine/basic/ob_chunk_row_store.cpp index b3b8281017..0b2b52e0cb 100644 --- a/src/sql/engine/basic/ob_chunk_row_store.cpp +++ b/src/sql/engine/basic/ob_chunk_row_store.cpp @@ -1239,13 +1239,13 @@ int ObChunkRowStore::write_file(void *buf, int64_t size) } else if (OB_FAIL(data_plane::tmp_file_open(io_.fd_, io_.dir_id_))) { } else { file_size_ = 0; - io_.io_timeout_ms_ = timeout_ms; } } ret = OB_E(EventTable::EN_8) ret; } if (OB_SUCC(ret) && size > 0) { set_io(size, static_cast(buf)); + io_.io_timeout_ms_ = timeout_ms; if (OB_FAIL(data_plane::tmp_file_write(io_))) { } } diff --git a/src/sql/engine/basic/ob_temp_block_store.cpp b/src/sql/engine/basic/ob_temp_block_store.cpp index edf6af5ada..153b5a58d4 100644 --- a/src/sql/engine/basic/ob_temp_block_store.cpp +++ b/src/sql/engine/basic/ob_temp_block_store.cpp @@ -48,8 +48,7 @@ int ObTempBlockStore::init(int64_t mem_limit, int64_t mem_ctx_id, const char *label, common::ObCompressorType compress_type, - const bool enable_trunc, - const bool sequential_read) + const bool enable_trunc) { int ret = OB_SUCCESS; mem_limit_ = mem_limit; @@ -65,7 +64,6 @@ int ObTempBlockStore::init(int64_t mem_limit, inited_ = true; compressor_.init(compress_type); enable_trunc_ = enable_trunc; - sequential_read_ = sequential_read; return ret; } @@ -682,13 +680,13 @@ int ObTempBlockStore::load_block(BlockReader &reader, const int64_t block_id, bi->length_))) { } else if (OB_FAIL(reader.get_read_io_handler(read_io_handler_ptr))) { } else if (OB_FAIL(read_file(reader.aio_buf_[aio_buf_idx].data(), bi->length_, bi->offset_, - *read_io_handler_ptr, reader.is_async(), sequential_read_))) { + *read_io_handler_ptr, reader.is_async()))) { } } else { if (OB_FAIL(ensure_reader_buffer(reader, reader.buf_, bi->length_))) { } else if (OB_FAIL(reader.get_read_io_handler(read_io_handler_ptr))) { } else if (OB_FAIL(read_file(reader.buf_.data(), bi->length_, bi->offset_, - *read_io_handler_ptr, reader.is_async(), sequential_read_))) { + *read_io_handler_ptr, reader.is_async()))) { } } } @@ -793,7 +791,7 @@ int ObTempBlockStore::load_idx_block(BlockReader &reader, IndexBlock *&ib, const reader, reader.idx_buf_, IndexBlock::INDEX_BLOCK_SIZE))) { } else if (OB_FAIL(reader.get_read_io_handler(read_io_handler_ptr))) { } else if (OB_FAIL(read_file( - reader.idx_buf_.data(), bi.length_, bi.offset_, *read_io_handler_ptr, false, false/*prefetch*/))) { + reader.idx_buf_.data(), bi.length_, bi.offset_, *read_io_handler_ptr, false))) { } else { ib = reinterpret_cast(reader.idx_buf_.data()); } @@ -909,7 +907,6 @@ int ObTempBlockStore::write_file(BlockIndex &bi, void *buf, int64_t size) } else if (OB_FAIL(data_plane::tmp_file_open(io_.fd_, io_.dir_id_))) { } else { file_size_ = 0; - io_.io_timeout_ms_ = timeout_ms; LOG_INFO("open file success", K_(io_.fd), K_(io_.dir_id), K(get_compressor_type())); } } @@ -918,6 +915,7 @@ int ObTempBlockStore::write_file(BlockIndex &bi, void *buf, int64_t size) if (OB_SUCC(ret) && size > 0) { io_.buf_ = static_cast(buf); io_.size_ = size; + io_.io_timeout_ms_ = timeout_ms; const uint64_t start = rdtsc(); if (write_io_handle_.is_valid() && OB_FAIL(write_io_handle_.wait())) { } else if (OB_FAIL(data_plane::tmp_file_aio_write(io_, write_io_handle_))) { @@ -938,19 +936,18 @@ int ObTempBlockStore::write_file(BlockIndex &bi, void *buf, int64_t size) } int ObTempBlockStore::read_file(void *buf, const int64_t size, const int64_t offset, - data_plane::ObTmpFileIOHandle &handle, const bool is_async, const bool prefetch) + data_plane::ObTmpFileIOHandle &handle, const bool is_async) { int ret = OB_SUCCESS; int64_t timeout_ms = 0; if (OB_UNLIKELY(offset < 0) || OB_UNLIKELY(size < 0) || OB_UNLIKELY(size > 0 && NULL == buf)) { ret = OB_INVALID_ARGUMENT; } else if (OB_FAIL(get_timeout(timeout_ms))) { - } else if (!handle.is_valid() && write_io_handle_.is_valid() && OB_FAIL(write_io_handle_.wait())) { + } else if (write_io_handle_.is_valid() && OB_FAIL(write_io_handle_.wait())) { } if (OB_SUCC(ret) && size > 0) { data_plane::ObTmpFileIOInfo tmp_read_id = io_; - tmp_read_id.prefetch_ = prefetch; tmp_read_id.buf_ = static_cast(buf); tmp_read_id.size_ = size; tmp_read_id.io_timeout_ms_ = timeout_ms; diff --git a/src/sql/engine/basic/ob_temp_block_store.h b/src/sql/engine/basic/ob_temp_block_store.h index af3edaaa68..737242426c 100644 --- a/src/sql/engine/basic/ob_temp_block_store.h +++ b/src/sql/engine/basic/ob_temp_block_store.h @@ -322,8 +322,7 @@ class ObTempBlockStore int64_t mem_ctx_id, const char *label, common::ObCompressorType compressor_type, - const bool enable_trunc = false, - const bool sequential_read = false); + const bool enable_trunc = false); void reset(); void reuse(); void reset_block_cnt(); @@ -383,10 +382,6 @@ class ObTempBlockStore { enable_trunc_ = enable_trunc; } - void set_sequential_read(bool sequential_read) - { - sequential_read_ = sequential_read; - } inline ShrinkBuffer &get_blk_buf() { return blk_buf_; } bool is_truncate() { return enable_trunc_; } inline int64_t get_cur_file_offset() const { return cur_file_offset_; } @@ -488,7 +483,7 @@ class ObTempBlockStore int ensure_reader_buffer(BlockReader &reader, ShrinkBuffer &buf, const int64_t size); int write_file(BlockIndex &bi, void *buf, int64_t size); int read_file(void *buf, const int64_t size, const int64_t offset, - data_plane::ObTmpFileIOHandle &handle, const bool is_async, const bool prefetch); + data_plane::ObTmpFileIOHandle &handle, const bool is_async); bool need_dump(const int64_t extra_size); int write_compressed_block(Block *blk, BlockIndex *bi); int dump_block(Block *blk, int64_t &dumped_size); @@ -540,7 +535,6 @@ class ObTempBlockStore bool enable_dump_; bool backup_enable_dump_; bool enable_trunc_; // if true, the read contents of tmp file we be removed from disk. - bool sequential_read_; int64_t last_trunc_offset_; private: diff --git a/src/storage/BUILD.bazel b/src/storage/BUILD.bazel index 6fe28a09ec..c866e942d0 100644 --- a/src/storage/BUILD.bazel +++ b/src/storage/BUILD.bazel @@ -420,6 +420,7 @@ grouped_unity_cc_library( ":storage_runtime_interface", ":storage_runtime_internal_headers", "//rust:config_headers", + "//rust:tmp_file_headers", ] + _STORAGE_EXACT_HEADER_DEPS + _STORAGE_RUNTIME_NON_SHARE_DEPS + [ "//src/oblib:common_sql_mode", "//src/oblib:oblib_base", diff --git a/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.cpp b/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.cpp index d6cb0ac321..0c4d71a49d 100644 --- a/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.cpp +++ b/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.cpp @@ -138,7 +138,7 @@ int ObMacroMetaTempStore::init(const int64_t dir_id) int ret = OB_SUCCESS; if (IS_INIT) { ret = OB_INIT_TWICE; - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->open(io_.fd_, io_.dir_id_))) { + } else if (OB_FAIL(data_plane::tmp_file_open(io_.fd_, io_.dir_id_))) { } else { @@ -154,7 +154,7 @@ void ObMacroMetaTempStore::reset() int ret = OB_SUCCESS; if (io_.fd_ > 0) { io_handle_.reset(); - if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->remove(io_.fd_))) { + if (OB_FAIL(data_plane::tmp_file_remove(io_.fd_))) { } else { LOG_INFO("remove tmp file success", K(ret), K_(io)); } @@ -252,7 +252,7 @@ int ObMacroMetaTempStore::inner_append(const ObDataMacroBlockMeta ¯o_meta, c io_.size_ = buffer_.pos(); const int64_t timeout_us = THIS_WORKER.get_timeout_remain(); io_.io_timeout_ms_ = timeout_us <= 0 ? 0 : timeout_us / 1000; - if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->aio_write(io_, io_handle_))) { + if (OB_FAIL(data_plane::tmp_file_aio_write(io_, io_handle_))) { } } } @@ -370,7 +370,7 @@ int ObMacroMetaTempStoreIter::init(ObMacroMetaTempStore &temp_meta_store) } else if (OB_UNLIKELY(!temp_meta_store.is_valid())) { ret = OB_INVALID_ARGUMENT; } else if (OB_FAIL(temp_meta_store.wait())) { - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->get_tmp_file_size(temp_meta_store.io_.fd_, + } else if (OB_FAIL(data_plane::tmp_file_get_size(temp_meta_store.io_.fd_, meta_store_file_length_))) { } else { io_info_ = temp_meta_store.io_; @@ -432,8 +432,8 @@ int ObMacroMetaTempStoreIter::try_submit_io() ret = OB_ALLOCATE_MEMORY_FAILED; } else { // submit io and update fragment info. - tmp_file::ObTmpFileIOHandle read_handle; - tmp_file::ObTmpFileIOInfo io_info = io_info_; + data_plane::ObTmpFileIOHandle read_handle; + data_plane::ObTmpFileIOInfo io_info = io_info_; io_info.buf_ = meta_store_fragment_; io_info.size_ = curr_read_size; const int64_t timeout_us = THIS_WORKER.get_timeout_remain(); @@ -445,7 +445,7 @@ int ObMacroMetaTempStoreIter::try_submit_io() } if (OB_FAIL(ret)) { // pass - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->pread(io_info, meta_store_read_offset_, read_handle))) { + } else if (OB_FAIL(data_plane::tmp_file_pread(io_info, meta_store_read_offset_, read_handle))) { } else if (OB_FAIL(read_handle.wait())) { } else { fragment_offset_ = meta_store_read_offset_; diff --git a/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.h b/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.h index 10a79daaa2..11c5a2f9c0 100644 --- a/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.h +++ b/src/storage/blocksstable/index_block/ob_macro_meta_temp_store.h @@ -21,7 +21,7 @@ #include "storage/blocksstable/ob_micro_block_reader_helper.h" #include "storage/blocksstable/ob_imicro_block_reader.h" #include "storage/blocksstable/ob_macro_block_reader.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" +#include "data_plane/tmp_file/ob_tmp_file.h" namespace oceanbase { @@ -89,8 +89,8 @@ class ObMacroMetaTempStore ObDataMacroBlockMeta ¯o_meta); private: - tmp_file::ObTmpFileIOInfo io_; - tmp_file::ObTmpFileIOHandle io_handle_; + data_plane::ObTmpFileIOInfo io_; + data_plane::ObTmpFileIOHandle io_handle_; ObSelfBufferWriter buffer_; ObArenaAllocator allocator_; // micro block reader, lifecycle in get_macro_meta_from_block_buf ObArenaAllocator datum_allocator_; // io buffer to temp file, lifecycle in inner_append @@ -120,7 +120,7 @@ class ObMacroMetaTempStoreIter static const int64_t META_TEMP_STORE_INITIAL_READ_SIZE = 64 * 1024; private: - tmp_file::ObTmpFileIOInfo io_info_; + data_plane::ObTmpFileIOInfo io_info_; int64_t meta_store_file_length_; ObArenaAllocator io_allocator_; ObMacroMetaTempStore::StoreItem curr_read_item_; diff --git a/src/storage/blocksstable/ob_block_manager.cpp b/src/storage/blocksstable/ob_block_manager.cpp index 6116e6b9fc..d37f3340c7 100644 --- a/src/storage/blocksstable/ob_block_manager.cpp +++ b/src/storage/blocksstable/ob_block_manager.cpp @@ -22,7 +22,6 @@ #include #include "share/rc/ob_server_runtime.h" #include "storage/blocksstable/ob_shared_macro_block_manager.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" #include "storage/meta_mem/ob_storage_meta_mem_mgr.h" #include "storage/meta_store/storage_meta_service.h" #include "storage/meta_store/ob_local_storage_meta_service.h" @@ -31,7 +30,6 @@ using namespace oceanbase::common; using namespace oceanbase::common::hash; using namespace oceanbase::blocksstable; -using namespace oceanbase::tmp_file; using namespace oceanbase::storage; using namespace oceanbase::share; @@ -805,7 +803,6 @@ void ObBlockManager::update_marker_status(const ObMacroBlockMarkerStatus &tmp_st marker_status_.linked_block_count_ = tmp_status.linked_block_count_; marker_status_.index_block_count_ = tmp_status.index_block_count_; marker_status_.ids_block_count_ = tmp_status.ids_block_count_; - marker_status_.tmp_file_count_ = tmp_status.tmp_file_count_; marker_status_.data_block_count_ = tmp_status.data_block_count_; marker_status_.pending_free_count_ = tmp_status.pending_free_count_; marker_status_.hold_info_ = tmp_status.hold_info_; @@ -815,7 +812,6 @@ void ObBlockManager::update_marker_status(const ObMacroBlockMarkerStatus &tmp_st marker_status_.linked_block_count_ = prev_result.linked_block_count_; marker_status_.index_block_count_ = prev_result.index_block_count_; marker_status_.ids_block_count_ = prev_result.ids_block_count_; - marker_status_.tmp_file_count_ = prev_result.tmp_file_count_; marker_status_.data_block_count_ = prev_result.data_block_count_; marker_status_.pending_free_count_ = prev_result.pending_free_count_; marker_status_.hold_info_ = prev_result.hold_info_; @@ -1023,7 +1019,6 @@ int ObBlockManager::mark_macro_blocks( if (0 == mark_info.count() && 0 == alloc_num_) { tmp_status.mark_finished_ = false; LOG_INFO("no block alloc/free, no need to mark blocks", K(ret)); - } else if (OB_FAIL(mark_tmp_file_blocks(mark_info, macro_id_set, tmp_status))) { } else { MacroBlockId macro_id; if (OB_FAIL(mark_local_storage_blocks(mark_info, macro_id_set, tmp_status))) { @@ -1176,38 +1171,6 @@ int ObBlockManager::do_mark_tablet_block( return ret; } -int ObBlockManager::mark_tmp_file_blocks( - MacroBlkIdMap &mark_info, - common::hash::ObHashSet - ¯o_id_set, - ObMacroBlockMarkerStatus &tmp_status) { - int ret = OB_SUCCESS; - - ObArray macro_block_list; - if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->get_macro_block_list(macro_block_list))) { - } else if (OB_FAIL(update_mark_info(macro_block_list, macro_id_set, mark_info))){ - } else { - tmp_status.tmp_file_count_ += macro_block_list.count(); - tmp_status.hold_count_ -= macro_block_list.count(); - } - return ret; -} - -int ObBlockManager::update_mark_info( - const ObIArray ¯o_block_list, - common::hash::ObHashSet - ¯o_id_set, - MacroBlkIdMap &mark_info) { - int ret = OB_SUCCESS; - for (int64_t i = 0; OB_SUCC(ret) && i < macro_block_list.count(); i++) { - const MacroBlockId ¯o_id = macro_block_list.at(i); - if (OB_FAIL(update_mark_info(macro_id, mark_info))) { - } else if (OB_FAIL(macro_id_set.set_refactored(macro_id))) { - } - } - return ret; -} - int ObBlockManager::update_mark_info(const MacroBlockId ¯o_id, MacroBlkIdMap &mark_info) { int ret = OB_SUCCESS; diff --git a/src/storage/blocksstable/ob_block_manager.h b/src/storage/blocksstable/ob_block_manager.h index 4db116fa1a..423b4b2c4d 100644 --- a/src/storage/blocksstable/ob_block_manager.h +++ b/src/storage/blocksstable/ob_block_manager.h @@ -368,17 +368,9 @@ class ObBlockManager storage::ObTabletHandle &handle, common::hash::ObHashSet ¯o_id_set, ObMacroBlockMarkerStatus &tmp_status); - int mark_tmp_file_blocks( - MacroBlkIdMap &mark_info, - common::hash::ObHashSet ¯o_id_set, - ObMacroBlockMarkerStatus &tmp_status); int do_sweep(MacroBlkIdMap &mark_info); int sweep_one_block(const MacroBlockId& macro_id); - int update_mark_info( - const common::ObIArray ¯o_block_list, - common::hash::ObHashSet ¯o_id_set, - MacroBlkIdMap &mark_info); int update_mark_info( const MacroBlockId ¯o_id, MacroBlkIdMap &mark_info); diff --git a/src/storage/blocksstable/ob_block_sstable_struct.cpp b/src/storage/blocksstable/ob_block_sstable_struct.cpp index f398c17d01..e04cba36f7 100644 --- a/src/storage/blocksstable/ob_block_sstable_struct.cpp +++ b/src/storage/blocksstable/ob_block_sstable_struct.cpp @@ -180,7 +180,6 @@ ObMacroBlockMarkerStatus::ObMacroBlockMarkerStatus() : total_block_count_(0), reserved_block_count_(0), linked_block_count_(0), - tmp_file_count_(0), data_block_count_(0), index_block_count_(0), ids_block_count_(0), @@ -224,7 +223,6 @@ void ObMacroBlockMarkerStatus::reuse() { reserved_block_count_ = 0; linked_block_count_ = 0; - tmp_file_count_ = 0; data_block_count_ = 0; index_block_count_ = 0; ids_block_count_ = 0; diff --git a/src/storage/blocksstable/ob_block_sstable_struct.h b/src/storage/blocksstable/ob_block_sstable_struct.h index 52bfa8624d..fdef14cb8b 100644 --- a/src/storage/blocksstable/ob_block_sstable_struct.h +++ b/src/storage/blocksstable/ob_block_sstable_struct.h @@ -821,7 +821,6 @@ class ObMacroBlockMarkerStatus final TO_STRING_KV(K_(total_block_count), K_(reserved_block_count), K_(linked_block_count), - K_(tmp_file_count), K_(data_block_count), K_(index_block_count), K_(ids_block_count), @@ -839,7 +838,6 @@ class ObMacroBlockMarkerStatus final int64_t total_block_count_; int64_t reserved_block_count_; int64_t linked_block_count_; - int64_t tmp_file_count_; int64_t data_block_count_; int64_t index_block_count_; int64_t ids_block_count_; diff --git a/src/storage/ob_disk_usage_reporter.cpp b/src/storage/ob_disk_usage_reporter.cpp index 483589354e..6aefc26047 100644 --- a/src/storage/ob_disk_usage_reporter.cpp +++ b/src/storage/ob_disk_usage_reporter.cpp @@ -22,7 +22,7 @@ #include "storage/tx_storage/ob_ls_service.h" #include "storage/meta_store/storage_meta_service.h" #include "storage/meta_store/ob_local_storage_meta_service.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" +#include "storage/tmp_file/tmp_file_service.h" #include "logservice/ob_server_log_block_mgr.h" namespace oceanbase diff --git a/src/storage/ob_parallel_external_sort.h b/src/storage/ob_parallel_external_sort.h index 0f950ab246..c52698d0c7 100644 --- a/src/storage/ob_parallel_external_sort.h +++ b/src/storage/ob_parallel_external_sort.h @@ -28,7 +28,7 @@ #include "share/io_request.h" #include "data_plane/scheduler/ob_dag_scheduler.h" #include "blocksstable/ob_block_sstable_struct.h" -#include "tmp_file/ob_tmp_file_manager.h" +#include "data_plane/tmp_file/ob_tmp_file.h" #include "share/config/ob_server_config.h" @@ -195,7 +195,6 @@ class ObFragmentWriterV2 ObMacroBufferWriter macro_buffer_writer_; bool has_sample_item_; T sample_item_; - tmp_file::ObTmpFileIOHandle file_io_handle_; int64_t fd_; int64_t dir_id_; @@ -207,7 +206,7 @@ ObFragmentWriterV2::ObFragmentWriterV2() : is_inited_(false), buf_(NULL), buf_size_(0), expire_timestamp_(0), allocator_(common::ObNewModIds::OB_ASYNC_EXTERNAL_SORTER, common::OB_MALLOC_BIG_BLOCK_SIZE), macro_buffer_writer_(), has_sample_item_(false), sample_item_(), - file_io_handle_(), fd_(-1), dir_id_(-1) + fd_(-1), dir_id_(-1) { } @@ -235,7 +234,7 @@ int ObFragmentWriterV2::open(const int64_t buf_size, const int64_t expire_tim if (NULL == (buf_ = static_cast(allocator_.alloc(align_buf_size)))) { ret = common::OB_ALLOCATE_MEMORY_FAILED; STORAGE_LOG(WARN, "fail to allocate buffer", K(ret), K(align_buf_size)); - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->open(fd_, dir_id_))) { + } else if (OB_FAIL(data_plane::tmp_file_open(fd_, dir_id_))) { } else { buf_size_ = align_buf_size; expire_timestamp_ = expire_timestamp; @@ -308,13 +307,13 @@ int ObFragmentWriterV2::flush_buffer() } else if (OB_FAIL(macro_buffer_writer_.serialize_header())) { STORAGE_LOG(WARN, "fail to serialize header", K(ret)); } else { - tmp_file::ObTmpFileIOInfo io_info; + data_plane::ObTmpFileIOInfo io_info; io_info.fd_ = fd_; io_info.dir_id_ = dir_id_; io_info.size_ = buf_size_; io_info.buf_ = buf_; io_info.io_timeout_ms_ = timeout_ms; - if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->aio_write(io_info, file_io_handle_))) { + if (OB_FAIL(data_plane::tmp_file_write(io_info))) { } else { macro_buffer_writer_.assign(ObExternalSortConstant::BUF_HEADER_LENGTH, buf_size_, buf_); } @@ -349,7 +348,6 @@ void ObFragmentWriterV2::reset() allocator_.reuse(); macro_buffer_writer_.assign(0, 0, NULL); has_sample_item_ = false; - file_io_handle_.reset(); fd_ = -1; dir_id_ = -1; @@ -449,7 +447,7 @@ class ObFragmentReaderV2 : public ObFragmentIterator int64_t fd_; int64_t dir_id_; T curr_item_; - tmp_file::ObTmpFileIOHandle file_io_handles_[MAX_HANDLE_COUNT]; + data_plane::ObTmpFileIOHandle file_io_handles_[MAX_HANDLE_COUNT]; int64_t handle_cursor_; char *buf_[MAX_HANDLE_COUNT]; @@ -544,14 +542,13 @@ int ObFragmentReaderV2::prefetch() } } if (OB_SUCC(ret)) { - tmp_file::ObTmpFileIOInfo io_info; + data_plane::ObTmpFileIOInfo io_info; io_info.fd_ = fd_; io_info.dir_id_ = dir_id_; io_info.size_ = buf_size_; io_info.buf_ = buf_[handle_index]; - io_info.disable_page_cache_ = true; if (OB_FAIL(ObExternalSortConstant::get_io_timeout_ms(expire_timestamp_, io_info.io_timeout_ms_))) { - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->aio_read(io_info, file_io_handles_[handle_index]))) { + } else if (OB_FAIL(data_plane::tmp_file_aio_read(io_info, file_io_handles_[handle_index]))) { if (common::OB_ITER_END != ret) { STORAGE_LOG(WARN, "fail to do aio read from macro file", K(ret), K(fd_), K(io_info)); } else { @@ -669,7 +666,7 @@ int ObFragmentReaderV2::clean_up() for (int64_t i = 0; i < MAX_HANDLE_COUNT; ++i) { file_io_handles_[i].reset(); } - if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->remove(fd_))) { + if (OB_FAIL(data_plane::tmp_file_remove(fd_))) { } reset(); } @@ -1048,7 +1045,7 @@ int ObExternalSortRound::init( ret = common::OB_INVALID_ARGUMENT; STORAGE_LOG(WARN, "invalid argument", K(ret), K(merge_count), K(file_buf_size), KP(compare)); - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->alloc_dir(dir_id_))) { + } else if (OB_FAIL(data_plane::tmp_file_alloc_dir(dir_id_))) { } else { is_inited_ = true; merge_count_ = merge_count; diff --git a/src/storage/storage_header_inventory.bzl b/src/storage/storage_header_inventory.bzl index 1b56e6f2c6..3ef900dad9 100644 --- a/src/storage/storage_header_inventory.bzl +++ b/src/storage/storage_header_inventory.bzl @@ -93,8 +93,7 @@ STORAGE_PUBLIC_HEADER_ROOTS = [ "tablet/ob_tablet_ddl_complete_mds_helper.h", "tablet/ob_tablet_fork_mds_helper.h", "tablet/ob_tablet_iterator.h", - "tmp_file/ob_tmp_file_cache.h", - "tmp_file/ob_tmp_file_manager.h", + "tmp_file/tmp_file_service.h", "truncate_info/ob_truncate_info.h", "truncate_info/ob_truncate_info_array.h", "truncate_info/ob_truncate_partition_filter.h", @@ -503,25 +502,6 @@ STORAGE_INTERFACE_CLOSURE_HEADERS = [ "throttle/ob_throttle_info.h", "throttle/ob_throttle_unit.h", "throttle/ob_throttle_unit.ipp", - "tmp_file/ob_tmp_file_types.h", - "tmp_file/ob_shared_nothing_tmp_file.h", - "tmp_file/ob_tmp_file_block_manager.h", - "tmp_file/ob_tmp_file_eviction_manager.h", - "tmp_file/ob_tmp_file_flush_ctx.h", - "tmp_file/ob_tmp_file_flush_list_iterator.h", - "tmp_file/ob_tmp_file_flush_manager.h", - "tmp_file/ob_tmp_file_flush_priority_manager.h", - "tmp_file/ob_tmp_file_global.h", - "tmp_file/ob_tmp_file_io_ctx.h", - "tmp_file/ob_tmp_file_io_handle.h", - "tmp_file/ob_tmp_file_io_info.h", - "tmp_file/ob_tmp_file_meta_tree.h", - "tmp_file/ob_tmp_file_page_cache_controller.h", - "tmp_file/ob_tmp_file_thread_job.h", - "tmp_file/ob_tmp_file_thread_wrapper.h", - "tmp_file/ob_tmp_file_write_buffer_index_cache.h", - "tmp_file/ob_tmp_file_write_buffer_pool.h", - "tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h", "truncate_info/ob_mds_info_distinct_mgr.h", "truncate_info/ob_truncate_info_kv_cache.h", "truncate_info/ob_truncate_info_mds_helper.h", diff --git a/src/storage/storage_source_inventory.bzl b/src/storage/storage_source_inventory.bzl index a9a2c0090c..745ed76ff0 100644 --- a/src/storage/storage_source_inventory.bzl +++ b/src/storage/storage_source_inventory.bzl @@ -715,27 +715,7 @@ STORAGE_UNITY_GROUPS = [ name = "ob_storage_tmp_file_0", language = "c++", srcs = [ - "src/storage/tmp_file/ob_tmp_file_io.cpp", - "src/storage/tmp_file/ob_shared_nothing_tmp_file.cpp", - "src/storage/tmp_file/ob_tmp_file_block_manager.cpp", - "src/storage/tmp_file/ob_tmp_file_cache.cpp", - "src/storage/tmp_file/ob_tmp_file_eviction_manager.cpp", - "src/storage/tmp_file/ob_tmp_file_flush_ctx.cpp", - "src/storage/tmp_file/ob_tmp_file_flush_list_iterator.cpp", - "src/storage/tmp_file/ob_tmp_file_flush_manager.cpp", - "src/storage/tmp_file/ob_tmp_file_flush_priority_manager.cpp", - "src/storage/tmp_file/ob_tmp_file_global.cpp", - "src/storage/tmp_file/ob_tmp_file_io_ctx.cpp", - "src/storage/tmp_file/ob_tmp_file_io_handle.cpp", - "src/storage/tmp_file/ob_tmp_file_io_info.cpp", - "src/storage/tmp_file/ob_tmp_file_meta_tree.cpp", - "src/storage/tmp_file/ob_tmp_file_manager.cpp", - "src/storage/tmp_file/ob_tmp_file_page_cache_controller.cpp", - "src/storage/tmp_file/ob_tmp_file_thread_wrapper.cpp", - "src/storage/tmp_file/ob_tmp_file_thread_job.cpp", - "src/storage/tmp_file/ob_tmp_file_write_buffer_pool.cpp", - "src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.cpp", - "src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.cpp", + "src/storage/tmp_file/tmp_file_service.cpp", ], ), struct( diff --git a/src/storage/tmp_file/ob_shared_nothing_tmp_file.cpp b/src/storage/tmp_file/ob_shared_nothing_tmp_file.cpp deleted file mode 100644 index 447623fa5b..0000000000 --- a/src/storage/tmp_file/ob_shared_nothing_tmp_file.cpp +++ /dev/null @@ -1,2045 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "storage/tmp_file/ob_tmp_file_io_ctx.h" -#include "storage/tmp_file/ob_tmp_file_page_cache_controller.h" - -namespace oceanbase -{ -namespace tmp_file -{ -void ObSNTmpFileInfo::reset() -{ - meta_tree_epoch_ = 0; - meta_tree_level_cnt_ = 0; - meta_size_ = 0; - cached_meta_page_num_ = 0; - write_back_meta_page_num_ = 0; - all_type_page_flush_cnt_ = 0; - ObTmpFileInfo::reset(); -} - -ObSharedNothingTmpFile::InnerFlushContext::InnerFlushContext() - : flush_seq_(ObTmpFileGlobal::INVALID_FLUSH_SEQUENCE), - data_finished_continuous_flush_info_num_(0), - meta_finished_continuous_flush_info_num_(0), - data_flush_infos_(), - meta_flush_infos_(), - need_to_wait_for_the_previous_data_flush_req_to_complete_(false), - need_to_wait_for_the_previous_meta_flush_req_to_complete_(false) -{ - data_flush_infos_.set_attr(ObMemAttr("TmpFileFInfo")); - meta_flush_infos_.set_attr(ObMemAttr("TmpFileFInfo")); -} - -void ObSharedNothingTmpFile::InnerFlushContext::reset() -{ - meta_finished_continuous_flush_info_num_ = 0; - data_finished_continuous_flush_info_num_ = 0; - meta_flush_infos_.reset(); - data_flush_infos_.reset(); - flush_seq_ = ObTmpFileGlobal::INVALID_FLUSH_SEQUENCE; - need_to_wait_for_the_previous_data_flush_req_to_complete_ = false; - need_to_wait_for_the_previous_meta_flush_req_to_complete_ = false; -} - -int ObSharedNothingTmpFile::InnerFlushContext::update_finished_continuous_flush_info_num(const bool is_meta, const int64_t end_pos) -{ - int ret = OB_SUCCESS; - if (is_meta) { - if (OB_UNLIKELY(end_pos < meta_finished_continuous_flush_info_num_)) { - ret = OB_ERR_UNEXPECTED; - } else { - meta_finished_continuous_flush_info_num_ = end_pos; - } - } else { - if (OB_UNLIKELY(end_pos < data_finished_continuous_flush_info_num_)) { - ret = OB_ERR_UNEXPECTED; - } else { - data_finished_continuous_flush_info_num_ = end_pos; - } - } - return ret; -} - -ObSharedNothingTmpFile::InnerFlushInfo::InnerFlushInfo() - : update_meta_data_done_(false), - flush_data_page_disk_begin_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - flush_data_page_num_(-1), - flush_virtual_page_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID), - file_size_(0), - flush_meta_page_array_() -{ - flush_meta_page_array_.set_attr(ObMemAttr("TFFlushMetaArr")); -} - -void ObSharedNothingTmpFile::InnerFlushInfo::reset() -{ - update_meta_data_done_ = false; - flush_data_page_disk_begin_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flush_data_page_num_ = -1; - flush_virtual_page_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - file_size_ = 0; - flush_meta_page_array_.reset(); -} - -int ObSharedNothingTmpFile::InnerFlushInfo::init_by_tmp_file_flush_info(const ObTmpFileFlushInfo& flush_info) -{ - int ret = OB_SUCCESS; - flush_data_page_disk_begin_id_ = flush_info.flush_data_page_disk_begin_id_; - flush_data_page_num_ = flush_info.flush_data_page_num_; - flush_virtual_page_id_ = flush_info.flush_virtual_page_id_; - file_size_ = flush_info.file_size_; - return ret; -} - -ObSharedNothingTmpFile::ObSharedNothingTmpFile() - : is_inited_(false), - dir_id_(ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID), - fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - is_deleting_(false), - is_sealed_(false), - ref_cnt_(0), - truncated_offset_(0), - read_offset_(0), - file_size_(0), - cached_page_nums_(0), - write_back_data_page_num_(0), - begin_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - begin_page_virtual_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID), - end_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - diag_log_print_cnt_(0), - data_page_flush_level_(-1), - data_flush_node_(*this), - meta_lock_(common::ObLatchIds::TMP_FILE_LOCK), - stat_lock_(common::ObLatchIds::TMP_FILE_LOCK), - multi_write_lock_(common::ObLatchIds::TMP_FILE_LOCK), - last_page_lock_(common::ObLatchIds::TMP_FILE_LOCK), - wbp_(nullptr), - flush_prio_mgr_(nullptr), - page_idx_cache_(), - callback_allocator_(nullptr), - trace_id_(), - birth_ts_(-1), - label_(), - write_req_cnt_(0), - unaligned_write_req_cnt_(0), - write_persisted_tail_page_cnt_(0), - lack_page_cnt_(0), - last_modify_ts_(-1), - read_req_cnt_(0), - unaligned_read_req_cnt_(0), - total_truncated_page_read_cnt_(0), - total_kv_cache_page_read_cnt_(0), - total_uncached_page_read_cnt_(0), - total_wbp_page_read_cnt_(0), - truncated_page_read_hits_(0), - kv_cache_page_read_hits_(0), - uncached_page_read_hits_(0), - wbp_page_read_hits_(0), - total_read_size_(0), - last_access_ts_(-1), - tmp_file_block_manager_(nullptr), - page_cache_controller_(nullptr), - eviction_mgr_(nullptr), - is_in_data_eviction_list_(false), - is_in_meta_eviction_list_(false), - meta_page_flush_level_(-1), - flushed_data_page_num_(0), - flushed_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - flushed_page_virtual_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID), - meta_tree_(), - meta_flush_node_(*this), - data_eviction_node_(*this), - meta_eviction_node_(*this), - truncate_lock_(common::ObLatchIds::TMP_FILE_LOCK), - inner_flush_ctx_() -{} - -ObSharedNothingTmpFile::~ObSharedNothingTmpFile() -{ - reset(); -} - -int ObSharedNothingTmpFile::init(const int64_t fd, const int64_t dir_id, - ObTmpFileBlockManager *block_manager, - ObIAllocator *callback_allocator, - ObIAllocator *wbp_index_cache_allocator, - ObIAllocator *wbp_index_cache_bkt_allocator, - ObTmpFilePageCacheController *pc_ctrl, - const char* label) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_FAIL(init_io_state_(dir_id, fd, &pc_ctrl->get_write_buffer_pool(), - &pc_ctrl->get_flush_priority_mgr(), - callback_allocator, - wbp_index_cache_allocator, - wbp_index_cache_bkt_allocator, - label))) { - } else { - if (OB_ISNULL(block_manager) || OB_ISNULL(pc_ctrl)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(meta_tree_.init(fd, &pc_ctrl->get_write_buffer_pool(), callback_allocator, block_manager))) { - } else { - tmp_file_block_manager_ = block_manager; - page_cache_controller_ = pc_ctrl; - eviction_mgr_ = &pc_ctrl->get_eviction_manager(); - } - if (OB_FAIL(ret)) { - is_inited_ = false; - } - } - - return ret; -} - -void ObSharedNothingTmpFile::reset() -{ - if (is_inited_) { - tmp_file_block_manager_ = nullptr; - page_cache_controller_ = nullptr; - eviction_mgr_ = nullptr; - is_in_data_eviction_list_ = false; - is_in_meta_eviction_list_ = false; - meta_page_flush_level_ = -1; - flushed_data_page_num_ = 0; - flushed_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flushed_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - meta_tree_.reset(); - meta_flush_node_.unlink(); - data_eviction_node_.unlink(); - meta_eviction_node_.unlink(); - inner_flush_ctx_.reset(); - reset_io_state_(); - } -} - -int ObSharedNothingTmpFile::release_resource() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - int64_t fd_backup = fd_; - int64_t free_cnt = 0; - - LOG_INFO("tmp file release_resource start", KR(ret), K(fd_), KPC(this)); - - if (cached_page_nums_ > 0) { - uint32_t cur_page_id = begin_page_id_; - while (OB_SUCC(ret) && cur_page_id != ObTmpFileGlobal::INVALID_PAGE_ID) { - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_page_virtual_id_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->free_page(fd_, cur_page_id, ObTmpFilePageUniqKey(begin_page_virtual_id_), next_page_id))) { - } else { - free_cnt++; - cur_page_id = next_page_id; - begin_page_virtual_id_ += 1; - } - } - } - if (OB_SUCC(ret) && cached_page_nums_ != free_cnt) { - LOG_ERROR("tmp file release resource, cached_page_nums_ and free_cnt are not equal", KR(ret), K(fd_), K(free_cnt), KPC(this)); - } - - LOG_INFO("tmp file release resource, free wbp page phase over", KR(ret), K(fd_), KPC(this)); - - if (FAILEDx(meta_tree_.clear(truncated_offset_, file_size_))) { - } - } - return ret; -} - -int ObSharedNothingTmpFile::inner_delete_file_() -{ - int ret = OB_SUCCESS; - if (OB_FAIL(eviction_mgr_->remove_file(*this))) { - } else if (OB_FAIL(flush_prio_mgr_->remove_file(*this))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_seal_() -{ - int ret = OB_SUCCESS; - - return ret; -} - -int ObSharedNothingTmpFile::inner_read_from_disk_(const int64_t expected_read_disk_size, - ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - ObTmpFileInfo::ObTmpFileReadInfo read_state; - common::ObArray data_items; - if (OB_FAIL(meta_tree_.search_data_items(io_ctx.get_read_offset_in_file(), - expected_read_disk_size, data_items))) { - } else if (OB_UNLIKELY(data_items.empty())) { - ret = OB_ERR_UNEXPECTED; - } - - // Iterate to read each block. - int64_t remain_read_size = expected_read_disk_size; - for (int64_t i = 0; OB_SUCC(ret) && i < data_items.count() && 0 < remain_read_size; i++) { - const int64_t block_index = data_items[i].block_index_; - const int64_t read_start_virtual_page_id = get_page_virtual_id_(io_ctx.get_read_offset_in_file(), - false /*is_open_interval*/); - const int64_t start_page_id_in_data_item = read_start_virtual_page_id - data_items[i].virtual_page_id_; - const int64_t begin_offset_in_block = - (data_items[i].physical_page_id_ + start_page_id_in_data_item) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - const int64_t end_offset_in_block = - (data_items[i].physical_page_id_ + data_items[i].physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - const int64_t begin_read_offset_in_block = begin_offset_in_block + - (0 == i? - get_offset_in_page_(io_ctx.get_read_offset_in_file()) : 0); - const int64_t end_read_offset_in_block = (data_items.count() - 1 == i? - begin_read_offset_in_block + remain_read_size : - end_offset_in_block); - // end_offset_in_block represents the range covered by the current data item, - // while end_read_offset_in_block denotes the range required by the user. - - ObTmpBlockValueHandle block_value_handle; - if (!io_ctx.is_disable_block_cache() && - OB_SUCC(ObTmpBlockCache::get_instance().get_block(ObTmpBlockCacheKey(block_index), - block_value_handle))) { - char *read_buf = io_ctx.get_todo_buffer(); - const int64_t read_size = end_read_offset_in_block - begin_read_offset_in_block; - ObTmpFileIOCtx::ObBlockCacheHandle block_cache_handle(read_buf, begin_read_offset_in_block, read_size); - block_cache_handle.block_handle_.move_from(block_value_handle); - if (OB_FAIL(io_ctx.get_block_cache_handles().push_back(block_cache_handle))) { - } else if (OB_FAIL(io_ctx.update_data_size(read_size))) { - } else { - int64_t page_begin_offset = get_page_begin_offset_(io_ctx.get_read_offset_in_file() - read_size); - int64_t page_end_offset = get_page_end_offset_(io_ctx.get_read_offset_in_file()); - read_state.kv_cache_page_read_hits_++; - read_state.total_kv_cache_page_read_cnt_ += - (page_end_offset - page_begin_offset) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - remain_read_size -= read_size; - LOG_DEBUG("succ to read data from cached block", - KR(ret), K(fd_), K(block_index), K(begin_offset_in_block), K(end_offset_in_block), - K(begin_read_offset_in_block), K(end_read_offset_in_block), - K(remain_read_size), K(read_size), K(expected_read_disk_size), - K(data_items[i]), K(io_ctx)); - } - } else if (OB_UNLIKELY(OB_ENTRY_NOT_EXIST != ret && OB_SUCCESS != ret)) { - } else { // not hit block cache, read page from disk. - ret = OB_SUCCESS; - const int64_t read_size = end_read_offset_in_block - begin_read_offset_in_block; - if (io_ctx.is_disable_page_cache()) { - if (OB_FAIL(inner_direct_read_from_block_(block_index, - begin_read_offset_in_block, - end_read_offset_in_block, - io_ctx))) { - } else { - int64_t page_begin_offset = get_page_begin_offset_(io_ctx.get_read_offset_in_file() - read_size); - int64_t page_end_offset = get_page_end_offset_(io_ctx.get_read_offset_in_file()); - read_state.uncached_page_read_hits_++; - read_state.total_uncached_page_read_cnt_ += - (page_end_offset - page_begin_offset) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - } else { - if (io_ctx.is_prefetch()) { - if (OB_FAIL(inner_cached_read_from_block_with_prefetch_(block_index, - begin_read_offset_in_block, - end_offset_in_block, - read_size, - io_ctx, - read_state))) { - } - } else { - if (OB_FAIL(inner_cached_read_from_block_(block_index, - begin_read_offset_in_block, - end_read_offset_in_block, - io_ctx, - read_state))) { - } - } - } - if (OB_SUCC(ret)) { - remain_read_size -= read_size; - LOG_DEBUG("succ to read from block", - KR(ret), K(fd_), K(block_index), K(begin_offset_in_block), K(end_offset_in_block), - K(begin_read_offset_in_block), K(end_read_offset_in_block), - K(remain_read_size), K(expected_read_disk_size), - K(data_items[i]), K(io_ctx), KPC(this)); - } - } - } // end for - - if (OB_SUCC(ret)) { - io_ctx.update_read_kv_cache_page_stat(read_state.total_kv_cache_page_read_cnt_, - read_state.kv_cache_page_read_hits_); - io_ctx.update_sn_read_uncached_page_stat(read_state.total_uncached_page_read_cnt_, - read_state.uncached_page_read_hits_); - } - return ret; -} - -int ObSharedNothingTmpFile::inner_direct_read_from_block_(const int64_t block_index, - const int64_t begin_read_offset_in_block, - const int64_t end_read_offset_in_block, - ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - const int64_t expected_read_size = end_read_offset_in_block - begin_read_offset_in_block; - ObTmpFileBlockHandle block_handle; - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX == block_index || - expected_read_size <= 0 || expected_read_size > ObTmpFileGlobal::SN_BLOCK_SIZE)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(tmp_file_block_manager_->get_tmp_file_block_handle(block_index, block_handle))) { - } else if (OB_ISNULL(block_handle.get()) || OB_UNLIKELY(!block_handle.get()->get_macro_block_id().is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else { - char *read_buf = io_ctx.get_todo_buffer(); - ObTmpFileIOCtx::ObIOReadHandle io_read_handle(read_buf, - 0 /*offset_in_src_data_buf_*/, - expected_read_size, block_handle); - ObTmpPageCacheReadInfo read_info; - if (OB_FAIL(io_ctx.get_io_handles().push_back(io_read_handle))) { - } else if (OB_FAIL(read_info.init_read(block_handle.get()->get_macro_block_id(), - expected_read_size, begin_read_offset_in_block, - io_ctx.get_io_flag(), io_ctx.get_io_timeout_ms(), - &io_ctx.get_io_handles().at(io_ctx.get_io_handles().count()-1).handle_))) { - } else if (OB_FAIL(ObTmpPageCache::get_instance().direct_read(read_info, *callback_allocator_))) { - } - } - - // Update read offset and read size. - if (OB_FAIL(ret)) { - } else if (OB_FAIL(io_ctx.update_data_size(expected_read_size))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_cached_read_from_block_(const int64_t block_index, - const int64_t begin_read_offset_in_block, - const int64_t end_read_offset_in_block, - ObTmpFileIOCtx &io_ctx, - ObTmpFileInfo::ObTmpFileReadInfo &read_state) -{ - int ret = OB_SUCCESS; - const int64_t begin_page_idx_in_block = get_page_virtual_id_(begin_read_offset_in_block, false); - const int64_t end_page_idx_in_block = get_page_virtual_id_(end_read_offset_in_block, true); - ObTmpFileBlockPageBitmap bitmap; - ObTmpFileBlockPageBitmapIterator iterator; - ObArray page_value_handles; - - if (OB_FAIL(collect_pages_in_block_(block_index, begin_page_idx_in_block, end_page_idx_in_block, - bitmap, page_value_handles))) { - } else if (OB_FAIL(iterator.init(&bitmap, begin_page_idx_in_block, end_page_idx_in_block))) { - } else { - int64_t already_read_cached_page_num = 0; - while (OB_SUCC(ret) && iterator.has_next()) { - bool is_in_cache = false; - int64_t begin_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t end_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t begin_read_offset = -1; - int64_t end_read_offset = -1; - int64_t user_read_size = -1; - if (OB_FAIL(iterator.next_range(is_in_cache, begin_page_id, end_page_id))) { - } else if (OB_UNLIKELY(begin_page_id > end_page_id || begin_page_id < 0 || end_page_id < 0)) { - ret = OB_ERR_UNEXPECTED; - } else { - begin_read_offset = begin_page_id == begin_page_idx_in_block ? - begin_read_offset_in_block : - get_page_begin_offset_by_virtual_id_(begin_page_id); - end_read_offset = end_page_id == end_page_idx_in_block ? - end_read_offset_in_block : - get_page_end_offset_by_virtual_id_(end_page_id); - user_read_size = end_read_offset - begin_read_offset; - } - - if (OB_FAIL(ret)) { - } else if (is_in_cache) { - if (OB_FAIL(inner_read_continuous_cached_pages_(begin_read_offset, end_read_offset, - page_value_handles, already_read_cached_page_num, - io_ctx))) { - } else { - read_state.total_kv_cache_page_read_cnt_ += end_page_id - begin_page_id + 1; - already_read_cached_page_num += (end_page_id - begin_page_id + 1); - read_state.kv_cache_page_read_hits_++; - } - } else { - if (OB_FAIL(inner_read_continuous_uncached_pages_(block_index, begin_read_offset, - end_read_offset, user_read_size, - io_ctx))) { - } else { - read_state.total_uncached_page_read_cnt_ += (get_page_end_offset_(end_read_offset) - - get_page_begin_offset_(begin_read_offset)) / - ObTmpFileGlobal::ALLOC_PAGE_SIZE; - read_state.uncached_page_read_hits_++; - } - } - } - } - - return ret; -} - -// This function retrieves data within the range [begin_read_offset_in_block, begin_read_offset_in_block + user_read_size] for the user. -// it reads the data from the disk in the range [begin_read_offset_in_block, end_offset_in_block] and stores it in the kv cache. -// consequently end_offset_in_block >= begin_read_offset_in_block + user_read_size. -int ObSharedNothingTmpFile::inner_cached_read_from_block_with_prefetch_( - const int64_t block_index, - const int64_t begin_read_offset_in_block, - const int64_t end_offset_in_block, - const int64_t user_read_size, - ObTmpFileIOCtx &io_ctx, - ObTmpFileInfo::ObTmpFileReadInfo &read_state) -{ - int ret = OB_SUCCESS; - bool all_in_cache = true; - const int64_t begin_page_idx_in_block = get_page_virtual_id_(begin_read_offset_in_block, false); - const int64_t end_page_idx_in_block = get_page_virtual_id_(end_offset_in_block, true); - - ObTmpFileBlockPageBitmap bitmap; - ObArray page_value_handles; - if (OB_FAIL(collect_pages_in_block_(block_index, begin_page_idx_in_block, - end_page_idx_in_block, bitmap, - page_value_handles))) { - } else if (OB_FAIL(bitmap.is_all_true(begin_page_idx_in_block, - end_page_idx_in_block, - all_in_cache))) { - } else { - if (all_in_cache) { - int64_t end_read_offset_in_block = begin_read_offset_in_block + user_read_size; - if (OB_FAIL(inner_read_continuous_cached_pages_(begin_read_offset_in_block, end_read_offset_in_block, - page_value_handles, 0 /*read_page_start_idx*/, - io_ctx))) { - } else { - read_state.total_kv_cache_page_read_cnt_ += (end_page_idx_in_block - begin_page_idx_in_block + 1); - read_state.kv_cache_page_read_hits_++; - } - } else { - if (OB_FAIL(inner_read_continuous_uncached_pages_(block_index, - begin_read_offset_in_block, - end_offset_in_block, - user_read_size, - io_ctx))) { - } else { - read_state.total_uncached_page_read_cnt_ += user_read_size / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - read_state.uncached_page_read_hits_++; - } - } - } - return ret; -} - -int ObSharedNothingTmpFile::collect_pages_in_block_(const int64_t block_index, - const int64_t begin_page_idx_in_block, - const int64_t end_page_idx_in_block, - ObTmpFileBlockPageBitmap &bitmap, - ObIArray &page_value_handles) -{ - int ret = OB_SUCCESS; - bitmap.reset(); - page_value_handles.reset(); - if (OB_FAIL(page_value_handles.reserve(ObTmpFileGlobal::BLOCK_PAGE_NUMS))) { - } else { - for (int64_t page_idx_in_block = begin_page_idx_in_block; - OB_SUCC(ret) && page_idx_in_block <= end_page_idx_in_block; - page_idx_in_block++) { - ObTmpPageCacheKey key(block_index, page_idx_in_block); - ObTmpPageValueHandle p_handle; - if (OB_SUCC(ObTmpPageCache::get_instance().get_page(key, p_handle))) { - if (OB_FAIL(page_value_handles.push_back(p_handle))) { - } else if (OB_FAIL(bitmap.set_bitmap(page_idx_in_block, true))) { - } - } else if (OB_ENTRY_NOT_EXIST == ret) { - ret = OB_SUCCESS; - if (OB_FAIL(bitmap.set_bitmap(page_idx_in_block, false))) { - } - } else { - } - } - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_read_continuous_uncached_pages_(const int64_t block_index, - const int64_t begin_io_read_offset, - const int64_t end_io_read_offset, - const int64_t user_read_size, - ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - ObArray page_keys; - const int64_t begin_page_idx = get_page_virtual_id_(begin_io_read_offset, false); - const int64_t end_page_idx = get_page_virtual_id_(end_io_read_offset, true); - const int64_t block_read_begin_offset = get_page_begin_offset_(begin_io_read_offset); - // from loaded disk block buf, from "offset_in_block_buf" read "user_read_size" size data to user's read buf - const int64_t offset_in_block_buf = begin_io_read_offset - block_read_begin_offset; - - for (int64_t page_id = begin_page_idx; OB_SUCC(ret) && page_id <= end_page_idx; page_id++) { - ObTmpPageCacheKey key(block_index, page_id); - if (OB_FAIL(page_keys.push_back(key))) { - } - } - - ObTmpFileBlockHandle block_handle; - if (OB_FAIL(ret)) { - } else if (OB_FAIL(tmp_file_block_manager_->get_tmp_file_block_handle(block_index, block_handle))) { - } else { - char *user_read_buf = io_ctx.get_todo_buffer(); - ObTmpFileIOCtx::ObIOReadHandle io_read_handle(user_read_buf, - offset_in_block_buf, - user_read_size, block_handle); - ObTmpPageCacheReadInfo read_info; - - if (OB_FAIL(io_ctx.get_io_handles().push_back(io_read_handle))) { - } else if (OB_FAIL(read_info.init_read(block_handle.get()->get_macro_block_id(), - page_keys.count() * ObTmpFileGlobal::ALLOC_PAGE_SIZE, - block_read_begin_offset, - io_ctx.get_io_flag(), io_ctx.get_io_timeout_ms(), - &io_ctx.get_io_handles().at(io_ctx.get_io_handles().count()-1).handle_))) { - } else if (OB_FAIL(ObTmpPageCache::get_instance().cached_read(page_keys, read_info, *callback_allocator_))) { - } else if (OB_FAIL(io_ctx.update_data_size(user_read_size))) { - } - } - return ret; -} - -int ObSharedNothingTmpFile::inner_read_continuous_cached_pages_(const int64_t begin_read_offset_in_block, - const int64_t end_read_offset_in_block, - const ObArray &page_value_handles, - const int64_t start_array_idx, - ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - const int64_t begin_page_idx = get_page_virtual_id_(begin_read_offset_in_block, false); - const int64_t end_page_idx = get_page_virtual_id_(end_read_offset_in_block, true); - const int64_t iter_array_cnt = end_page_idx - begin_page_idx + 1; - - if (OB_UNLIKELY(start_array_idx < 0 || start_array_idx + iter_array_cnt > page_value_handles.count())) { - ret = OB_ERR_UNEXPECTED; - } - - int64_t read_offset = begin_read_offset_in_block; - int64_t cur_array_idx = start_array_idx; - for (int64_t cached_page_idx = begin_page_idx; OB_SUCC(ret) && cached_page_idx <= end_page_idx; cached_page_idx++) { - char *read_buf = io_ctx.get_todo_buffer(); - const int64_t cur_page_end_offset = get_page_end_offset_by_virtual_id_(cached_page_idx); - const int64_t read_size = MIN(cur_page_end_offset, end_read_offset_in_block) - read_offset; - const int64_t read_offset_in_page = get_offset_in_page_(read_offset); - ObTmpFileIOCtx::ObPageCacheHandle page_handle(read_buf, read_offset_in_page, read_size); - if (OB_FAIL(page_handle.page_handle_.assign(page_value_handles.at(cur_array_idx++)))) { - } else if (OB_FAIL(io_ctx.get_page_cache_handles().push_back(page_handle))) { - } else if (OB_FAIL(io_ctx.update_data_size(read_size))) { - } else { - read_offset += read_size; - } - } // end for - - return ret; -} - -int ObSharedNothingTmpFile::swap_page_to_disk_(const ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(page_cache_controller_->invoke_swap_and_wait( - MIN(io_ctx.get_todo_size(), ObTmpFileGlobal::TMP_FILE_WRITE_BATCH_PAGE_NUM * ObTmpFileGlobal::ALLOC_PAGE_SIZE), - io_ctx.get_io_timeout_ms()))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::load_disk_tail_page_and_rewrite_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - // `file_size_` is already under multi-write lock's protection, no need to fetch meta lock. - const int64_t has_written_size = get_offset_in_page_(file_size_); - const int64_t tail_page_virtual_id = get_page_virtual_id_(file_size_, true /*is_open_interval*/); - const int64_t write_size = MIN(ObTmpFileGlobal::ALLOC_PAGE_SIZE - has_written_size, io_ctx.get_todo_size()); - char *write_buff = io_ctx.get_todo_buffer(); - uint32_t new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObSharedNothingTmpFileDataItem data_item; - bool block_meta_tree_flushing = false; - bool has_update_file_meta = false; - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == tail_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(has_written_size + write_size > ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(write_buff)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(meta_tree_.prepare_for_write_tail(data_item))) { - } else { - block_meta_tree_flushing = true; - } - - if (OB_SUCC(ret)) { - blocksstable::MacroBlockId macro_block_id; - int64_t last_page_begin_offset_in_block = - (data_item.physical_page_id_ + data_item.physical_page_num_ - 1) - * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - char *page_buf = nullptr; - if (OB_FAIL(tmp_file_block_manager_->get_macro_block_id(data_item.block_index_, macro_block_id))) { - } else if (OB_UNLIKELY(!macro_block_id.is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->alloc_page(fd_, ObTmpFilePageUniqKey(tail_page_virtual_id), new_page_id, page_buf))) { - } else { - // load last unfilled page from disk - blocksstable::ObMacroBlockHandle mb_handle; - blocksstable::ObMacroBlockReadInfo info; - info.io_desc_ = io_ctx.get_io_flag(); - info.io_desc_.set_mode(ObIOMode::READ); - info.macro_block_id_ = macro_block_id; - info.size_ = has_written_size; - info.offset_ = last_page_begin_offset_in_block; - info.io_timeout_ms_ = io_ctx.get_io_timeout_ms(); - - if (OB_FAIL(mb_handle.async_read(info))) { - } else if (OB_FAIL(mb_handle.wait())) { - } else if (OB_ISNULL(mb_handle.get_buffer()) || mb_handle.get_data_size() < has_written_size) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!io_ctx.check_buf_range_valid(write_buff, write_size))) { - ret = OB_ERR_UNEXPECTED; - } else { - MEMCPY(page_buf, mb_handle.get_buffer(), has_written_size); - // fill last page in memory - MEMCPY(page_buf + has_written_size, write_buff, write_size); - } - if (FAILEDx(wbp_->notify_dirty(fd_, new_page_id, ObTmpFilePageUniqKey(tail_page_virtual_id)))) { - } - } - } - - // update meta data - if (OB_SUCC(ret)) { - common::TCRWLock::WLockGuard guard(meta_lock_); - if (OB_UNLIKELY(is_deleting_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(meta_tree_.finish_write_tail(data_item, true /*release_tail_in_disk*/))) { - } else if (OB_FAIL(io_ctx.update_data_size(write_size))) { - } else if (OB_FAIL(page_idx_cache_.push(new_page_id))) { - } else { - cached_page_nums_ = 1; - file_size_ += write_size; - begin_page_id_ = new_page_id; - begin_page_virtual_id_ = tail_page_virtual_id; - end_page_id_ = new_page_id; - has_update_file_meta = true; - } - - if (FAILEDx(insert_or_update_data_flush_node_())) { - } else if (OB_FAIL(insert_or_update_meta_flush_node_())) { - } - - if (OB_FAIL(ret) && has_update_file_meta) { - cached_page_nums_ = 0; - file_size_ -= write_size; - begin_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - begin_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - page_idx_cache_.reset(); - } - } - - if (OB_FAIL(ret)) { - int tmp_ret = OB_SUCCESS; - if (block_meta_tree_flushing) { - if (OB_TMP_FAIL(meta_tree_.finish_write_tail(data_item, false /*release_tail_in_disk*/))) { - } - } - - if (new_page_id != ObTmpFileGlobal::INVALID_PAGE_ID) { - uint32_t unused_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_TMP_FAIL(wbp_->free_page(fd_, new_page_id, ObTmpFilePageUniqKey(tail_page_virtual_id), unused_page_id))) { - } - } - } - return ret; -} - -// attention: -// last_page_lock_ could promise that there are not truncating task, -// evicting task or flush generator task for the last page. -// however, it might happen that append write for the last page is processing after -// flush generator task has been processed over. -// thus, this function should consider the concurrence problem between append write and callback of flush task. -int ObSharedNothingTmpFile::append_write_memory_tail_page_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - char *page_buff = nullptr; - const int64_t has_written_size = get_offset_in_page_(file_size_); - const int64_t need_write_size = MIN(ObTmpFileGlobal::ALLOC_PAGE_SIZE - has_written_size, - io_ctx.get_todo_size()); - const int64_t end_page_virtual_id = get_end_page_virtual_id_(); - char *write_buff = io_ctx.get_todo_buffer(); - uint32_t unused_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObSharedNothingTmpFileDataItem rightest_data_item; - - if (OB_UNLIKELY(has_written_size + need_write_size > ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(write_buff)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == end_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->read_page(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id), - page_buff, unused_page_id))) { - } else if (OB_ISNULL(page_buff)) { - ret = OB_ERR_UNEXPECTED; - } else if ((wbp_->is_write_back(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id)) || - wbp_->is_cached(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id))) && - OB_FAIL(meta_tree_.prepare_for_write_tail(rightest_data_item))) { - } else if (OB_UNLIKELY(!io_ctx.check_buf_range_valid(write_buff, need_write_size))) { - ret = OB_ERR_UNEXPECTED; - } else { - MEMCPY(page_buff + has_written_size, write_buff, need_write_size); - } - - // update meta data - if (OB_SUCC(ret)) { - common::TCRWLock::WLockGuard guard(meta_lock_); - const bool is_cached = wbp_->is_cached(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id)); - const bool is_write_back = wbp_->is_write_back(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id)); - if (OB_UNLIKELY(is_deleting_)) { - ret = OB_ERR_UNEXPECTED; - } else if (is_cached || is_write_back) { - // due to the appending writing for the last page which is flushing or flushed into disk, - // the page carbon in memory and disk will be different. - // thus, we need to rollback the flush status of the last page, - if (OB_FAIL(wbp_->notify_dirty(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id)))) { - } else if (is_cached) { - // for the last page, if the status of flushed_page_id_ page is not cached, - // we will treat this page as a non-flushed page - flushed_data_page_num_--; - if (0 == flushed_data_page_num_) { - LOG_INFO("flushed_page_id_ has been written", KPC(this)); - flushed_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flushed_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } - } else if (is_write_back) { - write_back_data_page_num_--; - } - - // modify meta tree - if (OB_FAIL(ret)) { - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(meta_tree_.finish_write_tail(rightest_data_item, false /*release_tail_in_disk*/))) { - } - } else { - // add file into flush list if file is not flushing, - // because we produce 1 dirty data page and 1 dirty meta page after writing tail page - if (OB_FAIL(meta_tree_.finish_write_tail(rightest_data_item, true /*release_tail_in_disk*/))) { - } else if (OB_FAIL(insert_or_update_data_flush_node_())) { - } else if (OB_FAIL(insert_or_update_meta_flush_node_())) { - } - } - } - - if (FAILEDx(io_ctx.update_data_size(need_write_size))) { - } else { - file_size_ += need_write_size; - } - - } - - return ret; -} - -// Attention!!!! -// in order to prevent concurrency problems of eviction list -// from the operation from eviction manager and flush manager, -// before eviction manager calls this function, -// it removes the file's node from its' eviction list, -// but still keeps the file's `is_in_data_eviction_list_` be true. -// when this function run over, -// if `remain_flushed_page_num` > 0, this function will reinsert node into the list of eviction manager again; -// otherwise, this function will set `is_in_data_eviction_list_` be false. -int ObSharedNothingTmpFile::evict_data_pages(const int64_t expected_evict_page_num, - int64_t &actual_evict_page_num, - int64_t &remain_flushed_page_num) -{ - int ret = OB_SUCCESS; - bool lock_last_page = false; - common::TCRWLock::WLockGuard meta_lock_guard(meta_lock_); - const int64_t end_page_virtual_id = get_end_page_virtual_id_(); - actual_evict_page_num = 0; - remain_flushed_page_num = 0; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_deleting_)) { - // actual_evict_page_num = 0; - // remain_flushed_page_num = 0; - is_in_data_eviction_list_ = false; - LOG_INFO("try to evict data pages when file is deleting", K(fd_), KPC(this)); - } else if (OB_UNLIKELY(expected_evict_page_num <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == end_page_virtual_id || - 0 == flushed_data_page_num_)) { - is_in_data_eviction_list_ = false; - LOG_INFO("tmp file has no flushed data pages need to be evicted", KR(ret), K(fd_), K(flushed_data_page_num_), KPC(this)); - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == flushed_page_id_ || - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == flushed_page_virtual_id_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!is_in_data_eviction_list_)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN( "the file is not in data eviction list", K(fd_), K(is_in_data_eviction_list_), KPC(this)); - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_page_virtual_id_)) { - ret = OB_ERR_UNEXPECTED; - } else { - bool need_to_evict_last_page = false; - if (flushed_data_page_num_ == cached_page_nums_ && expected_evict_page_num >= flushed_data_page_num_ && - wbp_->is_cached(fd_, end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id))) { - need_to_evict_last_page = true; - // last page should be evicted, try to lock the last page. - if (OB_FAIL(last_page_lock_.trylock())) { - // fail to get the lock of last data page, it will not be evicted. - ret = OB_SUCCESS; - } else { - lock_last_page = true; - } - } - - int64_t remain_evict_page_num = 0; - if (lock_last_page) { - remain_evict_page_num = flushed_data_page_num_; - } else if (need_to_evict_last_page) { // need_to_evict_last_page && !lock_last_page - remain_evict_page_num = flushed_data_page_num_ - 1; - } else { - remain_evict_page_num = MIN(flushed_data_page_num_, expected_evict_page_num); - } - - const int64_t evict_end_virtual_id = begin_page_virtual_id_ + remain_evict_page_num; - if (OB_FAIL(ret)) { - } else if (OB_FAIL(page_idx_cache_.truncate(evict_end_virtual_id))) { - } - - // evict data pages - const bool evict_last_page = lock_last_page; - while (OB_SUCC(ret) && remain_evict_page_num > 0) { - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t first_cached_page_idx = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (OB_UNLIKELY(!wbp_->is_cached(fd_, begin_page_id_, ObTmpFilePageUniqKey(begin_page_virtual_id_)))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->free_page(fd_, begin_page_id_, ObTmpFilePageUniqKey(begin_page_virtual_id_), next_page_id))) { - } else { - if (begin_page_id_ == flushed_page_id_) { - flushed_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flushed_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } - begin_page_id_ = next_page_id; - if (ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_) { - end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - begin_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } else { - begin_page_virtual_id_ += 1; - } - actual_evict_page_num++; - remain_evict_page_num--; - flushed_data_page_num_--; - cached_page_nums_--; - } - } // end while - - if (OB_FAIL(ret)) { - } else if (flushed_data_page_num_ > 0) { - if (OB_FAIL(eviction_mgr_->add_file(false/*is_meta*/, *this))) { - } - } else { - is_in_data_eviction_list_ = false; - } - - if (OB_SUCC(ret)) { - remain_flushed_page_num = flushed_data_page_num_; - } - - if (lock_last_page) { - last_page_lock_.unlock(); - } - - } - - return ret; -} - -// Attention!!!! -// in order to prevent concurrency problems of eviction list -// from the operation from eviction manager and flush manager, -// before eviction manager calls this function, -// it removes the file's node from its' eviction list, -// but still keeps the file's `is_in_meta_eviction_list_` be true. -// when this function run over, -// if `remain_flushed_page_num` > 0, this function will reinsert node into the list of eviction manager again; -// otherwise, this function will set `is_in_meta_eviction_list_` be false. -int ObSharedNothingTmpFile::evict_meta_pages(const int64_t expected_evict_page_num, - int64_t &actual_evict_page_num) -{ - int ret = OB_SUCCESS; - // TODO: wanyue.wy, wuyuefei.wyf - // if meta_tree_ could protect the consistency by itself, this lock could be removed - common::TCRWLock::WLockGuard meta_lock_guard(meta_lock_); - actual_evict_page_num = 0; - int64_t total_need_evict_page_num = 0; - int64_t total_need_evict_rightmost_page_num = 0; - int64_t remain_need_evict_page_num = 0; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_deleting_)) { - // actual_evict_page_num = 0; - is_in_meta_eviction_list_ = false; - LOG_INFO("try to evict data pages when file is deleting", K(fd_), KPC(this)); - } else if (OB_UNLIKELY(expected_evict_page_num <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(!is_in_meta_eviction_list_)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN( "the file is not in meta eviction list", K(fd_), K(is_in_meta_eviction_list_), KPC(this)); - } else if (OB_FAIL(meta_tree_.get_need_evict_page_num(total_need_evict_page_num, total_need_evict_rightmost_page_num))) { - } else if (OB_UNLIKELY(total_need_evict_page_num <= 0)) { - is_in_meta_eviction_list_ = false; - LOG_INFO("meta tree has no flushed pages need to be evicted", K(fd_), K(total_need_evict_page_num), KPC(this)); - } else if (OB_FAIL(meta_tree_.evict_meta_pages(expected_evict_page_num, - ObTmpFileTreeEvictType::FULL, actual_evict_page_num))) { - } else { - remain_need_evict_page_num = total_need_evict_page_num - actual_evict_page_num; - if (remain_need_evict_page_num > 0) { - if (OB_FAIL(eviction_mgr_->add_file(true/*is_meta*/, *this))) { - } - } else { - is_in_meta_eviction_list_ = false; - } - } - - return ret; -} - -int ObSharedNothingTmpFile::truncate(const int64_t truncate_offset) -{ - int ret = OB_SUCCESS; - SpinWLockGuard truncate_lock_guard(truncate_lock_); - - if (OB_FAIL(truncate_io_(truncate_offset))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::truncate_persistent_pages_(const int64_t truncate_offset) -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(meta_tree_.truncate(truncated_offset_, truncate_offset))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::truncate_the_first_wbp_page_() -{ - int ret = OB_SUCCESS; - bool is_flushed_page = false; - bool is_write_back_page = false; - bool is_dirty_page = false; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_ || - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_page_virtual_id_) { - ret = OB_ERR_UNEXPECTED; - } else if (wbp_->is_cached(fd_, begin_page_id_, ObTmpFilePageUniqKey(begin_page_virtual_id_))) { - // [begin_page_id_, flushed_page_id_] has been flushed - is_flushed_page = true; - } else if (wbp_->is_write_back(fd_, begin_page_id_, ObTmpFilePageUniqKey(begin_page_virtual_id_))) { - is_write_back_page = true; - } else if (wbp_->is_dirty(fd_, begin_page_id_, ObTmpFilePageUniqKey(begin_page_virtual_id_))) { - is_dirty_page = true; - } else { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("begin page state is unexpected", KR(ret), KPC(this)); - wbp_->print_page_entry(begin_page_id_); - } - - if (FAILEDx(wbp_->free_page(fd_, begin_page_id_, ObTmpFilePageUniqKey(begin_page_virtual_id_), next_page_id))) { - } else { - if (is_flushed_page) { - if (flushed_data_page_num_ <= 0) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("flushed_data_page_num_ is unexpected", KR(ret), KPC(this)); - } else if (1 == flushed_data_page_num_) { - if (flushed_page_id_ != begin_page_id_ && wbp_->is_cached(fd_, flushed_page_id_, - ObTmpFilePageUniqKey(flushed_page_virtual_id_))) { - // the page of flushed_page_id_ might not be flushed if it was the tail page of file and was appended. - // thus, only if the page is flushed, we can check the equality of flushed_page_id_ and begin_page_id_ - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("flushed_page_id_ or flushed_data_page_num_ is unexpected", KR(ret), KPC(this)); - } - } - if (OB_SUCC(ret)) { - flushed_data_page_num_--; - } - } else if (is_write_back_page) { - write_back_data_page_num_--; - } else if (is_dirty_page) { - if (flushed_page_id_ == begin_page_id_ && flushed_data_page_num_ != 0) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("flushed_page_id_ or flushed_data_page_num_ is unexpected", KR(ret), KPC(this)); - } - } - - if (OB_SUCC(ret)) { - if (flushed_page_id_ == begin_page_id_) { - flushed_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flushed_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - LOG_INFO("all flushed page has been truncated", KPC(this)); - } - } - - if (OB_SUCC(ret)) { - cached_page_nums_--; - begin_page_id_ = next_page_id; - if (ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_) { - end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - begin_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } else { - begin_page_virtual_id_ += 1; - } - } - } - return ret; -} - -void ObSharedNothingTmpFile::get_dirty_meta_page_num_with_lock(int64_t &non_rightmost_dirty_page_num, int64_t &rightmost_dirty_page_num) -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - get_dirty_meta_page_num(non_rightmost_dirty_page_num, rightmost_dirty_page_num); -} - -void ObSharedNothingTmpFile::get_dirty_meta_page_num(int64_t &non_rightmost_dirty_page_num, int64_t &rightmost_dirty_page_num) const -{ - int ret = OB_SUCCESS; - int64_t total_need_flush_page_num = 0; - if (OB_FAIL(meta_tree_.get_need_flush_page_num(total_need_flush_page_num, rightmost_dirty_page_num))) { - non_rightmost_dirty_page_num = 1; - rightmost_dirty_page_num = 1; - } else { - non_rightmost_dirty_page_num = total_need_flush_page_num - rightmost_dirty_page_num; - } -} - -int64_t ObSharedNothingTmpFile::get_dirty_data_page_size_() const -{ - int ret = OB_SUCCESS; - - int64_t dirty_size = 0; - // cached_page_nums == flushed_data_page_num + dirty_data_page_num - if (0 == cached_page_nums_ || flushed_data_page_num_ + write_back_data_page_num_ == cached_page_nums_) { - dirty_size = 0; - } else if (OB_UNLIKELY(cached_page_nums_ < flushed_data_page_num_ + write_back_data_page_num_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("page num is invalid", KR(ret), K(cached_page_nums_), K(flushed_data_page_num_), - K(write_back_data_page_num_), KPC(this)); - dirty_size = 0; - } else if (0 == file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE) { - dirty_size = - (cached_page_nums_ - flushed_data_page_num_ - write_back_data_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } else { - dirty_size = - (cached_page_nums_ - flushed_data_page_num_ - write_back_data_page_num_ - 1) * ObTmpFileGlobal::ALLOC_PAGE_SIZE - + file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - - if (dirty_size < 0) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("dirty_size is unexpected", KR(ret), K(dirty_size), KPC(this)); - dirty_size = 0; - } - return dirty_size; -} - -int ObSharedNothingTmpFile::copy_info_for_virtual_table(ObTmpFileInfo &tmp_file_info) -{ - int ret = OB_SUCCESS; - const int64_t abs_timeout_us = common::ObTimeUtility::current_time() + 100 * 1000L; - common::TCRWLock::RLockGuardWithTimeout lock_guard(meta_lock_, abs_timeout_us, ret); - ObSNTmpFileInfo &sn_tmp_file_info = static_cast(tmp_file_info); - - if (OB_FAIL(ret)) { - } else{ - ObSpinLockGuard guard(stat_lock_); - if (OB_FAIL(sn_tmp_file_info.init(trace_id_, dir_id_, fd_, - file_size_, truncated_offset_, is_deleting_, - cached_page_nums_, write_back_data_page_num_, - flushed_data_page_num_, ref_cnt_, - birth_ts_, this, label_.ptr(), - write_req_cnt_, unaligned_write_req_cnt_, - write_persisted_tail_page_cnt_, lack_page_cnt_, last_modify_ts_, - read_req_cnt_, unaligned_read_req_cnt_, - total_truncated_page_read_cnt_, total_kv_cache_page_read_cnt_, - total_uncached_page_read_cnt_, total_wbp_page_read_cnt_, - truncated_page_read_hits_, kv_cache_page_read_hits_, - uncached_page_read_hits_, wbp_page_read_hits_, - total_read_size_, last_access_ts_))) { - } else if (OB_FAIL(meta_tree_.copy_info(sn_tmp_file_info))) { - } - } - return ret; -}; - -int ObSharedNothingTmpFile::remove_meta_flush_node() -{ - int ret = OB_SUCCESS; - common::TCRWLock::WLockGuard guard(meta_lock_); - if (OB_FAIL(flush_prio_mgr_->remove_file(true, *this))) { - } - return ret; -} - -int ObSharedNothingTmpFile::reinsert_meta_flush_node() -{ - int ret = OB_SUCCESS; - common::TCRWLock::WLockGuard guard(meta_lock_); - if (OB_FAIL(reinsert_meta_flush_node_())) { - } - - return ret; -} - -int ObSharedNothingTmpFile::reinsert_meta_flush_node_() -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(nullptr != meta_flush_node_.get_next())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(is_deleting_)) { - // do nothing - } else { - int64_t non_rightmost_dirty_page_num = 0; - int64_t rightmost_dirty_page_num = 0; - get_dirty_meta_page_num(non_rightmost_dirty_page_num, rightmost_dirty_page_num); - if (0 == non_rightmost_dirty_page_num && 0 == rightmost_dirty_page_num) { - // no need to reinsert - meta_page_flush_level_ = -1; - } else if (OB_FAIL(flush_prio_mgr_->insert_meta_flush_list(*this, non_rightmost_dirty_page_num, - rightmost_dirty_page_num))) { - } - } - - return ret; -} - -bool ObSharedNothingTmpFile::is_in_meta_flush_list() -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - return OB_NOT_NULL(meta_flush_node_.get_next()); -} - -bool ObSharedNothingTmpFile::is_flushing_() -{ - return inner_flush_ctx_.is_flushing(); -} - - -// ATTENTION! call this need to be protected it in meta_lock_ -int ObSharedNothingTmpFile::insert_or_update_meta_flush_node_() -{ - int ret = OB_SUCCESS; - if (!is_flushing_()) { - int64_t non_rightmost_dirty_page_num = 0; - int64_t rightmost_dirty_page_num = 0; - get_dirty_meta_page_num(non_rightmost_dirty_page_num, rightmost_dirty_page_num); - if (meta_page_flush_level_ >= 0 && OB_ISNULL(meta_flush_node_.get_next())) { - // flush task mgr is processing this file. - // it will add this file to according flush list in the end - } else if (0 == non_rightmost_dirty_page_num + rightmost_dirty_page_num) { - // do nothing - } else if (meta_page_flush_level_ < 0) { - if (OB_FAIL(flush_prio_mgr_->insert_meta_flush_list(*this, non_rightmost_dirty_page_num, - rightmost_dirty_page_num))) { - } - } else if (OB_FAIL(flush_prio_mgr_->update_meta_flush_list(*this, non_rightmost_dirty_page_num, - rightmost_dirty_page_num))) { - } - } - return ret; -} - -int ObSharedNothingTmpFile::cal_end_position_( - ObArray &flush_infos, - const int64_t start_pos, - int64_t &end_pos, - int64_t &flushed_data_page_num) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(start_pos >= flush_infos.count() || start_pos < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(flush_infos[start_pos].has_data() && flush_infos[start_pos].has_meta())) { - // we require that each flush info only represents one type of data or meta - ret = OB_ERR_UNEXPECTED; - } else if (flush_infos[start_pos].update_meta_data_done_) { - for (end_pos = start_pos; OB_SUCC(ret) && end_pos < flush_infos.count(); end_pos++) { - if (OB_UNLIKELY(flush_infos[end_pos].has_data() && flush_infos[end_pos].has_meta()) || - OB_UNLIKELY(!flush_infos[end_pos].has_data() && !flush_infos[end_pos].has_meta())) { - ret = OB_ERR_UNEXPECTED; // flush_info contains one and only one type of pages - } else if (flush_infos[end_pos].update_meta_data_done_) { - if (flush_infos[end_pos].has_data()) { - flushed_data_page_num += flush_infos[end_pos].flush_data_page_num_; - } - } else { - break; - } - } // end for - } - return ret; -} - -int ObSharedNothingTmpFile::update_meta_after_flush(const int64_t info_idx, const bool is_meta, bool &reset_ctx) -{ - int ret = OB_SUCCESS; - reset_ctx = false; - common::TCRWLock::WLockGuard guard(meta_lock_); - int64_t start_pos = is_meta ? inner_flush_ctx_.meta_finished_continuous_flush_info_num_ - : inner_flush_ctx_.data_finished_continuous_flush_info_num_; - int64_t end_pos = start_pos; - ObArray &flush_infos_ = is_meta ? inner_flush_ctx_.meta_flush_infos_ - : inner_flush_ctx_.data_flush_infos_; - int64_t flushed_data_page_num = 0; - if (OB_UNLIKELY(info_idx < 0 || info_idx >= flush_infos_.count())) { - ret = OB_ERR_UNEXPECTED; - } else if (FALSE_IT(flush_infos_[info_idx].update_meta_data_done_ = true)) { - } else if (OB_FAIL(cal_end_position_(flush_infos_, start_pos, end_pos, flushed_data_page_num))) { - } else if (start_pos < end_pos) { // have new continuous finished flush infos - if (is_meta && OB_FAIL(update_meta_tree_after_flush_(start_pos, end_pos))) { - LOG_ERROR("fail to update meta tree", KR(ret), K(start_pos), K(end_pos), KPC(this)); - } else if (!is_meta && OB_FAIL(update_file_meta_after_flush_(start_pos, end_pos, flushed_data_page_num))) { - LOG_ERROR("fail to update file meta", KR(ret), K(start_pos), K(end_pos), K(flushed_data_page_num), KPC(this)); - } else { - // When the flush info segment between [start_pos, end_pos] is updated, the corresponding pages can be immediately freed. - // However, the flush context in flush_mgr may still contain stale flush positions. - // Setting the reset_ctx flag clears the context in the flush manager, enabling the file to regenerate the context - // using its new metadata during the next flush, thereby preventing access the illegal pages. - reset_ctx = true; - if (is_meta) { - inner_flush_ctx_.need_to_wait_for_the_previous_meta_flush_req_to_complete_ = true; - } else { - inner_flush_ctx_.need_to_wait_for_the_previous_data_flush_req_to_complete_ = true; - } - } - } - - if (FAILEDx(inner_flush_ctx_.update_finished_continuous_flush_info_num(is_meta, end_pos))) { - } else { - int tmp_ret = OB_SUCCESS; - if (inner_flush_ctx_.is_data_finished()) { - if (OB_ISNULL(data_flush_node_.get_next()) && OB_TMP_FAIL(reinsert_data_flush_node_())) { - LOG_ERROR("fail to reinsert data flush node", KR(tmp_ret), K(is_meta), K(inner_flush_ctx_), KPC(this)); - } - inner_flush_ctx_.need_to_wait_for_the_previous_data_flush_req_to_complete_ = false; - } - if (inner_flush_ctx_.is_meta_finished()) { - if (OB_ISNULL(meta_flush_node_.get_next()) && OB_TMP_FAIL(reinsert_meta_flush_node_())) { - LOG_ERROR("fail to reinsert meta flush node", KR(tmp_ret), K(is_meta), K(inner_flush_ctx_), KPC(this)); - } - inner_flush_ctx_.need_to_wait_for_the_previous_meta_flush_req_to_complete_ = false; - } - - if (inner_flush_ctx_.is_all_finished()) { - inner_flush_ctx_.reset(); - } - } - - return ret; -} - -// 1. skip truncated flush infos -// 2. abort updating file meta for tail data page if it is appending written after generating flushing task -int ObSharedNothingTmpFile::remove_useless_page_in_data_flush_infos_(const int64_t start_pos, - const int64_t end_pos, - const int64_t flushed_data_page_num, - int64_t &new_start_pos, - int64_t &new_flushed_data_page_num) -{ - int ret = OB_SUCCESS; - ObArray &flush_infos_ = inner_flush_ctx_.data_flush_infos_; - new_start_pos = start_pos; - new_flushed_data_page_num = flushed_data_page_num; - - if (OB_UNLIKELY(start_pos >= end_pos || end_pos < 1 || flushed_data_page_num <= 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (start_pos >= flush_infos_.count() || end_pos > flush_infos_.count()) { - ret = OB_ERR_UNEXPECTED; - } else { - // skip truncated flush infos - for (int64_t i = start_pos; OB_SUCC(ret) && i < end_pos; i++) { - int64_t flushed_start_offset = get_page_begin_offset_by_virtual_id_(flush_infos_[i].flush_virtual_page_id_); - int64_t flushed_end_offset = flushed_start_offset + - flush_infos_[i].flush_data_page_num_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - if (truncated_offset_ <= flushed_start_offset) { - // the following flushing pages are not affected by truncate_offset - break; - } else if (truncated_offset_ < flushed_end_offset) { - // although a page is truncated partly, it will also be flushed whole page - int64_t flush_info_flushed_size = flushed_end_offset - truncated_offset_; - int64_t flush_info_data_page_num = - common::upper_align(flush_info_flushed_size, ObTmpFileGlobal::ALLOC_PAGE_SIZE) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - uint32_t flush_info_virtual_page_id = - common::lower_align(truncated_offset_, ObTmpFileGlobal::ALLOC_PAGE_SIZE) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - new_flushed_data_page_num -= (flush_infos_[i].flush_data_page_num_ - flush_info_data_page_num); - - LOG_INFO("due to truncating, modify flush info", KR(ret), K(fd_), - K(start_pos), K(end_pos), K(flushed_data_page_num), K(i), - K(new_start_pos), K(new_flushed_data_page_num), - K(truncated_offset_), K(flushed_start_offset), K(flushed_end_offset), K(flush_infos_[i]), - K(flush_info_data_page_num), K(flush_info_virtual_page_id)); - flush_infos_[i].flush_data_page_num_ = flush_info_data_page_num; - flush_infos_[i].flush_virtual_page_id_ = flush_info_virtual_page_id; - break; - } else { - // all pages of this flush_info have been truncated, abort it - new_start_pos++; - new_flushed_data_page_num -= flush_infos_[i].flush_data_page_num_; - LOG_INFO("due to truncating, abort flush info", KR(ret), K(fd_), - K(start_pos), K(end_pos), K(flushed_data_page_num), K(i), - K(new_start_pos), K(new_flushed_data_page_num), - K(truncated_offset_), K(flushed_start_offset), K(flushed_end_offset), K(flush_infos_[i])); - } - } // end for - - // abort updating file meta for tail data page - if (OB_SUCC(ret) && new_flushed_data_page_num > 0 && new_start_pos < end_pos) { - if (flush_infos_[end_pos - 1].file_size_ > 0 && flush_infos_[end_pos - 1].file_size_ != file_size_) { - // the last page has been written after flush task has been generated. - // we will discard the flushed last page when update meta data - // (append write has correct the meta data of the last page, here only need to ignore it) - - int64_t discard_page_virtual_id = flush_infos_[end_pos - 1].flush_virtual_page_id_ + - flush_infos_[end_pos - 1].flush_data_page_num_ - 1; - uint32_t discard_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == discard_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(get_physical_page_id_in_wbp_(discard_page_virtual_id, discard_page_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == discard_page_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!wbp_->is_dirty(fd_, discard_page_id, ObTmpFilePageUniqKey(discard_page_virtual_id)))) { - ret = OB_ERR_UNEXPECTED; - } else { - new_flushed_data_page_num -= 1; - flush_infos_[end_pos - 1].flush_data_page_num_ -= 1; - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFile::update_file_meta_after_flush_(const int64_t start_pos, - const int64_t end_pos, - const int64_t flushed_data_page_num) -{ - int ret = OB_SUCCESS; - ObArray &flush_infos_ = inner_flush_ctx_.data_flush_infos_; - int64_t new_start_pos = start_pos; - int64_t new_flushed_data_page_num = flushed_data_page_num; - - if (OB_UNLIKELY(start_pos >= end_pos || end_pos < 1 || flushed_data_page_num <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (start_pos >= flush_infos_.count() || end_pos > flush_infos_.count()) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(remove_useless_page_in_data_flush_infos_(start_pos, end_pos, flushed_data_page_num, - new_start_pos, new_flushed_data_page_num))) { - } else if (0 == new_flushed_data_page_num) { - // do nothing - } else if (OB_UNLIKELY(new_flushed_data_page_num < 0 || new_start_pos >= end_pos)) { - ret = OB_INVALID_ARGUMENT; - } else { // exist multiple continuous pages have been flushed over - uint32_t last_flushed_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t cur_flush_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t cur_flush_page_virtual_id = flush_infos_[new_start_pos].flush_virtual_page_id_; - if (OB_FAIL(get_physical_page_id_in_wbp_(flush_infos_[new_start_pos].flush_virtual_page_id_, cur_flush_page_id))) { - } else { - int64_t write_back_succ_data_page_num = 0; - - // update each flush info - for (int64_t i = new_start_pos; OB_SUCC(ret) && i < end_pos; ++i) { - const InnerFlushInfo& flush_info = flush_infos_[i]; - const int64_t cur_flushed_data_page_num = flush_info.flush_data_page_num_; - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == cur_flush_page_id)) { - ret = OB_ERR_UNEXPECTED; - } else { - int64_t cur_page_virtual_id_in_flush_info = cur_flush_page_virtual_id; - // update each page of flush info - for (int64_t j = 0; OB_SUCC(ret) && j < cur_flushed_data_page_num; ++j) { - if (OB_FAIL(wbp_->notify_write_back_succ(fd_, cur_flush_page_id, ObTmpFilePageUniqKey(cur_page_virtual_id_in_flush_info)))) { - } else if (FALSE_IT(last_flushed_page_id = cur_flush_page_id)) { - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, cur_flush_page_id, - ObTmpFilePageUniqKey(cur_page_virtual_id_in_flush_info), cur_flush_page_id))) { - } else { - cur_page_virtual_id_in_flush_info += 1; - } - } // end for - if (OB_SUCC(ret)) { - write_back_succ_data_page_num += cur_flushed_data_page_num; - cur_flush_page_virtual_id += cur_flushed_data_page_num; - } - } - } // end for - - // update file meta - if (OB_SUCC(ret)) { - if (write_back_succ_data_page_num != new_flushed_data_page_num) { - ret = OB_ERR_UNEXPECTED; - } else { - flushed_page_id_ = last_flushed_page_id; - flushed_page_virtual_id_ = cur_flush_page_virtual_id - 1; - flushed_data_page_num_ += new_flushed_data_page_num; - write_back_data_page_num_ -= new_flushed_data_page_num; - if (write_back_data_page_num_ < 0) { - int tmp_ret = OB_ERR_UNEXPECTED; - LOG_WARN("write_back_data_page_num_ is unexpected", KR(tmp_ret), K(fd_), - K(write_back_data_page_num_), K(flushed_data_page_num), K(new_flushed_data_page_num), KPC(this)); - write_back_data_page_num_ = 0; - } - - if (!is_deleting_ && !is_in_data_eviction_list_ && OB_ISNULL(data_eviction_node_.get_next())) { - if (OB_FAIL(eviction_mgr_->add_file(false/*is_meta*/, *this))) { - } else { - is_in_data_eviction_list_ = true; - } - } - } - } // update file meta over - } - } // handle continuous success flush infos over - - return ret; -} - -int ObSharedNothingTmpFile::update_meta_tree_after_flush_(const int64_t start_pos, const int64_t end_pos) -{ - int ret = OB_SUCCESS; - int tmp_ret = OB_SUCCESS; - - ObArray &flush_infos_ = inner_flush_ctx_.meta_flush_infos_; - for (int64_t i = start_pos; i < end_pos; i++) { - // ATTENTION! need to alloc memory inside, caller must retry update meta data if alloc fail - if (OB_FAIL(meta_tree_.update_after_flush(flush_infos_[i].flush_meta_page_array_))) { - } else { - LOG_INFO("succ to update meta items", KR(ret), K(fd_), K(flush_infos_[i]), KPC(this)); - } - } - - if (OB_SUCC(ret)) { - if (!is_deleting_ && !is_in_meta_eviction_list_ && OB_ISNULL(meta_eviction_node_.get_next())) { - int64_t total_need_evict_page_num = 1; - int64_t total_need_evict_rightmost_page_num = 1; - if (OB_TMP_FAIL(meta_tree_.get_need_evict_page_num(total_need_evict_page_num, - total_need_evict_rightmost_page_num))) { - } - - if (total_need_evict_page_num > 0) { - if (OB_FAIL(eviction_mgr_->add_file(true/*is_meta*/, *this))) { - } else { - is_in_meta_eviction_list_ = true; - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFile::generate_data_flush_info_( - ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileDataFlushContext &data_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail) -{ - int ret = OB_SUCCESS; - - uint32_t copy_begin_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t copy_begin_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - - uint32_t copy_end_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(cal_next_flush_page_id_from_flush_ctx_or_file_(data_flush_context, - copy_begin_page_id, - copy_begin_page_virtual_id))) { - } else if (ObTmpFileGlobal::INVALID_PAGE_ID == copy_begin_page_id) { - ret = OB_ITER_END; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == copy_begin_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(get_flush_end_page_id_(copy_end_page_id, need_flush_tail))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_FLUSH_SEQUENCE != inner_flush_ctx_.flush_seq_ - && flush_sequence != inner_flush_ctx_.flush_seq_ - && flush_sequence != flush_task.get_flush_seq())) { - ret = OB_ERR_UNEXPECTED; - } else if (ObTmpFileFlushTask::TaskType::META == flush_task.get_type()) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(collect_flush_data_page_id_(flush_task, info, data_flush_context, - copy_begin_page_id, copy_begin_page_virtual_id, - copy_end_page_id, - flush_sequence, need_flush_tail))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::generate_data_flush_info( - ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileDataFlushContext &data_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail) -{ - int ret = OB_SUCCESS; - info.reset(); - - if (!truncate_lock_.try_rdlock()) { - ret = OB_ITER_END; - } else { - common::TCRWLock::RLockGuard guard(meta_lock_); - if (inner_flush_ctx_.need_to_wait_for_the_previous_data_flush_req_to_complete_) { - ret = OB_ITER_END; - LOG_INFO("need_to_wait_for_the_previous_data_flush_req_to_complete_", KR(ret), K(fd_), KPC(this)); - } else if (OB_FAIL(generate_data_flush_info_(flush_task, info, - data_flush_context, flush_sequence, need_flush_tail))) { - } - if (OB_FAIL(ret)) { - truncate_lock_.unlock(); - } - } - - return ret; -} - -int ObSharedNothingTmpFile::collect_flush_data_page_id_( - ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileDataFlushContext &data_flush_context, - const uint32_t copy_begin_page_id, - const int64_t copy_begin_page_virtual_id, - const uint32_t copy_end_page_id, - const int64_t flush_sequence, - const bool need_flush_tail) -{ - int ret = OB_SUCCESS; - char *buf = flush_task.get_data_buf(); - int64_t write_offset = flush_task.get_total_page_num() * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - - bool has_last_page_lock = false; - int64_t next_disk_page_id = flush_task.get_next_free_page_id(); - int64_t flushing_page_num = 0; - int64_t origin_info_num = inner_flush_ctx_.data_flush_infos_.size(); - uint32_t cur_flushed_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t cur_page_id = copy_begin_page_id; - int64_t cur_page_virtual_id = copy_begin_page_virtual_id; - int64_t collected_page_cnt = 0; - - if (OB_UNLIKELY(OB_STORAGE_OBJECT_MGR.get_macro_object_size() <= write_offset)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(inner_flush_ctx_.data_flush_infos_.push_back(InnerFlushInfo()))) { - } - while (OB_SUCC(ret) && cur_page_id != copy_end_page_id && write_offset < OB_STORAGE_OBJECT_MGR.get_macro_object_size()) { - if (need_flush_tail && cur_page_id == end_page_id_ && file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE != 0) { - if (OB_SUCC(last_page_lock_.trylock())) { - has_last_page_lock = true; - } else { - ret = OB_SUCCESS; // ignore error to continue flushing the copied data - break; - } - } - char *page_buf = nullptr; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - bool original_state_is_dirty = wbp_->is_dirty(fd_, cur_page_id, ObTmpFilePageUniqKey(cur_page_virtual_id)); - if (OB_FAIL(wbp_->read_page(fd_, cur_page_id, ObTmpFilePageUniqKey(cur_page_virtual_id), page_buf, next_page_id))) { - } else if (OB_FAIL(wbp_->notify_write_back(fd_, cur_page_id, ObTmpFilePageUniqKey(cur_page_virtual_id)))) { - } else if (OB_FAIL(flush_task.get_flush_page_id_arr().push_back(cur_page_id))) { - } else { - // ObTmpPageCacheKey cache_key(flush_task.get_block_index(), - // ObTmpPageCacheValue cache_value(page_buf); - // ObTmpPageCache::get_instance().try_put_page_to_cache(cache_key, cache_value); - - write_offset += ObTmpFileGlobal::ALLOC_PAGE_SIZE; - flushing_page_num += 1; - cur_flushed_page_id = cur_page_id; - cur_page_id = next_page_id; - cur_page_virtual_id += 1; - collected_page_cnt += 1; - if (original_state_is_dirty) { - write_back_data_page_num_++; - } - } - } - - if (OB_SUCC(ret) && 0 == flushing_page_num) { - ret = OB_ITER_END; - } - if (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID == cur_flushed_page_id) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("cur_flushed_page_id is unexpected", KR(ret), K(cur_flushed_page_id), KPC(this)); - } - - if (OB_SUCC(ret)) { - int64_t flush_info_idx = inner_flush_ctx_.data_flush_infos_.size() - 1; - // set flush_info in flush_task - info.flush_data_page_disk_begin_id_ = next_disk_page_id; - info.flush_data_page_num_ = flushing_page_num; - info.batch_flush_idx_ = flush_info_idx; - info.flush_virtual_page_id_ = copy_begin_page_virtual_id; - info.has_last_page_lock_ = has_last_page_lock; - info.type_ = ObTmpFileFlushInfo::Type::DATA; - // record file_size to check if the last page is appended while flushing - if (has_last_page_lock) { - info.file_size_ = file_size_; - } - - info.fd_ = fd_; - // set flush_info in file inner_flush_ctx - if (OB_FAIL(info.file_handle_.init(this))) { - } else if (OB_FAIL(inner_flush_ctx_.data_flush_infos_.at(flush_info_idx).init_by_tmp_file_flush_info(info))) { - } - } - - // override error code, we will handle OB_ITER_END in flush mgr - if (OB_ALLOCATE_MEMORY_FAILED == ret) { - ret = OB_ITER_END; - } - - if (OB_SUCC(ret)) { - // maintain flushed_page_id recorded in flush_mgr - data_flush_context.set_flushed_page_id(cur_flushed_page_id); - data_flush_context.set_flushed_page_virtual_id(cur_page_virtual_id - 1); - data_flush_context.set_next_flush_page_id(cur_page_id); - data_flush_context.set_next_flush_page_virtual_id(cur_page_virtual_id); - data_flush_context.set_is_valid(true); - if (has_last_page_lock) { - data_flush_context.set_has_flushed_last_partially_written_page(true); - } - flush_task.set_data_length(write_offset); - flush_task.set_buffer_pool_ptr(wbp_); - flush_task.set_type(ObTmpFileFlushTask::DATA); - - inner_flush_ctx_.flush_seq_ = flush_sequence; - } else { - for (int32_t i = 0; i < collected_page_cnt; ++i) { - flush_task.get_flush_page_id_arr().pop_back(); - } - if (inner_flush_ctx_.data_flush_infos_.size() == origin_info_num + 1) { - inner_flush_ctx_.data_flush_infos_.pop_back(); - } - if (has_last_page_lock) { - last_page_lock_.unlock(); - } - } - return ret; -} - -int ObSharedNothingTmpFile::generate_meta_flush_info_( - ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileTreeFlushContext &meta_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail) -{ - int ret = OB_SUCCESS; - - ObArray &flush_infos = inner_flush_ctx_.meta_flush_infos_; - int64_t origin_info_num = flush_infos.size(); - - const int64_t block_index = flush_task.get_block_index(); - char *buf = flush_task.get_data_buf(); - int64_t write_offset = flush_task.get_total_page_num() * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - - ObTmpFileTreeEvictType flush_type = need_flush_tail ? - ObTmpFileTreeEvictType::FULL : ObTmpFileTreeEvictType::MAJOR; - - int64_t flush_info_idx = -1; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_FLUSH_SEQUENCE != inner_flush_ctx_.flush_seq_ - && flush_sequence != inner_flush_ctx_.flush_seq_ - && flush_sequence != flush_task.get_flush_seq())) { - ret = OB_ERR_UNEXPECTED; - } else if (ObTmpFileFlushTask::TaskType::DATA == flush_task.get_type()) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(buf) || OB_UNLIKELY(OB_STORAGE_OBJECT_MGR.get_macro_object_size() <= write_offset)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(flush_infos.push_back(InnerFlushInfo()))) { - } else if (FALSE_IT(flush_info_idx = flush_infos.size() - 1)) { - } else if (OB_FAIL(meta_tree_.flush_meta_pages_for_block(block_index, flush_type, buf, write_offset, - meta_flush_context, - flush_infos.at(flush_info_idx).flush_meta_page_array_))) { - } else if (0 == flush_infos.at(flush_info_idx).flush_meta_page_array_.count()) { - ret = OB_ITER_END; - } - - if (OB_SUCC(ret)) { - info.batch_flush_idx_ = flush_info_idx; - info.fd_ = fd_; - info.type_ = ObTmpFileFlushInfo::Type::META; - // set flush_info in flush_task - if (OB_FAIL(info.file_handle_.init(this))) { - } else if (OB_FAIL(flush_infos.at(flush_info_idx).init_by_tmp_file_flush_info(info))) { - } - } - - // override error code, we will handle OB_ITER_END in flush mgr - if (OB_ALLOCATE_MEMORY_FAILED == ret) { - ret = OB_ITER_END; - } - - if (OB_SUCC(ret)) { - flush_task.set_data_length(write_offset); - flush_task.set_type(ObTmpFileFlushTask::META); - inner_flush_ctx_.flush_seq_ = flush_sequence; - } else { - LOG_ERROR("fail to generate meta flush info", KR(ret), K(fd_), K(flush_task), - K(meta_flush_context), K(flush_sequence), K(need_flush_tail)); - if (flush_infos.size() == origin_info_num + 1) { - flush_infos.pop_back(); - } - } - - LOG_INFO("generate_meta_flush_info_ end", KR(ret), K(fd_), K(need_flush_tail), - K(inner_flush_ctx_), K(meta_flush_context), K(info), K(flush_task), KPC(this)); - return ret; -} - -int ObSharedNothingTmpFile::generate_meta_flush_info( - ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileTreeFlushContext &meta_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail) -{ - int ret = OB_SUCCESS; - info.reset(); - - common::TCRWLock::RLockGuard guard(meta_lock_); - if (inner_flush_ctx_.need_to_wait_for_the_previous_meta_flush_req_to_complete_) { - ret = OB_ITER_END; - LOG_INFO("need_to_wait_for_the_previous_meta_flush_req_to_complete_", KR(ret), K(fd_), KPC(this)); - } else if (OB_FAIL(generate_meta_flush_info_(flush_task, info, - meta_flush_context, flush_sequence, need_flush_tail))) { - } - - return ret; -} - -int ObSharedNothingTmpFile::insert_meta_tree_item(const ObTmpFileFlushInfo &info, int64_t block_index) -{ - int ret = OB_SUCCESS; - int tmp_ret = OB_SUCCESS; - - common::TCRWLock::WLockGuard guard(meta_lock_); - if (info.has_data()) { - ObSharedNothingTmpFileDataItem data_item; - data_item.block_index_ = block_index; - data_item.physical_page_id_ = info.flush_data_page_disk_begin_id_; - data_item.physical_page_num_ = info.flush_data_page_num_; - data_item.virtual_page_id_ = info.flush_virtual_page_id_; - ObSEArray data_items; - - if (OB_FAIL(data_items.push_back(data_item))) { - } else if (OB_FAIL(meta_tree_.prepare_for_insert_items())) { - } else if (OB_FAIL(meta_tree_.insert_items(data_items))) { - } - - if (OB_SUCC(ret) && info.has_last_page_lock_) { - last_page_lock_.unlock(); - } - - } else { - ret = OB_ERR_UNEXPECTED; - } - - if (!is_deleting_ && !is_in_meta_eviction_list_ && OB_ISNULL(meta_eviction_node_.get_next())) { - int64_t total_need_evict_page_num = 1; - int64_t total_need_evict_rightmost_page_num = 1; - if (OB_TMP_FAIL(meta_tree_.get_need_evict_page_num(total_need_evict_page_num, - total_need_evict_rightmost_page_num))) { - } - - if (total_need_evict_page_num > 0) { - if (OB_TMP_FAIL(eviction_mgr_->add_file(true/*is_meta*/, *this))) { - } else { - is_in_meta_eviction_list_ = true; - } - } - } - - // reinsert meta flush node to allow meta pages to be flushed multiple times in one round of flushing - if (!is_deleting_ && inner_flush_ctx_.is_meta_finished() && OB_ISNULL(meta_flush_node_.get_next())) { - if (OB_TMP_FAIL(reinsert_meta_flush_node_())) { - } - } - - return ret; -} - -int ObSharedNothingTmpFile::copy_finish() -{ - int ret = OB_SUCCESS; - truncate_lock_.unlock(); - return ret; -} - -int ObSharedNothingTmpFile::cal_next_flush_page_id_from_flush_ctx_or_file_( - const ObTmpFileDataFlushContext &data_flush_context, - uint32_t &next_flush_page_id, - int64_t &next_flush_page_virtual_id) -{ - int ret = OB_SUCCESS; - if (data_flush_context.is_valid()) { - // use next_flush_page_id from data_flush_ctx - if (data_flush_context.has_flushed_last_partially_written_page()) { - next_flush_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - next_flush_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } else { - next_flush_page_id = data_flush_context.get_next_flush_page_id(); - next_flush_page_virtual_id = data_flush_context.get_next_flush_page_virtual_id(); - int64_t truncate_page_virtual_id = get_page_virtual_id_(truncated_offset_, false /*is_open_interval*/); - if (ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID != truncate_page_virtual_id && - truncate_page_virtual_id > data_flush_context.get_flushed_page_virtual_id()) { - if (OB_FAIL(get_next_flush_page_id_(next_flush_page_id, next_flush_page_virtual_id))) { - } else { - LOG_INFO("origin next flush page has been truncated", - KR(ret), K(next_flush_page_id), K(next_flush_page_virtual_id), K(data_flush_context), KPC(this)); - } - } - - if (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID != truncate_page_virtual_id && - truncate_page_virtual_id <= data_flush_context.get_flushed_page_virtual_id()) { - uint32_t last_flushed_page_id = data_flush_context.get_flushed_page_id(); - int64_t last_flushed_page_virtual_id = data_flush_context.get_flushed_page_virtual_id(); - if (ObTmpFileGlobal::INVALID_PAGE_ID != last_flushed_page_id) { - if (!wbp_->is_write_back(fd_, last_flushed_page_id, ObTmpFilePageUniqKey(last_flushed_page_virtual_id))) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("last flushed page state not match", - KR(ret), K(last_flushed_page_id), K(data_flush_context), KPC(this)); - } - } - } - } - } else { - // cal next_flush_page_id from file meta when doing flush for the first time - if (OB_FAIL(get_next_flush_page_id_(next_flush_page_id, next_flush_page_virtual_id))) { - } - } - - if (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID != next_flush_page_id) { - if (!wbp_->is_dirty(fd_, next_flush_page_id, ObTmpFilePageUniqKey(next_flush_page_virtual_id)) && - !wbp_->is_write_back(fd_, next_flush_page_id, ObTmpFilePageUniqKey(next_flush_page_virtual_id))) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("next_flush_page_id state not validate", - KR(ret), K(next_flush_page_id), K(data_flush_context), KPC(this)); - } - } - - return ret; -} - -// output next page id after flushed_page_id_ in normal case, or output flushed_page_id for write operation appending last page -int ObSharedNothingTmpFile::get_next_flush_page_id_(uint32_t& next_flush_page_id, int64_t& next_flush_page_virtual_id) const -{ - int ret = OB_SUCCESS; - next_flush_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - next_flush_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - if (ObTmpFileGlobal::INVALID_PAGE_ID == flushed_page_id_) { - // all pages are dirty - if (OB_UNLIKELY((ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_ && - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID != begin_page_virtual_id_) || - (ObTmpFileGlobal::INVALID_PAGE_ID != begin_page_id_ && - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_page_virtual_id_) )) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("begin_page_id_ and begin_page_virtual_id_ not match", KR(ret), K(begin_page_id_), K(begin_page_virtual_id_), KPC(this)); - } else { - next_flush_page_id = begin_page_id_; - next_flush_page_virtual_id = begin_page_virtual_id_; - } - } else if (wbp_->is_dirty(fd_, flushed_page_id_, ObTmpFilePageUniqKey(flushed_page_virtual_id_))) { - // start from flushed_page_id_ if flushed_page_id_ is dirty caused by appending write - if (OB_UNLIKELY((ObTmpFileGlobal::INVALID_PAGE_ID == flushed_page_id_ && - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID != flushed_page_virtual_id_) || - (ObTmpFileGlobal::INVALID_PAGE_ID != flushed_page_id_ && - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == flushed_page_virtual_id_) )) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("flushed_page_id_ and flushed_page_virtual_id_ not match", - KR(ret), K(flushed_page_id_), K(flushed_page_virtual_id_), KPC(this)); - } else { - next_flush_page_id = flushed_page_id_; - next_flush_page_virtual_id = flushed_page_virtual_id_; - } - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, flushed_page_id_, ObTmpFilePageUniqKey(flushed_page_virtual_id_), next_flush_page_id))){ - } else if (ObTmpFileGlobal::INVALID_PAGE_ID == next_flush_page_id) { - next_flush_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } else { - next_flush_page_virtual_id = flushed_page_virtual_id_ + 1; - } - - return ret; -} - -int ObSharedNothingTmpFile::get_physical_page_id_in_wbp_(const int64_t virtual_page_id, uint32_t& page_id) const -{ - int ret = OB_SUCCESS; - int64_t end_page_virtual_id = get_end_page_virtual_id_(); - page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == virtual_page_id)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_page_virtual_id_ || - ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_ || - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == end_page_virtual_id || - ObTmpFileGlobal::INVALID_PAGE_ID == end_page_id_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(virtual_page_id < begin_page_virtual_id_ || virtual_page_id > end_page_virtual_id)) { - ret = OB_INVALID_ARGUMENT; - } else if (virtual_page_id == begin_page_virtual_id_) { - page_id = begin_page_id_; - } else if (ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == flushed_page_virtual_id_ || - virtual_page_id < flushed_page_virtual_id_) { - if (OB_FAIL(wbp_->get_page_id_by_virtual_id(fd_, virtual_page_id, begin_page_id_, page_id))) { - } - } else if (virtual_page_id == flushed_page_virtual_id_) { - page_id = flushed_page_id_; - } else if (virtual_page_id == end_page_virtual_id) { - page_id = end_page_id_; - } else { // virtual_page_id < end_page_virtual_id - if (OB_FAIL(wbp_->get_page_id_by_virtual_id(fd_, virtual_page_id, flushed_page_id_, page_id))) { - } - } - - return ret; -} - -// output the last page to be flushed -int ObSharedNothingTmpFile::get_flush_end_page_id_(uint32_t& flush_end_page_id, const bool need_flush_tail) const -{ - int ret = OB_SUCCESS; - const int64_t INVALID_PAGE_ID = ObTmpFileGlobal::INVALID_PAGE_ID; - flush_end_page_id = INVALID_PAGE_ID; - if (file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE == 0) { - flush_end_page_id = INVALID_PAGE_ID; - } else { // determined whether to flush last page based on flag if last page is not full - flush_end_page_id = need_flush_tail ? INVALID_PAGE_ID : end_page_id_; - } - - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_shared_nothing_tmp_file.h b/src/storage/tmp_file/ob_shared_nothing_tmp_file.h deleted file mode 100644 index 1856155766..0000000000 --- a/src/storage/tmp_file/ob_shared_nothing_tmp_file.h +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "storage/tmp_file/ob_tmp_file_cache.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_tmp_file_types.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_index_cache.h" -#include "storage/blocksstable/ob_macro_block_id.h" -#include "lib/lock/ob_spin_rwlock.h" -#include "lib/lock/ob_spin_lock.h" -#include "lib/lock/ob_tc_rwlock.h" -#include "storage/tmp_file/ob_tmp_file_meta_tree.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileIOCtx; -class ObTmpFileBlockPageBitmap; -class ObTmpFileBlockManager; -class ObTmpFileEvictionManager; -class ObTmpFileFlushPriorityManager; -class ObTmpFileFlushInfo; -class ObTmpFileFlushTask; -class ObTmpFilePageCacheController; -class ObTmpFileTreeFlushContext; -class ObTmpFileDataFlushContext; - -//for virtual table show -class ObSNTmpFileInfo final : public ObTmpFileInfo -{ -public: - ObSNTmpFileInfo() : - ObTmpFileInfo(), - meta_tree_epoch_(0), - meta_tree_level_cnt_(0), - meta_size_(0), - cached_meta_page_num_(0), - write_back_meta_page_num_(0), - all_type_page_flush_cnt_(0) {} - virtual ~ObSNTmpFileInfo() { reset(); } - virtual void reset() override; -public: - int64_t meta_tree_epoch_; - int64_t meta_tree_level_cnt_; - int64_t meta_size_; - int64_t cached_meta_page_num_; - int64_t write_back_meta_page_num_; - int64_t all_type_page_flush_cnt_; - INHERIT_TO_STRING_KV("ObTmpFileInfo", ObTmpFileInfo, - K(meta_tree_epoch_), - K(meta_tree_level_cnt_), K(meta_size_), K(cached_meta_page_num_), - K(write_back_meta_page_num_), K(all_type_page_flush_cnt_)); -}; - -class ObSharedNothingTmpFile final -{ -public: - int delete_file(); - int seal(); - int aio_pread(ObTmpFileIOCtx &io_ctx); - int aio_write(ObTmpFileIOCtx &io_ctx); - // truncate offset is open interval - - struct ObTmpFileNode : public ObDLinkBase - { - ObTmpFileNode(ObSharedNothingTmpFile &file) : file_(file) {} - ObSharedNothingTmpFile &file_; - }; - - bool can_remove(); - bool is_deleting(); - bool is_flushing(); - - int64_t get_file_size(); - void update_read_offset(int64_t read_offset); - int64_t get_dirty_data_page_size_with_lock(); - - OB_INLINE int64_t get_fd() const { return fd_; } - OB_INLINE int64_t get_dir_id() const { return dir_id_; } - OB_INLINE void inc_ref_cnt() { ATOMIC_INC(&ref_cnt_); } - OB_INLINE void dec_ref_cnt() { ATOMIC_AAF(&ref_cnt_, -1); } - OB_INLINE void dec_ref_cnt(int64_t &ref_cnt) - { - ref_cnt = ATOMIC_AAF(&ref_cnt_, -1); - } - OB_INLINE int64_t get_ref_cnt() const { return ATOMIC_LOAD(&ref_cnt_); } - OB_INLINE void set_data_page_flush_level(int64_t data_page_flush_level) - { - data_page_flush_level_ = data_page_flush_level; - } - OB_INLINE int64_t get_data_page_flush_level() const { return data_page_flush_level_; } - OB_INLINE ObTmpFileNode *get_data_flush_node() { return &data_flush_node_; } - int reinsert_data_flush_node(); - int remove_data_flush_node(); - - // for virtual table - void set_read_stats_vars(const ObTmpFileIOCtx &ctx, const int64_t read_size); - void set_write_stats_vars(const ObTmpFileIOCtx &ctx); - - struct InnerFlushInfo - { - public: - InnerFlushInfo(); - ~InnerFlushInfo() { reset(); } - void reset(); - bool has_data() const { return flush_data_page_num_ > 0; } - bool has_meta() const { return !flush_meta_page_array_.empty(); } - int init_by_tmp_file_flush_info(const ObTmpFileFlushInfo& flush_info); - TO_STRING_KV(K(flush_data_page_disk_begin_id_), K(flush_data_page_num_), K(flush_virtual_page_id_), K(file_size_), - K(flush_meta_page_array_)); - public: - bool update_meta_data_done_; - // information for updating data - int64_t flush_data_page_disk_begin_id_; // record begin page id in the macro block, for updating meta tree item - int64_t flush_data_page_num_; - int64_t flush_virtual_page_id_; // record virtual_page_id while copying data, pass to meta tree while inserting items - int64_t file_size_; // if file_size > 0, it means the last page is in flushing - // information for updating meta tree - ObArray flush_meta_page_array_; - }; - - struct InnerFlushContext - { - InnerFlushContext(); - void reset(); - int update_finished_continuous_flush_info_num(const bool is_meta, const int64_t end_pos); - bool is_all_finished() const { return is_data_finished() && is_meta_finished(); } - bool is_data_finished() const - { - return data_flush_infos_.size() == data_finished_continuous_flush_info_num_; - } - bool is_meta_finished() const - { - return meta_flush_infos_.size() == meta_finished_continuous_flush_info_num_; - } - bool is_flushing() const - { - return !data_flush_infos_.empty() || !meta_flush_infos_.empty(); - } - TO_STRING_KV(K(flush_seq_), K(data_flush_infos_.size()), K(meta_flush_infos_.size()), - K(data_finished_continuous_flush_info_num_), - K(meta_finished_continuous_flush_info_num_), - K(need_to_wait_for_the_previous_data_flush_req_to_complete_), - K(need_to_wait_for_the_previous_meta_flush_req_to_complete_)); - int64_t flush_seq_; - int64_t data_finished_continuous_flush_info_num_; - int64_t meta_finished_continuous_flush_info_num_; - ObArray data_flush_infos_; - ObArray meta_flush_infos_; - bool need_to_wait_for_the_previous_data_flush_req_to_complete_; - bool need_to_wait_for_the_previous_meta_flush_req_to_complete_; - }; - - ObSharedNothingTmpFile(); - ~ObSharedNothingTmpFile(); - int init(const int64_t fd, const int64_t dir_id, - ObTmpFileBlockManager *block_manager, - ObIAllocator *callback_allocator, - ObIAllocator *wbp_index_cache_allocator, - ObIAllocator *wbp_index_cache_bkt_allocator, - ObTmpFilePageCacheController *page_cache_controller, - const char* label); - void reset(); - int release_resource(); - int evict_data_pages(const int64_t expected_evict_page_num, - int64_t &actual_evict_page_num, - int64_t &remain_flushed_page_num); - int evict_meta_pages(const int64_t expected_evict_page_num, - int64_t &actual_evict_page_num); - // truncate offset is open interval - int truncate(const int64_t truncate_offset); - - // ATTENTION!!! - // Currently, K(tmp_file) is used to print the ObSharedNothingTmpFile structure without holding - // the file lock. Before adding the print field, make sure it is thread-safe. - TO_STRING_KV(K(is_inited_), K(dir_id_), K(fd_), - K(is_deleting_), K(is_sealed_), - K(ref_cnt_), K(truncated_offset_), K(read_offset_), - K(file_size_), - K(cached_page_nums_), K(write_back_data_page_num_), - K(begin_page_id_), K(begin_page_virtual_id_), - K(end_page_id_), - K(data_page_flush_level_), - KP(data_flush_node_.get_next()), - KP(wbp_), KP(flush_prio_mgr_), KP(&page_idx_cache_), KP(callback_allocator_), - K(trace_id_), K(birth_ts_), K(label_), - K(write_req_cnt_), K(unaligned_write_req_cnt_), - K(write_persisted_tail_page_cnt_), K(lack_page_cnt_), K(last_modify_ts_), - K(read_req_cnt_), K(unaligned_read_req_cnt_), - K(total_truncated_page_read_cnt_), K(total_uncached_page_read_cnt_), - K(total_kv_cache_page_read_cnt_), K(total_wbp_page_read_cnt_), - K(truncated_page_read_hits_), K(uncached_page_read_hits_), - K(kv_cache_page_read_hits_), K(wbp_page_read_hits_), - K(total_read_size_), K(last_access_ts_), - K(flushed_data_page_num_), - K(flushed_page_id_), K(flushed_page_virtual_id_), - K(meta_page_flush_level_), KP(meta_flush_node_.get_next()), - K(is_in_data_eviction_list_), K(is_in_meta_eviction_list_), - KP(data_eviction_node_.get_next()), - KP(meta_eviction_node_.get_next())); - - // for flush - int update_meta_after_flush(const int64_t info_idx, const bool is_meta, bool &reset_ctx); - int generate_data_flush_info(ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileDataFlushContext &data_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail); - int generate_meta_flush_info(ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileTreeFlushContext &meta_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail); - int insert_meta_tree_item(const ObTmpFileFlushInfo &info, int64_t block_index); - int copy_finish(); - - int remove_meta_flush_node(); - int reinsert_meta_flush_node(); - bool is_in_meta_flush_list(); - OB_INLINE ObTmpFileNode *get_meta_flush_node() { return &meta_flush_node_; } - OB_INLINE ObTmpFileNode &get_data_eviction_node() { return data_eviction_node_; } - OB_INLINE ObTmpFileNode &get_meta_eviction_node() { return meta_eviction_node_; } - OB_INLINE const ObTmpFileNode &get_data_eviction_node() const { return data_eviction_node_; } - OB_INLINE const ObTmpFileNode &get_meta_eviction_node() const { return meta_eviction_node_; } - - OB_INLINE void set_meta_page_flush_level(int64_t meta_page_flush_level) - { - meta_page_flush_level_ = meta_page_flush_level; - } - OB_INLINE int64_t get_meta_page_flush_level() const { return meta_page_flush_level_; } - void get_dirty_meta_page_num(int64_t &non_rightmost_dirty_page_num, int64_t &rightmost_dirty_page_num) const; - void get_dirty_meta_page_num_with_lock(int64_t &non_rightmost_dirty_page_num, int64_t &rightmost_dirty_page_num); - int copy_info_for_virtual_table(ObTmpFileInfo &tmp_file_info); - -private: - int init_io_state_(const int64_t dir_id, - const int64_t fd, - ObTmpWriteBufferPool *wbp, - ObTmpFileFlushPriorityManager *flush_prio_mgr, - ObIAllocator *callback_allocator, - ObIAllocator *wbp_index_cache_allocator, - ObIAllocator *wbp_index_cache_bkt_allocator, - const char* label); - void reset_io_state_(); - - int truncate_io_(const int64_t truncate_offset); - - int inner_read_truncated_part_(ObTmpFileIOCtx &io_ctx); - int inner_read_from_wbp_(ObTmpFileIOCtx &io_ctx); - - int inner_write_(ObTmpFileIOCtx &io_ctx); - int inner_fill_tail_page_(ObTmpFileIOCtx &io_ctx); - int inner_write_continuous_pages_(ObTmpFileIOCtx &io_ctx); - int alloc_and_write_pages_(const ObTmpFileIOCtx &io_ctx, - ObArray &alloced_page_id, - int64_t &actual_write_size); - - int truncate_cached_pages_(const int64_t truncate_offset, const int64_t wbp_begin_offset); - - // for virtual table - void inner_set_read_stats_vars_(const ObTmpFileIOCtx &ctx, const int64_t read_size); - void inner_set_write_stats_vars_(const ObTmpFileIOCtx &ctx); - - int64_t cal_wbp_begin_offset_() const; - int reinsert_data_flush_node_(); - int insert_or_update_data_flush_node_(); - - OB_INLINE bool has_unfinished_page_() const { return file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE != 0; } - OB_INLINE int64_t get_page_begin_offset_(const int64_t offset) const - { - return common::lower_align(offset, ObTmpFileGlobal::ALLOC_PAGE_SIZE); - } - OB_INLINE int64_t get_page_end_offset_(const int64_t offset) const - { - return common::upper_align(offset, ObTmpFileGlobal::ALLOC_PAGE_SIZE); - } - OB_INLINE int64_t get_page_begin_offset_by_virtual_id_(const int64_t virtual_page_id) const - { - return virtual_page_id * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - OB_INLINE int64_t get_page_end_offset_by_virtual_id_(const int64_t virtual_page_id) const - { - return (virtual_page_id + 1) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - OB_INLINE int64_t get_page_virtual_id_(const int64_t offset, const bool is_open_interval) const - { - return is_open_interval ? - common::upper_align(offset, ObTmpFileGlobal::ALLOC_PAGE_SIZE) / ObTmpFileGlobal::ALLOC_PAGE_SIZE - 1 : - offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - OB_INLINE int64_t get_end_page_virtual_id_() const - { - return cached_page_nums_ == 0 ? - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID : - get_page_virtual_id_(file_size_, true /*is_open_interval*/); - } - OB_INLINE int64_t get_offset_in_page_(const int64_t offset) const - { - return offset % ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - - OB_INLINE int64_t get_offset_in_block_(int64_t file_offset) const - { - int64_t ret = 0; - ret = file_offset % ObTmpFileGlobal::SN_BLOCK_SIZE; - return ret; - } - - bool is_inited_; - - int64_t dir_id_; - int64_t fd_; - bool is_deleting_; - bool is_sealed_; - int64_t ref_cnt_; - int64_t truncated_offset_; // read data befor truncated_offset will be set as 0 - int64_t read_offset_; // read offset is on the entire file - int64_t file_size_; // has written size of this file - int64_t cached_page_nums_; // page nums in write buffer pool - int64_t write_back_data_page_num_; - uint32_t begin_page_id_; // the first page index in write buffer pool - int64_t begin_page_virtual_id_; - uint32_t end_page_id_; // the last page index in write buffer pool - int64_t diag_log_print_cnt_; // print diagnosis log every PRINT_LOG_FILE_SIZE - int64_t data_page_flush_level_; - ObTmpFileNode data_flush_node_; - common::TCRWLock meta_lock_; // handle conflicts between writing and reading meta tree and meta data of file - ObSpinLock stat_lock_; // for updating vtable write info/read info - ObSpinLock multi_write_lock_; // handle conflicts between multiple writes - ObSpinLock last_page_lock_; // handle conflicts between writing and evicting for last page - ObTmpWriteBufferPool *wbp_; - ObTmpFileFlushPriorityManager *flush_prio_mgr_; - ObTmpFileWBPIndexCache page_idx_cache_; - ObIAllocator *callback_allocator_; - /********for virtual table begin********/ - // common info - common::ObCurTraceId::TraceId trace_id_; - int64_t birth_ts_; - ObFixedLengthString label_; - // write info - int64_t write_req_cnt_; - int64_t unaligned_write_req_cnt_; - int64_t write_persisted_tail_page_cnt_; - int64_t lack_page_cnt_; - int64_t last_modify_ts_; - // read info - int64_t read_req_cnt_; - int64_t unaligned_read_req_cnt_; - int64_t total_truncated_page_read_cnt_; - int64_t total_kv_cache_page_read_cnt_; - int64_t total_uncached_page_read_cnt_; - int64_t total_wbp_page_read_cnt_; - int64_t truncated_page_read_hits_; - int64_t kv_cache_page_read_hits_; - int64_t uncached_page_read_hits_; - int64_t wbp_page_read_hits_; - int64_t total_read_size_; - int64_t last_access_ts_; - /********for virtual table end********/ - - int inner_read_from_disk_(const int64_t expected_read_disk_size, ObTmpFileIOCtx &io_ctx); - int inner_direct_read_from_block_(const int64_t block_index, - const int64_t begin_read_offset_in_block, const int64_t end_read_offset_in_block, - ObTmpFileIOCtx &io_ctx); - int inner_cached_read_from_block_(const int64_t block_index, - const int64_t begin_read_offset_in_block, const int64_t end_read_offset_in_block, - ObTmpFileIOCtx &io_ctx, - ObTmpFileInfo::ObTmpFileReadInfo &read_stat); - int inner_cached_read_from_block_with_prefetch_(const int64_t block_index, - const int64_t begin_read_offset_in_block, - const int64_t end_offset_in_block, - const int64_t user_read_size, - ObTmpFileIOCtx &io_ctx, - ObTmpFileInfo::ObTmpFileReadInfo &read_stat); - int collect_pages_in_block_(const int64_t block_index, - const int64_t begin_page_idx_in_block, - const int64_t end_page_idx_in_block, - ObTmpFileBlockPageBitmap &bitmap, - ObIArray &page_value_handles); - int inner_read_continuous_cached_pages_(const int64_t begin_read_offset_in_block, - const int64_t end_read_offset_in_block, - const ObArray &page_value_handles, - const int64_t start_array_idx, - ObTmpFileIOCtx &io_ctx); - int inner_read_continuous_uncached_pages_(const int64_t block_index, - const int64_t begin_io_read_offset, - const int64_t end_io_read_offset, - const int64_t user_read_size, - ObTmpFileIOCtx &io_ctx); - - int swap_page_to_disk_(const ObTmpFileIOCtx &io_ctx); - int load_disk_tail_page_and_rewrite_(ObTmpFileIOCtx &io_ctx); - int append_write_memory_tail_page_(ObTmpFileIOCtx &io_ctx); - - int truncate_the_first_wbp_page_(); - int truncate_persistent_pages_(const int64_t truncate_offset); - - int collect_flush_data_page_id_(ObTmpFileFlushTask &flush_task, ObTmpFileFlushInfo &info, - ObTmpFileDataFlushContext &data_flush_context, - const uint32_t copy_begin_page_id, const int64_t copy_begin_page_virtual_id, - const uint32_t copy_end_page_id, const int64_t flush_sequence, const bool need_flush_tail); - int cal_end_position_(ObArray &flush_infos, - const int64_t start_pos, - int64_t &end_pos, - int64_t &flushed_data_page_num); - int cal_next_flush_page_id_from_flush_ctx_or_file_(const ObTmpFileDataFlushContext &data_flush_context, - uint32_t &next_flush_page_id, - int64_t &next_flush_page_virtual_id); - int64_t get_dirty_data_page_size_() const; - int get_next_flush_page_id_(uint32_t& next_flush_page_id, int64_t& next_flush_page_virtual_id) const; - int get_flush_end_page_id_(uint32_t& flush_end_page_id, const bool need_flush_tail) const; - int get_physical_page_id_in_wbp_(const int64_t virtual_page_id, uint32_t& page_id) const ; - int remove_useless_page_in_data_flush_infos_(const int64_t start_pos, - const int64_t end_pos, - const int64_t flushed_data_page_num, - int64_t &new_start_pos, - int64_t &new_flushed_data_page_num); - int update_file_meta_after_flush_(const int64_t start_pos, - const int64_t end_pos, - const int64_t flushed_data_page_num); - int update_meta_tree_after_flush_(const int64_t start_pos, const int64_t end_pos); - - int generate_data_flush_info_(ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileDataFlushContext &data_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail); - int generate_meta_flush_info_(ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &info, - ObTmpFileTreeFlushContext &meta_flush_context, - const int64_t flush_sequence, - const bool need_flush_tail); - int reinsert_meta_flush_node_(); - int insert_or_update_meta_flush_node_(); - bool is_flushing_(); - - int inner_seal_(); - int inner_delete_file_(); - - ObTmpFileBlockManager *tmp_file_block_manager_; - ObTmpFilePageCacheController *page_cache_controller_; - ObTmpFileEvictionManager *eviction_mgr_; - bool is_in_data_eviction_list_; - bool is_in_meta_eviction_list_; - int64_t meta_page_flush_level_; - int64_t flushed_data_page_num_; // equal to the page num between [begin_page_id_, flushed_page_id_] in wbp - uint32_t flushed_page_id_; // the last flushed page index in write buffer pool. - // specifically, if flushed_page_id_ == end_page_id_, - // it means the last page has been flushed. However, - // the last page might be appending written after flushing. - // thus, in this case, whether "flushed_page_id_" page in wbp is flushed - // needs to be checked with page status (with some get functions). - int64_t flushed_page_virtual_id_; - ObSharedNothingTmpFileMetaTree meta_tree_; - ObTmpFileNode meta_flush_node_; - ObTmpFileNode data_eviction_node_; - ObTmpFileNode meta_eviction_node_; - SpinRWLock truncate_lock_; // handle conflicts between truncate and flushing - InnerFlushContext inner_flush_ctx_; // file-level flush context - -}; - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_block_manager.cpp b/src/storage/tmp_file/ob_tmp_file_block_manager.cpp deleted file mode 100644 index 6ae35fbd1a..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_block_manager.cpp +++ /dev/null @@ -1,821 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_block_manager.h" -#include "storage/tmp_file/ob_tmp_file_cache.h" -namespace oceanbase -{ -using namespace storage; -using namespace share; - -namespace tmp_file -{ -//-----------------------ObTmpFileBlockPageBitmapIterator----------------------- -int ObTmpFileBlockPageBitmapIterator::init(const ObTmpFileBlockPageBitmap *bitmap, - const int64_t start_idx, int64_t end_idx) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_ISNULL(bitmap) || - OB_UNLIKELY(start_idx < 0 || end_idx < 0 || start_idx > end_idx || - end_idx >= ObTmpFileBlockPageBitmap::get_capacity())) { - ret = OB_INVALID_ARGUMENT; - } else { - is_inited_ = true; - bitmap_ = bitmap; - cur_idx_ = start_idx; - end_idx_ = end_idx; - } - return ret; -} - -void ObTmpFileBlockPageBitmapIterator::reset() -{ - bitmap_ = nullptr; - is_inited_ = false; - cur_idx_ = OB_INVALID_INDEX; - end_idx_ = OB_INVALID_INDEX; -} - -int ObTmpFileBlockPageBitmapIterator::next_range(bool &value, int64_t &start_page_id, int64_t &end_page_id) -{ - int ret = OB_SUCCESS; - start_page_id = OB_INVALID_INDEX; - end_page_id = OB_INVALID_INDEX; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (has_next()) { - start_page_id = cur_idx_; - if (OB_FAIL(bitmap_->get_value(cur_idx_++, value))) { - } else { - while(cur_idx_ <= end_idx_ && OB_SUCC(ret)) { - bool cur_value = false; - if (OB_FAIL(bitmap_->get_value(cur_idx_, cur_value))) { - } else if (cur_value != value) { - break; - } else { - cur_idx_ += 1; - } - } - end_page_id = cur_idx_ - 1; - } - } else { - ret = OB_ITER_END; - } - return ret; -} - -//---------------------------ObTmpFileBlockPageBitmap--------------------------- -int ObTmpFileBlockPageBitmap::get_value(const int64_t offset, bool &value) const -{ - int ret = OB_SUCCESS; - const int64_t capacity = PAGE_CAPACITY; - - if (OB_UNLIKELY(capacity <= offset || offset < 0)) { - ret = OB_INVALID_ARGUMENT; - } else { - value = (bitmap_[offset / 8] & (1 << (offset % 8))) != 0; - } - return ret; -} - -int ObTmpFileBlockPageBitmap::set_bitmap(const int64_t offset, const bool value) -{ - int ret = OB_SUCCESS; - const int64_t capacity = PAGE_CAPACITY; - if (OB_UNLIKELY(capacity <= offset || offset < 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (value) { - bitmap_[offset / 8] |= (1 <<(offset % 8)); - } else { - bitmap_[offset / 8] &= ~(1 <<(offset % 8)); - } - return ret; -} - -int ObTmpFileBlockPageBitmap::set_bitmap_batch(const int64_t offset, const int64_t count, const bool value) -{ - int ret = OB_SUCCESS; - const int64_t capacity = PAGE_CAPACITY; - uint8_t start_byte_pos = offset / 8; - uint8_t end_byte_pos = (offset + count - 1) / 8; - uint8_t start_bit_pos = offset % 8; - uint8_t end_bit_pos = (offset + count - 1) % 8; - if (OB_UNLIKELY(capacity < (offset + count) || count <= 0 || offset < 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (start_byte_pos == end_byte_pos) { - // only one byte - uint8_t mask = ((1 << (end_bit_pos + 1)) - 1) & ~((1 << start_bit_pos) - 1); - if (value) { - bitmap_[start_byte_pos] |= mask; - } else { - bitmap_[start_byte_pos] &= ~mask; - } - } else { - uint8_t start_mask = ~((1 << start_bit_pos) - 1); - uint8_t end_mask = (1 << (end_bit_pos + 1)) - 1; - if (value) { - bitmap_[start_byte_pos] |= start_mask; - bitmap_[end_byte_pos] |= end_mask; - } else { - bitmap_[start_byte_pos] &= ~start_mask; - bitmap_[end_byte_pos] &= ~end_mask; - } - for (uint8_t i = start_byte_pos + 1; i < end_byte_pos; ++i) { - bitmap_[i] = value ? (1 << 8) - 1 : 0; - } - } - - return ret; -} - -int ObTmpFileBlockPageBitmap::is_all_true(const int64_t start, const int64_t end, bool &is_all_true) const -{ - int ret = OB_SUCCESS; - const int64_t capacity = PAGE_CAPACITY; - const uint8_t start_byte_pos = start / 8; - const uint8_t end_byte_pos = end / 8; - const uint8_t start_bit_pos = start % 8; - const uint8_t end_bit_pos = end % 8; - is_all_true = false; - - if (OB_UNLIKELY(start > end || start < 0 || end >= capacity)) { - ret = OB_INVALID_ARGUMENT; - } else if (start_byte_pos == end_byte_pos) { - // only one byte - uint8_t mask = ((1 << (end_bit_pos + 1)) - 1) & ~((1 << start_bit_pos) - 1); - is_all_true = (bitmap_[start_byte_pos] & mask) == mask; - } else { - uint8_t start_mask = ~((1 << start_bit_pos) - 1); - uint8_t end_mask = (1 << (end_bit_pos + 1)) - 1; - - if ((bitmap_[start_byte_pos] & start_mask) != start_mask || - (bitmap_[end_byte_pos] & end_mask) != end_mask) { - is_all_true = false; - } else { - is_all_true = true; - for (int64_t i = start_byte_pos + 1; is_all_true && i < end_byte_pos; ++i) { - if (bitmap_[i] != 0XFF) { - is_all_true = false; - } - } - } - } - - return ret; -} - -int ObTmpFileBlockPageBitmap::is_all_false(const int64_t start, const int64_t end, bool &is_all_false) const -{ - int ret = OB_SUCCESS; - const int64_t capacity = PAGE_CAPACITY; - const uint8_t start_byte_pos = start / 8; - const uint8_t end_byte_pos = end / 8; - const uint8_t start_bit_pos = start % 8; - const uint8_t end_bit_pos = end % 8; - is_all_false = false; - - if (OB_UNLIKELY(start > end || start < 0 || end >= capacity)) { - is_all_false = false; - ret = OB_INVALID_ARGUMENT; - } else if (start_byte_pos == end_byte_pos) { - // only one byte - uint8_t mask = ((1 << (end_bit_pos + 1)) - 1) & ~((1 << start_bit_pos) - 1); - is_all_false = (bitmap_[start_byte_pos] & mask) == 0; - } else { - uint8_t start_mask = ~((1 << start_bit_pos) - 1); - uint8_t end_mask = (1 << (end_bit_pos + 1)) - 1; - - if ((bitmap_[start_byte_pos] & start_mask) != 0 || - (bitmap_[end_byte_pos] & end_mask) != 0) { - is_all_false = false; - } else { - is_all_false = true; - for (int64_t i = start_byte_pos + 1; is_all_false && i < end_byte_pos; ++i) { - if (bitmap_[i] != 0) { - is_all_false = false; - } - } - } - } - - return ret; -} - -int ObTmpFileBlockPageBitmap::is_all_true(bool &b_ret) const -{ - return is_all_true(0, PAGE_CAPACITY - 1, b_ret); -} - -int ObTmpFileBlockPageBitmap::is_all_false(bool &b_ret) const -{ - return is_all_false(0, PAGE_CAPACITY - 1, b_ret); -} - -int64_t ObTmpFileBlockPageBitmap::to_string(char* buf, const int64_t buf_len) const -{ - int64_t pos = 0; - J_OBJ_START(); - for (int i = 0; i < PAGE_BYTE_CAPACITY / sizeof(uint64_t); ++i) { - int64_t offset = i * sizeof(uint64_t); - if (i > 0) { - J_COMMA(); - } - char bitmap_id[11]; - snprintf(bitmap_id, sizeof(bitmap_id), "bitmap_[%d]", i); - J_KV(bitmap_id, *(reinterpret_cast(bitmap_ + offset))); - } - J_OBJ_END(); - return pos; -} -//-----------------------ObTmpFileBlock----------------------- -ObTmpFileBlock::~ObTmpFileBlock() -{ - reset(); -} - -int ObTmpFileBlock::reset() -{ - int ret = OB_SUCCESS; - if (is_valid() && BlockState::ON_DISK == block_state_ && OB_FAIL(OB_SERVER_BLOCK_MGR.dec_ref(macro_block_id_))) { - LOG_ERROR("failed to dec macro block ref cnt", KR(ret), KPC(this)); - } else { - block_state_ = BlockState::INVALID; - page_bitmap_.reset(); - block_index_ = ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - macro_block_id_.reset(); - ref_cnt_ = 0; - } - return ret; -} - -int ObTmpFileBlock::init_block(const int64_t block_index, - const int64_t begin_page_id, const int64_t page_num) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - bool use_released_pages = false; - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX == block_index)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(page_num <= 0 || begin_page_id < 0 || - begin_page_id + page_num > ObTmpFileGlobal::BLOCK_PAGE_NUMS)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(block_index_ != ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX)) { - ret = OB_ERR_UNEXPECTED; - } else if (block_state_ != BlockState::INVALID) { - ret = OB_OP_NOT_ALLOW; - } else if (OB_FAIL(page_bitmap_.is_all_false(begin_page_id, begin_page_id + page_num - 1, use_released_pages))) { - } else if (OB_UNLIKELY(!use_released_pages)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(page_bitmap_.set_bitmap_batch(begin_page_id, page_num, true))) { - } else { - block_index_ = block_index; - block_state_ = BlockState::IN_MEMORY; - } - return ret; -} - -int ObTmpFileBlock::write_back_start() -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (block_state_ != BlockState::IN_MEMORY && block_state_ != BlockState::WRITE_BACK) { - ret = OB_OP_NOT_ALLOW; - } else { - block_state_ = BlockState::WRITE_BACK; - } - return ret; -} - -int ObTmpFileBlock::write_back_failed() -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (block_state_ != BlockState::WRITE_BACK) { - ret = OB_OP_NOT_ALLOW; - } else { - block_state_ = BlockState::IN_MEMORY; - } - return ret; -} - -int ObTmpFileBlock::write_back_succ(blocksstable::MacroBlockId macro_block_id) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (OB_UNLIKELY(!macro_block_id.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (block_state_ != BlockState::WRITE_BACK) { - ret = OB_OP_NOT_ALLOW; - } else if (OB_FAIL(OB_SERVER_BLOCK_MGR.inc_ref(macro_block_id))) { - } else { - macro_block_id_ = macro_block_id; - block_state_ = BlockState::ON_DISK; - } - return ret; -} - -int ObTmpFileBlock::release_pages(const int64_t begin_page_id, const int64_t page_num) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - bool release_allocated_page = false; - if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(page_num <= 0 || begin_page_id < 0 || - begin_page_id + page_num > ObTmpFileGlobal::BLOCK_PAGE_NUMS)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(page_bitmap_.is_all_true(begin_page_id, begin_page_id + page_num - 1, release_allocated_page))) { - } else if (OB_UNLIKELY(!release_allocated_page)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(page_bitmap_.set_bitmap_batch(begin_page_id, page_num, false))) { - } - return ret; -} - -int ObTmpFileBlock::get_page_usage(int64_t &page_num) const -{ - int ret = OB_SUCCESS; - SpinRLockGuard guard(lock_); - page_num = 0; - if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else { - for (int i = 0; OB_SUCC(ret) && i < ObTmpFileBlockPageBitmap::get_capacity(); ++i) { - bool value = false; - if (OB_FAIL(page_bitmap_.get_value(i, value))) { - } else if (value) { - page_num++; - } - } // end for - } - return ret; -} - -int ObTmpFileBlock::inc_ref_cnt() -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - - if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else { - ref_cnt_++; - } - - return ret; -} - -int ObTmpFileBlock::dec_ref_cnt(int64_t &ref_cnt) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - - if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(ref_cnt_ <= 0)) { - ret = OB_ERR_UNEXPECTED; - } else { - ref_cnt_ -= 1; - ref_cnt = ref_cnt_; - } - - return ret; -} - -bool ObTmpFileBlock::on_disk() const -{ - SpinRLockGuard guard(lock_); - return BlockState::ON_DISK == block_state_; -} - -int ObTmpFileBlock::can_remove(bool &can_remove) const -{ - int ret = OB_SUCCESS; - SpinRLockGuard guard(lock_); - - can_remove = false; - bool is_all_page_released = false; - if (OB_FAIL(page_bitmap_.is_all_false(is_all_page_released))) { - } else { - can_remove = is_all_page_released && BlockState::WRITE_BACK != block_state_; - } - return ret; -} - -blocksstable::MacroBlockId ObTmpFileBlock::get_macro_block_id() const -{ - SpinRLockGuard guard(lock_); - return macro_block_id_; -} - -int64_t ObTmpFileBlock::get_block_index() const -{ - SpinRLockGuard guard(lock_); - return block_index_; -} -//-----------------------ObTmpFileBlockHandle----------------------- - -ObTmpFileBlockHandle::ObTmpFileBlockHandle(ObTmpFileBlock *block, ObTmpFileBlockManager *tmp_file_blk_mgr) - : ptr_(nullptr), tmp_file_blk_mgr_(nullptr) -{ - if (nullptr != block && nullptr != tmp_file_blk_mgr) { - ptr_ = block; - tmp_file_blk_mgr_ = tmp_file_blk_mgr; - ptr_->inc_ref_cnt(); - } -} - -ObTmpFileBlockHandle::ObTmpFileBlockHandle(const ObTmpFileBlockHandle &handle) - : ptr_(nullptr), tmp_file_blk_mgr_(nullptr) -{ - operator=(handle); -} - -ObTmpFileBlockHandle & ObTmpFileBlockHandle::operator=(const ObTmpFileBlockHandle &other) -{ - if (other.ptr_ != ptr_) { - reset(); - ptr_ = other.ptr_; - tmp_file_blk_mgr_ = other.tmp_file_blk_mgr_; - if (is_inited()) { - ptr_->inc_ref_cnt(); - } - } - return *this; -} - -void ObTmpFileBlockHandle::reset() -{ - int ret = OB_SUCCESS; - if (is_inited()) { - int64_t cur_ref_cnt = -1; - int64_t block_index = ptr_->get_block_index(); - if (OB_FAIL(ptr_->dec_ref_cnt(cur_ref_cnt))) { - } else if (0 == cur_ref_cnt) { - ptr_->reset(); - tmp_file_blk_mgr_->get_block_allocator().free(ptr_); - } - ptr_ = nullptr; - } -} - -int ObTmpFileBlockHandle::init(ObTmpFileBlock *block, ObTmpFileBlockManager *tmp_file_blk_mgr) -{ - int ret = OB_SUCCESS; - - if (is_inited()) { - ret = OB_INIT_TWICE; - } else if (OB_ISNULL(block) || OB_ISNULL(tmp_file_blk_mgr)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(block->inc_ref_cnt())) { - } else { - ptr_ = block; - tmp_file_blk_mgr_ = tmp_file_blk_mgr; - } - - return ret; -} - -//-----------------------ObTmpFileBlockManager----------------------- -ObTmpFileBlockManager::ObTmpFileBlockManager() : - is_inited_(false), - used_page_num_(0), - physical_block_num_(0), - block_index_generator_(0), - block_map_(), - block_allocator_(), - stat_lock_() - {} - -ObTmpFileBlockManager::~ObTmpFileBlockManager() -{ - destroy(); -} - -void ObTmpFileBlockManager::destroy() -{ - is_inited_ = false; - used_page_num_ = 0; - physical_block_num_ = 0; - block_index_generator_ = 0; - block_map_.destroy(); - block_allocator_.reset(); -} - -int ObTmpFileBlockManager::init() -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(is_inited_)) { - ret = OB_INIT_TWICE; - } else if (OB_FAIL(block_map_.init("TmpFileBlkMgr"))) { - } else if (OB_FAIL(block_allocator_.init(common::OB_MALLOC_MIDDLE_BLOCK_SIZE, - ObModIds::OB_TMP_BLOCK_MANAGER, INT64_MAX))) { - } else { - block_allocator_.set_attr(ObMemAttr("TmpFileBlk")); - is_inited_ = true; - } - - return ret; -} - -int ObTmpFileBlockManager::create_tmp_file_block(const int64_t begin_page_id, const int64_t page_num, - int64_t &block_index) -{ - int ret = OB_SUCCESS; - ObTmpFileBlockHandle handle; - ObTmpFileBlock* blk = nullptr; - const uint64_t blk_size = sizeof(ObTmpFileBlock); - void *buf = nullptr; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_ISNULL(buf = block_allocator_.alloc(blk_size, lib::ObMemAttr("TmpFileBlk")))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (FALSE_IT(blk = new (buf) ObTmpFileBlock())) { - } else if (FALSE_IT(block_index = ATOMIC_AAF(&block_index_generator_, 1))) { - } else if (OB_FAIL(blk->init_block(block_index, begin_page_id, page_num))) { - } else if (OB_FAIL(handle.init(blk, this))) { - } else { - if (OB_FAIL(block_map_.insert(ObTmpFileBlockKey(block_index), handle))) { - } - } - - if (OB_FAIL(ret) && OB_NOT_NULL(blk)) { - blk->~ObTmpFileBlock(); - block_allocator_.free(blk); - blk = nullptr; - } - - return ret; -} - -int ObTmpFileBlockManager::write_back_start(const int64_t block_index) -{ - int ret = OB_SUCCESS; - ObTmpFileBlockHandle handle; - ObTmpFileBlock *blk = nullptr; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.get(ObTmpFileBlockKey(block_index), handle))) { - } else if (OB_ISNULL(blk = handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(blk->write_back_start())) { - } - - return ret; -} - -int ObTmpFileBlockManager::write_back_failed(const int64_t block_index) -{ - int ret = OB_SUCCESS; - ObTmpFileBlockHandle handle; - ObTmpFileBlock *blk = nullptr; - bool can_remove = false; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.get(ObTmpFileBlockKey(block_index), handle))) { - } else if (OB_ISNULL(blk = handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(blk->write_back_failed())) { - } - - if (FAILEDx(handle.get()->can_remove(can_remove))) { - } else if (can_remove) { - if (OB_FAIL(remove_tmp_file_block_(block_index))) { - } - } - return ret; -} - -int ObTmpFileBlockManager::write_back_succ(const int64_t block_index, const blocksstable::MacroBlockId macro_block_id) -{ - int ret = OB_SUCCESS; - ObTmpFileBlockHandle handle; - ObTmpFileBlock *blk = nullptr; - bool can_remove = false; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.get(ObTmpFileBlockKey(block_index), handle))) { - } else if (OB_ISNULL(blk = handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else { - SpinWLockGuard guard(stat_lock_); - int64_t used_page_num = 0; - if (OB_FAIL(blk->write_back_succ(macro_block_id))) { - } else if (OB_FAIL(blk->get_page_usage(used_page_num))) { - } else { - used_page_num_ += used_page_num; - physical_block_num_ += 1; - } - } - - if (FAILEDx(handle.get()->can_remove(can_remove))) { - } else if (can_remove) { - if (OB_FAIL(remove_tmp_file_block_(block_index))) { - } - } - return ret; -} - -// if a block is released all pages in this function, -// when ObTmpFileBlockHandle destructed, the handle will remove itself from block_map -int ObTmpFileBlockManager::release_tmp_file_page(const int64_t block_index, - const int64_t begin_page_id, const int64_t page_num) -{ - int ret = OB_SUCCESS; - ObTmpFileBlockHandle handle; - bool can_remove = false; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.get(ObTmpFileBlockKey(block_index), handle))) { - } else if (OB_ISNULL(handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else{ - SpinWLockGuard guard(stat_lock_); - if (OB_FAIL(handle.get()->release_pages(begin_page_id, page_num))) { - } else if (handle.get()->on_disk()) { - used_page_num_ -= page_num; - if (used_page_num_ < 0) { - LOG_ERROR("invalid used_page_num", K(used_page_num_), K(block_index), K(begin_page_id), K(page_num), K(handle)); - } - } - } - - - if (FAILEDx(handle.get()->can_remove(can_remove))) { - } else if (can_remove) { - if (OB_FAIL(remove_tmp_file_block_(block_index))) { - } - } - - return ret; -} - -int ObTmpFileBlockManager::remove_tmp_file_block_(const int64_t block_index) -{ - int ret = OB_SUCCESS; - ObTmpFileBlock* blk = nullptr; - ObTmpFileBlockHandle handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - if (OB_FAIL(block_map_.erase(ObTmpFileBlockKey(block_index), handle))) { - if (ret != OB_ENTRY_NOT_EXIST) { - } else { - ret = OB_SUCCESS; - } - } else if (OB_UNLIKELY(nullptr == (blk = handle.get()))) { - ret = OB_ERR_UNEXPECTED; - } else { - ObTmpBlockCache::get_instance().erase(ObTmpBlockCacheKey(block_index)); - } - } - - if (OB_SUCC(ret) && OB_NOT_NULL(blk) && blk->on_disk()) { - SpinWLockGuard guard(stat_lock_); - int64_t used_page_num = 0; - if (OB_FAIL(blk->get_page_usage(used_page_num))) { - } else { - used_page_num_ -= used_page_num; - if (used_page_num != 0 || used_page_num_ < 0) { - LOG_ERROR("invalid used_page_num when removing tmp file block", K(used_page_num_), K(used_page_num), KPC(blk)); - } - physical_block_num_ -= 1; - } - } - - return ret; -} - -int ObTmpFileBlockManager::get_block_usage_stat(int64_t &used_page_num, int64_t ¯o_block_count) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - SpinRLockGuard guard(stat_lock_); - used_page_num = used_page_num_; - macro_block_count = physical_block_num_; - } - - return ret; -} - -void ObTmpFileBlockManager::print_block_usage() -{ - int ret = OB_SUCCESS; - int64_t used_page_num = 0; - int64_t block_num = 0; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(get_block_usage_stat(used_page_num, block_num))) { - } else if (OB_UNLIKELY(0 == block_num)) { - LOG_INFO("temporary file module use no blocks"); - } else { - int64_t occupied_page_num = block_num * ObTmpFileGlobal::BLOCK_PAGE_NUMS; - double disk_fragment_ratio = static_cast(used_page_num) / static_cast(occupied_page_num); - LOG_INFO("the block usage for temporary files", - K(used_page_num), K(occupied_page_num), K(block_num), K(disk_fragment_ratio)); - } -} - -int ObTmpFileBlockManager::get_macro_block_count(int64_t ¯o_block_count) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - SpinRLockGuard guard(stat_lock_); - macro_block_count = physical_block_num_; - } - return ret; -} - -int ObTmpFileBlockManager::get_macro_block_list(common::ObIArray ¯o_id_list) -{ - int ret = OB_SUCCESS; - CollectMacroBlockIdFunctor func(macro_id_list); - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.for_each(func))) { - } - - return ret; -} - -bool ObTmpFileBlockManager::CollectMacroBlockIdFunctor::operator()(const ObTmpFileBlockKey &block_index, const ObTmpFileBlockHandle &handle) -{ - int ret = OB_SUCCESS; - - if (OB_ISNULL(handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (!handle.get()->is_valid()) { - ret = OB_ERR_UNEXPECTED; - } else if (!handle.get()->on_disk()) { - // do nothing - } else if (OB_FAIL(macro_id_list_.push_back(handle.get()->get_macro_block_id()))) { - } - return OB_SUCCESS == ret; -} - -int ObTmpFileBlockManager::get_macro_block_id(const int64_t block_index, blocksstable::MacroBlockId ¯o_block_id) -{ - int ret = OB_SUCCESS; - ObTmpFileBlockHandle handle; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.get(ObTmpFileBlockKey(block_index), handle))) { - } else if (OB_ISNULL(handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!handle.get()->is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else { - macro_block_id = handle.get()->get_macro_block_id(); - } - - return ret; -} - -int ObTmpFileBlockManager::get_tmp_file_block_handle(const int64_t block_index, ObTmpFileBlockHandle &handle) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(block_map_.get(ObTmpFileBlockKey(block_index), handle))) { - } else if (OB_ISNULL(handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!handle.get()->is_valid())) { - ret = OB_ERR_UNEXPECTED; - } - - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_block_manager.h b/src/storage/tmp_file/ob_tmp_file_block_manager.h deleted file mode 100644 index 5281c8eae3..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_block_manager.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_BLOCK_MANAGER_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_BLOCK_MANAGER_H_ - -#include "storage/blocksstable/ob_macro_block_id.h" -#include "storage/blocksstable/ob_block_manager.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "lib/hash/ob_linear_hash_map.h" -#include "lib/lock/ob_spin_rwlock.h" -#include "lib/allocator/page_arena.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileBlockPageBitmap; -class ObTmpFileBlockManager; - -struct ObTmpFileBlockKey final -{ - explicit ObTmpFileBlockKey(const int64_t block_index) : block_index_(block_index) {} - OB_INLINE int hash(uint64_t &hash_val) const - { - hash_val = murmurhash(&block_index_, sizeof(int64_t), 0); - return OB_SUCCESS; - } - OB_INLINE bool operator==(const ObTmpFileBlockKey &other) const - { - return block_index_ == other.block_index_; - } - TO_STRING_KV(K(block_index_)); - int64_t block_index_; -}; - -// search every set of continuous existence or non-existence pages in the range of [start_idx, end_idx_] -class ObTmpFileBlockPageBitmapIterator -{ -public: - ObTmpFileBlockPageBitmapIterator() : - bitmap_(nullptr), is_inited_(false), cur_idx_(OB_INVALID_INDEX), end_idx_(OB_INVALID_INDEX) {} - ~ObTmpFileBlockPageBitmapIterator() { reset(); } - int init(const ObTmpFileBlockPageBitmap *bitmap, const int64_t start_idx, int64_t end_idx); - void reset(); - int next_range(bool &value, int64_t &start_page_id, int64_t &end_page_id); - OB_INLINE bool has_next() const { return is_inited_ && cur_idx_ <= end_idx_; } -private: - const ObTmpFileBlockPageBitmap *bitmap_; - bool is_inited_; - int64_t cur_idx_; - int64_t end_idx_; -}; - -class ObTmpFileBlockPageBitmap -{ -public: - ObTmpFileBlockPageBitmap() { reset(); } - ~ObTmpFileBlockPageBitmap() { reset(); } - OB_INLINE void reset() { MEMSET(bitmap_, 0, PAGE_CAPACITY / 8); } - int get_value(const int64_t offset, bool &value) const; - int set_bitmap(const int64_t offset, const bool value); - int set_bitmap_batch(const int64_t offset, const int64_t count, const bool value); - // [start, end] - int is_all_true(const int64_t start, const int64_t end, bool &is_all_true) const; - int is_all_false(const int64_t start, const int64_t end, bool &is_all_false) const; - int is_all_true(bool &b_ret) const; - int is_all_false(bool &b_ret) const; - OB_INLINE static int64_t get_capacity() { return PAGE_CAPACITY; } - int64_t to_string(char* buf, const int64_t buf_len) const; -private: - static constexpr int64_t PAGE_CAPACITY = ObTmpFileGlobal::BLOCK_PAGE_NUMS; - // upper_align(PAGE_CAPACITY/8, 8) - static constexpr int64_t PAGE_BYTE_CAPACITY = (PAGE_CAPACITY / 8 + 7) & ~7; - -private: - uint8_t bitmap_[PAGE_BYTE_CAPACITY]; -}; - -// ObTmpFileBlock records the usage of a macro block. -// Each macro block may be referenced by one or more local temporary files. -class ObTmpFileBlock final -{ - enum BlockState { - INVALID = -1, - IN_MEMORY = 0, - WRITE_BACK = 1, - ON_DISK = 2, - }; -public: - ObTmpFileBlock(): block_state_(BlockState::INVALID), lock_(common::ObLatchIds::TMP_FILE_LOCK), - page_bitmap_(), block_index_(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX), - macro_block_id_(), ref_cnt_(0) {} - ~ObTmpFileBlock(); - - OB_INLINE bool is_valid() const { - bool b_ret = false; - - if (block_state_ < BlockState::INVALID || block_state_ > BlockState::ON_DISK) { - b_ret = false; - } else { - b_ret = block_index_ != ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - if (BlockState::ON_DISK == block_state_) { - b_ret = b_ret && macro_block_id_.is_valid(); - } - } - return b_ret; - } - - int reset(); - int init_block(const int64_t block_index, const int64_t begin_page_id, const int64_t page_num); - int write_back_start(); - int write_back_failed(); - int write_back_succ(const blocksstable::MacroBlockId macro_block_id); - int release_pages(const int64_t begin_page_id, const int64_t page_num); - int get_page_usage(int64_t &page_num) const; - int inc_ref_cnt(); - int dec_ref_cnt(int64_t &ref_cnt); - bool on_disk() const; - int can_remove(bool &can_remove) const; - blocksstable::MacroBlockId get_macro_block_id() const; - int64_t get_block_index() const; - - TO_STRING_KV(K(block_index_), K(macro_block_id_), - K(block_state_), K(page_bitmap_), - K(ref_cnt_)); - -private: - BlockState block_state_; - common::SpinRWLock lock_; - ObTmpFileBlockPageBitmap page_bitmap_; // records the page usage of this block - int64_t block_index_; - blocksstable::MacroBlockId macro_block_id_; - int64_t ref_cnt_; - DISALLOW_COPY_AND_ASSIGN(ObTmpFileBlock); -}; - -class ObTmpFileBlockHandle final -{ -public: - ObTmpFileBlockHandle() : ptr_(nullptr) {} - ObTmpFileBlockHandle(ObTmpFileBlock *block, ObTmpFileBlockManager *tmp_file_blk_mgr); - ObTmpFileBlockHandle(const ObTmpFileBlockHandle &handle); - ObTmpFileBlockHandle & operator=(const ObTmpFileBlockHandle &other); - ~ObTmpFileBlockHandle() { reset(); } - OB_INLINE ObTmpFileBlock * get() const {return ptr_; } - bool is_inited() { return nullptr != ptr_ && nullptr != tmp_file_blk_mgr_; } - void reset(); - int init(ObTmpFileBlock *block, ObTmpFileBlockManager *tmp_file_blk_mgr); - TO_STRING_KV(KPC(ptr_)); -private: - ObTmpFileBlock *ptr_; - ObTmpFileBlockManager *tmp_file_blk_mgr_; -}; - -class ObTmpFileBlockManager final -{ -public: - ObTmpFileBlockManager(); - ~ObTmpFileBlockManager(); - int init(); - void destroy(); - int create_tmp_file_block(const int64_t begin_page_id, const int64_t page_num, - int64_t &block_index); - - int write_back_start(const int64_t block_index); - int write_back_failed(const int64_t block_index); - int write_back_succ(const int64_t block_index, const blocksstable::MacroBlockId macro_block_id); - int release_tmp_file_page(const int64_t block_index, - const int64_t begin_page_id, const int64_t page_num); - int get_macro_block_list(common::ObIArray ¯o_id_list); - int get_macro_block_count(int64_t ¯o_block_count); - int get_tmp_file_block_handle(const int64_t block_index, ObTmpFileBlockHandle &handle); - int get_macro_block_id(const int64_t block_index, blocksstable::MacroBlockId ¯o_block_id); - int get_block_usage_stat(int64_t &used_page_num, int64_t ¯o_block_count); - void print_block_usage(); - OB_INLINE common::ObConcurrentFIFOAllocator &get_block_allocator() { return block_allocator_; } - TO_STRING_KV(K(is_inited_), K(used_page_num_), - K(physical_block_num_), K(block_index_generator_)); -private: - int remove_tmp_file_block_(const int64_t block_index); -private: - typedef common::ObLinearHashMap ObTmpFileBlockMap; - typedef SpinWLockGuard ExclusiveLockGuard; - typedef SpinRLockGuard SharedLockGuard; -private: - class CollectMacroBlockIdFunctor final - { - public: - CollectMacroBlockIdFunctor(common::ObIArray ¯o_id_list) - : macro_id_list_(macro_id_list) {} - bool operator()(const ObTmpFileBlockKey &block_index, const ObTmpFileBlockHandle &block); - - private: - common::ObIArray ¯o_id_list_; - }; -private: - bool is_inited_; - uint64_t used_page_num_; - uint64_t physical_block_num_; - uint64_t block_index_generator_; - ObTmpFileBlockMap block_map_; - common::ObConcurrentFIFOAllocator block_allocator_; - common::SpinRWLock stat_lock_; // to protect the consistency of used_page_num_ and physical_block_num_ - DISALLOW_COPY_AND_ASSIGN(ObTmpFileBlockManager); -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_BLOCK_MANAGER_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_cache.cpp b/src/storage/tmp_file/ob_tmp_file_cache.cpp deleted file mode 100644 index fb3b15bfad..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_cache.cpp +++ /dev/null @@ -1,745 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "storage/tmp_file/ob_tmp_file_cache.h" -#include "share/rc/ob_server_runtime.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" -#include "storage/blocksstable/ob_storage_object_handle.h" -#include "share/ob_server_struct.h" - -using namespace oceanbase::storage; -using namespace oceanbase::share; - -namespace oceanbase -{ -namespace tmp_file -{ -/* -------------------------- ObTmpBlockCacheKey --------------------------- */ -ObTmpBlockCacheKey::ObTmpBlockCacheKey() - : block_id_(-1) -{ -} - -ObTmpBlockCacheKey::ObTmpBlockCacheKey(const int64_t block_id) - : block_id_(block_id) -{ -} - -ObTmpBlockCacheKey::~ObTmpBlockCacheKey() -{ -} - -bool ObTmpBlockCacheKey::operator ==(const ObIKVCacheKey &other) const -{ - const ObTmpBlockCacheKey &other_key = reinterpret_cast (other); - return block_id_ == other_key.block_id_; -} - - - -uint64_t ObTmpBlockCacheKey::hash() const -{ - return murmurhash(this, sizeof(ObTmpBlockCacheKey), 0); -} - -int64_t ObTmpBlockCacheKey::size() const -{ - return sizeof(*this); -} - -int ObTmpBlockCacheKey::deep_copy(char *buf, const int64_t buf_len, ObIKVCacheKey *&key) const -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len < size())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "Invalid argument, ", KR(ret)); - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid tmp block cache key, ", KPC(this), KR(ret)); - } else { - key = new (buf) ObTmpBlockCacheKey(block_id_); - } - return ret; -} - -bool ObTmpBlockCacheKey::is_valid() const -{ - return OB_LIKELY(block_id_ >= 0 && size() > 0); -} - -/* -------------------------- ObTmpBlockCacheValue --------------------------- */ -ObTmpBlockCacheValue::ObTmpBlockCacheValue(char *buf) - : buf_(buf), size_(ObTmpFileGlobal::SN_BLOCK_SIZE) -{ -} - -ObTmpBlockCacheValue::~ObTmpBlockCacheValue() -{ -} - -int64_t ObTmpBlockCacheValue::size() const -{ - return sizeof(*this) + size_; -} - -int ObTmpBlockCacheValue::deep_copy(char *buf, const int64_t buf_len, ObIKVCacheValue *&value) const -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len < size())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), KP(buf), K(buf_len), - "request_size", size()); - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid tmp block cache value", KR(ret)); - } else { - ObTmpBlockCacheValue *blk_cache_value = new (buf) ObTmpBlockCacheValue(buf + sizeof(*this)); - MEMCPY(buf + sizeof(*this), buf_, size() - sizeof(*this)); - blk_cache_value->size_ = size_; - value = blk_cache_value; - } - return ret; -} - -/* -------------------------- ObTmpBlockCache --------------------------- */ - -ObTmpBlockCache &ObTmpBlockCache::get_instance() -{ - static ObTmpBlockCache instance; - return instance; -} - -int ObTmpBlockCache::init(const char *cache_name) -{ - int ret = OB_SUCCESS; - if (OB_FAIL((common::ObKVCache::init( - cache_name)))) { - } - return ret; -} - -void ObTmpBlockCache::destroy() -{ - common::ObKVCache::destroy(); -} - -int ObTmpBlockCache::get_block(const ObTmpBlockCacheKey &key, ObTmpBlockValueHandle &handle) -{ - int ret = OB_SUCCESS; - const ObTmpBlockCacheValue *value = NULL; - if (OB_UNLIKELY(!key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), K(key)); - } else if (OB_FAIL(get(key, value, handle.handle_))) { - if (OB_UNLIKELY(OB_ENTRY_NOT_EXIST != ret)) { - STORAGE_LOG(WARN, "fail to get key from block cache", KR(ret), K(key)); - } else { - } - } else { - if (OB_ISNULL(value)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected error, the value must not be NULL", KR(ret)); - } else { - handle.value_ = const_cast(value); - } - } - return ret; -} - -int ObTmpBlockCache::put_block(ObKVCacheInstHandle &inst_handle, - ObKVCachePair *&kvpair, - ObTmpBlockValueHandle &block_handle) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!inst_handle.is_valid() || nullptr == kvpair || !block_handle.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(inst_handle), KP(kvpair), K(block_handle)); - } else if (OB_FAIL(put_kvpair(inst_handle, kvpair, block_handle.handle_, false/*overwrite*/))) { - } else { - // refresh the block cache score by calling get_block() to prevent eviction, - // otherwise new block's score is 0 and may be evicted immediately - ObTmpBlockValueHandle block_value_handle; - const ObIKVCacheKey &key = *kvpair->key_; - get_block(dynamic_cast(key), block_value_handle); - } - - return ret; -} - -int ObTmpBlockCache::prealloc_block(const ObTmpBlockCacheKey &key, ObKVCacheInstHandle &inst_handle, - ObKVCachePair *&kvpair, - ObTmpBlockValueHandle &block_handle) -{ - int ret = OB_SUCCESS; - inst_handle.reset(); - kvpair = nullptr; - block_handle.reset(); - if (OB_UNLIKELY(!key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(key)); - } else if (OB_FAIL(alloc(key.size(), - sizeof(ObTmpBlockCacheValue) + ObTmpFileGlobal::SN_BLOCK_SIZE, - kvpair, block_handle.handle_, inst_handle))) { - } else if (OB_FAIL(key.deep_copy(reinterpret_cast(kvpair->key_), - key.size(), kvpair->key_))) { - } else { - char *buf = reinterpret_cast(kvpair->value_); - block_handle.value_ = new (buf) ObTmpBlockCacheValue(buf + sizeof(ObTmpBlockCacheValue)); - } - - if (OB_FAIL(ret)) { - block_handle.reset(); - inst_handle.reset(); - kvpair = NULL; - } - return ret; -} - -/* -------------------------- ObTmpPageCacheKey --------------------------- */ -ObTmpPageCacheKey::ObTmpPageCacheKey() - : block_id_(-1), page_id_(-1) -{ -} - -ObTmpPageCacheKey::ObTmpPageCacheKey(const int64_t block_id, const int64_t page_id) - : block_id_(block_id), page_id_(page_id) -{ -} - -ObTmpPageCacheKey::~ObTmpPageCacheKey() -{ -} - -bool ObTmpPageCacheKey::operator ==(const ObIKVCacheKey &other) const -{ - const ObTmpPageCacheKey &other_key = reinterpret_cast (other); - return block_id_ == other_key.block_id_ - && page_id_ == other_key.page_id_; -} - -uint64_t ObTmpPageCacheKey::hash() const -{ - return murmurhash(this, sizeof(ObTmpPageCacheKey), 0); -} - -int64_t ObTmpPageCacheKey::size() const -{ - return sizeof(*this); -} - -int ObTmpPageCacheKey::deep_copy(char *buf, const int64_t buf_len, ObIKVCacheKey *&key) const -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len < size())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "Invalid argument, ", KR(ret)); - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid tmp page cache key, ", KPC(this), KR(ret)); - } else { - key = new (buf) ObTmpPageCacheKey(block_id_, page_id_); - } - return ret; -} - -bool ObTmpPageCacheKey::is_valid() const -{ - return OB_LIKELY(block_id_ >= 0 && page_id_ >= 0 && size() > 0); -} - -int64_t ObTmpPageCacheKey::to_string(char* buf, const int64_t buf_len) const -{ - int64_t pos = 0; - J_OBJ_START(); - J_KV(K(block_id_), K(page_id_)); - J_OBJ_END(); - return pos; -} -/* -------------------------- ObTmpPageCacheValue --------------------------- */ -ObTmpPageCacheValue::ObTmpPageCacheValue(char *buf) - : buf_(buf), size_(ObTmpFileGlobal::ALLOC_PAGE_SIZE) -{ -} - -ObTmpPageCacheValue::~ObTmpPageCacheValue() -{ -} - -int64_t ObTmpPageCacheValue::size() const -{ - return sizeof(*this) + size_; -} - -int ObTmpPageCacheValue::deep_copy(char *buf, const int64_t buf_len, ObIKVCacheValue *&value) const -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len < size())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), KP(buf), K(buf_len), - "request_size", size()); - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid tmp page cache value", KR(ret)); - } else { - ObTmpPageCacheValue *page_cache_value = new (buf) ObTmpPageCacheValue(buf + sizeof(*this)); - MEMCPY(buf + sizeof(*this), buf_, size() - sizeof(*this)); - page_cache_value->size_ = size_; - value = page_cache_value; - } - return ret; -} - -/* -------------------------- ObTmpPageCacheReadInfo --------------------------- */ - -void ObTmpPageCacheReadInfo::reset() -{ - is_inited_ = false; - macro_block_id_.reset(); - read_size_ = 0; - begin_offset_ = -1; - io_desc_.reset(); - io_timeout_ms_ = 0; - object_handle_ = nullptr; -} - -bool ObTmpPageCacheReadInfo::is_valid() -{ - bool ret = is_inited_ && macro_block_id_.is_valid() && read_size_ > 0 && begin_offset_ >= 0 && - io_desc_.is_valid() && io_timeout_ms_ > 0 && - OB_NOT_NULL(object_handle_); - if(OB_UNLIKELY(!ret)) { - } else { - ret = begin_offset_ + read_size_ <= ObTmpFileGlobal::SN_BLOCK_SIZE; - } - return ret; -} - -int ObTmpPageCacheReadInfo::init_read(const blocksstable::MacroBlockId ¯o_block_id, - const int64_t read_size, const int64_t begin_offset, - common::ObIOFlag io_flag, const int64_t io_timeout_ms, - blocksstable::ObStorageObjectHandle *handle) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - STORAGE_LOG(WARN, "ObTmpPageCacheReadInfo has been inited", KR(ret), KPC(this)); - } else if (OB_UNLIKELY(!macro_block_id.is_valid() || read_size <= 0 || begin_offset < 0 || - !io_flag.is_valid() || io_timeout_ms <= 0 || - OB_ISNULL(handle))) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), K(macro_block_id), K(read_size), - K(begin_offset), K(io_flag), K(io_timeout_ms), KP(handle)); - - } else if (begin_offset + read_size > ObTmpFileGlobal::SN_BLOCK_SIZE) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), K(macro_block_id), K(read_size), - K(begin_offset), K(io_flag), K(io_timeout_ms), KP(handle)); - } else { - macro_block_id_ = macro_block_id; - read_size_ = read_size; - begin_offset_ = begin_offset; - io_desc_ = io_flag; - io_timeout_ms_ = io_timeout_ms; - object_handle_ = handle; - is_inited_ = true; - } - return ret; -} - -int ObTmpPageCacheReadInfo::async_read(std::unique_ptr callback) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpPageCacheReadInfo has not been inited", KR(ret), KPC(this)); - } else if (OB_ISNULL(callback)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), KP(callback.get())); - } else { - blocksstable::ObStorageObjectReadInfo read_info; - read_info.macro_block_id_ = macro_block_id_; - read_info.size_ = read_size_; - read_info.offset_ = begin_offset_; - read_info.io_desc_ = io_desc_; - read_info.io_timeout_ms_ = io_timeout_ms_; - - read_info.io_desc_.set_sys_module_id(ObIOModule::TMP_PAGE_CACHE_IO); - if (OB_FAIL(object_handle_->async_read(read_info, std::move(callback)))) { - } - } - - - return ret; -} -/* -------------------------- ObTmpPageCache --------------------------- */ - -ObTmpPageCache &ObTmpPageCache::get_instance() -{ - static ObTmpPageCache instance; - return instance; -} - -int ObTmpPageCache::init(const char *cache_name) -{ - int ret = OB_SUCCESS; - if (OB_FAIL((common::ObKVCache::init( - cache_name)))) { - } - return ret; -} - -void ObTmpPageCache::destroy() -{ - common::ObKVCache::destroy(); -} - -int ObTmpPageCache::get_page(const ObTmpPageCacheKey &key, ObTmpPageValueHandle &handle) -{ - int ret = OB_SUCCESS; - const ObTmpPageCacheValue *value = NULL; - if (OB_UNLIKELY(!key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), K(key)); - } else if (OB_FAIL(get(key, value, handle.handle_))) { - if (OB_UNLIKELY(OB_ENTRY_NOT_EXIST == ret)) { - } else { - STORAGE_LOG(WARN, "fail to get key from page cache", KR(ret), K(key)); - } - } else { - if (OB_ISNULL(value)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected error, the value must not be NULL", KR(ret)); - } else { - handle.value_ = const_cast(value); - } - } - return ret; -} - -void ObTmpPageCache::try_put_page_to_cache(const ObTmpPageCacheKey &key, - const ObTmpPageCacheValue &value) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!key.is_valid() || !value.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), K(key), K(value)); - } else if (OB_FAIL(put(key, value, false/*overwrite*/))) { - } else { - // refresh the page cache score by calling get_page() to prevent eviction, - // otherwise its score is 0 and may be evicted immediately - ObTmpPageValueHandle handle; - get_page(key, handle); - } -} - -int ObTmpPageCache::load_page(const ObTmpPageCacheKey &key, - ObIAllocator *callback_allocator, - ObTmpPageValueHandle &p_handle) -{ - int ret = OB_SUCCESS; - ObKVCacheInstHandle inst_handle; - ObKVCachePair *kvpair = NULL; - p_handle.reset(); - if (OB_UNLIKELY(!key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(key)); - } else if (OB_ISNULL(callback_allocator)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "callback_allocator is unexpected nullptr", KR(ret), K(key)); - } else if (OB_FAIL(alloc(key.size(), - sizeof(ObTmpPageCacheValue) + ObTmpFileGlobal::ALLOC_PAGE_SIZE, - kvpair, p_handle.handle_, inst_handle))) { - } else if (OB_FAIL(key.deep_copy(reinterpret_cast(kvpair->key_), - key.size(), kvpair->key_))) { - } else { - char *buf = reinterpret_cast(kvpair->value_); - p_handle.value_ = new (buf) ObTmpPageCacheValue(buf + sizeof(ObTmpPageCacheValue)); - } - if (OB_SUCC(ret)) { - ObTmpFileBlockManager &block_manager = ::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->get_tmp_file_block_manager(); - blocksstable::ObStorageObjectHandle obj_handle; - blocksstable::MacroBlockId macro_block_id; - //TODO: io_desc and io_timeout_ms value settings - common::ObIOFlag io_desc; - int64_t io_timeout_ms = 10 * 1000; // 10s - ObTmpPageCacheReadInfo read_info; - - if (OB_FAIL(block_manager.get_macro_block_id(key.get_block_id(), macro_block_id))) { - } else if (OB_FAIL(read_info.init_read(macro_block_id, ObTmpFileGlobal::ALLOC_PAGE_SIZE, - key.get_page_id() * ObTmpFileGlobal::ALLOC_PAGE_SIZE, - io_desc, io_timeout_ms, - &obj_handle))) { - } else if (OB_FAIL(direct_read(read_info, *callback_allocator))) { - } else if (OB_FAIL(obj_handle.wait())) { - } else { - MEMCPY(p_handle.value_->get_buffer(), obj_handle.get_buffer(), ObTmpFileGlobal::ALLOC_PAGE_SIZE); - } - } - if (FAILEDx(put_kvpair(inst_handle, kvpair, p_handle.handle_, false/*overwrite*/))) { - if (OB_ENTRY_EXIST == ret) { - ret = OB_SUCCESS; - } else { - STORAGE_LOG(WARN, "fail to put tmp page to page cache", KR(ret), K(key)); - } - } - if (OB_FAIL(ret)) { - p_handle.reset(); - inst_handle.reset(); - kvpair = NULL; - } - return ret; -} - -// only read pages from disk -int ObTmpPageCache::direct_read(ObTmpPageCacheReadInfo &read_info, - common::ObIAllocator &callback_allocator) -{ - int ret = OB_SUCCESS; - void *buf = nullptr; - ObTmpDirectReadPageIOCallback *callback = nullptr; - if (OB_UNLIKELY(!read_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid read info", KR(ret), K(read_info)); - } else if (OB_ISNULL(buf = callback_allocator.alloc(sizeof(ObTmpDirectReadPageIOCallback)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - STORAGE_LOG(WARN, "allocate callback memory failed", KR(ret)); - } else { - callback = new (buf) ObTmpDirectReadPageIOCallback; - callback->cache_ = this; - callback->allocator_ = &callback_allocator; - if (OB_FAIL(inner_read_io_(read_info, callback))) { - } - } - return ret; -} - -// read pages from disk and put them into kv_cache -int ObTmpPageCache::cached_read(const common::ObIArray &page_keys, - ObTmpPageCacheReadInfo &read_info, - common::ObIAllocator &callback_allocator) -{ - int ret = OB_SUCCESS; - void *buf = nullptr; - ObTmpCachedReadPageIOCallback *callback = nullptr; - - if (OB_UNLIKELY(page_keys.count() <= 0)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "Invalid arguments", KR(ret), K(page_keys.count())); - } else if (OB_UNLIKELY(!read_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid read info", KR(ret), K(read_info)); - } else if (OB_UNLIKELY(read_info.get_begin_offset() % ObTmpFileGlobal::ALLOC_PAGE_SIZE != 0)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "cached_read should read completed pages", KR(ret), K(read_info)); - } else if (OB_ISNULL(buf = callback_allocator.alloc(sizeof(ObTmpCachedReadPageIOCallback)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - STORAGE_LOG(WARN, "allocate callback memory failed", KR(ret)); - } else { - callback = new (buf) ObTmpCachedReadPageIOCallback; - callback->cache_ = this; - callback->allocator_ = &callback_allocator; - if (OB_FAIL(callback->page_keys_.assign(page_keys))) { - STORAGE_LOG(WARN, "fail to assign page keys", KR(ret), K(page_keys.count())); - callback->~ObTmpCachedReadPageIOCallback(); - callback_allocator.free(callback); - } else if (OB_FAIL(inner_read_io_(read_info, callback))) { - } - } - return ret; -} - -// read pages from disk and put some of them into kv_cache -int ObTmpPageCache::aggregate_read(const common::ObIArray> &page_infos, - ObTmpPageCacheReadInfo &read_info, - common::ObIAllocator &callback_allocator) -{ - int ret = OB_SUCCESS; - void *buf = nullptr; - ObTmpAggregatePageIOCallback *callback = nullptr; - - if (OB_UNLIKELY(page_infos.count() <= 0)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "Invalid arguments", KR(ret), K(page_infos.count())); - } else if (OB_UNLIKELY(!read_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid read info", KR(ret), K(read_info)); - } else if (OB_UNLIKELY(read_info.get_begin_offset() % ObTmpFileGlobal::ALLOC_PAGE_SIZE != 0)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "aggregate_read should read completed pages", KR(ret), K(read_info)); - } else if (OB_ISNULL(buf = callback_allocator.alloc(sizeof(ObTmpAggregatePageIOCallback)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - STORAGE_LOG(WARN, "allocate callback memory failed", KR(ret)); - } else { - callback = new (buf) ObTmpAggregatePageIOCallback; - callback->cache_ = this; - callback->allocator_ = &callback_allocator; - if (OB_FAIL(callback->page_infos_.assign(page_infos))) { - STORAGE_LOG(WARN, "fail to assign page keys", KR(ret), K(page_infos.count())); - callback->~ObTmpAggregatePageIOCallback(); - callback_allocator.free(callback); - } else if (OB_FAIL(inner_read_io_(read_info, callback))) { - } - } - return ret; -} - -int ObTmpPageCache::inner_read_io_(ObTmpPageCacheReadInfo &read_info, - ObITmpPageIOCallback *callback) -{ - auto owner = storage_io::adopt_callback(callback); - return owner ? read_info.async_read(std::move(owner)) : OB_ALLOCATE_MEMORY_FAILED; -} - -ObTmpPageCache::ObITmpPageIOCallback::ObITmpPageIOCallback(const common::ObIOCallbackType type) - : common::ObIOCallback(type), cache_(NULL), allocator_(NULL), data_buf_(NULL) -{ -} - -ObTmpPageCache::ObITmpPageIOCallback::~ObITmpPageIOCallback() -{ - if (NULL != allocator_ && NULL != data_buf_) { - allocator_->free(data_buf_); - data_buf_ = NULL; - } - allocator_ = NULL; -} - -int ObTmpPageCache::ObITmpPageIOCallback::alloc_data_buf(const char *io_data_buffer, const int64_t data_size) -{ - int ret = alloc_and_copy_data(io_data_buffer, data_size, allocator_, data_buf_); - return ret; -} - -int ObTmpPageCache::ObITmpPageIOCallback::process_page( - const ObTmpPageCacheKey &key, const ObTmpPageCacheValue &value) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!key.is_valid() || !value.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid arguments", KR(ret), K(key), K(value)); - } else if (OB_FAIL(cache_->put(key, value, true/*overwrite*/))) { - } - return ret; -} - -ObTmpPageCache::ObTmpCachedReadPageIOCallback::ObTmpCachedReadPageIOCallback() - : ObITmpPageIOCallback(ObIOCallbackType::TMP_CACHED_READ_CALLBACK), page_keys_() -{ - page_keys_.set_attr(ObMemAttr("TFCacheRead")); -} - -ObTmpPageCache::ObTmpCachedReadPageIOCallback::~ObTmpCachedReadPageIOCallback() -{ - page_keys_.reset(); -} - -int ObTmpPageCache::ObTmpCachedReadPageIOCallback::process(const char *data_buffer, const int64_t size) -{ - int ret = OB_SUCCESS; - ObTimeGuard time_guard("TmpCachedReadPage_Callback_Process", 100000); //100ms - - if (OB_ISNULL(cache_) || OB_ISNULL(allocator_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "Invalid tmp page cache callback allocator", KR(ret), KP(cache_), KP(allocator_)); - } else if (OB_UNLIKELY(size <= 0 || data_buffer == nullptr)) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid data buffer size", KR(ret), K(size), KP(data_buffer)); - } else if (OB_UNLIKELY(page_keys_.count() * ObTmpFileGlobal::ALLOC_PAGE_SIZE != size)) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid data buffer size", KR(ret), K(size), K(page_keys_.count())); - } else if (OB_FAIL(alloc_data_buf(data_buffer, size))) { - } else if (FALSE_IT(time_guard.click("alloc_data_buf"))) { - } else { - for (int32_t i = 0; OB_SUCC(ret) && i < page_keys_.count(); i++) { - ObTmpPageCacheValue value(nullptr); - value.set_buffer(data_buf_ + i * ObTmpFileGlobal::ALLOC_PAGE_SIZE); - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(process_page(page_keys_.at(i), value))) { - } - } - time_guard.click("process_page"); - } - if (OB_FAIL(ret) && NULL != allocator_ && NULL != data_buf_) { - allocator_->free(data_buf_); - data_buf_ = NULL; - } - return ret; -} - -ObTmpPageCache::ObTmpAggregatePageIOCallback::ObTmpAggregatePageIOCallback() - : ObITmpPageIOCallback(ObIOCallbackType::TMP_MULTI_PAGE_CALLBACK), page_infos_() -{ - page_infos_.set_attr(ObMemAttr("TFPrefetch")); -} - -ObTmpPageCache::ObTmpAggregatePageIOCallback::~ObTmpAggregatePageIOCallback() -{ - page_infos_.reset(); -} - -int ObTmpPageCache::ObTmpAggregatePageIOCallback::process(const char *data_buffer, const int64_t size) -{ - int ret = OB_SUCCESS; - ObTimeGuard time_guard("TmpPrefetchPage_Callback_Process", 100000); //100ms - if (OB_ISNULL(cache_) || OB_ISNULL(allocator_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "Invalid tmp page cache callback allocator", KR(ret), KP(cache_), KP(allocator_)); - } else if (OB_UNLIKELY(size <= 0 || data_buffer == nullptr)) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid data buffer size", KR(ret), K(size), KP(data_buffer)); - } else if (OB_FAIL(alloc_data_buf(data_buffer, size))) { - } else if (FALSE_IT(time_guard.click("alloc_data_buf"))) { - } else { - for (int32_t i = 0; OB_SUCC(ret) && i < page_infos_.count(); i++) { - ObTmpPageCacheValue value(nullptr); - value.set_buffer(data_buf_ + page_infos_.at(i).second); - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(process_page(page_infos_.at(i).first, value))) { - } - } - time_guard.click("process_page"); - page_infos_.reset(); - } - if (OB_FAIL(ret) && NULL != allocator_ && NULL != data_buf_) { - allocator_->free(data_buf_); - data_buf_ = NULL; - } - return ret; -} - -int ObTmpPageCache::ObTmpDirectReadPageIOCallback::process(const char *data_buffer, const int64_t size) -{ - int ret = OB_SUCCESS; - ObTimeGuard time_guard("ObTmpDirectReadPageIOCallback", 100000); //100ms - if (OB_ISNULL(cache_) || OB_ISNULL(allocator_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "Invalid tmp page cache callback allocator", KR(ret), KP(cache_), KP(allocator_)); - } else if (OB_UNLIKELY(size <= 0 || data_buffer == nullptr)) { - ret = OB_INVALID_DATA; - STORAGE_LOG(WARN, "invalid data buffer size", KR(ret), K(size), KP(data_buffer)); - } else if (OB_FAIL(alloc_data_buf(data_buffer, size))) { - } else if (FALSE_IT(time_guard.click("alloc_data_buf"))) { - } - if (OB_FAIL(ret) && NULL != allocator_ && NULL != data_buf_) { - allocator_->free(data_buf_); - data_buf_ = NULL; - } - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_cache.h b/src/storage/tmp_file/ob_tmp_file_cache.h deleted file mode 100644 index a622527398..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_cache.h +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_CACHE_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_CACHE_H_ - -#include "share/io_request.h" -#include "storage/blocksstable/ob_macro_block_id.h" -#include "share/cache/ob_kv_storecache.h" - -namespace oceanbase -{ -namespace blocksstable -{ - class ObStorageObjectHandle; - class MacroBlockId; -} -namespace tmp_file -{ - -template -int assign_tmp_file_cache_handle( - common::ObKVCacheHandle &handle, CacheValue *&value, - const common::ObKVCacheHandle &other_handle, CacheValue *const &other_value) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(handle.assign(other_handle))) { - COMMON_LOG(WARN, "failed to assign handle", K(ret)); - value = nullptr; - } else { - value = other_value; - } - return ret; -} - -class ObTmpPageCacheReadInfo; - -class ObTmpBlockCacheKey final : public common::ObIKVCacheKey -{ -public: - ObTmpBlockCacheKey(); - ObTmpBlockCacheKey(const int64_t block_id); - ~ObTmpBlockCacheKey(); - bool operator ==(const ObIKVCacheKey &other) const override; - - uint64_t hash() const override; - int64_t size() const override; - int deep_copy(char *buf, const int64_t buf_len, ObIKVCacheKey *&key) const override; - bool is_valid() const; - int64_t get_block_id() const { return block_id_; } - TO_STRING_KV(K(block_id_)); - -private: - int64_t block_id_; -}; - -class ObTmpBlockCacheValue final : public common::ObIKVCacheValue -{ -public: - explicit ObTmpBlockCacheValue(char *buf); - ~ObTmpBlockCacheValue(); - int64_t size() const override; - int deep_copy(char *buf, const int64_t buf_len, ObIKVCacheValue *&value) const override; - bool is_valid() const { return NULL != buf_ && size() > 0; } - char *get_buffer() { return buf_; } - void set_buffer(char *buf) { buf_ = buf;} - TO_STRING_KV(KP(buf_), K(size_)); - -private: - char *buf_; - int64_t size_; - DISALLOW_COPY_AND_ASSIGN(ObTmpBlockCacheValue); -}; - -struct ObTmpBlockValueHandle final -{ -public: - ObTmpBlockValueHandle() : value_(NULL), handle_() {} - ~ObTmpBlockValueHandle() = default; - void move_from(ObTmpBlockValueHandle& other) - { - this->value_ = other.value_; - this->handle_.move_from(other.handle_); - other.reset(); - } - int assign(const ObTmpBlockValueHandle& other) - { - return assign_tmp_file_cache_handle(handle_, value_, other.handle_, other.value_); - } - bool is_valid() const { return NULL != value_ && handle_.is_valid(); } - void reset() - { - handle_.reset(); - value_ = NULL; - } - TO_STRING_KV(KP(value_), K(handle_)); - ObTmpBlockCacheValue *value_; - common::ObKVCacheHandle handle_; -}; - -class ObTmpBlockCache final : public common::ObKVCache -{ -public: - typedef common::ObKVCache BasePageCache; - static ObTmpBlockCache &get_instance(); - int init(const char *cache_name); - void destroy(); - int get_block(const ObTmpBlockCacheKey &key, ObTmpBlockValueHandle &handle); - int put_block(ObKVCacheInstHandle &inst_handle, - ObKVCachePair *&kvpair, - ObTmpBlockValueHandle &block_handle); - int prealloc_block(const ObTmpBlockCacheKey &key, - ObKVCacheInstHandle &inst_handle, - ObKVCachePair *&kvpair, - ObTmpBlockValueHandle &block_handle); -private: - ObTmpBlockCache() {} - ~ObTmpBlockCache() {} - -private: - DISALLOW_COPY_AND_ASSIGN(ObTmpBlockCache); -}; - -class ObTmpPageCacheKey final : public common::ObIKVCacheKey -{ -public: - ObTmpPageCacheKey(); - ObTmpPageCacheKey(const int64_t block_id, const int64_t page_id); - ~ObTmpPageCacheKey(); - bool operator ==(const ObIKVCacheKey &other) const override; - - uint64_t hash() const override; - int64_t size() const override; - int deep_copy(char *buf, const int64_t buf_len, ObIKVCacheKey *&key) const override; - bool is_valid() const; - int64_t get_page_id() const { return page_id_; } - int64_t get_block_id() const { return block_id_; } - int64_t to_string(char* buf, const int64_t buf_len) const; -private: - int64_t block_id_; - int64_t page_id_; - -}; - -class ObTmpPageCacheValue final : public common::ObIKVCacheValue -{ -public: - explicit ObTmpPageCacheValue(char *buf); - ~ObTmpPageCacheValue(); - int64_t size() const override; - int deep_copy(char *buf, const int64_t buf_len, ObIKVCacheValue *&value) const override; - bool is_valid() const { return NULL != buf_ && size() > 0; } - char *get_buffer() { return buf_; } - void set_buffer(char *buf) { buf_ = buf;} - TO_STRING_KV(KP(buf_), K(size_)); - -private: - char *buf_; - int64_t size_; - DISALLOW_COPY_AND_ASSIGN(ObTmpPageCacheValue); -}; - -struct ObTmpPageValueHandle final -{ -public: - ObTmpPageValueHandle() : value_(NULL), handle_() {} - ~ObTmpPageValueHandle() = default; - void reset() - { - handle_.reset(); - value_ = NULL; - } - void move_from(ObTmpPageValueHandle& other) - { - this->handle_.move_from(other.handle_); - this->value_ = other.value_; - other.reset(); - } - int assign(const ObTmpPageValueHandle& other) - { - return assign_tmp_file_cache_handle(handle_, value_, other.handle_, other.value_); - } - TO_STRING_KV(KP(value_), K(handle_)); - ObTmpPageCacheValue *value_; - common::ObKVCacheHandle handle_; -}; - -class ObTmpPageCache final : public common::ObKVCache -{ -public: - typedef common::ObKVCache BasePageCache; - static ObTmpPageCache &get_instance(); - int init(const char *cache_name); - // only read disk pages - int direct_read(ObTmpPageCacheReadInfo &read_info, - common::ObIAllocator &callback_allocator); - // read disk pages and put all of them into cache - int cached_read(const common::ObIArray &page_keys, - ObTmpPageCacheReadInfo &read_info, - common::ObIAllocator &callback_allocator); - // read disk pages and put some of them into cache - int aggregate_read(const common::ObIArray> &page_infos, - ObTmpPageCacheReadInfo &read_info, - common::ObIAllocator &callback_allocator); - int get_page(const ObTmpPageCacheKey &key, ObTmpPageValueHandle &handle); - int load_page(const ObTmpPageCacheKey &key, - ObIAllocator *callback_allocator, - ObTmpPageValueHandle &p_handle); - void try_put_page_to_cache(const ObTmpPageCacheKey &key, const ObTmpPageCacheValue &value); - void destroy(); -public: - class ObITmpPageIOCallback : public common::ObIOCallback - { - public: - ObITmpPageIOCallback(const common::ObIOCallbackType type); - virtual ~ObITmpPageIOCallback(); - int alloc_data_buf(const char *io_data_buffer, const int64_t data_size); - const char *get_data() const override { return data_buf_; } - - protected: - friend class ObTmpPageCache; - virtual int process_page(const ObTmpPageCacheKey &key, const ObTmpPageCacheValue &value); - virtual ObIAllocator *get_allocator() { return allocator_; } - - protected: - BasePageCache *cache_; - common::ObIAllocator *allocator_; - char *data_buf_; // actual data buffer - }; - - class ObTmpCachedReadPageIOCallback final : public ObITmpPageIOCallback - { - public: - ObTmpCachedReadPageIOCallback(); - ~ObTmpCachedReadPageIOCallback(); - int process(const char *data_buffer, const int64_t size) override; - TO_STRING_KV("callback_type:", "ObTmpCachedReadPageIOCallback", KP(data_buf_)); - DISALLOW_COPY_AND_ASSIGN(ObTmpCachedReadPageIOCallback); - private: - friend class ObTmpPageCache; - common::ObArray page_keys_; - }; - - class ObTmpAggregatePageIOCallback final : public ObITmpPageIOCallback - { - public: - ObTmpAggregatePageIOCallback(); - ~ObTmpAggregatePageIOCallback(); - int process(const char *data_buffer, const int64_t size) override; - TO_STRING_KV("callback_type:", "ObTmpAggregatePageIOCallback", KP(data_buf_)); - DISALLOW_COPY_AND_ASSIGN(ObTmpAggregatePageIOCallback); - private: - friend class ObTmpPageCache; - // each pair is (page key, page offset in io buffer) - common::ObArray> page_infos_; - }; - - class ObTmpDirectReadPageIOCallback final : public ObITmpPageIOCallback - { - public: - ObTmpDirectReadPageIOCallback() : ObITmpPageIOCallback(ObIOCallbackType::TMP_DIRECT_READ_PAGE_CALLBACK) {} - ~ObTmpDirectReadPageIOCallback() {} - int process(const char *data_buffer, const int64_t size) override; - TO_STRING_KV("callback_type:", "ObTmpDirectReadPageIOCallback", KP(data_buf_)); - DISALLOW_COPY_AND_ASSIGN(ObTmpDirectReadPageIOCallback); - }; -private: - ObTmpPageCache() {} - ~ObTmpPageCache() {} - int inner_read_io_(ObTmpPageCacheReadInfo &read_info, - ObITmpPageIOCallback *callback); - -private: - DISALLOW_COPY_AND_ASSIGN(ObTmpPageCache); -}; - -struct ObTmpPageCacheReadInfo final -{ -public: - ObTmpPageCacheReadInfo() - : is_inited_(false), - macro_block_id_(), - read_size_(0), - begin_offset_(-1), - io_desc_(), - io_timeout_ms_(-1), - object_handle_(nullptr) {} - ~ObTmpPageCacheReadInfo() { reset(); } - void reset(); - int init_read(const blocksstable::MacroBlockId ¯o_block_id, const int64_t read_size, const int64_t begin_offset, - common::ObIOFlag io_flag, const int64_t io_timeout_ms, blocksstable::ObStorageObjectHandle *handle); - bool is_valid(); - int async_read(std::unique_ptr callback); - OB_INLINE int64_t get_begin_offset() const { return begin_offset_; } - TO_STRING_KV(K(is_inited_), K(macro_block_id_), K(read_size_), K(begin_offset_), - K(io_desc_), K(io_timeout_ms_), KP(object_handle_)); -private: - bool is_inited_; - blocksstable::MacroBlockId macro_block_id_; - int64_t read_size_; - // the begin_offset is in the block - int64_t begin_offset_; - common::ObIOFlag io_desc_; - int64_t io_timeout_ms_; - blocksstable::ObStorageObjectHandle *object_handle_; -}; -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_CACHE_H_ - diff --git a/src/storage/tmp_file/ob_tmp_file_eviction_manager.cpp b/src/storage/tmp_file/ob_tmp_file_eviction_manager.cpp deleted file mode 100644 index 864aa6579d..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_eviction_manager.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_eviction_manager.h" -#include "storage/tmp_file/ob_tmp_file_global.h" - -namespace oceanbase -{ -using namespace storage; -using namespace share; - -namespace tmp_file -{ -void ObTmpFileEvictionManager::destroy() -{ - // int ret = OB_SUCCESS; - // ObSharedNothingTmpFile *file = nullptr; - { - ObSpinLockGuard guard(meta_list_lock_); - file_meta_eviction_list_.reset(); - } - - { - ObSpinLockGuard guard(data_list_lock_); - file_data_eviction_list_.reset(); - } -} - -int64_t ObTmpFileEvictionManager::get_file_size() -{ - int64_t file_size = 0; - { - ObSpinLockGuard guard(meta_list_lock_); - file_size += file_meta_eviction_list_.get_size(); - } - { - ObSpinLockGuard guard(data_list_lock_); - file_size += file_data_eviction_list_.get_size(); - } - return file_size; -} - -int ObTmpFileEvictionManager::add_file(const bool is_meta, ObSharedNothingTmpFile &file) -{ - int ret = OB_SUCCESS; - ObSpinLock &lock = is_meta ? meta_list_lock_ : data_list_lock_; - TmpFileEvictionList &eviction_list = is_meta ? file_meta_eviction_list_ : file_data_eviction_list_; - ObSharedNothingTmpFile::ObTmpFileNode &eviction_node = is_meta ? file.get_meta_eviction_node() : file.get_data_eviction_node(); - - ObSpinLockGuard guard(lock); - file.inc_ref_cnt(); - if (OB_UNLIKELY(!eviction_list.add_last(&eviction_node))) { - file.dec_ref_cnt(); - ret = OB_ERR_UNEXPECTED; - } - - return ret; -} - -int ObTmpFileEvictionManager::remove_file(ObSharedNothingTmpFile &file) -{ - return ObTmpFileGlobal::remove_from_meta_and_data_lists( - [this, &file](const bool is_meta) { return remove_file(is_meta, file); }); -} - -int ObTmpFileEvictionManager::remove_file(const bool is_meta, ObSharedNothingTmpFile &file) -{ - int ret = OB_SUCCESS; - ObSpinLock &lock = is_meta ? meta_list_lock_ : data_list_lock_; - TmpFileEvictionList &eviction_list = is_meta ? file_meta_eviction_list_ : file_data_eviction_list_; - ObSharedNothingTmpFile::ObTmpFileNode &eviction_node = is_meta ? file.get_meta_eviction_node() : file.get_data_eviction_node(); - ObSpinLockGuard guard(lock); - if (OB_NOT_NULL(eviction_node.get_next())) { - if (OB_UNLIKELY(!eviction_list.remove(&eviction_node))) { - ret = OB_ERR_UNEXPECTED; - } else { - file.dec_ref_cnt(); - } - } - - return ret; -} - -int ObTmpFileEvictionManager::evict(const int64_t expected_evict_page_num, int64_t &actual_evict_page_num) -{ - int ret = OB_SUCCESS; - int64_t remain_evict_page_num = expected_evict_page_num; - actual_evict_page_num = 0; - - int64_t actual_evict_data_page_num = 0; - if (OB_FAIL(evict_file_from_list_(false/*is_meta*/, remain_evict_page_num, actual_evict_data_page_num))) { - } else { - remain_evict_page_num -= actual_evict_data_page_num; - actual_evict_page_num += actual_evict_data_page_num; - } - - int64_t actual_evict_meta_page_num = 0; - if (FAILEDx(evict_file_from_list_(true/*is_meta*/, remain_evict_page_num, actual_evict_meta_page_num))) { - } else { - remain_evict_page_num -= actual_evict_meta_page_num; - actual_evict_page_num += actual_evict_meta_page_num; - } - - return ret; -} - -int ObTmpFileEvictionManager::evict_file_from_list_(const bool &is_meta, - const int64_t expected_evict_page_num, - int64_t &actual_evict_page_num) -{ - int ret = OB_SUCCESS; - bool is_empty_list = false; - int64_t remain_evict_page_num = expected_evict_page_num; - actual_evict_page_num = 0; - - // attention: - // in order to avoid repeated inserting file node into list by flush manager, - // even thought evict manager has popped file from list, - // we also keep the file's `is_in_meta_eviction_list_` or `is_in_data_eviction_list_` be true. - // in evict_page() of file, if `remain_flushed_file_page_num` > 0, it will reinsert file node - // into eviction list; otherwise, it will set `is_in_meta_eviction_list_` or `is_in_data_eviction_list_` be false - - int64_t list_cnt = - is_meta ? file_meta_eviction_list_.get_size() : file_data_eviction_list_.get_size(); - - while(OB_SUCC(ret) && remain_evict_page_num > 0 && !is_empty_list && list_cnt-- > 0) { - ObSNTmpFileHandle file_handle; - int64_t actual_evict_file_page_num = 0; - int64_t remain_flushed_file_page_num = 0; - if (OB_FAIL(pop_file_from_list_(is_meta, file_handle))) { - if (OB_EMPTY_RESULT == ret) { - ret = OB_SUCCESS; - is_empty_list = true; - } else { - } - } else if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (is_meta) { - if (OB_FAIL(file_handle.get()->evict_meta_pages(remain_evict_page_num, - actual_evict_file_page_num))) { - } - } else { - if (OB_FAIL(file_handle.get()->evict_data_pages(remain_evict_page_num, - actual_evict_file_page_num, - remain_flushed_file_page_num))) { - } else if (OB_UNLIKELY(remain_evict_page_num > actual_evict_file_page_num && remain_flushed_file_page_num > 1)) { - // we allow to not evict the last data page - ret = OB_ERR_UNEXPECTED; - } - } - - if (OB_SUCC(ret)) { - remain_evict_page_num -= actual_evict_file_page_num; - actual_evict_page_num += actual_evict_file_page_num; - } - } - - return ret; -} - -int ObTmpFileEvictionManager::pop_file_from_list_(const bool &is_meta, ObSNTmpFileHandle &file_handle) -{ - int ret = OB_SUCCESS; - file_handle.reset(); - ObSharedNothingTmpFile *file = nullptr; - ObSpinLock &lock = is_meta ? meta_list_lock_ : data_list_lock_; - TmpFileEvictionList &eviction_list = is_meta ? file_meta_eviction_list_ : file_data_eviction_list_; - - ObSpinLockGuard guard(lock); - if (eviction_list.is_empty()) { - ret = OB_EMPTY_RESULT; - } else if (OB_ISNULL(file = &eviction_list.remove_first()->file_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(file_handle.init(file))) { - ret = OB_ERR_UNEXPECTED; - } else { - file->dec_ref_cnt(); - } - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_eviction_manager.h b/src/storage/tmp_file/ob_tmp_file_eviction_manager.h deleted file mode 100644 index 18884ca505..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_eviction_manager.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_ELIMINATION_MANAGER_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_ELIMINATION_MANAGER_H_ - -#include "storage/blocksstable/ob_macro_block_id.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "lib/allocator/ob_fifo_allocator.h" -#include "lib/list/ob_dlist.h" -#include "lib/lock/ob_spin_lock.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileEvictionManager -{ -public: - typedef ObSharedNothingTmpFile::ObTmpFileNode TmpFileNode; - typedef common::ObDList TmpFileEvictionList; - -public: - ObTmpFileEvictionManager() : data_list_lock_(), file_data_eviction_list_(), - meta_list_lock_(), file_meta_eviction_list_() {} - ~ObTmpFileEvictionManager() { destroy(); } - void destroy(); - int64_t get_file_size(); - int add_file(const bool is_meta, ObSharedNothingTmpFile &file); - int remove_file(ObSharedNothingTmpFile &file); - int remove_file(const bool is_meta, ObSharedNothingTmpFile &file); - int evict(const int64_t expected_evict_page_num, int64_t &actual_evict_page_num); - -private: - int evict_file_from_list_(const bool &is_meta, const int64_t expected_evict_page_num, int64_t &actual_evict_page_num); - int pop_file_from_list_(const bool &is_meta, ObSNTmpFileHandle &file_handle); -private: - ObSpinLock data_list_lock_; - TmpFileEvictionList file_data_eviction_list_; - ObSpinLock meta_list_lock_; - TmpFileEvictionList file_meta_eviction_list_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase - -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_ELIMINATION_MANAGER_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_flush_ctx.cpp b/src/storage/tmp_file/ob_tmp_file_flush_ctx.cpp deleted file mode 100644 index 848a664ac2..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_ctx.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_flush_ctx.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -ObTmpFileWriteBlockTask::ObTmpFileWriteBlockTask(ObTmpFileFlushTask &flush_task) - : flush_task_(flush_task) -{ -} - -void ObTmpFileWriteBlockTask::runTimerTask() -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(flush_task_.write_one_block())) { - } - - flush_task_.atomic_set_write_block_ret_code(ret); - flush_task_.atomic_set_write_block_executed(true); -} - -ObTmpFileFlushInfo::ObTmpFileFlushInfo() - : fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - type_(Type::INVALID), - batch_flush_idx_(0), - has_last_page_lock_(false), - insert_meta_tree_done_(false), - update_meta_data_done_(false), - file_handle_(), - flush_data_page_disk_begin_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - flush_data_page_num_(-1), - flush_virtual_page_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID), - file_size_(0) -{ -} - -void ObTmpFileFlushInfo::reset() -{ - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - type_ = Type::INVALID; - batch_flush_idx_ = 0; - has_last_page_lock_ = false; - insert_meta_tree_done_ = false; - update_meta_data_done_ = false; - file_handle_.reset(); - flush_data_page_disk_begin_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flush_data_page_num_ = -1; - flush_virtual_page_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - file_size_ = 0; -} - -int ObTmpFileFlushInfo::assign(const ObTmpFileFlushInfo &other) -{ - int ret = OB_SUCCESS; - fd_ = other.fd_; - type_ = other.type_; - batch_flush_idx_ = other.batch_flush_idx_; - has_last_page_lock_ = other.has_last_page_lock_; - insert_meta_tree_done_ = other.insert_meta_tree_done_; - update_meta_data_done_ = other.update_meta_data_done_; - file_handle_ = other.file_handle_; - flush_data_page_disk_begin_id_ = other.flush_data_page_disk_begin_id_; - flush_data_page_num_ = other.flush_data_page_num_; - flush_virtual_page_id_ = other.flush_virtual_page_id_; - file_size_ = other.file_size_; - return ret; -} - -// -------------- ObTmpFileBatchFlushContext --------------- // - -int ObTmpFileBatchFlushContext::init() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_FAIL(file_ctx_hash_.create(256, ObMemAttr("TFileFLCtx")))) { - } else { - flush_failed_array_.set_attr(ObMemAttr("TFFlushFailArr")); - state_ = FlushCtxState::FSM_F1; - is_inited_ = true; - } - return ret; -} - -int ObTmpFileBatchFlushContext::prepare_flush_ctx( - const int64_t expect_flush_size, - ObTmpFileFlushPriorityManager *prio_mgr, - ObTmpFileFlushMonitor *flush_monitor) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(expect_flush_size <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_ISNULL(prio_mgr) || OB_ISNULL(flush_monitor)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(flush_failed_array_.reserve(MAX_COPY_FAIL_COUNT))) { - } else if (OB_FAIL(iter_.init(prio_mgr))) { - } else { - expect_flush_size_ = expect_flush_size; - flush_monitor_ptr_ = flush_monitor; - } - - if (OB_FAIL(ret)) { - flush_failed_array_.reset(); - iter_.reset(); - LOG_INFO("failed to prepare flush ctx, rollback ctx", KR(ret), KPC(this)); - } - return ret; -} - -int ObTmpFileBatchFlushContext::clear_flush_ctx(ObTmpFileFlushPriorityManager &prio_mgr) -{ - int ret = OB_SUCCESS; - // insert the remaining files in the iterator back into the flush priority manager - if (OB_FAIL(iter_.reset())) { - } - - // insert the files that failed to copy data back into the flush queue. after this step, - // call files taken out by the iterator for this round - // (excluding files with no dirty pages) will appear in the flush priority manager. - for (int64_t i = 0; i < flush_failed_array_.count(); i++) { - const ObTmpFileFlushFailRecord &record = flush_failed_array_.at(i); - const ObSNTmpFileHandle &file_handle = record.file_handle_; - if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("file handle is nullptr", KR(ret)); - } else { - ObSharedNothingTmpFile &file = *file_handle.get(); - if (record.is_meta_) { - if (OB_FAIL(file.reinsert_meta_flush_node())) { - } - } else { - if (OB_FAIL(file.reinsert_data_flush_node())) { - } - } - } - } - - if (OB_FAIL(ret)) { - } else if (flush_seq_ctx_.prepare_finished_cnt_ == flush_seq_ctx_.create_flush_task_cnt_) { - flush_seq_ctx_.prepare_finished_cnt_ = 0; - flush_seq_ctx_.create_flush_task_cnt_ = 0; - flush_seq_ctx_.flush_sequence_ += 1; - // remove the files that have already been successfully flushed(recorded in file_ctx_hash_) - // from flush priority manager, ensuring that these files do not trigger flushing - // before the completion of this round of flush IO. - RemoveFileOp remove_op(prio_mgr); - if (OB_FAIL(file_ctx_hash_.foreach_refactored(remove_op))) { - } else { - file_ctx_hash_.clear(); - } - } else if (flush_seq_ctx_.prepare_finished_cnt_ < flush_seq_ctx_.create_flush_task_cnt_) { - // likely to occur when write buffer pool is full and need to fast flush meta page - LOG_WARN("flush_seq_ctx_ could not increase flush sequence", KPC(this)); - } else if (OB_UNLIKELY(flush_seq_ctx_.prepare_finished_cnt_ > flush_seq_ctx_.create_flush_task_cnt_)) { - LOG_ERROR("unexpected flush_seq_ctx_", KPC(this)); - } - - fail_too_many_ = false; - expect_flush_size_ = 0; - actual_flush_size_ = 0; - iter_.destroy(); - flush_failed_array_.reset(); - state_ = FlushCtxState::FSM_F1; - return ret; -} - -int ObTmpFileBatchFlushContext::RemoveFileOp::operator () (hash::HashMapPair &kv) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle &file_handle = kv.second.file_handle_; - if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else { - // remove all flush nodes for this file to prevent repeated flushing when flushing only data page or only meta page, - // this avoids triggering a data page flush while waiting for I/O on meta pages, which could lead to new data items - // being inserted to the flushing meta page, causing the memory meta page to become inconsistent with the page on disk. - ObSharedNothingTmpFile &file = *file_handle.get(); - if (file.is_flushing()) { - if (OB_FAIL(file.remove_data_flush_node())) { - } else if (OB_FAIL(file.remove_meta_flush_node())) { - } else { - } - } - } - return ret; -} - -void ObTmpFileBatchFlushContext::destroy() -{ - is_inited_ = false; - fail_too_many_ = false; - expect_flush_size_ = 0; - actual_flush_size_ = 0; - flush_monitor_ptr_ = nullptr; - state_ = FlushCtxState::FSM_F1; - iter_.destroy(); - flush_failed_array_.reset(); - file_ctx_hash_.destroy(); -} - -void ObTmpFileBatchFlushContext::update_actual_flush_size(const ObTmpFileFlushTask &flush_task) -{ - actual_flush_size_ += flush_task.get_data_length(); -} - -void ObTmpFileBatchFlushContext::try_update_prepare_finished_cnt(const ObTmpFileFlushTask &flush_task, bool& recorded) -{ - int ret = OB_SUCCESS; - - recorded = false; - if (OB_UNLIKELY(flush_seq_ctx_.prepare_finished_cnt_ >= flush_seq_ctx_.create_flush_task_cnt_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected flush_seq_ctx_", KPC(this)); - } else if (ObTmpFileFlushTask::TFFT_WAIT == flush_task.get_state() || - ObTmpFileFlushTask::TFFT_ABORT == flush_task.get_state() || - flush_task.get_data_length() == 0) { - ++flush_seq_ctx_.prepare_finished_cnt_; - recorded = true; - } -} - -void ObTmpFileBatchFlushContext::record_flush_stage() -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_monitor_ptr_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("flush monitor is null", KR(ret)); - } else { - flush_monitor_ptr_->record_flush_stage(state_); - } -} - -void ObTmpFileBatchFlushContext::record_flush_task(const int64_t data_length) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_monitor_ptr_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("flush monitor is null", KR(ret)); - } else { - flush_monitor_ptr_->record_flush_task(data_length); - } -} - -// -------------- ObTmpFileFlushTask --------------- // - -ObTmpFileFlushTask::ObTmpFileFlushTask() - : inst_handle_(), - kvpair_(nullptr), - block_handle_(), - flush_page_id_arr_(), - write_block_ret_code_(OB_SUCCESS), - io_result_ret_code_(OB_SUCCESS), - data_length_(0), - block_index_(-1), - flush_seq_(-1), - create_ts_(-1), - is_write_block_executed_(false), - is_io_finished_(false), - fast_flush_tree_page_(false), - recorded_as_prepare_finished_(false), - type_(TaskType::INVALID), - task_state_(ObTmpFileFlushTaskState::TFFT_INITED), - tmp_file_block_handle_(), - handle_(), - flush_infos_(), - flush_write_block_task_(*this) -{ - flush_infos_.set_attr(ObMemAttr("TFFlushInfos")); -} - -void ObTmpFileFlushTask::destroy() -{ - flush_write_block_task_.~ObTmpFileWriteBlockTask(); - // flush task io buffer is allocated in kv cache, and we hold its memory by keeping block_handle_. - // since buffer's memory life cycle must be longer than the object handle, - // the handle_ must be reset before block_handle_. - handle_.reset(); - block_handle_.reset(); - flush_page_id_arr_.reset(); - inst_handle_.reset(); - kvpair_ = nullptr; - write_block_ret_code_ = OB_SUCCESS; - io_result_ret_code_ = OB_SUCCESS; - data_length_ = 0; - block_index_ = -1; - flush_seq_ = -1; - create_ts_ = -1; - is_write_block_executed_ = false; - is_io_finished_ = false; - fast_flush_tree_page_ = false; - recorded_as_prepare_finished_ = false; - type_ = TaskType::INVALID; - task_state_ = ObTmpFileFlushTaskState::TFFT_INITED; - tmp_file_block_handle_.reset(); - flush_infos_.reset(); -} - -int ObTmpFileFlushTask::prealloc_block_buf() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(ObTmpBlockCache::get_instance().prealloc_block( - ObTmpBlockCacheKey(block_index_), inst_handle_, kvpair_, block_handle_))) { - } - return ret; -} - -int ObTmpFileFlushTask::lazy_alloc_and_fill_block_buf_for_data_page_() -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(flush_page_id_arr_.count() <= 0 || - flush_page_id_arr_.count() > ObTmpFileGlobal::BLOCK_PAGE_NUMS || - flush_page_id_arr_.count() != upper_align(data_length_, ObTmpFileGlobal::ALLOC_PAGE_SIZE) / ObTmpFileGlobal::ALLOC_PAGE_SIZE)){ - ret = OB_ERR_UNEXPECTED; - } else if (flush_infos_.size() == 0) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_ISNULL(wbp_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(prealloc_block_buf())) { - } else { - char* page_buf = nullptr; - int32_t copy_index = 0; - for (int32_t i = 0; OB_SUCC(ret) && i < flush_infos_.count(); ++i) { - ObTmpFileFlushInfo &flush_info = flush_infos_.at(i); - int64_t cur_info_fd = flush_info.fd_; - int64_t cur_info_disk_begin_id = flush_info.flush_data_page_disk_begin_id_; - int64_t cur_info_page_num = flush_info.flush_data_page_num_; - int64_t cur_info_virtual_page_id = flush_info.flush_virtual_page_id_; - if (copy_index != cur_info_disk_begin_id) { - ret = OB_ERR_UNEXPECTED; - } - while (OB_SUCC(ret) && copy_index < cur_info_disk_begin_id + cur_info_page_num - && copy_index < flush_page_id_arr_.count()) { - uint32_t page_id = flush_page_id_arr_.at(copy_index); - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; // UNUSED - if (OB_FAIL(wbp_->read_page(cur_info_fd, page_id, ObTmpFilePageUniqKey(cur_info_virtual_page_id), page_buf, next_page_id))) { - } else if (OB_UNLIKELY(!check_buf_range_valid(get_data_buf(), ObTmpFileGlobal::ALLOC_PAGE_SIZE))) { - ret = OB_ERR_UNEXPECTED; - } else { - // only copy the size we recorded if we need to flush the last page - // since we do not hold last_page_lock and the last page may be appended - int64_t copy_size = flush_info.file_size_ != 0 && cur_info_disk_begin_id + cur_info_page_num - 1 == copy_index ? - flush_info.file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE : ObTmpFileGlobal::ALLOC_PAGE_SIZE; - MEMCPY(get_data_buf() + copy_index * ObTmpFileGlobal::ALLOC_PAGE_SIZE, page_buf, copy_size); - } - copy_index += 1; - cur_info_virtual_page_id += 1; - } - } - - if (OB_FAIL(ret)) { - } - - // release truncate_lock regardless of ret - for (int32_t i = 0; i < flush_infos_.count(); ++i) { - flush_infos_.at(i).file_handle_.get()->copy_finish(); - } - - if (OB_SUCC(ret)) { - int tmp_ret = OB_SUCCESS; - if (TaskType::DATA != type_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid task type when copy data in writing block", KR(ret), KPC(this)); - } else if (OB_TMP_FAIL(ObTmpBlockCache::get_instance().put_block(get_inst_handle(), - get_kvpair(), - get_block_handle()))) { - } - } - } - return ret; -} - -int ObTmpFileFlushTask::write_one_block() -{ - int ret = OB_SUCCESS; - handle_.reset(); - - if (!block_handle_.is_valid()) { - if (TaskType::DATA != type_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("block handle is null when writing non data task", KR(ret), KPC(this)); - } else if (OB_FAIL(lazy_alloc_and_fill_block_buf_for_data_page_())) { - } - } - - static const int64_t SEND_IO_WARN_TIMEOUT_US = 30 * 1000 * 1000; // 30s - if (ObTimeUtil::current_time() - get_create_ts() > SEND_IO_WARN_TIMEOUT_US) { // debug log - LOG_WARN("flush task send io takes too much time", KPC(this)); - } - - if (OB_SUCC(ret)) { - blocksstable::ObMacroBlockWriteInfo write_info; - write_info.io_desc_.set_sys_module_id(ObIOModule::TMP_MEM_BLOCK_IO); - write_info.buffer_ = get_data_buf(); - write_info.size_ = upper_align(get_data_length(), ObTmpFileGlobal::ALLOC_PAGE_SIZE); - write_info.offset_ = 0; - if (OB_FAIL(blocksstable::ObBlockManager::async_write_block(write_info, handle_))) { - } else if (OB_FAIL(OB_SERVER_BLOCK_MGR.update_write_time(handle_.get_macro_id(), - true/*update_to_max_time)*/))){ - } - } - return ret; -} - -// async wait, return OB_EAGAIN immediately if IO is not finished -int ObTmpFileFlushTask::wait_macro_block_handle() -{ - int ret = OB_SUCCESS; - int64_t wait_timeout_ms = 0; // timeout == 0 for async wait - if (OB_FAIL(handle_.wait(wait_timeout_ms))) { - if (OB_EAGAIN == ret) { - // do nothing - } else { - atomic_set_ret_code(ret); - atomic_set_io_finished(true); - ret = OB_SUCCESS; - } - } else { - atomic_set_ret_code(OB_SUCCESS); - atomic_set_io_finished(true); - } - return ret; -} - -int64_t ObTmpFileFlushTask::get_total_page_num() const -{ - const int64_t ALLOC_PAGE_SIZE = ObTmpFileGlobal::ALLOC_PAGE_SIZE; - return upper_align(data_length_, ALLOC_PAGE_SIZE) / ALLOC_PAGE_SIZE; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_flush_ctx.h b/src/storage/tmp_file/ob_tmp_file_flush_ctx.h deleted file mode 100644 index e2552d4563..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_ctx.h +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_CTX_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_CTX_H_ - -#include "lib/queue/ob_link_queue.h" -#include "lib/utility/ob_print_utils.h" -#include "storage/tmp_file/ob_tmp_file_block_manager.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_tmp_file_flush_list_iterator.h" -#include "storage/tmp_file/ob_tmp_file_meta_tree.h" -#include "storage/tmp_file/ob_tmp_file_thread_job.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileFlushThread; - -class ObTmpFileWriteBlockTask : public common::ObTimerTask -{ -public: - explicit ObTmpFileWriteBlockTask(ObTmpFileFlushTask &flush_task); - virtual ~ObTmpFileWriteBlockTask() {} - virtual void runTimerTask() override; -private: - ObTmpFileFlushTask &flush_task_; -}; - -struct ObTmpFileDataFlushContext -{ -public: - ObTmpFileDataFlushContext () - : is_valid_(false), - has_flushed_last_partially_written_page_(false), - flushed_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - flushed_page_virtual_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID), - next_flush_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - next_flush_page_virtual_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID) {} - - ~ObTmpFileDataFlushContext () { reset(); } - void reset() { - is_valid_ = false; - has_flushed_last_partially_written_page_ = false; - flushed_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flushed_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - next_flush_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - next_flush_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } - OB_INLINE bool is_valid() const { return is_valid_; } - OB_INLINE void set_is_valid(const bool is_valid) { is_valid_ = is_valid; } - OB_INLINE bool has_flushed_last_partially_written_page() const { - return has_flushed_last_partially_written_page_; - } - OB_INLINE void set_has_flushed_last_partially_written_page(bool has_flushed_last_partially_written_page) { - has_flushed_last_partially_written_page_ = has_flushed_last_partially_written_page; - } - OB_INLINE uint32_t get_flushed_page_id() const { return flushed_page_id_; } - OB_INLINE void set_flushed_page_id(const uint32_t flushed_page_id) { flushed_page_id_ = flushed_page_id; } - OB_INLINE int64_t get_flushed_page_virtual_id() const { - return flushed_page_virtual_id_; - } - OB_INLINE void set_flushed_page_virtual_id(int64_t virtual_page_id) { - flushed_page_virtual_id_ = virtual_page_id; - } - OB_INLINE uint32_t get_next_flush_page_id() const { return next_flush_page_id_; } - OB_INLINE void set_next_flush_page_id(const uint32_t next_flush_page_id) { - next_flush_page_id_ = next_flush_page_id; - } - OB_INLINE void set_next_flush_page_virtual_id(const int64_t virtual_page_id) { - next_flush_page_virtual_id_ = virtual_page_id; - } - OB_INLINE int64_t get_next_flush_page_virtual_id() const { return next_flush_page_virtual_id_; } - TO_STRING_KV(K(is_valid_), K(has_flushed_last_partially_written_page_), K(flushed_page_id_), - K(flushed_page_virtual_id_), - K(next_flush_page_id_), K(next_flush_page_virtual_id_)); -public: - bool is_valid_; - bool has_flushed_last_partially_written_page_; - uint32_t flushed_page_id_; - int64_t flushed_page_virtual_id_; - uint32_t next_flush_page_id_; - int64_t next_flush_page_virtual_id_; -}; - -struct ObTmpFileSingleFlushContext -{ -public: - ObTmpFileSingleFlushContext() : file_handle_(), data_ctx_(), meta_ctx_() {} - ObTmpFileSingleFlushContext(ObSNTmpFileHandle file_handle) : file_handle_(file_handle), data_ctx_(), meta_ctx_() {} - TO_STRING_KV(K(file_handle_), K(data_ctx_), K(meta_ctx_)); -public: - ObSNTmpFileHandle file_handle_; - ObTmpFileDataFlushContext data_ctx_; - ObTmpFileTreeFlushContext meta_ctx_; -}; - -// The ObTmpFileFlushManager maintains multiple file flushing contexts during a round of flushing -class ObTmpFileBatchFlushContext -{ -public: - ObTmpFileBatchFlushContext() - : is_inited_(), - fail_too_many_(false), - expect_flush_size_(0), - actual_flush_size_(0), - flush_seq_ctx_(), - flush_monitor_ptr_(nullptr), - state_(ObTmpFileGlobal::FlushCtxState::FSM_F1), - iter_(), - file_ctx_hash_(), - flush_failed_array_() - { - } - ~ObTmpFileBatchFlushContext() { destroy(); } - int init(); - int prepare_flush_ctx(const int64_t expect_flush_size, - ObTmpFileFlushPriorityManager *prio_mgr, - ObTmpFileFlushMonitor *flush_monitor); - int clear_flush_ctx(ObTmpFileFlushPriorityManager &prio_mgr); - void destroy(); - void record_flush_stage(); - void record_flush_task(const int64_t data_length); - void update_actual_flush_size(const ObTmpFileFlushTask &flush_task); - void try_update_prepare_finished_cnt(const ObTmpFileFlushTask &flush_task, bool& recorded); -public: - static const int64_t MAX_COPY_FAIL_COUNT = 512; - typedef hash::ObHashMap ObTmpFileFlushCtxHash; - struct ObTmpFileFlushFailRecord - { - public: - ObTmpFileFlushFailRecord() : is_meta_(false), file_handle_() {} - ObTmpFileFlushFailRecord(bool is_meta, ObSNTmpFileHandle file_handle) : is_meta_(is_meta), file_handle_(file_handle) {} - TO_STRING_KV(K(is_meta_), K(file_handle_)); - public: - bool is_meta_; - ObSNTmpFileHandle file_handle_; - }; - struct FlushSequenceContext - { - FlushSequenceContext() : create_flush_task_cnt_(0), prepare_finished_cnt_(0), flush_sequence_(0) {} - int64_t create_flush_task_cnt_; // created flush task number in one round - int64_t prepare_finished_cnt_; - int64_t flush_sequence_; // increate flush seq only when all task in this round send io succ - TO_STRING_KV(K(create_flush_task_cnt_), K(prepare_finished_cnt_), K(flush_sequence_)); - }; - struct RemoveFileOp - { - public: - RemoveFileOp(ObTmpFileFlushPriorityManager &flush_priority_mgr) : flush_priority_mgr_(flush_priority_mgr) {} - int operator () (hash::HashMapPair &kv); - private: - ObTmpFileFlushPriorityManager &flush_priority_mgr_; - }; - bool can_clear_flush_ctx() const - { - return flush_seq_ctx_.prepare_finished_cnt_ == flush_seq_ctx_.create_flush_task_cnt_ && - flush_seq_ctx_.prepare_finished_cnt_ > 0; - } - OB_INLINE void set_fail_too_many(const bool fail_too_many) { fail_too_many_ = fail_too_many; } - OB_INLINE bool is_fail_too_many() { return fail_too_many_; } - OB_INLINE ObTmpFileFlushListIterator &get_flush_list_iterator() { return iter_; } - OB_INLINE void set_expect_flush_size(const int64_t flush_size) { expect_flush_size_ = flush_size; } - OB_INLINE int64_t get_expect_flush_size() { return expect_flush_size_; } - OB_INLINE void add_actual_flush_size(const int64_t flush_size) { actual_flush_size_ += flush_size; } - OB_INLINE int64_t get_actual_flush_size() { return actual_flush_size_; } - OB_INLINE bool is_inited() { return is_inited_; } - OB_INLINE void set_state(const FlushCtxState state) { state_ = state; } - OB_INLINE FlushCtxState get_state() { return state_; } - OB_INLINE ObTmpFileFlushCtxHash &get_file_ctx_hash() { return file_ctx_hash_; } - OB_INLINE ObArray &get_flush_failed_array() { return flush_failed_array_; } - OB_INLINE ObTmpFileFlushMonitor *get_flush_monitor() { return flush_monitor_ptr_; } - OB_INLINE void inc_create_flush_task_cnt() { ++flush_seq_ctx_.create_flush_task_cnt_; } - OB_INLINE int64_t get_flush_sequence() { return flush_seq_ctx_.flush_sequence_; } - TO_STRING_KV(K(is_inited_), K(fail_too_many_), K(expect_flush_size_), K(actual_flush_size_), - K(flush_seq_ctx_), K(state_), K(iter_), K(file_ctx_hash_.size()), K(flush_failed_array_.size())); -private: - bool is_inited_; - bool fail_too_many_; // indicate wether the number of file copy failures exceeds MAX_COPY_FAIL_COUNT in one round. - int64_t expect_flush_size_; - int64_t actual_flush_size_; - FlushSequenceContext flush_seq_ctx_; - ObTmpFileFlushMonitor *flush_monitor_ptr_; - FlushCtxState state_; - ObTmpFileFlushListIterator iter_; - ObTmpFileFlushCtxHash file_ctx_hash_; // maintain the data/meta flushing offset for each file in one round - ObArray flush_failed_array_; // record files that failed to copy data/meta pages, re-insert them into flush priority mgr - // after the iteration ends to prevent these files from appearing multiple times in flush iterator. -}; - -// represent up to 2MB flush information of a file, -// if a macro block contains multiple tmp files, it will include multiple flush infos -struct ObTmpFileFlushInfo -{ -public: - enum Type { - INVALID = 0, - DATA, - META - }; - ObTmpFileFlushInfo(); - ~ObTmpFileFlushInfo() { reset(); } - void reset(); - bool has_data() const { return Type::DATA == type_ && flush_data_page_num_ > 0; } - bool has_meta() const { return Type::META == type_; } - int assign(const ObTmpFileFlushInfo &other); - TO_STRING_KV(K(fd_), K(batch_flush_idx_), K(has_last_page_lock_), K(insert_meta_tree_done_), K(update_meta_data_done_), - K(flush_data_page_disk_begin_id_), K(flush_data_page_num_), K(flush_virtual_page_id_), K(file_size_), - KP(file_handle_.get())); -public: - int64_t fd_; - Type type_; - int64_t batch_flush_idx_; // during one round of flushing, multiple FlushInfo may be generated. - // records the sequence number to which this info belongs (starting from 0). - bool has_last_page_lock_; // indicate the last page is in flushing and holds last_page_lock_ in file - bool insert_meta_tree_done_; // indicate the insertion of the corresponding data item into the meta tree is completed - bool update_meta_data_done_; // indicate the file metadata or metadata tree update is completed - ObSNTmpFileHandle file_handle_; - - // information for updating data - int64_t flush_data_page_disk_begin_id_; // record begin page id in the macro block, for updating meta tree item - int64_t flush_data_page_num_; - int64_t flush_virtual_page_id_; // record virtual_page_id while copying data, pass to meta tree while inserting items - int64_t file_size_; // if file_size > 0, it means the last page is in flushing -}; - -// Each ObTmpFileFlushTask corresponds to a flushing macro block, which can be exclusively used by one file -// or shared by multiple files based on observer config. The task internally maintains the state machine, -// and the ObTmpFileFlushManager continuously advances each task to TFFT_FINISH terminal state. -// Each task that are higher than TFFT_FILL_BLOCK_BUF will be retried if errors occurred. -struct ObTmpFileFlushTask : public common::ObSpLinkQueue::Link -{ -public: - ObTmpFileFlushTask(); - virtual ~ObTmpFileFlushTask() { destroy(); } - enum ObTmpFileFlushTaskState - { - TFFT_INITED = 0, - TFFT_ALLOC_BLOCK_BUF = 1, - TFFT_CREATE_BLOCK_INDEX = 2, - TFFT_FILL_BLOCK_BUF = 3, - TFFT_INSERT_META_TREE = 4, - TFFT_ASYNC_WRITE = 5, - TFFT_WAIT = 6, - TFFT_FINISH = 7, - TFFT_ABORT = 8, - }; - enum TaskType - { - INVALID = -1, - DATA = 0, - META = 1, - }; -public: - void destroy(); - int prealloc_block_buf(); - virtual int write_one_block(); - virtual int wait_macro_block_handle(); - int64_t get_total_page_num() const; - OB_INLINE ObKVCacheInstHandle& get_inst_handle() { return inst_handle_; } - OB_INLINE ObKVCachePair*& get_kvpair() { return kvpair_; } - OB_INLINE ObTmpBlockValueHandle& get_block_handle() { return block_handle_; } - OB_INLINE bool is_valid() const { return OB_NOT_NULL(get_data_buf()); } - OB_INLINE bool is_full() const { return data_length_ == OB_STORAGE_OBJECT_MGR.get_macro_object_size(); } - OB_INLINE char *get_data_buf() const { return block_handle_.value_ == nullptr ? nullptr : block_handle_.value_->get_buffer(); } - OB_INLINE ObSEArray& get_flush_page_id_arr() { - return flush_page_id_arr_; - } - OB_INLINE void atomic_set_ret_code(int ret_code) { ATOMIC_SET(&io_result_ret_code_, ret_code); } - OB_INLINE int atomic_get_ret_code() const { return ATOMIC_LOAD(&io_result_ret_code_); } - OB_INLINE void atomic_set_write_block_ret_code(int write_block_ret_code) { - ATOMIC_SET(&write_block_ret_code_, write_block_ret_code); - } - OB_INLINE int atomic_get_write_block_ret_code() const { - return ATOMIC_LOAD(&write_block_ret_code_); - } - OB_INLINE void set_data_length(const int64_t len) { data_length_ = len; } - OB_INLINE int64_t get_data_length() const { return data_length_; } - OB_INLINE void set_block_index(const int64_t block_index) { block_index_ = block_index; } - OB_INLINE int64_t get_block_index() const { return block_index_; } - OB_INLINE void set_flush_seq(const int64_t flush_seq) { flush_seq_ = flush_seq; } - OB_INLINE int64_t get_flush_seq() const { return flush_seq_; } - OB_INLINE void set_create_ts(const int64_t create_ts) { create_ts_ = create_ts; } - OB_INLINE int64_t get_create_ts() const { return create_ts_; } - OB_INLINE void set_last_print_ts(const int64_t print_ts) { last_print_ts_ = print_ts; } - OB_INLINE int64_t get_last_print_ts() const { return last_print_ts_; } - OB_INLINE void atomic_set_io_finished(const bool is_finished) { ATOMIC_SET(&is_io_finished_, is_finished); } - OB_INLINE bool atomic_get_io_finished() const { return ATOMIC_LOAD(&is_io_finished_); } - OB_INLINE void set_is_fast_flush_tree(const bool is_fast_flush_tree) { fast_flush_tree_page_ = is_fast_flush_tree; } - OB_INLINE bool get_is_fast_flush_tree() const { return fast_flush_tree_page_; } - OB_INLINE void mark_recorded_as_prepare_finished() { recorded_as_prepare_finished_ = true; } - OB_INLINE bool get_recorded_as_prepare_finished() const { return recorded_as_prepare_finished_; } - OB_INLINE void set_type(TaskType type) { type_ = type; } - OB_INLINE TaskType get_type() const { return type_; } - OB_INLINE void set_state(const ObTmpFileFlushTaskState state) { task_state_ = state; } - OB_INLINE ObTmpFileFlushTaskState get_state() const { return task_state_; } - OB_INLINE void set_tmp_file_block_handle(const ObTmpFileBlockHandle &tfb_handle) { tmp_file_block_handle_ = tfb_handle; } - OB_INLINE ObTmpFileBlockHandle &get_tmp_file_block_handle() { return tmp_file_block_handle_; } - OB_INLINE void set_macro_block_handle(const blocksstable::ObMacroBlockHandle &handle) { handle_ = handle; } - OB_INLINE blocksstable::ObMacroBlockHandle &get_macro_block_handle() { return handle_; } - OB_INLINE ObArray &get_flush_infos() { return flush_infos_; } - OB_INLINE int64_t get_next_free_page_id() { return get_total_page_num(); } - OB_INLINE bool check_buf_range_valid(const char* buffer, const int64_t length) const - { - return buffer != nullptr && get_data_buf() != nullptr && - buffer >= get_data_buf() && buffer + length <= get_data_buf() + OB_STORAGE_OBJECT_MGR.get_macro_object_size(); - } - OB_INLINE void set_buffer_pool_ptr(ObTmpWriteBufferPool *wbp) { wbp_ = wbp; } - OB_INLINE void atomic_set_write_block_executed(const bool executed) { ATOMIC_SET(&is_write_block_executed_, executed); } - OB_INLINE bool atomic_get_write_block_executed() const { return ATOMIC_LOAD(&is_write_block_executed_); } - OB_INLINE ObTmpFileWriteBlockTask& get_flush_write_block_task() { return flush_write_block_task_; } - - TO_STRING_KV(KP(this), KP(kvpair_), K(io_result_ret_code_), K(block_handle_), K(data_length_), - K(block_index_), K(flush_seq_), K(create_ts_), K(last_print_ts_), K(is_io_finished_), K(handle_), - K(fast_flush_tree_page_), K(recorded_as_prepare_finished_), K(type_), K(task_state_), K(tmp_file_block_handle_), K(flush_infos_), - K(is_write_block_executed_), K(write_block_ret_code_), K(flush_write_block_task_), K(flush_page_id_arr_.count())); -private: - int lazy_alloc_and_fill_block_buf_for_data_page_(); -private: - ObKVCacheInstHandle inst_handle_; - ObKVCachePair *kvpair_; - ObTmpBlockValueHandle block_handle_; - ObSEArray flush_page_id_arr_; - int write_block_ret_code_; - int io_result_ret_code_; - int64_t data_length_; // data length (including padding to make length upper align to page size) - int64_t block_index_; // tmp file block logical index in ObTmpFileBlockManager - int64_t flush_seq_; // flush sequence, for verification purpose - int64_t create_ts_; - int64_t last_print_ts_; // for debug purpose - bool is_write_block_executed_; // set to true if task has sent IO - bool is_io_finished_; // set to true if task has finished async IO - bool fast_flush_tree_page_; // indicate the task requires fast flush tree pages - bool recorded_as_prepare_finished_; // set to true if this task has been recorded by ObTmpFileBatchFlushContext as prepare_finished - TaskType type_; - ObTmpFileFlushTaskState task_state_; - ObTmpFileBlockHandle tmp_file_block_handle_;// hold a reference to the corresponding tmp file block to prevent it from being released - blocksstable::ObMacroBlockHandle handle_; - ObArray flush_infos_; // multi file flush into one block if size > 0 - ObTmpFileWriteBlockTask flush_write_block_task_; - ObTmpWriteBufferPool *wbp_; // use to lazy read data pages -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_CTX_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_flush_list_iterator.cpp b/src/storage/tmp_file/ob_tmp_file_flush_list_iterator.cpp deleted file mode 100644 index 6a455fccfa..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_list_iterator.cpp +++ /dev/null @@ -1,717 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "share/ob_errno.h" -#include "share/rc/ob_server_runtime.h" -#include "storage/tmp_file/ob_tmp_file_flush_list_iterator.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" - -namespace oceanbase -{ -namespace tmp_file -{ -ObTmpFileFlushListIterator::ObTmpFileFlushListIterator() : - is_inited_(false), files_(), dirs_(), cur_caching_list_is_meta_(false), - cur_caching_list_idx_(FileList::L1), - cur_iter_dir_idx_(-1), cur_iter_file_idx_(-1), - cached_file_num_(0), cached_dir_num_(0) -{} - -ObTmpFileFlushListIterator::~ObTmpFileFlushListIterator() -{ - destroy(); -} - -int ObTmpFileFlushListIterator::init(ObTmpFileFlushPriorityManager *prio_mgr) -{ - int ret = OB_SUCCESS; - if (is_inited_) { - ret = OB_INIT_TWICE; - } else if (OB_ISNULL(prio_mgr)) { - ret = OB_INVALID_ARGUMENT; - } else if (FALSE_IT(files_.set_attr(ObMemAttr("TFFlushIterFile")))) { - } else if (OB_FAIL(files_.prepare_allocate(MAX_CACHE_NUM))) { - } else if (FALSE_IT(dirs_.set_attr(ObMemAttr("TFFlushIterDir")))) { - } else if (OB_FAIL(dirs_.prepare_allocate(MAX_CACHE_NUM))) { - } else { - is_inited_ = true; - prio_mgr_ = prio_mgr; - } - return ret; -} - -int ObTmpFileFlushListIterator::clear() -{ - int ret = OB_SUCCESS; - - // reinsert unused cached file into flush list - FlushCtxState cur_stage = cal_current_flush_stage_(); - if (cur_stage < FlushCtxState::FSM_F1 || cur_stage >= FlushCtxState::FSM_FINISHED) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected flush stage", KR(ret), K(cur_stage)); - } else if (0 == cached_file_num_) { - // no need to reinsert files, do nothing - } else if (FlushCtxState::FSM_F1 == cur_stage) { - if (OB_FAIL(reinsert_files_into_flush_list_(cur_iter_file_idx_, cached_file_num_ - 1))){ - } - } else { - for (int64_t i = cur_iter_dir_idx_; OB_SUCC(ret) && (i >= 0 && i < cached_dir_num_); i++) { - if (OB_UNLIKELY(!dirs_[i].is_inited_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("uninitialized dir is unexpected", KR(ret), K(dirs_[i])); - } else { - int64_t start_file_idx = dirs_[i].start_file_idx_; - int64_t end_file_idx = dirs_[i].end_file_idx_; - if (i == cur_iter_dir_idx_) { - start_file_idx = cur_iter_file_idx_; - if (start_file_idx < dirs_[i].start_file_idx_ || start_file_idx > dirs_[i].end_file_idx_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("start file idx not in cur dir range", KR(ret), K(start_file_idx), K(dirs_[i])); - } - } - if (FAILEDx(reinsert_files_into_flush_list_(start_file_idx, end_file_idx))) { - LOG_ERROR("fail to reinsert files into flush list", - KR(ret), K(i), K(dirs_[i]), K(start_file_idx), K(end_file_idx)); - } - } - } - } - - if (OB_SUCC(ret)) { - cur_caching_list_is_meta_ = false; - cur_caching_list_idx_ = FileList::L1; - cur_iter_dir_idx_ = -1; - cur_iter_file_idx_ = -1; - cached_file_num_ = 0; - cached_dir_num_ = 0; - for (int64_t i = 0; i < files_.count(); ++i) { - files_[i].reset(); - } - for (int64_t i = 0; i < dirs_.count(); ++i) { - dirs_[i].reset(); - } - } - - return ret; -} - -int ObTmpFileFlushListIterator::reset() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - if (OB_FAIL(clear())) { - } - is_inited_ = false; - } - return ret; -} - -void ObTmpFileFlushListIterator::destroy() -{ - reset(); -} - -int ObTmpFileFlushListIterator::reinsert_files_into_flush_list_(const int64_t start_file_idx, - const int64_t end_file_idx) -{ - int ret = OB_SUCCESS; - for (int64_t i = start_file_idx; OB_SUCC(ret) && (i >= 0 && i <= end_file_idx); i++) { - if (OB_UNLIKELY(i < 0 || i >= cached_file_num_ || cached_file_num_ > files_.count())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!files_[i].is_inited_)) { - ret = OB_ERR_UNEXPECTED; - } else { - ObSNTmpFileHandle &file_handle = files_[i].file_handle_; - if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (files_[i].is_meta_) { - ObSharedNothingTmpFile *sn_file = file_handle.get(); - if (sn_file->is_in_meta_flush_list()) { - // do nothing, because meta flush node may be re-inserted after - // tmp file insert meta tree item; do not handle data flush node here - // because data node will not be re-inserted during flushing procedure - } else if (OB_FAIL(sn_file->reinsert_meta_flush_node())) { - } - } else if (OB_FAIL(file_handle.get()->reinsert_data_flush_node())) { - } - } - } - return ret; -} - -int ObTmpFileFlushListIterator::next(const FlushCtxState iter_stage, ObSNTmpFileHandle &file_handle) -{ - int ret = OB_SUCCESS; - FlushCtxState cur_stage = FlushCtxState::FSM_FINISHED; - if (OB_UNLIKELY(!is_inited_)) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(dirs_.count() != MAX_CACHE_NUM || - cached_dir_num_ > MAX_CACHE_NUM || - cached_dir_num_ < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(files_.count() != MAX_CACHE_NUM || - cached_file_num_ > MAX_CACHE_NUM || - cached_file_num_ < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(FlushCtxState::FSM_FINISHED <= iter_stage || iter_stage < FlushCtxState::FSM_F1)) { - ret = OB_ERR_UNEXPECTED; - } else if (FALSE_IT(cur_stage = cal_current_flush_stage_())) { - } else if (OB_UNLIKELY(FlushCtxState::FSM_FINISHED <= cur_stage || FlushCtxState::FSM_F1 > cur_stage)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_stage > iter_stage)) { - ret = OB_ERR_UNEXPECTED; - } else if (cur_stage < iter_stage || - (FlushCtxState::FSM_F1 == cur_stage && cur_iter_file_idx_ == cached_file_num_) || - (FlushCtxState::FSM_F1 < cur_stage && cur_iter_dir_idx_ == cached_dir_num_)) { - // code will run here when: - // 1. expected iterating flush stage is over than current flush stage; - // 2. all cached file has been iterated - if (OB_FAIL(clear())) { - } - } - - if (OB_FAIL(ret)) { - } else if (0 == cached_file_num_ && OB_FAIL(cache_files_(iter_stage))) { - if (OB_ITER_END == ret) { - } else { - } - } else if (OB_FAIL(check_cur_idx_status_())) { - } else { - file_handle = files_[cur_iter_file_idx_].file_handle_; - if (FileList::L1 == cur_caching_list_idx_) { - if (OB_FAIL(advance_big_file_idx_())) { - } - } else if (OB_FAIL(advance_small_file_idx_())) { - } - } - return ret; -} - -int ObTmpFileFlushListIterator::cache_files_(const FlushCtxState iter_stage) -{ - int ret = OB_SUCCESS; - FileList end_list_idx = FileList::MAX; - const int64_t target_cache_file_num = iter_stage == FlushCtxState::FSM_F1 ? - BIG_FILE_CACHE_NUM : MAX_CACHE_NUM; - ObArray file_handles; - - if (OB_UNLIKELY(0 != cached_dir_num_ || 0 != cached_file_num_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(init_caching_list_with_flush_stage_(iter_stage))) { - } else if (OB_FAIL(acquire_final_list_of_flush_stage_(iter_stage, end_list_idx))) { - } else if (OB_FAIL(file_handles.prepare_allocate_and_keep_count(target_cache_file_num))) { - } else { // pop enough files from priority manager for caching - int64_t remain_cache_file_num = target_cache_file_num; - bool cache_over = false; - while (OB_SUCC(ret) && !cache_over && remain_cache_file_num > 0) { - int64_t actual_cache_file_num = 0; - if (OB_FAIL(prio_mgr_->popN_from_file_list(cur_caching_list_is_meta_, cur_caching_list_idx_, - remain_cache_file_num, actual_cache_file_num, - file_handles))) { - } else if (FALSE_IT(remain_cache_file_num -= actual_cache_file_num)) { - } else if (OB_UNLIKELY(remain_cache_file_num < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (0 == remain_cache_file_num) { // cache enough files - cache_over = true; - } else { // remain_cache_file_num > 0 - if (cur_caching_list_idx_ == end_list_idx) { // has reached the last list of this flush stage - if (file_handles.empty()) { - ret = OB_ITER_END; - } else { // cache files successful, but the num is not enough - cache_over = true; - } - } else if (OB_FAIL(advance_caching_list_idx_())) { - } - } - } // end while - } - - if (OB_SUCC(ret)) { - if (FileList::L1 == cur_caching_list_idx_) { - if (OB_FAIL(cache_big_files_(file_handles))) { - } - } else if (OB_FAIL(cache_small_files_(file_handles))) { - } - } - - if (OB_FAIL(ret)) { - cached_file_num_ = 0; // to guarantee that the iterator must not reinsert cached part files into priority list - int tmp_ret = OB_SUCCESS; - for (int64_t i = 0; OB_LIKELY(OB_SUCCESS == tmp_ret) && i < file_handles.count(); ++i) { - ObSharedNothingTmpFile *tmp_file = file_handles[i].get(); - if (OB_ISNULL(tmp_file)) { - // could not happen, just skip - } else if (cur_caching_list_is_meta_) { - ObSharedNothingTmpFile *sn_file = tmp_file; - if (OB_FAIL(sn_file->reinsert_meta_flush_node())) { - } - } else if (OB_TMP_FAIL(tmp_file->reinsert_data_flush_node())) { - } - } - } - return ret; -} - -int ObTmpFileFlushListIterator::cache_big_files_(const ObArray &file_handles) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(build_file_wrappers_(file_handles))) { - } else { - cur_iter_file_idx_ = 0; - cur_iter_dir_idx_ = -1; // no need to aggregate files into dir - cached_dir_num_ = 0; - } - return ret; -} - -int ObTmpFileFlushListIterator::cache_small_files_(const ObArray &file_handles) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(build_file_wrappers_(file_handles))) { - } else if (OB_FAIL(build_dir_wrappers_())) { - } else { - cur_iter_file_idx_ = dirs_[0].start_file_idx_; - cur_iter_dir_idx_ = 0; - } - return ret; -} - -int ObTmpFileFlushListIterator::build_file_wrappers_(const ObArray &file_handles) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(file_handles.empty())) { - ret = OB_INVALID_ARGUMENT; - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < file_handles.count(); ++i) { - if (i >= files_.count()) { - ret = OB_ERROR_OUT_OF_RANGE; - LOG_ERROR("index is out of range", KR(ret), K(i), K(files_)); - } else if (OB_FAIL(files_[i].init(cur_caching_list_is_meta_, file_handles[i]))) { - - for (int64_t j = 0; j < i; ++j) { - files_[j].reset(); - } - } - } - - if (OB_SUCC(ret)) { - lib::ob_sort(files_.begin(), files_.begin() + file_handles.count()); - cached_file_num_ = file_handles.count(); - } - } - return ret; -} - -int ObTmpFileFlushListIterator::build_dir_wrappers_() -{ - int ret = OB_SUCCESS; - int cached_dir_num = 0; - - if (OB_UNLIKELY(cached_file_num_ <= 0 || cached_file_num_ > files_.count())) { - ret = OB_ERR_UNEXPECTED; - } else { // we assume that files_ has been initialized and sorted - int64_t dir_id = ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID; - int64_t start_file_idx = -1; - int64_t end_file_idx = -1; - int64_t page_num = 0; - for (int64_t i = 0; OB_SUCC(ret) && i < cached_file_num_; ++i) { - ObSharedNothingTmpFile *file = nullptr; - int64_t file_dirty_page_num = 0; - if (OB_UNLIKELY(!files_[i].is_inited_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(file = files_[i].file_handle_.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(get_flushing_file_dirty_page_num_(*file, file_dirty_page_num))) { - } else if (file->get_dir_id() != dir_id) { - if (0 != i) { - end_file_idx = i - 1; - if (cached_dir_num >= dirs_.count()) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("cached_dir_num is equal or bigger than dirs_.count", - KR(ret), K(cached_dir_num), K(dirs_)); - } else if (OB_FAIL(dirs_[cached_dir_num].init(cur_caching_list_is_meta_, page_num, - start_file_idx, end_file_idx))) { - } else { - cached_dir_num++; - } - } - - if (OB_SUCC(ret)) { - dir_id = file->get_dir_id(); - start_file_idx = i; - page_num = file_dirty_page_num; - } - } else { - page_num += file_dirty_page_num; - } - - if (OB_SUCC(ret) && cached_file_num_ - 1 == i) { - end_file_idx = i; - if (cached_dir_num >= dirs_.count()) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("cached_dir_num is equal or bigger than dirs_.count", - KR(ret), K(cached_dir_num), K(dirs_)); - } else if (OB_FAIL(dirs_[cached_dir_num].init(cur_caching_list_is_meta_, page_num, - start_file_idx, end_file_idx))) { - } else { - cached_dir_num++; - } - } - } // end for - - } - - if (OB_FAIL(ret)) { - for (int64_t i = 0; i < cached_dir_num; i++) { - dirs_[i].reset(); - } - for (int64_t i = 0; i < cached_file_num_; i++) { - files_[i].reset(); - cached_file_num_ = 0; - } - } else { - lib::ob_sort(dirs_.begin(), dirs_.begin() + cached_dir_num); - cached_dir_num_ = cached_dir_num; - } - - return ret; -} - -int ObTmpFileFlushListIterator::get_flushing_file_dirty_page_num_(const ObSharedNothingTmpFile &file, int64_t &page_num) -{ - int ret = OB_SUCCESS; - FlushCtxState cur_stage = cal_current_flush_stage_(); - if (OB_UNLIKELY(cur_stage < FlushCtxState::FSM_F1 || cur_stage > FlushCtxState::FSM_F5)) { - ret = OB_ERR_UNEXPECTED; - } else if (cur_stage <= FlushCtxState::FSM_F3) { - ObSharedNothingTmpFile &mutable_file_ref = const_cast(file); - int64_t dirty_page_size = mutable_file_ref.get_dirty_data_page_size_with_lock(); - page_num = upper_align(dirty_page_size, ObTmpFileGlobal::ALLOC_PAGE_SIZE) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } else { // stage > FlushCtxState::FSM_F3 is flushing meta page - int64_t non_rightmost_dirty_page_num = 0; - int64_t rightmost_dirty_page_num = 0; - ObSharedNothingTmpFile &mutable_file_ref = const_cast(file); - mutable_file_ref.get_dirty_meta_page_num_with_lock(non_rightmost_dirty_page_num, rightmost_dirty_page_num); - if (cur_stage == FlushCtxState::FSM_F4) { - page_num = non_rightmost_dirty_page_num; - } else if (cur_stage == FlushCtxState::FSM_F5) { - page_num = rightmost_dirty_page_num; - } - } - return ret; -} - -int ObTmpFileFlushListIterator::advance_caching_list_idx_() -{ - int ret = OB_SUCCESS; - if (!cur_caching_list_is_meta_ && FileList::L5 == cur_caching_list_idx_) { - cur_caching_list_is_meta_ = true; - cur_caching_list_idx_ = FileList::L1; - } else { - switch(cur_caching_list_idx_) { - case FileList::L1: - cur_caching_list_idx_ = FileList::L2; - break; - case FileList::L2: - cur_caching_list_idx_ = FileList::L3; - break; - case FileList::L3: - cur_caching_list_idx_ = FileList::L4; - break; - case FileList::L4: - cur_caching_list_idx_ = FileList::L5; - break; - default: - ret = OB_ERR_UNEXPECTED; - break; - } - } - - return ret; -} - -int ObTmpFileFlushListIterator::check_cur_idx_status_() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(cur_iter_file_idx_ < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (FileList::L1 == cur_caching_list_idx_) { - // the file in L1 list will not be flushed with an aggregating dir. - // thus, it is no need to check dir - if (OB_UNLIKELY(cur_iter_file_idx_ >= cached_file_num_ || cached_file_num_ > files_.count())) { - ret = OB_ERR_UNEXPECTED; - } - } else if (OB_UNLIKELY(cur_iter_dir_idx_ < 0 || cur_iter_dir_idx_ >= cached_dir_num_ || - cached_dir_num_ > dirs_.count())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!dirs_[cur_iter_dir_idx_].is_inited_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_iter_file_idx_ < dirs_[cur_iter_dir_idx_].start_file_idx_ || - cur_iter_file_idx_ > dirs_[cur_iter_dir_idx_].end_file_idx_)) { - ret = OB_ERR_UNEXPECTED; - } - - if (OB_SUCC(ret) && OB_UNLIKELY(!files_[cur_iter_file_idx_].is_inited_)) { - ret = OB_ERR_UNEXPECTED; - } - - return ret; -} - -int ObTmpFileFlushListIterator::advance_big_file_idx_() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(FileList::L1 != cur_caching_list_idx_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_iter_file_idx_ < 0 || cur_iter_file_idx_ >= cached_file_num_ || - cached_file_num_ > files_.count())) { - ret = OB_ERR_UNEXPECTED; - } else { - files_[cur_iter_file_idx_].reset(); - cur_iter_file_idx_++; - } - return ret; -} - -int ObTmpFileFlushListIterator::advance_small_file_idx_() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(cur_caching_list_idx_ <= FileList::L1 || - cur_caching_list_idx_ > FileList::L5)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_iter_dir_idx_ < 0 || cur_iter_dir_idx_ >= cached_dir_num_ || - cached_dir_num_ > dirs_.count())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_iter_file_idx_ < 0 || cur_iter_file_idx_ >= cached_file_num_ || - cached_file_num_ > files_.count())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_iter_file_idx_ < dirs_[cur_iter_dir_idx_].start_file_idx_ || - cur_iter_file_idx_ > dirs_[cur_iter_dir_idx_].end_file_idx_)) { - ret = OB_ERR_UNEXPECTED; - } else { - files_[cur_iter_file_idx_].reset(); - cur_iter_file_idx_++; - if (cur_iter_file_idx_ > dirs_[cur_iter_dir_idx_].end_file_idx_) { - if (OB_FAIL(advance_dir_idx_())) { - } else if (cur_iter_dir_idx_ < cached_dir_num_) { - if (OB_UNLIKELY(!dirs_[cur_iter_dir_idx_].is_inited_)) { - ret = OB_ERR_UNEXPECTED; - } else { - cur_iter_file_idx_ = dirs_[cur_iter_dir_idx_].start_file_idx_; - } - } else { - // iter end - } - } - } - return ret; -} - -int ObTmpFileFlushListIterator::advance_dir_idx_() -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(FileList::L1 == cur_caching_list_idx_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(cur_iter_dir_idx_ < 0 || cur_iter_dir_idx_ >= cached_dir_num_ || - cached_dir_num_ > dirs_.count())) { - ret = OB_ERR_UNEXPECTED; - } else { - dirs_[cur_iter_dir_idx_].reset(); - cur_iter_dir_idx_++; - } - - return ret; -} - -FlushCtxState ObTmpFileFlushListIterator::cal_current_flush_stage_() -{ - FlushCtxState stage = FlushCtxState::FSM_FINISHED; - if (OB_UNLIKELY(cur_caching_list_idx_ < FileList::L1 || - cur_caching_list_idx_ > FileList::L5)) { - // stage = FlushCtxState::FSM_FINISHED; - } else if (!cur_caching_list_is_meta_) { - if (cur_caching_list_idx_ == FileList::L1) { - stage = FlushCtxState::FSM_F1; - } else if (cur_caching_list_idx_ <= FileList::L4) { - stage = FlushCtxState::FSM_F2; - } else if (cur_caching_list_idx_ == FileList::L5) { - stage = FlushCtxState::FSM_F3; - } - } else { - if (cur_caching_list_idx_ <= FileList::L4) { - stage = FlushCtxState::FSM_F4; - } else if (cur_caching_list_idx_ == FileList::L5) { - stage = FlushCtxState::FSM_F5; - } - } - - return stage; -} - -int ObTmpFileFlushListIterator::init_caching_list_with_flush_stage_(const FlushCtxState iter_stage) -{ - int ret = OB_SUCCESS; - if (cal_current_flush_stage_() == iter_stage) { - // no need to change caching list - } else if (iter_stage == FlushCtxState::FSM_F1) { - cur_caching_list_is_meta_ = false; - cur_caching_list_idx_ = FileList::L1; - } else if (iter_stage == FlushCtxState::FSM_F2) { - cur_caching_list_is_meta_ = false; - cur_caching_list_idx_ = FileList::L2; - } else if (iter_stage == FlushCtxState::FSM_F3) { - cur_caching_list_is_meta_ = false; - cur_caching_list_idx_ = FileList::L5; - } else if (iter_stage == FlushCtxState::FSM_F4) { - cur_caching_list_is_meta_ = true; - cur_caching_list_idx_ = FileList::L1; - } else if (iter_stage == FlushCtxState::FSM_F5) { - cur_caching_list_is_meta_ = true; - cur_caching_list_idx_ = FileList::L5; - } else { - ret = OB_ERR_UNEXPECTED; - } - - return ret; -} - -int ObTmpFileFlushListIterator::acquire_final_list_of_flush_stage_(const FlushCtxState iter_stage, - FileList &list_idx) -{ - int ret = OB_SUCCESS; - switch(iter_stage) { - case FlushCtxState::FSM_F1: - list_idx = FileList::L1; - break; - case FlushCtxState::FSM_F2: - list_idx = FileList::L4; - break; - case FlushCtxState::FSM_F3: - list_idx = FileList::L5; - break; - case FlushCtxState::FSM_F4: - list_idx = FileList::L4; - break; - case FlushCtxState::FSM_F5: - list_idx = FileList::L5; - break; - default: - ret = OB_ERR_UNEXPECTED; - } - return ret; -} - -int ObTmpFileFlushListIterator::ObFlushingTmpFileWrapper::init(const bool is_meta, const ObSNTmpFileHandle &file_handle) -{ - int ret = OB_SUCCESS; - if (is_inited_) { - ret = OB_INIT_TWICE; - } else if (OB_ISNULL(file_handle.get())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", KR(ret), KP(file_handle.get())); - } else { - is_meta_ = is_meta; - file_handle_ = file_handle; - is_inited_ = true; - } - return ret; -} - -void ObTmpFileFlushListIterator::ObFlushingTmpFileWrapper::reset() -{ - if (IS_INIT) { - is_inited_ = false; - is_meta_ = false; - file_handle_.reset(); - } -} - -bool ObTmpFileFlushListIterator::ObFlushingTmpFileWrapper::operator <(const ObFlushingTmpFileWrapper &other) -{ - int ret = OB_SUCCESS; - bool b_ret = false; - if (OB_UNLIKELY(!other.is_inited_ || !is_inited_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(other.file_handle_.get()) || OB_ISNULL(file_handle_.get())) { - ret = OB_ERR_UNEXPECTED; - } else if (!is_meta_ && other.is_meta_) { - b_ret = true; - } else if (is_meta_ && !other.is_meta_) { - b_ret = false; - } else if (file_handle_.get()->get_dir_id() < other.file_handle_.get()->get_dir_id()) { - b_ret = true; - } else if (file_handle_.get()->get_dir_id() > other.file_handle_.get()->get_dir_id()) { - b_ret = false; - } else if (is_meta_) { - ObSharedNothingTmpFile *sn_file = file_handle_.get(); - ObSharedNothingTmpFile *sn_other_file = other.file_handle_.get(); - b_ret = sn_file->get_meta_page_flush_level() < sn_other_file->get_meta_page_flush_level(); - } else { - b_ret = file_handle_.get()->get_data_page_flush_level() < other.file_handle_.get()->get_data_page_flush_level(); - } - return b_ret; -} - -int ObTmpFileFlushListIterator::ObFlushingTmpFileDirWrapper::init(const bool is_meta, const int64_t page_num, - const int64_t start_file_idx, - const int64_t end_file_idx) -{ - int ret = OB_SUCCESS; - if (is_inited_) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(page_num < 0 || start_file_idx < 0 || start_file_idx > end_file_idx)) { - ret = OB_INVALID_ARGUMENT; - } else { - is_inited_ = true; - is_meta_ = is_meta; - page_num_ = page_num; - start_file_idx_ = start_file_idx; - end_file_idx_ = end_file_idx; - } - return ret; -} - -void ObTmpFileFlushListIterator::ObFlushingTmpFileDirWrapper::reset() -{ - if (IS_INIT) { - is_meta_ = false; - page_num_ = 0; - start_file_idx_ = -1; - end_file_idx_ = -1; - is_inited_ = false; - } -} - -bool ObTmpFileFlushListIterator::ObFlushingTmpFileDirWrapper::operator <(const ObFlushingTmpFileDirWrapper &other) -{ - int ret = OB_SUCCESS; - bool b_ret = false; - if (OB_UNLIKELY(!other.is_inited_ || !is_inited_)) { - LOG_WARN("unexpected status", K(other), KPC(this)); - } else if (!is_meta_ && other.is_meta_) { - b_ret = true; - } else if (is_meta_ && !other.is_meta_) { - b_ret = false; - } else { - b_ret = page_num_ > other.page_num_; - } - return b_ret; -} -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_flush_list_iterator.h b/src/storage/tmp_file/ob_tmp_file_flush_list_iterator.h deleted file mode 100644 index 491ee693f9..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_list_iterator.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_LIST_ITERATOR_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_LIST_ITERATOR_H_ - -#include "storage/tmp_file/ob_tmp_file_flush_priority_manager.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -typedef ObTmpFileGlobal::FlushCtxState FlushCtxState; - -class ObTmpFileFlushListIterator -{ -public: - ObTmpFileFlushListIterator(); - ~ObTmpFileFlushListIterator(); - - int init(ObTmpFileFlushPriorityManager *prio_mgr); - int clear(); - int reset(); - void destroy(); - int next(const FlushCtxState iter_stage, ObSNTmpFileHandle &file_handle); - - TO_STRING_KV(K(is_inited_), K(cur_caching_list_idx_), K(cur_caching_list_is_meta_), - K(cur_iter_dir_idx_), K(cur_iter_file_idx_), K(cached_file_num_), K(cached_dir_num_)) -private: - typedef ObTmpFileGlobal::FileList FileList; - int reinsert_files_into_flush_list_(const int64_t start_file_idx, const int64_t end_file_idx); - FlushCtxState cal_current_flush_stage_(); - int init_caching_list_with_flush_stage_(const FlushCtxState iter_stage); - int acquire_final_list_of_flush_stage_(const FlushCtxState iter_stage, - FileList &list_idx); - int cache_files_(const FlushCtxState iter_stage); - int build_file_wrappers_(const ObArray &file_handles); - int build_dir_wrappers_(); - int cache_big_files_(const ObArray &file_handles); - int cache_small_files_(const ObArray &file_handles); - int get_flushing_file_dirty_page_num_(const ObSharedNothingTmpFile &file, int64_t &page_num); - int check_cur_idx_status_(); - int advance_big_file_idx_(); - int advance_small_file_idx_(); - int advance_dir_idx_(); - int advance_caching_list_idx_(); -private: - struct ObFlushingTmpFileWrapper - { - ObFlushingTmpFileWrapper() : is_inited_(false), is_meta_(false), file_handle_() {} - ~ObFlushingTmpFileWrapper() { reset(); }; - int init(const bool is_meta, const ObSNTmpFileHandle &file_handle); - void reset(); - bool operator <(const ObFlushingTmpFileWrapper &other); - TO_STRING_KV(K(is_inited_), K(is_meta_), K(file_handle_)); - - bool is_inited_; - bool is_meta_; - ObSNTmpFileHandle file_handle_; - }; - - struct ObFlushingTmpFileDirWrapper - { - ObFlushingTmpFileDirWrapper() : is_inited_(false), is_meta_(false), page_num_(0), - start_file_idx_(-1), end_file_idx_(-1) {} - ~ObFlushingTmpFileDirWrapper() { reset(); }; - int init(const bool is_meta, const int64_t page_num, const int64_t start_file_idx, const int64_t end_file_idx); - void reset(); - bool operator <(const ObFlushingTmpFileDirWrapper &other); - TO_STRING_KV(K(is_inited_), K(is_meta_), K(page_num_), K(start_file_idx_), K(end_file_idx_)); - - bool is_inited_; - bool is_meta_; - int64_t page_num_; - int64_t start_file_idx_; - int64_t end_file_idx_; - }; -private: - static constexpr int64_t MAX_CACHE_NUM = 256; - static constexpr int64_t BIG_FILE_CACHE_NUM = 8; - bool is_inited_; - ObTmpFileFlushPriorityManager *prio_mgr_; - ObArray files_; - ObArray dirs_; - bool cur_caching_list_is_meta_; - FileList cur_caching_list_idx_; - int64_t cur_iter_dir_idx_; - int64_t cur_iter_file_idx_; - int64_t cached_file_num_; - int64_t cached_dir_num_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_LIST_ITERATOR_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_flush_manager.cpp b/src/storage/tmp_file/ob_tmp_file_flush_manager.cpp deleted file mode 100644 index 8ab02f26cc..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_manager.cpp +++ /dev/null @@ -1,1107 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "ob_tmp_file_flush_manager.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -ObTmpFileFlushManager::ObTmpFileFlushManager(ObTmpFilePageCacheController &pc_ctrl) - : is_inited_(false), - flush_ctx_(), - pc_ctrl_(pc_ctrl), - tmp_file_block_mgr_(pc_ctrl.get_tmp_file_block_manager()), - task_allocator_(pc_ctrl.get_task_allocator()), - write_buffer_pool_(pc_ctrl.get_write_buffer_pool()), - evict_mgr_(pc_ctrl.get_eviction_manager()), - flush_priority_mgr_(pc_ctrl.get_flush_priority_mgr()), - cur_flush_timer_idx_(0) -{ - for (int64_t i = 0; i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - flush_timers_[i] = nullptr; - } -} - -int ObTmpFileFlushManager::init() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - STORAGE_LOG(WARN, "ObTmpFileFlushManager inited twice", KR(ret)); - } else if (OB_FAIL(flush_ctx_.init())) { - } else { - cur_flush_timer_idx_ = 0; - is_inited_ = true; - } - return ret; -} - -void ObTmpFileFlushManager::destroy() -{ - is_inited_ = false; - for (int64_t i = 0; i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - flush_timers_[i] = nullptr; - } - flush_ctx_.destroy(); -} - -void ObTmpFileFlushManager::set_flush_timers(common::ObTimer *flush_timers, const int64_t timer_cnt) -{ - for (int64_t i = 0; i < timer_cnt && i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - flush_timers_[i] = &flush_timers[i]; - } -} - -int ObTmpFileFlushManager::alloc_flush_task(ObTmpFileFlushTask *&flush_task) -{ - int ret = OB_SUCCESS; - flush_task = nullptr; - - void *task_buf = nullptr; - if (OB_ISNULL(task_buf = task_allocator_.alloc(sizeof(ObTmpFileFlushTask)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - STORAGE_LOG(WARN, "fail to allocate memory for flush callback", KR(ret)); - } else { - flush_task = new (task_buf) ObTmpFileFlushTask(); - } - return ret; -} - -int ObTmpFileFlushManager::free_flush_task(ObTmpFileFlushTask *flush_task) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task ptr is null", KR(ret)); - } else { - if (ObTimeUtil::current_time() - flush_task->get_create_ts() > FLUSH_TASK_FINISH_WARN_TIMEOUT_US) { - LOG_WARN("flush task execute takes too much time", KPC(flush_task)); - } - flush_task->~ObTmpFileFlushTask(); - task_allocator_.free(flush_task); - } - return ret; -} - -int ObTmpFileFlushManager::notify_write_back_failed(ObTmpFileFlushTask *flush_task) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task ptr is null", KR(ret)); - } else if (OB_FAIL(tmp_file_block_mgr_.write_back_failed(flush_task->get_block_index()))) { - } - return ret; -} - -// release whole block -int ObTmpFileFlushManager::free_tmp_file_block(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - int64_t block_index = flush_task.get_block_index(); - if (ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX == block_index) { - // do nothing - } else if (OB_FAIL(tmp_file_block_mgr_.release_tmp_file_page(block_index, - 0/*begin_page_id*/, - ObTmpFileGlobal::BLOCK_PAGE_NUMS))) { - } - return ret; -} - -void ObTmpFileFlushManager::init_flush_level_() -{ - int64_t dirty_page_percentage = write_buffer_pool_.get_dirty_page_percentage(); - if (pc_ctrl_.is_flush_all_data()) { - flush_ctx_.set_state(FlushCtxState::FSM_F1); - } else { - if (FLUSH_WATERMARK_F1 <= dirty_page_percentage) { - flush_ctx_.set_state(FlushCtxState::FSM_F1); - } else if (FLUSH_WATERMARK_F2 <= dirty_page_percentage) { - flush_ctx_.set_state(FlushCtxState::FSM_F2); - } else if (FLUSH_WATERMARK_F3 <= dirty_page_percentage) { - flush_ctx_.set_state(FlushCtxState::FSM_F3); - } else if (FLUSH_WATERMARK_F4 <= dirty_page_percentage) { - flush_ctx_.set_state(FlushCtxState::FSM_F4); - } else if (FLUSH_WATERMARK_F5 <= dirty_page_percentage) { - flush_ctx_.set_state(FlushCtxState::FSM_F5); - } else { - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - } - } -} - -void ObTmpFileFlushManager::advance_flush_level_(const int ret_code) -{ - int64_t dirty_page_percentage = write_buffer_pool_.get_dirty_page_percentage(); - - if (pc_ctrl_.is_flush_all_data()) { - if (OB_SUCCESS == ret_code) { - // continue to flush to OB_ITER_END, do nothing - } else if (OB_ITER_END == ret_code) { - inner_advance_flush_level_without_checking_watermark_(); - } else { - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - } - } else { - if (OB_SUCCESS == ret_code) { - // if lower than low_watermark or reach expect_flush_size, terminate flush process - if (get_low_watermark_(flush_ctx_.get_state()) >= dirty_page_percentage - || flush_ctx_.get_actual_flush_size() >= flush_ctx_.get_expect_flush_size()) { - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - } - } else if (OB_ITER_END == ret_code) { - inner_advance_flush_level_(); - } else { - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - } - } - -} - -int64_t ObTmpFileFlushManager::get_low_watermark_(FlushCtxState state) -{ - int ret = OB_SUCCESS; - int64_t low_watermark = 100; - switch(state) { - case FlushCtxState::FSM_F1: - low_watermark = FLUSH_LOW_WATERMARK_F1; - break; - case FlushCtxState::FSM_F2: - low_watermark = FLUSH_LOW_WATERMARK_F2; - break; - case FlushCtxState::FSM_F3: - low_watermark = FLUSH_LOW_WATERMARK_F3; - break; - case FlushCtxState::FSM_F4: - low_watermark = FLUSH_LOW_WATERMARK_F4; - break; - case FlushCtxState::FSM_F5: - low_watermark = FLUSH_LOW_WATERMARK_F5; - break; - case FlushCtxState::FSM_FINISHED: - break; - default: - STORAGE_LOG(WARN, "unexpected flush state", K(state), K(flush_ctx_)); - break; - } - return low_watermark; -} - -void ObTmpFileFlushManager::inner_advance_flush_level_() -{ - if (flush_ctx_.get_actual_flush_size() >= flush_ctx_.get_expect_flush_size()) { - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - } - - int64_t dirty_page_percentage = write_buffer_pool_.get_dirty_page_percentage(); - if (FLUSH_WATERMARK_F2 <= dirty_page_percentage && flush_ctx_.get_state() < FlushCtxState::FSM_F2) { - flush_ctx_.set_state(FlushCtxState::FSM_F2); - } else if (FLUSH_WATERMARK_F3 <= dirty_page_percentage && flush_ctx_.get_state() < FlushCtxState::FSM_F3) { - flush_ctx_.set_state(FlushCtxState::FSM_F3); - } else if (FLUSH_WATERMARK_F4 <= dirty_page_percentage && flush_ctx_.get_state() < FlushCtxState::FSM_F4) { - flush_ctx_.set_state(FlushCtxState::FSM_F4); - } else if (FLUSH_WATERMARK_F5 <= dirty_page_percentage && flush_ctx_.get_state() < FlushCtxState::FSM_F5) { - flush_ctx_.set_state(FlushCtxState::FSM_F5); - } else { - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - } -} - -void ObTmpFileFlushManager::inner_advance_flush_level_without_checking_watermark_() -{ - switch(flush_ctx_.get_state()) { - case FlushCtxState::FSM_F1: - flush_ctx_.set_state(FlushCtxState::FSM_F2); - break; - case FlushCtxState::FSM_F2: - flush_ctx_.set_state(FlushCtxState::FSM_F3); - break; - case FlushCtxState::FSM_F3: - flush_ctx_.set_state(FlushCtxState::FSM_F4); - break; - case FlushCtxState::FSM_F4: - flush_ctx_.set_state(FlushCtxState::FSM_F5); - break; - case FlushCtxState::FSM_F5: - flush_ctx_.set_state(FlushCtxState::FSM_FINISHED); - break; - default: - break; - } -} - -// Generate a set of flush tasks based on the flushing level to flush dirty pages, -// and attempt to advance the task status to TFFT_WAIT (waiting for asynchronous IO). -// When OB_ALLOCATE_TMP_FILE_PAGE_FAILED error occurs during flushing, -// a special flush task is generated to flush meta pages and terminate the current round of flushing. -// Setting fast_flush_meta to true by the caller also triggers this process. -int ObTmpFileFlushManager::flush(ObSpLinkQueue &flushing_queue, - ObTmpFileFlushMonitor &flush_monitor, - const int64_t expect_flush_size, - const int64_t current_flush_cnt, - const bool is_flush_meta_tree) -{ - int ret = OB_SUCCESS; - bool fast_flush_meta = is_flush_meta_tree; - - init_flush_level_(); - - if (FlushCtxState::FSM_FINISHED == flush_ctx_.get_state() && !fast_flush_meta) { - ret = OB_SUCCESS; - } else if (OB_FAIL(flush_ctx_.prepare_flush_ctx(expect_flush_size, &flush_priority_mgr_, &flush_monitor))) { - } else { - if (OB_FAIL(flush_by_watermark_(flushing_queue, current_flush_cnt, is_flush_meta_tree))) { - } - - if (!flushing_queue.is_empty()) { - } - if (OB_FAIL(ret) && ret != OB_TMP_FILE_EXCEED_DISK_QUOTA && !flushing_queue.is_empty()) { - ret = OB_SUCCESS; // ignore error if generate at least 1 task - } - flush_ctx_.clear_flush_ctx(flush_priority_mgr_); - } - return ret; -} - -int ObTmpFileFlushManager::flush_by_watermark_(ObSpLinkQueue &flushing_queue, - const int64_t current_flush_cnt, - const bool is_flush_meta_tree) -{ - int ret = OB_SUCCESS; - bool fast_flush_meta = is_flush_meta_tree; - int64_t flushing_cnt = current_flush_cnt; - while (OB_SUCC(ret) && !flush_ctx_.is_fail_too_many() - && (FlushCtxState::FSM_FINISHED != flush_ctx_.get_state() || fast_flush_meta)) { - ObTmpFileFlushTask *flush_task = nullptr; - if (OB_FAIL(check_tmp_file_disk_usage_limit_(flushing_cnt++))) { - } else if (OB_FAIL(handle_alloc_flush_task_(fast_flush_meta, flush_task))) { - } else { - flush_ctx_.inc_create_flush_task_cnt(); - flushing_queue.push(flush_task); - - FlushState state = ObTmpFileFlushTask::TFFT_INITED; - FlushState next_state = state; - do { - next_state = state = flush_task->get_state(); - if (OB_FAIL(drive_flush_task_prepare_(*flush_task, state, next_state))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to drive flush task prepare", KR(ret), K(flush_ctx_)); - } - } else if (flush_task->get_state() >= next_state) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected flush state after drive task succ", KR(ret), K(flush_ctx_), K(state)); - } else if (OB_FAIL(advance_status_(*flush_task, next_state))) { - } - } while (OB_SUCC(ret) && FlushState::TFFT_WAIT != next_state); - - bool recorded_as_prepare_finished = false; - flush_ctx_.update_actual_flush_size(*flush_task); - flush_ctx_.try_update_prepare_finished_cnt(*flush_task, recorded_as_prepare_finished); - if (recorded_as_prepare_finished) { - flush_task->mark_recorded_as_prepare_finished(); - } - if (ObTmpFileFlushTask::TFFT_FILL_BLOCK_BUF < flush_task->get_state()) { - flush_ctx_.record_flush_task(flush_task->get_data_length()); // maintain statistics - } - if (flush_task->get_is_fast_flush_tree()) { - if (OB_FAIL(ret) && flush_task->get_data_length() > 0) { - STORAGE_LOG(ERROR, "fail to execute fast_flush_tree_page flush task to TFFT_WAIT", KR(ret), KPC(flush_task)); - } - break; // generate only one fast_flush_tree_page_ task to avoid excessive flushing of the meta - } - if (OB_ALLOCATE_TMP_FILE_PAGE_FAILED == ret){ - if (flush_task->get_state() == FlushState::TFFT_INSERT_META_TREE) { - STORAGE_LOG(ERROR, "fail to insert meta tree, generating fast_flush_meta task", KR(ret)); - fast_flush_meta = true; // set this flag generate fast_flush_tree_page_ task in the next loop - ret = OB_SUCCESS; - } else { - STORAGE_LOG(ERROR, "flush task is not in TFFT_INSERT_META_TREE state", KPC(flush_task)); - } - } - } - } - return ret; -} - -int ObTmpFileFlushManager::check_tmp_file_disk_usage_limit_(const int64_t current_flush_cnt) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - int64_t disk_usage_limit = pc_ctrl_.get_disk_usage_limit(); - int64_t used_page_num = 0; - int64_t tmp_file_block_num = 0; - int64_t current_disk_usage = 0; - if (OB_FAIL(tmp_file_block_mgr_.get_block_usage_stat(used_page_num, tmp_file_block_num))) { - } else if (FALSE_IT(current_disk_usage = (tmp_file_block_num + current_flush_cnt) * ObTmpFileGlobal::SN_BLOCK_SIZE)) { - } else if (disk_usage_limit > 0 && current_disk_usage > disk_usage_limit) { - ret = OB_TMP_FILE_EXCEED_DISK_QUOTA; - STORAGE_LOG(WARN, "tmp file exceeds disk usage limit", - KR(ret), K(current_disk_usage), K(disk_usage_limit), K(tmp_file_block_num), K(current_flush_cnt)); - } - } - return ret; -} - -// skip flush level, copy meta tree pages directly -int ObTmpFileFlushManager::fast_fill_block_buf_with_meta_(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(inner_fill_block_buf_(flush_task, FlushCtxState::FSM_F4, true/*is_meta*/, false/*flush_tail*/))) { - } - - if (flush_task.get_data_length() < FAST_FLUSH_TREE_PAGE_NUM * ObTmpFileGlobal::ALLOC_PAGE_SIZE) { // ignore error code and try F5 - if (OB_FAIL(inner_fill_block_buf_(flush_task, FlushCtxState::FSM_F5, true/*is_meta*/, true/*flush_tail*/))) { - } - } - - if (OB_FAIL(ret)) { - if (OB_ITER_END == ret && flush_task.get_flush_infos().size() != 0) { - // ignore OB_ITER_END error code to continue to next stage - LOG_INFO("fast_fill_block_buf_with_meta_ iterator reach end, ignore error code to continue", - KR(ret), K(flush_task), K(flush_ctx_)); - ret = OB_SUCCESS; - } else { - } - } - return ret; -} - -int ObTmpFileFlushManager::fill_block_buf_(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - switch(flush_ctx_.get_state()) { - case FlushCtxState::FSM_F1: - if (!flush_task.is_full() && FlushCtxState::FSM_FINISHED != flush_ctx_.get_state() - && OB_FAIL(inner_fill_block_buf_(flush_task, flush_ctx_.get_state(), - false/*is_meta*/, false/*flush_tail*/))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to generate flush data task in flush policy f1", KR(ret), K(flush_task)); - } - } - advance_flush_level_(ret); - // go through - case FlushCtxState::FSM_F2: - if (!flush_task.is_full() && FlushCtxState::FSM_FINISHED != flush_ctx_.get_state() - && OB_FAIL(inner_fill_block_buf_(flush_task, flush_ctx_.get_state(), - false/*is_meta*/, false/*flush_tail*/))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to generate flush data task in flush policy f2", KR(ret), K(flush_task)); - } - } - advance_flush_level_(ret); - // go through - case FlushCtxState::FSM_F3: - if (!flush_task.is_full() && FlushCtxState::FSM_FINISHED != flush_ctx_.get_state() - && OB_FAIL(inner_fill_block_buf_(flush_task, flush_ctx_.get_state(), - false/*is_meta*/, true/*flush_tail*/))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to generate flush data task in flush policy f3", KR(ret), K(flush_task)); - } - } - advance_flush_level_(ret); - // break here to forbid flush data pages and meta pages in the same flush task - // to prevent 1 flush task contains all of meta page that can be flushed, - // but is stuck in TFFT_INSERT_META_TREE state and new task has no meta pages to flush - break; - case FlushCtxState::FSM_F4: - if (OB_FAIL(flush_task.prealloc_block_buf())) { - } else if (!flush_task.is_full() && FlushCtxState::FSM_FINISHED != flush_ctx_.get_state() - && OB_FAIL(inner_fill_block_buf_(flush_task, flush_ctx_.get_state(), - true/*is_meta*/, false/*flush_tail*/))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(ERROR, "fail to generate flush meta task in flush policy f4", KR(ret), K(flush_task)); - } - } - advance_flush_level_(ret); - // go through - case FlushCtxState::FSM_F5: - if (!flush_task.get_block_handle().is_valid() && OB_FAIL(flush_task.prealloc_block_buf())) { - STORAGE_LOG(WARN, "fail to prealloc block buf", KR(ret), K(flush_task)); - } else if (!flush_task.is_full() && FlushCtxState::FSM_FINISHED != flush_ctx_.get_state() - && OB_FAIL(inner_fill_block_buf_(flush_task, flush_ctx_.get_state(), - true/*is_meta*/, true/*flush_tail*/))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(ERROR, "fail to generate flush meta task in flush policy f5", KR(ret), K(flush_task)); - } - } - advance_flush_level_(ret); - // go through - case FlushCtxState::FSM_FINISHED: - // do nothing - break; - default: - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected flush state", KR(ret), K(flush_ctx_)); - break; - } - if (OB_ITER_END == ret && flush_task.get_flush_infos().size() != 0) { - // ignore OB_ITER_END error code to continue TFFT_INSERT_META_TREE state - ret = OB_SUCCESS; - } - return ret; -} - -int ObTmpFileFlushManager::inner_fill_block_buf_( - ObTmpFileFlushTask &flush_task, - const FlushCtxState flush_stage, - const bool is_meta, - const bool flush_tail) -{ - int ret = OB_SUCCESS; - const int64_t BLOCK_SIZE = ObTmpFileGlobal::SN_BLOCK_SIZE; - bool fail_too_many = false; - - ObArray &flush_failed_array = flush_ctx_.get_flush_failed_array(); - ObTmpFileFlushListIterator &iter = flush_ctx_.get_flush_list_iterator(); - ObSNTmpFileHandle file_handle; - while (OB_SUCC(ret) && !fail_too_many && !flush_task.is_full()) { - if (OB_FAIL(iter.next(flush_stage, file_handle))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to get file from iterator", - KR(ret), K(flush_stage), K(is_meta), K(flush_tail), K(flush_ctx_)); - // it is no need to process the error code of iterator. it will handle with problem by itself. - // just using OB_ITER_END to finish this flushing loop is enough - ret = OB_ITER_END; - } - } else if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "file handle is nullptr", KR(ret)); - } else { - ObSharedNothingTmpFile &file = *file_handle.get(); - if (file.is_deleting()) { - STORAGE_LOG(INFO, "file is deleted while generating flush task", K(file)); - } else { - STORAGE_LOG(DEBUG, "try to copy data from file", K(file.get_fd()), K(is_meta), K(flush_tail), K(file)); - int64_t last_idx = -1; - bool copy_flush_info_fail = false; - ObArray &flush_infos = flush_task.get_flush_infos(); - const int64_t origin_info_cnt = flush_infos.count(); - ObTmpFileSingleFlushContext file_flush_ctx(file_handle); - // push back first to prevent array resizing or - // hash map allocate node failure AFTER copying the file data - if (FAILEDx(get_or_create_file_in_ctx_(file.get_fd(), file_flush_ctx))) { - } else if (OB_FAIL(flush_infos.push_back(ObTmpFileFlushInfo()))) { - } else if (FALSE_IT(last_idx = flush_infos.size() - 1)) { - } else if (!is_meta && OB_FAIL(file.generate_data_flush_info(flush_task, flush_infos.at(last_idx), - file_flush_ctx.data_ctx_, flush_ctx_.get_flush_sequence(), flush_tail))) { - STORAGE_LOG(WARN, "fail to generate flush data info", KR(ret), K(flush_task), - K(flush_stage), K(is_meta), K(flush_tail), K(file)); - copy_flush_info_fail = true; - } else if (is_meta && OB_FAIL(file.generate_meta_flush_info(flush_task, flush_infos.at(last_idx), - file_flush_ctx.meta_ctx_, flush_ctx_.get_flush_sequence(), flush_tail))) { - STORAGE_LOG(ERROR, "fail to generate flush meta info", KR(ret), K(flush_task), - K(flush_stage), K(is_meta), K(flush_tail), K(file)); - copy_flush_info_fail = true; - } else { - if (!(flush_tail || (is_meta && file_flush_ctx.meta_ctx_.is_meta_reach_end_))) { - if (is_meta) { - if (OB_FAIL(file.reinsert_meta_flush_node())) { - } - } else { - if (OB_FAIL(file.reinsert_data_flush_node())) { - } - } - } - UpdateFlushCtx update_op(file_flush_ctx); - if (FAILEDx(flush_ctx_.get_file_ctx_hash().set_or_update(file.get_fd(), file_flush_ctx, update_op))) { - // if update fails, the copy offset will be incorrect when the file is flushed a second time in the same round - STORAGE_LOG(ERROR, "fail to set flush ctx after copying data", KR(ret), K(file)); - copy_flush_info_fail = true; - } - flush_ctx_.record_flush_stage(); - } - - if (OB_FAIL(ret)) { - int tmp_ret = OB_SUCCESS; - ObTmpFileBatchFlushContext::ObTmpFileFlushFailRecord record(is_meta, ObSNTmpFileHandle(&file)); - if (OB_TMP_FAIL(flush_failed_array.push_back(record))) { - } else if (!flush_task.get_is_fast_flush_tree() - && flush_failed_array.size() >= ObTmpFileBatchFlushContext::MAX_COPY_FAIL_COUNT - 8) { - fail_too_many = true; - LOG_WARN("inner_fill_block_buf_ fail too many times", K(file.get_fd()), K(flush_failed_array.size())); - } else if (flush_task.get_is_fast_flush_tree() - && flush_failed_array.size() >= ObTmpFileBatchFlushContext::MAX_COPY_FAIL_COUNT) { - fail_too_many = true; - LOG_WARN("inner_fill_block_buf_ fail too many times", K(file.get_fd()), K(flush_failed_array.size())); - flush_ctx_.set_fail_too_many(true); // set this flag to exit flush - } - - if (flush_infos.size() > origin_info_cnt) { - flush_infos.pop_back(); - } - if (!file_flush_ctx.data_ctx_.is_valid() && !file_flush_ctx.meta_ctx_.is_valid()) { - // clear pre-created files to ensure that file_ctx_hash_ only records files that were able to send IO - if (OB_TMP_FAIL(flush_ctx_.get_file_ctx_hash().erase_refactored(file.get_fd()))) { - if (OB_HASH_NOT_EXIST != tmp_ret) { - STORAGE_LOG(ERROR, "fail to erase file ctx from hash", KR(tmp_ret), K(file.get_fd())); - } - } - } - - if (!copy_flush_info_fail) { - STORAGE_LOG(WARN, "inner fill block buffer fail, try next file", KR(ret), K(file.get_fd())); - ret = OB_SUCCESS; // ignore error code if fail before copying data - } - } - } - } - file_handle.reset(); - } // end while - - return ret; -} - -void ObTmpFileFlushManager::UpdateFlushCtx::operator() (hash::HashMapPair &pair) -{ - int64_t fd = pair.first; - ObTmpFileDataFlushContext &data_ctx = pair.second.data_ctx_; - ObTmpFileTreeFlushContext &meta_ctx = pair.second.meta_ctx_; - if (input_data_ctx_.is_valid()) { - data_ctx = input_data_ctx_; - } - if (input_meta_ctx_.is_valid()) { - meta_ctx = input_meta_ctx_; - } -} - -int ObTmpFileFlushManager::get_or_create_file_in_ctx_(const int64_t fd, ObTmpFileSingleFlushContext &file_flush_ctx) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(flush_ctx_.get_file_ctx_hash().get_refactored(fd, file_flush_ctx))) { - if (OB_HASH_NOT_EXIST == ret) { - ret = OB_SUCCESS; - if (OB_FAIL(flush_ctx_.get_file_ctx_hash().set_refactored(fd, file_flush_ctx))) { - } - } else { - STORAGE_LOG(WARN, "fail to get file flush context", KR(ret), K(fd)); - } - } - return ret; -} - -// iterate all file to insert data items into its meta tree -int ObTmpFileFlushManager::insert_items_into_meta_tree_(ObTmpFileFlushTask &flush_task, - const int64_t logic_block_index) -{ - int ret = OB_SUCCESS; - ObArray &flush_infos = flush_task.get_flush_infos(); - for (int64_t i = 0; OB_SUCC(ret) && i < flush_infos.count(); ++i) { - ObTmpFileFlushInfo &flush_info = flush_infos.at(i); - ObSharedNothingTmpFile *file = flush_info.file_handle_.get(); - if (OB_ISNULL(file)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "file is nullptr", KR(ret), K(flush_info)); - } else { - if (flush_info.has_data() && !flush_info.insert_meta_tree_done_) { - if (OB_FAIL(file->insert_meta_tree_item(flush_info, logic_block_index))) { - STORAGE_LOG(WARN, "fail to insert meta tree item", KR(ret), K(flush_info), K(logic_block_index), KP(&flush_task)); - // flushing data pages may generate new meta pages. ff there is not enough space allocated for the meta pages, - // it will result in the failure of the current data flushing. therefore, we need to evict some pages to free up space - if (OB_ALLOCATE_TMP_FILE_PAGE_FAILED == ret) { - if (OB_FAIL(evict_pages_and_retry_insert_(flush_task, flush_info, logic_block_index))) { - } - } - } else { - flush_info.insert_meta_tree_done_ = true; - } - } - } - } - return ret; -} - -// If eviction or insertion fails, retry the operation on the next round -int ObTmpFileFlushManager::evict_pages_and_retry_insert_(ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &flush_info, - const int64_t logic_block_index) -{ - int ret = OB_SUCCESS; - int64_t expect_evict_page = FAST_FLUSH_TREE_PAGE_NUM; - int64_t actual_evict_page = 0; - ObSharedNothingTmpFile *file = flush_info.file_handle_.get(); - if (OB_ISNULL(file)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "file ptr is null", KR(ret), K(flush_task), K(logic_block_index)); - } else if (OB_FAIL(evict_mgr_.evict(expect_evict_page, actual_evict_page))) { - } else if (OB_FAIL(file->insert_meta_tree_item(flush_info, logic_block_index))) { - } else { - flush_info.insert_meta_tree_done_ = true; - } - return ret; -} - -int ObTmpFileFlushManager::drive_flush_task_prepare_(ObTmpFileFlushTask &flush_task, - const FlushState state, - FlushState &next_state) -{ - int ret = OB_SUCCESS; - next_state = state; - switch (state) { - case FlushState::TFFT_CREATE_BLOCK_INDEX: - if (OB_FAIL(handle_create_block_index_(flush_task, next_state))) { - } - break; - case FlushState::TFFT_FILL_BLOCK_BUF: - if (OB_FAIL(handle_fill_block_buf_(flush_task, next_state))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to handle flush task fill block", KR(ret), K(flush_task)); - } - } - break; - case FlushState::TFFT_INSERT_META_TREE: - if (OB_FAIL(handle_insert_meta_tree_(flush_task, next_state))) { - } - break; - case FlushState::TFFT_ASYNC_WRITE: - if (OB_FAIL(handle_async_write_(flush_task, next_state))) { - } - break; - default: - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected state in drive_flush_task_prepare_", KR(ret), K(state), K(flush_task)); - break; - } - return ret; -} - -void ObTmpFileFlushManager::try_remove_unused_flush_info_(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - - ObArray &flush_infos = flush_task.get_flush_infos(); - if (!flush_task.get_block_handle().is_valid()) { - } else { - for (int64_t i = 0; OB_SUCC(ret) && i >= 0 && i < flush_infos.count(); ++i) { - ObTmpFileFlushInfo &flush_info = flush_infos.at(i); - ObSharedNothingTmpFile *file = flush_info.file_handle_.get(); - if (OB_ISNULL(file)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "file is nullptr", KR(ret), K(flush_info)); - } else if (file->is_deleting()) { - STORAGE_LOG(INFO, "the file is deleting, abort this flush info", - KR(ret), K(flush_info), K(flush_task)); - flush_info.reset(); - // manually move and reset flush_info to avoid file handle not released - int64_t last_idx = flush_infos.count() - 1; - for (int64_t j = i; j < last_idx; ++j) { - flush_infos.at(j) = flush_infos.at(j + 1); - } - flush_infos.at(last_idx).reset(); - flush_infos.remove(last_idx); - --i; - } - } - } -} - -int ObTmpFileFlushManager::drive_flush_task_retry_( - ObTmpFileFlushTask &flush_task, - const FlushState state, - FlushState &next_state) -{ - int ret = OB_SUCCESS; - int tmp_ret = OB_SUCCESS; - - next_state = state; - switch (state) { - case FlushState::TFFT_INSERT_META_TREE: - if (OB_FAIL(handle_insert_meta_tree_(flush_task, next_state))) { - } - break; - case FlushState::TFFT_ASYNC_WRITE: - try_remove_unused_flush_info_(flush_task); - if (0 == flush_task.get_flush_infos().count()) { - STORAGE_LOG(INFO, "all flush info is aborted", KR(ret), K(flush_task)); - next_state = FlushState::TFFT_ABORT; - if (OB_TMP_FAIL(tmp_file_block_mgr_.write_back_failed(flush_task.get_block_index()))) { - } - } else if (OB_FAIL(handle_async_write_(flush_task, next_state))) { - } - break; - default: - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected state in drive_flush_task_retry_", KR(ret), K(state), K(flush_task)); - break; - } - return ret; -} - -int ObTmpFileFlushManager::drive_flush_task_wait_(ObTmpFileFlushTask &flush_task, FlushState &next_state) -{ - int ret = OB_SUCCESS; - ObTmpFileFlushTask::ObTmpFileFlushTaskState state = flush_task.get_state(); - switch (state) { - case FlushState::TFFT_WAIT: - if (OB_FAIL(handle_wait_(flush_task, next_state))) { - } - break; - default: - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected state in drive_flush_task_wait_", KR(ret), K(state), K(flush_task)); - break; - } - return ret; -} - -int ObTmpFileFlushManager::retry(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - - FlushState state = flush_task.get_state(); - FlushState next_state = state; - do { - next_state = state = flush_task.get_state(); - if (OB_FAIL(drive_flush_task_retry_(flush_task, state, next_state))) { - } else if (flush_task.get_state() >= next_state) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected flush state after drive task succ", KR(ret), K(state), K(flush_task)); - } else if (OB_FAIL(advance_status_(flush_task, next_state))) { - } - } while (OB_SUCC(ret) && FlushState::TFFT_WAIT != next_state && FlushState::TFFT_ABORT != next_state); - - if (!flush_task.get_recorded_as_prepare_finished()) { - if (flush_task.get_flush_seq() != flush_ctx_.get_flush_sequence()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "flush_seq in flush_task is not equal to flush_seq in flush_ctx", - KR(ret), K(flush_task), K(flush_ctx_)); - } else { - bool recorded_as_prepare_finished = false; - flush_ctx_.try_update_prepare_finished_cnt(flush_task, recorded_as_prepare_finished); - if (recorded_as_prepare_finished) { - flush_task.mark_recorded_as_prepare_finished(); - if (flush_ctx_.can_clear_flush_ctx()) { - flush_ctx_.clear_flush_ctx(flush_priority_mgr_); - } - } - } - } - return ret; -} - -int ObTmpFileFlushManager::io_finished(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - FlushState next_state = FlushState::TFFT_INITED; - if (OB_FAIL(drive_flush_task_wait_(flush_task, next_state))) { - } else if (flush_task.get_state() < next_state && OB_FAIL(advance_status_(flush_task, next_state))) { - // if the task encounters an IO error, its status will silently revert to TFFT_ASYNC_WRITE; do not verify status here. - STORAGE_LOG(WARN, "fail to advance status", KR(ret), K(flush_task.get_state()), K(next_state)); - } - return ret; -} - -int ObTmpFileFlushManager::update_file_meta_after_flush(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - if (FlushState::TFFT_FINISH != flush_task.get_state()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected flush state after drive task succ", KR(ret), K(flush_task)); - } else if (OB_FAIL(handle_finish_(flush_task))) { - } - return ret; -} - -int ObTmpFileFlushManager::advance_status_(ObTmpFileFlushTask &flush_task, const FlushState &state) -{ - int ret = OB_SUCCESS; - if (flush_task.get_state() >= state) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "unexpected state in advance_status_", K(state), K(flush_task)); - } else { - flush_task.set_state(state); - } - return ret; -} - -int ObTmpFileFlushManager::handle_alloc_flush_task_(const bool fast_flush_meta, ObTmpFileFlushTask *&flush_task) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(alloc_flush_task(flush_task))) { - } else if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush cb is null", KR(ret)); - } else { - flush_task->set_state(FlushState::TFFT_CREATE_BLOCK_INDEX); - flush_task->set_create_ts(ObTimeUtil::current_time()); - flush_task->set_last_print_ts(ObTimeUtil::current_time()); - flush_task->set_flush_seq(flush_ctx_.get_flush_sequence()); - flush_task->set_is_fast_flush_tree(fast_flush_meta); - } - return ret; -} - -int ObTmpFileFlushManager::handle_create_block_index_(ObTmpFileFlushTask &flush_task, FlushState &next_state) -{ - int ret = OB_SUCCESS; - int64_t block_index = ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - ObTmpFileBlockHandle tmp_file_block_handle; - // occupy the whole tmp file block because we don't know how many pages we will use before TFFT_FILL_BLOCK_BUF, - // and we still create block first because copy meta tree pages needs to provide tmp file block's block_index, - // unused pages will be released after TFFT_FILL_BLOCK_BUF succ - if (OB_FAIL(tmp_file_block_mgr_.create_tmp_file_block(0/*begin_page_id*/, - ObTmpFileGlobal::BLOCK_PAGE_NUMS, - block_index))) { - } else if (OB_FAIL(tmp_file_block_mgr_.get_tmp_file_block_handle(block_index, tmp_file_block_handle))) { - } else { - flush_task.set_tmp_file_block_handle(tmp_file_block_handle); - flush_task.set_block_index(block_index); - next_state = FlushState::TFFT_FILL_BLOCK_BUF; - } - return ret; -} - -// For performance reasons, we have delayed the memory allocation and data copying of the flush data task -// until the TFFT_ASYNC_WRITE stage, distributing tasks across 4 timer threads for execution; -// flush meta task has fewer occurrences, so we allocate and copy memory directly in the current thread. -int ObTmpFileFlushManager::handle_fill_block_buf_(ObTmpFileFlushTask &flush_task, FlushState &next_state) -{ - int ret = OB_SUCCESS; - int tmp_ret = OB_SUCCESS; - if (flush_task.get_is_fast_flush_tree()) { // skip flush level, copy meta tree pages directly - if (OB_FAIL(flush_task.prealloc_block_buf())) { - } else if (OB_FAIL(fast_fill_block_buf_with_meta_(flush_task))) { - } - } else { - if (OB_FAIL(fill_block_buf_(flush_task))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to fill block buf", KR(ret), K(flush_task)); - } - } - - // override error code - if (OB_ITER_END == ret && pc_ctrl_.is_flush_all_data() && 0 == flush_task.get_data_length()) { - // try to fill with meta pages if could not get any data pages - if (OB_FAIL(fill_block_buf_(flush_task))) { - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to fill block buf", KR(ret), K(flush_task)); - } - } - } - - if (OB_SUCC(ret) && 0 == flush_task.get_data_length()) { - ret = OB_ITER_END; - } - } - - if (OB_FAIL(ret)){ - if (OB_ITER_END != ret) { - STORAGE_LOG(WARN, "fail to fill block buf, skip release page", KR(ret)); - } - } else if (OB_UNLIKELY(flush_task.get_flush_infos().empty())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "flush infos is empty", KR(ret), K(flush_task)); - } else { - for (int64_t i = 0; OB_SUCC(ret) && i < flush_task.get_flush_infos().count(); ++i) { - if (OB_UNLIKELY(flush_task.get_flush_infos().at(i).has_data() && - flush_task.get_flush_infos().at(i).has_meta())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "flush info has both data and meta", KR(ret), K(flush_task)); - } else if (OB_UNLIKELY(ObTmpFileFlushTask::DATA == flush_task.get_type() && - flush_task.get_flush_infos().at(i).has_meta())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "flush infos contain unexpected page type", KR(ret), K(flush_task)); - } else if (OB_UNLIKELY(ObTmpFileFlushTask::META == flush_task.get_type() && - flush_task.get_flush_infos().at(i).has_data())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "flush infos contain unexpected page type", KR(ret), K(flush_task)); - } - } - } - - if (OB_SUCC(ret)) { - int64_t used_page_num = flush_task.get_total_page_num(); - int64_t unused_page_id = used_page_num; - int64_t unused_page_num = ObTmpFileGlobal::BLOCK_PAGE_NUMS - used_page_num; - int64_t block_index = flush_task.get_block_index(); - bool need_release_page = unused_page_num > 0; - - if (OB_FAIL(tmp_file_block_mgr_.write_back_start(block_index))) { - } else if (need_release_page && OB_FAIL(tmp_file_block_mgr_.release_tmp_file_page( - block_index, unused_page_id, unused_page_num))) { - STORAGE_LOG(ERROR, "fail to release tmp file page", - KR(ret), K(unused_page_id), K(unused_page_num), K(used_page_num), K(block_index), K(flush_task)); - } else { - next_state = FlushState::TFFT_INSERT_META_TREE; - } - } - - return ret; -} - -int ObTmpFileFlushManager::handle_insert_meta_tree_(ObTmpFileFlushTask &flush_task, FlushState &next_state) -{ - int ret = OB_SUCCESS; - if (OB_FAIL(insert_items_into_meta_tree_(flush_task, flush_task.get_block_index()))) { - } else { - next_state = FlushState::TFFT_ASYNC_WRITE; - } - return ret; -} - -int ObTmpFileFlushManager::handle_async_write_(ObTmpFileFlushTask &flush_task, FlushState &next_state) -{ - int ret = OB_SUCCESS; - cur_flush_timer_idx_ = (cur_flush_timer_idx_ + 1) % ObTmpFileGlobal::FLUSH_TIMER_CNT; - if (OB_UNLIKELY(cur_flush_timer_idx_ < 0 || cur_flush_timer_idx_ >= ObTmpFileGlobal::FLUSH_TIMER_CNT)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected cur_flush_timer_idx_", KR(ret), K(cur_flush_timer_idx_)); - } else if (OB_ISNULL(flush_timers_[cur_flush_timer_idx_])) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(flush_timers_[cur_flush_timer_idx_]->schedule( - flush_task.get_flush_write_block_task(), 0/*delay*/, false/*repeat*/))) { - } else { - next_state = FlushState::TFFT_WAIT; - } - - return ret; -} - -int ObTmpFileFlushManager::handle_wait_(ObTmpFileFlushTask &flush_task, FlushState &next_state) -{ - int ret = OB_SUCCESS; - int write_block_ret_code = flush_task.atomic_get_write_block_ret_code(); - int task_ret_code = flush_task.atomic_get_ret_code(); - if (OB_SUCCESS != write_block_ret_code || OB_SUCCESS != task_ret_code) { - // rollback the status to TFFT_ASYNC_WRITE if IO failed, and re-send the I/O in the retry process. - STORAGE_LOG(INFO, "flush_task io fail, retry it later", - KR(write_block_ret_code), KR(task_ret_code), K(flush_task)); - flush_task.atomic_set_write_block_executed(false); - flush_task.atomic_set_io_finished(false); - flush_task.set_state(FlushState::TFFT_ASYNC_WRITE); - } else if (OB_FAIL(tmp_file_block_mgr_.write_back_succ(flush_task.get_block_index(), - flush_task.get_macro_block_handle().get_macro_id()))) { - } else { - next_state = FlushState::TFFT_FINISH; - } - return ret; -} - -// Update file meta after flush task IO complete, ensures reentrancy -int ObTmpFileFlushManager::handle_finish_(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(update_meta_data_after_flush_for_files_(flush_task))) { - } else { - } - - return ret; -} - - -int ObTmpFileFlushManager::update_meta_data_after_flush_for_files_(ObTmpFileFlushTask &flush_task) -{ - int ret = OB_SUCCESS; - ObArray &flush_infos = flush_task.get_flush_infos(); - for (int64_t i = 0; OB_SUCC(ret) && i < flush_infos.size(); ++i) { - ObTmpFileFlushInfo &flush_info = flush_infos.at(i); - ObSharedNothingTmpFile *file = flush_info.file_handle_.get(); - bool is_meta = false; - bool reset_ctx = false; - if (!flush_info.update_meta_data_done_) { - if (OB_ISNULL(file)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "tmp file ptr is null", KR(ret), K(i), K(flush_task)); - } else if ((OB_UNLIKELY(flush_info.has_data() && flush_info.has_meta()) || - OB_UNLIKELY(!flush_info.has_data() && !flush_info.has_meta()))) { - ret = OB_ERR_UNEXPECTED; // expect one flush_info only contains one type of pages - STORAGE_LOG(ERROR, "flush info is not valid", KR(ret), K(flush_info)); - } else if (FALSE_IT(is_meta = flush_info.has_meta())) { - } else if (OB_FAIL(file->update_meta_after_flush(flush_info.batch_flush_idx_, is_meta, reset_ctx))){ - } else { - if (reset_ctx && flush_task.get_flush_seq() == flush_ctx_.get_flush_sequence()) { - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(reset_flush_ctx_for_file_(file, is_meta))) { - } - } - flush_info.update_meta_data_done_ = true; - } - } - } - return ret; -} - -// reset data/meta flush ctx after file update meta complete to prevent -// flush use stale flushed_page_id to copy data after the page is evicted -int ObTmpFileFlushManager::reset_flush_ctx_for_file_(const ObSharedNothingTmpFile *file, const bool is_meta) -{ - int ret = OB_SUCCESS; - ObTmpFileSingleFlushContext update_ctx; - if (OB_ISNULL(file)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "tmp file ptr is null", KR(ret), K(file)); - } else if (OB_FAIL(flush_ctx_.get_file_ctx_hash().get_refactored(file->get_fd(), update_ctx))) { - if (OB_HASH_NOT_EXIST == ret) { - // do nothing - } else { - STORAGE_LOG(WARN, "fail to get file ctx from hash", KR(ret), K(file)); - } - } else if (OB_ISNULL(update_ctx.file_handle_.get())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "file handle in flush context is null", KR(ret), K(file)); - } else { - if (is_meta) { - update_ctx.meta_ctx_.reset(); - } else { - update_ctx.data_ctx_.reset(); - } - - if (OB_FAIL(flush_ctx_.get_file_ctx_hash().set_refactored(file->get_fd(), update_ctx, 1/*cover_object*/))) { - } - } - return ret; -} - -void ObTmpFileFlushManager::try_remove_unused_file_flush_ctx() -{ - int ret = OB_SUCCESS; - - ObArray deleted_fd_arr; - ObTmpFileBatchFlushContext::ObTmpFileFlushCtxHash& file_ctx_hash = flush_ctx_.get_file_ctx_hash(); - for (ObTmpFileBatchFlushContext::ObTmpFileFlushCtxHash::iterator iter = file_ctx_hash.begin(); - OB_SUCC(ret) && iter != file_ctx_hash.end(); - ++iter) { - int64_t fd = iter->first; - ObTmpFileSingleFlushContext &file_flush_ctx = iter->second; - ObSharedNothingTmpFile *file = file_flush_ctx.file_handle_.get(); - if (OB_ISNULL(file)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "file is nullptr", KR(ret), K(fd), K(file_flush_ctx)); - } else if (file->is_deleting()) { - STORAGE_LOG(INFO, "the file is deleting, delete unused file flush ctx", - KR(ret), K(fd), K(file_flush_ctx)); - if (OB_FAIL(deleted_fd_arr.push_back(fd))) { - } - } - } - - int tmp_ret = OB_SUCCESS; - for (int64_t i = 0; OB_SUCCESS == tmp_ret && i < deleted_fd_arr.count(); ++i) { - if (OB_TMP_FAIL(flush_ctx_.get_file_ctx_hash().erase_refactored(deleted_fd_arr[i]))) { - } - } -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_flush_manager.h b/src/storage/tmp_file/ob_tmp_file_flush_manager.h deleted file mode 100644 index 10fed89976..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_manager.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_TASK_MANAGER_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_TASK_MANAGER_H_ - -#include "storage/tmp_file/ob_tmp_file_eviction_manager.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_tmp_file_flush_ctx.h" -#include "storage/tmp_file/ob_tmp_file_flush_priority_manager.h" -#include "storage/tmp_file/ob_tmp_file_thread_job.h" -#include "lib/task/ob_timer.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -// flush manager generates flush tasks according to dirty page watermark -class ObTmpFileFlushManager -{ -public: - static const int32_t FLUSH_WATERMARK_F1 = 50; // percentage - static const int32_t FLUSH_WATERMARK_F2 = 70; - static const int32_t FLUSH_WATERMARK_F3 = 75; - static const int32_t FLUSH_WATERMARK_F4 = 80; - static const int32_t FLUSH_WATERMARK_F5 = 90; - static const int32_t FLUSH_LOW_WATERMARK_F1 = 25; - static const int32_t FLUSH_LOW_WATERMARK_F2 = 60; - static const int32_t FLUSH_LOW_WATERMARK_F3 = 65; - static const int32_t FLUSH_LOW_WATERMARK_F4 = 70; - static const int32_t FLUSH_LOW_WATERMARK_F5 = 80; - static const int64_t FAST_FLUSH_TREE_PAGE_NUM = 32; - static const int64_t FLUSH_TASK_FINISH_WARN_TIMEOUT_US = 60 * 1000 * 1000; // 60s - struct UpdateFlushCtx - { - public: - UpdateFlushCtx(ObTmpFileSingleFlushContext &file_ctx) - : input_data_ctx_(file_ctx.data_ctx_), - input_meta_ctx_(file_ctx.meta_ctx_) {} - void operator() (hash::HashMapPair &pair); - private: - ObTmpFileDataFlushContext &input_data_ctx_; - ObTmpFileTreeFlushContext &input_meta_ctx_; - }; - struct ResetFlushCtxOp - { - public: - public: - ResetFlushCtxOp(const bool is_meta) : is_meta_(is_meta) {} - private: - bool is_meta_; - }; -public: - typedef ObTmpFileGlobal::FlushCtxState FlushCtxState; - typedef common::ObDList ObTmpFileFlushList; - typedef ObTmpFileFlushTask::ObTmpFileFlushTaskState FlushState; - ObTmpFileFlushManager(ObTmpFilePageCacheController &pc_ctrl); - ~ObTmpFileFlushManager() {} - int init(); - void destroy(); - void set_flush_timers(common::ObTimer *flush_timers, const int64_t timer_cnt); - TO_STRING_KV(K(is_inited_), K(flush_ctx_)); - -public: - int free_tmp_file_block(ObTmpFileFlushTask &flush_task); - virtual int alloc_flush_task(ObTmpFileFlushTask *&flush_task); - int free_flush_task(ObTmpFileFlushTask *flush_task); - int notify_write_back_failed(ObTmpFileFlushTask *flush_task); - int flush(ObSpLinkQueue &flushing_queue, - ObTmpFileFlushMonitor &flush_monitor, - const int64_t expect_flush_size, - const int64_t current_flush_cnt, - const bool is_flush_meta_tree); - int retry(ObTmpFileFlushTask &flush_task); - int io_finished(ObTmpFileFlushTask &flush_task); - int update_file_meta_after_flush(ObTmpFileFlushTask &flush_task); - void try_remove_unused_file_flush_ctx(); -private: - int check_tmp_file_disk_usage_limit_(const int64_t current_flushing_cnt); - int fill_block_buf_(ObTmpFileFlushTask &flush_task); - int fast_fill_block_buf_with_meta_(ObTmpFileFlushTask &flush_task); - int inner_fill_block_buf_(ObTmpFileFlushTask &flush_task, - const FlushCtxState flush_stage, - const bool is_meta, - const bool flush_tail); - int insert_items_into_meta_tree_(ObTmpFileFlushTask &flush_task, - const int64_t logic_block_index); - void init_flush_level_(); - void advance_flush_level_(const int ret_code); - void inner_advance_flush_level_(); - void inner_advance_flush_level_without_checking_watermark_(); - int64_t get_low_watermark_(FlushCtxState state); - int advance_status_(ObTmpFileFlushTask &flush_task, const FlushState &state); - int drive_flush_task_prepare_(ObTmpFileFlushTask &flush_task, const FlushState state, FlushState &next_state); - int drive_flush_task_retry_(ObTmpFileFlushTask &flush_task, const FlushState state, FlushState &next_state); - int drive_flush_task_wait_(ObTmpFileFlushTask &flush_task, FlushState &next_state); - int handle_alloc_flush_task_(const bool fast_flush_meta, ObTmpFileFlushTask *&flush_task); - int handle_create_block_index_(ObTmpFileFlushTask &flush_task, FlushState &next_state); - int handle_fill_block_buf_(ObTmpFileFlushTask &flush_task, FlushState &next_state); - int handle_insert_meta_tree_(ObTmpFileFlushTask &flush_task, FlushState &next_state); - int handle_async_write_(ObTmpFileFlushTask &flush_task, FlushState &next_state); - int handle_wait_(ObTmpFileFlushTask &flush_task, FlushState &next_state); - int handle_finish_(ObTmpFileFlushTask &flush_task); -private: - int flush_by_watermark_(ObSpLinkQueue &flushing_queue, - const int64_t current_flush_cnt, - const bool is_flush_meta_tree); - int update_meta_data_after_flush_for_files_(ObTmpFileFlushTask &flush_task); - int reset_flush_ctx_for_file_(const ObSharedNothingTmpFile *file, const bool is_meta); - int get_or_create_file_in_ctx_(const int64_t fd, ObTmpFileSingleFlushContext &file_flush_ctx); - int evict_pages_and_retry_insert_(ObTmpFileFlushTask &flush_task, - ObTmpFileFlushInfo &flush_info, - const int64_t logic_block_index); - void try_remove_unused_flush_info_(ObTmpFileFlushTask &flush_task); - DISALLOW_COPY_AND_ASSIGN(ObTmpFileFlushManager); -private: - bool is_inited_; - ObTmpFileBatchFlushContext flush_ctx_; - ObTmpFilePageCacheController &pc_ctrl_; - ObTmpFileBlockManager &tmp_file_block_mgr_; - ObIAllocator &task_allocator_; // ref to ObTmpFilePageCacheController::task_allocator_ - ObTmpWriteBufferPool &write_buffer_pool_; - ObTmpFileEvictionManager &evict_mgr_; - ObTmpFileFlushPriorityManager &flush_priority_mgr_; - int32_t cur_flush_timer_idx_; - common::ObTimer *flush_timers_[ObTmpFileGlobal::FLUSH_TIMER_CNT]; -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_TASK_MANAGER_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_flush_priority_manager.cpp b/src/storage/tmp_file/ob_tmp_file_flush_priority_manager.cpp deleted file mode 100644 index 99fe8546f4..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_priority_manager.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_flush_priority_manager.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "share/ob_errno.h" - -namespace oceanbase -{ -namespace tmp_file -{ -//----------------------- ObTmpFileFlushPriorityManager -------------------// -int ObTmpFileFlushPriorityManager::init() -{ - int ret = OB_SUCCESS; - STATIC_ASSERT(ARRAYSIZEOF(data_flush_lists_) == (int64_t)FileList::MAX, - "data_flush_lists_ size mismatch enum FileList count"); - STATIC_ASSERT(ARRAYSIZEOF(data_list_locks_) == (int64_t)FileList::MAX, - "data_list_locks_ size mismatch enum FileList count"); - STATIC_ASSERT(ARRAYSIZEOF(meta_flush_lists_) == (int64_t)FileList::MAX, - "meta_flush_lists_ size mismatch enum FileList count"); - STATIC_ASSERT(ARRAYSIZEOF(meta_list_locks_) == (int64_t)FileList::MAX, - "meta_list_locks_ size mismatch enum FileList count"); - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else { - is_inited_ = true; - LOG_INFO("ObTmpFileFlushPriorityManager init succ", K(is_inited_)); - } - return ret; -} - -void ObTmpFileFlushPriorityManager::destroy() -{ - // int ret = OB_SUCCESS; - // ObSharedNothingTmpFile *file = nullptr; - is_inited_ = false; - for (int64_t i = 0; i < FileList::MAX; i++) { - ObSpinLockGuard guard(data_list_locks_[i]); - data_flush_lists_[i].reset(); - } - for (int64_t i = 0; i < FileList::MAX; i++) { - ObSpinLockGuard guard(meta_list_locks_[i]); - meta_flush_lists_[i].reset(); - } - LOG_INFO("ObTmpFileFlushPriorityManager destroy succ"); -} - -int64_t ObTmpFileFlushPriorityManager::get_file_size() -{ - int64_t size = 0; - is_inited_ = false; - for (int64_t i = 0; i < FileList::MAX; i++) { - ObSpinLockGuard guard(data_list_locks_[i]); - size += data_flush_lists_[i].get_size(); - } - for (int64_t i = 0; i < FileList::MAX; i++) { - ObSpinLockGuard guard(meta_list_locks_[i]); - size += meta_flush_lists_[i].get_size(); - } - return size; -} - -// attention: -// call this function with protection of ObSharedNothingTmpFile's meta_lock -int ObTmpFileFlushPriorityManager::insert_data_flush_list(ObSharedNothingTmpFile &file, const int64_t dirty_page_size) -{ - int ret = OB_SUCCESS; - FileList flush_idx = FileList::MAX; - - if (OB_FAIL(get_data_list_idx_(dirty_page_size, flush_idx))) { - } else if (OB_FAIL(insert_flush_list_(false/*is_meta*/, file, flush_idx))) { - } else { - } - - return ret; -} - -// attention: -// call this function with protection of ObSharedNothingTmpFile's meta_lock -int ObTmpFileFlushPriorityManager::insert_meta_flush_list(ObSharedNothingTmpFile &file, - const int64_t non_rightmost_dirty_page_num, - const int64_t rightmost_dirty_page_num) -{ - int ret = OB_SUCCESS; - FileList flush_idx = FileList::MAX; - - if (OB_FAIL(get_meta_list_idx_(non_rightmost_dirty_page_num, rightmost_dirty_page_num, flush_idx))) { - } else if (OB_FAIL(insert_flush_list_(true/*is_meta*/, file, flush_idx))) { - } else { - } - - return ret; -} - -int ObTmpFileFlushPriorityManager::insert_flush_list_(const bool is_meta, ObSharedNothingTmpFile &file, - const FileList flush_idx) -{ - int ret = OB_SUCCESS; - ObSharedNothingTmpFile::ObTmpFileNode *flush_node = nullptr; - ObSpinLock* locks = is_meta ? meta_list_locks_ : data_list_locks_; - ObTmpFileFlushList *flush_lists = is_meta ? meta_flush_lists_ : data_flush_lists_; - - if (OB_FAIL(get_file_flush_node_(is_meta, file, flush_node))) { - } else if (OB_ISNULL(flush_node)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(flush_node->get_next() != nullptr)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(flush_idx < FileList::L1 || flush_idx >= FileList::MAX)) { - ret = OB_ERR_UNEXPECTED; - } else { - ObSpinLockGuard guard(locks[flush_idx]); - file.inc_ref_cnt(); - if (OB_UNLIKELY(!flush_lists[flush_idx].add_last(flush_node))) { - file.dec_ref_cnt(); - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(set_flush_page_level_(is_meta, flush_idx, file))) { - } - } - - return ret; -} - -// attention: -// call this function with protection of ObSharedNothingTmpFile's meta_lock -int ObTmpFileFlushPriorityManager::update_data_flush_list(ObSharedNothingTmpFile &file, const int64_t dirty_page_size) -{ - int ret = OB_SUCCESS; - FileList new_flush_idx = FileList::MAX; - - if (OB_FAIL(get_data_list_idx_(dirty_page_size, new_flush_idx))) { - } else if (OB_FAIL(update_flush_list_(false/*is_meta*/, file, new_flush_idx))) { - } else { - } - return ret; -} - -// attention: -// call this function with protection of ObSharedNothingTmpFile's meta_lock -int ObTmpFileFlushPriorityManager::update_meta_flush_list(ObSharedNothingTmpFile &file, - const int64_t non_rightmost_dirty_page_num, - const int64_t rightmost_dirty_page_num) -{ - int ret = OB_SUCCESS; - FileList new_flush_idx = FileList::MAX; - - if (OB_FAIL(get_meta_list_idx_(non_rightmost_dirty_page_num, rightmost_dirty_page_num, new_flush_idx))) { - } else if (OB_FAIL(update_flush_list_(true/*is_meta*/, file, new_flush_idx))) { - } else { - } - return ret; -} - -int ObTmpFileFlushPriorityManager::update_flush_list_(const bool is_meta, ObSharedNothingTmpFile &file, - const FileList new_flush_idx) -{ - int ret = OB_SUCCESS; - ObSharedNothingTmpFile::ObTmpFileNode *flush_node = nullptr; - ObSpinLock* locks = is_meta ? meta_list_locks_ : data_list_locks_; - ObTmpFileFlushList *flush_lists = is_meta ? meta_flush_lists_ : data_flush_lists_; - FileList cur_flush_idx = FileList::INVALID; - - if (OB_FAIL(get_file_flush_node_(is_meta, file, flush_node))) { - } else if (OB_ISNULL(flush_node)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(get_file_flush_level_(is_meta, file, cur_flush_idx))) { - } else if (cur_flush_idx < FileList::L1 || cur_flush_idx >= FileList::MAX){ - ret = OB_ERR_UNEXPECTED; - } else if (new_flush_idx == cur_flush_idx) { - // no need to update - } else { // need to move file into a new flush list - bool is_in_flushing = false; - { - ObSpinLockGuard guard(locks[cur_flush_idx]); - if (OB_ISNULL(flush_node->get_next())) { - // before we lock the list, flush task mgr has popped the node from list and is operating it, do nothing - is_in_flushing = true; - } else if (OB_UNLIKELY(!flush_lists[cur_flush_idx].remove(flush_node))) { - ret = OB_ERR_UNEXPECTED; - } - } - - if (OB_FAIL(ret)) { - } else if (is_in_flushing) { - // the node will be added into flush list again by flush task mgr - // do nothing - } else { - ObSpinLockGuard guard(locks[new_flush_idx]); - if (OB_UNLIKELY(!flush_lists[new_flush_idx].add_last(flush_node))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(set_flush_page_level_(is_meta, new_flush_idx, file))) { - } - } - } - - return ret; -} - -int ObTmpFileFlushPriorityManager::remove_file(ObSharedNothingTmpFile &file) -{ - return ObTmpFileGlobal::remove_from_meta_and_data_lists( - [this, &file](const bool is_meta) { return remove_file(is_meta, file); }); -} - -// attention: -// call this function with protection of ObSharedNothingTmpFile's meta_lock -int ObTmpFileFlushPriorityManager::remove_file(const bool is_meta, ObSharedNothingTmpFile &file) -{ - int ret = OB_SUCCESS; - FileList flush_idx = FileList::INVALID ; - ObSharedNothingTmpFile::ObTmpFileNode *flush_node = nullptr; - - if (OB_FAIL(get_file_flush_level_(is_meta, file, flush_idx))) { - } else if (FileList::INVALID == flush_idx) { - // file doesn't exist in the flushing list - // do nothing - } else if (flush_idx < FileList::L1 || flush_idx >= FileList::MAX){ - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(get_file_flush_node_(is_meta, file, flush_node))) { - } else if (OB_ISNULL(flush_node)) { - ret = OB_ERR_UNEXPECTED; - } else { - ObSpinLock* locks = is_meta ? meta_list_locks_ : data_list_locks_; - ObTmpFileFlushList *flush_lists = is_meta ? meta_flush_lists_ : data_flush_lists_; - ObSpinLockGuard guard(locks[flush_idx]); - if (OB_ISNULL(flush_node->get_next())) { - // node has not been inserted, do nothing - } else if (OB_ISNULL(flush_lists[flush_idx].remove(flush_node))) { - ret = OB_ERR_UNEXPECTED; - } else { - file.dec_ref_cnt(); - if (OB_FAIL(set_flush_page_level_(is_meta, FileList::INVALID, file))) { - } - } - } - return ret; -} - -int ObTmpFileFlushPriorityManager::popN_from_file_list(const bool is_meta, const int64_t list_idx, - const int64_t expected_count, int64_t &actual_count, - ObArray &file_handles) -{ - int ret = OB_SUCCESS; - ObSpinLock* locks = is_meta ? meta_list_locks_ : data_list_locks_; - ObTmpFileFlushList *flush_lists = is_meta ? meta_flush_lists_ : data_flush_lists_; - actual_count = 0; - - if (OB_UNLIKELY(list_idx < FileList::L1 || list_idx >= FileList::MAX)) { - ret = OB_INVALID_ARGUMENT; - } else { - ObSpinLockGuard guard(locks[list_idx]); - while (OB_SUCC(ret) && !flush_lists[list_idx].is_empty() && actual_count < expected_count) { - ObSharedNothingTmpFile *file = nullptr; - if (OB_ISNULL(file = &flush_lists[list_idx].remove_first()->file_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(file_handles.push_back(file))) { - int tmp_ret = OB_SUCCESS; - ObSharedNothingTmpFile::ObTmpFileNode *node = nullptr; - if (OB_FAIL(get_file_flush_node_(is_meta, *file, node))) { - } else if (OB_ISNULL(node)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!flush_lists[list_idx].add_last(node))) { - tmp_ret = OB_ERR_UNEXPECTED; - LOG_WARN("fail to add node to list", KR(tmp_ret), K(list_idx), KP(file)); - } - } else { - file->dec_ref_cnt(); // ref_cnt of flush list - actual_count++; - } - } // end while - } - - return ret; -} - -int ObTmpFileFlushPriorityManager::get_file_flush_node_(const bool is_meta, ObSharedNothingTmpFile &file, - ObSharedNothingTmpFile::ObTmpFileNode *&flush_node) -{ - int ret = OB_SUCCESS; - flush_node = nullptr; - - if (is_meta) { - flush_node = file.get_meta_flush_node(); - } else { - flush_node = file.get_data_flush_node(); - } - - return ret; -} - -int ObTmpFileFlushPriorityManager::get_file_flush_level_(const bool is_meta, ObSharedNothingTmpFile &file, FileList &flush_level) -{ - int ret = OB_SUCCESS; - flush_level = FileList::INVALID; - - if (is_meta) { - flush_level = static_cast(file.get_meta_page_flush_level()); - } else { - flush_level = static_cast(file.get_data_page_flush_level()); - } - - return ret; -} - -int ObTmpFileFlushPriorityManager::set_flush_page_level_(const bool is_meta, const FileList flush_idx, ObSharedNothingTmpFile &file) -{ - int ret = OB_SUCCESS; - if (is_meta) { - file.set_meta_page_flush_level(flush_idx); - } else { - file.set_data_page_flush_level(flush_idx); - } - - return ret; -} - -int ObTmpFileFlushPriorityManager::get_meta_list_idx_(const int64_t non_rightmost_dirty_page_num, - const int64_t rightmost_dirty_page_num, FileList &idx) -{ - int ret = OB_SUCCESS; - idx = FileList::MAX; - if (non_rightmost_dirty_page_num + rightmost_dirty_page_num <= 0) { - ret = OB_INVALID_ARGUMENT; - } else if (non_rightmost_dirty_page_num == 0) { // all dirty pages is the rightmost page - idx = FileList::L5; - } else if (non_rightmost_dirty_page_num < 16) { // (0KB, 128KB) - idx = FileList::L4; - } else if (non_rightmost_dirty_page_num < 128) { // [128KB, 1MB) - idx = FileList::L3; - } else if (non_rightmost_dirty_page_num < 256) { // [1MB, 2MB) - idx = FileList::L2; - } else { // [2MB, INFINITE) - idx = FileList::L1; - } - return ret; -} - -int ObTmpFileFlushPriorityManager::get_data_list_idx_(const int64_t dirty_page_size, FileList &idx) -{ - int ret = OB_SUCCESS; - idx = FileList::MAX; - if (dirty_page_size <= 0) { - ret = OB_INVALID_ARGUMENT; - } else if (dirty_page_size < (1 << 13)) { // page_size 8KB, (0, 8KB) - idx = FileList::L5; - } else if (dirty_page_size < (1 << 17)) { // [8KB, 128KB) - idx = FileList::L4; - } else if (dirty_page_size < (1 << 20)) { // [128KB, 1MB) - idx = FileList::L3; - } else if (dirty_page_size < (1 << 21)) { // [1MB, 2MB) - idx = FileList::L2; - } else { // [2MB, INFINITE) - idx = FileList::L1; - } - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_flush_priority_manager.h b/src/storage/tmp_file/ob_tmp_file_flush_priority_manager.h deleted file mode 100644 index 1c798be305..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_flush_priority_manager.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_PRIORITY_MANAGER_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_PRIORITY_MANAGER_H_ - -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "lib/container/ob_array.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileFlushPriorityManager -{ -public: - ObTmpFileFlushPriorityManager() - : is_inited_(false), - data_flush_lists_(), - data_list_locks_(), - meta_flush_lists_(), - meta_list_locks_() - {} - ~ObTmpFileFlushPriorityManager() {} - int init(); - void destroy(); - -private: - typedef common::ObDList ObTmpFileFlushList; - friend class ObTmpFileFlushListIterator; - -public: - int insert_data_flush_list(ObSharedNothingTmpFile &file, const int64_t dirty_page_size); - int insert_meta_flush_list(ObSharedNothingTmpFile &file, const int64_t non_rightmost_dirty_page_num, - const int64_t rightmost_dirty_page_num); - int update_data_flush_list(ObSharedNothingTmpFile &file, const int64_t dirty_page_size); - int update_meta_flush_list(ObSharedNothingTmpFile &file, const int64_t non_rightmost_dirty_page_num, - const int64_t rightmost_dirty_page_num); - int remove_file(ObSharedNothingTmpFile &file); - int remove_file(const bool is_meta, ObSharedNothingTmpFile &file); - int popN_from_file_list(const bool is_meta, const int64_t list_idx, - const int64_t expected_count, int64_t &actual_count, - ObArray &file_handles); - int64_t get_file_size(); -private: - typedef ObTmpFileGlobal::FileList FileList; - int get_file_flush_node_(const bool is_meta, ObSharedNothingTmpFile &file, ObSharedNothingTmpFile::ObTmpFileNode *&flush_node); - int get_file_flush_level_(const bool is_meta, ObSharedNothingTmpFile &file, FileList &flush_level); - int get_meta_list_idx_(const int64_t non_rightmost_dirty_page_num, - const int64_t rightmost_dirty_page_num, FileList &idx); - int get_data_list_idx_(const int64_t dirty_page_size, FileList &idx); - int set_flush_page_level_(const bool is_meta, const FileList flush_idx, ObSharedNothingTmpFile &file); - int insert_flush_list_(const bool is_meta, ObSharedNothingTmpFile &file, - const FileList flush_idx); - int update_flush_list_(const bool is_meta, ObSharedNothingTmpFile &file, - const FileList new_flush_idx); - -private: - bool is_inited_; - ObTmpFileFlushList data_flush_lists_[FileList::MAX]; - ObSpinLock data_list_locks_[FileList::MAX]; - ObTmpFileFlushList meta_flush_lists_[FileList::MAX]; - ObSpinLock meta_list_locks_[FileList::MAX]; -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_FLUSH_PRIORITY_MANAGER_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_global.cpp b/src/storage/tmp_file/ob_tmp_file_global.cpp deleted file mode 100644 index 2291ded13d..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_global.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "lib/oblog/ob_log_module.h" -#include "lib/oblog/ob_log_print_kv.h" -#include "lib/oblog/ob_log.h" - -namespace oceanbase -{ -namespace tmp_file -{ -const int64_t ObTmpFileGlobal::INVALID_TMP_FILE_FD = -1; -const int64_t ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID = -1; -const int64_t ObTmpFileGlobal::TMP_FILE_READ_BATCH_SIZE = 8 * 1024 * 1024; // 8MB -const int64_t ObTmpFileGlobal::TMP_FILE_WRITE_BATCH_PAGE_NUM = 16; -const int64_t ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX = -1; -const uint32_t ObTmpFileGlobal::INVALID_PAGE_ID = UINT32_MAX; -const int64_t ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID = -1; - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_global.h b/src/storage/tmp_file/ob_tmp_file_global.h deleted file mode 100644 index d1c7d2ae0c..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_global.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_GLOBAL_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_GLOBAL_H_ -#include "lib/ob_define.h" - -namespace oceanbase -{ -namespace tmp_file -{ -struct ObTmpFileGlobal final -{ - // SN_TMP_FILE - static const int64_t INVALID_TMP_FILE_FD; - static const int64_t INVALID_TMP_FILE_DIR_ID; - - static constexpr int64_t ALLOC_PAGE_SIZE = 8 * 1024; // 8KB - static constexpr int64_t SN_BLOCK_SIZE = OB_DEFAULT_MACRO_BLOCK_SIZE; // 2MB - static constexpr int64_t BLOCK_PAGE_NUMS = - SN_BLOCK_SIZE / ALLOC_PAGE_SIZE; // 256 pages per macro block - - static const int64_t TMP_FILE_READ_BATCH_SIZE; - static const int64_t TMP_FILE_WRITE_BATCH_PAGE_NUM; - - static const int64_t TMP_FILE_MAX_LABEL_SIZE = 15; - - // SN_TMP_FILE_BLOCK - static const int64_t INVALID_TMP_FILE_BLOCK_INDEX; - - // TMP_FILE_WRITE_BUFFER - static const uint32_t INVALID_PAGE_ID; - static const int64_t INVALID_VIRTUAL_PAGE_ID; - - // TMP_FILE_FLUSH_STAGE - enum FlushCtxState - { - FSM_F1 = 0, // flush data list L1 - FSM_F2 = 1, // flush data list L2 & L3 & L4 - FSM_F3 = 2, // flush data list L5 - FSM_F4 = 3, // flush meta list non-rightmost pages - FSM_F5 = 4, // flush meta list rightmost pages - FSM_FINISHED = 5 - }; - static const int64_t INVALID_FLUSH_SEQUENCE = -1; - static const int32_t FLUSH_TIMER_CNT = 4; - static const int64_t MAX_FLUSHING_BLOCK_NUM = 200; - - enum FileList { - INVALID = -1, - L1 = 0, // [2MB, INFINITE) - L2, // [1MB, 2MB) - L3, // [128KB, 1MB) - L4, // data_list: [8KB, 128KB); meta_list: (0KB, 128KB) - L5, // data_list: (0, 8KB); meta_list: 0KB - MAX - }; - static const int64_t TMP_FILE_STAT_FREQUENCY = 1 * 1000 * 1000; // 1s - - template - static int remove_from_meta_and_data_lists(Remove remove) - { - const int ret = remove(true /* is_meta */); - return common::OB_SUCCESS == ret ? remove(false /* is_meta */) : ret; - } -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_GLOBAL_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_io.cpp b/src/storage/tmp_file/ob_tmp_file_io.cpp deleted file mode 100644 index b501b75f10..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io.cpp +++ /dev/null @@ -1,1017 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "share/ob_server_struct.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "share/ob_errno.h" -#include "share/config/ob_server_config.h" -#include "storage/tmp_file/ob_tmp_file_flush_priority_manager.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool.h" -#include "storage/tmp_file/ob_tmp_file_io_ctx.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -int ObTmpFileInfo::init( - const ObCurTraceId::TraceId &trace_id, - const int64_t dir_id, - const int64_t fd, - const int64_t file_size, - const int64_t truncated_offset, - const bool is_deleting, - const int64_t cached_page_num, - const int64_t write_back_data_page_num, - const int64_t flushed_data_page_num, - const int64_t ref_cnt, - const int64_t birth_ts, - const void* const tmp_file_ptr, - const char* const label, - const int64_t write_req_cnt, - const int64_t unaligned_write_req_cnt, - const int64_t write_persisted_tail_page_cnt, - const int64_t lack_page_cnt, - const int64_t last_modify_ts, - const int64_t read_req_cnt, - const int64_t unaligned_read_req_cnt, - const int64_t total_truncated_page_read_cnt, - const int64_t total_kv_cache_page_read_cnt, - const int64_t total_uncached_page_read_cnt, - const int64_t total_wbp_page_read_cnt, - const int64_t truncated_page_read_hits, - const int64_t kv_cache_page_read_hits, - const int64_t uncached_page_read_hits, - const int64_t wbp_page_read_hits, - const int64_t total_read_size, - const int64_t last_access_ts) -{ - int ret = OB_SUCCESS; - // common info - trace_id_ = trace_id; - - dir_id_ = dir_id; - fd_ = fd; - file_size_ = file_size; - truncated_offset_ = truncated_offset; - is_deleting_ = is_deleting; - cached_data_page_num_ = cached_page_num; - write_back_data_page_num_ = write_back_data_page_num; - flushed_data_page_num_ = flushed_data_page_num; - ref_cnt_ = ref_cnt; - birth_ts_ = birth_ts; - tmp_file_ptr_ = tmp_file_ptr; - if (NULL != label) { - label_.assign_strive(label); - } - - // write info - write_info_.write_req_cnt_ = write_req_cnt; - write_info_.unaligned_write_req_cnt_ = unaligned_write_req_cnt; - write_info_.write_persisted_tail_page_cnt_ = write_persisted_tail_page_cnt; - write_info_.lack_page_cnt_ = lack_page_cnt; - write_info_.last_modify_ts_ = last_modify_ts; - - // read info - read_info_.read_req_cnt_ = read_req_cnt; - read_info_.unaligned_read_req_cnt_ = unaligned_read_req_cnt; - read_info_.total_truncated_page_read_cnt_ = total_truncated_page_read_cnt; - read_info_.total_kv_cache_page_read_cnt_ = total_kv_cache_page_read_cnt; - read_info_.total_uncached_page_read_cnt_ = total_uncached_page_read_cnt; - read_info_.total_wbp_page_read_cnt_ = total_wbp_page_read_cnt; - read_info_.truncated_page_read_hits_ = truncated_page_read_hits; - read_info_.kv_cache_page_read_hits_ = kv_cache_page_read_hits; - read_info_.uncached_page_read_hits_ = uncached_page_read_hits; - read_info_.wbp_page_read_hits_ = wbp_page_read_hits; - read_info_.total_read_size_ = total_read_size; - read_info_.last_access_ts_ = last_access_ts; - return ret; -} - -void ObTmpFileInfo::reset() -{ - // common info - trace_id_.reset(); - - dir_id_ = ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID; - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - file_size_ = 0; - truncated_offset_ = 0; - is_deleting_ = false; - cached_data_page_num_ = 0; - write_back_data_page_num_ = 0; - flushed_data_page_num_ = 0; - ref_cnt_ = 0; - birth_ts_ = -1; - tmp_file_ptr_ = nullptr; - label_.reset(); - write_info_.reset(); - read_info_.reset(); -} - -void ObTmpFileInfo::ObTmpFileWriteInfo::reset() -{ - write_req_cnt_ = 0; - unaligned_write_req_cnt_ = 0; - write_persisted_tail_page_cnt_ = 0; - lack_page_cnt_ = 0; - last_modify_ts_ = -1; -} - -void ObTmpFileInfo::ObTmpFileReadInfo::reset() -{ - read_req_cnt_ = 0; - unaligned_read_req_cnt_ = 0; - total_truncated_page_read_cnt_ = 0; - total_kv_cache_page_read_cnt_ = 0; - total_uncached_page_read_cnt_ = 0; - total_wbp_page_read_cnt_ = 0; - truncated_page_read_hits_ = 0; - kv_cache_page_read_hits_ = 0; - uncached_page_read_hits_ = 0; - wbp_page_read_hits_ = 0; - total_read_size_ = 0; - last_access_ts_ = -1; -} - -ObSNTmpFileHandle::ObSNTmpFileHandle(ObSharedNothingTmpFile *tmp_file) - : ptr_(tmp_file) -{ - if (ptr_ != nullptr) { - ptr_->inc_ref_cnt(); - } -} - -ObSNTmpFileHandle::ObSNTmpFileHandle(const ObSNTmpFileHandle &handle) - : ptr_(nullptr) -{ - operator=(handle); -} - -ObSNTmpFileHandle & ObSNTmpFileHandle::operator=(const ObSNTmpFileHandle &other) -{ - if (other.get() != ptr_) { - reset(); - ptr_ = other.get(); - if (ptr_ != nullptr) { - ptr_->inc_ref_cnt(); - } - } - return *this; -} - -void ObSNTmpFileHandle::reset() -{ - if (ptr_ != nullptr) { - int64_t ref_cnt = -1; - ptr_->dec_ref_cnt(ref_cnt); - if (OB_UNLIKELY(ref_cnt < 0)) { - int ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid ref cnt", K(ret), KP(ptr_), K(ref_cnt)); - } else if (ref_cnt == 0) { - ptr_->~ObSharedNothingTmpFile(); - } - ptr_ = nullptr; - } -} - -int ObSNTmpFileHandle::init(ObSharedNothingTmpFile *tmp_file) -{ - int ret = OB_SUCCESS; - - if (is_inited()) { - ret = OB_INIT_TWICE; - } else if (OB_ISNULL(tmp_file)) { - ret = OB_INVALID_ARGUMENT; - } else { - ptr_ = tmp_file; - ptr_->inc_ref_cnt(); - } - - return ret; -} - -int ObSharedNothingTmpFile::init_io_state_(const int64_t dir_id, - const int64_t fd, - ObTmpWriteBufferPool *wbp, - ObTmpFileFlushPriorityManager *flush_prio_mgr, - ObIAllocator *callback_allocator, - ObIAllocator *wbp_index_cache_allocator, - ObIAllocator *wbp_index_cache_bkt_allocator, - const char* label) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || - ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID == dir_id)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_ISNULL(wbp) || OB_ISNULL(flush_prio_mgr) || OB_ISNULL(callback_allocator) || - OB_ISNULL(wbp_index_cache_allocator) || OB_ISNULL(wbp_index_cache_bkt_allocator)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(page_idx_cache_.init(fd, wbp, wbp_index_cache_allocator, - wbp_index_cache_bkt_allocator))) { - } else { - is_inited_ = true; - dir_id_ = dir_id; - fd_ = fd; - - wbp_ = wbp; - flush_prio_mgr_ = flush_prio_mgr; - callback_allocator_ = callback_allocator; - - /******for virtual table begin******/ - const ObCurTraceId::TraceId *cur_trace_id = ObCurTraceId::get_trace_id(); - if (nullptr != cur_trace_id) { - trace_id_ = *cur_trace_id; - } else { - trace_id_.init(GCTX.self_addr()); - } - last_access_ts_ = ObTimeUtility::current_time(); - last_modify_ts_ = ObTimeUtility::current_time(); - birth_ts_ = ObTimeUtility::current_time(); - if (NULL != label) { - label_.assign_strive(label); - } - /******for virtual table end******/ - } - return ret; -} - -void ObSharedNothingTmpFile::reset_io_state_() -{ - if (is_inited_) { - is_inited_ = false; - - dir_id_ = ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID; - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - is_deleting_ = false; - is_sealed_ = false; - ref_cnt_ = 0; - truncated_offset_ = 0; - read_offset_ = 0; - file_size_ = 0; - cached_page_nums_ = 0; - write_back_data_page_num_ = 0; - begin_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - begin_page_virtual_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - diag_log_print_cnt_ = 0; - data_page_flush_level_ = -1; - data_flush_node_.unlink(); - wbp_ = nullptr; - flush_prio_mgr_ = nullptr; - page_idx_cache_.destroy(); - callback_allocator_ = nullptr; - /******for virtual table begin******/ - // common info - trace_id_.reset(); - birth_ts_ = -1; - label_.reset(); - // write info - write_req_cnt_ = 0; - unaligned_write_req_cnt_ = 0; - write_persisted_tail_page_cnt_ = 0; - lack_page_cnt_ = 0; - last_modify_ts_ = -1; - // read info - read_req_cnt_ = 0; - unaligned_read_req_cnt_ = 0; - total_truncated_page_read_cnt_ = 0; - total_kv_cache_page_read_cnt_ = 0; - total_uncached_page_read_cnt_ = 0; - total_wbp_page_read_cnt_ = 0; - truncated_page_read_hits_ = 0; - kv_cache_page_read_hits_ = 0; - uncached_page_read_hits_ = 0; - wbp_page_read_hits_ = 0; - total_read_size_ = 0; - last_access_ts_ = -1; - /******for virtual table end******/ - } -} - -int ObSharedNothingTmpFile::delete_file() -{ - int ret = OB_SUCCESS; - LOG_INFO("tmp file delete start", K(fd_)); - common::TCRWLock::WLockGuard guard(meta_lock_); - if (IS_INIT && !is_deleting_) { - if (OB_FAIL(inner_delete_file_())) { - } else { - // read, write, truncate, flush and evict function will fail when is_deleting_ == true. - is_deleting_ = true; - } - } - - return ret; -} - -int ObSharedNothingTmpFile::seal() -{ - int ret = OB_SUCCESS; - LOG_INFO("tmp file seal start", K(fd_)); - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - ObSpinLockGuard write_guard(multi_write_lock_); - if (OB_UNLIKELY(is_sealed_)) { - ret = OB_ERR_TMP_FILE_ALREADY_SEALED; - } else if (OB_FAIL(inner_seal_())) { - } - LOG_INFO("tmp file seal over", KR(ret), KPC(this)); - } - return ret; -} - -int ObSharedNothingTmpFile::aio_pread(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(meta_lock_); - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_deleting_)) { - ret = OB_ERR_UNEXPECTED; - } else { - if (io_ctx.get_read_offset_in_file() < 0) { - io_ctx.set_read_offset_in_file(read_offset_); - } - if (0 != io_ctx.get_read_offset_in_file() % ObTmpFileGlobal::ALLOC_PAGE_SIZE - || 0 != io_ctx.get_todo_size() % ObTmpFileGlobal::ALLOC_PAGE_SIZE) { - io_ctx.set_is_unaligned_read(true); - } - - if (OB_UNLIKELY(!io_ctx.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(io_ctx.get_read_offset_in_file() >= file_size_)) { - ret = OB_ITER_END; - } else if (io_ctx.get_read_offset_in_file() < truncated_offset_ && - OB_FAIL(inner_read_truncated_part_(io_ctx))) { - } else if (OB_UNLIKELY(io_ctx.get_todo_size() == 0)) { - // do nothing - } else { - // Iterate to read disk data. - int64_t wbp_begin_offset = cal_wbp_begin_offset_(); - if (OB_UNLIKELY(wbp_begin_offset < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (io_ctx.get_read_offset_in_file() < wbp_begin_offset) { - const int64_t expected_read_disk_size = MIN(io_ctx.get_todo_size(), - wbp_begin_offset - io_ctx.get_read_offset_in_file()); - - if (OB_UNLIKELY(expected_read_disk_size < 0)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected read disk size", KR(ret), K(fd_), K(expected_read_disk_size), K(wbp_begin_offset), K(io_ctx)); - } else if (expected_read_disk_size == 0) { - // do nothing - } else if (OB_FAIL(inner_read_from_disk_(expected_read_disk_size, io_ctx))) { - } else { - LOG_DEBUG("finish disk read", K(fd_), K(io_ctx.get_read_offset_in_file()), - K(io_ctx.get_todo_size()), - K(io_ctx.get_done_size()), - K(wbp_begin_offset), K(expected_read_disk_size), KPC(this)); - } - } - - // Iterate to read memory data (in write buffer pool). - if (OB_SUCC(ret) && io_ctx.get_todo_size() > 0) { - const int64_t aligned_begin_offset = get_page_begin_offset_(io_ctx.get_read_offset_in_file()); - if (OB_UNLIKELY(0 == cached_page_nums_)) { - ret = OB_ITER_END; - } else if (OB_FAIL(inner_read_from_wbp_(io_ctx))) { - } else { - const int64_t aligned_end_offset = get_page_end_offset_(io_ctx.get_read_offset_in_file()); - const int64_t total_wbp_page_read_cnt = (aligned_end_offset - aligned_begin_offset) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - io_ctx.update_read_wbp_page_stat(total_wbp_page_read_cnt); - LOG_DEBUG("finish wbp read", K(fd_), K(io_ctx.get_read_offset_in_file()), - K(io_ctx.get_todo_size()), - K(io_ctx.get_done_size()), K(wbp_begin_offset), KPC(this)); - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFile::inner_read_truncated_part_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(io_ctx.get_read_offset_in_file() >= truncated_offset_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!io_ctx.is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(io_ctx.get_todo_size() == 0)) { - // do nothing - } else { - int64_t total_truncated_page_read_cnt = 0; - const int64_t origin_read_offset = io_ctx.get_read_offset_in_file(); - int64_t read_size = MIN(truncated_offset_ - io_ctx.get_read_offset_in_file(), - io_ctx.get_todo_size()); - char *read_buf = io_ctx.get_todo_buffer(); - if (OB_UNLIKELY(!io_ctx.check_buf_range_valid(read_buf, read_size))) { - ret = OB_ERR_UNEXPECTED; - } else if (FALSE_IT(MEMSET(read_buf, 0, read_size))) { - } else if (OB_FAIL(io_ctx.update_data_size(read_size))) { - } else if (FALSE_IT(total_truncated_page_read_cnt = (get_page_end_offset_(io_ctx.get_read_offset_in_file()) - - get_page_begin_offset_(origin_read_offset)) / - ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - } else if (FALSE_IT(io_ctx.update_read_truncated_stat(total_truncated_page_read_cnt))) { - } else if (OB_UNLIKELY(io_ctx.get_todo_size() > 0 && - truncated_offset_ == file_size_)) { - ret = OB_ITER_END; - } - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_read_from_wbp_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - const int64_t begin_read_page_virtual_id = get_page_virtual_id_(io_ctx.get_read_offset_in_file(), - false /*is_open_interval*/); - uint32_t begin_read_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t wbp_begin_offset = cal_wbp_begin_offset_(); - - if (OB_UNLIKELY(wbp_begin_offset < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_read_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (io_ctx.get_read_offset_in_file() < wbp_begin_offset + ObTmpFileGlobal::ALLOC_PAGE_SIZE) { - begin_read_page_id = begin_page_id_; - } else if (OB_FAIL(page_idx_cache_.binary_search(begin_read_page_virtual_id, begin_read_page_id))) { - } else if (ObTmpFileGlobal::INVALID_PAGE_ID == begin_read_page_id && - OB_FAIL(wbp_->get_page_id_by_virtual_id(fd_, begin_read_page_virtual_id, begin_page_id_, begin_read_page_id))) { - } else if (OB_UNLIKELY(begin_read_page_id == ObTmpFileGlobal::INVALID_PAGE_ID)) { - ret = OB_ERR_UNEXPECTED; - } - - uint32_t curr_page_id = begin_read_page_id; - int64_t curr_page_virtual_id = begin_read_page_virtual_id; - while (OB_SUCC(ret) && io_ctx.get_todo_size() > 0) { - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - char *data_page = nullptr; - if (OB_FAIL(wbp_->read_page(fd_, curr_page_id, ObTmpFilePageUniqKey(curr_page_virtual_id), data_page, next_page_id))) { - } else if (OB_ISNULL(data_page)) { - ret = OB_ERR_UNEXPECTED; - } else { - const int64_t read_offset_in_page = get_offset_in_page_(io_ctx.get_read_offset_in_file()); - const int64_t read_size = MIN3(ObTmpFileGlobal::ALLOC_PAGE_SIZE - read_offset_in_page, - io_ctx.get_todo_size(), - file_size_ - io_ctx.get_read_offset_in_file()); - char *read_buf = io_ctx.get_todo_buffer(); - if (OB_UNLIKELY(!io_ctx.check_buf_range_valid(read_buf, read_size))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(io_ctx.update_data_size(read_size))) { - } else { - MEMCPY(read_buf, data_page + read_offset_in_page, read_size); - curr_page_id = next_page_id; - curr_page_virtual_id += 1; - } - } - - if (OB_SUCC(ret) && io_ctx.get_todo_size() > 0 && io_ctx.get_read_offset_in_file() == file_size_) { - ret = OB_ITER_END; - } - } - - return ret; -} - -// attention: -// in order to avoid blocking reading, flushing and evicting pages, -// write operation only adds write lock for meta_lock when it try to update meta data. -// due to the write operation is appending write, if the meta data doesn't been modified, -// all operation could not write or read the new appending data. -int ObSharedNothingTmpFile::aio_write(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - ObSpinLockGuard guard(multi_write_lock_); - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!io_ctx.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(is_deleting_)) { - // this check is just a hint. - // although is_deleting_ == false, it might be set as true in the processing of inner_write(). - // we will check is_deleting_ again when try to update meta data in the inner_write() - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(is_sealed_)) { - ret = OB_ERR_TMP_FILE_ALREADY_SEALED; - } else { - bool is_unaligned_write = 0 != file_size_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE || - 0 != io_ctx.get_todo_size() % ObTmpFileGlobal::ALLOC_PAGE_SIZE; - io_ctx.set_is_unaligned_write(is_unaligned_write); - while (OB_SUCC(ret) && io_ctx.get_todo_size() > 0) { - if (OB_FAIL(inner_write_(io_ctx))) { - if (OB_ALLOCATE_TMP_FILE_PAGE_FAILED == ret) { - io_ctx.add_lack_page_cnt(); - ret = OB_SUCCESS; - if (TC_REACH_COUNT_INTERVAL(10)) { - LOG_INFO("alloc mem failed, try to evict pages", K(fd_), K(file_size_), K(io_ctx), KPC(this)); - } - if (OB_FAIL(swap_page_to_disk_(io_ctx))) { - } - } else { - } - } - } // end while - } - - if (OB_SUCC(ret)) { - // ATTENTION! we print tmp file data members here without meta_lock_. - static const int64_t PRINT_LOG_FILE_SIZE = 100 * 1024 * 1024; // 100MB - int64_t cur_print_cnt = file_size_ / PRINT_LOG_FILE_SIZE; - if (cur_print_cnt > ATOMIC_LOAD(&diag_log_print_cnt_)) { - ATOMIC_INC(&diag_log_print_cnt_); - LOG_INFO("aio write finish", K(fd_), K(io_ctx), KPC(this)); - } else { - } - } else { - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_write_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - if (has_unfinished_page_()) { - if (OB_FAIL(inner_fill_tail_page_(io_ctx))) { - } else if (OB_UNLIKELY(has_unfinished_page_() && io_ctx.get_todo_size() > 0)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("tmp file page is unaligned", KR(ret), K(fd_)); - } - } - - // each batch at most write TMP_FILE_WRITE_BATCH_PAGE_NUM pages - while (OB_SUCC(ret) && io_ctx.get_todo_size() > 0) { - if (OB_FAIL(inner_write_continuous_pages_(io_ctx))) { - } - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_fill_tail_page_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - ObSpinLockGuard last_page_lock_guard(last_page_lock_); - const bool is_in_disk = (0 == cached_page_nums_); - - if (OB_UNLIKELY(!io_ctx.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (is_in_disk) { - if (OB_FAIL(load_disk_tail_page_and_rewrite_(io_ctx))) { - } else { - io_ctx.add_write_persisted_tail_page_cnt(); - } - } else { - if (OB_FAIL(append_write_memory_tail_page_(io_ctx))) { - } - } - - return ret; -} - -int ObSharedNothingTmpFile::inner_write_continuous_pages_(ObTmpFileIOCtx &io_ctx) -{ - int ret = OB_SUCCESS; - bool is_alloc_failed = false; - int64_t write_size = 0; - ObArray page_entry_idxs; - bool has_update_file_meta = false; - - if (OB_UNLIKELY(!io_ctx.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(alloc_and_write_pages_(io_ctx, page_entry_idxs, write_size))) { - if (OB_ALLOCATE_TMP_FILE_PAGE_FAILED == ret) { - // this error code will return to caller after modifing meta data of file based on written data pages - ret = OB_SUCCESS; - is_alloc_failed = true; - if (TC_REACH_COUNT_INTERVAL(10)) { - LOG_INFO("fail to alloc memory", K(fd_), K(write_size), - K(page_entry_idxs), K(io_ctx)); - } - } else { - } - } - - // Update meta data. - if (OB_FAIL(ret)) { - } else if (OB_UNLIKELY(page_entry_idxs.empty() || write_size <= 0)) { - if (!is_alloc_failed) { - ret = OB_ERR_UNEXPECTED; - } else { - // do nothing, no need to update meta data - } - } else { - common::TCRWLock::WLockGuard guard(meta_lock_); - const int64_t end_page_virtual_id = cached_page_nums_ == 0 ? - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID : - get_page_virtual_id_(file_size_, true /*is_open_interval*/); - const int64_t old_begin_page_id = begin_page_id_; - const int64_t old_begin_page_virtual_id_ = begin_page_virtual_id_; - const int64_t old_end_page_id = end_page_id_; - if (OB_UNLIKELY(is_deleting_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID != end_page_id_ && - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == end_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY((ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_ && - ObTmpFileGlobal::INVALID_PAGE_ID != end_page_id_) || - (ObTmpFileGlobal::INVALID_PAGE_ID != begin_page_id_ && - ObTmpFileGlobal::INVALID_PAGE_ID == end_page_id_))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(io_ctx.update_data_size(write_size))) { - } else { - if (ObTmpFileGlobal::INVALID_PAGE_ID != end_page_id_ && - OB_FAIL(wbp_->link_page(fd_, page_entry_idxs.at(0), end_page_id_, ObTmpFilePageUniqKey(end_page_virtual_id)))) { - } else { - if (ObTmpFileGlobal::INVALID_PAGE_ID == begin_page_id_) { - begin_page_id_ = page_entry_idxs.at(0); - begin_page_virtual_id_ = get_page_virtual_id_(file_size_, false /*is_open_interval*/); - } - end_page_id_ = page_entry_idxs.at(page_entry_idxs.count() - 1); - file_size_ += write_size; - cached_page_nums_ += page_entry_idxs.count(); - has_update_file_meta = true; - } - - if (FAILEDx(insert_or_update_data_flush_node_())) { - } - } - - if (OB_FAIL(ret)) { - int tmp_ret = OB_SUCCESS; - uint32_t unused_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t free_page_virtual_id = file_size_ == 0 ? 0 : end_page_virtual_id + 1; - for (int64_t i = 0; i < page_entry_idxs.count() && OB_LIKELY(OB_SUCCESS == tmp_ret); i++) { - if (OB_TMP_FAIL(tmp_ret = wbp_->free_page(fd_, page_entry_idxs[i], ObTmpFilePageUniqKey(free_page_virtual_id), unused_page_id))) { - } else { - free_page_virtual_id += 1; - } - } - if (has_update_file_meta) { - begin_page_id_ = old_begin_page_id; - begin_page_virtual_id_ = old_begin_page_virtual_id_; - end_page_id_ = old_end_page_id; - cached_page_nums_ -= page_entry_idxs.count(); - file_size_ -= write_size; - } - } else { - int tmp_ret = OB_SUCCESS; - for (int64_t i = 0; i < page_entry_idxs.count() && OB_LIKELY(tmp_ret == OB_SUCCESS); i++) { - if (OB_TMP_FAIL(page_idx_cache_.push(page_entry_idxs[i]))) { - } - } - } - } // end update meta data. - - // reset allocation failure status - ret = is_alloc_failed && OB_SUCC(ret) ? OB_ALLOCATE_TMP_FILE_PAGE_FAILED : ret; - return ret; -} - -int ObSharedNothingTmpFile::alloc_and_write_pages_(const ObTmpFileIOCtx &io_ctx, - ObArray &alloced_page_id, - int64_t &actual_write_size) -{ - int ret = OB_SUCCESS; - int64_t write_size = 0; - const int64_t new_begin_page_virtual_id = get_page_virtual_id_(file_size_, false /*is_open_interval*/); - uint32_t previous_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - alloced_page_id.reset(); - actual_write_size = 0; - - if (OB_UNLIKELY(has_unfinished_page_())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == new_begin_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!io_ctx.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(alloced_page_id.prepare_allocate_and_keep_count( - ObTmpFileGlobal::TMP_FILE_WRITE_BATCH_PAGE_NUM))) { - } else { - const int64_t expected_write_size = io_ctx.get_todo_size(); - int64_t new_page_virtual_id = new_begin_page_virtual_id; - while (OB_SUCC(ret) && actual_write_size < expected_write_size && - alloced_page_id.count() < ObTmpFileGlobal::TMP_FILE_WRITE_BATCH_PAGE_NUM) { - char *page_buf = nullptr; - uint32_t new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(wbp_->alloc_page(fd_, ObTmpFilePageUniqKey(new_page_virtual_id), new_page_id, page_buf))) { - } else if (OB_ISNULL(page_buf)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(new_page_id == ObTmpFileGlobal::INVALID_PAGE_ID)) { - ret = OB_ERR_UNEXPECTED; - } else { - int64_t write_size = common::min(ObTmpFileGlobal::ALLOC_PAGE_SIZE, - expected_write_size - actual_write_size); - const char *write_buf = io_ctx.get_todo_buffer() + actual_write_size; - - if (OB_UNLIKELY(!io_ctx.check_buf_range_valid(write_buf, write_size))) { - ret = OB_ERR_UNEXPECTED; - } else if (FALSE_IT(MEMCPY(page_buf, write_buf, write_size))) { - } else if (FALSE_IT(actual_write_size += write_size)) { - } else if (OB_FAIL(wbp_->notify_dirty(fd_, new_page_id, ObTmpFilePageUniqKey(new_page_virtual_id)))) { - } else if (previous_page_id != ObTmpFileGlobal::INVALID_PAGE_ID && - OB_FAIL(wbp_->link_page(fd_, new_page_id, previous_page_id, - ObTmpFilePageUniqKey(new_page_virtual_id - 1)))) { - } else if (OB_FAIL(alloced_page_id.push_back(new_page_id))) { - } else { - previous_page_id = new_page_id; - new_page_virtual_id += 1; - } - } - - if (OB_FAIL(ret) && OB_NOT_NULL(page_buf)) { - int tmp_ret = OB_SUCCESS; - uint32_t tmp_pid = ObTmpFileGlobal::INVALID_PAGE_ID; // unused - if (OB_TMP_FAIL(wbp_->free_page(fd_, new_page_id, ObTmpFilePageUniqKey(new_page_virtual_id), tmp_pid))) { - } - } - } // end while - - if (OB_FAIL(ret) && ret != OB_ALLOCATE_TMP_FILE_PAGE_FAILED && !alloced_page_id.empty()) { - int64_t invalid_page_virtual_id = new_begin_page_virtual_id; - for (int64_t i = 0; i < alloced_page_id.count(); i++) { - int tmp_ret = OB_SUCCESS; - uint32_t invalid_page_id = alloced_page_id.at(i); - uint32_t tmp_pid = ObTmpFileGlobal::INVALID_PAGE_ID; // unused - if (OB_TMP_FAIL(wbp_->free_page(fd_, invalid_page_id, ObTmpFilePageUniqKey(invalid_page_virtual_id), tmp_pid))) { - } else { - invalid_page_virtual_id += 1; - } - } // end for - alloced_page_id.reset(); - } - } - return ret; -} - -// Attention!! -// 1. if truncate_offset is not the begin or end offset of page, -// we will fill zero from begin_offset to truncate_offset for truncated page in wbp. -// 2. truncate_offset is a open interval number, which means the offset before than it need to be truncated -int ObSharedNothingTmpFile::truncate_io_(const int64_t truncate_offset) -{ - int ret = OB_SUCCESS; - ObSpinLockGuard last_page_lock_guard(last_page_lock_); - common::TCRWLock::WLockGuard guard(meta_lock_); - int64_t wbp_begin_offset = cal_wbp_begin_offset_(); - LOG_INFO("start to truncate a temporary file", KR(ret), K(fd_), K(truncate_offset), K(wbp_begin_offset), KPC(this)); - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_deleting_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(truncate_offset <= 0 || truncate_offset > file_size_)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(wbp_begin_offset < 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(truncate_offset <= truncated_offset_)) { - // do nothing - } else if (OB_FAIL(truncate_cached_pages_(truncate_offset, wbp_begin_offset))) { - } else if (OB_FAIL(truncate_persistent_pages_(truncate_offset))) { - } else { - truncated_offset_ = truncate_offset; - last_modify_ts_ = ObTimeUtility::current_time(); - } - - LOG_INFO("truncate over", KR(ret), K(truncate_offset), K(wbp_begin_offset), KPC(this)); - return ret; -} - -int ObSharedNothingTmpFile::truncate_cached_pages_(const int64_t truncate_offset, const int64_t wbp_begin_offset) -{ - int ret = OB_SUCCESS; - uint32_t truncate_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (OB_UNLIKELY(wbp_begin_offset < 0 || truncate_offset <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (truncate_offset > wbp_begin_offset) { - const int64_t truncate_page_virtual_id = get_page_virtual_id_(truncate_offset, - true /*is_open_interval*/); - const int64_t truncate_offset_in_page = get_offset_in_page_(truncate_offset); - if (OB_FAIL(page_idx_cache_.binary_search(truncate_page_virtual_id, truncate_page_id))) { - } else if (ObTmpFileGlobal::INVALID_PAGE_ID != truncate_page_id) { - // the page index of truncate_offset is in the range of cached page index. - // truncate all page indexes whose offset is smaller than truncate_offset. - const int64_t truncate_page_virtual_id_in_cache = truncate_offset_in_page == 0 ? - truncate_page_virtual_id + 1 : - truncate_page_virtual_id; - if (OB_FAIL(page_idx_cache_.truncate(truncate_page_virtual_id_in_cache))) { - } - } else { // ObTmpFileGlobal::INVALID_PAGE_ID == truncate_page_id - // the page index of truncate_offset is smaller than the smallest cached page index. - // we need to find truncate_page_id by iterating wbp_. - if (OB_FAIL(wbp_->get_page_id_by_virtual_id(fd_, truncate_page_virtual_id, begin_page_id_, truncate_page_id))) { - } - } - - if (OB_SUCC(ret)) { - // truncate complete pages except the last page - while(OB_SUCC(ret) && begin_page_id_ != truncate_page_id) { - if (OB_FAIL(truncate_the_first_wbp_page_())) { - } - } - - // truncate the last page - if (OB_SUCC(ret)) { - if (OB_UNLIKELY(truncate_page_virtual_id != begin_page_virtual_id_)) { - ret = OB_ERR_UNEXPECTED; - } else if (0 == truncate_offset_in_page) { - if (OB_FAIL(truncate_the_first_wbp_page_())) { - } - } else { // truncate_offset_in_page is in the middle of page, fill zero before the truncate_offset of page - if (OB_FAIL(wbp_->truncate_page(fd_, truncate_page_id, - ObTmpFilePageUniqKey(truncate_page_virtual_id), - truncate_offset_in_page))) { - } else { - LOG_INFO("truncate part of page", KR(ret), K(truncate_page_id), K(truncate_offset), - K(truncate_offset_in_page), K(wbp_begin_offset), KPC(this)); - } - } - } - } - } - return ret; -} - -bool ObSharedNothingTmpFile::can_remove() -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - return is_deleting_ && get_ref_cnt() == 1; -} - -bool ObSharedNothingTmpFile::is_deleting() -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - return is_deleting_; -} - -bool ObSharedNothingTmpFile::is_flushing() -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - return is_flushing_(); -} - -int64_t ObSharedNothingTmpFile::get_file_size() -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - return file_size_; -} - -int64_t ObSharedNothingTmpFile::cal_wbp_begin_offset_() const -{ - int ret = OB_SUCCESS; - int64_t res = -1; - if (0 == cached_page_nums_) { - res = file_size_; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == begin_page_virtual_id_ || - begin_page_virtual_id_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE != - get_page_end_offset_(file_size_) - - cached_page_nums_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - } else { - res = begin_page_virtual_id_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - - return res; -} - -void ObSharedNothingTmpFile::update_read_offset(int64_t read_offset) -{ - common::TCRWLock::WLockGuard guard(meta_lock_); - if (read_offset > read_offset_) { - read_offset_ = read_offset; - } -} - -int64_t ObSharedNothingTmpFile::get_dirty_data_page_size_with_lock() -{ - common::TCRWLock::RLockGuard guard(meta_lock_); - return get_dirty_data_page_size_(); -} - -int ObSharedNothingTmpFile::reinsert_data_flush_node() -{ - int ret = OB_SUCCESS; - common::TCRWLock::WLockGuard guard(meta_lock_); - if (OB_FAIL(reinsert_data_flush_node_())) { - } - - return ret; -} - -int ObSharedNothingTmpFile::reinsert_data_flush_node_() -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(nullptr != data_flush_node_.get_next())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(is_deleting_)) { - // do nothing - } else { - int64_t dirty_page_size = get_dirty_data_page_size_(); - if (0 == dirty_page_size) { - // no need to reinsert - data_page_flush_level_ = -1; - } else if (OB_FAIL(flush_prio_mgr_->insert_data_flush_list(*this, dirty_page_size))) { - } - } - - return ret; -} - -int ObSharedNothingTmpFile::remove_data_flush_node() -{ - int ret = OB_SUCCESS; - common::TCRWLock::WLockGuard guard(meta_lock_); - if (OB_FAIL(flush_prio_mgr_->remove_file(false, *this))) { - } - - return ret; -} - -// ATTENTION! need to be protected by meta_lock_ -int ObSharedNothingTmpFile::insert_or_update_data_flush_node_() -{ - int ret = OB_SUCCESS; - - if (!is_flushing_()) { - int64_t dirty_data_page_size = get_dirty_data_page_size_(); - if (data_page_flush_level_ >= 0 && OB_ISNULL(data_flush_node_.get_next())) { - // flush task mgr is processing this file. - // it will add this file to according flush list in the end - } else if (0 == dirty_data_page_size) { - // do nothing - } else if (data_page_flush_level_ < 0) { - if (OB_FAIL(flush_prio_mgr_->insert_data_flush_list(*this, dirty_data_page_size))) { - } - } else if (OB_FAIL(flush_prio_mgr_->update_data_flush_list(*this, dirty_data_page_size))) { - } - } - - return ret; -} - -void ObSharedNothingTmpFile::set_read_stats_vars(const ObTmpFileIOCtx &ctx, const int64_t read_size) -{ - ObSpinLockGuard guard(stat_lock_); - inner_set_read_stats_vars_(ctx, read_size); -} - -void ObSharedNothingTmpFile::inner_set_read_stats_vars_(const ObTmpFileIOCtx &ctx, const int64_t read_size) -{ - read_req_cnt_++; - if (ctx.is_unaligned_read()) { - unaligned_read_req_cnt_++; - } - total_read_size_ += read_size; - last_access_ts_ = ObTimeUtility::current_time(); - total_truncated_page_read_cnt_ += ctx.get_total_truncated_page_read_cnt(); - total_kv_cache_page_read_cnt_ += ctx.get_total_kv_cache_page_read_cnt(); - total_uncached_page_read_cnt_ += ctx.get_total_uncached_page_read_cnt(); - total_wbp_page_read_cnt_ += ctx.get_total_wbp_page_read_cnt(); - truncated_page_read_hits_ += ctx.get_truncated_page_read_hits(); - kv_cache_page_read_hits_ += ctx.get_kv_cache_page_read_hits(); - uncached_page_read_hits_ += ctx.get_uncached_page_read_hits(); - wbp_page_read_hits_ += ctx.get_wbp_page_read_hits(); -} - -void ObSharedNothingTmpFile::set_write_stats_vars(const ObTmpFileIOCtx &ctx) -{ - ObSpinLockGuard guard(stat_lock_); - inner_set_write_stats_vars_(ctx); -} - -void ObSharedNothingTmpFile::inner_set_write_stats_vars_(const ObTmpFileIOCtx &ctx) -{ - write_req_cnt_++; - if (ctx.is_unaligned_write()) { - unaligned_write_req_cnt_++; - } - write_persisted_tail_page_cnt_ += ctx.get_write_persisted_tail_page_cnt(); - lack_page_cnt_ += ctx.get_lack_page_cnt(); - last_modify_ts_ = ObTimeUtility::current_time(); -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_io_ctx.cpp b/src/storage/tmp_file/ob_tmp_file_io_ctx.cpp deleted file mode 100644 index 9cd3ded5bc..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io_ctx.cpp +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_io_ctx.h" -#include "share/ob_server_struct.h" - -namespace oceanbase -{ -using namespace storage; -using namespace share; - -namespace tmp_file -{ -ObTmpFileIOCtx::ObTmpFileIOCtx(): - is_inited_(false), - is_read_(false), - fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - dir_id_(ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID), - buf_(nullptr), - buf_size_(-1), - done_size_(-1), - todo_size_(-1), - read_offset_in_file_(-1), - disable_page_cache_(false), - disable_block_cache_(false), - prefetch_(false), - io_flag_(), - io_timeout_ms_(DEFAULT_IO_WAIT_TIME_MS), - io_handles_(), - page_cache_handles_(), - block_cache_handles_(), - is_unaligned_write_(false), - write_persisted_tail_page_cnt_(0), - lack_page_cnt_(0), - is_unaligned_read_(false), - total_truncated_page_read_cnt_(0), - total_kv_cache_page_read_cnt_(0), - total_uncached_page_read_cnt_(0), - total_wbp_page_read_cnt_(0), - truncated_page_read_hits_(0), - kv_cache_page_read_hits_(0), - uncached_page_read_hits_(0), - aggregate_read_io_cnt_(0), - wbp_page_read_hits_(0) -{ - io_handles_.set_attr(ObMemAttr("TMP_IO_HDL")); - page_cache_handles_.set_attr(ObMemAttr("TMP_PCACHE_HDL")); - block_cache_handles_.set_attr(ObMemAttr("TMP_BCACHE_HDL")); -} - -ObTmpFileIOCtx::~ObTmpFileIOCtx() -{ - reset(); -} - -int ObTmpFileIOCtx::init(const int64_t fd, const int64_t dir_id, - const bool is_read, - const common::ObIOFlag io_flag, - const int64_t io_timeout_ms, - const bool disable_page_cache, - const bool disable_block_cache, - const bool prefetch) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(is_inited_)) { - ret = OB_INIT_TWICE; - LOG_ERROR("ObTmpFileIOCtx init twice", KR(ret)); - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || - ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID == dir_id)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(!io_flag.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(io_timeout_ms < 0)) { - ret = OB_INVALID_ARGUMENT; - } else { - fd_ = fd; - dir_id_ = dir_id; - is_read_ = is_read; - io_flag_ = io_flag; - io_timeout_ms_ = io_timeout_ms; - disable_page_cache_ = disable_page_cache; - disable_block_cache_ = disable_block_cache; - prefetch_ = prefetch; - is_inited_ = true; - } - return ret; -} - -void ObTmpFileIOCtx::reuse() -{ - buf_ = nullptr; - buf_size_ = -1; - done_size_ = -1; - todo_size_ = -1; - read_offset_in_file_ = -1; - for (int32_t i = 0; i < io_handles_.count(); i++) { - io_handles_.at(i).handle_.reset(); - } - for (int32_t i = 0; i < page_cache_handles_.count(); i++) { - page_cache_handles_.at(i).page_handle_.reset(); - } - for (int32_t i = 0; i < block_cache_handles_.count(); i++) { - block_cache_handles_.at(i).block_handle_.reset(); - } - io_handles_.reset(); - page_cache_handles_.reset(); - block_cache_handles_.reset(); -} - -void ObTmpFileIOCtx::reset() -{ - reuse(); - is_inited_ = false; - is_read_ = false; - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - dir_id_ = ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID; - disable_page_cache_ = false; - disable_block_cache_ = false; - io_flag_.reset(); - io_timeout_ms_ = DEFAULT_IO_WAIT_TIME_MS; - /********for virtual table statistics begin********/ - is_unaligned_write_ = false; - write_persisted_tail_page_cnt_ = 0; - lack_page_cnt_ = 0; - is_unaligned_read_ = false; - total_truncated_page_read_cnt_ = 0; - total_kv_cache_page_read_cnt_ = 0; - total_uncached_page_read_cnt_ = 0; - total_wbp_page_read_cnt_ = 0; - truncated_page_read_hits_ = 0; - kv_cache_page_read_hits_ = 0; - uncached_page_read_hits_ = 0; - aggregate_read_io_cnt_ = 0; - wbp_page_read_hits_ = 0; - /********for virtual table statistics end ********/ -} - -bool ObTmpFileIOCtx::is_valid() const -{ - return is_inited_ && - fd_ != ObTmpFileGlobal::INVALID_TMP_FILE_FD && - dir_id_ != ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID && - nullptr != buf_ && buf_size_ > 0 && done_size_ >= 0 && todo_size_ >= 0 && - (is_read_ ? read_offset_in_file_ >= 0 : true) && - io_timeout_ms_ >= 0 && io_flag_.is_valid(); -} - -int ObTmpFileIOCtx::prepare_read(char *read_buf, const int64_t read_size) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_ISNULL(read_buf)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(read_size <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else { - is_read_ = true; - buf_ = read_buf; - buf_size_ = read_size; - done_size_ = 0; - todo_size_ = read_size; - read_offset_in_file_ = -1; - } - return ret; -} - -int ObTmpFileIOCtx::prepare_read(char *read_buf, const int64_t read_size, const int64_t read_offset) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(read_offset < 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(prepare_read(read_buf, read_size))) { - } else { - read_offset_in_file_ = read_offset; - } - return ret; -} - -int ObTmpFileIOCtx::prepare_write(char *write_buf, const int64_t write_size) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_ISNULL(write_buf)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(write_size <= 0)) { - ret = OB_INVALID_ARGUMENT; - } else { - is_read_ = false; - buf_ = write_buf; - buf_size_ = write_size; - done_size_ = 0; - todo_size_ = write_size; - read_offset_in_file_ = -1; - } - return ret; -} - -int ObTmpFileIOCtx::update_data_size(const int64_t size) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(size > todo_size_)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(is_read_ && read_offset_in_file_ < 0)) { - ret = OB_ERR_UNEXPECTED; - } else { - if (is_read_) { - read_offset_in_file_ += size; - } - done_size_ += size; - todo_size_ -= size; - } - return ret; -} - -int ObTmpFileIOCtx::wait() -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (!is_read_) { - // due to tmp file always writes data in buffer, - // there are no asynchronous io tasks need to wait - // do nothing - } else if (OB_FAIL(wait_read_finish_())) { - } - - return ret; -} - -int ObTmpFileIOCtx::wait_read_finish_() -{ - int ret = OB_SUCCESS; - - OB_ASSERT(is_read_); - OB_ASSERT(buf_size_ == done_size_ + todo_size_); - if (OB_FAIL(do_read_wait_())) { - } - - return ret; -} - -int ObTmpFileIOCtx::do_read_wait_() -{ - int ret = OB_SUCCESS; - - for (int64_t i = 0; OB_SUCC(ret) && i < page_cache_handles_.count(); ++i) { - ObPageCacheHandle &page_cache_handle = page_cache_handles_.at(i); - if (OB_UNLIKELY(!page_cache_handle.is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else { - const char * page_buf = page_cache_handle.page_handle_.value_->get_buffer(); - const int64_t offset_in_page = page_cache_handle.offset_in_src_data_buf_; - const int64_t read_size = page_cache_handle.read_size_; - char * read_buf = page_cache_handle.dest_user_read_buf_; - if (OB_ISNULL(page_buf)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!check_buf_range_valid(read_buf, read_size))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(offset_in_page + read_size > ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - } else { - MEMCPY(read_buf, page_buf + offset_in_page, read_size); - page_cache_handle.page_handle_.reset(); - } - } - } - if (OB_SUCC(ret)) { - page_cache_handles_.reset(); - } - - for (int64_t i = 0; OB_SUCC(ret) && i < block_cache_handles_.count(); ++i) { - ObBlockCacheHandle &block_cache_handle = block_cache_handles_.at(i); - if (OB_UNLIKELY(!block_cache_handle.is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else { - const char * block_buf = block_cache_handle.block_handle_.value_->get_buffer(); - const int64_t offset_in_block = block_cache_handle.offset_in_src_data_buf_; - const int64_t read_size = block_cache_handle.read_size_; - char * read_buf = block_cache_handle.dest_user_read_buf_; - if (OB_ISNULL(block_buf)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!check_buf_range_valid(read_buf, read_size))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(offset_in_block + read_size > ObTmpFileGlobal::SN_BLOCK_SIZE)) { - ret = OB_ERR_UNEXPECTED; - } else { - MEMCPY(read_buf, block_buf + offset_in_block, read_size); - block_cache_handle.block_handle_.reset(); - } - } - } - if (OB_SUCC(ret)) { - block_cache_handles_.reset(); - } - - // Wait read io finish. - for (int64_t i = 0; OB_SUCC(ret) && i < io_handles_.count(); ++i) { - ObIOReadHandle &io_handle = io_handles_.at(i); - if (OB_UNLIKELY(!io_handle.is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(io_handle.handle_.wait())) { - } else { - const char * data_buf = io_handle.handle_.get_buffer(); - const int64_t offset = io_handle.offset_in_src_data_buf_; - const int64_t size = io_handle.read_size_; - char * read_buf = io_handle.dest_user_read_buf_; - if (OB_ISNULL(data_buf)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!check_buf_range_valid(read_buf, size))) { - ret = OB_ERR_UNEXPECTED; - } else { - MEMCPY(read_buf, data_buf + offset, size); - io_handle.handle_.reset(); - } - } - } - - if (OB_SUCC(ret)) { - io_handles_.reset(); - } - - return ret; -} - -ObTmpFileIOCtx::ObIReadHandle::ObIReadHandle() - : dest_user_read_buf_(nullptr), offset_in_src_data_buf_(0), read_size_(0) -{ -} - -ObTmpFileIOCtx::ObIReadHandle::ObIReadHandle( - char *dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size) - : dest_user_read_buf_(dest_user_read_buf), offset_in_src_data_buf_(offset_in_src_data_buf), read_size_(read_size) -{ -} - -ObTmpFileIOCtx::ObIReadHandle::~ObIReadHandle() -{ -} - -ObTmpFileIOCtx::ObIReadHandle::ObIReadHandle(const ObTmpFileIOCtx::ObIReadHandle &other) -{ - *this = other; -} - -ObTmpFileIOCtx::ObIReadHandle &ObTmpFileIOCtx::ObIReadHandle::operator=( - const ObTmpFileIOCtx::ObIReadHandle &other) -{ - if (&other != this) { - offset_in_src_data_buf_ = other.offset_in_src_data_buf_; - dest_user_read_buf_ = other.dest_user_read_buf_; - read_size_ = other.read_size_; - } - return *this; -} - -ObTmpFileIOCtx::ObIOReadHandle::ObIOReadHandle() - : ObIReadHandle(), handle_() -{ -} - -ObTmpFileIOCtx::ObIOReadHandle::ObIOReadHandle( - char *dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size) - : ObIReadHandle(dest_user_read_buf, offset_in_src_data_buf, read_size), handle_(), block_handle_() -{ -} - -ObTmpFileIOCtx::ObIOReadHandle::ObIOReadHandle( - char *dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size, - ObTmpFileBlockHandle block_handle) - : ObIReadHandle(dest_user_read_buf, offset_in_src_data_buf, read_size), handle_(), block_handle_(block_handle) -{ -} - -ObTmpFileIOCtx::ObIOReadHandle::~ObIOReadHandle() -{ -} - -ObTmpFileIOCtx::ObIOReadHandle::ObIOReadHandle(const ObTmpFileIOCtx::ObIOReadHandle &other) -{ - *this = other; -} - -ObTmpFileIOCtx::ObIOReadHandle &ObTmpFileIOCtx::ObIOReadHandle::operator=( - const ObTmpFileIOCtx::ObIOReadHandle &other) -{ - if (&other != this) { - handle_ = other.handle_; - block_handle_ = other.block_handle_; - ObIReadHandle::operator=(other); - } - return *this; -} - -bool ObTmpFileIOCtx::ObIOReadHandle::is_valid() -{ - bool bret = OB_NOT_NULL(dest_user_read_buf_) && offset_in_src_data_buf_ >= 0 && - read_size_ >= 0 && - handle_.is_valid(); - - if (bret) { - bret = read_size_ <= ObTmpFileGlobal::SN_BLOCK_SIZE && block_handle_.is_inited(); - } - - return bret; -} - -ObTmpFileIOCtx::ObBlockCacheHandle::ObBlockCacheHandle() - : ObIReadHandle(), block_handle_() -{ -} - -ObTmpFileIOCtx::ObBlockCacheHandle::ObBlockCacheHandle( - char* dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size) - : ObIReadHandle(dest_user_read_buf, offset_in_src_data_buf, read_size) -{} - -ObTmpFileIOCtx::ObBlockCacheHandle::~ObBlockCacheHandle() -{ -} - -bool ObTmpFileIOCtx::ObBlockCacheHandle::is_valid() -{ - bool bret = false; - if (OB_NOT_NULL(dest_user_read_buf_) && offset_in_src_data_buf_ >= 0 && - read_size_ >= 0 && - read_size_ <= ObTmpFileGlobal::SN_BLOCK_SIZE && - OB_NOT_NULL(block_handle_.value_) && - block_handle_.handle_.is_valid()) { - bret = true; - } - return bret; -} - -ObTmpFileIOCtx::ObPageCacheHandle::ObPageCacheHandle() - : ObIReadHandle(), page_handle_() -{ -} - -ObTmpFileIOCtx::ObPageCacheHandle::ObPageCacheHandle( - char* dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size) - : ObIReadHandle(dest_user_read_buf, offset_in_src_data_buf, read_size) -{ -} - -ObTmpFileIOCtx::ObPageCacheHandle::~ObPageCacheHandle() -{ -} - -bool ObTmpFileIOCtx::ObPageCacheHandle::is_valid() -{ - bool bret = false; - if (OB_NOT_NULL(dest_user_read_buf_) && offset_in_src_data_buf_ >= 0 && - read_size_ >= 0 && - read_size_ <= ObTmpFileGlobal::ALLOC_PAGE_SIZE && - OB_NOT_NULL(page_handle_.value_) && - page_handle_.handle_.is_valid()) { - bret = true; - } - return bret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_io_ctx.h b/src/storage/tmp_file/ob_tmp_file_io_ctx.h deleted file mode 100644 index 20f667f6b9..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io_ctx.h +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_CTX_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_CTX_H_ - -#include "storage/blocksstable/ob_macro_block_handle.h" -#include "storage/tmp_file/ob_tmp_file_cache.h" -#include "storage/tmp_file/ob_tmp_file_block_manager.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileIOCtx -{ -public: - ObTmpFileIOCtx(); - ~ObTmpFileIOCtx(); - - int init(const int64_t fd, const int64_t dir_id, - const bool is_read, - const common::ObIOFlag io_flag, - const int64_t io_timeout_ms, - const bool disable_page_cache, - const bool disable_block_cache, - const bool prefetch); - void reuse(); - void reset(); - bool is_valid() const; - int prepare_read(char *read_buf, const int64_t read_size); - int prepare_read(char *read_buf, const int64_t read_size, const int64_t read_offset); - int prepare_write(char *write_buf, const int64_t write_size); - int update_data_size(const int64_t size); - int wait(); - -public: - OB_INLINE bool check_buf_range_valid(const char* buffer, const int64_t length) const - { - return buffer != nullptr && buffer >= buf_ && buffer + length <= buf_ + buf_size_; - } - OB_INLINE int64_t get_fd() const { return fd_; } - OB_INLINE int64_t get_dir_id() const { return dir_id_; } - OB_INLINE bool is_read() const { return is_read_; } - OB_INLINE char *get_buffer() { return buf_; } - OB_INLINE char *get_buffer() const { return buf_; } - OB_INLINE char *get_todo_buffer() { return buf_ + done_size_; } - OB_INLINE char *get_todo_buffer() const { return buf_ + done_size_; } - OB_INLINE int64_t get_done_size() const { return done_size_; } - OB_INLINE int64_t get_todo_size() const { return todo_size_; } - OB_INLINE int64_t get_read_offset_in_file() const { return read_offset_in_file_; } - OB_INLINE void set_read_offset_in_file(const int64_t offset) { read_offset_in_file_ = offset; } - OB_INLINE bool is_disable_page_cache() const { return disable_page_cache_; } - OB_INLINE bool is_disable_block_cache() const { return disable_block_cache_; } - OB_INLINE bool is_prefetch() const { return prefetch_; } - OB_INLINE common::ObIOFlag get_io_flag() const { return io_flag_; } - OB_INLINE int64_t get_io_timeout_ms() const { return io_timeout_ms_; } - TO_STRING_KV(K(is_inited_), K(is_read_), - K(fd_), K(dir_id_), KP(buf_), - K(buf_size_), K(done_size_), K(todo_size_), - K(read_offset_in_file_), - K(disable_page_cache_), K(disable_block_cache_), - K(prefetch_), K(io_flag_), K(io_timeout_ms_), - K(is_unaligned_write_), - K(write_persisted_tail_page_cnt_), K(lack_page_cnt_), - K(is_unaligned_read_), - K(total_truncated_page_read_cnt_), K(total_kv_cache_page_read_cnt_), - K(total_uncached_page_read_cnt_), K(total_wbp_page_read_cnt_), - K(truncated_page_read_hits_), K(kv_cache_page_read_hits_), - K(uncached_page_read_hits_), K(aggregate_read_io_cnt_), K(wbp_page_read_hits_)); -public: - // for virtual table stat info - OB_INLINE void set_is_unaligned_write(const bool is_unaligned_write) { is_unaligned_write_ = is_unaligned_write; } - OB_INLINE bool is_unaligned_write() const { return is_unaligned_write_; } - - OB_INLINE void add_write_persisted_tail_page_cnt() { write_persisted_tail_page_cnt_++; } - OB_INLINE int64_t get_write_persisted_tail_page_cnt() const { return write_persisted_tail_page_cnt_; } - - OB_INLINE void add_lack_page_cnt() { lack_page_cnt_++; } - OB_INLINE int64_t get_lack_page_cnt() const { return lack_page_cnt_; } - - OB_INLINE void set_is_unaligned_read(const bool is_unaligned_read) { is_unaligned_read_ = is_unaligned_read; } - OB_INLINE bool is_unaligned_read() const { return is_unaligned_read_; } - - OB_INLINE void update_read_truncated_stat(const int64_t page_num) - { - total_truncated_page_read_cnt_ += page_num; - truncated_page_read_hits_++; - } - OB_INLINE int64_t get_total_truncated_page_read_cnt() const { return total_truncated_page_read_cnt_; } - OB_INLINE int64_t get_truncated_page_read_hits() const { return truncated_page_read_hits_; } - - OB_INLINE void update_read_kv_cache_page_stat(const int64_t page_num, const int64_t read_cnt) - { - total_kv_cache_page_read_cnt_ += page_num; - kv_cache_page_read_hits_ += read_cnt; - } - OB_INLINE int64_t get_total_kv_cache_page_read_cnt() const { return total_kv_cache_page_read_cnt_; } - OB_INLINE int64_t get_kv_cache_page_read_hits() const { return kv_cache_page_read_hits_; } - - OB_INLINE void update_sn_read_uncached_page_stat(const int64_t page_num, const int64_t read_cnt) - { - total_uncached_page_read_cnt_ += page_num; - uncached_page_read_hits_ += read_cnt; - } - OB_INLINE int64_t get_total_uncached_page_read_cnt() const { return total_uncached_page_read_cnt_; } - OB_INLINE int64_t get_uncached_page_read_hits() const { return uncached_page_read_hits_; } - - OB_INLINE void update_read_wbp_page_stat(const int64_t page_num) - { - total_wbp_page_read_cnt_ += page_num; - wbp_page_read_hits_++; - } - OB_INLINE int64_t get_total_wbp_page_read_cnt() const { return total_wbp_page_read_cnt_; } - OB_INLINE int64_t get_wbp_page_read_hits() const { return wbp_page_read_hits_; } - -public: - struct ObIReadHandle - { - ObIReadHandle(); - ObIReadHandle(char *dest_user_read_buf, - const int64_t offset_in_src_data_buf, - const int64_t read_size); - ~ObIReadHandle(); - ObIReadHandle(const ObIReadHandle &other); - ObIReadHandle &operator=(const ObIReadHandle &other); - virtual bool is_valid() = 0; - TO_STRING_KV(KP(dest_user_read_buf_), K(offset_in_src_data_buf_), K(read_size_)); - - char *dest_user_read_buf_; // user buf - int64_t offset_in_src_data_buf_; - int64_t read_size_; - }; - - struct ObIOReadHandle final : public ObIReadHandle - { - ObIOReadHandle(); - ObIOReadHandle(char *dest_user_read_buf, - const int64_t offset_in_src_data_buf, const int64_t read_size); - ObIOReadHandle(char *dest_user_read_buf, - const int64_t offset_in_src_data_buf, const int64_t read_size, - ObTmpFileBlockHandle block_handle); - ~ObIOReadHandle(); - ObIOReadHandle(const ObIOReadHandle &other); - ObIOReadHandle &operator=(const ObIOReadHandle &other); - virtual bool is_valid() override; - INHERIT_TO_STRING_KV("ObIReadHandle", ObIReadHandle, K(handle_), K(block_handle_)); - blocksstable::ObStorageObjectHandle handle_; - ObTmpFileBlockHandle block_handle_; - }; - - struct ObBlockCacheHandle final : public ObIReadHandle - { - ObBlockCacheHandle(); - ObBlockCacheHandle(char* dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size); - ~ObBlockCacheHandle(); - int assign(const ObBlockCacheHandle &other) - { - int ret = OB_SUCCESS; - if (OB_FAIL(this->block_handle_.assign(other.block_handle_))) { - } else { - ObIReadHandle::operator=(other); - } - return ret; - } - virtual bool is_valid() override; - INHERIT_TO_STRING_KV("ObIReadHandle", ObIReadHandle, K(block_handle_)); - ObTmpBlockValueHandle block_handle_; - }; - - struct ObPageCacheHandle final : public ObIReadHandle - { - ObPageCacheHandle(); - ObPageCacheHandle(char* dest_user_read_buf, const int64_t offset_in_src_data_buf, const int64_t read_size); - ~ObPageCacheHandle(); - int init(const ObTmpPageValueHandle &page_handle) { - return page_handle_.assign(page_handle); - } - int assign(const ObPageCacheHandle &other) - { - int ret = OB_SUCCESS; - if (OB_FAIL(this->page_handle_.assign(other.page_handle_))) { - } else { - ObIReadHandle::operator=(other); - } - return ret; - } - virtual bool is_valid() override; - INHERIT_TO_STRING_KV("ObIReadHandle", ObIReadHandle, K(page_handle_)); - ObTmpPageValueHandle page_handle_; - }; - - common::ObIArray &get_io_handles() - { - return io_handles_; - } - common::ObIArray &get_page_cache_handles() - { - return page_cache_handles_; - } - common::ObIArray &get_block_cache_handles() - { - return block_cache_handles_; - } - -private: - int wait_read_finish_(); - int do_read_wait_(); - -private: - bool is_inited_; - bool is_read_; - int64_t fd_; - int64_t dir_id_; - char *buf_; - int64_t buf_size_; - int64_t done_size_; - int64_t todo_size_; - int64_t read_offset_in_file_; // this var means the start offset for read. - // if this var is negative, it will be set by - // read_offset of file in file's read function - bool disable_page_cache_; - bool disable_block_cache_; // only used in ut, to control whether read data from block cache - bool prefetch_; - common::ObIOFlag io_flag_; - int64_t io_timeout_ms_; - common::ObSEArray io_handles_; - common::ObSEArray page_cache_handles_; - common::ObSEArray block_cache_handles_; - /********for virtual table statistics begin********/ - // for write - bool is_unaligned_write_; - int64_t write_persisted_tail_page_cnt_; - int64_t lack_page_cnt_; - // for read - bool is_unaligned_read_; - int64_t total_truncated_page_read_cnt_; - int64_t total_kv_cache_page_read_cnt_; - int64_t total_uncached_page_read_cnt_; - int64_t total_wbp_page_read_cnt_; - int64_t truncated_page_read_hits_; - int64_t kv_cache_page_read_hits_; - int64_t uncached_page_read_hits_; - int64_t aggregate_read_io_cnt_; - int64_t wbp_page_read_hits_; - /********for virtual table statistics end********/ - DISALLOW_COPY_AND_ASSIGN(ObTmpFileIOCtx); -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_CTX_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_io_handle.cpp b/src/storage/tmp_file/ob_tmp_file_io_handle.cpp deleted file mode 100644 index 9bf07e3465..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io_handle.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_io_info.h" -#include "share/rc/ob_server_runtime.h" -#include "storage/tmp_file/ob_tmp_file_io_handle.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" - -namespace oceanbase -{ -using namespace storage; -using namespace share; - -namespace tmp_file -{ -ObTmpFileIOHandle::ObTmpFileIOHandle() - : is_inited_(false), - fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - ctx_(), - buf_(nullptr), - update_offset_in_file_(false), - buf_size_(-1), - done_size_(-1), - read_offset_in_file_(-1) -{ -} - -ObTmpFileIOHandle::~ObTmpFileIOHandle() -{ - reset(); -} - -void ObTmpFileIOHandle::reset() -{ - is_inited_ = false; - ctx_.reset(); - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - buf_ = nullptr; - update_offset_in_file_ = false; - buf_size_ = -1; - done_size_ = -1; - read_offset_in_file_ = -1; -} - -int ObTmpFileIOHandle::init_write(const ObTmpFileIOInfo &io_info) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(ctx_.init(io_info.fd_, io_info.dir_id_, false /*is_read*/, - io_info.io_desc_, io_info.io_timeout_ms_, io_info.disable_page_cache_, - io_info.disable_block_cache_, false /*prefetch*/))) { - } else if (OB_FAIL(ctx_.prepare_write(io_info.buf_, io_info.size_))) { - } else { - is_inited_ = true; - fd_ = io_info.fd_; - buf_ = io_info.buf_; - buf_size_ = io_info.size_; - done_size_ = 0; - } - - return ret; -} - -int ObTmpFileIOHandle::init_pread(const ObTmpFileIOInfo &io_info, const int64_t read_offset) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(read_offset < 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(ctx_.init(io_info.fd_, io_info.dir_id_, true /*is_read*/, - io_info.io_desc_, io_info.io_timeout_ms_, io_info.disable_page_cache_, - io_info.disable_block_cache_, io_info.prefetch_))) { - } else if (OB_FAIL(ctx_.prepare_read(io_info.buf_, MIN(io_info.size_, ObTmpFileGlobal::TMP_FILE_READ_BATCH_SIZE), read_offset))) { - } else { - is_inited_ = true; - fd_ = io_info.fd_; - buf_ = io_info.buf_; - buf_size_ = io_info.size_; - done_size_ = 0; - read_offset_in_file_ = read_offset; - } - - return ret; -} - -int ObTmpFileIOHandle::init_read(const ObTmpFileIOInfo &io_info) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(ctx_.init(io_info.fd_, io_info.dir_id_, true /*is_read*/, - io_info.io_desc_, io_info.io_timeout_ms_, io_info.disable_page_cache_, - io_info.disable_block_cache_, io_info.prefetch_))) { - } else if (OB_FAIL(ctx_.prepare_read(io_info.buf_, MIN(io_info.size_, ObTmpFileGlobal::TMP_FILE_READ_BATCH_SIZE)))) { - } else { - is_inited_ = true; - fd_ = io_info.fd_; - buf_ = io_info.buf_; - buf_size_ = io_info.size_; - done_size_ = 0; - read_offset_in_file_ = -1; - update_offset_in_file_ = true; - } - - return ret; -} - -bool ObTmpFileIOHandle::is_valid() const -{ - return is_inited_ && - nullptr != buf_ && - done_size_ >= 0 && buf_size_ > 0 && - buf_size_ >= done_size_; -} - -int ObTmpFileIOHandle::wait() -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!is_valid())) { - ret = OB_ERR_UNEXPECTED; - } else if (is_finished() || !ctx_.is_read()) { - // do nothing - } else { - - if (FAILEDx(ctx_.wait())) { - } else if (OB_FAIL(handle_finished_ctx_(ctx_))) { - } else if (OB_UNLIKELY(done_size_ > buf_size_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>()->get_tmp_file(fd_, file_handle))) { - } else { - while (OB_SUCC(ret) && !is_finished()) { - if (OB_FAIL(ctx_.prepare_read(buf_ + done_size_, - MIN(buf_size_ - done_size_, - ObTmpFileGlobal::TMP_FILE_READ_BATCH_SIZE), - read_offset_in_file_))) { - } else if (OB_FAIL(file_handle.get()->aio_pread(ctx_))) { - } else if (OB_FAIL(ctx_.wait())) { - } else if (OB_FAIL(handle_finished_ctx_(ctx_))) { - } - } // end while - - if (update_offset_in_file_ && (OB_SUCC(ret) || OB_ITER_END == ret)) { - file_handle.get()->update_read_offset(read_offset_in_file_); - } - } - } - - return ret; -} - -int ObTmpFileIOHandle::handle_finished_ctx_(ObTmpFileIOCtx &ctx) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!ctx.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else { - if (ctx_.is_read()) { - read_offset_in_file_ = ctx.get_read_offset_in_file(); - } - done_size_ += ctx.get_done_size(); - ctx.reuse(); - } - - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_io_handle.h b/src/storage/tmp_file/ob_tmp_file_io_handle.h deleted file mode 100644 index 6cceee60e2..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io_handle.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_DEFINE_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_DEFINE_H_ - -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "storage/tmp_file/ob_tmp_file_io_ctx.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileIOInfo; - -class ObTmpFileIOHandle final -{ -public: - ObTmpFileIOHandle(); - ~ObTmpFileIOHandle(); - int init_write(const ObTmpFileIOInfo &io_info); - int init_read(const ObTmpFileIOInfo &io_info); - int init_pread(const ObTmpFileIOInfo &io_info, const int64_t read_offset); - int wait(); - void reset(); - bool is_valid() const; - - TO_STRING_KV(K(is_inited_), K(fd_), K(ctx_), - KP(buf_), K(update_offset_in_file_), - K(buf_size_), K(done_size_), - K(read_offset_in_file_)); -public: - OB_INLINE char *get_buffer() { return buf_; } - OB_INLINE int64_t get_done_size() const { return done_size_; } - OB_INLINE int64_t get_buf_size() const { return buf_size_; } - OB_INLINE ObTmpFileIOCtx &get_io_ctx() { return ctx_; } - OB_INLINE bool is_finished() const { return done_size_ == buf_size_; } -private: - int handle_finished_ctx_(ObTmpFileIOCtx &ctx); - -private: - bool is_inited_; - int64_t fd_; - ObTmpFileIOCtx ctx_; - char *buf_; - bool update_offset_in_file_; - int64_t buf_size_; // excepted total read or write size - int64_t done_size_; // has finished read or write size - int64_t read_offset_in_file_; // records the beginning read offset for current read ctx - - DISALLOW_COPY_AND_ASSIGN(ObTmpFileIOHandle); -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_DEFINE_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_io_info.cpp b/src/storage/tmp_file/ob_tmp_file_io_info.cpp deleted file mode 100644 index 65b679f8a7..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io_info.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_io_info.h" - -namespace oceanbase -{ -using namespace share; - -namespace tmp_file -{ - -ObTmpFileIOInfo::ObTmpFileIOInfo() - : fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - dir_id_(0), buf_(nullptr), size_(0), - disable_page_cache_(false), disable_block_cache_(false), - io_desc_(), io_timeout_ms_(DEFAULT_IO_WAIT_TIME_MS) -{} - -ObTmpFileIOInfo::~ObTmpFileIOInfo() -{ - reset(); -} - -void ObTmpFileIOInfo::reset() -{ - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - dir_id_ = 0; - size_ = 0; - io_timeout_ms_ = DEFAULT_IO_WAIT_TIME_MS; - buf_ = nullptr; - io_desc_.reset(); - disable_page_cache_ = false; - disable_block_cache_ = false; -} - -bool ObTmpFileIOInfo::is_valid() const -{ - return fd_ != ObTmpFileGlobal::INVALID_TMP_FILE_FD && - dir_id_ != ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID && - size_ > 0 && - nullptr != buf_ && io_desc_.is_valid() && io_timeout_ms_ >= 0; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_io_info.h b/src/storage/tmp_file/ob_tmp_file_io_info.h deleted file mode 100644 index 8b38bb801d..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_io_info.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_INFO_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_INFO_H_ - -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "share/io_request.h" - -namespace oceanbase -{ -namespace tmp_file -{ -struct ObTmpFileIOInfo final -{ - ObTmpFileIOInfo(); - ~ObTmpFileIOInfo(); - void reset(); - bool is_valid() const; - TO_STRING_KV(K(fd_), K(dir_id_), KP(buf_), K(size_), K(disable_page_cache_), K(disable_block_cache_), - K(prefetch_), K(io_timeout_ms_), K(io_desc_)); - - int64_t fd_; - int64_t dir_id_; - char *buf_; - int64_t size_; - bool disable_page_cache_; - bool disable_block_cache_; - bool prefetch_; - common::ObIOFlag io_desc_; - int64_t io_timeout_ms_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_IO_INFO_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_manager.cpp b/src/storage/tmp_file/ob_tmp_file_manager.cpp deleted file mode 100644 index 3a0ff16c96..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_manager.cpp +++ /dev/null @@ -1,886 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_manager.h" -#include "data_plane/tmp_file/ob_tmp_file.h" -#include "lib/utility/ob_platform_utils.h" - -#ifdef _WIN32 -#include -#define sleep(sec) Sleep((sec) * 1000) -#endif - -namespace oceanbase -{ -namespace tmp_file -{ -ObTmpFileManager::ObTmpFileManager() - : is_inited_(false), - is_running_(false), - tmp_file_allocator_(), - callback_allocator_(), - wbp_index_cache_allocator_(), - wbp_index_cache_bucket_allocator_(), - files_(), - tmp_file_block_manager_(), - page_cache_controller_(tmp_file_block_manager_) -{ -} - -ObTmpFileManager::~ObTmpFileManager() -{ - destroy(); -} - -int ObTmpFileManager::init() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(IS_INIT)) { - ret = OB_INIT_TWICE; - } else if (OB_FAIL(files_.init("TmpFileMap"))) { - } else if (OB_FAIL(tmp_file_allocator_.init(common::OB_MALLOC_MIDDLE_BLOCK_SIZE, - ObModIds::OB_TMP_FILE_MANAGER, - INT64_MAX))) { - } else if (OB_FAIL(callback_allocator_.init(lib::ObMallocAllocator::get_instance(), - OB_MALLOC_MIDDLE_BLOCK_SIZE, - ObMemAttr("TmpFileCallback", ObCtxIds::DEFAULT_CTX_ID)))) { - } else if (OB_FAIL(wbp_index_cache_allocator_.init(lib::ObMallocAllocator::get_instance(), - OB_MALLOC_NORMAL_BLOCK_SIZE, - ObMemAttr("TmpFileIndCache", - ObCtxIds::DEFAULT_CTX_ID)))) { - } else if (OB_FAIL(wbp_index_cache_bucket_allocator_.init(lib::ObMallocAllocator::get_instance(), - OB_MALLOC_MIDDLE_BLOCK_SIZE, - ObMemAttr("TmpFileIndCBkt", - ObCtxIds::DEFAULT_CTX_ID)))) { - } else if (OB_FAIL(init_sub_module_())) { - } else { - is_inited_ = true; - } - - return ret; -} - -int ObTmpFileManager::start() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_running())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(start_sub_module_())) { - } else { - is_running_ = true; - } - - return ret; -} - -void ObTmpFileManager::stop() -{ - int ret = OB_SUCCESS; - if (is_running_) { - if (OB_FAIL(stop_sub_module_())) { - } else { - is_running_ = false; - } - } -} - -void ObTmpFileManager::wait() -{ - int ret = OB_SUCCESS; - if (OB_FAIL(wait_sub_module_())) { - } -} - -void ObTmpFileManager::destroy() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - if (OB_FAIL(destroy_sub_module_())) { - } else { - int64_t curr_file_cnt = files_.count(); - if (OB_UNLIKELY(curr_file_cnt > 0)) { - int ret = OB_SUCCESS; - TmpFileMap::BlurredIterator iter(files_); - while (OB_SUCC(ret)) { - ObTmpFileKey unused_key(ObTmpFileGlobal::INVALID_TMP_FILE_FD); - ObSNTmpFileHandle handle; - if (OB_FAIL(iter.next(unused_key, handle))) { - if (OB_ITER_END == ret) { - ret = OB_SUCCESS; - break; - } else { - } - } else { - // resource leak - LOG_ERROR("the tmp file has not been removed when tmp file mgr is destroying", KPC(handle.get())); - } - } // end while - - int64_t new_file_cnt = files_.count(); - if (OB_UNLIKELY(new_file_cnt != curr_file_cnt)) { - LOG_ERROR("there are some operation for tmp files when tmp file mgr is destroying", K(curr_file_cnt)); - } - } - files_.destroy(); - tmp_file_allocator_.reset(); - callback_allocator_.reset(); - wbp_index_cache_allocator_.reset(); - wbp_index_cache_bucket_allocator_.reset(); - is_inited_ = false; - } - } - - LOG_INFO("ObTmpFileManager destroy", KP(this)); -} - -int ObTmpFileManager::remove(const int64_t fd) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - int64_t start_remove_ts = ObTimeUtility::current_time(); - LOG_INFO("remove a tmp file start", KR(ret), K(start_remove_ts), K(fd), K(lbt())); - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - // } else if (OB_UNLIKELY(!is_running())) { - // // some modules remove tmp file when they are destroying. - // // at this time, the tmp file mgr is not running because of stop(). - // // thus, we need to support this case - // ret = OB_ERR_UNEXPECTED; - // LOG_WARN("ObTmpFileManager is not running", KR(ret), K(is_running_)); - } else if (OB_FAIL(files_.erase(ObTmpFileKey(fd), tmp_file_handle))) { - if (OB_ENTRY_NOT_EXIST == ret) { - ret = OB_SUCCESS; - LOG_INFO("erase non-exist tmp file", K(fd), K(lbt())); - } else { - } - } else if (OB_ISNULL(tmp_file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected null", KR(ret), KP(tmp_file_handle.get()), K(fd)); - } else if (OB_FAIL(tmp_file_handle.get()->delete_file())) { - } else { - ObSharedNothingTmpFile *tmp_file = tmp_file_handle.get(); - - int64_t LOG_WARN_TIMEOUT = 10 * 1000 * 1000; - int64_t LOG_ERROR_TIMEOUT = 60 * 1000 * 1000; - while(!tmp_file->can_remove()) - { - if (start_remove_ts + LOG_ERROR_TIMEOUT < ObTimeUtility::current_time()) { - LOG_ERROR("wait thread release reference too long", - K(start_remove_ts), KP(tmp_file), KPC(tmp_file), K(lbt())); - sleep(10); // 10s - } else if (start_remove_ts + LOG_WARN_TIMEOUT < ObTimeUtility::current_time()) { - LOG_WARN("wait thread release reference too long", - K(start_remove_ts), KP(tmp_file), KPC(tmp_file), K(lbt())); - sleep(2); // 2s - } else { - lib::ob_usleep(100 * 1000); // 100ms - } - } - if (OB_FAIL(tmp_file->release_resource())) { - } else { - tmp_file_handle.reset(); - tmp_file_allocator_.free(tmp_file); - } - } - - LOG_INFO("remove a tmp file over", KR(ret), K(start_remove_ts), K(fd), K(lbt())); - return ret; -} - -int ObTmpFileManager::aio_read(const ObTmpFileIOInfo &io_info, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(io_handle.is_valid() && !io_handle.is_finished())) { - ret = OB_INVALID_ARGUMENT; - } else if (FALSE_IT(io_handle.reset())) { - } else if (OB_FAIL(get_tmp_file(io_info.fd_, tmp_file_handle))) { - } else if (OB_FAIL(io_handle.init_read(io_info))) { - } else if (OB_FAIL(tmp_file_handle.get()->aio_pread(io_handle.get_io_ctx()))) { - } else { - tmp_file_handle.get()->set_read_stats_vars(io_handle.get_io_ctx(), io_info.size_); - } - - LOG_DEBUG("aio_read a tmp file over", KR(ret), K(io_info), K(io_handle), KPC(tmp_file_handle.get())); - return ret; -} - -int ObTmpFileManager::aio_pread(const ObTmpFileIOInfo &io_info, - const int64_t offset, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(io_handle.is_valid() && !io_handle.is_finished())) { - ret = OB_INVALID_ARGUMENT; - } else if (FALSE_IT(io_handle.reset())) { - } else if (OB_FAIL(get_tmp_file(io_info.fd_, tmp_file_handle))) { - } else if (OB_FAIL(io_handle.init_pread( io_info, offset))) { - } else if (OB_FAIL(tmp_file_handle.get()->aio_pread(io_handle.get_io_ctx()))) { - } else { - tmp_file_handle.get()->set_read_stats_vars(io_handle.get_io_ctx(), io_info.size_); - } - - LOG_DEBUG("aio_pread a tmp file over", KR(ret), K(io_info), K(offset), K(io_handle), KPC(tmp_file_handle.get())); - return ret; -} - -int ObTmpFileManager::read(const ObTmpFileIOInfo &io_info, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(io_handle.is_valid() && !io_handle.is_finished())) { - ret = OB_INVALID_ARGUMENT; - } else if (FALSE_IT(io_handle.reset())) { - } else if (OB_FAIL(get_tmp_file(io_info.fd_, tmp_file_handle))) { - } else if (OB_FAIL(io_handle.init_read(io_info))) { - } else if (OB_FAIL(tmp_file_handle.get()->aio_pread(io_handle.get_io_ctx()))) { - } else { - tmp_file_handle.get()->set_read_stats_vars(io_handle.get_io_ctx(), io_info.size_); - } - - if (OB_SUCC(ret) || OB_ITER_END == ret) { - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(io_handle.wait())) { - } - ret = OB_SUCCESS == ret ? tmp_ret : ret; - } - - LOG_DEBUG("read a tmp file over", KR(ret), K(io_info), K(io_handle), KPC(tmp_file_handle.get())); - return ret; -} - -int ObTmpFileManager::pread(const ObTmpFileIOInfo &io_info, - const int64_t offset, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(io_handle.is_valid() && !io_handle.is_finished())) { - ret = OB_INVALID_ARGUMENT; - } else if (FALSE_IT(io_handle.reset())) { - } else if (OB_FAIL(get_tmp_file(io_info.fd_, tmp_file_handle))) { - } else if (OB_FAIL(io_handle.init_pread( io_info, offset))) { - } else if (OB_FAIL(tmp_file_handle.get()->aio_pread(io_handle.get_io_ctx()))) { - } else { - tmp_file_handle.get()->set_read_stats_vars(io_handle.get_io_ctx(), io_info.size_); - } - - if (OB_SUCC(ret) || OB_ITER_END == ret) { - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(io_handle.wait())) { - } - ret = OB_SUCCESS == ret ? tmp_ret : ret; - } - - LOG_DEBUG("pread a tmp file over", KR(ret), K(io_info), K(offset), K(io_handle), KPC(tmp_file_handle.get())); - return ret; -} - -int ObTmpFileManager::aio_write(const ObTmpFileIOInfo &io_info, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - io_handle.reset(); - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!io_info.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(get_tmp_file(io_info.fd_, tmp_file_handle))) { - } else if (OB_FAIL(io_handle.init_write(io_info))) { - } else if (OB_FAIL(tmp_file_handle.get()->aio_write(io_handle.get_io_ctx()))) { - } else { - tmp_file_handle.get()->set_write_stats_vars(io_handle.get_io_ctx()); - } - - LOG_DEBUG("aio_write a tmp file over", KR(ret), K(io_info), K(io_handle), KPC(tmp_file_handle.get())); - return ret; -} - -// tmp file is always buffer writing, there are no io tasks need to be waited -int ObTmpFileManager::write(const ObTmpFileIOInfo &io_info) -{ - int ret = OB_SUCCESS; - ObTmpFileIOHandle io_handle; - - if (OB_FAIL(aio_write(io_info, io_handle))) { - } - - return ret; -} - -int ObTmpFileManager::truncate(const int64_t fd, const int64_t offset) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(fd == ObTmpFileGlobal::INVALID_TMP_FILE_FD || offset < 0)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(get_tmp_file(fd, tmp_file_handle))) { - } else if (OB_FAIL(tmp_file_handle.get()->truncate(offset))) { - } else { - } - return ret; -} - -int ObTmpFileManager::seal(const int64_t fd) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(get_tmp_file(fd, tmp_file_handle))) { - } else if (OB_FAIL(tmp_file_handle.get()->seal())) { - } else { - LOG_INFO("seal a tmp file over", KR(ret), K(fd)); - } - return ret; -} - -// Get tmp file and increase its refcnt -int ObTmpFileManager::get_tmp_file(const int64_t fd, ObSNTmpFileHandle &file_handle) -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(fd == ObTmpFileGlobal::INVALID_TMP_FILE_FD)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(files_.get(ObTmpFileKey(fd), file_handle))) { - if (OB_ENTRY_NOT_EXIST == ret) { - } else { - } - } else if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("get invalid tmp file pointer", KR(ret), K(fd), KP(file_handle.get())); - } - - return ret; -} - -int ObTmpFileManager::get_tmp_file_size(const int64_t fd, int64_t &size) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle tmp_file_handle; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(get_tmp_file(fd, tmp_file_handle))) { - } else { - size = tmp_file_handle.get()->get_file_size(); - } - - return ret; -} - -bool ObTmpFileManager::CollectTmpFileKeyFunctor::operator()( - const ObTmpFileKey &key, const ObSNTmpFileHandle &tmp_file_handle) -{ - int ret = OB_SUCCESS; - ObSharedNothingTmpFile *tmp_file_ptr = NULL; - - if (OB_ISNULL(tmp_file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("get invalid tmp file pointer", KR(ret), K(key), KP(tmp_file_handle.get())); - } else if (OB_FAIL(fds_.push_back(key.fd_))) { - } - return OB_SUCCESS == ret; -} - -int ObTmpFileManager::get_tmp_file_fds(ObIArray &fd_arr) -{ - int ret = OB_SUCCESS; - CollectTmpFileKeyFunctor func(fd_arr); - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_FAIL(files_.for_each(func))) { - } - - return ret; -} - -int ObTmpFileManager::get_tmp_file_info(const int64_t fd, ObTmpFileInfo *tmp_file_info) -{ - int ret = OB_SUCCESS; - ObSNTmpFileHandle file_handle; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_ISNULL(tmp_file_info)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(get_tmp_file(fd, file_handle))) { - if (OB_ENTRY_NOT_EXIST == ret) { - LOG_INFO("tmp file not exist", KR(ret), K(fd)); - } else { - } - } else if (OB_ISNULL(file_handle.get())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("get invalid tmp file pointer", KR(ret), K(fd), KP(file_handle.get())); - } else if (OB_FAIL(file_handle.get()->copy_info_for_virtual_table(*tmp_file_info))) { - } - - return ret; -} - -int64_t ObTmpFileManager::current_fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; -int64_t ObTmpFileManager::current_dir_id_ = ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID; - -int ObTmpFileManager::init_sub_module_() -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(tmp_file_block_manager_.init())) { - } else if (OB_FAIL(page_cache_controller_.init())) { - } else { - LOG_INFO("ObTmpFileManager init successful", KP(this)); - } - - return ret; -} - -int ObTmpFileManager::start_sub_module_() -{ - int ret = OB_SUCCESS; - if (OB_FAIL(page_cache_controller_.start())) { - ret = OB_ERR_UNEXPECTED; - } else { - is_running_ = true; - LOG_INFO("ObTmpFileManager start successful", KP(this)); - } - return ret; -} - -int ObTmpFileManager::stop_sub_module_() -{ - int ret = OB_SUCCESS; - page_cache_controller_.stop(); - LOG_INFO("ObTmpFileManager stop successful", KP(this)); - return ret; -} - -int ObTmpFileManager::wait_sub_module_() -{ - int ret = OB_SUCCESS; - page_cache_controller_.wait(); - LOG_INFO("ObTmpFileManager wait successful", KP(this)); - return ret; -} - -int ObTmpFileManager::destroy_sub_module_() -{ - int ret = OB_SUCCESS; - page_cache_controller_.destroy(); - tmp_file_block_manager_.destroy(); - - LOG_INFO("ObTmpFileManager destroy", KP(this)); - return ret; -} - -int ObTmpFileManager::alloc_dir(int64_t &dir_id) -{ - int ret = OB_SUCCESS; - dir_id = ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!is_running())) { - ret = OB_ERR_UNEXPECTED; - } else { - dir_id = ATOMIC_AAF(¤t_dir_id_, 1); - } - - LOG_DEBUG("alloc dir over", KR(ret), K(dir_id), K(lbt())); - return ret; -} - -int ObTmpFileManager::open(int64_t &fd, const int64_t &dir_id, const char* const label) -{ - int ret = OB_SUCCESS; - fd = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - void *buf = nullptr; - ObSharedNothingTmpFile *tmp_file = nullptr; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(!is_running())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(buf = tmp_file_allocator_.alloc(sizeof(ObSharedNothingTmpFile), - lib::ObMemAttr("SNTmpFile")))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (FALSE_IT(tmp_file = new (buf) ObSharedNothingTmpFile())) { - } else if (FALSE_IT(fd = ATOMIC_AAF(¤t_fd_, 1))) { - } else if (OB_FAIL(tmp_file->init(fd, dir_id, - &tmp_file_block_manager_, &callback_allocator_, - &wbp_index_cache_allocator_, &wbp_index_cache_bucket_allocator_, - &page_cache_controller_, label))) { - } else if (OB_FAIL(files_.insert(ObTmpFileKey(fd), tmp_file))) { - } - - if (OB_FAIL(ret) && OB_NOT_NULL(tmp_file)) { - tmp_file->~ObSharedNothingTmpFile(); - tmp_file_allocator_.free(tmp_file); - tmp_file = nullptr; - } - - LOG_INFO("open a tmp file over", KR(ret), K(fd), K(dir_id), KP(tmp_file), K(lbt())); - return ret; -} - -int ObTmpFileManager::get_macro_block_list(common::ObIArray ¯o_id_list) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; -// This function remains available after the service stops and before destruction. -// } else if (OB_UNLIKELY(!is_running())) { -// ret = OB_ERR_UNEXPECTED; -// LOG_WARN("ObTmpFileManager is not running", KR(ret), K(is_running_)); - } else if (OB_FAIL(tmp_file_block_manager_.get_macro_block_list(macro_id_list))) { - } - - LOG_INFO("get tmp file macro block list", KR(ret), K(macro_id_list.count())); - return ret; -} - -int ObTmpFileManager::get_tmp_file_disk_usage(int64_t &disk_data_size, int64_t &occupied_disk_size) -{ - int ret = OB_SUCCESS; - int64_t used_page_num = 0; - int64_t macro_block_count = 0; - disk_data_size = 0; - occupied_disk_size = 0; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; -// This function remains available after the service stops and before destruction. -// } else if (OB_UNLIKELY(!is_running())) { -// ret = OB_ERR_UNEXPECTED; -// LOG_WARN("ObTmpFileManager is not running", KR(ret), K(is_running_)); - } else if (OB_FAIL(tmp_file_block_manager_.get_block_usage_stat(used_page_num, macro_block_count))) { - } else { - disk_data_size = used_page_num * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - occupied_disk_size = macro_block_count * ObTmpFileGlobal::SN_BLOCK_SIZE; - } - - LOG_INFO("get tmp file macro block count", KR(ret), K(used_page_num), K(macro_block_count)); - return ret; -} - -int ObTmpFileManager::server_module_init(ObTmpFileManager *&manager) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(manager)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(manager->init())) { - } - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase - -namespace oceanbase -{ -namespace data_plane -{ - -using ObTmpFileIOHandleImpl = tmp_file::ObTmpFileIOHandle; - -class ObTmpFileAccess -{ -public: - static ObTmpFileIOHandleImpl *get(const ObTmpFileIOHandle &handle) - { - return static_cast(handle.impl_); - } - - static int ensure(ObTmpFileIOHandle &handle, ObTmpFileIOHandleImpl *&impl) - { - int ret = OB_SUCCESS; - impl = get(handle); - if (OB_ISNULL(impl)) { - impl = OB_NEW(ObTmpFileIOHandleImpl, common::ObMemAttr("QryTmpFileIO")); - if (OB_ISNULL(impl)) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else { - handle.impl_ = impl; - } - } - return ret; - } - - static void destroy(ObTmpFileIOHandle &handle) - { - ObTmpFileIOHandleImpl *impl = get(handle); - if (OB_NOT_NULL(impl)) { - OB_DELETE(ObTmpFileIOHandleImpl, common::ObMemAttr("QryTmpFileIO"), impl); - handle.impl_ = nullptr; - } - } -}; - -namespace -{ -tmp_file::ObTmpFileManager *get_tmp_file_manager() -{ - return ::oceanbase::share::server_service<::oceanbase::tmp_file::ObTmpFileManager>(); -} - -void translate_io_info(const ObTmpFileIOInfo &from, tmp_file::ObTmpFileIOInfo &to) -{ - to.fd_ = from.fd_; - to.dir_id_ = from.dir_id_; - to.buf_ = from.buf_; - to.size_ = from.size_; - to.disable_page_cache_ = from.disable_page_cache_; - to.disable_block_cache_ = from.disable_block_cache_; - to.prefetch_ = from.prefetch_; - to.io_desc_ = from.io_desc_; - to.io_timeout_ms_ = from.io_timeout_ms_; -} - -typedef int (tmp_file::ObTmpFileManager::*TmpFileIOFn)( - const tmp_file::ObTmpFileIOInfo &, tmp_file::ObTmpFileIOHandle &); - -int submit_io(const ObTmpFileIOInfo &io_info, - ObTmpFileIOHandle &io_handle, - TmpFileIOFn operation) -{ - int ret = OB_SUCCESS; - tmp_file::ObTmpFileIOHandle *impl = nullptr; - if (OB_FAIL(ObTmpFileAccess::ensure(io_handle, impl))) { - } else if (OB_ISNULL(get_tmp_file_manager())) { - ret = OB_NOT_INIT; - } else { - tmp_file::ObTmpFileIOInfo impl_info; - translate_io_info(io_info, impl_info); - ret = (get_tmp_file_manager()->*operation)(impl_info, *impl); - } - return ret; -} -} // namespace - -ObTmpFileIOInfo::ObTmpFileIOInfo() - : fd_(tmp_file::ObTmpFileGlobal::INVALID_TMP_FILE_FD), - dir_id_(0), - buf_(nullptr), - size_(0), - disable_page_cache_(false), - disable_block_cache_(false), - prefetch_(false), - io_desc_(), - io_timeout_ms_(DEFAULT_IO_WAIT_TIME_MS) -{ -} - -void ObTmpFileIOInfo::reset() -{ - fd_ = tmp_file::ObTmpFileGlobal::INVALID_TMP_FILE_FD; - dir_id_ = 0; - buf_ = nullptr; - size_ = 0; - disable_page_cache_ = false; - disable_block_cache_ = false; - prefetch_ = false; - io_desc_.reset(); - io_timeout_ms_ = DEFAULT_IO_WAIT_TIME_MS; -} - -bool ObTmpFileIOInfo::is_valid() const -{ - return fd_ != tmp_file::ObTmpFileGlobal::INVALID_TMP_FILE_FD - && dir_id_ != tmp_file::ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID - && size_ > 0 - && OB_NOT_NULL(buf_) - && io_desc_.is_valid() - && io_timeout_ms_ >= 0; -} - -ObTmpFileIOHandle::ObTmpFileIOHandle() : impl_(nullptr) -{ -} - -ObTmpFileIOHandle::~ObTmpFileIOHandle() -{ - ObTmpFileAccess::destroy(*this); -} - -void ObTmpFileIOHandle::reset() -{ - tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - if (OB_NOT_NULL(impl)) { - impl->reset(); - } -} - -int ObTmpFileIOHandle::wait() -{ - tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - return OB_ISNULL(impl) ? OB_NOT_INIT : impl->wait(); -} - -bool ObTmpFileIOHandle::is_valid() const -{ - const tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - return OB_NOT_NULL(impl) && impl->is_valid(); -} - -char *ObTmpFileIOHandle::get_buffer() -{ - tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - return OB_ISNULL(impl) ? nullptr : impl->get_buffer(); -} - -int64_t ObTmpFileIOHandle::get_done_size() const -{ - const tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - return OB_ISNULL(impl) ? -1 : impl->get_done_size(); -} - -int64_t ObTmpFileIOHandle::get_buf_size() const -{ - const tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - return OB_ISNULL(impl) ? -1 : impl->get_buf_size(); -} - -bool ObTmpFileIOHandle::is_finished() const -{ - const tmp_file::ObTmpFileIOHandle *impl = ObTmpFileAccess::get(*this); - return OB_NOT_NULL(impl) && impl->is_finished(); -} - -int tmp_file_alloc_dir(int64_t &dir_id) -{ - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->alloc_dir(dir_id); -} - -int tmp_file_open(int64_t &fd, int64_t dir_id, const char *label) -{ - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->open(fd, dir_id, label); -} - -int tmp_file_remove(int64_t fd) -{ - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->remove(fd); -} - -int tmp_file_aio_read(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle) -{ - return submit_io(io_info, io_handle, - &tmp_file::ObTmpFileManager::aio_read); -} - -int tmp_file_aio_pread(const ObTmpFileIOInfo &io_info, - int64_t offset, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - tmp_file::ObTmpFileIOHandle *impl = nullptr; - if (OB_FAIL(ObTmpFileAccess::ensure(io_handle, impl))) { - } else if (OB_ISNULL(get_tmp_file_manager())) { - ret = OB_NOT_INIT; - } else { - tmp_file::ObTmpFileIOInfo impl_info; - translate_io_info(io_info, impl_info); - ret = get_tmp_file_manager()->aio_pread(impl_info, offset, *impl); - } - return ret; -} - -int tmp_file_pread(const ObTmpFileIOInfo &io_info, - int64_t offset, - ObTmpFileIOHandle &io_handle) -{ - int ret = OB_SUCCESS; - tmp_file::ObTmpFileIOHandle *impl = nullptr; - if (OB_FAIL(ObTmpFileAccess::ensure(io_handle, impl))) { - } else if (OB_ISNULL(get_tmp_file_manager())) { - ret = OB_NOT_INIT; - } else { - tmp_file::ObTmpFileIOInfo impl_info; - translate_io_info(io_info, impl_info); - ret = get_tmp_file_manager()->pread(impl_info, offset, *impl); - } - return ret; -} - -int tmp_file_aio_write(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle) -{ - return submit_io(io_info, io_handle, - &tmp_file::ObTmpFileManager::aio_write); -} - -int tmp_file_write(const ObTmpFileIOInfo &io_info) -{ - tmp_file::ObTmpFileIOInfo impl_info; - translate_io_info(io_info, impl_info); - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->write(impl_info); -} - -int tmp_file_truncate(int64_t fd, int64_t offset) -{ - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->truncate(fd, offset); -} - -int tmp_file_seal(int64_t fd) -{ - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->seal(fd); -} - -int tmp_file_get_size(int64_t fd, int64_t &file_size) -{ - tmp_file::ObTmpFileManager *manager = get_tmp_file_manager(); - return OB_ISNULL(manager) ? OB_NOT_INIT : manager->get_tmp_file_size(fd, file_size); -} - -} // namespace data_plane -} // namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_manager.h b/src/storage/tmp_file/ob_tmp_file_manager.h deleted file mode 100644 index 17e3c88660..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_manager.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "lib/hash/ob_linear_hash_map.h" -#include "lib/container/ob_array.h" -#include "storage/tmp_file/ob_shared_nothing_tmp_file.h" -#include "storage/tmp_file/ob_tmp_file_page_cache_controller.h" -#include "share/rc/ob_server_runtime.h" -#include "storage/tmp_file/ob_tmp_file_io_info.h" -#include "storage/tmp_file/ob_tmp_file_io_handle.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileManager final -{ -public: - typedef common::ObLinearHashMap TmpFileMap; -public: - static int server_module_init(ObTmpFileManager *&manager); - ObTmpFileManager(); - ~ObTmpFileManager(); - int init(); - int start(); - void stop(); - void wait(); - void destroy(); - OB_INLINE bool is_running() const { return is_running_; } - -public: - int alloc_dir(int64_t &dir_id); - int open(int64_t &fd, - const int64_t &dir_id, - const char *const label = "TmpFile"); - int remove(const int64_t fd); - int aio_read(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle); - int aio_pread(const ObTmpFileIOInfo &io_info, const int64_t offset, ObTmpFileIOHandle &io_handle); - int read(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle); - int pread(const ObTmpFileIOInfo &io_info, const int64_t offset, ObTmpFileIOHandle &io_handle); - // NOTE: - // only support append write. - int aio_write(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle); - // NOTE: - // only support append write. - int write(const ObTmpFileIOInfo &io_info); - int truncate(const int64_t fd, const int64_t offset); - int seal(const int64_t fd); - -public: - int get_tmp_file(const int64_t fd, ObSNTmpFileHandle &file_handle); - int get_tmp_file_size(const int64_t fd, int64_t &size); - int get_macro_block_list(common::ObIArray ¯o_id_list); - OB_INLINE ObTmpFileBlockManager &get_tmp_file_block_manager() { return tmp_file_block_manager_; } - OB_INLINE ObTmpFilePageCacheController &get_page_cache_controller() { return page_cache_controller_; } - int get_tmp_file_disk_usage(int64_t &disk_data_size, int64_t &occupied_disk_size); - -public: - //for virtual table to show - int get_tmp_file_fds(ObIArray &fd_arr); - int get_tmp_file_info(const int64_t fd, ObTmpFileInfo *tmp_file_info); - -private: - int init_sub_module_(); - int start_sub_module_(); - int stop_sub_module_(); - int wait_sub_module_(); - int destroy_sub_module_(); - -private: - class CollectTmpFileKeyFunctor final - { - public: - CollectTmpFileKeyFunctor(ObIArray &fds) - : fds_(fds) {} - bool operator()(const ObTmpFileKey &key, const ObSNTmpFileHandle &tmp_file_handle); - - private: - ObIArray &fds_; - }; - -private: - bool is_inited_; - bool is_running_; - - common::ObConcurrentFIFOAllocator tmp_file_allocator_; - common::ObFIFOAllocator callback_allocator_; - common::ObFIFOAllocator wbp_index_cache_allocator_; - common::ObFIFOAllocator wbp_index_cache_bucket_allocator_; - TmpFileMap files_; - ObTmpFileBlockManager tmp_file_block_manager_; - ObTmpFilePageCacheController page_cache_controller_; - static int64_t current_fd_; - static int64_t current_dir_id_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_meta_tree.cpp b/src/storage/tmp_file/ob_tmp_file_meta_tree.cpp deleted file mode 100644 index e874482b0b..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_meta_tree.cpp +++ /dev/null @@ -1,3030 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ob_tmp_file_meta_tree.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" - -namespace oceanbase -{ -using namespace storage; -using namespace share; - -namespace tmp_file -{ - -const uint16_t ObSharedNothingTmpFileMetaTree::PAGE_MAGIC_NUM = 0xa12f; -const int16_t ObSharedNothingTmpFileMetaTree::PAGE_HEADER_SIZE = 16; //16B -int16_t ObSharedNothingTmpFileMetaTree::MAX_DATA_ITEM_ARRAY_COUNT = 16; - -//only for unittest -int16_t ObSharedNothingTmpFileMetaTree::MAX_PAGE_ITEM_COUNT = INT16_MAX; - -ObSharedNothingTmpFileMetaTree::ObSharedNothingTmpFileMetaTree() : - is_inited_(false), - fd_(-1), - wbp_(nullptr), - callback_allocator_(nullptr), - block_manager_(nullptr), - tree_epoch_(0), - root_item_(), - data_item_array_(), - level_page_range_array_(), - is_writing_(false), - lock_(common::ObLatchIds::TMP_FILE_LOCK), - last_truncate_leaf_info_(), - released_offset_(0), - stat_info_() -{ - STATIC_ASSERT(sizeof(struct ObSharedNothingTmpFileMetaItem) == 24, "size of tree meta item is mismatch"); - STATIC_ASSERT(sizeof(struct ObSharedNothingTmpFileDataItem) == 24, "size of tree data item is mismatch"); - STATIC_ASSERT(sizeof(struct ObSharedNothingTmpFileTreePageHeader) == 16, "size of tree page header is mismatch"); -} - -ObSharedNothingTmpFileMetaTree::~ObSharedNothingTmpFileMetaTree() -{ - reset(); -} - -void ObSharedNothingTmpFileMetaTree::reset() -{ - is_inited_ = false; - fd_ = -1; - wbp_ = nullptr; - callback_allocator_ = nullptr; - block_manager_ = nullptr; - tree_epoch_ = 0; - root_item_.reset(); - data_item_array_.reset(); - level_page_range_array_.reset(); - is_writing_ = false; - last_truncate_leaf_info_.reset(); - released_offset_ = 0; - stat_info_.reset(); -} - -int ObSharedNothingTmpFileMetaTree::init(const int64_t fd, - ObTmpWriteBufferPool *wbp, - ObIAllocator *callback_allocator, - ObTmpFileBlockManager *block_manager) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(NULL == wbp - || NULL == callback_allocator - || NULL == block_manager)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(fd_), KP(wbp), KP(callback_allocator), KP(block_manager)); - } else { - data_item_array_.set_attr(ObMemAttr("TFDataItemArr")); - level_page_range_array_.set_attr(ObMemAttr("TFTreeLevelArr")); - fd_ = fd; - wbp_ = wbp; - callback_allocator_ = callback_allocator; - block_manager_ = block_manager; - is_inited_ = true; - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::prepare_for_insert_items() -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (!root_item_.is_valid()) { - //do nothing - } else { - ObSharedNothingTmpFileMetaItem page_info; - if (OB_FAIL(get_rightmost_leaf_page_for_write_(page_info))) { - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::get_rightmost_leaf_page_for_write_( - ObSharedNothingTmpFileMetaItem &page_info) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(is_writing_ - || level_page_range_array_.empty())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected is_writing_ or level_array_", KR(ret), K(fd_), K(is_writing_), K(level_page_range_array_)); - } else { - is_writing_ = true; //need to be protected by lock_ - ObSharedNothingTmpFileMetaItem meta_item = root_item_; - uint32_t parent_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObSharedNothingTmpFileMetaItem next_level_meta_item; - while (OB_SUCC(ret) - && 0 < meta_item.page_level_) { - next_level_meta_item.reset(); - if (OB_FAIL(get_last_item_of_internal_page_(parent_page_id, meta_item, next_level_meta_item))) { - } else { - parent_page_id = meta_item.buffer_page_id_; - meta_item = next_level_meta_item; - } - } - if (OB_SUCC(ret)) { - if (OB_UNLIKELY(0 != meta_item.page_level_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_level_", KR(ret), K(meta_item)); - } else if (OB_FAIL(cache_page_for_write_(parent_page_id, meta_item))) { - } else { - page_info = meta_item; - } - } - - //there is no need to remove the successfully loaded rightmost page from the write cache - if (OB_FAIL(ret)) { - is_writing_ = false; - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::get_last_item_of_internal_page_( - const uint32_t parent_page_id, - ObSharedNothingTmpFileMetaItem &page_info, - ObSharedNothingTmpFileMetaItem &last_meta_item) -{ - int ret = OB_SUCCESS; - ObSharedNothingTmpFileTreePageHeader page_header; - if (OB_FAIL(cache_page_for_write_(parent_page_id, page_info))) { - } else { - char* page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t level_page_index = level_page_range_array_[page_info.page_level_].evicted_page_num_ + - level_page_range_array_[page_info.page_level_].cached_page_num_ - 1; - ObTmpFilePageUniqKey page_key(page_info.page_level_, level_page_index); - if (OB_FAIL(wbp_->read_page(fd_, page_info.buffer_page_id_, page_key, page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else if (OB_UNLIKELY(0 >= page_header.item_num_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), K(page_header)); - } else if (OB_FAIL(read_item_(page_buff, page_header.item_num_ - 1, last_meta_item))) { - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::insert_items( - const ObIArray &data_items) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (OB_UNLIKELY(data_items.empty())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(data_items)); - } else if (OB_UNLIKELY(!data_items.at(0).is_valid() || - released_offset_ > data_items.at(0).virtual_page_id_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(data_items.at(0)), KPC(this)); - } else { - int64_t write_count = 0; - const int64_t data_item_count = data_items.count(); - ObSEArray level_origin_page_write_counts; - ObSEArray, 2> level_new_pages; - if (!root_item_.is_valid() && OB_FAIL(try_to_insert_items_to_array_(data_items, level_new_pages))) { - STORAGE_LOG(WARN, "fail to try to insert items to array", KR(ret), K(data_items), KPC(this)); - } else if (root_item_.is_valid()) { - //we set is_writing_ in previous step, - // so, we need not to worry about end pages of each level will be evicted. - if (OB_UNLIKELY(!is_writing_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected is_writing_", KR(ret), KPC(this)); - } else if (OB_FAIL(try_to_fill_rightmost_leaf_page_(data_items, level_new_pages, write_count, - level_origin_page_write_counts))) { - } else if (write_count < data_item_count) { - ObSEArray meta_items; - ObSharedNothingTmpFileMetaItem meta_item; - if (level_page_range_array_.count() <= 1) { - //there is only a root page - if (OB_FAIL(meta_items.push_back(root_item_))) { - } - } - //alloc new leaf pages - while (OB_SUCC(ret) - && write_count < data_item_count) { - meta_item.reset(); - if (OB_FAIL(add_new_page_and_fill_items_at_leaf_(data_items, write_count, meta_item, level_new_pages))) { - } else if (OB_FAIL(meta_items.push_back(meta_item))) { - } - } - //cascade to modify the internal pages - if (FAILEDx(cascade_modification_at_internal_(meta_items, - level_origin_page_write_counts, level_new_pages))) { - } - } - if (FAILEDx(level_page_range_array_.reserve(level_new_pages.count()))) { - STORAGE_LOG(WARN, "fail to reserve for level_page_range_array_", KR(ret), K(fd_), K(level_new_pages.count())); - } - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(finish_insert_(ret, level_origin_page_write_counts, level_new_pages))) { - } - if (OB_SUCC(ret)) { - ret = tmp_ret; - } - is_writing_ = false; - } - } - if (OB_SUCC(ret)) { - ARRAY_FOREACH_N(data_items, i, cnt) { - stat_info_.all_type_page_flush_cnt_ += data_items.at(i).physical_page_num_; - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::try_to_insert_items_to_array_( - const ObIArray &data_items, - ObIArray> &level_new_pages) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(data_items.empty() - || !level_new_pages.empty() - || !level_page_range_array_.empty() - || MAX_DATA_ITEM_ARRAY_COUNT > MAX_PAGE_ITEM_COUNT - || is_writing_)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(data_items), K(level_page_range_array_), - K(level_new_pages), K(MAX_DATA_ITEM_ARRAY_COUNT), K(MAX_PAGE_ITEM_COUNT), K(is_writing_)); - } else if (!data_item_array_.empty()) { - const ObSharedNothingTmpFileDataItem &last_item = data_item_array_.at(data_item_array_.count() - 1); - if (OB_UNLIKELY(data_items.at(0).virtual_page_id_ != last_item.virtual_page_id_ + last_item.physical_page_num_)) { - // This error may occur due to a failure in the previous flush task's insert_item, - // flush mgr will automatically retry to resolve the issue. - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected data_items or data_item_array_", KR(ret), K(fd_), K(data_items), K(last_item)); - } - } - if (OB_SUCC(ret)) { - bool need_build_tree = false; - const int64_t total_count = data_item_array_.count() + data_items.count(); - if (total_count <= MAX_DATA_ITEM_ARRAY_COUNT) { - const int16_t array_capacity = data_item_array_.get_capacity(); - if (array_capacity < total_count) { - if (OB_FAIL(data_item_array_.reserve(MIN(MAX(total_count, 2 * array_capacity), MAX_DATA_ITEM_ARRAY_COUNT)))) { - STORAGE_LOG(WARN, "fail to reserve for data_item_array_", KR(ret), K(fd_), K(total_count), K(array_capacity)); - if (OB_ALLOCATE_MEMORY_FAILED == ret) { - need_build_tree = true; - } - } - } - ARRAY_FOREACH_N(data_items, i, cnt) { - if (OB_UNLIKELY(!data_items.at(i).is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(data_items.at(i))); - } else if (OB_FAIL(data_item_array_.push_back(data_items.at(i)))) { - } - } - } else { - need_build_tree = true; - } - if (true == need_build_tree) { - ret = OB_SUCCESS; - ObTmpFilePageUniqKey leaf_page_offset(0/*tree level*/, 0/*level page index*/); - ObSEArray new_pages; - if (OB_FAIL(new_pages.push_back(ObTmpFileGlobal::INVALID_PAGE_ID))) { - } else if (OB_FAIL(level_new_pages.push_back(new_pages))) { - } else { - uint32_t new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - char *new_page_buff = NULL; - int16_t count = 0; - if (OB_FAIL(wbp_->alloc_page(fd_, leaf_page_offset, new_page_id, new_page_buff))) { - } else if (FALSE_IT(stat_info_.meta_page_alloc_cnt_++)) { - } else if (OB_FAIL(init_page_header_(new_page_buff, 0 /*level*/))) { - } else if (!data_item_array_.empty() && - OB_FAIL(write_items_(new_page_buff, data_item_array_, 0/*begin_index*/, count))) { - STORAGE_LOG(WARN, "fail to write items", KR(ret), K(fd_), K(data_item_array_), KP(new_page_buff)); - } else if (OB_FAIL(wbp_->notify_dirty(fd_, new_page_id, leaf_page_offset))) { - } else { - level_new_pages.at(0).at(0) = new_page_id; - is_writing_ = true; //must be protected by lock - root_item_.page_level_ = 0; - root_item_.buffer_page_id_ = new_page_id; - root_item_.virtual_page_id_ = data_item_array_.empty() ? - data_items.at(0).virtual_page_id_ : data_item_array_.at(0).virtual_page_id_; - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObSharedNothingTmpFileDataItem first_item; - ObSharedNothingTmpFileDataItem last_item; - read_page_simple_content_(new_page_buff, tmp_page_header, first_item, last_item); - STORAGE_LOG(INFO, "dump tree page", KR(ret), K(fd_), K(new_page_id), K(leaf_page_offset), - KP(new_page_buff), K(tmp_page_header), K(first_item), K(last_item)); - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::try_to_fill_rightmost_leaf_page_( - const ObIArray &data_items, - const ObIArray> &level_new_pages, - int64_t &write_count, - ObIArray &level_origin_page_write_counts) -{ - int ret = OB_SUCCESS; - write_count = 0; - if (OB_UNLIKELY(data_items.empty() || !data_items.at(0).is_valid() - || (level_new_pages.empty() && level_page_range_array_.empty()) - || !level_origin_page_write_counts.empty())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(data_items), K(level_new_pages), - K(level_page_range_array_), K(level_origin_page_write_counts)); - } else { - const int16_t MAX_PAGE_DATA_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(data_items.at(0))); - uint32_t page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t level_page_index = -1; - int16_t count = 0; - ObSharedNothingTmpFileTreePageHeader page_header; - char *leaf_page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (!level_new_pages.empty()) { - page_id = level_new_pages.at(0/*level*/).at(0); - level_page_index = 0; - } else { - page_id = level_page_range_array_.at(0/*level*/).end_page_id_; - level_page_index = level_page_range_array_.at(0).evicted_page_num_ + level_page_range_array_.at(0).cached_page_num_ - 1; - } - ObTmpFilePageUniqKey leaf_page_offset(0, level_page_index); - if (OB_FAIL(wbp_->read_page(fd_, page_id, leaf_page_offset, leaf_page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(leaf_page_buff, page_header))) { - } else if (0 == page_header.item_num_) { - //maybe the item have been cleared (corresponds to an unfilled data page) - //or maybe this is a newly allocated meta page - //so "0 == item_num" - //but we do not need to rewrite page info (change virtual_page_id) - STORAGE_LOG(INFO, "item_num is 0", KR(ret), K(fd_), KP(leaf_page_buff), K(page_id)); - } else { - //check last data item - ObSharedNothingTmpFileDataItem origin_last_item; - if (OB_FAIL(read_item_(leaf_page_buff, page_header.item_num_ - 1, origin_last_item))) { - } else if (OB_UNLIKELY(data_items.at(0).virtual_page_id_ != origin_last_item.virtual_page_id_ + origin_last_item.physical_page_num_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data_items or origin_last_item", KR(ret), K(fd_), K(data_items), K(origin_last_item)); - } - } - if (OB_SUCC(ret)) { - if (!level_page_range_array_.empty() && OB_FAIL(level_origin_page_write_counts.push_back(count))) { - STORAGE_LOG(WARN, "fail to push back", KR(ret), K(fd_), K(count)); - } else if (page_header.item_num_ < MAX_PAGE_DATA_ITEM_NUM) { - if (OB_FAIL(write_items_(leaf_page_buff, data_items, 0, count))) { - } else if (OB_FAIL(wbp_->notify_dirty(fd_, page_id, leaf_page_offset))) { - } else { - write_count += count; - if (!level_page_range_array_.empty()) { - level_origin_page_write_counts.at(0) = count; - } - } - if (OB_SUCC(ret)) { - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObSharedNothingTmpFileDataItem first_item; - ObSharedNothingTmpFileDataItem last_item; - read_page_simple_content_(leaf_page_buff, tmp_page_header, first_item, last_item); - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::add_new_page_and_fill_items_at_leaf_( - const ObIArray &data_items, - int64_t &write_count, - ObSharedNothingTmpFileMetaItem &meta_item, - ObIArray> &level_new_pages) -{ - int ret = OB_SUCCESS; - meta_item.reset(); - uint32_t new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - char *new_page_buff = NULL; - int16_t count = 0; - int32_t level_page_index = 0; - if (!level_page_range_array_.empty()) { - level_page_index += (level_page_range_array_.at(0).evicted_page_num_ + - level_page_range_array_.at(0).cached_page_num_); - } - if (!level_new_pages.empty()) { - level_page_index += level_new_pages.at(0).count(); - } - ObTmpFilePageUniqKey leaf_page_offset(0, level_page_index); - if (OB_UNLIKELY(!level_new_pages.empty() && 1 != level_new_pages.count())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(level_new_pages)); - } else if (OB_UNLIKELY(data_items.count() <= write_count || !data_items.at(write_count).is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(data_items), K(write_count)); - } else if (level_new_pages.empty()) { - ObSEArray new_pages; - if (OB_FAIL(level_new_pages.push_back(new_pages))) { - } - } - if (FAILEDx(level_new_pages.at(0).push_back(ObTmpFileGlobal::INVALID_PAGE_ID))) { - } else if (OB_FAIL(wbp_->alloc_page(fd_, leaf_page_offset, new_page_id, new_page_buff))) { - } else if (FALSE_IT(stat_info_.meta_page_alloc_cnt_++)) { - } else if (OB_FAIL(init_page_header_(new_page_buff, 0 /*level*/))) { - } else if (OB_FAIL(write_items_(new_page_buff, data_items, write_count/*begin_index*/, count))) { - } else if (OB_FAIL(wbp_->notify_dirty(fd_, new_page_id, leaf_page_offset))) { - } else { - meta_item.page_level_ = 0; - meta_item.buffer_page_id_ = new_page_id; - meta_item.virtual_page_id_ = data_items.at(write_count).virtual_page_id_; - write_count += count; - level_new_pages.at(0).at(level_new_pages.at(0).count() - 1) = new_page_id; - } - if (OB_SUCC(ret)) { - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObSharedNothingTmpFileDataItem first_item; - ObSharedNothingTmpFileDataItem last_item; - read_page_simple_content_(new_page_buff, tmp_page_header, first_item, last_item); - STORAGE_LOG(INFO, "dump tree page", KR(ret), K(fd_), K(new_page_id), K(leaf_page_offset), - KP(new_page_buff), K(tmp_page_header), K(first_item), K(last_item)); - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::cascade_modification_at_internal_( - const ObIArray &new_leaf_page_infos, - ObIArray &level_origin_page_write_counts, - ObIArray> &level_new_pages) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(new_leaf_page_infos.empty() - || level_new_pages.empty())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(new_leaf_page_infos), K(level_new_pages)); - } else { - ObSEArray prev_meta_items; - ObSEArray meta_items; - ObSharedNothingTmpFileMetaItem meta_item; - const int16_t origin_level_count = level_page_range_array_.count(); - int16_t cur_level = 1; - while (OB_SUCC(ret)) { - int64_t write_count = 0; - prev_meta_items.reset(); - if (cur_level > origin_level_count && meta_items.count() == 1) { - //we need to change root_item_ - break; - } else if (cur_level == 1 && OB_FAIL(prev_meta_items.assign(new_leaf_page_infos))) { - STORAGE_LOG(WARN, "fail to assign", KR(ret), K(fd_), K(new_leaf_page_infos)); - } else if (cur_level > 1 && OB_FAIL(prev_meta_items.assign(meta_items))) { - STORAGE_LOG(WARN, "fail to assign", KR(ret), K(fd_), K(meta_items)); - } else if (cur_level < origin_level_count && - OB_FAIL(try_to_fill_rightmost_internal_page_(prev_meta_items, cur_level, write_count, - level_origin_page_write_counts))) { - STORAGE_LOG(WARN, "fail to try to fill rightmost internal page", KR(ret), K(fd_), K(prev_meta_items), - K(cur_level), K(level_origin_page_write_counts)); - } else { - int64_t meta_item_count = prev_meta_items.count(); - if (write_count < meta_item_count) { - meta_items.reset(); - if (origin_level_count - 1 == cur_level) { - if (OB_FAIL(meta_items.push_back(root_item_))) { - } - } - while (OB_SUCC(ret) && write_count < meta_item_count) { - meta_item.reset(); - if (OB_FAIL(add_new_page_and_fill_items_at_internal_(prev_meta_items, cur_level, write_count, - meta_item, level_new_pages))) { - } else if (OB_FAIL(meta_items.push_back(meta_item))) { - } - } - } else { - //cur level does not alloc new pages - break; - } - } - cur_level++; - } - if (OB_SUCC(ret)) { - if (OB_UNLIKELY(origin_level_count == level_new_pages.count())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_new_pages", KR(ret), K(fd_), K(level_new_pages), K(origin_level_count)); - } else if (origin_level_count < level_new_pages.count()) { - if (OB_UNLIKELY(1 != meta_items.count() - || 1 != level_new_pages.at(level_new_pages.count() - 1).count())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected meta_items or level_new_pages", KR(ret), K(fd_), K(meta_items), - K(level_new_pages), K(origin_level_count)); - } else { - root_item_ = meta_items.at(0); - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::try_to_fill_rightmost_internal_page_( - const ObIArray &meta_items, - const int16_t page_level, - int64_t &write_count, - ObIArray &level_origin_page_write_counts) -{ - int ret = OB_SUCCESS; - write_count = 0; - //only a writing thread, array count will not change - if (OB_UNLIKELY(meta_items.empty() - || page_level < 1 - || page_level >= level_page_range_array_.count() - || page_level != level_origin_page_write_counts.count())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(meta_items), K(page_level), K(level_page_range_array_), - K(level_origin_page_write_counts)); - } else { - const int16_t MAX_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(meta_items.at(0))); - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - char *internal_page_buff = NULL; - ObSharedNothingTmpFileTreePageHeader page_header; - int16_t count = 0; - uint32_t page_id = level_page_range_array_[page_level].end_page_id_; - int32_t level_page_index = level_page_range_array_[page_level].evicted_page_num_ + - level_page_range_array_[page_level].cached_page_num_ - 1; - ObTmpFilePageUniqKey internal_page_offset(page_level, level_page_index); - //only a writing thread. - if (OB_FAIL(wbp_->read_page(fd_, page_id, internal_page_offset, internal_page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(internal_page_buff, page_header))) { - } else if (OB_FAIL(level_origin_page_write_counts.push_back(count))) { - } else if (page_header.item_num_ < MAX_PAGE_META_ITEM_NUM) { - if (page_header.item_num_ <= 0) { - //the rightmost page in internal level must has items - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), K(fd_), K(page_header)); - } else if (OB_FAIL(write_items_(internal_page_buff, meta_items, 0, count))) { - } else if (OB_FAIL(wbp_->notify_dirty(fd_, page_id, internal_page_offset))) { - } else { - write_count += count; - level_origin_page_write_counts.at(page_level) = count; - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObSharedNothingTmpFileMetaItem first_item; - ObSharedNothingTmpFileMetaItem last_item; - read_page_simple_content_(internal_page_buff, tmp_page_header, first_item, last_item); - STORAGE_LOG(INFO, "dump tree page", KR(ret), K(fd_), K(page_id), K(internal_page_offset), - KP(internal_page_buff), K(tmp_page_header), K(first_item), K(last_item)); - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::add_new_page_and_fill_items_at_internal_( - const ObIArray &meta_items, - const int16_t page_level, - int64_t &write_count, - ObSharedNothingTmpFileMetaItem &meta_item, - ObIArray> &level_new_pages) -{ - int ret = OB_SUCCESS; - uint32_t new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - char *new_page_buff = NULL; - int16_t count = 0; - int32_t level_page_index = 0; - if (page_level < level_page_range_array_.count()) { - level_page_index += (level_page_range_array_.at(page_level).evicted_page_num_ + - level_page_range_array_.at(page_level).cached_page_num_); - } - if (page_level < level_new_pages.count()) { - level_page_index += level_new_pages.at(page_level).count(); - } - ObTmpFilePageUniqKey internal_page_offset(page_level, level_page_index); - if (OB_UNLIKELY(meta_items.count() <= write_count || !meta_items.at(write_count).is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(meta_items), K(write_count)); - } else if (OB_UNLIKELY(level_new_pages.count() != page_level - && level_new_pages.count() != page_level + 1)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_new_pages", KR(ret), K(fd_), K(page_level), K(level_new_pages)); - } else if (level_new_pages.count() == page_level) { - ObSEArray new_pages; - if (OB_FAIL(level_new_pages.push_back(new_pages))) { - } - } - if (FAILEDx(level_new_pages.at(page_level).push_back(ObTmpFileGlobal::INVALID_PAGE_ID))) { - } else if (OB_FAIL(wbp_->alloc_page(fd_, internal_page_offset, new_page_id, new_page_buff))) { - } else if (FALSE_IT(stat_info_.meta_page_alloc_cnt_++)) { - } else if (OB_FAIL(init_page_header_(new_page_buff, page_level))) { - } else if (OB_FAIL(write_items_(new_page_buff, meta_items, write_count/*begin_index*/, count))) { - } else if (OB_FAIL(wbp_->notify_dirty(fd_, new_page_id, internal_page_offset))) { - } else { - meta_item.page_level_ = page_level; - meta_item.buffer_page_id_ = new_page_id; - meta_item.virtual_page_id_ = meta_items.at(write_count).virtual_page_id_; - write_count += count; - level_new_pages.at(page_level).at(level_new_pages.at(page_level).count() - 1) = new_page_id; - } - if (OB_SUCC(ret)) { - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObSharedNothingTmpFileMetaItem first_item; - ObSharedNothingTmpFileMetaItem last_item; - read_page_simple_content_(new_page_buff, tmp_page_header, first_item, last_item); - STORAGE_LOG(INFO, "dump tree page", KR(ret), K(fd_), K(new_page_id), K(internal_page_offset), - KP(new_page_buff), K(tmp_page_header), K(first_item), K(last_item)); - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::finish_insert_( - const int return_ret, - ObIArray &level_origin_page_write_counts, - ObIArray> &level_new_pages) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(level_origin_page_write_counts.count() > level_page_range_array_.count())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected new record level page infos", KR(ret), K(fd_), - K(level_origin_page_write_counts), K(level_page_range_array_)); - } else if (OB_SUCCESS == return_ret) { - ARRAY_FOREACH_N(level_new_pages, level, level_cnt) { - ARRAY_FOREACH_N(level_new_pages.at(level), i, new_page_cnt) { - const uint32_t new_page_id = level_new_pages.at(level).at(i); - if (0 == i && level_page_range_array_.count() <= level) { - if (OB_FAIL(level_page_range_array_.push_back( - LevelPageRangeInfo(new_page_id, ObTmpFileGlobal::INVALID_PAGE_ID, new_page_id, 1, 0, 0)))) { - } - } else if (OB_UNLIKELY(level_page_range_array_.count() <= level)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_page_range_array_", KR(ret), K(fd_), K(level_page_range_array_), K(level)); - } else { - uint32_t end_page_id_in_array = level_page_range_array_[level].end_page_id_; - int32_t level_prev_page_index = level_page_range_array_[level].evicted_page_num_ + - level_page_range_array_[level].cached_page_num_ - 1; - if (ObTmpFileGlobal::INVALID_PAGE_ID != end_page_id_in_array - && OB_FAIL(wbp_->link_page(fd_, new_page_id, end_page_id_in_array, - ObTmpFilePageUniqKey(level, level_prev_page_index)))) { - STORAGE_LOG(ERROR, "fail to link page in write cache", KR(ret), K(fd_), K(level_page_range_array_), - K(new_page_id), K(level)); - } else { - if (ObTmpFileGlobal::INVALID_PAGE_ID == end_page_id_in_array) { - level_page_range_array_[level].start_page_id_ = new_page_id; - } - level_page_range_array_[level].end_page_id_ = new_page_id; - level_page_range_array_[level].cached_page_num_++; - } - } - } - } - if (OB_SUCC(ret) && !data_item_array_.empty()) { - data_item_array_.reset(); - } - } else { //fail - //rollback - ARRAY_FOREACH_N(level_origin_page_write_counts, i, cnt) { - const int16_t remove_cnt = level_origin_page_write_counts.at(i); - if (0 != remove_cnt) { - char *page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t end_page_id = level_page_range_array_[i].end_page_id_; - int32_t level_page_index = level_page_range_array_[i].evicted_page_num_ + - level_page_range_array_[i].cached_page_num_ - 1; - ObTmpFilePageUniqKey page_key(i, level_page_index); - if (OB_FAIL(wbp_->read_page(fd_, end_page_id, page_key, page_buff, next_page_id))) { - } else if (OB_FAIL(remove_page_item_from_tail_(page_buff, remove_cnt))) { - } - } - } - ARRAY_FOREACH_N(level_new_pages, level, level_cnt) { - int32_t level_page_index = 0; - if (level_page_range_array_.count() > level) { - level_page_index += (level_page_range_array_[level].evicted_page_num_ + - level_page_range_array_[level].cached_page_num_); - } - ARRAY_FOREACH_N(level_new_pages.at(level), i, new_page_cnt) { - const uint32_t new_page_id = level_new_pages.at(level).at(i); - if (ObTmpFileGlobal::INVALID_PAGE_ID != new_page_id) { - uint32_t unused_next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageUniqKey page_key(level, level_page_index + i); - if (OB_FAIL(wbp_->free_page(fd_, new_page_id, page_key, unused_next_page_id))) { - } else { - stat_info_.meta_page_free_cnt_++; - } - } - } - } - if (OB_SUCC(ret)) { - if (level_page_range_array_.empty()) { - if (OB_UNLIKELY(stat_info_.meta_page_alloc_cnt_ != stat_info_.meta_page_free_cnt_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected stat_info_", KR(ret), K(fd_), K(return_ret), K(stat_info_)); - } else { - root_item_.reset(); - } - } - } - STORAGE_LOG(INFO, "fail to insert, finish rollback to before", KR(ret), K(return_ret), KPC(this)); - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::search_data_items( - const int64_t start_offset, - const int64_t read_size, - ObIArray &data_items) -{ - int ret = OB_SUCCESS; - data_items.reset(); - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - const int64_t end_offset = start_offset + read_size; - int64_t offset = start_offset; - SpinRLockGuard guard(lock_); - if (OB_UNLIKELY(start_offset < released_offset_ - || read_size <= 0)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(start_offset), K(read_size), KPC(this)); - } else if (!root_item_.is_valid()) { - //read from data_item_array_ - if (OB_FAIL(search_data_items_from_array_(end_offset, offset, data_items))) { - } - } else { - const int64_t target_virtual_page_id = start_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - ObSharedNothingTmpFileMetaItem meta_item = root_item_; - ObSharedNothingTmpFileMetaItem next_level_meta_item; - //read from meta tree - //root page index must be 0 - int32_t level_page_index = 0; - //we use a array to simulate a stack - ObSEArray search_path; - while (OB_SUCC(ret) - && 0 < meta_item.page_level_) { - next_level_meta_item.reset(); - int16_t item_index = -1; - ObSharedNothingTmpFileTreePageHeader page_header; - char *page_buff = NULL; - ObTmpPageValueHandle p_handle; - if (OB_FAIL(get_page_(meta_item, level_page_index, page_buff, p_handle))) { - } else if (OB_FAIL(read_item_(page_buff, target_virtual_page_id, item_index, next_level_meta_item))) { - } else if (OB_FAIL(search_path.push_back(BacktraceNode(meta_item /*page info*/, - level_page_index, /*page index in level*/ - item_index /*item index on the page*/)))) { - } else { - meta_item = next_level_meta_item; - level_page_index = level_page_index * FULL_PAGE_META_ITEM_NUM + item_index; - } - p_handle.reset(); - } - if (OB_SUCC(ret)) { - if (0 == meta_item.page_level_) { - if (OB_FAIL(get_items_of_leaf_page_(meta_item, level_page_index, end_offset, - true /*need read from specified item index*/, offset, data_items))) { - } else if (offset < end_offset - && OB_FAIL(backtrace_search_data_items_(end_offset, offset, search_path, data_items))) { - STORAGE_LOG(WARN, "fail to backtrace search data items", KR(ret), - K(end_offset), K(offset), K(search_path), KPC(this)); - } - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page type", KR(ret), K(meta_item), KPC(this)); - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::search_data_items_from_array_( - const int64_t end_offset, - int64_t &cur_offset, - common::ObIArray &data_items) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(cur_offset < 0 - || cur_offset >= end_offset - || data_item_array_.empty() - || data_item_array_.count() > MAX_DATA_ITEM_ARRAY_COUNT)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(cur_offset), K(end_offset), K(data_item_array_)); - } else { - const int64_t target_virtual_page_id = cur_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - int16_t index = -1; - ARRAY_FOREACH_N(data_item_array_, i, cnt) { - const ObSharedNothingTmpFileDataItem &data_item = data_item_array_.at(i); - if (OB_UNLIKELY(!data_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data_item", KR(ret), K(fd_), K(i), K(data_item)); - } else if (data_item.virtual_page_id_ <= target_virtual_page_id) { - index = i; - } else { - break; - } - } - if (OB_UNLIKELY(0 > index)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected index", KR(ret), K(fd_), K(index), K(cur_offset), K(data_item_array_)); - } else { - for (int16_t i = index; OB_SUCC(ret) && i < data_item_array_.count() && cur_offset < end_offset; i++) { - const ObSharedNothingTmpFileDataItem &data_item = data_item_array_.at(i); - if (OB_UNLIKELY(i > index && cur_offset != data_item.virtual_page_id_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected virtual_page_id", KR(ret), K(fd_), K(cur_offset), K(i), K(index), K(data_item)); - } else if (OB_FAIL(data_items.push_back(data_item))) { - } else { - cur_offset = (data_item.virtual_page_id_ + data_item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - } - } - if (OB_SUCC(ret) && cur_offset < end_offset) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected offset", KR(ret), K(fd_), K(cur_offset), K(end_offset)); - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::get_items_of_leaf_page_( - const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - const int64_t end_offset, - const bool need_find_index, - int64_t &cur_offset, - common::ObIArray &data_items) -{ - int ret = OB_SUCCESS; - char *page_buff = NULL; - int16_t item_index = -1; - int64_t tmp_offset = -1; - const int64_t target_virtual_page_id = cur_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - ObSharedNothingTmpFileDataItem data_item; - ObSharedNothingTmpFileTreePageHeader page_header; - ObTmpPageValueHandle p_handle; - if (OB_FAIL(get_page_(page_info, level_page_index, page_buff, p_handle))) { - } else if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else { - if (!need_find_index) { - if (OB_UNLIKELY(0 != cur_offset % ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected cur_offset", KR(ret), K(fd_), K(cur_offset)); - } else { - //read from beginning of the page - item_index = 0; - } - } else { - //get the specified item_index based on target_virtual_page_id - if (OB_FAIL(read_item_(page_buff, target_virtual_page_id, item_index, data_item))) { - } else if (FALSE_IT(tmp_offset = (data_item.virtual_page_id_ + data_item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - } else if (cur_offset >= tmp_offset) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected offset", KR(ret), K(fd_), K(cur_offset), K(tmp_offset), K(data_item)); - } else if (OB_FAIL(data_items.push_back(data_item))) { - } else { - cur_offset = tmp_offset; - item_index++; - } - } - if (OB_SUCC(ret)) { - while (OB_SUCC(ret) - && cur_offset < end_offset - && item_index < page_header.item_num_) { - data_item.reset(); - if (OB_FAIL(read_item_(page_buff, item_index, data_item))) { - } else if (OB_UNLIKELY(cur_offset != data_item.virtual_page_id_ * ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - //print page content - //NOTE: control print frequence - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObArray items; - read_page_content_(page_buff, tmp_page_header, items); - STORAGE_LOG(ERROR, "unexpected virtual_page_id, dump tree page", KR(ret), K(fd_), KP(page_buff), K(cur_offset), - K(item_index), K(data_item), K(target_virtual_page_id), K(tmp_page_header), K(items)); - } else if (OB_FAIL(data_items.push_back(data_item))) { - } else { - cur_offset = (data_item.virtual_page_id_ + data_item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - item_index++; - } - } - } - if (OB_FAIL(ret)) { - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObSharedNothingTmpFileDataItem first_item; - ObSharedNothingTmpFileDataItem last_item; - read_page_simple_content_(page_buff, page_header, first_item, last_item); - STORAGE_LOG(WARN, "dump tree page", KR(ret), K(fd_), K(page_info), K(level_page_index), - KP(page_buff), K(tmp_page_header), K(first_item), K(last_item)); - } - } - p_handle.reset(); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::backtrace_search_data_items_( - const int64_t end_offset, - int64_t &offset, - ObIArray &search_path, - ObIArray &data_items) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(search_path.empty() - || 1 != search_path.at(search_path.count() - 1).page_meta_info_.page_level_ - || data_items.empty() - || offset >= end_offset)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(search_path), K(data_items), - K(end_offset), K(offset)); - } else { - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - ObSEArray meta_items; - while (OB_SUCC(ret) - && !search_path.empty() - && offset < end_offset) { - meta_items.reset(); - bool reach_last_item = false; - int64_t last_node_index = search_path.count() - 1; - //meta_item points to a page - const ObSharedNothingTmpFileMetaItem &page_info = search_path.at(last_node_index).page_meta_info_; - //the page index in its level - const int32_t level_page_index = search_path.at(last_node_index).level_page_index_; - //current pos need to be processed on this page. - int16_t cur_item_index = search_path.at(last_node_index).prev_item_index_ + 1; - if (OB_FAIL(get_items_of_internal_page_(page_info, level_page_index, cur_item_index, - end_offset, reach_last_item, meta_items))) { - } else if (1 == page_info.page_level_) { - //process level_0 - int64_t i = 0; - const int64_t cnt = meta_items.count(); - const int32_t start_leaf_level_page_index = level_page_index * FULL_PAGE_META_ITEM_NUM + cur_item_index; - for (; OB_SUCC(ret) && i < cnt && offset < end_offset; i++) { - const ObSharedNothingTmpFileMetaItem &leaf_page_info = meta_items.at(i); - bool need_lock = ((i + 1 == cnt) && reach_last_item); - if (OB_FAIL(get_items_of_leaf_page_(leaf_page_info, start_leaf_level_page_index + i, end_offset, - false /*need read from specified item index*/, offset, data_items))) { - } - } - if (OB_SUCC(ret)) { - if (OB_UNLIKELY(cnt != i || (!reach_last_item && offset < end_offset))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected meta_items", KR(ret), K(fd_), K(meta_items), K(i), - K(reach_last_item), K(offset), K(end_offset)); - } else { - search_path.pop_back(); - } - } - } else if (page_info.page_level_ > 1) { - if (meta_items.count() == 1) { - const int32_t child_level_page_index = level_page_index * FULL_PAGE_META_ITEM_NUM + cur_item_index; - search_path.at(last_node_index).prev_item_index_ = cur_item_index; - if (OB_FAIL(search_path.push_back(BacktraceNode(meta_items.at(0), child_level_page_index, -1)))) { - } - } else if (meta_items.empty()) { - search_path.pop_back(); - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected meta_items", KR(ret), K(fd_), K(meta_items)); - } - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page info", KR(ret), K(fd_), K(page_info)); - } - } - if (OB_SUCC(ret) && end_offset > offset) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected offset", KR(ret), K(fd_), K(end_offset), K(offset)); - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::get_items_of_internal_page_( - const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - const int16_t item_index, - const int64_t end_offset, - bool &reach_last_item, - ObIArray &meta_items) -{ - int ret = OB_SUCCESS; - reach_last_item = false; - meta_items.reset(); - int16_t cur_item_index = item_index; - ObSharedNothingTmpFileTreePageHeader page_header; - ObSharedNothingTmpFileMetaItem meta_item; - char *page_buff = NULL; - ObTmpPageValueHandle p_handle; - //when truncate, the page must in read/write cache(because we already hold a p_handle about this page if in read cache) - if (OB_FAIL(get_page_(page_info, level_page_index, page_buff, p_handle))) { - } else if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else if (OB_UNLIKELY(0 >= page_header.item_num_ - || item_index > page_header.item_num_ - || item_index < 0)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_header", KR(ret), K(fd_), K(page_header), K(item_index)); - } else { - int64_t end_virtual_page_id = upper_align(end_offset, ObTmpFileGlobal::ALLOC_PAGE_SIZE) / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - while (OB_SUCC(ret) - && cur_item_index < page_header.item_num_) { - meta_item.reset(); - if (OB_FAIL(read_item_(page_buff, cur_item_index, meta_item))) { - } else if (meta_item.virtual_page_id_ >= end_virtual_page_id) { - break; - } else if (OB_FAIL(meta_items.push_back(meta_item))) { - } else if (FALSE_IT(cur_item_index++)) { - } else if (1 != page_info.page_level_) { - break; - } - } - } - p_handle.reset(); - if (OB_SUCC(ret) && cur_item_index == page_header.item_num_) { - reach_last_item = true; - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::flush_meta_pages_for_block( - const int64_t block_index, - const ObTmpFileTreeEvictType flush_type, - char *block_buff, - int64_t &write_offset, - ObTmpFileTreeFlushContext &flush_context, - ObIArray &tree_io_array) -{ - int ret = OB_SUCCESS; - tree_io_array.reset(); - SpinWLockGuard guard(lock_); - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX == block_index - || ObTmpFileTreeEvictType::INVALID == flush_type - || NULL == block_buff - || 0 != write_offset % ObTmpFileGlobal::ALLOC_PAGE_SIZE - || level_page_range_array_.count() >= INT16_MAX)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(block_index), K(flush_type), - KP(block_buff), K(write_offset), KPC(this)); - } else if (!root_item_.is_valid()) { - if (!level_page_range_array_.empty()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_page_range_array_", KR(ret), KPC(this)); - } else { - flush_context.is_meta_reach_end_ = true; - } - } else { - int16_t level = 0; - bool need_use_context = false; - bool need_flush = true; - const int16_t level_cnt = level_page_range_array_.count(); - ObTmpFileTreeIOInfo tree_io_info; - if (flush_context.is_valid()) { - if (flush_context.tree_epoch_ != tree_epoch_) { - STORAGE_LOG(INFO, "the tree_epoch_ in flush context is not equal to current tree_epoch_", - K(fd_), K(flush_context), K(tree_epoch_)); - need_flush = false; - flush_context.is_meta_reach_end_ = true; - } else { - //flush context means: in this round of flushing, - // the meta tree has already flushed some pages in previous blocks, - // so we need "flush context" to avoid repeated flushing. - level = flush_context.last_flush_level_; - need_use_context = true; - if (last_truncate_leaf_info_.is_valid()) { - if (OB_UNLIKELY(level_cnt <= level)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_index_arr", KR(ret), K(level), KPC(this)); - } else if (flush_context.last_flush_page_index_in_level_ < level_page_range_array_.at(level).evicted_page_num_) { - need_flush = false; - flush_context.is_meta_reach_end_ = true; - } - } - } - } - if (OB_SUCC(ret) && need_flush) { - if (OB_FAIL(tree_io_array.reserve(level_cnt))) { - } - while (OB_SUCC(ret) - && level < level_cnt - && write_offset < ObTmpFileGlobal::SN_BLOCK_SIZE) - { - uint32_t flush_start_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t level_page_index = -1; - if (need_use_context) { - level_page_index = flush_context.last_flush_page_index_in_level_; - ObTmpFilePageUniqKey page_key(level, level_page_index); - if (wbp_->is_dirty(fd_, flush_context.last_flush_page_id_, page_key)) { - //do nothing, we just skip this level. - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, flush_context.last_flush_page_id_, - page_key, flush_start_page_id))) { - } else { - level_page_index++; - } - //only used the first time - need_use_context = false; - } else { - uint32_t flushed_page_id = level_page_range_array_[level].flushed_end_page_id_; - level_page_index = level_page_range_array_[level].flushed_page_num_; - if (ObTmpFileGlobal::INVALID_PAGE_ID == flushed_page_id) { - flush_start_page_id = level_page_range_array_[level].start_page_id_; - } else { - level_page_index--; - ObTmpFilePageUniqKey page_key(level, level_page_index); - if (wbp_->is_dirty(fd_, flushed_page_id, page_key)) { - //flushed page -> write cache - //we only write rightmost page, so pages before flushed_end_page_id_ can not be dirty. - flush_start_page_id = flushed_page_id; - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, flushed_page_id, page_key, flush_start_page_id))) { - } else { - level_page_index++; - } - } - } - if (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID != flush_start_page_id) { - tree_io_info.reset(); - tree_io_info.tree_epoch_ = tree_epoch_; - tree_io_info.block_index_ = block_index; - if (0 == level && OB_FAIL(flush_leaf_pages_(flush_start_page_id, level_page_index, flush_type, - block_buff, write_offset, tree_io_info))) { - STORAGE_LOG(WARN, "fail to flush leaf pages", KR(ret), K(flush_start_page_id), - K(level_page_index), K(flush_type), KP(block_buff), K(write_offset), KPC(this)); - } else if (0 < level && OB_FAIL(flush_internal_pages_(flush_start_page_id, level, level_page_index, - flush_type, block_buff, write_offset, tree_io_info))) { - STORAGE_LOG(WARN, "fail to flush internal pages", KR(ret), K(flush_start_page_id), - K(level), K(level_page_index), K(flush_type), KP(block_buff), K(write_offset), KPC(this)); - } else if (0 == tree_io_info.flush_nums_) { - //do nothing - STORAGE_LOG(INFO, "no meta page flush in this level", KR(ret), K(fd_), K(level), K(level_page_range_array_)); - } else if (OB_UNLIKELY(!tree_io_info.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected tree_io_info", KR(ret), K(tree_io_info), KPC(this)); - //set the page flush information on the parent node, so that we can flush parent pages in advance. - } else if (OB_FAIL(modify_meta_items_at_parent_level_(tree_io_info, level_page_index))) { - } else if (OB_FAIL(tree_io_array.push_back(tree_io_info))) { - } else { - flush_context.tree_epoch_ = tree_epoch_; - flush_context.last_flush_level_ = level; - flush_context.last_flush_page_id_ = tree_io_info.flush_end_page_id_; - flush_context.last_flush_page_index_in_level_ = level_page_index + tree_io_info.flush_nums_ - 1; - stat_info_.meta_page_flushing_cnt_ += tree_io_info.flush_nums_; - stat_info_.all_type_page_flush_cnt_ += tree_io_info.flush_nums_; - } - } - if (OB_SUCC(ret) && level_cnt == level + 1) { - flush_context.is_meta_reach_end_ = true; - } - level++; - } - } - } - STORAGE_LOG(INFO, "finish flush meta pages for block", KR(ret), K(fd_), K(tree_io_array)); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::flush_leaf_pages_( - const uint32_t flush_start_page_id, - const int32_t start_page_index_in_level, - const ObTmpFileTreeEvictType flush_type, - char *block_buff, - int64_t &write_offset, - ObTmpFileTreeIOInfo &tree_io_info) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == flush_start_page_id - || 0 > start_page_index_in_level - || 0 != write_offset % ObTmpFileGlobal::ALLOC_PAGE_SIZE - || level_page_range_array_.empty())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(flush_start_page_id), K(start_page_index_in_level), - K(write_offset), K(level_page_range_array_)); - } else { - tree_io_info.physical_start_page_id_ = write_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - tree_io_info.page_level_ = 0; - uint32_t cur_page_id = flush_start_page_id; - const uint32_t end_page_id = level_page_range_array_[0].end_page_id_; - int32_t page_index_in_level = start_page_index_in_level; - while (OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id - && write_offset + ObTmpFileGlobal::ALLOC_PAGE_SIZE <= ObTmpFileGlobal::SN_BLOCK_SIZE - && (ObTmpFileTreeEvictType::FULL == flush_type || end_page_id != cur_page_id)) { - char *page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageUniqKey page_key(0, page_index_in_level); - if (OB_UNLIKELY(!wbp_->is_dirty(fd_, cur_page_id, page_key))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page state", KR(ret), K(fd_), K(cur_page_id)); - } else if (OB_FAIL(wbp_->read_page(fd_, cur_page_id, page_key, page_buff, next_page_id))) { - } else if (OB_FAIL(wbp_->notify_write_back(fd_, cur_page_id, page_key))) { - } else { - ObTmpPageCacheKey cache_key(tree_io_info.block_index_, - write_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE); - ObTmpPageCacheValue cache_value(page_buff); - MEMCPY(block_buff + write_offset, page_buff, ObTmpFileGlobal::ALLOC_PAGE_SIZE); - if (OB_FAIL(calc_and_set_page_checksum_(block_buff + write_offset))) { - } else { - ObTmpPageCacheValue cache_value(block_buff + write_offset); - ObTmpPageCache::get_instance().try_put_page_to_cache(cache_key, cache_value); - write_offset += ObTmpFileGlobal::ALLOC_PAGE_SIZE; - if (flush_start_page_id == cur_page_id) { - tree_io_info.flush_start_page_id_ = cur_page_id; - tree_io_info.flush_start_level_page_index_ = page_index_in_level; - } - tree_io_info.flush_end_page_id_ = cur_page_id; - tree_io_info.flush_nums_++; - cur_page_id = next_page_id; - page_index_in_level++; - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::calc_and_set_page_checksum_(char* page_buff) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - ObSharedNothingTmpFileTreePageHeader page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - page_header.checksum_ = ob_crc64(page_buff + PAGE_HEADER_SIZE, ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE); - MEMCPY(page_buff, &page_header, PAGE_HEADER_SIZE); - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::flush_internal_pages_( - const uint32_t flush_start_page_id, - const int16_t level, - const int32_t start_page_index_in_level, - const ObTmpFileTreeEvictType flush_type, - char *block_buff, - int64_t &write_offset, - ObTmpFileTreeIOInfo &tree_io_info) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == flush_start_page_id - || level >= level_page_range_array_.count() - || level < 1 - || 0 > start_page_index_in_level - || ObTmpFileTreeEvictType::INVALID == flush_type - || NULL == block_buff - || 0 != write_offset % ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(flush_start_page_id), K(level), K(start_page_index_in_level), - K(flush_type), KP(block_buff), K(level_page_range_array_), K(write_offset)); - } else { - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - tree_io_info.physical_start_page_id_ = write_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - tree_io_info.page_level_ = level; - uint32_t cur_page_id = flush_start_page_id; - const uint32_t end_page_id = level_page_range_array_[level].end_page_id_; - ObSharedNothingTmpFileMetaItem last_item; - int32_t page_index_in_level = start_page_index_in_level; - while (OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id - && write_offset + ObTmpFileGlobal::ALLOC_PAGE_SIZE <= ObTmpFileGlobal::SN_BLOCK_SIZE - && (ObTmpFileTreeEvictType::FULL == flush_type || end_page_id != cur_page_id)) { - char * page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageUniqKey page_key(level, page_index_in_level); - if (OB_UNLIKELY(!wbp_->is_dirty(fd_, cur_page_id, page_key))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page state", KR(ret), K(fd_), K(cur_page_id)); - } else if (OB_FAIL(wbp_->read_page(fd_, cur_page_id, page_key, page_buff, next_page_id))) { - } else { - //check whether the page is satisfied for flush - last_item.reset(); - ObSharedNothingTmpFileTreePageHeader page_header; - int32_t rightmost_child_page_index = -1; - if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else if (page_header.item_num_ <= 0) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), K(fd_), K(page_header)); - } else if (OB_FAIL(read_item_(page_buff, page_header.item_num_ - 1/*item_index*/, last_item))) { - } else if (FALSE_IT(rightmost_child_page_index = page_index_in_level * FULL_PAGE_META_ITEM_NUM + page_header.item_num_ - 1)) { - } else if (!is_page_flushed(last_item) - || (is_page_in_write_cache(last_item) - && wbp_->is_dirty(fd_, last_item.buffer_page_id_, ObTmpFilePageUniqKey(level - 1, rightmost_child_page_index)))) { - //we can be sure that the following pages in this level will not satisfy - break; - //change page state to write back - } else if (OB_FAIL(wbp_->notify_write_back(fd_, cur_page_id, page_key))) { - } else { - ObTmpPageCacheKey cache_key(tree_io_info.block_index_, - write_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE); - MEMCPY(block_buff + write_offset, page_buff, ObTmpFileGlobal::ALLOC_PAGE_SIZE); - if (OB_FAIL(modify_child_pages_location(block_buff + write_offset))) { - } else if (OB_FAIL(calc_and_set_page_checksum_(block_buff + write_offset))) { - } else { - ObTmpPageCacheValue cache_value(block_buff + write_offset); - ObTmpPageCache::get_instance().try_put_page_to_cache(cache_key, cache_value); - write_offset += ObTmpFileGlobal::ALLOC_PAGE_SIZE; - if (flush_start_page_id == cur_page_id) { - tree_io_info.flush_start_page_id_ = cur_page_id; - tree_io_info.flush_start_level_page_index_ = page_index_in_level; - } - tree_io_info.flush_end_page_id_ = cur_page_id; - tree_io_info.flush_nums_++; - cur_page_id = next_page_id; - page_index_in_level++; - } - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::modify_child_pages_location( - char *page_buff) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - ObSharedNothingTmpFileTreePageHeader page_header; - if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else { - int16_t item_index = 0; - ObSharedNothingTmpFileMetaItem meta_item; - while (OB_SUCC(ret) - && item_index < page_header.item_num_) { - meta_item.reset(); - if (OB_FAIL(read_item_(page_buff, item_index, meta_item))) { - } else if (ObTmpFileGlobal::INVALID_PAGE_ID == meta_item.buffer_page_id_) { - //do nothing - } else { - meta_item.buffer_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(rewrite_item_(page_buff, item_index, meta_item))) { - } - } - item_index++; - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::modify_meta_items_at_parent_level_( - const ObTmpFileTreeIOInfo &tree_io, - const int32_t start_page_index_in_level) -{ - int ret = OB_SUCCESS; - const uint32_t cur_level = tree_io.page_level_ + 1; - if (OB_UNLIKELY(cur_level > level_page_range_array_.count() - || !tree_io.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(tree_io), K(level_page_range_array_)); - } else if (cur_level == level_page_range_array_.count()) { - //this must be the root page being flushed - if (OB_UNLIKELY(1 != tree_io.flush_nums_ - || tree_io.flush_start_page_id_ != tree_io.flush_end_page_id_ - || tree_io.flush_start_page_id_ != root_item_.buffer_page_id_ - || 0 != start_page_index_in_level)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected tree_io", KR(ret), K(fd_), K(tree_io), K(root_item_), K(start_page_index_in_level)); - //NOTE: It doesn't matter if we release this page early, because under wlock. - } else if (is_page_flushed(root_item_) - && OB_FAIL(release_tmp_file_page_(root_item_.block_index_, root_item_.physical_page_id_, 1))) { - STORAGE_LOG(WARN, "fail to release tmp file page", KR(ret), K(fd_), K(root_item_)); - } else { - root_item_.block_index_ = tree_io.block_index_; - root_item_.physical_page_id_ = tree_io.physical_start_page_id_; - } - } else { - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - int32_t child_level_page_index = start_page_index_in_level; - uint32_t physical_page_id = tree_io.physical_start_page_id_; - ObSharedNothingTmpFileMetaItem meta_item; - bool is_end = false; - bool has_find = false; - uint32_t last_flushed_page_id = level_page_range_array_.at(cur_level).flushed_end_page_id_; - //the child page of last meta item on last_flushed_page may be flushed again. - uint32_t cur_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t cur_level_page_index = level_page_range_array_.at(cur_level).flushed_page_num_; - if (ObTmpFileGlobal::INVALID_PAGE_ID == last_flushed_page_id) { - cur_page_id = level_page_range_array_.at(cur_level).start_page_id_; - } else { - cur_page_id = last_flushed_page_id; - cur_level_page_index--; - } - while (OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id - && !is_end) { - int16_t item_index = 0; - char *page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObSharedNothingTmpFileTreePageHeader page_header; - ObTmpFilePageUniqKey page_key(cur_level, cur_level_page_index); - //this upper layer page must be in write cache - if (OB_FAIL(wbp_->read_page(fd_, cur_page_id, page_key, page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else if (OB_UNLIKELY(0 >= page_header.item_num_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_header", KR(ret), K(fd_), K(page_header)); - } else { - while (OB_SUCC(ret) - && item_index < page_header.item_num_ - && !is_end) { - meta_item.reset(); - if (OB_FAIL(read_item_(page_buff, item_index, meta_item))) { - } else { - if (has_find || cur_level_page_index * FULL_PAGE_META_ITEM_NUM + item_index == child_level_page_index) { - if (OB_UNLIKELY((!has_find && tree_io.flush_start_page_id_ != meta_item.buffer_page_id_) - || cur_level_page_index * FULL_PAGE_META_ITEM_NUM + item_index != child_level_page_index)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected meta_item", KR(ret), K(fd_), K(has_find), K(tree_io), K(meta_item), - K(child_level_page_index), K(cur_page_id), K(cur_level_page_index), K(item_index)); - } else { - has_find = true; - if (is_page_flushed(meta_item) - && OB_FAIL(release_tmp_file_page_(meta_item.block_index_, meta_item.physical_page_id_, 1))) { - STORAGE_LOG(WARN, "fail to release tmp file page", KR(ret), K(fd_), K(meta_item), K(item_index), K(page_header)); - } else { - meta_item.block_index_ = tree_io.block_index_; - meta_item.physical_page_id_ = physical_page_id; - physical_page_id++; - child_level_page_index++; - if (OB_FAIL(rewrite_item_(page_buff, item_index, meta_item))) { - } else if (tree_io.flush_end_page_id_ == meta_item.buffer_page_id_) { - is_end = true; - } - } - } - } - item_index++; - } - } - } - if (OB_SUCC(ret) && has_find && OB_FAIL(wbp_->notify_dirty(fd_, cur_page_id, page_key))) { - STORAGE_LOG(ERROR, "fail to notify dirty for meta", KR(ret), K(fd_), K(cur_page_id), K(page_key)); - } - cur_page_id = next_page_id; - cur_level_page_index++; - } - if (OB_SUCC(ret)) { - if (OB_UNLIKELY(!is_end - || physical_page_id - tree_io.physical_start_page_id_ != tree_io.flush_nums_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected is_end or flush_nums_", KR(ret), K(fd_), - K(is_end), K(physical_page_id), K(tree_io)); - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::update_after_flush( - const common::ObIArray &tree_io_array) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (OB_UNLIKELY(tree_io_array.empty())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(fd_), K(tree_io_array), K(root_item_)); - } else { - ARRAY_FOREACH_N(tree_io_array, i, cnt) { - bool tree_io_is_empty = false; - const ObTmpFileTreeIOInfo &tree_io = tree_io_array.at(i); - const int16_t origin_tree_flush_num = tree_io.flush_nums_; - bool end_page_flush_again = false; - if (OB_UNLIKELY(!tree_io.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(tree_io), KPC(this)); - } else if (tree_io.tree_epoch_ != tree_epoch_) { - STORAGE_LOG(INFO, "the tree_epoch_ in tree_io is not equal to current tree_epoch_", - K(fd_), K(tree_io), K(tree_epoch_)); - } else if (tree_io.page_level_ >= level_page_range_array_.count()) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(tree_io), KPC(this)); - } else { - const uint32_t flushed_end_page_id_in_array = level_page_range_array_[tree_io.page_level_].flushed_end_page_id_; - const uint32_t start_page_id_in_array = level_page_range_array_[tree_io.page_level_].start_page_id_; - uint32_t next_page_id_in_array = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t level_page_index = level_page_range_array_[tree_io.page_level_].flushed_page_num_; - if (ObTmpFileGlobal::INVALID_PAGE_ID != flushed_end_page_id_in_array) { - level_page_index--; - ObTmpFilePageUniqKey page_key(tree_io.page_level_, level_page_index); - if (OB_FAIL(wbp_->get_next_page_id(fd_, flushed_end_page_id_in_array, page_key, next_page_id_in_array))) { - } else if (OB_UNLIKELY(flushed_end_page_id_in_array != tree_io.flush_start_page_id_ - && !wbp_->is_cached(fd_, flushed_end_page_id_in_array, page_key))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected flushed_end_page_id_in_array or tree_io", KR(ret), K(tree_io), - K(flushed_end_page_id_in_array), KPC(this)); - } else if (OB_UNLIKELY(flushed_end_page_id_in_array != tree_io.flush_start_page_id_ - && next_page_id_in_array != tree_io.flush_start_page_id_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_id_in_array or tree_io", KR(ret), K(tree_io), - K(flushed_end_page_id_in_array), K(next_page_id_in_array), KPC(this)); - } else if (flushed_end_page_id_in_array == tree_io.flush_start_page_id_) { - end_page_flush_again = true; - } else { - level_page_index++; - } - } else { - if (level_page_index > tree_io.flush_start_level_page_index_) { - int64_t truncated_num = level_page_index - tree_io.flush_start_level_page_index_; - if (truncated_num >= tree_io.flush_nums_) { - tree_io_is_empty = true; - } else { - ObTmpFileTreeIOInfo& tree_io_mutable_ref = const_cast(tree_io); - tree_io_mutable_ref.flush_start_page_id_ = start_page_id_in_array; - tree_io_mutable_ref.flush_nums_ -= truncated_num; - } - } else if (OB_UNLIKELY(start_page_id_in_array != tree_io.flush_start_page_id_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected tree_io", KR(ret), K(tree_io), KPC(this)); - } - } - if (OB_SUCC(ret) && !tree_io_is_empty) { - uint32_t cur_page_id = tree_io.flush_start_page_id_; - int16_t num = 0; - //change page state from writeback to cached - while (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id) { - ObTmpFilePageUniqKey page_key(tree_io.page_level_, level_page_index); - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (cur_page_id == tree_io.flush_end_page_id_ && wbp_->is_dirty(fd_, cur_page_id, page_key)) { - //do nothing - STORAGE_LOG(INFO, "page is dirty again, do not change page status", KR(ret), K(fd_), K(cur_page_id)); - } else if (OB_FAIL(wbp_->notify_write_back_succ(fd_, cur_page_id, page_key))) { - } - if (OB_SUCC(ret)) { - num++; - if (OB_UNLIKELY(num > tree_io.flush_nums_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected num", KR(ret), K(tree_io), K(num), K(cur_page_id), KPC(this)); - } else if (cur_page_id == tree_io.flush_end_page_id_) { - break; - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, cur_page_id, page_key, next_page_id))) { - } else { - cur_page_id = next_page_id; - level_page_index++; - } - } - } - if (OB_SUCC(ret)) { - if (OB_UNLIKELY(tree_io.flush_nums_ != num - || cur_page_id != tree_io.flush_end_page_id_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page level or flush num", KR(ret), K(tree_io), K(num), K(cur_page_id), KPC(this)); - } else { - level_page_range_array_[tree_io.page_level_].flushed_end_page_id_ = tree_io.flush_end_page_id_; - if (end_page_flush_again) { - num--; - } - level_page_range_array_[tree_io.page_level_].flushed_page_num_ += num; - } - } - } - } - if (OB_SUCC(ret)) { - stat_info_.meta_page_flushing_cnt_ -= origin_tree_flush_num; - } - } - } - STORAGE_LOG(INFO, "finish update after flush", KR(ret), K(fd_), K(level_page_range_array_)); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::prepare_for_write_tail( - ObSharedNothingTmpFileDataItem &last_data_item) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (!root_item_.is_valid()) { - if (OB_UNLIKELY(data_item_array_.empty())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data_item_array_ count", KR(ret), K(fd_), K(data_item_array_)); - } else { - last_data_item = data_item_array_.at(data_item_array_.count() - 1); - if (OB_UNLIKELY(0 >= last_data_item.physical_page_num_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected physical_page_num", KR(ret), K(last_data_item), KPC(this)); - } - } - } else { - ObSharedNothingTmpFileTreePageHeader page_header; - ObSharedNothingTmpFileMetaItem page_info; - if (OB_UNLIKELY(level_page_range_array_.empty())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_page_range_array_", KR(ret), KPC(this)); - } else if (OB_FAIL(get_rightmost_leaf_page_for_write_(page_info))) { - } else { - //we don't need to worry about the rightmost leaf page being evicted, - // because we set is_writing_ = true. - char *leaf_page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t leaf_level_page_index = level_page_range_array_.at(0).evicted_page_num_ + - level_page_range_array_.at(0).cached_page_num_ - 1; - if (OB_FAIL(wbp_->read_page(fd_, page_info.buffer_page_id_, ObTmpFilePageUniqKey(0, leaf_level_page_index), - leaf_page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(leaf_page_buff, page_header))) { - } else if (OB_UNLIKELY(0 >= page_header.item_num_)) { - //There is no concurrent writing - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), KP(leaf_page_buff), K(page_header), KPC(this)); - } else if (OB_FAIL(read_item_(leaf_page_buff, page_header.item_num_ - 1, last_data_item))) { - } else if (OB_UNLIKELY(0 >= last_data_item.physical_page_num_)) { - ret = OB_ERR_UNEXPECTED; - //print page content - //NOTE: control print frequence - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObArray items; - read_page_content_(leaf_page_buff, tmp_page_header, items); - STORAGE_LOG(ERROR, "unexpected physical_page_num, dump tree page", KR(ret), K(last_data_item), KP(leaf_page_buff), - K(page_info), K(leaf_level_page_index), K(tmp_page_header), K(items), KPC(this)); - } - } - } - return ret; -} - -//After the tail is written -int ObSharedNothingTmpFileMetaTree::finish_write_tail( - const ObSharedNothingTmpFileDataItem &last_data_item, - const bool release_tail_in_disk) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (!root_item_.is_valid()) { - if (OB_UNLIKELY(data_item_array_.empty() - || last_data_item != data_item_array_[data_item_array_.count() - 1])) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data_item_array_ or last_data_item", KR(ret), K(last_data_item), KPC(this)); - } else if (release_tail_in_disk) { - if (0 == --data_item_array_[data_item_array_.count() - 1].physical_page_num_) { - data_item_array_.pop_back(); - } - } - } else { - if (OB_UNLIKELY(level_page_range_array_.empty() - || !is_writing_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_array_ or is_writing_", KR(ret), KPC(this)); - } else if (release_tail_in_disk) { - char *leaf_page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t page_id = level_page_range_array_[0].end_page_id_; - int32_t level_page_index = level_page_range_array_.at(0).evicted_page_num_ + - level_page_range_array_.at(0).cached_page_num_ - 1; - ObSharedNothingTmpFileTreePageHeader page_header; - ObSharedNothingTmpFileDataItem data_item; - ObTmpFilePageUniqKey page_key(0, level_page_index); - if (OB_FAIL(wbp_->read_page(fd_, page_id, page_key, leaf_page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(leaf_page_buff, page_header))) { - } else if (OB_FAIL(read_item_(leaf_page_buff, page_header.item_num_ - 1, data_item))) { - } else if (OB_UNLIKELY(last_data_item != data_item)) { - ret = OB_ERR_UNEXPECTED; - //print page content - //NOTE: control print frequence - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObArray items; - read_page_content_(leaf_page_buff, tmp_page_header, items); - STORAGE_LOG(ERROR, "unexpected virtual_page_id, dump tree page", KR(ret), KP(leaf_page_buff), K(page_id), K(page_key), - K(last_data_item), K(data_item), K(tmp_page_header), K(items), KPC(this)); - } else if (FALSE_IT(data_item.physical_page_num_--)) { - } else if (0 == data_item.physical_page_num_) { - if (OB_FAIL(remove_page_item_from_tail_(leaf_page_buff, 1/*remove_num*/))) { - } - } else if (OB_FAIL(rewrite_item_(leaf_page_buff, page_header.item_num_ - 1, data_item))) { - } - if (FAILEDx(wbp_->notify_dirty(fd_, page_id, page_key))) { - } - } - if (OB_SUCC(ret)) { - is_writing_ = false; - } - } - if (OB_SUCC(ret) && release_tail_in_disk) { - if (OB_FAIL(release_tmp_file_page_(last_data_item.block_index_, - last_data_item.physical_page_id_ + last_data_item.physical_page_num_ - 1, 1))) { - } - } - STORAGE_LOG(INFO, "finish write tail", KR(ret), K(fd_), K(release_tail_in_disk)); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::evict_meta_pages( - const int64_t expected_page_num, - const ObTmpFileTreeEvictType flush_type, - int64_t &actual_evict_page_num) -{ - int ret = OB_SUCCESS; - actual_evict_page_num = 0; - if (OB_UNLIKELY(0 >= expected_page_num - || ObTmpFileTreeEvictType::INVALID == flush_type)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(fd_), K(expected_page_num), K(flush_type)); - } else { - SpinWLockGuard guard(lock_); - if (!root_item_.is_valid()) { - //do nothing - } else { - ObSEArray evict_pages; - ARRAY_FOREACH_X(level_page_range_array_, level, level_cnt, - OB_SUCC(ret) && actual_evict_page_num < expected_page_num) { - evict_pages.reset(); - uint32_t next_page_id = level_page_range_array_[level].start_page_id_; - const uint32_t end_evict_page = level_page_range_array_[level].flushed_end_page_id_; - const uint32_t end_page_id = level_page_range_array_[level].end_page_id_; - const int32_t start_level_page_index = level_page_range_array_.at(level).evicted_page_num_; - uint32_t cur_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t level_page_index = start_level_page_index; - if (ObTmpFileGlobal::INVALID_PAGE_ID == end_evict_page) { - //no pages need to be evicted at this level - continue; - } - while (OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != next_page_id - && actual_evict_page_num < expected_page_num - && (!is_writing_ || end_page_id != next_page_id) //not evict end page if is writing - && (ObTmpFileTreeEvictType::FULL == flush_type || end_page_id != next_page_id)) { - ObTmpFilePageUniqKey page_key(level, level_page_index); - if (OB_UNLIKELY(end_evict_page != next_page_id && !wbp_->is_cached(fd_, next_page_id, page_key))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected next_page_id", KR(ret), K(next_page_id), KPC(this)); - } else if (end_evict_page == next_page_id && !wbp_->is_cached(fd_, next_page_id, page_key)) { - break; - } else if (level > 0) { - //check whether the page is satisfied for evict - char * page_buff = NULL; - ObSharedNothingTmpFileMetaItem last_item; - uint32_t unused_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(wbp_->read_page(fd_, next_page_id, page_key, page_buff, unused_page_id))) { - } else { - last_item.reset(); - ObSharedNothingTmpFileTreePageHeader page_header; - if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else if (page_header.item_num_ <= 0) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), K(page_header), KPC(this)); - } else if (OB_FAIL(read_item_(page_buff, page_header.item_num_ - 1/*item_index*/, last_item))) { - } else if (is_page_in_write_cache(last_item)) { - if (OB_UNLIKELY(end_evict_page != next_page_id)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected next_page", KR(ret), K(next_page_id), K(last_item), KPC(this)); - } else { - break; - } - } - } - } - if (OB_SUCC(ret)) { - cur_page_id = next_page_id; - next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(evict_pages.push_back(cur_page_id))) { - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, cur_page_id, page_key, next_page_id))) { - } else { - actual_evict_page_num++; - level_page_index++; - if (end_evict_page == cur_page_id) { - break; - } - } - } - } - if (OB_SUCC(ret) && !evict_pages.empty()) { - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == cur_page_id)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected cur_page_id", KR(ret), K(cur_page_id), K(level), K(level_page_index), KPC(this)); - } else if (OB_FAIL(modify_meta_items_during_evict_(evict_pages, level + 1, start_level_page_index))) { - } else { - uint32_t unused_next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ARRAY_FOREACH_N(evict_pages, i, cnt) { - //change page state from flushed/cached to evicted/invalid - if (OB_FAIL(wbp_->free_page(fd_, evict_pages.at(i), - ObTmpFilePageUniqKey(level, start_level_page_index + i), unused_next_page_id))) { - } else { - stat_info_.meta_page_free_cnt_++; - } - } - } - if (OB_SUCC(ret)) { - if (end_page_id == cur_page_id) { - //all pages in this level are evicted - level_page_range_array_[level].start_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - level_page_range_array_[level].end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - level_page_range_array_[level].flushed_end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == next_page_id)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected next_page_id", KR(ret), K(next_page_id), K(cur_page_id), KPC(this)); - } else if (end_evict_page == cur_page_id) { - //flushed_end_page is not equal to end_page, - // and pages are evicted to flushed_end_page(including flushed_end_page) - level_page_range_array_[level].start_page_id_ = next_page_id; - level_page_range_array_[level].flushed_end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - } else { - //pages are not evicted to flushed_end_page - level_page_range_array_[level].start_page_id_ = next_page_id; - } - if (OB_SUCC(ret)) { - level_page_range_array_[level].cached_page_num_ -= evict_pages.count(); - level_page_range_array_[level].evicted_page_num_ += evict_pages.count(); - } - } - } - } - } - } - STORAGE_LOG(INFO, "finish evict meta pages", KR(ret), K(fd_), K(level_page_range_array_)); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::modify_meta_items_during_evict_( - const ObIArray &evict_pages, - const int16_t level, - const int32_t start_page_index_in_level) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(evict_pages.empty() - || level > level_page_range_array_.count())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected evict_pages", KR(ret), K(fd_), K(evict_pages), - K(level), K(level_page_range_array_)); - } else { - char *page_buff = NULL; - const int64_t level_count = level_page_range_array_.count(); - const int64_t evict_page_count = evict_pages.count(); - int64_t array_index = 0; - bool has_find = false; - if (level < level_count) { - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - uint32_t cur_page_id = level_page_range_array_[level].start_page_id_; - const uint32_t end_page_id = level_page_range_array_[level].end_page_id_; - int32_t level_page_index = level_page_range_array_[level].evicted_page_num_; - int32_t evict_page_index_in_level = start_page_index_in_level; - ObSharedNothingTmpFileMetaItem meta_item; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == cur_page_id - || ObTmpFileGlobal::INVALID_PAGE_ID == end_page_id - || 0 > evict_page_index_in_level)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_id", KR(ret), K(fd_), K(level_page_range_array_), - K(level), K(evict_page_index_in_level)); - } else { - while(OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id - && array_index < evict_page_count) { - ObSharedNothingTmpFileTreePageHeader page_header; - char *page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(wbp_->read_page(fd_, cur_page_id, ObTmpFilePageUniqKey(level, level_page_index), page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else { - int16_t item_index = 0; - while (OB_SUCC(ret) - && item_index < page_header.item_num_ - && array_index < evict_page_count) { - meta_item.reset(); - if (OB_FAIL(read_item_(page_buff, item_index, meta_item))) { - } else { - if (has_find || level_page_index * FULL_PAGE_META_ITEM_NUM + item_index == evict_page_index_in_level) { - if (OB_UNLIKELY(meta_item.buffer_page_id_ != evict_pages.at(array_index) - || level_page_index * FULL_PAGE_META_ITEM_NUM + item_index != evict_page_index_in_level - || !is_page_in_write_cache(meta_item) - || !is_page_flushed(meta_item))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected meta_item", KR(ret), K(fd_), K(evict_pages), K(array_index), K(meta_item), - K(evict_page_index_in_level), K(cur_page_id), K(level_page_index), K(item_index)); - } else { - has_find = true; - meta_item.buffer_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - array_index++; - evict_page_index_in_level++; - if (OB_FAIL(rewrite_item_(page_buff, item_index, meta_item))) { - } - } - } - } - item_index++; - } - } - //it is not necessary to mark it as dirty. - cur_page_id = next_page_id; - level_page_index++; - } - if (OB_SUCC(ret) && evict_page_count != array_index) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected array_index", KR(ret), K(fd_), K(array_index), K(evict_pages), K(level_page_range_array_)); - } - } - } else { //level == level_count - if (OB_UNLIKELY(!is_page_in_write_cache(root_item_) - || !is_page_flushed(root_item_) - || 1 != evict_page_count - || evict_pages.at(0) != root_item_.buffer_page_id_ - || 0 != start_page_index_in_level)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected root_item_ or evict_pages", KR(ret), K(fd_), K(root_item_), - K(evict_pages), K(start_page_index_in_level)); - } else { - root_item_.buffer_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::clear( - const int64_t last_truncate_offset, - const int64_t total_file_size) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - int64_t end_truncate_offset = upper_align(total_file_size, ObTmpFileGlobal::ALLOC_PAGE_SIZE); - - if (OB_UNLIKELY(last_truncate_offset < released_offset_ - || last_truncate_offset > total_file_size - || is_writing_)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(last_truncate_offset), K(total_file_size), KPC(this)); - } else { - while (true) { - if (OB_FAIL(truncate_(end_truncate_offset))) { - } else { - break; - } - usleep(100 * 1000); // 100ms - ret = OB_SUCCESS; - } - if (OB_FAIL(ret)) { - } else if (OB_UNLIKELY(root_item_.is_valid() - || !level_page_range_array_.empty() - || !data_item_array_.empty())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected root_item_ or array_", KR(ret), KPC(this)); - } else if (OB_UNLIKELY(stat_info_.all_type_page_flush_cnt_ != stat_info_.all_type_flush_page_released_cnt_ - || stat_info_.meta_page_alloc_cnt_ != stat_info_.meta_page_free_cnt_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected stat_info_", KR(ret), KPC(this)); - } - } - return ret; -} - -//clear leaf page or internal page in meta tree -int ObSharedNothingTmpFileMetaTree::release_meta_page_( - const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t page_index_in_level) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(level_page_range_array_.count() <= page_info.page_level_ - || 0 > page_index_in_level)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_page_range_array_ or page_info", KR(ret), K(fd_), K(level_page_range_array_), - K(page_info), K(page_index_in_level)); - } else if (is_page_in_write_cache(page_info)) { - const uint32_t start_page_id_in_array = level_page_range_array_.at(page_info.page_level_).start_page_id_; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - if (OB_FAIL(wbp_->free_page(fd_, page_info.buffer_page_id_, - ObTmpFilePageUniqKey(page_info.page_level_, page_index_in_level), next_page_id))) { - } else if (FALSE_IT(stat_info_.meta_page_free_cnt_++)) { - } else if (OB_UNLIKELY(start_page_id_in_array != page_info.buffer_page_id_)) { - //NOTE: pages must be released sequentially (from front to back in array) - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_page_range_array_", KR(ret), K(fd_), K(level_page_range_array_), K(page_info)); - } else { - level_page_range_array_.at(page_info.page_level_).start_page_id_ = next_page_id; - if (start_page_id_in_array == level_page_range_array_.at(page_info.page_level_).end_page_id_) { - //next_page_id must be invalid - level_page_range_array_.at(page_info.page_level_).end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - } - if (ObTmpFileGlobal::INVALID_PAGE_ID == level_page_range_array_.at(page_info.page_level_).flushed_end_page_id_) { - level_page_range_array_.at(page_info.page_level_).flushed_page_num_ += 1; - } - if (start_page_id_in_array == level_page_range_array_.at(page_info.page_level_).flushed_end_page_id_) { - level_page_range_array_.at(page_info.page_level_).flushed_end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - } - level_page_range_array_.at(page_info.page_level_).cached_page_num_ -= 1; - level_page_range_array_.at(page_info.page_level_).evicted_page_num_ += 1; - } - } - if (OB_SUCC(ret) && is_page_flushed(page_info)) { - if (OB_FAIL(release_tmp_file_page_(page_info.block_index_, page_info.physical_page_id_, 1))) { - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::release_tmp_file_page_( - const int64_t block_index, const int64_t begin_page_id, const int64_t page_num) -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(block_manager_->release_tmp_file_page(block_index, begin_page_id, page_num))) { - } else { - stat_info_.all_type_flush_page_released_cnt_ += page_num; - } - - // ignore ret - for (int64_t i = 0; i < page_num; ++i) { - int64_t page_id = begin_page_id + i; - ObTmpPageCacheKey key(block_index, page_id); - ObTmpPageCache::get_instance().erase(key); - } - - return ret; -} - -int ObSharedNothingTmpFileMetaTree::truncate( - const int64_t last_truncate_offset, - const int64_t end_truncate_offset) -{ - int ret = OB_SUCCESS; - SpinWLockGuard guard(lock_); - if (OB_UNLIKELY(last_truncate_offset < released_offset_ - || 0 != released_offset_ % ObTmpFileGlobal::ALLOC_PAGE_SIZE - || last_truncate_offset > end_truncate_offset - || is_writing_)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(last_truncate_offset), K(end_truncate_offset), KPC(this)); - } else { - while (true) { - if (OB_FAIL(truncate_(end_truncate_offset))) { - } else { - break; - } - usleep(100 * 1000); // 100ms - ret = OB_SUCCESS; - } - if (OB_SUCC(ret)) { - if (!root_item_.is_valid()) { - //NOTE: end_truncate_offset >= max offset in tree. - // released_offset_ = end_truncate_offset; - } - } - } - - STORAGE_LOG(INFO, "finish truncate array or meta tree", KR(ret), K(fd_), K(released_offset_), K(last_truncate_offset), K(end_truncate_offset)); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::truncate_( - const int64_t end_truncate_offset) -{ - int ret = OB_SUCCESS; - if (!root_item_.is_valid()) { - if (OB_FAIL(truncate_array_(end_truncate_offset))) { - } - } else { - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - ObArray> item_index_arr; - if (OB_FAIL(calculate_truncate_index_path_(item_index_arr))) { - } else if (OB_UNLIKELY(item_index_arr.empty())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_index_arr", KR(ret), K(fd_), K(item_index_arr)); - } else { - ObSharedNothingTmpFileMetaItem meta_item = root_item_; - ObSharedNothingTmpFileMetaItem next_level_meta_item; - ObSEArray truncate_path; - ObSEArray p_handles; - while (OB_SUCC(ret) - && 0 < meta_item.page_level_) { - next_level_meta_item.reset(); - int16_t item_index = -1; - int32_t level_page_index = -1; - ObSharedNothingTmpFileTreePageHeader page_header; - char *page_buff = NULL; - ObTmpPageValueHandle p_handle; - if (OB_UNLIKELY(item_index_arr.count() <= meta_item.page_level_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_index_arr", KR(ret), K(fd_), K(item_index_arr), K(meta_item)); - } else if (FALSE_IT(level_page_index = item_index_arr.at(meta_item.page_level_).first)) { - } else if (FALSE_IT(item_index = item_index_arr.at(meta_item.page_level_).second)) { - } else if (OB_FAIL(get_page_(meta_item, level_page_index, page_buff, p_handle))) { - } else if (OB_FAIL(p_handles.push_back(p_handle))) { - } else if (OB_FAIL(read_item_(page_buff, item_index, next_level_meta_item))) { - } else if (OB_FAIL(truncate_path.push_back(BacktraceNode(meta_item /*page info*/, - level_page_index, /*page index in its level*/ - item_index /*item index on the page*/)))) { - } else { - meta_item = next_level_meta_item; - } - if (OB_FAIL(ret)) { - p_handle.reset(); - } - } - if (OB_SUCC(ret)) { - bool release_last_item = false; - if (0 == meta_item.page_level_) { - ObArray reserved_meta_items(8 * 1024); //block_size = 8K - if (item_index_arr.count() > 1 && OB_FAIL(reserved_meta_items.reserve(FULL_PAGE_META_ITEM_NUM))) { - STORAGE_LOG(WARN, "fail to reserve", KR(ret), K(fd_)); - } else if (OB_FAIL(release_items_of_leaf_page_(meta_item, item_index_arr.at(0).first, end_truncate_offset, - item_index_arr.at(0).second, release_last_item))) { - } else if (release_last_item) { - if (OB_FAIL(release_meta_page_(meta_item, item_index_arr.at(0).first))) { - } else if (OB_FAIL(backtrace_truncate_tree_(end_truncate_offset, truncate_path, reserved_meta_items, p_handles))) { - } - } - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page type", KR(ret), K(fd_), K(meta_item)); - } - } - for (int16_t i = 0; i < p_handles.count(); i++) { - p_handles.at(i).reset(); - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::truncate_array_( - const int64_t end_offset) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(end_offset < 0 - || data_item_array_.count() > MAX_DATA_ITEM_ARRAY_COUNT)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(end_offset), K(data_item_array_)); - } else if (data_item_array_.empty()) { - STORAGE_LOG(INFO, "no data to truncate", KR(ret), K(fd_), K(data_item_array_), K(root_item_)); - } else { - const ObSharedNothingTmpFileDataItem &last_item = data_item_array_.at(data_item_array_.count() - 1); - if (OB_UNLIKELY(!last_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected last item", KR(ret), K(fd_), K(last_item)); - } else if (end_offset >= (last_item.virtual_page_id_ + last_item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE) { - //clear all items - ARRAY_FOREACH_N(data_item_array_, i, cnt) { - const ObSharedNothingTmpFileDataItem &item = data_item_array_.at(i); - if (OB_FAIL(release_tmp_file_page_(item.block_index_, - item.physical_page_id_, item.physical_page_num_))) { - } else if (i + 1 == cnt) { - released_offset_ = (item.virtual_page_id_ + item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - } - if (OB_SUCC(ret)) { - data_item_array_.reset(); - } - } else { - //clear some items - const int64_t target_virtual_page_id = end_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - int16_t index = 0; - ARRAY_FOREACH_N(data_item_array_, i, cnt) { - const ObSharedNothingTmpFileDataItem &data_item = data_item_array_.at(i); - if (OB_UNLIKELY(!data_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data item", KR(ret), K(fd_), K(data_item)); - } else if (data_item.virtual_page_id_ <= target_virtual_page_id) { - index = i; - } else { - break; - } - } - if (OB_SUCC(ret)) { - if (0 == index) { - //do nothing - } else { - //release items before "index" - int16_t array_cnt = data_item_array_.count(); - for (int16_t i = 0; OB_SUCC(ret) && i < index; i++) { - ObSharedNothingTmpFileDataItem &data_item = data_item_array_.at(i); - if (OB_UNLIKELY(!data_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data item", KR(ret), K(fd_), K(data_item)); - } else if (OB_FAIL(release_tmp_file_page_(data_item.block_index_, - data_item.physical_page_id_, - data_item.physical_page_num_))) { - } else if (i + 1 == index) { - released_offset_ = (data_item.virtual_page_id_ + data_item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } else { - data_item.reset(); - } - } - if (OB_SUCC(ret)) { - //move items - for (int16_t i = index; i < array_cnt; i++) { - data_item_array_.at(i - index) = data_item_array_.at(i); - } - for (int16_t i = 0; i < index; i++) { - data_item_array_.pop_back(); - } - } - } - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::calculate_truncate_index_path_( - ObIArray> &item_index_arr) -{ - int ret = OB_SUCCESS; - item_index_arr.reset(); - if (OB_UNLIKELY(!root_item_.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected root_item_", KR(ret), K(fd_), K(root_item_)); - } else { - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - int32_t child_level_page_index = -1; - ARRAY_FOREACH_N(level_page_range_array_, i, cnt) { - int16_t item_index = -1; - if (!last_truncate_leaf_info_.is_valid()) { - child_level_page_index = 0; - item_index = 0; - } else { - int32_t level_page_index = -1; - int32_t level_page_num = level_page_range_array_.at(i).evicted_page_num_ + level_page_range_array_.at(i).cached_page_num_; - if (0 == i) { - level_page_index = last_truncate_leaf_info_.page_index_in_leaf_level_; - item_index = last_truncate_leaf_info_.item_index_in_page_ + 1; - if (last_truncate_leaf_info_.release_to_end_in_page_) { - level_page_index++; - item_index = 0; - } - } else { //internal level - item_index = child_level_page_index % FULL_PAGE_META_ITEM_NUM; - level_page_index = child_level_page_index / FULL_PAGE_META_ITEM_NUM; - } - if (level_page_index >= level_page_num) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "no data to truncate but root_item_ is valid", KR(ret), K(fd_), - K(i), K(level_page_index), K(level_page_num), K(level_page_range_array_)); - } else { - child_level_page_index = level_page_index; - } - } - if (FAILEDx(item_index_arr.push_back(std::make_pair(child_level_page_index, item_index)))) { - } - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::release_items_of_leaf_page_( - const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - const int64_t end_offset, - const int16_t begin_release_index, - bool &release_last_item) -{ - int ret = OB_SUCCESS; - release_last_item = false; - char *page_buff = NULL; - int16_t item_index = -1; - int16_t end_release_index = -1; - int64_t tmp_release_offset = released_offset_; - ObSharedNothingTmpFileDataItem data_item; - ObSharedNothingTmpFileTreePageHeader page_header; - ObTmpPageValueHandle p_handle; - if (OB_UNLIKELY(0 != tmp_release_offset % ObTmpFileGlobal::ALLOC_PAGE_SIZE - || 0 > begin_release_index - || PAGE_HEADER_SIZE + (begin_release_index + 1) * sizeof(ObSharedNothingTmpFileDataItem) > ObTmpFileGlobal::ALLOC_PAGE_SIZE - || begin_release_index >= MAX_PAGE_ITEM_COUNT)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected release_offset or begin_release_index", KR(ret), K(fd_), K(tmp_release_offset), K(begin_release_index)); - } else if (OB_FAIL(get_page_(page_info, level_page_index, page_buff, p_handle))) { - } else if (OB_FAIL(read_page_header_(page_buff, page_header))) { - } else if (0 == page_header.item_num_ || begin_release_index == page_header.item_num_) { - //maybe the item have been cleared (corresponds to an unfilled data page) - release_last_item = true; - } else { - //get end_release_index - int64_t target_virtual_page_id = end_offset / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - item_index = -1; - data_item.reset(); - if (OB_FAIL(read_item_(page_buff, target_virtual_page_id, item_index, data_item))) { - } else if (OB_UNLIKELY(!data_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data item", KR(ret), K(fd_), K(data_item)); - } else if (target_virtual_page_id >= data_item.virtual_page_id_ + data_item.physical_page_num_) { - if (OB_UNLIKELY(item_index + 1 != page_header.item_num_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_index", KR(ret), K(fd_), K(item_index)); - } else { - end_release_index = item_index; - release_last_item = true; - } - } else { - end_release_index = item_index - 1; - } - if (OB_SUCC(ret)) { - item_index = begin_release_index; - while (OB_SUCC(ret) - && item_index <= end_release_index) { - data_item.reset(); - if (OB_FAIL(read_item_(page_buff, item_index, data_item))) { - } else if (OB_UNLIKELY(!data_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected data item", KR(ret), K(fd_), K(data_item)); - } else if (OB_FAIL(release_tmp_file_page_(data_item.block_index_, - data_item.physical_page_id_, - data_item.physical_page_num_))) { - } else { - item_index++; - } - } - } - if (OB_SUCC(ret) && begin_release_index <= end_release_index) { - tmp_release_offset = (data_item.virtual_page_id_ + data_item.physical_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - if (OB_UNLIKELY(tmp_release_offset > end_offset - || tmp_release_offset <= released_offset_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected release_offset", KR(ret), K(fd_), K(tmp_release_offset), K(end_offset), K(released_offset_)); - } else { - released_offset_ = tmp_release_offset; - last_truncate_leaf_info_.page_index_in_leaf_level_ = level_page_index; - last_truncate_leaf_info_.item_index_in_page_ = end_release_index; - last_truncate_leaf_info_.release_to_end_in_page_ = release_last_item; - } - } - if (OB_FAIL(ret)) { - //print page content - //NOTE: control print frequence - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ObArray items; - read_page_content_(page_buff, tmp_page_header, items); - STORAGE_LOG(WARN, "fail to release leaf page items, dump tree page", KR(ret), K(fd_), KP(page_buff), K(page_info), - K(level_page_index), K(begin_release_index), K(end_release_index), K(end_offset), K(tmp_page_header), K(items)); - } - } - p_handle.reset(); - return ret; -} - -int ObSharedNothingTmpFileMetaTree::backtrace_truncate_tree_( - const int64_t end_offset, - ObIArray &search_path, - ObIArray &meta_items, - ObIArray &p_handles) -{ - int ret = OB_SUCCESS; - const int16_t FULL_PAGE_META_ITEM_NUM = - MIN(MAX_PAGE_ITEM_COUNT, (ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE) / sizeof(ObSharedNothingTmpFileMetaItem)); - bool need_finish = false; - while (OB_SUCC(ret) - && !search_path.empty() - && !need_finish) { - meta_items.reuse(); - bool reach_last_item = false; - int64_t last_node_index = search_path.count() - 1; - //meta_item points to a page - const ObSharedNothingTmpFileMetaItem &page_info = search_path.at(last_node_index).page_meta_info_; - //the page index in its level - const int32_t level_page_index = search_path.at(last_node_index).level_page_index_; - //current pos need to be processed on this page. - int16_t cur_item_index = search_path.at(last_node_index).prev_item_index_ + 1; - if (OB_UNLIKELY(p_handles.count() != search_path.count())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected p_handles or search_path", KR(ret), K(fd_), K(p_handles), K(search_path)); - //must not fail - } else if (OB_FAIL(get_items_of_internal_page_(page_info, level_page_index, cur_item_index, - end_offset, reach_last_item, meta_items))) { - } else if (1 == page_info.page_level_) { - int16_t release_page_cnt = 0; - const int32_t start_leaf_level_page_index = level_page_index * FULL_PAGE_META_ITEM_NUM + cur_item_index; - ARRAY_FOREACH_X(meta_items, i, cnt, OB_SUCC(ret) && !need_finish) { - bool release_last_item = false; - if (OB_FAIL(release_items_of_leaf_page_(meta_items.at(i), start_leaf_level_page_index + i, end_offset, - 0 /*release from start of the page*/, release_last_item))) { - } else if (release_last_item) { - if (OB_FAIL(release_meta_page_(meta_items.at(i), start_leaf_level_page_index + i))) { - } else { - release_page_cnt++; - } - } else { - need_finish = true; - } - } - if (OB_SUCC(ret)) { - if (!reach_last_item) { - need_finish = true; - } else if (reach_last_item && (meta_items.empty() || release_page_cnt == meta_items.count())) { - if (OB_FAIL(release_meta_page_(page_info, level_page_index))) { - } else { - search_path.pop_back(); - p_handles.at(last_node_index).reset(); - p_handles.pop_back(); - } - } - } - } else if (1 < page_info.page_level_) { - if (meta_items.count() == 1) { - const int32_t child_level_page_index = level_page_index * FULL_PAGE_META_ITEM_NUM + cur_item_index; - search_path.at(last_node_index).prev_item_index_ = cur_item_index; - char *unused_page_buff = NULL; - ObTmpPageValueHandle p_handle; - if (OB_FAIL(get_page_(meta_items.at(0), child_level_page_index, unused_page_buff, p_handle))) { - } else if (OB_FAIL(p_handles.push_back(p_handle))) { - } else if (OB_FAIL(search_path.push_back(BacktraceNode(meta_items.at(0), child_level_page_index, -1)))) { - } - if (OB_FAIL(ret)) { - p_handle.reset(); - } - } else if (meta_items.empty()) { - if (reach_last_item) { - if (OB_FAIL(release_meta_page_(page_info, level_page_index))) { - } else { - search_path.pop_back(); - p_handles.at(last_node_index).reset(); - p_handles.pop_back(); - } - } else { - need_finish = true; - } - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected meta_items", KR(ret), K(fd_), K(meta_items)); - } - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page info", KR(ret), K(fd_), K(page_info)); - } - } - if (OB_SUCC(ret) && !need_finish) { - //all pages are released - if (OB_FAIL(check_tree_is_empty_())) { - } else if (OB_UNLIKELY(stat_info_.all_type_page_flush_cnt_ != stat_info_.all_type_flush_page_released_cnt_ - || stat_info_.meta_page_alloc_cnt_ != stat_info_.meta_page_free_cnt_)) { - //TODO: do not throw errors in the future - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected stat_info_", KR(ret), K(fd_), K(stat_info_)); - } else { - ++tree_epoch_; - root_item_.reset(); - level_page_range_array_.reset(); - last_truncate_leaf_info_.reset(); - STORAGE_LOG(INFO, "meta tree pages are all truncated", KR(ret), K(fd_), K(tree_epoch_)); - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::check_tree_is_empty_() -{ - int ret = OB_SUCCESS; - ARRAY_FOREACH_N(level_page_range_array_, i, cnt) { - if (OB_UNLIKELY(0 != level_page_range_array_.at(i).cached_page_num_ - || ObTmpFileGlobal::INVALID_PAGE_ID != level_page_range_array_.at(i).start_page_id_ - || ObTmpFileGlobal::INVALID_PAGE_ID != level_page_range_array_.at(i).end_page_id_ - || ObTmpFileGlobal::INVALID_PAGE_ID != level_page_range_array_.at(i).flushed_end_page_id_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected level_page_range_array_", KR(ret), K(fd_), K(level_page_range_array_), K(i)); - } - } - return ret; -} - -//total_need_flush_rightmost_page_num will not consider "is_writing_ = true" or "ObTmpFileTreeEvictType" -int ObSharedNothingTmpFileMetaTree::get_need_flush_page_num( - int64_t &total_need_flush_page_num, - int64_t &total_need_flush_rightmost_page_num) const -{ - int ret = OB_SUCCESS; - total_need_flush_page_num = 0; - total_need_flush_rightmost_page_num = 0; - SpinRLockGuard guard(lock_); - ARRAY_FOREACH_N(level_page_range_array_, level, level_cnt) { - const uint32_t start_page_id = level_page_range_array_[level].start_page_id_; - const uint32_t flushed_end_page_id = level_page_range_array_[level].flushed_end_page_id_; - const uint32_t end_page_id = level_page_range_array_[level].end_page_id_; - if (ObTmpFileGlobal::INVALID_PAGE_ID != start_page_id) { - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == end_page_id)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected end_page_id", KR(ret), K(fd_), K(level_page_range_array_), K(level)); - } else { - uint32_t cur_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int32_t level_page_index = level_page_range_array_[level].flushed_page_num_; - if (ObTmpFileGlobal::INVALID_PAGE_ID == flushed_end_page_id) { - cur_page_id = start_page_id; - } else { - cur_page_id = flushed_end_page_id; - level_page_index--; - } - while (OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id) { - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageUniqKey page_key(level, level_page_index); - if (wbp_->is_dirty(fd_, cur_page_id, page_key)) { - total_need_flush_page_num++; - if (end_page_id == cur_page_id) { - total_need_flush_rightmost_page_num++; - break; - } - } - if (OB_FAIL(wbp_->get_next_page_id(fd_, cur_page_id, page_key, next_page_id))) { - } else { - cur_page_id = next_page_id; - level_page_index++; - } - } - if (OB_SUCC(ret) && end_page_id != cur_page_id && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected cur_page_id", KR(ret), K(fd_), K(cur_page_id), - K(level_page_range_array_), K(level)); - } - } - } - } - return ret; -} - -//total_need_evict_rightmost_page_num will not consider "is_writing_ = true" or "ObTmpFileTreeEvictType" -int ObSharedNothingTmpFileMetaTree::get_need_evict_page_num( - int64_t &total_need_evict_page_num, - int64_t &total_need_evict_rightmost_page_num) const -{ - int ret = OB_SUCCESS; - total_need_evict_page_num = 0; - total_need_evict_rightmost_page_num = 0; - SpinRLockGuard guard(lock_); - ARRAY_FOREACH_N(level_page_range_array_, level, level_cnt) { - const uint32_t start_page_id = level_page_range_array_[level].start_page_id_; - const uint32_t flushed_end_page_id = level_page_range_array_[level].flushed_end_page_id_; - const uint32_t end_page_id = level_page_range_array_[level].end_page_id_; - if (ObTmpFileGlobal::INVALID_PAGE_ID != flushed_end_page_id) { - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == start_page_id - || ObTmpFileGlobal::INVALID_PAGE_ID == end_page_id)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected start_page_id or end_page_id", KR(ret), K(fd_), K(level_page_range_array_), K(level)); - } else { - uint32_t cur_page_id = start_page_id; - int32_t level_page_index = level_page_range_array_[level].evicted_page_num_; - while (OB_SUCC(ret) - && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id) { - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageUniqKey page_key(level, level_page_index); - if (OB_UNLIKELY(flushed_end_page_id != cur_page_id && !wbp_->is_cached(fd_, cur_page_id, page_key))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected cur_page_id", KR(ret), K(fd_), K(cur_page_id), K(flushed_end_page_id)); - } else if (!wbp_->is_cached(fd_, cur_page_id, page_key)) { - break; - } else if (FALSE_IT(total_need_evict_page_num++)) { - } else if (end_page_id == cur_page_id && FALSE_IT(total_need_evict_rightmost_page_num++)) { - } else if (flushed_end_page_id == cur_page_id) { - break; - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, cur_page_id, page_key, next_page_id))) { - } else { - cur_page_id = next_page_id; - level_page_index++; - } - } - if (OB_SUCC(ret) && flushed_end_page_id != cur_page_id) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected cur_page_id", KR(ret), K(fd_), K(cur_page_id), - K(level_page_range_array_), K(level)); - } - } - } - } - return ret; -} -//NOTE: This page was retrieved without locking, so it may be necessary to have a separate lock for read/write operations on write_cache -int ObSharedNothingTmpFileMetaTree::get_page_( - const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - char *&page_buff, - ObTmpPageValueHandle &p_handle) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!page_info.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(page_info)); - } else { - if (!is_page_in_write_cache(page_info)) { - bool need_load_from_disk = false; - ObTmpPageCacheKey key(page_info.block_index_, page_info.physical_page_id_); - if (OB_SUCC(ObTmpPageCache::get_instance().get_page(key, p_handle))) { - page_buff = p_handle.value_->get_buffer(); - } else if (OB_ENTRY_NOT_EXIST != ret) { - STORAGE_LOG(ERROR, "fail to read from read_cache", KR(ret), K(fd_), K(key)); - } else { - ret = OB_SUCCESS; - need_load_from_disk = true; - if (OB_FAIL(ObTmpPageCache::get_instance().load_page(key, callback_allocator_, p_handle))) { - } else { - page_buff = p_handle.value_->get_buffer(); - } - } - if (FAILEDx(check_page_(page_buff))) { - } - STORAGE_LOG(INFO, "load page from disk", KR(ret), K(fd_), K(need_load_from_disk), K(page_info), K(level_page_index)); - } else { - //still in write cache - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageUniqKey page_key(page_info.page_level_, level_page_index); - if (OB_FAIL(wbp_->read_page(fd_, page_info.buffer_page_id_, page_key, page_buff, next_page_id))) { - } - } - if (OB_SUCC(ret) && OB_ISNULL(page_buff)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_buff", KR(ret), K(fd_), KP(page_buff)); - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::check_page_(const char* const page_buff) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - ObSharedNothingTmpFileTreePageHeader page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - const uint64_t checksum = ob_crc64(page_buff + PAGE_HEADER_SIZE, ObTmpFileGlobal::ALLOC_PAGE_SIZE - PAGE_HEADER_SIZE); - if (OB_UNLIKELY(PAGE_MAGIC_NUM != page_header.magic_number_ - || checksum != page_header.checksum_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "checksum or magic_number is not equal, page is invalid", KR(ret), K(fd_), - KP(page_buff), K(page_header), K(checksum), K(PAGE_MAGIC_NUM)); - } - } - return ret; -} - -//get page and put into write cache (if not exists) -//put page_id into level_page_range_array_ -int ObSharedNothingTmpFileMetaTree::cache_page_for_write_( - const uint32_t parent_page_id, - ObSharedNothingTmpFileMetaItem &page_info) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!page_info.is_valid() - || page_info.page_level_ >= level_page_range_array_.count() - || (ObTmpFileGlobal::INVALID_PAGE_ID != parent_page_id - && page_info.page_level_ + 1 >= level_page_range_array_.count()))) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), K(page_info), K(level_page_range_array_), K(parent_page_id)); - } else { - if (!is_page_in_write_cache(page_info)) { - bool need_load_from_disk = false; - uint32_t new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - char *new_page_buff = NULL; - int32_t level_page_index = level_page_range_array_[page_info.page_level_].evicted_page_num_ - 1; - ObTmpFilePageUniqKey page_key(page_info.page_level_, level_page_index); - if (OB_UNLIKELY(!is_page_flushed(page_info) - || 0 < level_page_range_array_[page_info.page_level_].cached_page_num_ - || 0 > level_page_index - || ObTmpFileGlobal::INVALID_PAGE_ID != level_page_range_array_[page_info.page_level_].end_page_id_)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected page_info", KR(ret), K(fd_), K(page_info), K(level_page_range_array_)); - } else if (OB_FAIL(wbp_->alloc_page(fd_, page_key, new_page_id, new_page_buff))) { - } else if (FALSE_IT(stat_info_.meta_page_alloc_cnt_++)) { - } else if (OB_ISNULL(new_page_buff)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected null page buff", KR(ret), K(fd_), KP(new_page_buff)); - } else if (OB_FAIL(wbp_->notify_load(fd_, new_page_id, page_key))) { - } else { - ObTmpPageValueHandle p_handle; - ObTmpPageCacheKey key(page_info.block_index_, page_info.physical_page_id_); - if (OB_SUCC(ObTmpPageCache::get_instance().get_page(key, p_handle))) { - MEMCPY(new_page_buff, p_handle.value_->get_buffer(), ObTmpFileGlobal::ALLOC_PAGE_SIZE); - } else if (OB_ENTRY_NOT_EXIST != ret) { - STORAGE_LOG(ERROR, "fail to read from read_cache", KR(ret), K(fd_), K(key)); - } else { - ret = OB_SUCCESS; - p_handle.reset(); - need_load_from_disk = true; - if (OB_FAIL(ObTmpPageCache::get_instance().load_page(key, callback_allocator_, p_handle))) { - } else { - MEMCPY(new_page_buff, p_handle.value_->get_buffer(), ObTmpFileGlobal::ALLOC_PAGE_SIZE); - } - } - if (FAILEDx(check_page_(new_page_buff))) { - } - if (OB_SUCC(ret)) { - //change page state to cached - if (OB_FAIL(wbp_->notify_load_succ(fd_, new_page_id, page_key))) { - } - } else { - int tmp_ret = OB_SUCCESS; - //change page state to invalid - if (OB_TMP_FAIL(wbp_->notify_load_fail(fd_, new_page_id, page_key))) { - } - } - p_handle.reset(); - } - if (OB_SUCC(ret)) { - int64_t origin_block_index = page_info.block_index_; - int16_t origin_physical_page_id = page_info.physical_page_id_; - page_info.buffer_page_id_ = new_page_id; - page_info.block_index_ = ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - page_info.physical_page_id_ = -1; - if (ObTmpFileGlobal::INVALID_PAGE_ID == parent_page_id) { - root_item_ = page_info; - } else { - char *parent_page_buff = NULL; - uint32_t next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - ObSharedNothingTmpFileTreePageHeader page_header; - int32_t parent_level_page_index = level_page_range_array_[page_info.page_level_ + 1].evicted_page_num_ - + level_page_range_array_[page_info.page_level_ + 1].cached_page_num_ - 1; - ObTmpFilePageUniqKey parent_page_offset(page_info.page_level_ + 1, parent_level_page_index); - if (OB_FAIL(wbp_->read_page(fd_, parent_page_id, parent_page_offset, parent_page_buff, next_page_id))) { - } else if (OB_FAIL(read_page_header_(parent_page_buff, page_header))) { - } else if (OB_FAIL(rewrite_item_(parent_page_buff, page_header.item_num_ - 1, page_info))) { - } else if (OB_FAIL(wbp_->notify_dirty(fd_, parent_page_id, parent_page_offset))) { - } - } - if (OB_SUCC(ret)) { - int16_t page_level = page_info.page_level_; - if (OB_FAIL(wbp_->notify_dirty(fd_, new_page_id, page_key))) { - } else if (OB_FAIL(release_tmp_file_page_(origin_block_index, origin_physical_page_id, 1))) { - } else { - level_page_range_array_[page_level].start_page_id_ = new_page_id; - level_page_range_array_[page_level].end_page_id_ = new_page_id; - level_page_range_array_[page_level].cached_page_num_++; - level_page_range_array_[page_level].evicted_page_num_--; - level_page_range_array_[page_level].flushed_page_num_--; - } - } - } else if (ObTmpFileGlobal::INVALID_PAGE_ID != new_page_id) { //fail - uint32_t unused_next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(wbp_->free_page(fd_, new_page_id, page_key, unused_next_page_id))) { - } else { - stat_info_.meta_page_free_cnt_++; - } - } - STORAGE_LOG(INFO, "load page to write cache", KR(ret), K(fd_), K(need_load_from_disk), K(page_info), K(page_key)); - } else { - //still in write cache - //do nothing - } - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::init_page_header_( - char* page_buff, - const int16_t page_level) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - ObSharedNothingTmpFileTreePageHeader page_header; - page_header.item_num_ = 0; - page_header.page_level_ = page_level; - page_header.magic_number_ = PAGE_MAGIC_NUM; - MEMCPY(page_buff, &page_header, PAGE_HEADER_SIZE); - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::read_page_header_( - const char* page_buff, - ObSharedNothingTmpFileTreePageHeader &page_header) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(NULL == page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - } - return ret; -} - -int ObSharedNothingTmpFileMetaTree::remove_page_item_from_tail_( - char* page_buff, - const int16_t remove_item_num) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(NULL == page_buff - || 0 > remove_item_num)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff), K(remove_item_num)); - } else { - ObSharedNothingTmpFileTreePageHeader page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - page_header.item_num_ -= remove_item_num; - if (OB_UNLIKELY(page_header.item_num_ < 0)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), K(fd_), K(page_header)); - } else { - MEMCPY(page_buff, &page_header, PAGE_HEADER_SIZE); - } - } - return ret; -} - -template -int ObSharedNothingTmpFileMetaTree::read_item_( - const char* page_buff, - const int64_t target_virtual_page_id, - int16_t &item_index, - ItemType &item) -{ - int ret = OB_SUCCESS; - item_index = -1; - item.reset(); - ObSharedNothingTmpFileTreePageHeader page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - int16_t item_num = page_header.item_num_; - if (OB_UNLIKELY(NULL == page_buff - || target_virtual_page_id < 0)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff), K(target_virtual_page_id)); - } else if (OB_UNLIKELY(PAGE_HEADER_SIZE + item_num * sizeof(item) > ObTmpFileGlobal::ALLOC_PAGE_SIZE - || item_num > MAX_PAGE_ITEM_COUNT)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num", KR(ret), K(fd_), K(page_header)); - } else { - int16_t left = 0; - int16_t right = item_num - 1; - const char *items_buff = page_buff + PAGE_HEADER_SIZE; - //find the last index less than or equal to the target_virtual_page_id - while (left <= right) { - int16_t mid = (left + right) / 2; - ItemType mid_item = *((ItemType *)(items_buff + mid * sizeof(item))); - if (OB_UNLIKELY(!mid_item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected mid item", KR(ret), K(fd_), K(mid_item)); - } else if (mid_item.virtual_page_id_ <= target_virtual_page_id) { - left = mid + 1; - } else { - right = mid - 1; - } - } - if (OB_UNLIKELY(right < 0)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected dichotomy result", KR(ret), K(fd_), K(right)); - } else { - item_index = right; - item = *((ItemType *)(items_buff + item_index * sizeof(item))); - if (OB_UNLIKELY(!item.is_valid())) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item", KR(ret), K(fd_), K(item)); - } else if (item.virtual_page_id_ > target_virtual_page_id) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected virtual_page_id", KR(ret), K(fd_), K(item), K(target_virtual_page_id)); - } - } - } - if (OB_FAIL(ret)) { - //print page content - ObSharedNothingTmpFileTreePageHeader tmp_page_header; - ItemType first_item; - ItemType last_item; - read_page_simple_content_(page_buff, tmp_page_header, first_item, last_item); - STORAGE_LOG(WARN, "fail to read item, dump tree page", KR(ret), K(fd_), KP(page_buff), K(target_virtual_page_id), - K(tmp_page_header), K(first_item), K(last_item)); - } - return ret; -} -// XXX add page physical range validation; -template -int ObSharedNothingTmpFileMetaTree::read_item_( - const char* page_buff, - const int16_t item_index, - ItemType &item) -{ - int ret = OB_SUCCESS; - item.reset(); - ObSharedNothingTmpFileTreePageHeader page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - if (OB_UNLIKELY(NULL == page_buff - || item_index < 0 - || item_index >= page_header.item_num_ - || PAGE_HEADER_SIZE + page_header.item_num_ * sizeof(item) > ObTmpFileGlobal::ALLOC_PAGE_SIZE - || PAGE_HEADER_SIZE + (item_index + 1) * sizeof(item) > ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff), K(item_index), K(page_header)); - } else { - const char *items_buff = page_buff + PAGE_HEADER_SIZE; - item = *((ItemType *)(items_buff + item_index * sizeof(item))); - } - return ret; -} - -template -int ObSharedNothingTmpFileMetaTree::rewrite_item_( - char* page_buff, - const int16_t item_index, - const ItemType &item) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(NULL == page_buff - || item_index < 0 - || PAGE_HEADER_SIZE + (item_index + 1) * sizeof(item) > ObTmpFileGlobal::ALLOC_PAGE_SIZE - || !item.is_valid())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff), K(item_index), K(item)); - } else { - char *items_buff = page_buff + PAGE_HEADER_SIZE; - MEMCPY(items_buff + item_index * sizeof(item), &item, sizeof(item)); - } - return ret; -} - -template -int ObSharedNothingTmpFileMetaTree::write_items_( - char* page_buff, - const ObIArray &items, - const int64_t begin_index, - int16_t &count) -{ - int ret = OB_SUCCESS; - count = 0; - if (OB_UNLIKELY(NULL == page_buff - || items.empty() - || begin_index < 0 - || begin_index >= items.count())) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff), K(items), K(begin_index)); - } else { - ObSharedNothingTmpFileTreePageHeader page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - char *items_buff = page_buff + PAGE_HEADER_SIZE; - int16_t item_index = page_header.item_num_; - for (int64_t i = begin_index; i < items.count() - && PAGE_HEADER_SIZE + (item_index + 1) * sizeof(items.at(i)) <= ObTmpFileGlobal::ALLOC_PAGE_SIZE && item_index < MAX_PAGE_ITEM_COUNT; i++) { - MEMCPY(items_buff + item_index * sizeof(items.at(i)), &items.at(i), sizeof(items.at(i))); - item_index++; - count++; - } - page_header.item_num_ = item_index; - MEMCPY(page_buff, &page_header, PAGE_HEADER_SIZE); - } - return ret; -} - - -template -void ObSharedNothingTmpFileMetaTree::read_page_content_( - const char *page_buff, - ObSharedNothingTmpFileTreePageHeader &page_header, - ObIArray &items) -{ - int ret = OB_SUCCESS; - items.reset(); - if (OB_ISNULL(page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - const char *items_buff = page_buff + PAGE_HEADER_SIZE; - int16_t index = 0; - page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - while (OB_SUCC(ret) - && index < page_header.item_num_ - && PAGE_HEADER_SIZE + (index + 1) * sizeof(ItemType) <= ObTmpFileGlobal::ALLOC_PAGE_SIZE) { - ItemType item = *((ItemType *)(items_buff + index * sizeof(ItemType))); - if (OB_FAIL(items.push_back(item))) { - } else { - index++; - } - } - } -} - -template -void ObSharedNothingTmpFileMetaTree::read_page_simple_content_( - const char *page_buff, - ObSharedNothingTmpFileTreePageHeader &page_header, - ItemType &first_item, - ItemType &last_item) -{ - int ret = OB_SUCCESS; - first_item.reset(); - last_item.reset(); - if (OB_ISNULL(page_buff)) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(ERROR, "invalid argument", KR(ret), K(fd_), KP(page_buff)); - } else { - const char *items_buff = page_buff + PAGE_HEADER_SIZE; - page_header = *((ObSharedNothingTmpFileTreePageHeader *)(page_buff)); - if (OB_UNLIKELY(0 > page_header.item_num_ - || PAGE_HEADER_SIZE + page_header.item_num_ * sizeof(ItemType) > ObTmpFileGlobal::ALLOC_PAGE_SIZE)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected item_num_", KR(ret), K(fd_), KP(page_buff), K(page_header)); - } else if (0 == page_header.item_num_) { - } else { - first_item = *((ItemType *)(items_buff)); - last_item = *((ItemType *)(items_buff + (page_header.item_num_ - 1) * sizeof(ItemType))); - } - } -} - -int ObSharedNothingTmpFileMetaTree::copy_info(ObSNTmpFileInfo &tmp_file_info) -{ - int ret = OB_SUCCESS; - const int64_t abs_timeout_us = ObTimeUtility::current_time() + 100 * 1000L; - if (OB_FAIL(lock_.rdlock(abs_timeout_us))) { - } else { - int64_t cached_page_num = 0; - int64_t total_page_num = 0; - for (int16_t i = 0; i < level_page_range_array_.count(); i++) { - cached_page_num += level_page_range_array_.at(i).cached_page_num_; - total_page_num += level_page_range_array_.at(i).cached_page_num_ + level_page_range_array_.at(i).evicted_page_num_; - } - tmp_file_info.meta_tree_epoch_ = tree_epoch_; - tmp_file_info.meta_tree_level_cnt_ = level_page_range_array_.count(); - tmp_file_info.meta_size_ = total_page_num * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - tmp_file_info.cached_meta_page_num_ = cached_page_num; - tmp_file_info.write_back_meta_page_num_ = stat_info_.meta_page_flushing_cnt_; - tmp_file_info.all_type_page_flush_cnt_ = stat_info_.all_type_page_flush_cnt_; - lock_.rdunlock(); - } - return ret; -} - -} -} diff --git a/src/storage/tmp_file/ob_tmp_file_meta_tree.h b/src/storage/tmp_file/ob_tmp_file_meta_tree.h deleted file mode 100644 index 5b49845713..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_meta_tree.h +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_META_TREE_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_META_TREE_H_ - -#include "lib/container/ob_se_array.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool.h" -#include "storage/tmp_file/ob_tmp_file_global.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -class ObTmpPageValueHandle; -class ObSNTmpFileInfo; -class ObTmpFileBlockManager; - -struct ObSharedNothingTmpFileMetaItem -{ -public: - ObSharedNothingTmpFileMetaItem() : - page_level_(-1), - physical_page_id_(-1), - buffer_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - block_index_(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX), - virtual_page_id_(-1) {} - bool is_valid() const - { - return page_level_ >= 0 - && virtual_page_id_ >= 0; - } - void reset() - { - page_level_ = -1; - physical_page_id_ = -1; - buffer_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - block_index_ = ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - virtual_page_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } - int16_t page_level_; // child page level - int16_t physical_page_id_; // child page id within the macroblock - uint32_t buffer_page_id_; // child page in the write cache's page id - int64_t block_index_; // child page corresponding macro block index - int64_t virtual_page_id_; // child page corresponding file logical page number minimum value (i.e., index) - TO_STRING_KV(K(page_level_), K(buffer_page_id_), K(physical_page_id_), - K(block_index_), K(virtual_page_id_)); -}; // 24B - -struct ObSharedNothingTmpFileDataItem -{ - ObSharedNothingTmpFileDataItem() : - block_index_(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX), - physical_page_id_(-1), - physical_page_num_(0), - virtual_page_id_(-1) {} - bool operator!=(const ObSharedNothingTmpFileDataItem &other) const - { - return other.block_index_ != block_index_ - || other.physical_page_id_ != physical_page_id_ - || other.physical_page_num_ != physical_page_num_ - || other.virtual_page_id_ != virtual_page_id_; - } - bool is_valid() const - { - return ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX != block_index_ - && physical_page_id_ >= 0 - && physical_page_num_ > 0 //data item must be cleaned up if physical_page_num_ = 0 - && virtual_page_id_ >= 0; - } - void reset() - { - block_index_ = ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - physical_page_id_ = -1; - physical_page_num_ = 0; - virtual_page_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - } - int64_t block_index_; // the macro block block index where the data extent is flushed to disk - int16_t physical_page_id_; // start page id of the data extent in the macroblock when flushing to disk - int16_t physical_page_num_; // The number of continuous pages of the data extent in the macroblock - int64_t virtual_page_id_; // Logical page number (offset position) of the data extent in the entire file when flushed to disk - TO_STRING_KV(K(block_index_), K(physical_page_id_), - K(physical_page_num_), K(virtual_page_id_)); -}; // 24B - -struct ObSharedNothingTmpFileTreePageHeader -{ - ObSharedNothingTmpFileTreePageHeader() : - page_level_(-1), - item_num_(0), - magic_number_(0), - checksum_(0) {} - int16_t page_level_; - int16_t item_num_; - uint32_t magic_number_; - uint64_t checksum_; - TO_STRING_KV(K(page_level_), K(item_num_), K(magic_number_), K(checksum_)); -}; - -struct ObTmpFileTreeIOInfo -{ - ObTmpFileTreeIOInfo() :tree_epoch_(-1), block_index_(ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX), - flush_start_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - flush_start_level_page_index_(-1), - flush_end_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - physical_start_page_id_(-1), - flush_nums_(0), - page_level_(-1) {} - void reset() - { - tree_epoch_ = -1; - block_index_ = ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX; - flush_start_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - flush_start_level_page_index_ = -1; - flush_end_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - physical_start_page_id_ = -1; - flush_nums_ = 0; - page_level_ = -1; - } - bool is_valid() const - { - return 0 <= tree_epoch_ - && ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX != block_index_ - && ObTmpFileGlobal::INVALID_PAGE_ID != flush_start_page_id_ - && 0 <= flush_start_level_page_index_ - && ObTmpFileGlobal::INVALID_PAGE_ID != flush_end_page_id_ - && physical_start_page_id_ >= 0 - && flush_nums_ > 0 - && page_level_ >= 0; - } - int64_t tree_epoch_; - int64_t block_index_; // block index where the dirty page resides - uint32_t flush_start_page_id_; // start page id of dirty pages in write cache - int32_t flush_start_level_page_index_; // start page index of flushing in its level - uint32_t flush_end_page_id_; // flush the last page's page_id in write cache - int16_t physical_start_page_id_; // This batch of pages' start page id in the block (physical offset) - int16_t flush_nums_; // the number of dirty pages to flush - int16_t page_level_; // the metadata tree level to which the dirty page belongs - TO_STRING_KV(K(tree_epoch_), K(block_index_), K(flush_start_page_id_), - K(flush_start_level_page_index_), K(flush_end_page_id_), - K(physical_start_page_id_), K(flush_nums_), K(page_level_)); -}; - -struct ObTmpFileTreeFlushContext -{ - ObTmpFileTreeFlushContext() : tree_epoch_(-1), - is_meta_reach_end_(false), - last_flush_level_(-1), - last_flush_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - last_flush_page_index_in_level_(-1) {} - void reset() - { - tree_epoch_ = -1; - is_meta_reach_end_ = false; - last_flush_level_ = -1; - last_flush_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - last_flush_page_index_in_level_ = -1; - } - bool is_valid() const - { - return tree_epoch_ >= 0 - && last_flush_level_ >= 0 - && ObTmpFileGlobal::INVALID_PAGE_ID != last_flush_page_id_ - && last_flush_page_index_in_level_ >= 0; - } - int64_t tree_epoch_; - bool is_meta_reach_end_; - int16_t last_flush_level_; - uint32_t last_flush_page_id_; - int32_t last_flush_page_index_in_level_; - TO_STRING_KV(K(tree_epoch_), K(is_meta_reach_end_), K(last_flush_level_), K(last_flush_page_id_), - K(last_flush_page_index_in_level_)); -}; - -enum ObTmpFileTreeEvictType : int16_t -{ - INVALID = -1, - FULL = 0, //flush all pages - MAJOR, //flush all pages except rightmost page of each level -}; - -class ObSharedNothingTmpFileMetaTree -{ -public: - struct LevelPageRangeInfo - { - LevelPageRangeInfo() : start_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - flushed_end_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - end_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - cached_page_num_(0), - flushed_page_num_(0), - evicted_page_num_(0) {} - LevelPageRangeInfo(const uint32_t start_page_id, - const uint32_t flushed_page_id, - const uint32_t end_page_id, - const int32_t cached_page_num, - const int32_t flushed_page_num, - const int32_t evicted_page_num) : - start_page_id_(start_page_id), - flushed_end_page_id_(flushed_page_id), - end_page_id_(end_page_id), - cached_page_num_(cached_page_num), - flushed_page_num_(flushed_page_num), - evicted_page_num_(evicted_page_num) {} - uint32_t start_page_id_; - uint32_t flushed_end_page_id_; - uint32_t end_page_id_; - //Rules: - // cached_page_num_ + evicted_page_num_ = level total page num - // flushed_page_num_ >= evicted_page_num_ - // flushed_pages must contail evicted_pages, but maybe some cached_pages. - // cached_pages -> [start_page_id_, end_page_id_] - // flushed_pages -> [start_page_id_, flushed_end_page_id_] or none(depnds on whether flushed_end_page_id_ is valid or not) - // They do not contain duplicate pages, even if the page is cached/flushed/evicted multiple times. - int32_t cached_page_num_; - int32_t flushed_page_num_; - int32_t evicted_page_num_; - TO_STRING_KV(K(start_page_id_), K(flushed_end_page_id_), K(end_page_id_), - K(cached_page_num_), K(flushed_page_num_), K(evicted_page_num_)); - }; - - struct BacktraceNode - { - BacktraceNode() : page_meta_info_(), - level_page_index_(-1), - prev_item_index_(-1) {} - BacktraceNode(const ObSharedNothingTmpFileMetaItem &item, - const int32_t level_page_index, - const int16_t prev_item_index) - : page_meta_info_(item), - level_page_index_(level_page_index), - prev_item_index_(prev_item_index) {} - bool is_valid() const - { - return page_meta_info_.is_valid() - && 0 <= level_page_index_; - } - //corresponding to a page (represent meta info of the page) - ObSharedNothingTmpFileMetaItem page_meta_info_; - //the page index in its level - int32_t level_page_index_; - //prev processed item index on the page - int16_t prev_item_index_; - TO_STRING_KV(K(page_meta_info_), K(level_page_index_), K(prev_item_index_)); - }; - - struct LastTruncateLeafInfo - { - LastTruncateLeafInfo() : page_index_in_leaf_level_(-1), - item_index_in_page_(-1), - release_to_end_in_page_(false) {} - bool is_valid() const - { - return 0 <= page_index_in_leaf_level_ - && 0 <= item_index_in_page_; - } - void reset() - { - page_index_in_leaf_level_ = -1; - item_index_in_page_ = -1; - release_to_end_in_page_ = false; - } - int32_t page_index_in_leaf_level_; - int16_t item_index_in_page_; - bool release_to_end_in_page_; - TO_STRING_KV(K(page_index_in_leaf_level_), K(item_index_in_page_), K(release_to_end_in_page_)); - }; - - struct StatInfo - { - StatInfo() : meta_page_flushing_cnt_(0), - all_type_page_flush_cnt_(0), - all_type_flush_page_released_cnt_(0), - meta_page_alloc_cnt_(0), - meta_page_free_cnt_(0) {} - void reset() - { - meta_page_flushing_cnt_ = 0; - all_type_page_flush_cnt_ = 0; - all_type_flush_page_released_cnt_ = 0; - meta_page_alloc_cnt_ = 0; - meta_page_free_cnt_ = 0; - } - int64_t meta_page_flushing_cnt_; - //can contain the same page if page is flushed again - // contain total pages(meta and data) - int64_t all_type_page_flush_cnt_; - int64_t all_type_flush_page_released_cnt_; - //alloc and free in write cache - int64_t meta_page_alloc_cnt_; - int64_t meta_page_free_cnt_; - TO_STRING_KV(K(meta_page_flushing_cnt_), K(all_type_page_flush_cnt_), K(all_type_flush_page_released_cnt_), - K(meta_page_alloc_cnt_), K(meta_page_free_cnt_)); - }; - -public: - ObSharedNothingTmpFileMetaTree(); - ~ObSharedNothingTmpFileMetaTree(); - void reset(); -public: - int init(const int64_t fd, ObTmpWriteBufferPool *wbp, ObIAllocator *callback_allocator, ObTmpFileBlockManager *block_manager); - - //append write: We always write the rightmost page of the leaf layer - //It happens after a tmp file write request: - // data pages of a write request is persisted on disk - int prepare_for_insert_items(); - int insert_items(const common::ObIArray &data_items); - - //It happens when there is a tmp file read request - int search_data_items(const int64_t offset, - const int64_t read_size, - common::ObIArray &data_items); - - //It happens when there is a meta tree pages flush request: - // tmp file data and meta pages are aggregated to flush - int flush_meta_pages_for_block(const int64_t block_index, - const ObTmpFileTreeEvictType flush_type, - char *block_buff, - int64_t &write_offset, - ObTmpFileTreeFlushContext &flush_context, - common::ObIArray &meta_io_array); - - //It happens after meta tree pages flush: - // meta pages is persisted on disk successfully - int update_after_flush(const common::ObIArray &meta_io_array); - - //It happens when there is a tmp file write request: - // a tmp file page that is not full need to be continued writing. - //last_data_item is the page info of the unfilled data page. - int prepare_for_write_tail(ObSharedNothingTmpFileDataItem &last_data_item); - // After the tail is written (the tail page exists in disk) - int finish_write_tail(const ObSharedNothingTmpFileDataItem &last_data_item, - const bool release_tail_in_disk); - - //It happens when there is a tmp file eviction - int evict_meta_pages(const int64_t expected_page_num, - const ObTmpFileTreeEvictType flush_type, - int64_t &actual_evict_page_num); - - //it happens when there is a tmp file clearing - int clear(const int64_t last_truncate_offset, const int64_t total_file_size); - - //it happens when there is a need to truncate a tmp file - int truncate(const int64_t last_truncate_offset, const int64_t end_truncate_offset); - - //get the num of tree pages that need to be flushed - int get_need_flush_page_num(int64_t &total_need_flush_page_num, - int64_t &total_need_flush_rightmost_page_num) const; - //get the num of tree pages that need to be evicted - int get_need_evict_page_num(int64_t &total_need_evict_page_num, - int64_t &total_need_evict_rightmost_page_num) const; - //for virtual table to show - int copy_info(ObSNTmpFileInfo &tmp_file_info); - -private: - int modify_meta_items_at_parent_level_(const ObTmpFileTreeIOInfo &meta_io, - const int32_t start_page_index_in_level); - int truncate_array_(const int64_t end_offset); - int search_data_items_from_array_(const int64_t end_offset, - int64_t &cur_offset, - common::ObIArray &data_items); - int get_items_of_internal_page_(const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - const int16_t cur_item_index, - const int64_t end_offset, - bool &is_last_item, - ObIArray &meta_items); - int backtrace_truncate_tree_(const int64_t end_offset, - ObIArray &search_path, - ObIArray &reserved_meta_items, - ObIArray &p_handles); - int backtrace_search_data_items_(const int64_t end_offset, - int64_t &offset, - ObIArray &search_path, - ObIArray &data_items); - int finish_insert_(const int return_ret, - ObIArray &level_origin_page_write_counts, - ObIArray> &level_new_pages); - int try_to_insert_items_to_array_(const ObIArray &data_items, - ObIArray> &level_new_pages); - int release_items_of_leaf_page_(const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - const int64_t end_offset, - const int16_t begin_release_index, - bool &release_last_item); - int get_items_of_leaf_page_(const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - const int64_t end_offset, - const bool need_find_index, - int64_t &cur_offset, - common::ObIArray &data_items); - virtual int release_meta_page_(const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t page_index_in_level); - virtual int release_tmp_file_page_(const int64_t block_index, - const int64_t begin_page_id, const int64_t page_num); - int get_rightmost_leaf_page_for_write_(ObSharedNothingTmpFileMetaItem &page_info); - int get_last_item_of_internal_page_(const uint32_t parent_page_id, - ObSharedNothingTmpFileMetaItem &page_info, - ObSharedNothingTmpFileMetaItem &last_meta_item); - int try_to_fill_rightmost_internal_page_(const ObIArray &meta_items, - const int16_t page_level, - int64_t &write_count, - ObIArray &level_origin_page_write_counts); - int try_to_fill_rightmost_leaf_page_(const ObIArray &data_items, - const ObIArray> &level_new_pages, - int64_t &write_count, - ObIArray &level_origin_page_write_counts); - int add_new_page_and_fill_items_at_leaf_(const ObIArray &data_items, - int64_t &write_count, - ObSharedNothingTmpFileMetaItem &meta_item, - ObIArray> &level_new_pages); - int add_new_page_and_fill_items_at_internal_(const ObIArray &meta_items, - const int16_t page_level, - int64_t &write_count, - ObSharedNothingTmpFileMetaItem &meta_item, - ObIArray> &level_new_pages); - int cascade_modification_at_internal_(const ObIArray &new_leaf_page_infos, - ObIArray &level_origin_page_write_counts, - ObIArray> &level_new_pages); - int modify_child_pages_location(char *page_buff); - int modify_meta_items_during_evict_(const ObIArray &evict_pages, - const int16_t level, - const int32_t start_page_index_in_level); - int flush_leaf_pages_(const uint32_t flush_start_page_id, - const int32_t start_page_index_in_level, - const ObTmpFileTreeEvictType flush_type, - char *block_buff, - int64_t &write_offset, - ObTmpFileTreeIOInfo &meta_io_info); - int calc_and_set_page_checksum_(char* page_buff); - int flush_internal_pages_(const uint32_t flush_start_page_id, - const int16_t level, - const int32_t start_page_index_in_level, - const ObTmpFileTreeEvictType flush_type, - char *block_buff, - int64_t &write_offset, - ObTmpFileTreeIOInfo &meta_io_info); - int get_page_(const ObSharedNothingTmpFileMetaItem &page_info, - const int32_t level_page_index, - char *&page_buff, - ObTmpPageValueHandle &p_handle); - int check_page_(const char* const page_buff); - virtual int cache_page_for_write_(const uint32_t parent_page_id, - ObSharedNothingTmpFileMetaItem &page_info); - int init_page_header_(char* page_buff, - const int16_t page_level); - int read_page_header_(const char* page_buff, - ObSharedNothingTmpFileTreePageHeader &page_header); - int remove_page_item_from_tail_(char* page_buff, - const int16_t remove_item_num); - int truncate_(const int64_t end_offset); - int calculate_truncate_index_path_(ObIArray> &item_index_arr); - template - int read_item_(const char* page_buff, - const int64_t target_virtual_page_id, - int16_t &item_index, - ItemType &item); - template - int read_item_(const char* page_buff, - const int16_t item_index, - ItemType &item); - template - int rewrite_item_(char* page_buff, - const int16_t item_index, - const ItemType &item) __attribute__((noinline)); - template - int write_items_(char* page_buff, - const ObIArray &items, - const int64_t begin_index, - int16_t &write_count); - int check_tree_is_empty_(); - template - void read_page_content_(const char *page_buff, - ObSharedNothingTmpFileTreePageHeader &page_header, - ObIArray &data_items); - template - void read_page_simple_content_(const char *page_buff, - ObSharedNothingTmpFileTreePageHeader &page_header, - ItemType &first_item, - ItemType &last_item); - inline bool is_page_in_write_cache(const ObSharedNothingTmpFileMetaItem &meta_item) - { - return ObTmpFileGlobal::INVALID_PAGE_ID != meta_item.buffer_page_id_; - } - inline bool is_page_flushed(const ObSharedNothingTmpFileMetaItem &meta_item) - { - return ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX != meta_item.block_index_ - && 0 <= meta_item.physical_page_id_; - } - -private: - //only for unittest - static void set_max_array_item_cnt(const int16_t cnt) - { - MAX_DATA_ITEM_ARRAY_COUNT = cnt; - } - static void set_max_page_item_cnt(const int16_t cnt) - { - MAX_PAGE_ITEM_COUNT = cnt; - } -private: - static const uint16_t PAGE_MAGIC_NUM; - static const int16_t PAGE_HEADER_SIZE; - static int16_t MAX_DATA_ITEM_ARRAY_COUNT; - //only for unittest - static int16_t MAX_PAGE_ITEM_COUNT; - -private: - bool is_inited_; - int64_t fd_; - ObTmpWriteBufferPool *wbp_; - ObIAllocator *callback_allocator_; - ObTmpFileBlockManager *block_manager_; - int64_t tree_epoch_; - ObSharedNothingTmpFileMetaItem root_item_; - //When the tmp file writes less data, we can use an array instead of a tree to store metadata - common::ObSEArray data_item_array_; - //level page ranges in write cache - common::ObSEArray level_page_range_array_; - //Only writing the rightmost pages - //Used to prevent the rightmost pages from being evicted - bool is_writing_; - common::SpinRWLock lock_; - LastTruncateLeafInfo last_truncate_leaf_info_; - int64_t released_offset_; -public: - StatInfo stat_info_; - //NOTE: without protection of lock_, we do not recommend using K(meta_tree_) externally. - TO_STRING_KV(K(fd_), K(tree_epoch_), K(root_item_), - K(data_item_array_), K(level_page_range_array_), K(is_writing_), - K(last_truncate_leaf_info_), K(released_offset_), K(stat_info_)); -}; - - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_META_TREE_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_page_cache_controller.cpp b/src/storage/tmp_file/ob_tmp_file_page_cache_controller.cpp deleted file mode 100644 index 97b02bb18e..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_page_cache_controller.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "rust/config.h" -#include "storage/tmp_file/ob_tmp_file_page_cache_controller.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -int ObTmpFilePageCacheController::init() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - STORAGE_LOG(WARN, "ObTmpFilePageCacheController init twice"); - } else if (OB_FAIL(task_allocator_.init(lib::ObMallocAllocator::get_instance(), - OB_MALLOC_MIDDLE_BLOCK_SIZE, - ObMemAttr("TmpFileCtl", ObCtxIds::DEFAULT_CTX_ID)))) { - } else if (OB_FAIL(flush_mgr_.init())) { - } else if (OB_FAIL(flush_priority_mgr_.init())) { - } else if (OB_FAIL(write_buffer_pool_.init())) { - } else if (OB_FAIL(flush_thread_.init())) { - } else if (OB_FAIL(swap_thread_.init())) { - } else { - flush_all_data_ = false; - is_inited_ = true; - } - return ret; -} - -int ObTmpFilePageCacheController::start() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - STORAGE_LOG(WARN, "tmp file page cache controller is not inited"); - } else if (OB_FAIL(flush_thread_.start())) { - } else if (OB_FAIL(swap_thread_.start())) { - } - return ret; -} - -void ObTmpFilePageCacheController::stop() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - STORAGE_LOG(WARN, "tmp file page cache controller is not inited"); - } else { - // stop background threads should follow the order 'swap' -> 'flush' because 'swap' holds ref to 'flush' - swap_thread_.stop(); - flush_thread_.stop(); - } -} - -void ObTmpFilePageCacheController::wait() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - STORAGE_LOG(WARN, "tmp file page cache controller is not inited"); - } else { - swap_thread_.wait(); - flush_thread_.wait(); - } -} - -void ObTmpFilePageCacheController::destroy() -{ - swap_thread_.destroy(); - flush_thread_.destroy(); - task_allocator_.reset(); - write_buffer_pool_.destroy(); - flush_mgr_.destroy(); - evict_mgr_.destroy(); - flush_priority_mgr_.destroy(); - flush_all_data_ = false; - is_inited_ = false; -} - -int ObTmpFilePageCacheController::swap_job_enqueue_(ObTmpFileSwapJob *swap_job) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(swap_job)){ - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "swap job is null", KR(ret)); - } else if (!swap_job->is_valid()) { - ret = OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "swap job is not valid", KR(ret), KPC(swap_job)); - } else if (OB_FAIL(swap_thread_.swap_job_enqueue(swap_job))) { - } - return ret; -} - -int ObTmpFilePageCacheController::free_swap_job_(ObTmpFileSwapJob *swap_job) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(swap_job)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "swap job is null", KR(ret)); - } else if (swap_job->is_inited() && !swap_job->is_finished()) { - ret = OB_EAGAIN; - STORAGE_LOG(ERROR, "swap job is not finished", KR(ret), KPC(swap_job)); - } else { - swap_job->~ObTmpFileSwapJob(); - task_allocator_.free(swap_job); - } - return ret; -} - -// Refresh the temporary-file disk limit from runtime configuration with a 10 ms timeout. -void ObTmpFilePageCacheController::refresh_disk_usage_limit() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - const int64_t max_disk_usage = config::temporary_file_max_disk_size(); - int64_t disk_limit = max_disk_usage > 0 ? max_disk_usage : 0; - ATOMIC_SET(&disk_usage_limit_, disk_limit); - } -} - -int ObTmpFilePageCacheController::invoke_swap_and_wait(int64_t expect_swap_size, int64_t timeout_ms) -{ - int ret = OB_SUCCESS; - - int64_t mem_limit = write_buffer_pool_.get_memory_limit(); - int64_t min_swap_size = - max(ObTmpFileGlobal::ALLOC_PAGE_SIZE, min(expect_swap_size, static_cast(0.2 * mem_limit))); - expect_swap_size = upper_align(min_swap_size, ObTmpFileGlobal::ALLOC_PAGE_SIZE); - - void *task_buf = nullptr; - ObTmpFileSwapJob *swap_job = nullptr; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "tmp file page cache controller is not inited", KR(ret)); - } else if (OB_ISNULL(task_buf = task_allocator_.alloc(sizeof(ObTmpFileSwapJob)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - STORAGE_LOG(WARN, "fail to allocate memory for swap job", KR(ret)); - } else if (FALSE_IT(swap_job = new (task_buf) ObTmpFileSwapJob())) { - } else if (OB_FAIL(swap_job->init(expect_swap_size, timeout_ms))) { - } else if (OB_FAIL(swap_job_enqueue_(swap_job))) { - } else { - swap_thread_.notify_doing_swap(); - if (OB_FAIL(swap_job->wait_swap_complete())) { - } - } - - if (OB_NOT_NULL(swap_job)) { - if (OB_SUCCESS != swap_job->get_ret_code()) { - ret = swap_job->get_ret_code(); - STORAGE_LOG(WARN, "swap job complete with error code", KR(ret)); - } - // reset swap job to set is_finished to false in case of failure to push into queue: - // otherwise job is not finished, but it will not be executed, so it will never become finished. - swap_job->reset(); - int tmp_ret = OB_SUCCESS; - if (OB_TMP_FAIL(free_swap_job_(swap_job))) { - } - } - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_page_cache_controller.h b/src/storage/tmp_file/ob_tmp_file_page_cache_controller.h deleted file mode 100644 index 8a3602c8f2..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_page_cache_controller.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_PAGE_CACHE_CONTROLLER_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_PAGE_CACHE_CONTROLLER_H_ - -#include "storage/tmp_file/ob_tmp_file_thread_wrapper.h" -#include "storage/tmp_file/ob_tmp_file_flush_manager.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFilePageCacheController -{ -public: - ObTmpFilePageCacheController(ObTmpFileBlockManager &tmp_file_block_manager) - : is_inited_(false), - flush_all_data_(false), - disk_usage_limit_(0), - tmp_file_block_manager_(tmp_file_block_manager), - task_allocator_(), - write_buffer_pool_(), - flush_priority_mgr_(), - evict_mgr_(), - flush_mgr_(*this), - flush_thread_(write_buffer_pool_, flush_mgr_, task_allocator_, tmp_file_block_manager_), - swap_thread_(write_buffer_pool_, evict_mgr_, flush_thread_, *this) - { - } - ~ObTmpFilePageCacheController() {} -public: - static const int64_t FLUSH_FAST_INTERVAL = 5; // 5ms - static const int64_t FLUSH_INTERVAL = 1000; // 1s - static const int64_t SWAP_FAST_INTERVAL = 5; // 5ms - static const int64_t SWAP_INTERVAL = 1000; // 1s - static const int64_t REFRESH_CONFIG_INTERVAL = 10 * 1000 * 1000; // 10s - virtual int init(); - int start(); - void stop(); - void wait(); - void destroy(); - ObIAllocator &get_task_allocator() { return task_allocator_; } - ObTmpWriteBufferPool &get_write_buffer_pool() { return write_buffer_pool_; } - ObTmpFileFlushManager &get_flush_task_mgr() { return flush_mgr_; } - ObTmpFileEvictionManager &get_eviction_manager() { return evict_mgr_; } - ObTmpFileFlushPriorityManager &get_flush_priority_mgr() { return flush_priority_mgr_; } - ObTmpFileBlockManager &get_tmp_file_block_manager() { return tmp_file_block_manager_; } - OB_INLINE bool is_flush_all_data() { return ATOMIC_LOAD(&flush_all_data_); } - OB_INLINE void set_flush_all_data(bool flush_all_data) { ATOMIC_STORE(&flush_all_data_, flush_all_data); } - OB_INLINE int64_t get_disk_usage_limit() const { return ATOMIC_LOAD(&disk_usage_limit_); } - virtual int invoke_swap_and_wait(int64_t expect_swap_size, int64_t timeout_ms = ObTmpFileSwapJob::DEFAULT_TIMEOUT_MS); - void refresh_disk_usage_limit(); -private: - int swap_job_enqueue_(ObTmpFileSwapJob *swap_job); - int free_swap_job_(ObTmpFileSwapJob *swap_job); - DISALLOW_COPY_AND_ASSIGN(ObTmpFilePageCacheController); -private: - bool is_inited_; - bool flush_all_data_; // set to true to flush all pages when shrinking write buffer pool - int64_t disk_usage_limit_; // Periodically refreshed from runtime configuration. - ObTmpFileBlockManager &tmp_file_block_manager_; // ref to ObTmpFileBlockManager - ObFIFOAllocator task_allocator_; // used by flush_mgr_ to allocate flush tasks - ObTmpWriteBufferPool write_buffer_pool_; - ObTmpFileFlushPriorityManager flush_priority_mgr_; - ObTmpFileEvictionManager evict_mgr_; // maintain evict lists and evict pages from write buffer pool - ObTmpFileFlushManager flush_mgr_; // maintain flush lists and generate flush tasks - ObTmpFileFlushThread flush_thread_; // flush thread - ObTmpFileSwapThread swap_thread_; // swap thread -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_PAGE_CACHE_CONTROLLER_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_thread_job.cpp b/src/storage/tmp_file/ob_tmp_file_thread_job.cpp deleted file mode 100644 index 9d111f2956..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_thread_job.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_thread_job.h" -#include "lib/utility/utility.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -int ObTmpFileSwapJob::init(int64_t expect_swap_size, uint32_t timeout_ms) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - STORAGE_LOG(WARN, "ObTmpFileSwapJob init twice", KR(ret)); - } else if (timeout_ms <= 0) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(swap_cond_.init(ObWaitEventIds::THREAD_IDLING_COND_WAIT))) { - } else { - is_inited_ = true; - ret_code_ = OB_SUCCESS; - is_finished_ = false; - expect_swap_size_ = expect_swap_size; - timeout_ms_ = timeout_ms; - create_ts_ = ObTimeUtility::current_time(); - abs_timeout_ts_ = ObTimeUtility::current_time() + timeout_ms_ * 1000; - } - return ret; -} - -void ObTmpFileSwapJob::reset() -{ - is_inited_ = false; - ret_code_ = OB_SUCCESS; - is_finished_ = false; - expect_swap_size_ = 0; - timeout_ms_ = DEFAULT_TIMEOUT_MS; - create_ts_ = 0; - abs_timeout_ts_ = 0; - swap_cond_.destroy(); -} - -// waits for swap job to finish, loop inside until is_finished_ is true -int ObTmpFileSwapJob::wait_swap_complete() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileSwapJob not init", KR(ret)); - } else { - bool is_finished = false; - ObThreadCondGuard guard(swap_cond_); - while (false == (is_finished = ATOMIC_LOAD(&is_finished_))) { - if (OB_FAIL(swap_cond_.wait())) { - if (OB_TIMEOUT == ret) { - STORAGE_LOG(WARN, "fail to wait swap job complete", KR(ret), K(is_finished), K(timeout_ms_)); - ret = OB_SUCCESS; - } else { - STORAGE_LOG(ERROR, "fail to wait swap job thread cond", KR(ret), K(is_finished), KPC(this)); - } - } - } - } - return ret; -} - -// set swap job is_finished, wake up threads that invoke swap job -int ObTmpFileSwapJob::signal_swap_complete(int ret_code) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileSwapJob not init", KR(ret)); - } else { - ObThreadCondGuard guard(swap_cond_); - ATOMIC_SET(&ret_code_, ret_code); - ATOMIC_SET(&is_finished_, true); - if (OB_FAIL(swap_cond_.signal())) { - } - } - return ret; -} - -void ObTmpFileFlushMonitor::reset() -{ - flush_task_cnt_ = 0; - total_flushing_data_length_ = 0; - max_flush_data_length_ = -1; - min_flush_data_length_ = INT64_MAX; - f1_cnt_ = 0; - f2_cnt_ = 0; - f3_cnt_ = 0; - f4_cnt_ = 0; - f5_cnt_ = 0; -} - -void ObTmpFileFlushMonitor::print_statistics() -{ - int64_t flush_task_cnt = flush_task_cnt_; - int64_t avg_flush_data_len = total_flushing_data_length_ / max(flush_task_cnt, 1); - int64_t max_flush_data_len = max_flush_data_length_; - int64_t min_flush_data_len = min_flush_data_length_ == INT64_MAX ? -1 : min_flush_data_length_; - int64_t f1_cnt = f1_cnt_; - int64_t f2_cnt = f2_cnt_; - int64_t f3_cnt = f3_cnt_; - int64_t f4_cnt = f4_cnt_; - int64_t f5_cnt = f5_cnt_; - STORAGE_LOG(INFO, "tmp file flush statistics", K(flush_task_cnt), K(avg_flush_data_len), - K(max_flush_data_len), K(min_flush_data_len), K(f1_cnt), K(f2_cnt), K(f3_cnt), K(f4_cnt), K(f5_cnt)); - reset(); -} - -void ObTmpFileFlushMonitor::record_flush_stage(const ObTmpFileGlobal::FlushCtxState flush_stage) -{ - switch(flush_stage) { - case ObTmpFileGlobal::FSM_F1: - f1_cnt_++; - break; - case ObTmpFileGlobal::FSM_F2: - f2_cnt_++; - break; - case ObTmpFileGlobal::FSM_F3: - f3_cnt_++; - break; - case ObTmpFileGlobal::FSM_F4: - f4_cnt_++; - break; - case ObTmpFileGlobal::FSM_F5: - f5_cnt_++; - break; - default: - break; - } -} - -void ObTmpFileFlushMonitor::record_flush_task(const int64_t data_length) -{ - flush_task_cnt_ += 1; - total_flushing_data_length_ += data_length; - if (data_length > 0 && data_length > max_flush_data_length_) { - max_flush_data_length_ = data_length; - } - if (data_length > 0 && data_length < min_flush_data_length_) { - min_flush_data_length_ = data_length; - } -} - -void ObTmpFileSwapMonitor::reset() -{ - swap_task_cnt_ = 0; - swap_total_response_time_= 0; - swap_max_response_time_ = -1; - swap_min_response_time_ = INT64_MAX; -} - -void ObTmpFileSwapMonitor::print_statistics() -{ - int64_t swap_task_cnt = swap_task_cnt_; - int64_t avg_swap_response_time = swap_total_response_time_ / max(swap_task_cnt, 1); - int64_t max_swap_response_time = swap_max_response_time_; - int64_t min_swap_response_time = swap_min_response_time_ == INT64_MAX ? -1 : swap_min_response_time_; - STORAGE_LOG(INFO, "tmp file swap statistics", K(swap_task_cnt), - K(avg_swap_response_time), K(max_swap_response_time), K(min_swap_response_time)); - reset(); -} - -void ObTmpFileSwapMonitor::record_swap_response_time(const int64_t response_time) -{ - swap_task_cnt_ += 1; - swap_total_response_time_ += response_time; - if (response_time > swap_max_response_time_) { - swap_max_response_time_ = response_time; - } - if (response_time < swap_min_response_time_) { - swap_min_response_time_ = response_time; - } -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_thread_job.h b/src/storage/tmp_file/ob_tmp_file_thread_job.h deleted file mode 100644 index 1dc04f7ffa..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_thread_job.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_THREAD_JOB_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_THREAD_JOB_H_ - -#include "lib/lock/ob_thread_cond.h" -#include "lib/queue/ob_link_queue.h" -#include "lib/utility/ob_print_utils.h" -#include "storage/tmp_file/ob_tmp_file_global.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -class ObTmpFileSwapJob : public ObSpLinkQueue::Link -{ -public: - static const uint32_t DEFAULT_TIMEOUT_MS = 10 * 1000; - ObTmpFileSwapJob() - : is_inited_(false), - ret_code_(OB_SUCCESS), - is_finished_(false), - timeout_ms_(DEFAULT_TIMEOUT_MS), - create_ts_(0), - abs_timeout_ts_(0), - expect_swap_size_(0), - swap_cond_() {} - ~ObTmpFileSwapJob() { reset(); } - int init(int64_t expect_swap_size, uint32_t timeout_ms = DEFAULT_TIMEOUT_MS); - void reset(); - int wait_swap_complete(); - int signal_swap_complete(int ret_code); - OB_INLINE int64_t get_create_ts() const { return create_ts_; } - OB_INLINE int64_t get_abs_timeout_ts() const { return abs_timeout_ts_; } - OB_INLINE int64_t get_expect_swap_size() const { return expect_swap_size_; } - OB_INLINE bool is_valid() { return ATOMIC_LOAD(&is_inited_) && swap_cond_.is_inited(); } - OB_INLINE bool is_finished() const { return ATOMIC_LOAD(&is_finished_); } - OB_INLINE bool is_inited() const { return ATOMIC_LOAD(&is_inited_); } - OB_INLINE int get_ret_code() const { return ATOMIC_LOAD(&ret_code_); } - TO_STRING_KV(KP(this), K(is_inited_), K(is_finished_), K(create_ts_), K(timeout_ms_), K(abs_timeout_ts_), K(expect_swap_size_)); -private: - bool is_inited_; - int ret_code_; - bool is_finished_; - uint32_t timeout_ms_; - int64_t create_ts_; - int64_t abs_timeout_ts_; - int64_t expect_swap_size_; // in bytes - ObThreadCond swap_cond_; -}; - -// record statistics for flush tasks in flush thread thread -class ObTmpFileFlushMonitor -{ -public: - ObTmpFileFlushMonitor() - : flush_task_cnt_(0), - total_flushing_data_length_(0), - max_flush_data_length_(-1), - min_flush_data_length_(INT64_MAX), - f1_cnt_(0), - f2_cnt_(0), - f3_cnt_(0), - f4_cnt_(0), - f5_cnt_(0) {} - void reset(); - void print_statistics(); - void record_flush_stage(const ObTmpFileGlobal::FlushCtxState flush_stage); - void record_flush_task(const int64_t data_length); -private: - int64_t flush_task_cnt_; - int64_t total_flushing_data_length_; - int64_t max_flush_data_length_; - int64_t min_flush_data_length_; - int64_t f1_cnt_; - int64_t f2_cnt_; - int64_t f3_cnt_; - int64_t f4_cnt_; - int64_t f5_cnt_; -}; - -// record statistics for swap tasks in swap thread thread -class ObTmpFileSwapMonitor -{ -public: - ObTmpFileSwapMonitor() - : swap_task_cnt_(0), - swap_total_response_time_(0), - swap_max_response_time_(-1), - swap_min_response_time_(INT64_MAX) {} - void reset(); - void print_statistics(); - void record_swap_response_time(const int64_t response_time); -private: - int64_t swap_task_cnt_; - int64_t swap_total_response_time_; - int64_t swap_max_response_time_; - int64_t swap_min_response_time_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_THREAD_JOB_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_thread_wrapper.cpp b/src/storage/tmp_file/ob_tmp_file_thread_wrapper.cpp deleted file mode 100644 index c86f4a9c26..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_thread_wrapper.cpp +++ /dev/null @@ -1,1210 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "ob_tmp_file_thread_wrapper.h" -#include "lib/thread/ob_thread_name.h" -#include "storage/meta_store/storage_meta_service.h" -#include "storage/tmp_file/ob_tmp_file_manager.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -ObTmpFileFlushThread::ObTmpFileFlushThread( - ObTmpWriteBufferPool &wbp, - ObTmpFileFlushManager &flush_mgr, - ObIAllocator &allocator, - ObTmpFileBlockManager &tmp_file_block_mgr) - : is_inited_(false), - mode_(RUNNING_MODE::INVALID), - last_flush_timestamp_(0), - flush_io_finished_ret_(OB_SUCCESS), - flush_io_finished_round_(0), - flushing_block_num_(0), - is_fast_flush_meta_(false), - fast_flush_meta_task_cnt_(0), - wait_list_size_(0), - retry_list_size_(0), - finished_list_size_(0), - wait_list_(), - retry_list_(), - finished_list_(), - flush_monitor_(), - flush_mgr_(flush_mgr), - wbp_(wbp), - tmp_file_block_mgr_(tmp_file_block_mgr), - normal_loop_cnt_(0), - normal_idle_loop_cnt_(0), - fast_loop_cnt_(0), - fast_idle_loop_cnt_(0) -{ -} - -int ObTmpFileFlushThread::init() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - STORAGE_LOG(WARN, "ObTmpFileFlushThread init twice"); - } else { - for (int32_t i = 0; OB_SUCC(ret) && i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - if (OB_FAIL(flush_timers_[i].init("TFFlush", common::ObMemAttr("TFFlush")))) { - } - } - if (OB_SUCC(ret)) { - is_inited_ = true; - mode_ = RUNNING_MODE::NORMAL; - last_flush_timestamp_ = 0; - flush_io_finished_ret_ = OB_SUCCESS; - flush_io_finished_round_ = 0; - flushing_block_num_ = 0; - - fast_flush_meta_task_cnt_ = 0; - wait_list_size_ = 0; - retry_list_size_ = 0; - finished_list_size_ = 0; - - normal_loop_cnt_ = 0; - normal_idle_loop_cnt_ = 0; - fast_loop_cnt_ = 0; - fast_idle_loop_cnt_ = 0; - } - } - - if (OB_FAIL(ret)) { - destroy(); - } - return ret; -} - -int ObTmpFileFlushThread::start() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileFlushThread not init", KR(ret)); - } else { - for (int32_t i = 0; OB_SUCC(ret) && i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - if (OB_FAIL(flush_timers_[i].start())) { - } - } - - if (OB_SUCC(ret)) { - flush_mgr_.set_flush_timers(flush_timers_, ObTmpFileGlobal::FLUSH_TIMER_CNT); - } - } - return ret; -} - -void ObTmpFileFlushThread::stop() -{ - for (int32_t i = 0; i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - if (flush_timers_[i].inited()) { - flush_timers_[i].stop(); - } - } -} - -void ObTmpFileFlushThread::wait() -{ - for (int32_t i = 0; i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - if (flush_timers_[i].inited()) { - flush_timers_[i].wait(); - } - } -} - -void ObTmpFileFlushThread::destroy() -{ - clean_up_lists(); - mode_ = RUNNING_MODE::INVALID; - last_flush_timestamp_ = 0; - flush_io_finished_ret_ = OB_SUCCESS; - flush_io_finished_round_ = 0; - flushing_block_num_ = 0; - - is_fast_flush_meta_ = false; - fast_flush_meta_task_cnt_ = 0; - wait_list_size_ = 0; - retry_list_size_ = 0; - finished_list_size_ = 0; - - normal_loop_cnt_ = 0; - normal_idle_loop_cnt_ = 0; - fast_loop_cnt_ = 0; - fast_idle_loop_cnt_ = 0; - - is_inited_ = false; - for (int32_t i = 0; i < ObTmpFileGlobal::FLUSH_TIMER_CNT; ++i) { - flush_timers_[i].destroy(); - } -} - -void ObTmpFileFlushThread::clean_up_lists() -{ - int ret = OB_SUCCESS; - while (!retry_list_.is_empty()) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_retry_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is null", KR(ret)); - } else { - STORAGE_LOG(INFO, "free flush task in retry_list_", KPC(flush_task)); - flush_mgr_.free_flush_task(flush_task); - } - } - - while (!finished_list_.is_empty()) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_finished_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is null", KR(ret)); - } else { - STORAGE_LOG(INFO, "free flush task in finished_list_", KPC(flush_task)); - flush_mgr_.free_flush_task(flush_task); - } - } - - while (!wait_list_.is_empty()) { // clean up tasks after IO complete - STORAGE_LOG(WARN, "wait_list_ is not empty after flush thread stop", K(wait_list_size_)); - for (int64_t cnt = 0; cnt < wait_list_size_ && !wait_list_.is_empty(); ++cnt) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_wait_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is null", K(cnt), K(wait_list_size_)); - } else if (OB_FAIL(flush_task->wait_macro_block_handle())) { - if (OB_EAGAIN == ret) { - push_wait_list_(flush_task); - ret = OB_SUCCESS; - } else { - STORAGE_LOG(ERROR, "unexpected error in waiting flush task finished", KR(ret), KPC(this)); - } - } else if (!flush_task->atomic_get_io_finished()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected flush task state", KR(ret), KPC(flush_task)); - } else if (OB_FAIL(flush_mgr_.notify_write_back_failed(flush_task))) { - } else { - flush_mgr_.free_flush_task(flush_task); - } - } - usleep(10 * 1000); // 10ms - } -} - -void ObTmpFileFlushThread::set_running_mode(const RUNNING_MODE mode) -{ - mode_ = mode; -} - -void ObTmpFileFlushThread::notify_doing_flush() -{ - last_flush_timestamp_ = 0; -} - -void ObTmpFileFlushThread::signal_io_finish(int flush_io_finished_ret) -{ - flush_io_finished_ret_ = flush_io_finished_ret; - ++flush_io_finished_round_; -} - -int64_t ObTmpFileFlushThread::get_flush_io_finished_round() -{ - return flush_io_finished_round_; -} - -int64_t ObTmpFileFlushThread::get_flush_io_finished_ret() -{ - return flush_io_finished_ret_; -} - -int64_t ObTmpFileFlushThread::cal_idle_time() -{ - int64_t idle_time = 0; - int64_t dirty_page_percentage = wbp_.get_dirty_page_percentage(); - if (OB_UNLIKELY(!STORAGE_META_SERVICE.is_started())) { - idle_time = ObTmpFilePageCacheController::FLUSH_INTERVAL; - } else if (!wait_list_.is_empty() || !retry_list_.is_empty() || !finished_list_.is_empty() - || ObTmpFileFlushManager::FLUSH_WATERMARK_F1 <= dirty_page_percentage) { - idle_time = ObTmpFilePageCacheController::FLUSH_FAST_INTERVAL; - } else if (RUNNING_MODE::FAST == mode_) { - int64_t flushing_block_num = ATOMIC_LOAD(&flushing_block_num_); - if (flushing_block_num >= get_flushing_block_num_threshold_()) { - idle_time = ObTmpFilePageCacheController::FLUSH_FAST_INTERVAL; - } else { - idle_time = 0; - } - } else { - idle_time = ObTmpFilePageCacheController::FLUSH_INTERVAL; - } - return idle_time; -} - -int ObTmpFileFlushThread::try_work() -{ - int ret = OB_SUCCESS; - - int64_t cur_time = ObTimeUtility::current_monotonic_time(); - if (0 == last_flush_timestamp_ || cur_time - last_flush_timestamp_ >= cal_idle_time() * 1000) { - if (OB_UNLIKELY(!STORAGE_META_SERVICE.is_started())) { - ret = OB_NOT_RUNNING; - LOG_INFO("ObTmpFileFlushThread does not work before local storage recovery finished", - KR(ret), KPC(this)); - } else if (OB_FAIL(do_work_())) { - } - last_flush_timestamp_ = ObTimeUtility::current_monotonic_time(); - } - - return ret; -} - -int ObTmpFileFlushThread::do_work_() -{ - int ret = OB_SUCCESS; - - if (is_fast_flush_meta_) { - check_flush_task_io_finished_(); - retry_fast_flush_meta_task_(); - } else { - if (RUNNING_MODE::FAST == mode_) { - flush_fast_(); - } else if (RUNNING_MODE::NORMAL == mode_) { - flush_normal_(); - } else { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unknown running mode", KR(ret), K(mode_)); - } - } - - flush_mgr_.try_remove_unused_file_flush_ctx(); - - if (TC_REACH_TIME_INTERVAL(ObTmpFileGlobal::TMP_FILE_STAT_FREQUENCY)) { - tmp_file_block_mgr_.print_block_usage(); - flush_monitor_.print_statistics(); - wbp_.print_statistics(); - STORAGE_LOG(INFO, "ObTmpFileFlushThread information", KPC(this)); - normal_loop_cnt_ = 0; - normal_idle_loop_cnt_ = 0; - fast_loop_cnt_ = 0; - fast_idle_loop_cnt_ = 0; - } - return ret; -} - -// 1. check wait_list_ for IO complete task; 2. retry old task if exists; 3. build new task if needed -void ObTmpFileFlushThread::flush_fast_() -{ - int ret = OB_SUCCESS; - int64_t BLOCK_SIZE = ObTmpFileGlobal::SN_BLOCK_SIZE; - - if (OB_FAIL(check_flush_task_io_finished_())) { - } - if (OB_FAIL(retry_task_())) { - } - - int64_t flushing_block_num = ATOMIC_LOAD(&flushing_block_num_); - if (flushing_block_num >= get_flushing_block_num_threshold_()) { - } else { - int64_t max_flushing_block_num_cur_round = get_flushing_block_num_threshold_() - flushing_block_num; - int64_t flush_size = min(get_fast_flush_size_(), max_flushing_block_num_cur_round * BLOCK_SIZE); - if (flush_size > 0) { - if (OB_FAIL(wash_(flush_size, RUNNING_MODE::FAST))) { - } - } else { - } - } -} - -void ObTmpFileFlushThread::flush_normal_() -{ - int ret = OB_SUCCESS; - int64_t BLOCK_SIZE = ObTmpFileGlobal::SN_BLOCK_SIZE; - int64_t normal_flush_size = max(0, (ObTmpFileGlobal::MAX_FLUSHING_BLOCK_NUM - - ATOMIC_LOAD(&flushing_block_num_)) * BLOCK_SIZE); - if (OB_FAIL(check_flush_task_io_finished_())) { - } - if (OB_FAIL(retry_task_())) { - } - if (normal_flush_size > 0) { - if (OB_FAIL(wash_(normal_flush_size, RUNNING_MODE::NORMAL))) { - } - } else { - } -} - -int ObTmpFileFlushThread::handle_generated_flush_tasks_(ObSpLinkQueue &flushing_list, int64_t &task_num) -{ - int ret = OB_SUCCESS; - task_num = 0; - while (!flushing_list.is_empty()) { // ignore error code to handle all flush tasks - task_num += 1; - ObSpLinkQueue::Link *link = nullptr; - flushing_list.pop(link); - if (OB_ISNULL(link)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is null", KR(ret)); - } else { - ObTmpFileFlushTask *flush_task = static_cast(link); - FlushState state = flush_task->get_state(); - bool need_release_resource = false; - if (FlushState::TFFT_WAIT == state) { - ATOMIC_INC(&flushing_block_num_); - push_wait_list_(flush_task); - if (flush_task->get_is_fast_flush_tree()) { - // after setting this flag, the thread will only process tasks that are already in wait_list_ and finished_list_, - // and will not process tasks in retry_list_ or generate new flush tasks - is_fast_flush_meta_ = true; - fast_flush_meta_task_cnt_ += 1; - } - } else if (FlushState::TFFT_FILL_BLOCK_BUF > state) { - need_release_resource = true; - } else if (FlushState::TFFT_FILL_BLOCK_BUF == state && 0 == flush_task->get_data_length()) { - need_release_resource = true; - } else if (FlushState::TFFT_FILL_BLOCK_BUF == state && 0 < flush_task->get_data_length()) { - // ATTENTION! after the data has been copied, it should transition to the next state. - // staying in the TFFT_FILL_BLOCK_BUF is an abnormal behavior and the file should be discarded, - // do not free task here to avoid further corruption. - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("fail to switch state after data copied from tmp file", KR(ret), KPC(flush_task)); - } else if (FlushState::TFFT_FILL_BLOCK_BUF < state) { - if (FlushState::TFFT_ASYNC_WRITE == state && - flush_task->atomic_get_write_block_ret_code() == OB_SERVER_OUTOF_DISK_SPACE) { - signal_io_finish(OB_SERVER_OUTOF_DISK_SPACE); - } - push_retry_list_(flush_task); - ATOMIC_INC(&flushing_block_num_); - } - - if (need_release_resource) { - if (ObTmpFileGlobal::INVALID_TMP_FILE_BLOCK_INDEX != flush_task->get_block_index()) { - flush_mgr_.free_tmp_file_block(*flush_task); - } - flush_mgr_.free_flush_task(flush_task); - } - } - } // end while - return ret; -} - -int ObTmpFileFlushThread::wash_(const int64_t expect_flush_size, const RUNNING_MODE mode) -{ - int ret = OB_SUCCESS; - int64_t flushing_task_cnt = 0; - int64_t current_flush_cnt = ATOMIC_LOAD(&flushing_block_num_); - ObSpLinkQueue flushing_list; - - if (OB_FAIL(flush_mgr_.flush(flushing_list, flush_monitor_, expect_flush_size, - current_flush_cnt, is_fast_flush_meta_))) { - if (OB_TMP_FILE_EXCEED_DISK_QUOTA == ret) { - signal_io_finish(ret); - } - } - - if (!flushing_list.is_empty()) { // ignore ret - if (OB_FAIL(handle_generated_flush_tasks_(flushing_list, flushing_task_cnt))) { - } - } - - bool idle_loop = flushing_task_cnt == 0; - if (idle_loop && wbp_.get_cannot_be_evicted_page_percentage() < ObTmpFileFlushManager::FLUSH_WATERMARK_F3) { - signal_io_finish(OB_SUCCESS); - } - - if (RUNNING_MODE::NORMAL == mode) { - ++normal_loop_cnt_; - if (idle_loop) { - ++normal_idle_loop_cnt_; - } - } else if (RUNNING_MODE::FAST == mode) { - ++fast_loop_cnt_; - if (idle_loop) { - ++fast_idle_loop_cnt_; - } - } - return ret; -} - -int ObTmpFileFlushThread::retry_fast_flush_meta_task_() -{ - int ret = OB_SUCCESS; - for (int64_t cnt = retry_list_size_; cnt > 0 && !retry_list_.is_empty(); --cnt) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_retry_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } else if (!flush_task->get_is_fast_flush_tree()) { - push_retry_list_(flush_task); - } else { - // only retry is_fast_flush_tree tasks - if (OB_FAIL(flush_mgr_.retry(*flush_task))) { - } - - FlushState state = flush_task->get_state(); - if (FlushState::TFFT_WAIT == state) { - push_wait_list_(flush_task); - } else if (FlushState::TFFT_FILL_BLOCK_BUF < state) { - push_retry_list_(flush_task); - } else if (FlushState::TFFT_FILL_BLOCK_BUF >= state) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected flush task status in retry phase", KR(ret), KPC(flush_task)); - } - } - } - return ret; -} - -int ObTmpFileFlushThread::retry_task_() -{ - int ret = OB_SUCCESS; - for (int64_t cnt = retry_list_size_; cnt > 0 && !retry_list_.is_empty(); --cnt) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_retry_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } else { - if (OB_FAIL(flush_mgr_.retry(*flush_task))) { - } - // push task into wait_list_/retry_list_ according to task state, ignore error code - FlushState state = flush_task->get_state(); - if (FlushState::TFFT_ABORT == state) { - STORAGE_LOG(INFO, "free abort flush task", KPC(flush_task)); - flush_task_finished_(flush_task); - } else if (FlushState::TFFT_WAIT == state) { - push_wait_list_(flush_task); - } else if (FlushState::TFFT_FILL_BLOCK_BUF < state) { - if (FlushState::TFFT_ASYNC_WRITE == state && - flush_task->atomic_get_write_block_ret_code() == OB_SERVER_OUTOF_DISK_SPACE) { - signal_io_finish(OB_SERVER_OUTOF_DISK_SPACE); - } - push_retry_list_(flush_task); - if (FlushState::TFFT_INSERT_META_TREE == state && OB_ALLOCATE_TMP_FILE_PAGE_FAILED == ret) { - STORAGE_LOG(WARN, "fail to retry insert meta item in TFFT_INSERT_META_TREE", KPC(flush_task)); - if (OB_FAIL(special_flush_meta_tree_page_())) { - } - break; - } - } else if (FlushState::TFFT_FILL_BLOCK_BUF >= state) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected flush task status in retry phase", KR(ret), KPC(flush_task)); - } - } - } - return ret; -} - -int ObTmpFileFlushThread::special_flush_meta_tree_page_() -{ - int ret = OB_SUCCESS; - ObSpLinkQueue flushing_list; - int64_t flushing_task_cnt = 0; - int64_t current_flush_cnt = ATOMIC_LOAD(&flushing_block_num_); - int64_t expect_flush_size = OB_STORAGE_OBJECT_MGR.get_macro_object_size(); - if (OB_FAIL(flush_mgr_.flush(flushing_list, flush_monitor_, expect_flush_size, - current_flush_cnt, true/*is_flush_meta_tree*/))) { - if (OB_TMP_FILE_EXCEED_DISK_QUOTA == ret) { - signal_io_finish(ret); - } else { - STORAGE_LOG(ERROR, "flush mgr fail to do fast flush meta tree page", KR(ret), KPC(this)); - } - } - - if (!flushing_list.is_empty()) { // ignore ret - if (OB_FAIL(handle_generated_flush_tasks_(flushing_list, flushing_task_cnt))) { - } - } - return ret; -} - -int ObTmpFileFlushThread::check_flush_task_io_finished_() -{ - int ret = OB_SUCCESS; - for (int64_t cnt = ATOMIC_LOAD(&wait_list_size_); cnt > 0 && !wait_list_.is_empty(); --cnt) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_wait_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } - bool write_block_success = false; - if (OB_FAIL(ret)) { - } else if (!flush_task->atomic_get_write_block_executed()) { - push_wait_list_(flush_task); // not send IO yet, continue waiting - ret = OB_SUCCESS; - } else if (flush_task->atomic_get_write_block_ret_code() != OB_SUCCESS) { - if (flush_task->atomic_get_write_block_ret_code() == OB_SERVER_OUTOF_DISK_SPACE) { - signal_io_finish(OB_SERVER_OUTOF_DISK_SPACE); - } - // rollback to TFFT_ASYNC_WRITE and re-send IO - if (OB_FAIL(flush_mgr_.io_finished(*flush_task))) { - } else if (FlushState::TFFT_ASYNC_WRITE == flush_task->get_state()) { - push_retry_list_(flush_task); - } else { - STORAGE_LOG(ERROR, "unexpected flush task state", KR(ret), KPC(flush_task)); - } - } else { - write_block_success = true; - } - - if (OB_FAIL(ret) || !write_block_success) { - } else if (OB_FAIL(flush_task->wait_macro_block_handle())) { - if (OB_EAGAIN == ret) { - push_wait_list_(flush_task); // IO is not completed, continue waiting - static const int64_t FLUSH_TASK_IO_WARN_INTERVAL = 30 * 1000 * 1000; // 30s - if (ObTimeUtil::current_time() - flush_task->get_last_print_ts() > FLUSH_TASK_IO_WARN_INTERVAL) { - LOG_WARN("flush task execute takes too much time", KPC(flush_task)); - flush_task->set_last_print_ts(ObTimeUtil::current_time()); - } - ret = OB_SUCCESS; - } else { - STORAGE_LOG(WARN, "unexpected error in waiting flush task finished", KR(ret), KPC(this)); - } - } else if (!flush_task->atomic_get_io_finished()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "unexpected flush task state", KR(ret), KPC(flush_task)); - } else if (OB_FAIL(flush_mgr_.io_finished(*flush_task))) { - } else { - if (FlushState::TFFT_FINISH == flush_task->get_state()) { - push_finished_list_(flush_task); - } else if (FlushState::TFFT_ASYNC_WRITE == flush_task->get_state()) { - push_retry_list_(flush_task); - } else { - STORAGE_LOG(ERROR, "unexpected flush task state", KR(ret), KPC(flush_task)); - } - } - } - - for (int64_t cnt = ATOMIC_LOAD(&finished_list_size_); cnt > 0 && !finished_list_.is_empty(); --cnt) { - ObTmpFileFlushTask *flush_task = nullptr; - pop_finished_list_(flush_task); - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } else { - // if the update fails, it will be retried during the next wakeup - if (OB_FAIL(flush_mgr_.update_file_meta_after_flush(*flush_task))) { - STORAGE_LOG(WARN, "fail to drive flush state machine", KR(ret), KPC(flush_task)); - push_finished_list_(flush_task); - } else { - flush_task_finished_(flush_task); - } - } - } - return ret; -} - -void ObTmpFileFlushThread::flush_task_finished_(ObTmpFileFlushTask *flush_task) -{ - int ret = OB_SUCCESS; - - bool is_flush_tree_page = flush_task->get_is_fast_flush_tree(); - flush_mgr_.free_flush_task(flush_task); - ATOMIC_DEC(&flushing_block_num_); - fast_flush_meta_task_cnt_ -= is_flush_tree_page ? 1 : 0; - if (fast_flush_meta_task_cnt_ == 0) { - // reset is_fast_flush_meta_ flag to resume retry task and flush - is_fast_flush_meta_ = false; - } else if (OB_UNLIKELY(fast_flush_meta_task_cnt_ < 0)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "fast_flush_meta_task_cnt_ is negative", KR(ret), KPC(this)); - } - signal_io_finish(OB_SUCCESS); -} - -int ObTmpFileFlushThread::push_wait_list_(ObTmpFileFlushTask *flush_task) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_task)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } else if (OB_FAIL(wait_list_.push(flush_task))) { - } else { - ATOMIC_INC(&wait_list_size_); - } - return ret; -} - -int ObTmpFileFlushThread::pop_wait_list_(ObTmpFileFlushTask *&flush_task) -{ - int ret = OB_SUCCESS; - ObSpLinkQueue::Link *link = nullptr; - if (OB_FAIL(wait_list_.pop(link))) { - } else if (OB_ISNULL(link)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task ptr in wait list is null", KR(ret)); - } else { - ATOMIC_DEC(&wait_list_size_); - flush_task = static_cast(link); - } - return ret; -} - -int ObTmpFileFlushThread::push_retry_list_(ObTmpFileFlushTask *flush_task) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_task)){ - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } else if (OB_FAIL(retry_list_.push(flush_task))) { - } else { - ATOMIC_INC(&retry_list_size_); - } - return ret; -} - -int ObTmpFileFlushThread::pop_retry_list_(ObTmpFileFlushTask *&flush_task) -{ - int ret = OB_SUCCESS; - ObSpLinkQueue::Link *link = nullptr; - if (OB_FAIL(retry_list_.pop(link))) { - } else if (OB_ISNULL(link)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task ptr is null", KR(ret)); - } else { - ATOMIC_DEC(&retry_list_size_); - flush_task = static_cast(link); - } - return ret; -} - -int ObTmpFileFlushThread::push_finished_list_(ObTmpFileFlushTask *flush_task) -{ - int ret = OB_SUCCESS; - if (OB_ISNULL(flush_task)){ - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task is nullptr", KR(ret)); - } else if (OB_FAIL(finished_list_.push(flush_task))) { - } else { - ATOMIC_INC(&finished_list_size_); - } - return ret; -} - -int ObTmpFileFlushThread::pop_finished_list_(ObTmpFileFlushTask *&flush_task) -{ - int ret = OB_SUCCESS; - ObSpLinkQueue::Link *link = nullptr; - if (OB_FAIL(finished_list_.pop(link))) { - } else if (OB_ISNULL(link)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "flush task ptr is null", KR(ret)); - } else { - ATOMIC_DEC(&finished_list_size_); - flush_task = static_cast(link); - } - return ret; -} - -int ObTmpFileFlushThread::get_fast_flush_size_() -{ - // TODO: move to page cache controller - const int64_t BLOCK_SIZE = ObTmpFileGlobal::SN_BLOCK_SIZE; - int64_t wbp_mem_limit = wbp_.get_memory_limit(); - int64_t flush_size = max(BLOCK_SIZE, min(ObTmpFileGlobal::MAX_FLUSHING_BLOCK_NUM * BLOCK_SIZE, - upper_align(0.1 * wbp_mem_limit, BLOCK_SIZE))); - return flush_size; -} - -int64_t ObTmpFileFlushThread::get_flushing_block_num_threshold_() -{ - const int64_t BLOCK_SIZE = ObTmpFileGlobal::SN_BLOCK_SIZE; - int64_t wbp_mem_limit = wbp_.get_memory_limit(); - int64_t flush_threshold = - max(1, min(ObTmpFileGlobal::MAX_FLUSHING_BLOCK_NUM, - static_cast(0.2 * wbp_mem_limit / BLOCK_SIZE))); - return flush_threshold; -} - -// --------------- swap ----------------// - -ObTmpFileSwapThread::ObTmpFileSwapThread(ObTmpWriteBufferPool &wbp, - ObTmpFileEvictionManager &elimination_mgr, - ObTmpFileFlushThread &flush_thread, - ObTmpFilePageCacheController &pc_ctrl) - : lib::ThreadPool(1), - is_inited_(false), - idle_cond_(), - last_swap_timestamp_(0), - swap_job_num_(0), - swap_job_list_(), - working_list_size_(0), - working_list_(), - swap_monitor_(), - flush_thread_ref_(flush_thread), - flush_io_finished_round_(0), - wbp_(wbp), - evict_mgr_(elimination_mgr), - pc_ctrl_(pc_ctrl) -{ -} - -int ObTmpFileSwapThread::init() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - STORAGE_LOG(WARN, "ObTmpFileSwapThread init twice"); - } else if (OB_FAIL(idle_cond_.init(ObWaitEventIds::THREAD_IDLING_COND_WAIT))) { - } else if (OB_FAIL(lib::ThreadPool::init())) { - } else { - is_inited_ = true; - last_swap_timestamp_ = 0; - swap_job_num_ = 0; - working_list_size_ = 0; - flush_io_finished_round_ = 0; - } - return ret; -} - -int ObTmpFileSwapThread::start() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileSwapThread thread is not inited", KR(ret)); - } else if (OB_FAIL(lib::ThreadPool::start())) { - } - return ret; -} - -void ObTmpFileSwapThread::stop() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileSwapThread thread is not inited", KR(ret)); - } else { - lib::ThreadPool::stop(); - ObThreadCondGuard guard(idle_cond_); - idle_cond_.signal(); - } -} - -void ObTmpFileSwapThread::wait() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileSwapThread thread is not inited", KR(ret)); - } else { - lib::ThreadPool::wait(); - } -} - -void ObTmpFileSwapThread::destroy() -{ - int ret = OB_SUCCESS; - if (is_inited_) { - stop(); - wait(); - lib::ThreadPool::destroy(); - } - - clean_up_lists_(); - last_swap_timestamp_ = 0; - swap_job_num_ = 0; - working_list_size_ = 0; - flush_io_finished_round_ = 0; - idle_cond_.destroy(); - is_inited_ = false; -} - -int ObTmpFileSwapThread::swap_job_enqueue(ObTmpFileSwapJob *swap_job) -{ - int ret = OB_SUCCESS; - if (has_set_stop()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "swap thread has been stopped", KR(ret), KP(swap_job)); - } else if (OB_FAIL(swap_job_list_.push(swap_job))) { - } else { - ATOMIC_INC(&swap_job_num_); - } - return ret; -} - -int ObTmpFileSwapThread::swap_job_dequeue(ObTmpFileSwapJob *&swap_job) -{ - int ret = OB_SUCCESS; - ObSpLinkQueue::Link *link = nullptr; - if (OB_FAIL(swap_job_list_.pop(link))) { - } else if (OB_ISNULL(link)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "fail to get swap job, ptr is nullptr", KR(ret)); - } else { - ATOMIC_DEC(&swap_job_num_); - swap_job = static_cast(link); - } - return ret; -} - -void ObTmpFileSwapThread::notify_doing_swap() -{ - ObThreadCondGuard guard(idle_cond_); - idle_cond_.signal(); -} - -int64_t ObTmpFileSwapThread::cal_idle_time() -{ - int64_t swap_idle_time = ObTmpFilePageCacheController::SWAP_INTERVAL; - if (OB_UNLIKELY(!STORAGE_META_SERVICE.is_started())) { - swap_idle_time = ObTmpFilePageCacheController::SWAP_INTERVAL; - } else if (ATOMIC_LOAD(&swap_job_num_) != 0 || ATOMIC_LOAD(&working_list_size_) != 0) { - if (flush_io_finished_round_ < flush_thread_ref_.get_flush_io_finished_round()) { - swap_idle_time = 0; - } else { - swap_idle_time = ObTmpFilePageCacheController::SWAP_FAST_INTERVAL; - } - } - return swap_idle_time; -} - -void ObTmpFileSwapThread::run1() -{ - int ret = OB_SUCCESS; - lib::set_thread_name("TFSwap"); - while (!has_set_stop()) { - if (OB_FAIL(shrink_wbp_if_needed_())) { - } - - // overwrite ret - if (OB_FAIL(swap())) { - } - - // overwrite ret - if (OB_FAIL(flush_thread_ref_.try_work())) { - } - - ObThreadCondGuard guard(idle_cond_); - int64_t swap_idle_time = cal_idle_time(); - int64_t flush_idle_time = flush_thread_ref_.cal_idle_time(); - int64_t idle_time = min(swap_idle_time, flush_idle_time); - if (!has_set_stop() && idle_time != 0) { - idle_cond_.wait(idle_time); - } - } -} - -void ObTmpFileSwapThread::clean_up_lists_() -{ - int ret = OB_SUCCESS; - while (!swap_job_list_.is_empty()) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(swap_job_dequeue(swap_job))) { - } else if (OB_FAIL(swap_job->signal_swap_complete(OB_SUCCESS))){ - } - } - - ret = OB_SUCCESS; - while (!working_list_.is_empty()) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(pop_working_job_(swap_job))) { - } else if (OB_FAIL(swap_job->signal_swap_complete(OB_SUCCESS))){ - } - } -} - -int ObTmpFileSwapThread::swap() -{ - int ret = OB_SUCCESS; - - int64_t cur_time = ObTimeUtility::current_monotonic_time(); - if (0 == last_swap_timestamp_ || cur_time - last_swap_timestamp_ >= cal_idle_time() * 1000) { - if (OB_FAIL(do_work_())) { - } - last_swap_timestamp_ = ObTimeUtility::current_monotonic_time(); - } - - return ret; -} - -int ObTmpFileSwapThread::do_work_() -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - STORAGE_LOG(WARN, "ObTmpFileSwapThread not init", KR(ret)); - } - - if (OB_SUCC(ret)) { - if (TC_REACH_TIME_INTERVAL(ObTmpFilePageCacheController::REFRESH_CONFIG_INTERVAL)) { - pc_ctrl_.refresh_disk_usage_limit(); - } - - if (ATOMIC_LOAD(&swap_job_num_) == 0 && ATOMIC_LOAD(&working_list_size_) == 0) { - if (OB_FAIL(swap_normal_())){ - } - } else { - if (OB_FAIL(swap_fast_())){ - } - if (OB_FAIL(swap_normal_())) { - } - } - if (ATOMIC_LOAD(&swap_job_num_) == 0 && ATOMIC_LOAD(&working_list_size_) == 0) { - flush_thread_ref_.set_running_mode(ObTmpFileFlushThread::RUNNING_MODE::NORMAL); - } - } - if (TC_REACH_TIME_INTERVAL(1 * 1000 * 1000)) { - swap_monitor_.print_statistics(); - } - return ret; -} - -// runs in normal mode when there is no swap job. -// since memory is not tight at this point, we try to evict pages -// but not guarantee eviction occurs if clean pages are not enough -int ObTmpFileSwapThread::swap_normal_() -{ - int ret = OB_SUCCESS; - - int64_t swap_size = wbp_.get_swap_size(); - int64_t actual_swap_page_cnt = 0; - if (swap_size > 0) { // do swap - int64_t swap_page_cnt = swap_size / ALLOC_PAGE_SIZE; - if (OB_FAIL(evict_mgr_.evict(swap_page_cnt, actual_swap_page_cnt))) { - } - } - return ret; -} - -// attempt to evict pages and wake up caller threads as soon as possible, -// this may trigger the flush thread to flush a small number of pages (FAST mode). -// caller threads will be awakened if swap job timeout -int ObTmpFileSwapThread::swap_fast_() -{ - int ret = OB_SUCCESS; - while (OB_SUCC(ret) && !swap_job_list_.is_empty()) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(swap_job_dequeue(swap_job))) { - } else if (OB_FAIL(push_working_job_(swap_job))) { - } - } - - while (OB_SUCC(ret) && !working_list_.is_empty()) { - int64_t expect_swap_page_cnt = 0; - int64_t actual_swap_page_cnt = 0; - // calculate expect swap pages number for a batch of jobs - if (OB_FAIL(calculate_swap_page_num_(PROCCESS_JOB_NUM_PER_BATCH, expect_swap_page_cnt))) { - } else if (OB_UNLIKELY(expect_swap_page_cnt <= 0)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(ERROR, "cur expect swap page cnt is invalid", KR(ret), K(expect_swap_page_cnt)); - } else if (OB_FAIL(evict_mgr_.evict(expect_swap_page_cnt, actual_swap_page_cnt))) { - } - - int64_t wakeup_job_cnt = 0; - wakeup_satisfied_jobs_(wakeup_job_cnt); - wakeup_timeout_jobs_(); - int io_finished_ret = flush_thread_ref_.get_flush_io_finished_ret(); - if (OB_SERVER_OUTOF_DISK_SPACE == io_finished_ret || - OB_TMP_FILE_EXCEED_DISK_QUOTA == io_finished_ret) { - wakeup_all_jobs_(io_finished_ret); - } - - // do flush if could not evict enough pages - if (OB_SUCC(ret) && !working_list_.is_empty() && wakeup_job_cnt < PROCCESS_JOB_NUM_PER_BATCH) { - flush_io_finished_round_ = flush_thread_ref_.get_flush_io_finished_round(); - flush_thread_ref_.set_running_mode(ObTmpFileFlushThread::RUNNING_MODE::FAST); - flush_thread_ref_.notify_doing_flush(); - break; - } - } // end while - - return ret; -} - -int ObTmpFileSwapThread::calculate_swap_page_num_(const int64_t batch_size, int64_t &expect_swap_cnt) -{ - int ret = OB_SUCCESS; - ObSpLinkQueue cur_working_list; - for (int64_t i = 0; OB_SUCC(ret) && i < batch_size && !working_list_.is_empty(); ++i) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(pop_working_job_(swap_job))) { - } else { - expect_swap_cnt += upper_align(swap_job->get_expect_swap_size(), ALLOC_PAGE_SIZE) / ALLOC_PAGE_SIZE; - cur_working_list.push_front(swap_job); - } - } - while (!cur_working_list.is_empty()) { - ObSpLinkQueue::Link *link = nullptr; - cur_working_list.pop(link); - ObTmpFileSwapJob *swap_job = static_cast(link); - if (OB_ISNULL(swap_job)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "swap job is invalid", KR(ret)); - } else if (OB_FAIL(push_working_job_front_(swap_job))) { - } - } - return ret; -} - -int ObTmpFileSwapThread::wakeup_satisfied_jobs_(int64_t& wakeup_job_cnt) -{ - int ret = OB_SUCCESS; - wakeup_job_cnt = 0; - int64_t wbp_free_page_cnt = wbp_.get_free_data_page_num(); - while (OB_SUCC(ret) && wbp_free_page_cnt > 0 && !working_list_.is_empty()) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(pop_working_job_(swap_job))) { - } else { - // wake up threads even if free page number < swap job's expect swap size - int64_t single_job_swap_page_cnt = upper_align(swap_job->get_expect_swap_size(), ALLOC_PAGE_SIZE) / ALLOC_PAGE_SIZE; - wbp_free_page_cnt -= min(wbp_free_page_cnt, single_job_swap_page_cnt); - int64_t response_time = ObTimeUtility::current_time() - swap_job->get_create_ts(); - swap_monitor_.record_swap_response_time(response_time); - if (OB_FAIL(swap_job->signal_swap_complete(OB_SUCCESS))) { - } else { - ++wakeup_job_cnt; - } - } - } - return ret; -} - -int ObTmpFileSwapThread::wakeup_timeout_jobs_() -{ - int ret = OB_SUCCESS; - for (int64_t i = working_list_size_; OB_SUCC(ret) && i > 0 && !working_list_.is_empty(); --i) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(pop_working_job_(swap_job))) { - } else if (swap_job->get_abs_timeout_ts() <= ObTimeUtility::current_time()) { - // timeout, wake it up - int64_t response_time = ObTimeUtility::current_time() - swap_job->get_create_ts(); - swap_monitor_.record_swap_response_time(response_time); - if (OB_FAIL(swap_job->signal_swap_complete(OB_TIMEOUT))) { - } - } else { - if (OB_FAIL(push_working_job_(swap_job))) { - } - } - } - return ret; -} - -void ObTmpFileSwapThread::wakeup_all_jobs_(int ret_code) -{ - int ret = OB_SUCCESS; - for (int64_t i = working_list_size_; OB_SUCC(ret) && i > 0 && !working_list_.is_empty(); --i) { - ObTmpFileSwapJob *swap_job = nullptr; - if (OB_FAIL(pop_working_job_(swap_job))) { - } else { - int64_t response_time = ObTimeUtility::current_time() - swap_job->get_create_ts(); - swap_monitor_.record_swap_response_time(response_time); - if (OB_FAIL(swap_job->signal_swap_complete(ret_code))) { - } - } - } -} - -int ObTmpFileSwapThread::push_working_job_(ObTmpFileSwapJob *swap_job) -{ - int ret = OB_SUCCESS; - if (has_set_stop()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "swap thread has been stopped", KR(ret), KP(swap_job)); - } else if (OB_FAIL(working_list_.push(swap_job))) { - } else { - ATOMIC_INC(&working_list_size_); - } - return ret; -} - -int ObTmpFileSwapThread::pop_working_job_(ObTmpFileSwapJob *&swap_job) -{ - int ret = OB_SUCCESS; - ObSpLinkQueue::Link *link = nullptr; - if (OB_FAIL(working_list_.pop(link))) { - } else if (OB_ISNULL(link)) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "fail to get swap job, ptr is nullptr", KR(ret)); - } else { - ATOMIC_DEC(&working_list_size_); - swap_job = static_cast(link); - } - return ret; -} - -int ObTmpFileSwapThread::push_working_job_front_(ObTmpFileSwapJob *swap_job) -{ - int ret = OB_SUCCESS; - if (has_set_stop()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "swap thread has been stopped", KR(ret), KP(swap_job)); - } else if (OB_FAIL(working_list_.push_front(swap_job))) { - } else { - ATOMIC_INC(&working_list_size_); - } - return ret; -} - -int ObTmpFileSwapThread::shrink_wbp_if_needed_() -{ - int ret = OB_SUCCESS; - int64_t actual_evict_num = 0; - bool is_auto = false; - ObTimeGuard time_guard("wbp_shrink", 1 * 1000 * 1000); - if (wbp_.need_to_shrink(is_auto)) { - LOG_DEBUG("current wbp shrinking state", K(wbp_.get_shrink_ctx())); - switch (wbp_.get_wbp_state()) { - case WBPShrinkContext::INVALID: - if (OB_FAIL(wbp_.begin_shrinking(is_auto))) { - } else { - pc_ctrl_.set_flush_all_data(true); - flush_thread_ref_.notify_doing_flush(); - wbp_.advance_shrink_state(); - } - break; - case WBPShrinkContext::SHRINKING_SWAP: - if (!wbp_.get_shrink_ctx().is_valid()) { - ret = OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "shrink context is invalid", KR(ret)); - } else if (OB_FAIL(evict_mgr_.evict(INT64_MAX, actual_evict_num))) { - } else { - wbp_.advance_shrink_state(); - } - break; - case WBPShrinkContext::SHRINKING_RELEASE_BLOCKS: - if (OB_FAIL(wbp_.release_blocks_in_shrink_range())) { - } else { - pc_ctrl_.set_flush_all_data(false); - wbp_.advance_shrink_state(); - } - break; - case WBPShrinkContext::SHRINKING_FINISH: - if (OB_FAIL(wbp_.finish_shrinking())) { - } - break; - default: - break; - } - } - - // abort shrinking if wbp memory limit enlarge or flush fail with OB_SERVER_OUTOF_DISK_SPACE - int io_finished_ret = flush_thread_ref_.get_flush_io_finished_ret(); - if (wbp_.get_shrink_ctx().is_valid() && (!wbp_.need_to_shrink(is_auto) || OB_SERVER_OUTOF_DISK_SPACE == io_finished_ret)) { - wbp_.finish_shrinking(); - } - time_guard.click("wbp_shrink finish one step"); - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_thread_wrapper.h b/src/storage/tmp_file/ob_tmp_file_thread_wrapper.h deleted file mode 100644 index 0d134d9d7c..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_thread_wrapper.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_THREAD_WRAPPER_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_THREAD_WRAPPER_H_ - -#include "storage/tmp_file/ob_tmp_file_thread_job.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool.h" -#include "storage/tmp_file/ob_tmp_file_eviction_manager.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_tmp_file_flush_manager.h" -#include "lib/lock/ob_thread_cond.h" -#include "lib/task/ob_timer.h" -#include "lib/thread/thread_pool.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileManager; -class ObTmpFileFlushManager; - -// When originally designed, ObTmpFileFlushThread was an independent thread. In order to reduce the -// number of threads, the thread of ObTmpFileFlushThread was driven by ObTmpFileSwapThread. -class ObTmpFileFlushThread -{ -public: - typedef ObTmpFileFlushTask::ObTmpFileFlushTaskState FlushState; - enum RUNNING_MODE { - INVALID = 0, - NORMAL = 1, - FAST = 2 - }; -public: - ObTmpFileFlushThread(ObTmpWriteBufferPool &wbp, - ObTmpFileFlushManager &flush_mgr, - ObIAllocator &allocator, - ObTmpFileBlockManager &tmp_file_block_mgr); - int init(); - int start(); - void stop(); - void wait(); - void destroy(); - - int try_work(); - void set_running_mode(const RUNNING_MODE mode); - void notify_doing_flush(); - void signal_io_finish(int flush_io_finished_ret); - int64_t get_flush_io_finished_ret(); - int64_t get_flush_io_finished_round(); - int64_t cal_idle_time(); - void clean_up_lists(); - TO_STRING_KV(K(is_inited_), K(mode_), K(last_flush_timestamp_), K(flush_io_finished_ret_), K(flush_io_finished_round_), - K(flushing_block_num_), K(is_fast_flush_meta_), K(fast_flush_meta_task_cnt_), - K(wait_list_size_), K(retry_list_size_), K(finished_list_size_), - K(normal_loop_cnt_), K(normal_idle_loop_cnt_), K(fast_loop_cnt_), K(fast_idle_loop_cnt_), - K(flush_mgr_)); -private: - int do_work_(); - int handle_generated_flush_tasks_(ObSpLinkQueue &flushing_list, int64_t &task_num); - int wash_(const int64_t expect_flush_size, const RUNNING_MODE mode); - int check_flush_task_io_finished_(); - int retry_fast_flush_meta_task_(); - int retry_task_(); - int special_flush_meta_tree_page_(); - void flush_fast_(); - void flush_normal_(); - int get_fast_flush_size_(); - int64_t get_flushing_block_num_threshold_(); - int push_wait_list_(ObTmpFileFlushTask *flush_task); - int pop_wait_list_(ObTmpFileFlushTask *&flush_task); - int push_retry_list_(ObTmpFileFlushTask *flush_task); - int pop_retry_list_(ObTmpFileFlushTask *&flush_task); - int push_finished_list_(ObTmpFileFlushTask *flush_task); - int pop_finished_list_(ObTmpFileFlushTask *&flush_task); - void flush_task_finished_(ObTmpFileFlushTask *flush_task); -private: - bool is_inited_; - RUNNING_MODE mode_; - int64_t last_flush_timestamp_; - int flush_io_finished_ret_; - int64_t flush_io_finished_round_; - - int64_t flushing_block_num_; // maintain it when ObTmpFileFlushTask is created and freed - bool is_fast_flush_meta_; // indicate thread is fast flushing meta page, no new flush tasks will be added and no tasks will be retried - int64_t fast_flush_meta_task_cnt_; - int64_t wait_list_size_; - int64_t retry_list_size_; - int64_t finished_list_size_; - ObSpLinkQueue wait_list_; // list for tasks that are waiting for IO finished - ObSpLinkQueue retry_list_; // list for tasks that need to be retried - ObSpLinkQueue finished_list_; // list for tasks which have finished IO and need to update file's meta - ObTmpFileFlushMonitor flush_monitor_; - ObTmpFileFlushManager &flush_mgr_; - ObTmpWriteBufferPool &wbp_; - ObTmpFileBlockManager &tmp_file_block_mgr_; - - int64_t normal_loop_cnt_; - int64_t normal_idle_loop_cnt_; - int64_t fast_loop_cnt_; - int64_t fast_idle_loop_cnt_; - - common::ObTimer flush_timers_[ObTmpFileGlobal::FLUSH_TIMER_CNT]; -}; - -class ObTmpFileSwapThread : public lib::ThreadPool -{ -public: - ObTmpFileSwapThread(ObTmpWriteBufferPool &wbp, - ObTmpFileEvictionManager &elimination_mgr, - ObTmpFileFlushThread &flush_thread, - ObTmpFilePageCacheController &pc_ctrl); - virtual int init(); - int start(); - void stop(); - void wait(); - void destroy(); - void run1() override; - int64_t cal_idle_time(); - int swap(); - int swap_job_enqueue(ObTmpFileSwapJob *swap_job); - int swap_job_dequeue(ObTmpFileSwapJob *&swap_job); - // wake up swap thread to do work - void notify_doing_swap(); - TO_STRING_KV(K(is_inited_), K(swap_job_num_), K(working_list_size_), - K(flush_io_finished_round_), K(last_swap_timestamp_), K(has_set_stop())); -private: - static const int64_t ALLOC_PAGE_SIZE = ObTmpFileGlobal::ALLOC_PAGE_SIZE; - static const int64_t PROCCESS_JOB_NUM_PER_BATCH = 128; - void clean_up_lists_(); - int do_work_(); - int swap_normal_(); - int swap_fast_(); - int push_working_job_(ObTmpFileSwapJob *swap_job); - int push_working_job_front_(ObTmpFileSwapJob *swap_job); - int pop_working_job_(ObTmpFileSwapJob *&swap_job); - int calculate_swap_page_num_(const int64_t batch_size, int64_t &expect_swap_cnt); - int wakeup_satisfied_jobs_(int64_t& wakeup_job_cnt); - int wakeup_timeout_jobs_(); - void wakeup_all_jobs_(int ret_code); - int shrink_wbp_if_needed_(); -private: - bool is_inited_; - ObThreadCond idle_cond_; - int64_t last_swap_timestamp_; - - int64_t swap_job_num_; - ObSpLinkQueue swap_job_list_; // list for swap jobs to be processed - int64_t working_list_size_; - ObSpLinkQueue working_list_; // list for swap jobs that are being processed - - ObTmpFileSwapMonitor swap_monitor_; - - ObTmpFileFlushThread &flush_thread_ref_; - int64_t flush_io_finished_round_; - - ObTmpWriteBufferPool &wbp_; - ObTmpFileEvictionManager &evict_mgr_; - ObTmpFilePageCacheController &pc_ctrl_; - ObTmpFileManager *file_mgr_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_THREAD_WRAPPER_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_types.h b/src/storage/tmp_file/ob_tmp_file_types.h deleted file mode 100644 index 84d220fd1e..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_types.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "share/ob_server_struct.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpFileIOCtx; -class ObTmpWriteBufferPool; -class ObTmpFileFlushPriorityManager; - -//for virtual table show -class ObTmpFileInfo -{ -public: - ObTmpFileInfo() : - trace_id_(), - dir_id_(ObTmpFileGlobal::INVALID_TMP_FILE_DIR_ID), - fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - file_size_(0), - truncated_offset_(0), - is_deleting_(false), - cached_data_page_num_(0), - write_back_data_page_num_(0), - flushed_data_page_num_(0), - ref_cnt_(0), - birth_ts_(-1), - tmp_file_ptr_(nullptr), - label_(), - write_info_(), - read_info_() {} - virtual ~ObTmpFileInfo() { reset(); } - virtual int init(const ObCurTraceId::TraceId &trace_id, - const int64_t dir_id, - const int64_t fd, - const int64_t file_size, - const int64_t truncated_offset, - const bool is_deleting, - const int64_t cached_page_num, - const int64_t write_back_data_page_num, - const int64_t flushed_data_page_num, - const int64_t ref_cnt, - const int64_t birth_ts, - const void* const tmp_file_ptr, - const char* const label, - const int64_t write_req_cnt, - const int64_t unaligned_write_req_cnt, - const int64_t write_persisted_tail_page_cnt, - const int64_t lack_page_cnt, - const int64_t last_modify_ts, - const int64_t read_req_cnt, - const int64_t unaligned_read_req_cnt, - const int64_t total_truncated_page_read_cnt, - const int64_t total_kv_cache_page_read_cnt, - const int64_t total_uncached_page_read_cnt, - const int64_t total_wbp_page_read_cnt, - const int64_t truncated_page_read_hits, - const int64_t kv_cache_page_read_hits, - const int64_t uncached_page_read_hits, - const int64_t wbp_page_read_hits, - const int64_t total_read_size, - const int64_t last_access_ts); - virtual void reset(); -public: - struct ObTmpFileWriteInfo - { - public: - ObTmpFileWriteInfo() : - write_req_cnt_(0), - unaligned_write_req_cnt_(0), - write_persisted_tail_page_cnt_(0), - lack_page_cnt_(0), - last_modify_ts_(-1) {} - void reset(); - public: - int64_t write_req_cnt_; - int64_t unaligned_write_req_cnt_; - int64_t write_persisted_tail_page_cnt_; - int64_t lack_page_cnt_; - int64_t last_modify_ts_; - TO_STRING_KV(K_(write_req_cnt), K_(unaligned_write_req_cnt), - K_(write_persisted_tail_page_cnt), K_(lack_page_cnt), K_(last_modify_ts)); - }; - struct ObTmpFileReadInfo - { - public: - ObTmpFileReadInfo() : - read_req_cnt_(0), - unaligned_read_req_cnt_(0), - total_truncated_page_read_cnt_(0), - total_kv_cache_page_read_cnt_(0), - total_uncached_page_read_cnt_(0), - total_wbp_page_read_cnt_(0), - truncated_page_read_hits_(0), - kv_cache_page_read_hits_(0), - uncached_page_read_hits_(0), - wbp_page_read_hits_(0), - total_read_size_(0), - last_access_ts_(-1) {} - void reset(); - public: - int64_t read_req_cnt_; - int64_t unaligned_read_req_cnt_; - int64_t total_truncated_page_read_cnt_; // the total read count of truncated pages - int64_t total_kv_cache_page_read_cnt_; // the total read count of pages in kv_cache - int64_t total_uncached_page_read_cnt_; // the total read count of pages with io - int64_t total_wbp_page_read_cnt_; // the total read count of pages in wbp - int64_t truncated_page_read_hits_; // the hit count of truncated pages when read - int64_t kv_cache_page_read_hits_; // the hit count of pages in kv_cache when read - int64_t uncached_page_read_hits_; // the hit count of persisted pages when read - int64_t wbp_page_read_hits_; // the hit count of pages in wbp when read - int64_t total_read_size_; - int64_t last_access_ts_; - TO_STRING_KV(K_(read_req_cnt), K_(unaligned_read_req_cnt), K_(total_truncated_page_read_cnt), - K_(total_kv_cache_page_read_cnt), K_(total_uncached_page_read_cnt), - K_(total_wbp_page_read_cnt), K_(truncated_page_read_hits), K_(kv_cache_page_read_hits), - K_(uncached_page_read_hits), K_(wbp_page_read_hits), K_(total_read_size), K_(last_access_ts)); - }; - -public: - // common info - common::ObCurTraceId::TraceId trace_id_; - - int64_t dir_id_; - int64_t fd_; - int64_t file_size_; - int64_t truncated_offset_; - bool is_deleting_; - int64_t cached_data_page_num_; - int64_t write_back_data_page_num_; - int64_t flushed_data_page_num_; - int64_t ref_cnt_; - int64_t birth_ts_; - const void *tmp_file_ptr_; - ObFixedLengthString label_; - ObTmpFileWriteInfo write_info_; - ObTmpFileReadInfo read_info_; - - TO_STRING_KV(K(trace_id_), K(dir_id_), K(fd_), K(file_size_), - K(truncated_offset_), K(is_deleting_), K(cached_data_page_num_), - K(write_back_data_page_num_), K(flushed_data_page_num_), - K(ref_cnt_), K(birth_ts_), KP(tmp_file_ptr_), K(label_), - K(write_info_), K(read_info_)); -}; - -class ObSharedNothingTmpFile; - -class ObSNTmpFileHandle final -{ -public: - ObSNTmpFileHandle() : ptr_(nullptr) {} - ObSNTmpFileHandle(ObSharedNothingTmpFile *tmp_file); - ObSNTmpFileHandle(const ObSNTmpFileHandle &handle); - ObSNTmpFileHandle & operator=(const ObSNTmpFileHandle &other); - ~ObSNTmpFileHandle() { reset(); } - OB_INLINE ObSharedNothingTmpFile * get() const {return ptr_; } - bool is_inited() { return nullptr != ptr_; } - void reset(); - int init(ObSharedNothingTmpFile *tmp_file); - TO_STRING_KV(KP(ptr_)); -private: - ObSharedNothingTmpFile *ptr_; -}; - -struct ObTmpFileKey final -{ - explicit ObTmpFileKey(const int64_t fd) : fd_(fd) {} - OB_INLINE int hash(uint64_t &hash_val) const - { - hash_val = murmurhash(&fd_, sizeof(int64_t), 0); - return OB_SUCCESS; - } - OB_INLINE bool operator==(const ObTmpFileKey &other) const { return fd_ == other.fd_; } - TO_STRING_KV(K(fd_)); - int64_t fd_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.cpp b/src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.cpp deleted file mode 100644 index 378fbbbe15..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.cpp +++ /dev/null @@ -1,688 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_write_buffer_index_cache.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool.h" -#include "share/rc/ob_server_runtime.h" - -namespace oceanbase -{ -namespace tmp_file -{ -ObTmpFileWBPIndexCache::ObTmpFileWBPIndexCache() : - ObTmpFileCircleArray(), bucket_array_allocator_(nullptr), bucket_allocator_(nullptr), - page_buckets_(nullptr) , - fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), wbp_(nullptr), - sparsify_count_(0), - ignored_push_count_(0), - max_bucket_array_capacity_(MAX_BUCKET_ARRAY_CAPACITY) {} - -ObTmpFileWBPIndexCache::~ObTmpFileWBPIndexCache() -{ - destroy(); -} - -int ObTmpFileWBPIndexCache::init(const int64_t fd, ObTmpWriteBufferPool* wbp, - ObIAllocator *wbp_index_cache_allocator, - ObIAllocator *wbp_index_cache_bkt_allocator) -{ - int ret = OB_SUCCESS; - void *buf = nullptr; - - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_ISNULL(wbp) || OB_ISNULL(wbp_index_cache_allocator) || - OB_ISNULL(wbp_index_cache_bkt_allocator)) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_ISNULL(buf = wbp_index_cache_allocator->alloc(sizeof(ObArray), - lib::ObMemAttr("TmpFileIdxCache")))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (FALSE_IT(page_buckets_ = new (buf) ObArray())) { - } else if (FALSE_IT(page_buckets_->set_attr(lib::ObMemAttr("TmpFileIdxCache")))) { - } else if (OB_FAIL(page_buckets_->prepare_allocate(INIT_BUCKET_ARRAY_CAPACITY, nullptr))) { - page_buckets_->destroy(); - wbp_index_cache_allocator->free(buf); - page_buckets_ = nullptr; - } else { - is_inited_ = true; - fd_ = fd; - wbp_ = wbp; - bucket_allocator_ = wbp_index_cache_bkt_allocator; - bucket_array_allocator_ = wbp_index_cache_allocator; - left_ = 0; - right_ = -1; - size_ = 0; - capacity_ = INIT_BUCKET_ARRAY_CAPACITY; - } - return ret; -} - -void ObTmpFileWBPIndexCache::reset() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - left_ = 0; - right_ = -1; - size_ = 0; - capacity_ = 0; - sparsify_count_ = 0; - ignored_push_count_ = 0; - if (OB_ISNULL(page_buckets_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(bucket_allocator_)) { - ret = OB_ERR_UNEXPECTED; - } else { - for (int64_t i = 0; i < page_buckets_->count(); ++i) { - if (OB_NOT_NULL(page_buckets_->at(i))) { - page_buckets_->at(i)->destroy(); - bucket_allocator_->free(page_buckets_->at(i)); - page_buckets_->at(i) = nullptr; - } - } - page_buckets_->reset(); - } - } -} - -void ObTmpFileWBPIndexCache::destroy() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - reset(); - is_inited_ = false; - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - wbp_ = nullptr; - if (OB_ISNULL(page_buckets_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(bucket_array_allocator_)) { - ret = OB_ERR_UNEXPECTED; - } else { - page_buckets_->destroy(); - bucket_array_allocator_->free(page_buckets_); - page_buckets_ = nullptr; - bucket_allocator_ = nullptr; - bucket_array_allocator_ = nullptr; - } - } -} - -int ObTmpFileWBPIndexCache::push(const uint32_t page_index) -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (0 == capacity_ || is_full()) { - if (max_bucket_array_capacity_ <= capacity_) { - if (OB_FAIL(sparsify_())) { - } - } else if (OB_FAIL(expand_())) { - } - } - - if (OB_SUCC(ret)) { - if (ignored_push_count_ < ((1 << sparsify_count_) - 1)) { - ignored_push_count_ += 1; - } else if (FALSE_IT(ignored_push_count_ = 0)) { - } else if (is_empty() || (OB_NOT_NULL(page_buckets_->at(right_)) && page_buckets_->at(right_)->is_full())) { - // alloc a new bucket - inc_pos_(right_); - - void *buf = nullptr; - ObTmpFilePageIndexBucket* bucket = nullptr; - if (OB_ISNULL(buf = bucket_allocator_->alloc(sizeof(ObTmpFilePageIndexBucket), - lib::ObMemAttr("TmpFileIdxBkt")))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (FALSE_IT(bucket = new (buf) ObTmpFilePageIndexBucket())) { - } else if (OB_FAIL(bucket->init(fd_, wbp_))) { - } else if (OB_FAIL(bucket->push(page_index))) { - } else { - page_buckets_->at(right_) = bucket; - } - - if (OB_FAIL(ret)) { - if (OB_NOT_NULL(bucket)) { - bucket->destroy(); - bucket_allocator_->free(bucket); - page_buckets_->at(right_) = nullptr; - } - dec_pos_(right_); - } else { - size_ += 1; - } - } else if (OB_ISNULL(page_buckets_->at(right_))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(page_buckets_->at(right_)->push(page_index))) { - } - } - - return ret; -} - -int ObTmpFileWBPIndexCache::truncate(const int64_t truncate_page_virtual_id) -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (!is_empty()) { - const int64_t logic_begin_pos = left_; - const int64_t logic_end_pos = get_logic_tail_(); - bool truncate_over = false; - for (int64_t i = logic_begin_pos; OB_SUCC(ret) && !truncate_over && i <= logic_end_pos; i++) { - int64_t bkt_min_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - int64_t bkt_min_page_index = ObTmpFileGlobal::INVALID_PAGE_ID; - ObTmpFilePageIndexBucket *&cur_bucket = page_buckets_->at(i % capacity_); - if (OB_ISNULL(cur_bucket)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY((bkt_min_page_index = cur_bucket->get_min_page_index()) == - ObTmpFileGlobal::INVALID_PAGE_ID)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->get_page_virtual_id(fd_, bkt_min_page_index, bkt_min_page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == bkt_min_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (i != logic_begin_pos) { - // truncate previous bucket - if (truncate_page_virtual_id < bkt_min_page_virtual_id) { - truncate_over = true; - ObTmpFilePageIndexBucket *&previous_bucket = page_buckets_->at(get_previous_pos(i % capacity_)); - if (OB_ISNULL(previous_bucket)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(previous_bucket->truncate(truncate_page_virtual_id))) { - } else if (OB_UNLIKELY(previous_bucket->is_empty())) { - // when truncate_page_virtual_id is smaller than min_page_virtual_id of cur bucket, - // there must exist at least one page in previous bucket whose virtual page id is larger than - // or equal to truncate_page_virtual_id (which means this page index doesn't need to be truncated). - // however, truncate all page indexes of previous bucket will not cause some problems. - // thus, we just allow code continue to run - previous_bucket->destroy(); - bucket_allocator_->free(previous_bucket); - previous_bucket = nullptr; - inc_pos_(left_); - size_ -= 1; - } - } else { // truncate_page_virtual_id >= bkt_min_page_virtual_id - ObTmpFilePageIndexBucket *&previous_bucket = page_buckets_->at(get_previous_pos(i % capacity_)); - if (OB_ISNULL(previous_bucket)) { - ret = OB_ERR_UNEXPECTED; - } else { - previous_bucket->destroy(); - bucket_allocator_->free(previous_bucket); - previous_bucket = nullptr; - inc_pos_(left_); - size_ -= 1; - } - } - } - if (i == logic_end_pos && truncate_page_virtual_id > bkt_min_page_virtual_id) { - if (FAILEDx(cur_bucket->truncate(truncate_page_virtual_id))) { - } else if (cur_bucket->is_empty()) { - cur_bucket->destroy(); - bucket_allocator_->free(cur_bucket); - cur_bucket = nullptr; - inc_pos_(left_); - size_ -= 1; - } - } - } // end for - - if (OB_FAIL(ret)) { - } else if (is_empty()) { - reset(); - } else { - shrink_(); - } - } - - return ret; -} - -// 1. if 'target_page_virtual_id' is smaller than virtual page id of first page in cache, -// page_index will be INVALID_PAGE_ID. -// in this case, caller should directly search write buffer pool with the beginning page index of file -// 2. if 'target_page_virtual_id' is in the range of cached pages but the page index of it doesn't exist in cache, -// the cache will find a page whose virtual id is smaller than and closest to 'target_page_virtual_id' -// and then iterate the page index of wbp from the closest page index to find the according page_index -int ObTmpFileWBPIndexCache::binary_search(const int64_t target_page_virtual_id, uint32_t &page_index) -{ - int ret = OB_SUCCESS; - page_index = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_LIKELY(!is_empty())) { - int64_t left_pos = left_; - int64_t right_pos = get_logic_tail_(); - ObTmpFilePageIndexBucket *target_bucket = nullptr; - bool find = false; - while (left_pos <= right_pos && !find && OB_SUCC(ret)) { - // find the bucket whose min_page_virtual_id is small than and closest to target_page_virtual_id - const int64_t logic_mid = left_pos + (right_pos - left_pos) / 2; - const int64_t mid = logic_mid % capacity_; - ObTmpFilePageIndexBucket *mid_bucket = page_buckets_->at(mid); - int64_t min_page_virtual_id = -1; - if (OB_ISNULL(mid_bucket)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(mid_bucket->get_min_page_index() == ObTmpFileGlobal::INVALID_PAGE_ID)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->get_page_virtual_id(fd_, mid_bucket->get_min_page_index(), min_page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == min_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (min_page_virtual_id <= target_page_virtual_id) { - target_bucket = mid_bucket; - if (min_page_virtual_id == target_page_virtual_id) { - find = true; - page_index = mid_bucket->get_min_page_index(); - } else { - left_pos = logic_mid + 1; - } - } else { - right_pos = logic_mid - 1; - } - } // end while - - if (OB_FAIL(ret)) { - } else if (find) { - // do nothing - } else if (OB_ISNULL(target_bucket)) { - // page_index = ObTmpFileGlobal::INVALID_PAGE_ID; - } else if (OB_FAIL(target_bucket->binary_search(target_page_virtual_id, page_index))) { - } - } - return ret; -} - -int ObTmpFileWBPIndexCache::expand_() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(max_bucket_array_capacity_ == capacity_)) { - ret = OB_SIZE_OVERFLOW; - } else if (OB_UNLIKELY(capacity_ != 0 && !is_full())) { - ret = OB_ERR_UNEXPECTED; - } else { - int64_t new_capacity = 0 == capacity_ ? - INIT_BUCKET_ARRAY_CAPACITY: - MIN(capacity_ * 2, max_bucket_array_capacity_); - if (OB_FAIL(page_buckets_->prepare_allocate(new_capacity, nullptr))) { - } else if (!is_empty() && right_ < left_) { - if (OB_UNLIKELY(right_ + capacity_ >= new_capacity)) { - ret = OB_ERR_UNEXPECTED; - } else { - for (int64_t i = 0; i <= right_; ++i) { - ObTmpFilePageIndexBucket*& cur_bucket = page_buckets_->at(i); - ObTmpFilePageIndexBucket*& new_bucket = page_buckets_->at(capacity_ + i); - new_bucket = cur_bucket; - page_buckets_->at(i) = nullptr; - } - right_ += capacity_; - } - } - - if (OB_SUCC(ret)) { - capacity_ = new_capacity; - } - } - return ret; -} - -void ObTmpFileWBPIndexCache::shrink_() -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(get_logic_tail_() - left_ + 1 != size_)) { - ret = OB_ERR_UNEXPECTED; - } else if (size_ > capacity_ / SHRINK_THRESHOLD || - INIT_BUCKET_ARRAY_CAPACITY == capacity_) { - // no need to shrink - } else { - int64_t new_capacity = capacity_ / 2; - void *buf = nullptr; - - ObArray *new_buckets = nullptr; - - if (OB_UNLIKELY(size_ > new_capacity)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_ISNULL(buf = bucket_array_allocator_->alloc(sizeof(ObArray), - lib::ObMemAttr("TmpFileIdxCache")))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (FALSE_IT(new_buckets = new (buf) ObArray())) { - } else if (FALSE_IT(new_buckets->set_attr(lib::ObMemAttr("TmpFileIdxCache")))) { - } else if (OB_FAIL(new_buckets->prepare_allocate(new_capacity, nullptr))) { - new_buckets->destroy(); - bucket_array_allocator_->free(buf); - new_buckets = nullptr; - } else { - for (int64_t i = left_; i <= get_logic_tail_() && OB_SUCC(ret); i++) { - ObTmpFilePageIndexBucket *bucket = page_buckets_->at(i % capacity_); - new_buckets->at(i - left_) = bucket; - } // end for - page_buckets_->destroy(); - bucket_array_allocator_->free(page_buckets_); - left_ = 0; - right_ = size_ - 1; - capacity_ = new_capacity; - page_buckets_ = new_buckets; - } - } -} - -int ObTmpFileWBPIndexCache::sparsify_() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(max_bucket_array_capacity_ != capacity_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(capacity_ % 2 != 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!is_full())) { - ret = OB_ERR_UNEXPECTED; - } else { - int64_t cur_bucket_pos = left_; - for (int64_t i = left_; i <= get_logic_tail_() && OB_SUCC(ret); i++) { - if (OB_ISNULL(page_buckets_->at(i % capacity_))) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(page_buckets_->at(i % capacity_)->shrink_half())) { - } else if ((i - left_) % 2 == 0) { - page_buckets_->at(cur_bucket_pos % capacity_) = page_buckets_->at(i % capacity_); - } else { - if (OB_FAIL(page_buckets_->at(cur_bucket_pos % capacity_)->merge(*page_buckets_->at(i % capacity_)))) { - } else { - page_buckets_->at(i % capacity_)->destroy(); - bucket_allocator_->free(page_buckets_->at(i % capacity_)); - cur_bucket_pos++; - } - } - - if (OB_SUCC(ret) && i > (get_logic_tail_() - left_) / 2 + left_) { - page_buckets_->at(i % capacity_) = nullptr; - } - } - - if (OB_SUCC(ret)) { - right_ = (cur_bucket_pos - 1) % capacity_; - size_ /= 2; - sparsify_count_ += 1; - ignored_push_count_ = 0; - } - } - LOG_INFO("sparsify tmp file wbp index cache over", KR(ret), KPC(this)); - return ret; -} - -ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::ObTmpFilePageIndexBucket() : - page_indexes_(), fd_(ObTmpFileGlobal::INVALID_TMP_FILE_FD), - wbp_(nullptr), min_page_index_(ObTmpFileGlobal::INVALID_PAGE_ID) {} - -ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::~ObTmpFilePageIndexBucket() -{ - destroy(); -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::init(int64_t fd, ObTmpWriteBufferPool* wbp) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(fd == ObTmpFileGlobal::INVALID_TMP_FILE_FD) || OB_ISNULL(wbp)) { - ret = OB_INVALID_ARGUMENT; - } else if (FALSE_IT(page_indexes_.set_attr(ObMemAttr("TmpFileIdxBkt")))) { - } else if (OB_FAIL(page_indexes_.prepare_allocate(BUCKET_CAPACITY, ObTmpFileGlobal::INVALID_PAGE_ID))) { - } else { - is_inited_ = true; - fd_ = fd; - wbp_ = wbp; - min_page_index_ = ObTmpFileGlobal::INVALID_PAGE_ID; - left_ = 0; - right_ = -1; - size_ = 0; - capacity_ = BUCKET_CAPACITY; - } - return ret; -} - -void ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::destroy() -{ - is_inited_ = false; - fd_ = ObTmpFileGlobal::INVALID_TMP_FILE_FD; - wbp_ = nullptr; - left_ = 0; - right_ = -1; - size_ = 0; - capacity_ = 0; - min_page_index_ = ObTmpFileGlobal::INVALID_PAGE_ID; - page_indexes_.reset(); -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::push(const uint32_t page_index) -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_full())) { - ret = OB_SIZE_OVERFLOW; - } else { - if (OB_UNLIKELY(is_empty())) { - min_page_index_ = page_index; - } - inc_pos_(right_); - page_indexes_[right_] = page_index; - size_ += 1; - } - - return ret; -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::pop_() -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_empty())) { - ret = OB_ERR_UNEXPECTED; - } else { - page_indexes_[left_] = ObTmpFileGlobal::INVALID_PAGE_ID; - inc_pos_(left_); - size_ -= 1; - - if (is_empty()) { - destroy(); - } else { - min_page_index_ = page_indexes_[left_]; - } - } - return ret; -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::truncate(const int64_t truncate_page_virtual_id) -{ - int ret = OB_SUCCESS; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_empty())) { - ret = OB_ERR_UNEXPECTED; - } else { - const int64_t logic_begin_pos = left_; - const int64_t logic_end_pos = get_logic_tail_(); - bool truncate_over = false; - for (int64_t i = logic_begin_pos; OB_SUCC(ret) && !truncate_over && i <= logic_end_pos; i++) { - int64_t page_virtual_id = -1; - if (OB_UNLIKELY(page_indexes_[i % capacity_] == ObTmpFileGlobal::INVALID_PAGE_ID)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->get_page_virtual_id(fd_, page_indexes_[i % capacity_], page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (page_virtual_id < truncate_page_virtual_id) { - if (OB_FAIL(pop_())) { - } - } else { - truncate_over = true; - } - } // end for - } - return ret; -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::binary_search( - const int64_t target_page_virtual_id, uint32_t &page_index) -{ - int ret = OB_SUCCESS; - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else if (OB_UNLIKELY(is_empty())) { - ret = OB_ERR_UNEXPECTED; - } else { - bool find = false; - int64_t left_pos = left_; - int64_t right_pos = get_logic_tail_(); - uint32_t target_page_index = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t cur_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - while (left_pos <= right_pos && !find && OB_SUCC(ret)) { - const int64_t logic_mid = left_pos + (right_pos - left_pos) / 2; - const int64_t mid = logic_mid % capacity_; - const uint32_t mid_page = page_indexes_[mid]; - if (OB_FAIL(wbp_->get_page_virtual_id(fd_, mid_page, cur_page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == cur_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (cur_page_virtual_id <= target_page_virtual_id) { - target_page_index = mid_page; - if (cur_page_virtual_id == target_page_virtual_id) { - find = true; - } else { - left_pos = logic_mid + 1; - } - } else { - right_pos = logic_mid - 1; - } - } // end while - - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == target_page_index)) { - ret = OB_ERR_UNEXPECTED; - } else if (find) { - page_index = target_page_index; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == target_page_index)) { - ret = OB_ERR_UNEXPECTED; - } else { - int64_t cur_page_index = target_page_index; - while (OB_SUCC(ret) && !find) { - uint32_t next_page_index = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - if (OB_FAIL(wbp_->get_page_virtual_id(fd_, cur_page_index, cur_page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == cur_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->get_next_page_id(fd_, cur_page_index, ObTmpFilePageUniqKey(cur_page_virtual_id), - next_page_index))) { - } else if (ObTmpFileGlobal::INVALID_PAGE_ID == next_page_index) { - ret = OB_ENTRY_NOT_EXIST; - } else if (OB_FAIL(wbp_->get_page_virtual_id(fd_, next_page_index, page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (page_virtual_id == target_page_virtual_id) { - page_index = next_page_index; - find = true; - } else if (page_virtual_id < target_page_virtual_id) { - cur_page_index = next_page_index; - } else { - ret = OB_ERR_UNEXPECTED; - } - } // end while - } - } - return ret; -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::shrink_half() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(capacity_ % 2 != 0)) { - ret = OB_ERR_UNEXPECTED; - } else if (size_ <= capacity_ / 2) { - // no need to shrink, do nothing - } else { - const int64_t eliminate_num = size_ - capacity_ / 2; - const int64_t eliminate_modulus = size_ / eliminate_num; - int64_t remain_eliminate_num = eliminate_num; - int64_t logic_pos = left_; - for (int64_t i = left_; i <= get_logic_tail_(); i++) { - if ((i - left_) % eliminate_modulus != 0 || 0 == remain_eliminate_num) { - page_indexes_[logic_pos % capacity_] = page_indexes_[i % capacity_]; - logic_pos++; - } else { // eliminate current page index - remain_eliminate_num--; - } - } - - for (int64_t i = logic_pos; i <= get_logic_tail_(); i++) { - page_indexes_[i % capacity_] = ObTmpFileGlobal::INVALID_PAGE_ID; - } - - right_ = (logic_pos - 1) % capacity_; - size_ -= eliminate_num; - - if (!is_empty()) { - min_page_index_ = page_indexes_[left_]; - } else { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("tmp file page index bucket is unexpected empty", KR(ret), KPC(this)); - } - } - return ret; -} - -int ObTmpFileWBPIndexCache::ObTmpFilePageIndexBucket::merge(ObTmpFilePageIndexBucket& other) -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(other.is_empty())) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(other.size_ + size_ > capacity_)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(!is_empty())) { - int64_t bkt_min_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - int64_t other_bkt_min_page_virtual_id = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - if (OB_FAIL(wbp_->get_page_virtual_id(fd_, min_page_index_, bkt_min_page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == bkt_min_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(wbp_->get_page_virtual_id(fd_, other.min_page_index_, other_bkt_min_page_virtual_id))) { - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == other_bkt_min_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_UNLIKELY(bkt_min_page_virtual_id > other_bkt_min_page_virtual_id)) { - ret = OB_ERR_UNEXPECTED; - } - } - - if (OB_SUCC(ret)) { - for (int64_t i = other.left_; OB_SUCC(ret) && i <= other.get_logic_tail_(); i++) { - uint32_t page_index = other.page_indexes_[i % other.capacity_]; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == page_index)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(push(page_index))) { - } - } - } - return ret; -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.h b/src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.h deleted file mode 100644 index b1de269bd9..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_write_buffer_index_cache.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_WRITE_BUFFER_INDEX_CACHE_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_WRITE_BUFFER_INDEX_CACHE_H_ - -#include "lib/container/ob_array.h" -#include "lib/allocator/ob_fifo_allocator.h" - -namespace oceanbase -{ -namespace tmp_file -{ -class ObTmpWriteBufferPool; - -class ObTmpFileCircleArray -{ -public: - ObTmpFileCircleArray() : is_inited_(false), left_(0), right_(-1), size_(0), capacity_(0) {} - virtual ~ObTmpFileCircleArray() {}; - virtual int push(const uint32_t page_index) = 0; - virtual int truncate(const int64_t truncate_page_virtual_id) = 0; - virtual int binary_search(const int64_t target_page_virtual_id, uint32_t &page_index) = 0; - -public: - OB_INLINE int64_t size() const { return size_; } - OB_INLINE bool is_empty() const { return size_ == 0; } - virtual OB_INLINE bool is_full() const { return size_ == capacity_; } - TO_STRING_KV(K(is_inited_), K(left_), K(right_), K(size_), K(capacity_)); - -protected: - OB_INLINE void inc_pos_(int64_t &pos) { pos = pos == capacity_ - 1 ? 0 : pos + 1; } - OB_INLINE void dec_pos_(int64_t &pos) { pos = pos == 0 ? capacity_ - 1 : pos - 1; } - OB_INLINE int64_t get_previous_pos(const int64_t pos) const { return pos == 0 ? capacity_ - 1 : pos - 1; } - OB_INLINE int64_t get_logic_tail_() const { return get_logic_pos_(right_); } - OB_INLINE int64_t get_logic_pos_(const int64_t pos) const - { - return pos >= left_ ? pos : capacity_ + pos; - } - -protected: - bool is_inited_; - int64_t left_; // close interval - int64_t right_; // close interval - int64_t size_; // record valid number of array - int64_t capacity_; // record the capacity of array -}; - -// Attention: -// ObTmpFileWBPIndexCache caches page indexes of a tmp file in write buffer pool. -// When ObTmpFileWBPIndexCache reaches the limitation of capacity, -// it will eliminates half page indexes of buckets for caching new page index. -// thus, the range of cached indexes might be not continuous. -class ObTmpFileWBPIndexCache : public ObTmpFileCircleArray -{ -public: - ObTmpFileWBPIndexCache(); - ~ObTmpFileWBPIndexCache(); - int init(const int64_t fd, ObTmpWriteBufferPool* wb, - ObIAllocator *wbp_index_cache_allocator, - ObIAllocator *wbp_index_cache_bkt_allocator); - void destroy(); - void reset(); - virtual int push(const uint32_t page_index) override; - // truncate page virtual id is open interval - virtual int truncate(const int64_t truncate_page_virtual_id) override; - // truncate page virtual id is close interval - virtual int binary_search(const int64_t target_page_virtual_id, uint32_t &page_index) override; - virtual OB_INLINE bool is_full() const override - { - return ObTmpFileCircleArray::is_full() && - right_ >= 0 && right_ < capacity_ && - OB_NOT_NULL(page_buckets_) && - OB_NOT_NULL(page_buckets_->at(right_)) && - page_buckets_->at(right_)->is_full(); - } - INHERIT_TO_STRING_KV("ObTmpFileCircleArray", ObTmpFileCircleArray, - K(fd_), KP(wbp_), KP(page_buckets_), - K(sparsify_count_), K(ignored_push_count_), - KP(bucket_array_allocator_), KP(bucket_allocator_), - K(max_bucket_array_capacity_)); - -private: - class ObTmpFilePageIndexBucket : public ObTmpFileCircleArray - { - public: - ObTmpFilePageIndexBucket(); - ~ObTmpFilePageIndexBucket(); - int init(int64_t fd, ObTmpWriteBufferPool* wbp); - void destroy(); - virtual int push(const uint32_t page_index) override; - // truncate offset is open interval - virtual int truncate(const int64_t truncate_page_virtual_id) override; - // target offset is close interval - virtual int binary_search(const int64_t target_page_virtual_id, uint32_t &page_index) override; - int shrink_half(); - int merge(ObTmpFilePageIndexBucket& other); - OB_INLINE int64_t get_min_page_index() const { return min_page_index_; } - INHERIT_TO_STRING_KV("ObTmpFileCircleArray", ObTmpFileCircleArray, - K(fd_), KP(wbp_), K(min_page_index_)); - private: - int pop_(); - private: - // due to each page index in bucket directs to a 8KB page in wbp, - // a bucket could indicate a 256KB data and hold on 128B memory - static const int64_t BUCKET_CAPACITY = 1 << 5; - - private: - common::ObArray page_indexes_; - int64_t fd_; - ObTmpWriteBufferPool* wbp_; - int64_t min_page_index_; - }; - -private: - // due to each bucket could indicate a 256KB data in wbp, - // the cache could indicate a 256MB data and hold on (128 + 8)*2^10 = 136KB memory at most - static const int64_t MAX_BUCKET_ARRAY_CAPACITY = 1 << 10; - static const int64_t INIT_BUCKET_ARRAY_CAPACITY = 1 << 3; // indicates 2MB data in wbp at most - static const int64_t SHRINK_THRESHOLD = 4; // attention: this value must be larger than 2 - -private: - int expand_(); - void shrink_(); - int sparsify_(); - -private: - ObIAllocator *bucket_array_allocator_; - ObIAllocator *bucket_allocator_; - common::ObArray *page_buckets_; - int64_t fd_; - ObTmpWriteBufferPool* wbp_; - int64_t sparsify_count_; // to keep each page indexes in cache have same sparse interval, - // we need to ignore 2^(sparsify_count_) - 1 push() calling - int64_t ignored_push_count_; - int64_t max_bucket_array_capacity_; // only allowed to modify this var in unit test!!! -}; - -} // end namespace tmp_file -} // end namespace oceanbase -#endif // OCEANBASE_STORAGE_TMP_FILE_OB_TMP_FILE_WRITE_BUFFER_INDEX_CACHE_H_ diff --git a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool.cpp b/src/storage/tmp_file/ob_tmp_file_write_buffer_pool.cpp deleted file mode 100644 index 06cd549960..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool.cpp +++ /dev/null @@ -1,1419 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define USING_LOG_PREFIX STORAGE - -#include "rust/config.h" -#include "share/ob_server_struct.h" -#include "lib/alloc/alloc_func.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -double ObTmpWriteBufferPool::MAX_DATA_PAGE_USAGE_RATIO = 0.9; - -ObTmpWriteBufferPool::ObTmpWriteBufferPool() - : fat_(), - lock_(), - free_list_lock_(), - allocator_(), - is_inited_(false), - capacity_(0), - dirty_page_num_(0), - used_page_num_(0), - first_free_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - wbp_memory_limit_(-1), - default_wbp_memory_limit_(-1), - last_access_runtime_config_ts_(-1), - last_shrink_complete_ts_(ObTimeUtility::current_time()), - max_used_watermark_after_shrinking_(0), - meta_page_cnt_(0), - data_page_cnt_(0), - dirty_meta_page_cnt_(0), - dirty_data_page_cnt_(0), - write_back_data_cnt_(0), - write_back_meta_cnt_(0) -{ -} - -ObTmpWriteBufferPool::~ObTmpWriteBufferPool() -{ - destroy(); -} - -int ObTmpWriteBufferPool::init() -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(is_inited_)) { - ret = OB_INIT_TWICE; - } else if (OB_FAIL(allocator_.init( - lib::ObMallocAllocator::get_instance(), OB_MALLOC_BIG_BLOCK_SIZE, - ObMemAttr("TmpFileWBPBlk", ObCtxIds::DEFAULT_CTX_ID)))) { - } else if (OB_FAIL(fat_.init())) { - } else { - last_shrink_complete_ts_ = ObTimeUtility::current_time(); - is_inited_ = true; - } - return ret; -} - -void ObTmpWriteBufferPool::destroy() -{ - release_all_blocks_(); - capacity_ = 0; - dirty_page_num_ = 0; - used_page_num_ = 0; - first_free_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - last_access_runtime_config_ts_ = -1; - last_shrink_complete_ts_ = -1; - max_used_watermark_after_shrinking_ = 0; - data_page_cnt_ = 0; - meta_page_cnt_ = 0; - dirty_meta_page_cnt_ = 0; - dirty_data_page_cnt_ = 0; - write_back_data_cnt_ = 0; - write_back_meta_cnt_ = 0; - wbp_memory_limit_ = -1; - default_wbp_memory_limit_ = -1; - fat_.destroy(); - allocator_.reset(); - is_inited_ = false; - shrink_ctx_.reset(); -} - -// limit data pages to use a maximum of 90% of the total space in the write buffer pool; -// considering that the total amount of meta pages for a single file accounts for less than 1% of data pages, -// there is no limit set for meta pages when allocating pages. -int ObTmpWriteBufferPool::inner_alloc_page_(const int64_t fd, - const ObTmpFilePageUniqKey page_key, - uint32_t &new_page_id, - char *&new_page_buf) -{ - int ret = OB_SUCCESS; - uint32_t curr_first_free_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t next_first_free_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - common::TCRWLock::RLockGuard guard(lock_); - ObSpinLockGuard list_guard(free_list_lock_); - if (has_free_page_(page_key.type_)) { - bool cas_succeed = false; - bool is_in_shrinking_range = false; - // fetch one free page. if it falls within the shrinking not_alloc_range, - // add it to the shrink list and proceed to the next free page. - // otherwise, allocate the page as usual. - do { - curr_first_free_page_id = ATOMIC_LOAD(&first_free_page_id_); - if (!is_valid_page_id_(curr_first_free_page_id) || OB_ISNULL(fat_[curr_first_free_page_id].buf_)) { - ret = OB_SEARCH_NOT_FOUND; - break; - } - next_first_free_page_id = fat_[curr_first_free_page_id].next_page_id_; - cas_succeed = ATOMIC_BCAS(&first_free_page_id_, curr_first_free_page_id, next_first_free_page_id); - if (cas_succeed) { - is_in_shrinking_range = false; - if (shrink_ctx_.is_valid() && shrink_ctx_.in_not_alloc_range(curr_first_free_page_id)) { - // put page into shrink list, outer loop continue - is_in_shrinking_range = true; - insert_page_entry_to_free_list_(curr_first_free_page_id, shrink_ctx_.shrink_list_head_); - ATOMIC_INC(&shrink_ctx_.shrink_list_size_); - } - } - } while (OB_SUCC(ret) && (!cas_succeed || is_in_shrinking_range)); - - if (OB_SUCC(ret) && is_valid_page_id_(curr_first_free_page_id)) { - fat_[curr_first_free_page_id].fd_ = fd; - fat_[curr_first_free_page_id].next_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - fat_[curr_first_free_page_id].page_key_ = page_key; - fat_[curr_first_free_page_id].switch_state(ObPageEntry::Ops::ALLOC); - new_page_id = curr_first_free_page_id; - new_page_buf = fat_[new_page_id].buf_; - ATOMIC_INC(&used_page_num_); - - const int64_t current_used_page_percent = ATOMIC_LOAD(&used_page_num_) * 100 / fat_.size(); - if (ATOMIC_LOAD(&max_used_watermark_after_shrinking_) < current_used_page_percent) { - // compare and set max_used_watermark_ is protected by free_list_lock_ - ATOMIC_STORE(&max_used_watermark_after_shrinking_, current_used_page_percent); - } - } - } - - if (ObTmpFileGlobal::INVALID_PAGE_ID == new_page_id) { - ret = OB_SEARCH_NOT_FOUND; - } - - return ret; -} - -int ObTmpWriteBufferPool::alloc_page_(const int64_t fd, - const ObTmpFilePageUniqKey page_key, - uint32_t &new_page_id, - char *&new_page_buf) -{ - int ret = OB_SUCCESS; - - new_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - new_page_buf = nullptr; - - // validate input argument. - if (ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd) { - ret = OB_INVALID_ARGUMENT; - } - - int64_t memory_limit = 0; - int64_t current_capacity = -1; - // continuously trying to allocate page and expand pool size, until capacity reach maximum memory limit. - while (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID == new_page_id && current_capacity < memory_limit) { - if (OB_FAIL(inner_alloc_page_(fd, page_key, new_page_id, new_page_buf))) { - if (OB_SEARCH_NOT_FOUND != ret) { - } else { // no free pages, try to expand pool size - ret = OB_SUCCESS; - memory_limit = get_memory_limit(); - current_capacity = ATOMIC_LOAD(&capacity_); - if (current_capacity < memory_limit && OB_FAIL(expand_())) { - LOG_WARN("wbp fail to expand", KR(ret), K(fd), K(ATOMIC_LOAD(&capacity_))); - } - } - } - } - - if (OB_ALLOCATE_MEMORY_FAILED == ret || OB_OP_NOT_ALLOW == ret || - (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID == new_page_id)) { - ret = OB_ALLOCATE_TMP_FILE_PAGE_FAILED; // can not allocate new page - } - - return ret; -} - -int ObTmpWriteBufferPool::alloc_page(const int64_t fd, - const ObTmpFilePageUniqKey page_key, - uint32_t &new_page_id, - char *&new_page_buf) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || !page_key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(alloc_page_(fd, page_key, new_page_id, new_page_buf))) { - } else if (page_key.type_ == PageEntryType::META) { - ATOMIC_INC(&meta_page_cnt_); - LOG_INFO("alloc meta page", KR(ret), K(new_page_id), K(fd), K(page_key)); - } else { - ATOMIC_INC(&data_page_cnt_); - } - return ret; -} - -int ObTmpWriteBufferPool::get_next_page_id( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - uint32_t &next_page_id) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || !page_key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(fd != fat_[page_id].fd_ || page_key != fat_[page_id].page_key_)) { - ret = OB_STATE_NOT_MATCH; - } else { - next_page_id = ATOMIC_LOAD(&fat_[page_id].next_page_id_); - } - return ret; -} - -int ObTmpWriteBufferPool::read_page( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - char *&buf, - uint32_t &next_page_id) -{ - int ret = OB_SUCCESS; - buf = nullptr; - next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || - OB_ISNULL(fat_[page_id].buf_) || - !page_key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(fd != fat_[page_id].fd_ || page_key != fat_[page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp fail to fetch page, PageEntry fd or offset not equal", KR(ret), K(page_id), K(fd), - K(page_key), K(fat_[page_id])); - } else { - buf = fat_[page_id].buf_; - next_page_id = fat_[page_id].next_page_id_; - } - return ret; -} - -int ObTmpWriteBufferPool::get_page_id_by_virtual_id(const int64_t fd, - const int64_t virtual_page_id, - const uint32_t begin_page_id, - uint32_t &page_id) -{ - int ret = OB_SUCCESS; - page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(begin_page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID == virtual_page_id || - fd != fat_[begin_page_id].fd_)) { - ret = OB_INVALID_ARGUMENT; - } else if (virtual_page_id < fat_[begin_page_id].page_key_.virtual_page_id_) { - ret = OB_SEARCH_NOT_FOUND; - } else { - uint32_t cur_page_id = begin_page_id; - while (cur_page_id != ObTmpFileGlobal::INVALID_PAGE_ID) { // iter to the end of this file - if (fat_[cur_page_id].page_key_.virtual_page_id_ >= virtual_page_id) { - if (fat_[cur_page_id].page_key_.virtual_page_id_ >= virtual_page_id) { - page_id = cur_page_id; - } - break; - } else { - cur_page_id = fat_[cur_page_id].next_page_id_; - } - } - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_PAGE_ID == page_id)) { - ret = OB_ITER_END; - } - } - return ret; -} - -int ObTmpWriteBufferPool::get_page_virtual_id(const int64_t fd, const uint32_t page_id, int64_t &virtual_page_id) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || !is_valid_page_id_(page_id))) { - ret = OB_SEARCH_NOT_FOUND; - } else if (fd != fat_[page_id].fd_) { - ret = OB_STATE_NOT_MATCH; - } else { - virtual_page_id = fat_[page_id].page_key_.virtual_page_id_; - } - return ret; -} - -int ObTmpWriteBufferPool::truncate_page(const int64_t fd, const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - const int64_t truncate_size) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || !page_key.is_valid() || - truncate_size > ObTmpFileGlobal::ALLOC_PAGE_SIZE || truncate_size <= 0 || - OB_ISNULL(fat_[page_id].buf_))) { - ret = OB_INVALID_ARGUMENT; - } else if (fd != fat_[page_id].fd_) { - ret = OB_STATE_NOT_MATCH; - } else if (page_key != fat_[page_id].page_key_) { - ret = OB_STATE_NOT_MATCH; - } else { - MEMSET(fat_[page_id].buf_, 0, truncate_size); - } - return ret; -} - -int ObTmpWriteBufferPool::link_page( - const int64_t fd, - const uint32_t page_id, - const uint32_t prev_page_id, - const ObTmpFilePageUniqKey prev_page_key) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id) || !is_valid_page_id_(prev_page_id) )) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || - !prev_page_key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(fat_[page_id].fd_ != fd || fat_[prev_page_id].fd_ != fd || - fat_[prev_page_id].next_page_id_ != ObTmpFileGlobal::INVALID_PAGE_ID || - prev_page_key != fat_[prev_page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("fail to link page, unexpected page id or offset", KR(ret), K(fd), - K(page_id), K(fat_[page_id]), K(prev_page_key), K(prev_page_id), - K(fat_[prev_page_id])); - } else if (prev_page_key.type_ == PageEntryType::META) { - //just for meta page check - ObTmpFilePageUniqKey page_key(prev_page_key.tree_level_, prev_page_key.level_page_index_ + 1); - if (OB_UNLIKELY(prev_page_key != fat_[prev_page_id].page_key_ - || page_key != fat_[page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("fail to link meta page, unexpected page offset", KR(ret), K(fd), K(prev_page_key), K(page_key), - K(fat_[prev_page_id]), K(fat_[page_id])); - } - } - - if (OB_SUCC(ret)) { - fat_[prev_page_id].next_page_id_ = page_id; - if (prev_page_key.type_ == PageEntryType::META) { - LOG_INFO("link meta page", KR(ret), K(fd), K(page_id), K(prev_page_id)); - } else { - } - } - return ret; -} - -int ObTmpWriteBufferPool::free_page( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - uint32_t &next_page_id) -{ - int ret = OB_SUCCESS; - next_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - common::TCRWLock::RLockGuard guard(lock_); - - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(ObTmpFileGlobal::INVALID_TMP_FILE_FD == fd || - !page_key.is_valid())) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(fd != fat_[page_id].fd_ - || page_key != fat_[page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp fail to free page, fd or offset not equal", KR(ret), K(page_id), K(fd), - K(page_key), K(fat_[page_id])); - } else { - // reset PageEntry, add it to free list head and update buffer pool statistics - next_page_id = ATOMIC_LOAD(&(fat_[page_id].next_page_id_)); - PageEntryType page_type = fat_[page_id].page_key_.type_; - if (PageEntryType::DATA == page_type) { - LOG_DEBUG("free data page", KR(ret), K(page_id), K(fd), K(fat_[page_id])); - } else { - LOG_INFO("free meta page", KR(ret), K(page_id), K(fd), K(fat_[page_id])); - } - ATOMIC_SET(&(fat_[page_id].fd_), ObTmpFileGlobal::INVALID_TMP_FILE_FD); - ATOMIC_SET(&(fat_[page_id].next_page_id_), ObTmpFileGlobal::INVALID_PAGE_ID); - if (ObPageEntry::State::DIRTY == ATOMIC_LOAD(&fat_[page_id].state_)) { - ATOMIC_DEC(&dirty_page_num_); - if (PageEntryType::DATA == page_type) { - ATOMIC_DEC(&dirty_data_page_cnt_); - } else if (PageEntryType::META == page_type) { - ATOMIC_DEC(&dirty_meta_page_cnt_); - } else { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid tmp file page type", KR(ret), K(page_id), K(fd), K(page_type)); - } - } - if (ObPageEntry::State::WRITE_BACK == ATOMIC_LOAD(&fat_[page_id].state_)) { - if (PageEntryType::DATA == page_type) { - ATOMIC_DEC(&write_back_data_cnt_); - } else if (PageEntryType::META == page_type) { - ATOMIC_DEC(&write_back_meta_cnt_); - } else { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid tmp file page type", KR(ret), K(page_id), K(fd), K(page_type)); - } - } - fat_[page_id].switch_state(ObPageEntry::Ops::DELETE); - fat_[page_id].page_key_.reset(); - - { - ObSpinLockGuard guard(free_list_lock_); - if (!shrink_ctx_.is_valid() || !shrink_ctx_.in_not_alloc_range(page_id)) { - insert_page_entry_to_free_list_(page_id, first_free_page_id_); - } else { - insert_page_entry_to_free_list_(page_id, shrink_ctx_.shrink_list_head_); - ATOMIC_INC(&shrink_ctx_.shrink_list_size_); - } - } - - ATOMIC_DEC(&used_page_num_); - - if (PageEntryType::DATA == page_type) { - ATOMIC_DEC(&data_page_cnt_); - } else if (PageEntryType::META == page_type) { - ATOMIC_DEC(&meta_page_cnt_); - } else { - LOG_ERROR("invalid tmp file page type", KR(ret), K(page_id), K(fd), K(page_type)); - } - } - return ret; -} - -// allocate a block size of WBP_BLOCK_SIZE each iteration -int ObTmpWriteBufferPool::expand_() -{ - int ret = OB_SUCCESS; - - // expand the buffer pool to twice the current size, with a minimum of WBP_BLOCK_SIZE - const int64_t memory_limit = get_memory_limit(); - int64_t current_capacity = ATOMIC_LOAD(&capacity_); - const int64_t expect_capacity = std::min( - memory_limit, std::max(current_capacity * 2, int64_t(WBP_BLOCK_SIZE))); - - // continuously allocate 2MB blocks and add them into the buffer pool. - while (OB_SUCC(ret) && current_capacity < expect_capacity) { - common::TCRWLock::WLockGuard guard(lock_); - // no need to acquire free_list_lock because we hold w-lock here - current_capacity = ATOMIC_LOAD(&capacity_); - if (shrink_ctx_.is_valid()) { - ret = OB_OP_NOT_ALLOW; - } else if (current_capacity < expect_capacity) { - int64_t old_fat_size = fat_.count(); - int64_t cur_expand_capacity = 0; - char * new_expand_buf = nullptr; - // allocate a chunk of WBP_BLOCK_SIZE each time - if (OB_ISNULL(new_expand_buf = static_cast(allocator_.alloc(WBP_BLOCK_SIZE)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else { - uint32_t new_page_id = fat_.count(); - for (uint32_t count = 0; OB_SUCC(ret) && count < BLOCK_PAGE_NUMS; ++new_page_id, ++count) { - if (OB_FAIL(fat_.push_back(ObPageEntry(ObTmpFileGlobal::INVALID_TMP_FILE_FD, - ObTmpFileGlobal::INVALID_PAGE_ID, - new_expand_buf + count * ObTmpFileGlobal::ALLOC_PAGE_SIZE)))) { - } else { - if (count > 0) { - fat_[new_page_id].next_page_id_ = new_page_id - 1; - } else { - fat_[new_page_id].next_page_id_ = first_free_page_id_; - fat_[new_page_id].is_block_beginning_ = true; - } - cur_expand_capacity += ObTmpFileGlobal::ALLOC_PAGE_SIZE; - } - } - current_capacity += WBP_BLOCK_SIZE; - } - - if (OB_SUCC(ret)) { - int64_t new_free_page_id = fat_.count() - 1; - ATOMIC_SET(&first_free_page_id_, new_free_page_id); // first_free_page_id_ points to the last page of this new block - ATOMIC_FAA(&capacity_, cur_expand_capacity); - } else { - while (fat_.count() > old_fat_size) { - fat_.pop_back(); - } - if (OB_NOT_NULL(new_expand_buf)) { - allocator_.free(new_expand_buf); - } - } - } else { - // maybe another thread has finish allocation, do nothing. - } - } - - LOG_INFO("wbp expand", KR(ret), K(expect_capacity), K(memory_limit), K(ATOMIC_LOAD(&capacity_))); - - return ret; -} - -int ObTmpWriteBufferPool::release_all_blocks_() -{ - int ret = OB_SUCCESS; - common::TCRWLock::WLockGuard guard(lock_); - for (int64_t i = 0; i < fat_.count(); i += BLOCK_PAGE_NUMS) { - char * buf = fat_[i].buf_; - if (OB_ISNULL(buf)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp get unexpected page buffer", KR(ret), K(i), KP(buf)); - } else if (!fat_[i].is_block_beginning_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp try to free a ptr which is not the address of a block", KR(ret), K(i), KP(buf), K(fat_[i])); - } else { - allocator_.free(buf); - } - } - return ret; -} - -int ObTmpWriteBufferPool::cal_target_shrink_range_(const bool is_auto, int64_t &lower_page_id, int64_t &upper_page_id) -{ - int ret = OB_SUCCESS; - int64_t capacity = ATOMIC_LOAD(&capacity_); - int64_t memory_limit = get_memory_limit(); - int64_t exceed_page_num = - ((capacity - memory_limit) / ObTmpFileGlobal::ALLOC_PAGE_SIZE + BLOCK_PAGE_NUMS - 1) / BLOCK_PAGE_NUMS * BLOCK_PAGE_NUMS; // upper_align - const int64_t max_used_page_watermark = ATOMIC_LOAD(&max_used_watermark_after_shrinking_); - exceed_page_num = max(0, exceed_page_num); - - if (is_auto) { // calculate target page id according to watermark when auto shrinking - int64_t target_page_id = 0; - if (max_used_page_watermark == AUTO_SHRINKING_WATERMARK_L3) { - target_page_id = fat_.count() * AUTO_SHRINKING_TARGET_SIZE_L3 / 100; - } else if (max_used_page_watermark <= AUTO_SHRINKING_WATERMARK_L2) { - target_page_id = fat_.count() * AUTO_SHRINKING_TARGET_SIZE_L2 / 100; - } else if (max_used_page_watermark <= AUTO_SHRINKING_WATERMARK_L1) { - target_page_id = fat_.count() * AUTO_SHRINKING_TARGET_SIZE_L1 / 100; - } else { - ret = OB_OP_NOT_ALLOW; - LOG_INFO("used page number watermark increases, stop shrinking", KR(ret), K(max_used_page_watermark)); - } - lower_page_id = (target_page_id + BLOCK_PAGE_NUMS - 1) / BLOCK_PAGE_NUMS * BLOCK_PAGE_NUMS; - } else { - lower_page_id = fat_.count() - exceed_page_num; - } - lower_page_id = max(lower_page_id, BLOCK_PAGE_NUMS); // reserve at least one block - upper_page_id = max(fat_.count() - 1, BLOCK_PAGE_NUMS); - - LOG_DEBUG("get target shrinking range", K(is_auto), K(capacity), K(memory_limit), - K(max_used_page_watermark), K(fat_.size()), - K(exceed_page_num), K(lower_page_id), K(upper_page_id)); - return ret; -} - -int ObTmpWriteBufferPool::init_shrink_context(const bool is_auto) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - ObSpinLockGuard list_guard(free_list_lock_); // exclusive with alloc_page && free_page - int64_t lower_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - int64_t upper_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t max_allow_alloc_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - - if (OB_FAIL(cal_target_shrink_range_(is_auto, lower_page_id, upper_page_id))) { - } else { - max_allow_alloc_page_id = cal_max_allow_alloc_page_id_(lower_page_id, upper_page_id); - if (OB_UNLIKELY(!is_valid_page_id_(lower_page_id) || !is_valid_page_id_(upper_page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(upper_page_id <= BLOCK_PAGE_NUMS)) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(shrink_ctx_.init(lower_page_id, max_allow_alloc_page_id, - upper_page_id, is_auto))) { - } else { - LOG_INFO("init shrinking context", KR(ret), K(shrink_ctx_)); - } - } - - return ret; -} - -bool ObTmpWriteBufferPool::need_to_shrink(bool &is_auto) -{ - bool b_ret = false; - int64_t current_capacity = ATOMIC_LOAD(&capacity_); - int64_t memory_limit = get_memory_limit(); - int64_t max_used_page_watermark = ATOMIC_LOAD(&max_used_watermark_after_shrinking_); - is_auto = false; - - if (current_capacity > memory_limit) { - b_ret = true; - } else if (current_capacity <= memory_limit) { - if (shrink_ctx_.is_valid()) { - if (shrink_ctx_.is_auto()) { - // if used_page_num exceeds threshold during auto-shrinking, stop shrinking - b_ret = AUTO_SHRINKING_WATERMARK_L1 / 2 >= max_used_page_watermark; - } else { - // manual-shrinking would stop if memory_limit increase during shrinking - b_ret = false; - } - } else if (ObTimeUtility::current_time() - last_shrink_complete_ts_ >= SHRINKING_PERIOD) { - if (AUTO_SHRINKING_WATERMARK_L1 >= max_used_page_watermark && - current_capacity > WBP_BLOCK_SIZE) { - is_auto = true; - b_ret = true; // invoke auto-shrinking(no less than WBP_BLOCK_SIZE) - LOG_INFO("invoke auto shrinking due to low watermark", K(max_used_page_watermark)); - } else { - // re-count max watermark for the next period - b_ret = false; - ATOMIC_STORE(&max_used_watermark_after_shrinking_, 0); - ATOMIC_STORE(&last_shrink_complete_ts_, ObTimeUtility::current_time()); - } - } - } - - if (shrink_ctx_.is_execution_too_long()) { - b_ret = false; - LOG_INFO("auto-shrinking takes too much time, stop it", K(shrink_ctx_)); - } - - return b_ret; -} - -WBPShrinkContext::WBPShrinkContext() - : is_inited_(false), - is_auto_(false), - shrink_begin_ts_(0), - max_allow_alloc_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - lower_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - upper_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - shrink_list_head_(ObTmpFileGlobal::INVALID_PAGE_ID), - shrink_list_size_(0), - wbp_shrink_state_(WBP_SHRINK_STATE::INVALID) -{} - -int WBPShrinkContext::init(const uint32_t lower_page_id, - const uint32_t max_allow_alloc_page_id, - const uint32_t upper_page_id, - const bool is_auto) -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_UNLIKELY(lower_page_id < 0 || lower_page_id >= upper_page_id || - lower_page_id % ObTmpWriteBufferPool::BLOCK_PAGE_NUMS != 0 || - (upper_page_id + 1) % ObTmpWriteBufferPool::BLOCK_PAGE_NUMS != 0)) { - ret = OB_INVALID_ARGUMENT; - } else { - is_auto_ = is_auto; - shrink_begin_ts_ = ObTimeUtility::current_time(); - lower_page_id_ = lower_page_id; - upper_page_id_ = upper_page_id; - max_allow_alloc_page_id_ = max_allow_alloc_page_id; - shrink_list_head_ = ObTmpFileGlobal::INVALID_PAGE_ID; - shrink_list_size_ = 0; - is_inited_ = true; - } - return ret; -} - -void WBPShrinkContext::reset() -{ - is_inited_ = false; - is_auto_ = false; - shrink_begin_ts_ = 0; - max_allow_alloc_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - lower_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - upper_page_id_ = ObTmpFileGlobal::INVALID_PAGE_ID; - shrink_list_head_ = ObTmpFileGlobal::INVALID_PAGE_ID; - shrink_list_size_ = 0; - wbp_shrink_state_ = WBP_SHRINK_STATE::INVALID; -} - -bool WBPShrinkContext::is_valid() -{ - return is_inited_ && - lower_page_id_ < upper_page_id_ && - max_allow_alloc_page_id_ + 1 >= lower_page_id_ && - WBP_SHRINK_STATE::INVALID != wbp_shrink_state_ && - (upper_page_id_ - lower_page_id_ + 1) % ObTmpWriteBufferPool::BLOCK_PAGE_NUMS == 0; -} - -bool WBPShrinkContext::in_not_alloc_range(uint32_t page_id) -{ - return is_inited_ && - page_id > ATOMIC_LOAD(&max_allow_alloc_page_id_) && - page_id <= upper_page_id_; -} - -bool WBPShrinkContext::in_shrinking_range(uint32_t page_id) -{ - return is_inited_ && - lower_page_id_ <= page_id && - page_id <= upper_page_id_; -} - -int64_t WBPShrinkContext::get_not_alloc_page_num() -{ - int64_t not_alloc_page_num = is_valid() ? upper_page_id_ - max_allow_alloc_page_id_ : 0; - return max(0, not_alloc_page_num); -} - -int ObTmpWriteBufferPool::begin_shrinking(const bool is_auto) -{ - int ret = OB_SUCCESS; - switch (shrink_ctx_.wbp_shrink_state_) { - case WBPShrinkContext::INVALID: - if (OB_FAIL(init_shrink_context(is_auto))) { - } else { - LOG_INFO("wbp begin_shrinking", K(shrink_ctx_)); - } - break; - default: - ret = OB_ERR_UNEXPECTED; - break; - } - return ret; -} - -int ObTmpWriteBufferPool::finish_shrinking() -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - ObSpinLockGuard list_guard(free_list_lock_); // holds lock to update free_page_list and shrink_ctx_ - if (!shrink_ctx_.is_valid()) { - ret = OB_ERR_UNEXPECTED; - } else if (WBPShrinkContext::SHRINKING_FINISH > shrink_ctx_.wbp_shrink_state_) { - LOG_INFO("wbp shrink abort", K(shrink_ctx_)); - // shrink abort, concat shrink list to free list if needed - if (ObTmpFileGlobal::INVALID_PAGE_ID != shrink_ctx_.shrink_list_head_) { - int64_t free_cnt = 0; - uint32_t prev_page_id = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t cur_page_id = shrink_ctx_.shrink_list_head_; - while (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID != cur_page_id) { - if (!is_valid_page_id_(cur_page_id)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("shrink list page is invalid in abort shrinking", - K(ret), K(cur_page_id), K(fat_.size()), K(shrink_ctx_)); - } else { - prev_page_id = cur_page_id; - cur_page_id = fat_[cur_page_id].next_page_id_; - free_cnt += 1; - } - } - - if (OB_FAIL(ret)) { - } else if (free_cnt != shrink_ctx_.shrink_list_size_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("free page number in shrink_page list is not equal to shrink_list_size", - K(ret), K(free_cnt), K(shrink_ctx_)); - } else { - fat_[prev_page_id].next_page_id_ = first_free_page_id_; - first_free_page_id_ = shrink_ctx_.shrink_list_head_; - } - } - // clean shrink_ctx_ regardless error to finish shrinking forcibly - shrink_ctx_.reset(); - } else { - // normal finish - int32_t max_page_num = get_max_page_num(); - int32_t cur_size_num = fat_.size(); - LOG_INFO("wbp shrink finish gracefully", K(max_page_num), K(cur_size_num), K(shrink_ctx_)); - shrink_ctx_.reset(); - } - - last_shrink_complete_ts_ = ObTimeUtility::current_time(); - ATOMIC_STORE(&max_used_watermark_after_shrinking_, 0); - return ret; -} - -int ObTmpWriteBufferPool::remove_invalid_page_in_free_list_() -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); // protect fat_ - ObSpinLockGuard list_guard(free_list_lock_); // protect free page list - uint32_t prev = ObTmpFileGlobal::INVALID_PAGE_ID; - uint32_t curr = ATOMIC_LOAD(&first_free_page_id_); - if (!shrink_ctx_.is_valid()) { - ret = OB_ERR_UNEXPECTED; - } - while (OB_SUCC(ret) && ObTmpFileGlobal::INVALID_PAGE_ID != curr) { - if (OB_UNLIKELY(!is_valid_page_id_(curr))) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected page id in free page list", K(ret), K(curr), K(fat_.size())); - } else if (OB_UNLIKELY(shrink_ctx_.is_higher_than_shrink_end_point(curr))) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected free page id higher than end point", K(ret), K(curr), K(shrink_ctx_)); - } else if (shrink_ctx_.in_shrinking_range(curr)) { - if (ObTmpFileGlobal::INVALID_PAGE_ID != prev) { - fat_[prev].next_page_id_ = fat_[curr].next_page_id_; - } else { - // curr is the first page in free page list to be removed, - // update first_free_page_id_ to the next page. - first_free_page_id_ = fat_[curr].next_page_id_; - } - curr = fat_[curr].next_page_id_; - } else { - prev = curr; - curr = fat_[curr].next_page_id_; - } - } - - LOG_DEBUG("remove_invalid_page_in_free_list_ complete", KR(ret), K(capacity_), K(fat_.size())); - return ret; -} - -int ObTmpWriteBufferPool::release_blocks_in_shrink_range() -{ - int ret = OB_SUCCESS; - if (!shrink_ctx_.is_valid()) { - ret = OB_ERR_UNEXPECTED; - } else if (OB_FAIL(remove_invalid_page_in_free_list_())) { - } else { - common::TCRWLock::WLockGuard guard(lock_); - - if (fat_.size() != shrink_ctx_.upper_page_id_ + 1) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("fat_ size is not equal to the size in shrink_ctx", K(ret), K(shrink_ctx_), K(fat_.size())); - } - for (uint32_t i = shrink_ctx_.lower_page_id_; OB_SUCC(ret) && i <= shrink_ctx_.upper_page_id_; ++i) { - if (!is_valid_page_id_(i)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid page id in shrink range", K(ret), K(i), K(shrink_ctx_), K(fat_.size())); - } else if (ObPageEntry::State::INVALID != fat_[i].state_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("page entry is not INVALID when releasing block", - KR(ret), K(i), K(fat_[i]), K(shrink_ctx_)); - } - } - for (uint32_t i = shrink_ctx_.upper_page_id_ - BLOCK_PAGE_NUMS + 1; - OB_SUCC(ret) && i >= shrink_ctx_.lower_page_id_; i -= BLOCK_PAGE_NUMS) { - if (!fat_[i].is_block_beginning_) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("page is not block beginning", K(ret), K(i), K(fat_[i])); - } else if (OB_ISNULL(fat_[i].buf_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("page buf_ is nullptr", K(ret), K(i), K(fat_[i])); - } else { - LOG_DEBUG("free block at ", K(i), K(capacity_), K(fat_.size())); - allocator_.free(fat_[i].buf_); - for (int64_t j = 0; j < BLOCK_PAGE_NUMS; ++j) { - fat_.pop_back(); - } - ATOMIC_AAF(&capacity_, -WBP_BLOCK_SIZE); - } - } - } - return ret; -} - -int ObTmpWriteBufferPool::advance_shrink_state() -{ - int ret = OB_SUCCESS; - switch (shrink_ctx_.wbp_shrink_state_) { - case WBPShrinkContext::INVALID: - shrink_ctx_.wbp_shrink_state_ = WBPShrinkContext::SHRINKING_SWAP; - break; - case WBPShrinkContext::SHRINKING_SWAP: - // Reduce max_allow_alloc_page_id_ until it falls below lower_page_id_, - // ensuring that no newly allocated pages exist within the range of [lower_page_id_, upper_page_id_]. - // After all pages in this range have been freed, we can release the fat_ blocks. - if (is_shrink_range_all_free_()) { - shrink_ctx_.wbp_shrink_state_ = WBPShrinkContext::SHRINKING_RELEASE_BLOCKS; - } - break; - case WBPShrinkContext::SHRINKING_RELEASE_BLOCKS: - if (fat_.count() == shrink_ctx_.lower_page_id_ || fat_.count() == 0) { - LOG_INFO("wbp shrink release blocks complete", K(shrink_ctx_)); - shrink_ctx_.wbp_shrink_state_ = WBPShrinkContext::SHRINKING_FINISH; - } else { - LOG_WARN("wbp shrink not finish, could not advance shrinking state", K(fat_.count()), K(shrink_ctx_)); - } - case WBPShrinkContext::SHRINKING_FINISH: - // do nothing - break; - default: - ret = OB_ERR_UNEXPECTED; - break; - } - return ret; -} - -bool ObTmpWriteBufferPool::is_shrink_range_all_free_() -{ - int ret = OB_SUCCESS; - bool is_all_free = false; - - common::TCRWLock::WLockGuard guard(lock_); - uint32_t cur_max_allow_alloc_page_id = - cal_max_allow_alloc_page_id_(shrink_ctx_.lower_page_id_, shrink_ctx_.upper_page_id_); - shrink_ctx_.max_allow_alloc_page_id_ = - min(cur_max_allow_alloc_page_id, shrink_ctx_.max_allow_alloc_page_id_); - - // only after max_allow_alloc_page_id_ falls below lower_page_id_, - // we can ensure that no newly allocated pages exist within the range of [lower_page_id_, upper_page_id_] - if (shrink_ctx_.max_allow_alloc_page_id_ < shrink_ctx_.lower_page_id_) { - is_all_free = true; - for (uint32_t i = shrink_ctx_.lower_page_id_; i <= shrink_ctx_.upper_page_id_; ++i) { - if (!is_valid_page_id_(i)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid page id in shrink range", K(ret), K(i), K(shrink_ctx_), K(fat_.size())); - } else if (ObPageEntry::State::INVALID != fat_[i].state_) { - is_all_free = false; - LOG_DEBUG("wbp shrink range is not all free", K(i), K(fat_[i]), K(shrink_ctx_)); - break; - } - } - if (is_all_free) { - LOG_INFO("wbp shrinking range is free, start to release blocks mem", - K(fat_.size()), K(shrink_ctx_)); - } - } - return is_all_free; -} - -// insert page_id to free_page_list_ or shrink_page_list_ -// ATTENTION! it is not thread-safe, must be called within critical section -void ObTmpWriteBufferPool::insert_page_entry_to_free_list_(const uint32_t page_id, uint32_t &list_head) -{ - bool cas_succeed = false; - do { - uint32_t old_list_head = ATOMIC_LOAD(&list_head); - ATOMIC_SET(&(fat_[page_id].next_page_id_), old_list_head); - cas_succeed = ATOMIC_BCAS(&list_head, old_list_head, page_id); - } while (false == cas_succeed); -} - -int64_t ObTmpWriteBufferPool::get_not_allow_alloc_percent_(const int64_t target_wbp_size) -{ - int64_t cur_wbp_size = fat_.size(); - const uint32_t ADDITIONAL_FREE_PAGE_PERCENT = 15; // reserve 10% free pages for meta pages and 5% more for data pages - int64_t cannot_evict_num = get_cannot_be_evicted_page_num(); - int64_t cannot_evict_percent = cannot_evict_num * 100 / cur_wbp_size; - int64_t not_allow_alloc_percent = max(0, 100 - cannot_evict_percent - ADDITIONAL_FREE_PAGE_PERCENT); - - // if cannot_evict_page_num < target_wbp_size, then we reserve 10% pages of target_wbp_size instead of cur_wbp_size, - // and expand no_allow_alloc range to cover [lower_page_id, upper_page_id] directly; - // otherwise we will have to wait for all pages are evicted when target_wbp_size is small(e.g. 5% of current size), - // it might be quite slow when there are writing operations - if (cannot_evict_num <= target_wbp_size * MAX_DATA_PAGE_USAGE_RATIO) { - not_allow_alloc_percent = 100; - } - return not_allow_alloc_percent; -} - -uint32_t ObTmpWriteBufferPool::cal_max_allow_alloc_page_id_(int64_t lower_bound, int64_t upper_bound) -{ - int64_t old_fat_size = fat_.size(); - int64_t not_allow_alloc_percent = get_not_allow_alloc_percent_(lower_bound + 1); - int64_t max_allow_alloc_page_id = - MAX3(0, lower_bound - 1 , upper_bound - old_fat_size * not_allow_alloc_percent / 100); - return max_allow_alloc_page_id; -} - -int64_t ObTmpWriteBufferPool::get_memory_limit() -{ - int64_t memory_limit = 0; - int64_t last_access_ts = ATOMIC_LOAD(&last_access_runtime_config_ts_); - int64_t default_wbp_memory_limit = ATOMIC_LOAD(&default_wbp_memory_limit_); - if (default_wbp_memory_limit > 0) { - memory_limit = (default_wbp_memory_limit + WBP_BLOCK_SIZE - 1) / WBP_BLOCK_SIZE * WBP_BLOCK_SIZE; // upper_align - } else if (last_access_ts > 0 && common::ObClockGenerator::getClock() - last_access_ts < 10000000) { // 10s - memory_limit = ATOMIC_LOAD(&wbp_memory_limit_); - } else { - if (0 == config::_temporary_file_io_area_size()) { - memory_limit = WBP_BLOCK_SIZE; - } else { - int64_t config_memory_budget = - lib::get_memory_budget() / 50 * config::_temporary_file_io_area_size(); - memory_limit = config_memory_budget; - } - memory_limit = ((memory_limit + WBP_BLOCK_SIZE - 1) / WBP_BLOCK_SIZE) * WBP_BLOCK_SIZE; - ATOMIC_STORE(&wbp_memory_limit_, memory_limit); - ATOMIC_STORE(&last_access_runtime_config_ts_, common::ObClockGenerator::getClock()); - } - return memory_limit; -} - -// expect swap min(10% * page cache memory, 20MB) each time -// if clean data size smaller than this min_swap_size return 0 -int64_t ObTmpWriteBufferPool::get_swap_size() -{ - const int64_t HIGH_WATERMARK_PERCENTAGE = 55; - const int64_t LOW_WATERMARK_PERCENTAGE = 30; - - int64_t memory_limit = get_memory_limit(); - int64_t used_page_num = ATOMIC_LOAD(&used_page_num_); - - int64_t high_watermark_bytes = (double)HIGH_WATERMARK_PERCENTAGE / 100 * memory_limit; - int64_t low_watermark_bytes = (double)LOW_WATERMARK_PERCENTAGE / 100 * memory_limit; - int64_t used_bytes = used_page_num * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - - const int64_t MACRO_BLOCK_SIZE = OB_STORAGE_OBJECT_MGR.get_macro_object_size(); - - int64_t swap_size = 0; - if (used_bytes > high_watermark_bytes) { - int64_t expected_swap_size = used_bytes - low_watermark_bytes; - int64_t dirty_data_bytes = ATOMIC_LOAD(&dirty_page_num_) * ObTmpFileGlobal::ALLOC_PAGE_SIZE; - swap_size = min(used_bytes - dirty_data_bytes, expected_swap_size); - } - - return swap_size; -} - -bool ObTmpWriteBufferPool::is_cached( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - common::TCRWLock::RLockGuard guard(lock_); - int ret = OB_SUCCESS; - bool cached = false; - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - LOG_ERROR("wbp use unexpected page id", KR(ret), K(fd), K(page_id), K(page_key), K(fat_.size())); - } else if ((OB_ISNULL(fat_[page_id].buf_) || fd != fat_[page_id].fd_ - || !page_key.is_valid() || page_key != fat_[page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp get unexpected page entry", KR(ret), K(fd), K(page_id), K(page_key), K(fat_[page_id])); - } else { - cached = ObPageEntry::State::CACHED == fat_[page_id].state_; - } - return cached; -} - -bool ObTmpWriteBufferPool::is_write_back(const int64_t fd, const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - common::TCRWLock::RLockGuard guard(lock_); - int ret = OB_SUCCESS; - bool write_back = false; - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - LOG_ERROR("wbp use unexpected page id", KR(ret), K(fd), K(page_id), K(page_key), K(fat_.size())); - } else if ((OB_ISNULL(fat_[page_id].buf_) || fd != fat_[page_id].fd_ - || !page_key.is_valid() || page_key != fat_[page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp get unexpected page entry", KR(ret), K(fd), K(page_id), K(page_key), K(fat_[page_id])); - } else { - write_back = ObPageEntry::State::WRITE_BACK == fat_[page_id].state_; - } - return write_back; -} - -bool ObTmpWriteBufferPool::is_dirty( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - common::TCRWLock::RLockGuard guard(lock_); - int ret = OB_SUCCESS; - bool dirty = false; - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - LOG_ERROR("wbp use unexpected page id", KR(ret), K(fd), K(page_id), K(page_key), K(fat_.size())); - } else if ((OB_ISNULL(fat_[page_id].buf_) || fd != fat_[page_id].fd_ - || !page_key.is_valid() || page_key != fat_[page_id].page_key_)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("wbp get unexpected page entry", KR(ret), K(fd), K(page_id), K(page_key), K(fat_[page_id])); - } else { - dirty = ObPageEntry::State::DIRTY == fat_[page_id].state_; - } - return dirty; -} - -// we allow the following states to transition to dirty: -// INVALID, INITED, CACHED, WRITE_BACK -int ObTmpWriteBufferPool::notify_dirty( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - bool is_already_dirty = false; - bool is_write_back = false; - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(INVALID_FD == fd - || fd != fat_[page_id].fd_ - || OB_ISNULL(fat_[page_id].buf_) - || !page_key.is_valid() - || page_key != fat_[page_id].page_key_)) { - ret = OB_INVALID_ARGUMENT; - ObPageEntry entry; - if (is_valid_page_id_(page_id)) { - entry = fat_[page_id]; - } - } else if (FALSE_IT(is_already_dirty = (ObPageEntry::State::DIRTY == fat_[page_id].state_))) { - } else if (FALSE_IT(is_write_back = (ObPageEntry::State::WRITE_BACK == fat_[page_id].state_))) { - } else if (OB_FAIL(fat_[page_id].switch_state(ObPageEntry::Ops::WRITE))) { - } else { - if (!is_already_dirty) { - ATOMIC_INC(&dirty_page_num_); - if (PageEntryType::DATA == page_key.type_) { - ATOMIC_INC(&dirty_data_page_cnt_); - } else if (PageEntryType::META == page_key.type_) { - ATOMIC_INC(&dirty_meta_page_cnt_); - } else { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid page type", K(page_key)); - } - } - if (is_write_back) { - if (PageEntryType::DATA == page_key.type_) { - ATOMIC_DEC(&write_back_data_cnt_); - } else if (PageEntryType::META == page_key.type_) { - ATOMIC_DEC(&write_back_meta_cnt_); - } else { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid page type", K(page_key)); - } - } - } - return ret; -} - -int ObTmpWriteBufferPool::notify_load( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(INVALID_FD == fd - || fd != fat_[page_id].fd_ - || OB_ISNULL(fat_[page_id].buf_) - || !page_key.is_valid() - || page_key != fat_[page_id].page_key_)) { - ret = OB_INVALID_ARGUMENT; - ObPageEntry entry; - if (is_valid_page_id_(page_id)) { - entry = fat_[page_id]; - } - } else if (OB_FAIL(fat_[page_id].switch_state(ObPageEntry::Ops::LOAD))) { - } - return ret; -} - -int ObTmpWriteBufferPool::notify_load_succ(const int64_t fd, const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(INVALID_FD == fd - || fd != fat_[page_id].fd_ - || OB_ISNULL(fat_[page_id].buf_) - || !page_key.is_valid() - || page_key != fat_[page_id].page_key_)) { - ret = OB_INVALID_ARGUMENT; - ObPageEntry entry; - if (is_valid_page_id_(page_id)) { - entry = fat_[page_id]; - } - } else if (OB_FAIL(fat_[page_id].switch_state(ObPageEntry::Ops::LOAD_SUCC))) { - } - return ret; -} - -int ObTmpWriteBufferPool::notify_load_fail( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - int ret = OB_SUCCESS; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(INVALID_FD == fd - || fd != fat_[page_id].fd_ - || OB_ISNULL(fat_[page_id].buf_) - || !page_key.is_valid() - || page_key != fat_[page_id].page_key_)) { - ret = OB_INVALID_ARGUMENT; - ObPageEntry entry; - if (is_valid_page_id_(page_id)) { - entry = fat_[page_id]; - } - } else if (OB_FAIL(fat_[page_id].switch_state(ObPageEntry::Ops::LOAD_FAIL))) { - } - return ret; -} - -int ObTmpWriteBufferPool::notify_write_back( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - int ret = OB_SUCCESS; - bool is_dirty = false; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(INVALID_FD == fd - || fd != fat_[page_id].fd_ - || OB_ISNULL(fat_[page_id].buf_) - || !page_key.is_valid() - || page_key != fat_[page_id].page_key_)) { - ret = OB_INVALID_ARGUMENT; - ObPageEntry entry; - if (is_valid_page_id_(page_id)) { - entry = fat_[page_id]; - } - } else if (FALSE_IT(is_dirty = (ObPageEntry::State::DIRTY == fat_[page_id].state_))) { - } else if (OB_FAIL(fat_[page_id].switch_state(ObPageEntry::Ops::WRITE_BACK))) { - } else if (is_dirty) { - ATOMIC_DEC(&dirty_page_num_); - if (PageEntryType::DATA == fat_[page_id].page_key_.type_) { - ATOMIC_DEC(&dirty_data_page_cnt_); - ATOMIC_INC(&write_back_data_cnt_); - LOG_DEBUG("notify data write back", K(fd), K(page_id), K(fat_[page_id])); - } else if (PageEntryType::META == fat_[page_id].page_key_.type_) { - ATOMIC_DEC(&dirty_meta_page_cnt_); - ATOMIC_INC(&write_back_meta_cnt_); - LOG_INFO("notify meta write back", K(fd), K(page_id), K(fat_[page_id])); - } - } - return ret; -} - -int ObTmpWriteBufferPool::notify_write_back_succ( - const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key) -{ - int ret = OB_SUCCESS; - bool is_write_back = false; - common::TCRWLock::RLockGuard guard(lock_); - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(INVALID_FD == fd - || fd != fat_[page_id].fd_ - || OB_ISNULL(fat_[page_id].buf_) - || !page_key.is_valid() - || page_key != fat_[page_id].page_key_)) { - ret = OB_INVALID_ARGUMENT; - ObPageEntry entry; - if (is_valid_page_id_(page_id)) { - entry = fat_[page_id]; - } - } else if (FALSE_IT(is_write_back = (ObPageEntry::State::WRITE_BACK == fat_[page_id].state_))) { - } else if (OB_FAIL(fat_[page_id].switch_state(ObPageEntry::Ops::WRITE_BACK_SUCC))) { - } else if (is_write_back) { - if (PageEntryType::DATA == fat_[page_id].page_key_.type_) { - ATOMIC_DEC(&write_back_data_cnt_); - LOG_DEBUG("notify data write back succ", K(fd), K(page_id), K(fat_[page_id])); - } else if (PageEntryType::META == fat_[page_id].page_key_.type_) { - ATOMIC_DEC(&write_back_meta_cnt_); - LOG_INFO("notify meta write back succ", K(fd), K(page_id), K(fat_[page_id])); - } - } - return ret; -} - -// Return the maximum page count derived from runtime memory and configuration. -int64_t ObTmpWriteBufferPool::get_max_page_num() -{ - int64_t mem_limit = get_memory_limit(); - return mem_limit / ObTmpFileGlobal::ALLOC_PAGE_SIZE; -} - -// return dirty page percentage -int64_t ObTmpWriteBufferPool::get_dirty_page_percentage() -{ - int64_t max_page_num = get_max_page_num(); - int64_t dirty_page_num = ATOMIC_LOAD(&dirty_page_num_); - return max_page_num == 0 ? 0 : dirty_page_num * 100 / max_page_num; -} - -int64_t ObTmpWriteBufferPool::get_cannot_be_evicted_page_num() -{ - int64_t dirty_page_num = ATOMIC_LOAD(&dirty_page_num_); - int64_t write_back_data_num = ATOMIC_LOAD(&write_back_data_cnt_); - int64_t write_back_meta_num = ATOMIC_LOAD(&write_back_meta_cnt_); - int64_t total_write_back_num = write_back_data_num + write_back_meta_num; - return dirty_page_num + total_write_back_num; -} - -int64_t ObTmpWriteBufferPool::get_cannot_be_evicted_page_percentage() -{ - int64_t max_page_num = get_max_page_num(); - int64_t cannot_evict_page_num = get_cannot_be_evicted_page_num(); - return max_page_num == 0 ? 0 : cannot_evict_page_num * 100 / max_page_num; -} - -int64_t ObTmpWriteBufferPool::get_dirty_page_num() -{ - return ATOMIC_LOAD(&dirty_page_num_); -} - -int64_t ObTmpWriteBufferPool::get_dirty_meta_page_num() -{ - return ATOMIC_LOAD(&dirty_meta_page_cnt_); -} - -int64_t ObTmpWriteBufferPool::get_dirty_data_page_num() -{ - return ATOMIC_LOAD(&dirty_data_page_cnt_); -} - -int64_t ObTmpWriteBufferPool::get_data_page_num() -{ - return ATOMIC_LOAD(&data_page_cnt_); -} - -int64_t ObTmpWriteBufferPool::get_max_data_page_num() -{ - return get_max_page_num() * MAX_DATA_PAGE_USAGE_RATIO; -} - -int64_t ObTmpWriteBufferPool::get_meta_page_num() -{ - return ATOMIC_LOAD(&meta_page_cnt_); -} - -int64_t ObTmpWriteBufferPool::get_free_data_page_num() -{ - int64_t data_page_cnt = ATOMIC_LOAD(&data_page_cnt_); - int64_t meta_page_cnt = ATOMIC_LOAD(&meta_page_cnt_); - int64_t max_page_num = get_max_page_num(); - int64_t free_data_page_num = 0; - - int64_t total_free_page_cnt = max_page_num - data_page_cnt - meta_page_cnt; - int64_t data_free_page_cnt = get_max_data_page_num() - data_page_cnt; - free_data_page_num = MIN(total_free_page_cnt, data_free_page_cnt); - return free_data_page_num; -} - -// ATTENTION! need to be protected by free_list_lock_ and lock_ -// because we may access fat_ and shrink_ctx_ here -bool ObTmpWriteBufferPool::has_free_page_(PageEntryType type) -{ - int ret = OB_SUCCESS; - bool b_ret = true; - if (PageEntryType::DATA == type) { - if (shrink_ctx_.is_valid()) { - b_ret = get_data_page_num() < fat_.size() * MAX_DATA_PAGE_USAGE_RATIO - shrink_ctx_.get_not_alloc_page_num(); - } else { - if (fat_.size() >= get_max_page_num()) { - // shrinking may not be invoked immediately when memory limit changes, - // use current fat_ size to prevent no data pages can be allocated - b_ret = get_data_page_num() < fat_.size() * MAX_DATA_PAGE_USAGE_RATIO; - } else { - b_ret = get_data_page_num() < get_max_data_page_num(); - } - } - } else if (PageEntryType::META == type) { - b_ret = true; // no limit for meta page - } else { - ret = OB_ERR_UNEXPECTED; - } - return b_ret; -} - -void ObTmpWriteBufferPool::print_page_entry(const uint32_t page_id) -{ - common::TCRWLock::RLockGuard guard(lock_); - int ret = OB_SUCCESS; - if (OB_UNLIKELY(!is_valid_page_id_(page_id))) { - ret = OB_INVALID_ARGUMENT; - LOG_ERROR("wbp use unexpected page id", KR(ret), K(page_id), K(fat_.size())); - } else { - LOG_INFO("page entry info", K(page_id), K(fat_[page_id])); - } -} - -void ObTmpWriteBufferPool::print_statistics() -{ - int64_t dirty_page_percentage = get_dirty_page_percentage(); - int64_t max_page_num = get_max_page_num(); - int64_t meta_page_num = get_meta_page_num(); - int64_t data_page_num = get_data_page_num(); - int64_t dirty_page_num = get_dirty_page_num(); - int64_t dirty_meta_page_num = get_dirty_meta_page_num(); - int64_t dirty_data_page_num = get_dirty_data_page_num(); - int64_t write_back_data_num = ATOMIC_LOAD(&write_back_data_cnt_); - int64_t write_back_meta_num = ATOMIC_LOAD(&write_back_meta_cnt_); - int64_t data_page_watermark = data_page_num * 100 / max(max_page_num, 1); - int64_t meta_page_watermark = meta_page_num * 100 / max(max_page_num, 1); - int64_t total_write_back_num = write_back_data_num + write_back_meta_num; - int64_t fat_actual_size = fat_.size(); - LOG_INFO("tmp file write buffer pool statistics", - K(dirty_page_percentage), K(max_page_num), K(fat_actual_size), - K(dirty_page_num), K(total_write_back_num), - K(meta_page_num), K(dirty_meta_page_num), K(write_back_meta_num), - K(data_page_num), K(dirty_data_page_num), K(write_back_data_num), - K(data_page_watermark), K(meta_page_watermark)); -} - -} // end namespace tmp_file -} // end namespace oceanbase diff --git a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool.h b/src/storage/tmp_file/ob_tmp_file_write_buffer_pool.h deleted file mode 100644 index 0b35162cb8..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool.h +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_WRITE_BUFFER_POOL_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_WRITE_BUFFER_POOL_H_ - -#include "lib/lock/ob_tc_rwlock.h" -#include "lib/container/ob_array.h" -#include "lib/allocator/ob_fifo_allocator.h" -#include "storage/tmp_file/ob_tmp_file_global.h" -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -struct WBPShrinkContext -{ -public: - static const int64_t MAX_SHRINKING_DURATION = 5 * 60 * 1000 * 1000; // 5min - enum WBP_SHRINK_STATE - { - INVALID = 0, - SHRINKING_SWAP, - SHRINKING_RELEASE_BLOCKS, - SHRINKING_FINISH - }; -public: - WBPShrinkContext(); - ~WBPShrinkContext() { reset(); } - int init(const uint32_t lower_page_id, - const uint32_t max_allow_alloc_page_id, - const uint32_t upper_page_id, - const bool is_auto); - void reset(); - bool is_valid(); - int64_t get_not_alloc_page_num(); - bool in_not_alloc_range(uint32_t page_id); - bool in_shrinking_range(uint32_t page_id); - bool is_higher_than_shrink_end_point(uint32_t page_id) - { - return is_inited_ && page_id > upper_page_id_; - } - bool is_execution_too_long() const - { - return is_inited_ && shrink_begin_ts_ > 0 && - ObTimeUtility::current_time() - shrink_begin_ts_ > MAX_SHRINKING_DURATION; - } - OB_INLINE bool is_auto() const { return is_auto_; } - TO_STRING_KV(K(is_inited_), K(is_auto_), - K(lower_page_id_), K(max_allow_alloc_page_id_), - K(upper_page_id_), K(wbp_shrink_state_), - K(shrink_list_head_), K(shrink_list_size_), K(shrink_begin_ts_)); -public: - bool is_inited_; - bool is_auto_; // indicates whether current shrinking process is auto or manual. - // auto shrinking may be aborted if watermark increases. - int64_t shrink_begin_ts_; - uint32_t max_allow_alloc_page_id_; // in the range between [lower_page_id_ - 1, upper_page_id_]. - // init as upper_page_id_ and will decrease towards lower_page_id_ - 1 - // when free page number increase. - // the pages in the range [max_allow_alloc_page_id_ + 1, upper_page_id_] - // are not allowed to be allocated during shrinking. - uint32_t lower_page_id_; - uint32_t upper_page_id_; - uint32_t shrink_list_head_; // tmp free_page_list when the new free page in the range [lower_page_id, upper_page_id] - // these pages will not be used by alloc_page() - int64_t shrink_list_size_; - WBP_SHRINK_STATE wbp_shrink_state_; -}; - -// preallocate a set of pages for the tmp file to write data. the pages are divided into data and meta types. -// data type pages can use up to 90% of the entire buffer pool space, while meta type pages have no upper limit. -// we build ObTmpWriteBufferPool upon this assumption: caller ensure only 1 writer operating a page entry at a time, -// and write operation must be exclusive with other r/w operations, therefore we have no need to limit the concurrency -// for every single page entry here. -class ObTmpWriteBufferPool final -{ -public: - // block size: 2MB - 24KB (header), use block size smaller than 2MB to avoid redundant AObject header - static const int64_t WBP_BLOCK_SIZE = 2 * 1024 * 1024 - 24 * 1024; - static const int64_t BLOCK_PAGE_NUMS = WBP_BLOCK_SIZE / ObTmpFileGlobal::ALLOC_PAGE_SIZE; // 253 pages per block (24KB for header) - static const int64_t INITIAL_POOL_SIZE = WBP_BLOCK_SIZE; - static const int64_t INITIAL_PAGE_NUMS = INITIAL_POOL_SIZE / ObTmpFileGlobal::ALLOC_PAGE_SIZE; - static const int64_t SHRINKING_PERIOD = 5 * 60 * 1000 * 1000; // 5min - static const int32_t AUTO_SHRINKING_WATERMARK_L1 = 10; - static const int32_t AUTO_SHRINKING_WATERMARK_L2 = 5; - static const int32_t AUTO_SHRINKING_WATERMARK_L3 = 0; - static const int32_t AUTO_SHRINKING_TARGET_SIZE_L1 = 50; // 50% - static const int32_t AUTO_SHRINKING_TARGET_SIZE_L2 = 20; // 20% - static const int32_t AUTO_SHRINKING_TARGET_SIZE_L3 = 10; // 10% -public: - ObTmpWriteBufferPool(); - ~ObTmpWriteBufferPool(); - int init(); - void destroy(); - -public: - // 1. according to the type_ of page_key, allocate a meta page or data page and set its state to INITED - // 2. return OB_ALLOCATE_TMP_FILE_PAGE_FAILED if data page number exceeds limits - // 3. always allow to alloc a meta page - int alloc_page(const int64_t fd, - const ObTmpFilePageUniqKey page_key, - uint32_t &new_page_id, - char *&buf); - - // read the content of a page and keep its original page state - int read_page(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key, - char *&buf, uint32_t &next_page_id); - - // set prev_page_id.next_page_id to point to 'page_id' without changing the page status - int link_page(const int64_t fd, const uint32_t page_id, const uint32_t prev_page_id, - const ObTmpFilePageUniqKey prev_page_key); - - // free given pages with INITED/CACHED/DIRTY state, - // return OB_STATE_NOT_MATCH if try to delete pages with other states - int free_page(const int64_t fd, const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, uint32_t &next_page_id); - - /** - * truncate a page from beginning to 'truncate_size' [0, truncate_size - 1], set data to 0; - * truncate_page will not change page state. if page is already flushed to disk, truncate_page - * only truncate data in buffer pool and will not mark page as dirty - */ - int truncate_page(const int64_t fd, const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - const int64_t truncate_size); -public: - /** - * given page_id, output next_page_id if existed; - * return OB_ITER_END for no more pages, others for error - */ - int get_next_page_id(const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - uint32_t &next_page_id); - - /** - * iter from the given page_id to end of the page list of a tmp file, - * to find a page which has a same virtual_page_id - * @param[in] virtual_page_id: the page we want to read(it equal to page_offset / page_size) - * @param[in] begin_page_id: the first cached page id of the tmp file - * @param[out] page_id: the target page - */ - int get_page_id_by_virtual_id(const int64_t fd, - const int64_t virtual_page_id, - const uint32_t begin_page_id, - uint32_t &page_id); - - /** - * get page_virtual_id of the given page_id, - * return OB_SEARCH_NOT_FOUND for page is INVALID, - */ - int get_page_virtual_id(const int64_t fd, const uint32_t page_id, int64_t &virtual_page_id); - -public: - int64_t get_swap_size(); - int64_t get_memory_limit(); - int64_t get_capacity() const { return ATOMIC_LOAD(&capacity_); } - bool is_cached(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - bool is_dirty(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - bool is_write_back(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int notify_dirty(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int notify_load(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int notify_load_succ(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int notify_load_fail(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int notify_write_back(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int notify_write_back_succ(const int64_t fd, const uint32_t page_id, const ObTmpFilePageUniqKey page_key); - int64_t get_max_page_num(); - OB_INLINE int64_t get_used_page_num() { return used_page_num_; } - int64_t get_data_page_num(); - int64_t get_dirty_page_num(); - int64_t get_write_back_page_num(); - int64_t get_dirty_meta_page_num(); - int64_t get_dirty_data_page_num(); - int64_t get_dirty_page_percentage(); - int64_t get_cannot_be_evicted_page_num(); - int64_t get_cannot_be_evicted_page_percentage(); - int64_t get_max_data_page_num(); - int64_t get_meta_page_num(); - int64_t get_free_data_page_num(); - void print_page_entry(const uint32_t page_id); - void print_statistics(); -public: - // for shrinking - bool need_to_shrink(bool &is_auto); - int init_shrink_context(const bool is_auto); - int begin_shrinking(const bool is_auto); - int finish_shrinking(); - int release_blocks_in_shrink_range(); - int advance_shrink_state(); - OB_INLINE WBPShrinkContext::WBP_SHRINK_STATE get_wbp_state() const { return shrink_ctx_.wbp_shrink_state_; } - OB_INLINE WBPShrinkContext &get_shrink_ctx() { return shrink_ctx_; } -private: - // for shrinking - int remove_invalid_page_in_free_list_(); - bool is_shrink_range_all_free_(); - void insert_page_entry_to_free_list_(const uint32_t page_id, uint32_t &free_list_head); - int64_t get_not_allow_alloc_percent_(const int64_t target_wbp_size); - uint32_t cal_max_allow_alloc_page_id_(int64_t lower_bound, int64_t upper_bound); - int cal_target_shrink_range_(const bool is_auto, int64_t &lower_page_id, int64_t &upper_page_id); -private: - static double MAX_DATA_PAGE_USAGE_RATIO; // control data pages ratio, can be preempted by meta pages - // only for unittest - OB_INLINE void set_max_data_page_usage_ratio_(const double ratio) - { - MAX_DATA_PAGE_USAGE_RATIO = ratio; - } - int read_page_(const int64_t fd, - const uint32_t page_id, - const ObTmpFilePageUniqKey page_key, - char *&buf, - uint32_t &next_page_id); - int alloc_page_(const int64_t fd, - const ObTmpFilePageUniqKey page_key, - uint32_t &new_page_id, - char *&buf); - int inner_alloc_page_(const int64_t fd, - const ObTmpFilePageUniqKey page_key, - uint32_t &new_page_id, - char *&buf); - // check if the specified PageEntryType has available space - bool has_free_page_(PageEntryType type); - OB_INLINE bool is_valid_page_id_(const uint32_t page_id) const - { - return page_id != ObTmpFileGlobal::INVALID_PAGE_ID && page_id >= 0 && - page_id < fat_.count(); - } - int expand_(); - int release_all_blocks_(); - DISALLOW_COPY_AND_ASSIGN(ObTmpWriteBufferPool); -private: - ObTmpWriteBufferPoolEntryArray fat_; // file allocation table - common::TCRWLock lock_; // holds w-lock when expanding and shrinking fat_, holds r-lock when reading fat_ - ObSpinLock free_list_lock_; // holds lock when updating free page list - common::ObFIFOAllocator allocator_; - bool is_inited_; - int64_t capacity_; // in bytes - int64_t dirty_page_num_; - int64_t used_page_num_; - uint32_t first_free_page_id_; // head of free page list - int64_t wbp_memory_limit_; // in bytes - int64_t default_wbp_memory_limit_; // if this var is valid, the wbp memory limit will always be it. - // currently, this var is only modified in ut. - int64_t last_access_runtime_config_ts_; - int64_t last_shrink_complete_ts_; - int64_t max_used_watermark_after_shrinking_; - int64_t meta_page_cnt_; - int64_t data_page_cnt_; - int64_t dirty_meta_page_cnt_; - int64_t dirty_data_page_cnt_; - int64_t write_back_data_cnt_; - int64_t write_back_meta_cnt_; - WBPShrinkContext shrink_ctx_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase - -#endif diff --git a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.cpp b/src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.cpp deleted file mode 100644 index f9cf5276d1..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define USING_LOG_PREFIX STORAGE - -#include "storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h" -#include "lib/oblog/ob_log_module.h" -#include "share/rc/ob_server_runtime.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -int ObPageEntry::switch_state(const int64_t op) -{ - int ret = OB_SUCCESS; - static const int64_t N = State::N; - static const int64_t INV = State::INVALID; - static const int64_t INITED = State::INITED; - static const int64_t LOADING = State::LOADING; - static const int64_t CACHED = State::CACHED; - static const int64_t DIRTY = State::DIRTY; - static const int64_t WRITE_BACK = State::WRITE_BACK; - static const int64_t MAX = State::MAX; - - static const int64_t STATE_MAP[State::MAX][Ops::MAX] = { - // ALLOC, LOAD, LOAD_FAIL, LOAD_SUCC, DELETE, WRITE, WRITE_BACK, WRITE_BACK_FAILED, WRITE_BACK_SUCC - {INITED, N, N, N, INV, N, N, N, N}, //INVALID - {N, LOADING, N, N, INV, DIRTY, N, N, N}, //INITED - {N, N, INITED, CACHED, N, N, N, N, N}, //LOADING - {N, N, N, N, INV, DIRTY, N, N, CACHED}, //CACHED - {N, N, N, N, INV, DIRTY, WRITE_BACK, N, N}, //DIRTY - {N, N, N, N, INV, DIRTY, WRITE_BACK, DIRTY, CACHED} //WRITE_BACK - }; - - if (OB_UNLIKELY(!Ops::is_valid(op))) { - ret = OB_INVALID_ARGUMENT; - LOG_ERROR("invalid operation", KR(ret), K(op)); - } else if (OB_UNLIKELY(!State::is_valid(state_))) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid state", KR(ret), K(state_)); - } else { - const int64_t n_stat = STATE_MAP[state_][op]; - if (OB_UNLIKELY(!State::is_valid(n_stat))) { - ret = OB_STATE_NOT_MATCH; - LOG_ERROR("invalid state transition", KR(ret), K(state_), K(op), K(n_stat)); - } else { - state_ = n_stat; - } - } - return ret; -} - -int ObTmpWriteBufferPoolEntryArray::init() -{ - int ret = OB_SUCCESS; - if (IS_INIT) { - ret = OB_INIT_TWICE; - } else if (OB_FAIL(allocator_.init(lib::ObMallocAllocator::get_instance(), - OB_MALLOC_MIDDLE_BLOCK_SIZE, - ObMemAttr("TmpFileEntArPt")))) { - } else { - extend_allocator_.set_attr(ObMemAttr("TmpFileEntBkt")); - buckets_.set_attr(ObMemAttr("TmpFileEntBktAr")); - size_ = 0; - is_inited_ = true; - } - return ret; -} - -void ObTmpWriteBufferPoolEntryArray::destroy() -{ - if (IS_INIT) { - for (int64_t i = 0; i < buckets_.size(); ++i) { - if (buckets_[i] != nullptr) { - buckets_[i]->reset(); - allocator_.free(buckets_[i]); - buckets_[i] = nullptr; - } - } - buckets_.reset(); - size_ = 0; - is_inited_ = false; - } -} - -int ObTmpWriteBufferPoolEntryArray::add_new_bucket_() -{ - int ret = OB_SUCCESS; - void *buf = nullptr; - ObArray *bucket = nullptr; - if (OB_ISNULL(buf = allocator_.alloc(sizeof(ObArray)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (FALSE_IT(bucket = new (buf) ObArray())) { - } else if (OB_FAIL(buckets_.push_back(bucket))) { - } else { - int64_t bucket_idx = buckets_.size() - 1; - buckets_[bucket_idx]->set_block_allocator(extend_allocator_); - - if (OB_FAIL(buckets_[bucket_idx]->reserve(MAX_BUCKET_CAPACITY))) { - } - } - return ret; -} - -int ObTmpWriteBufferPoolEntryArray::push_back(const ObPageEntry &entry) -{ - int ret = OB_SUCCESS; - int64_t bucket_idx = size_ / MAX_BUCKET_CAPACITY; - - if (IS_NOT_INIT) { - ret = OB_NOT_INIT; - } else { - if (bucket_idx >= buckets_.size()) { - if (OB_FAIL(add_new_bucket_())) { - } - } - - if (OB_FAIL(ret)) { - } else if (OB_UNLIKELY(bucket_idx >= buckets_.size() || bucket_idx < 0)) { - ret = OB_ERR_UNEXPECTED; - LOG_ERROR("invalid bucket index", KR(ret), K(bucket_idx), K(buckets_.size()), K(size_)); - } else if (OB_FAIL(buckets_[bucket_idx]->push_back(entry))) { - } - } - - if (OB_SUCC(ret)) { - size_ += 1; - } - return ret; -} - -void ObTmpWriteBufferPoolEntryArray::pop_back() -{ - if (size_ > 0) { - const int64_t bucket_idx = buckets_.size() - 1; - buckets_[bucket_idx]->pop_back(); - size_ -= 1; - - if (buckets_[bucket_idx]->size() == 0) { - buckets_[bucket_idx]->reset(); - allocator_.free(buckets_[bucket_idx]); - buckets_[bucket_idx] = nullptr; - buckets_.pop_back(); - LOG_DEBUG("pop back a bucket", K(buckets_.size()), K(size_)); - } - } -} - -} // end namespace tmp_file -} // end namespace oceanbase - diff --git a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h b/src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h deleted file mode 100644 index 0cd1e24d2f..0000000000 --- a/src/storage/tmp_file/ob_tmp_file_write_buffer_pool_entry_array.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2025 OceanBase. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OCEANBASE_STORAGE_TMP_FILE_OB_TMP_WRITE_BUFFER_POOL_ENTRY_ARRAY_H_ -#define OCEANBASE_STORAGE_TMP_FILE_OB_TMP_WRITE_BUFFER_POOL_ENTRY_ARRAY_H_ - -#include "lib/container/ob_array.h" -#include "lib/allocator/ob_fifo_allocator.h" -#include "storage/tmp_file/ob_tmp_file_global.h" - -namespace oceanbase -{ -namespace tmp_file -{ - -class ObTmpWriteBufferPool; -enum class PageEntryType -{ - INVALID = -1, - DATA = 0, - META = 1 -}; - -struct ObTmpFilePageUniqKey -{ -public: - ObTmpFilePageUniqKey() : type_(PageEntryType::INVALID), virtual_page_id_(ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID) {} - explicit ObTmpFilePageUniqKey(const int64_t virtual_page_id) : - type_(PageEntryType::DATA), virtual_page_id_(virtual_page_id) {} - explicit ObTmpFilePageUniqKey(const int64_t tree_level, const int64_t level_page_index) : - type_(PageEntryType::META), tree_level_(tree_level), - level_page_index_ (level_page_index) {} - - void reset() - { - virtual_page_id_ = ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID; - type_ = PageEntryType::INVALID; - } - - OB_INLINE bool is_valid() const - { - return type_ != PageEntryType::INVALID && - type_ == PageEntryType::META ? - 0 <= tree_level_ && 0 <= level_page_index_ : - ObTmpFileGlobal::INVALID_VIRTUAL_PAGE_ID != virtual_page_id_; - } - bool operator==(const ObTmpFilePageUniqKey other) const - { - return type_ == other.type_ && virtual_page_id_ == other.virtual_page_id_; - } - bool operator!=(const ObTmpFilePageUniqKey other) const - { - return type_ != other.type_ || virtual_page_id_ != other.virtual_page_id_; - } - -public: - PageEntryType type_; - union { - int64_t virtual_page_id_; // page_offset / page_size - struct { //The specific value for the tree pages - int64_t tree_level_:16; - int64_t level_page_index_:48; - }; - }; - TO_STRING_KV(K(type_), K(virtual_page_id_), K(tree_level_), K(level_page_index_)); -}; - -struct ObPageEntry final -{ - friend class ObTmpWriteBufferPool; -public: - ObPageEntry() - : buf_(nullptr), - fd_(-1), - state_(State::INVALID), - next_page_id_(ObTmpFileGlobal::INVALID_PAGE_ID), - page_key_() {} - ObPageEntry(const int64_t fd, const uint32_t next_page_id, char *buf) - : buf_(buf), - fd_(fd), - state_(State::INVALID), - next_page_id_(next_page_id), - page_key_() {} - - int switch_state(const int64_t op); - - TO_STRING_KV(K(fd_), K(page_key_), K(next_page_id_), K(state_), KP(buf_)); -public: - struct State - { - public: - static const int32_t N = -1; // illegal state - static const int32_t INVALID = 0; // page entry is INVALID after page is freed or before allocating - static const int32_t INITED = 1; // page entry is INITED after allocating - static const int32_t LOADING = 2; // page entry is LOADING after sending async io to read page from disk - static const int32_t CACHED = 3; // page entry is CACHED when page is clean - static const int32_t DIRTY = 4; // page entry is DIRTY after page is written - static const int32_t WRITE_BACK = 5; // page entry is WRITE_BACK when sending async io to write page to disk - static const int32_t MAX = 6; - public: - static bool is_valid(const int32_t state){ - return state > N && state < MAX; - } - }; - - struct Ops - { - public: - static const int64_t INVALID = -1; - static const int64_t ALLOC = 0; - static const int64_t LOAD = 1; - static const int64_t LOAD_FAIL = 2; - static const int64_t LOAD_SUCC = 3; - static const int64_t DELETE = 4; - static const int64_t WRITE = 5; - static const int64_t WRITE_BACK = 6; - static const int64_t WRITE_BACK_FAILED = 7; - static const int64_t WRITE_BACK_SUCC = 8; - static const int64_t MAX = 9; - public: - static bool is_valid(const int64_t op){ - return op > INVALID && op < MAX; - } - }; -public: - bool is_block_beginning_; // means buf_ points to the beginning of a memory block, - // allocator only free page entry with this flag set to true. - char *buf_; - int64_t fd_; - int32_t state_; - uint32_t next_page_id_; - ObTmpFilePageUniqKey page_key_; -}; - -// wrap ObArray to support release memory -class ObTmpWriteBufferPoolEntryArray -{ -public: - ObTmpWriteBufferPoolEntryArray() : is_inited_(false), size_(0), buckets_() {} - ~ObTmpWriteBufferPoolEntryArray() { destroy(); } - int init(); - void destroy(); - int push_back(const ObPageEntry &entry); - void pop_back(); - int64_t size() const { return size_; } - int64_t count() const { return size(); } - - inline ObPageEntry &operator[] (const int64_t idx) - { - const int64_t bucket_idx = idx / MAX_BUCKET_CAPACITY; - const int64_t bucket_offset = idx % MAX_BUCKET_CAPACITY; - return buckets_[bucket_idx]->at(bucket_offset); - } -private: - // by reserving 10000 entries(48 bytes), the array buffer will be upper aligned to accommodate 10085 entries - static const int64_t MAX_BUCKET_CAPACITY = 10085; - - int add_new_bucket_(); -private: - bool is_inited_; - int64_t size_; - ObArray *> buckets_; - ModulePageAllocator extend_allocator_; - ObFIFOAllocator allocator_; -}; - -} // end namespace tmp_file -} // end namespace oceanbase - -#endif diff --git a/src/storage/tmp_file/tmp_file_service.cpp b/src/storage/tmp_file/tmp_file_service.cpp new file mode 100644 index 0000000000..764b8da733 --- /dev/null +++ b/src/storage/tmp_file/tmp_file_service.cpp @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2025 OceanBase. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#define USING_LOG_PREFIX STORAGE + +#include +#include +#include +#include "storage/tmp_file/tmp_file_service.h" +#include "data_plane/tmp_file/ob_tmp_file.h" +#include "lib/alloc/alloc_func.h" +#include "lib/container/ob_iarray.h" +#include "share/ob_errno.h" +#include "lib/oblog/ob_log.h" +#include "rust/config.h" +#include "rust/tmp_file.h" +#include "share/rc/ob_server_runtime.h" + +namespace oceanbase +{ +namespace +{ +using namespace common; +using tmp_file::rust_io::Code; +using tmp_file::rust_io::Status; +using tmp_file::rust_io::Service; + +int convert_tmp_file_status(const Status status) +{ + switch (status.code) { + case Code::Ok: return OB_SUCCESS; + case Code::Invalid: return OB_INVALID_ARGUMENT; + case Code::Closed: return OB_ENTRY_NOT_EXIST; + case Code::Sealed: return OB_ERR_TMP_FILE_ALREADY_SEALED; + case Code::Busy: return OB_EAGAIN; + case Code::End: return OB_ITER_END; + case Code::Timeout: return OB_TIMEOUT; + case Code::Canceled: return OB_CANCELED; + case Code::DiskQuota: return OB_TMP_FILE_EXCEED_DISK_QUOTA; + case Code::DiskFull: return OB_SERVER_OUTOF_DISK_SPACE; + case Code::BufferQuota: return OB_ALLOCATE_MEMORY_FAILED; + default: return OB_IO_ERROR; + } +} + +int log_tmp_file_status(const Status status, const char *operation, const int64_t fd) +{ + const int ret = convert_tmp_file_status(status); + if (OB_SUCCESS != ret && OB_ITER_END != ret && OB_ENTRY_NOT_EXIST != ret) { + LOG_WARN("temporary file operation failed", KR(ret), K(operation), K(fd), K(status.os_error)); + } + return ret; +} + +uint64_t io_buffer_limit() +{ + // Keep the existing runtime-memory scale while allowing a full-size request. + return std::max(32 * 1024 * 1024, + lib::get_memory_budget() / 50 * config::_temporary_file_io_area_size()); +} + +const Service *tmp_file_service() +{ + auto *manager = share::server_service(); + return OB_ISNULL(manager) ? nullptr : manager->service(); +} +} // namespace + +namespace tmp_file +{ +using namespace common; + +int ObTmpFileManager::server_module_init(ObTmpFileManager *&manager) +{ + int ret = OB_SUCCESS; + if (OB_ISNULL(manager)) { + ret = OB_INVALID_ARGUMENT; + } else if (OB_NOT_NULL(manager->service_)) { + ret = OB_INIT_TWICE; + } else { + auto data_dir = config::data_dir(); + Status status{}; + auto service = rust_io::new_service(data_dir, config::temporary_file_max_disk_size(), + io_buffer_limit(), status); + if (OB_FAIL(log_tmp_file_status(status, "initialize", -1))) { + LOG_WARN("unable to open instance temporary storage", KR(ret), "data_dir", data_dir.c_str()); + } else { + manager->service_ = service.into_raw(); + } + } + return ret; +} + +void ObTmpFileManager::reload_config() +{ + if (OB_NOT_NULL(service_)) { + service_->configure(config::temporary_file_max_disk_size(), io_buffer_limit()); + } +} + +void ObTmpFileManager::shutdown() +{ + if (OB_NOT_NULL(service_)) { + (void)log_tmp_file_status(service_->shutdown(), "shutdown", -1); + } +} + +void ObTmpFileManager::destroy() +{ + if (OB_NOT_NULL(service_)) { + shutdown(); + auto service = rust::Box::from_raw(std::exchange(service_, nullptr)); + } +} + +int ObTmpFileManager::get_tmp_file_disk_usage(int64_t &data_bytes, int64_t &occupied_bytes) const +{ + if (OB_ISNULL(service_)) { + return OB_NOT_INIT; + } + const auto usage = service_->usage(); + data_bytes = usage.disk_bytes; + occupied_bytes = usage.disk_bytes; + return OB_SUCCESS; +} + +int ObTmpFileManager::get_tmp_file_fds(ObIArray &ids) const +{ + int ret = OB_SUCCESS; + if (OB_ISNULL(service_)) { + ret = OB_NOT_INIT; + } else { + for (const int64_t fd : service_->files()) { + if (OB_FAIL(ids.push_back(fd))) { + break; + } + } + } + return ret; +} + +int ObTmpFileManager::get_tmp_file_info(const int64_t fd, FileInfo &info) const +{ + int ret = OB_SUCCESS; + rust_io::Snapshot snapshot{}; + if (OB_ISNULL(service_)) { + ret = OB_NOT_INIT; + } else if (OB_FAIL(convert_tmp_file_status(service_->snapshot(fd, snapshot)))) { + } else { + info = {fd, snapshot.group, static_cast(snapshot.len), + static_cast(snapshot.prefix), static_cast(snapshot.writes), + static_cast(snapshot.reads), static_cast(snapshot.read_bytes)}; + } + return ret; +} +} // namespace tmp_file + +namespace data_plane +{ +using namespace common; +using tmp_file::rust_io::IoRequest; + +class ObTmpFileAccess +{ +public: + enum class Operation { APPEND, READ, PREAD }; + + static int submit(const ObTmpFileIOInfo &io, const int64_t offset, + const Operation operation, ObTmpFileIOHandle &handle) + { + int ret = OB_SUCCESS; + const Service *service = tmp_file_service(); + if (!io.is_valid() || offset < -1) { + ret = OB_INVALID_ARGUMENT; + } else if (OB_ISNULL(service)) { + ret = OB_NOT_INIT; + } else if (handle.is_valid() && !handle.is_finished()) { + ret = OB_STATE_NOT_MATCH; + } else { + handle.reset(); + Status status{}; + const bool append = Operation::APPEND == operation; + auto request = [&]() { + if (append) { + return service->append(io.fd_, rust::Slice( + reinterpret_cast(io.buf_), io.size_), io.io_timeout_ms_, status); + } else if (Operation::PREAD == operation) { + return service->read_at(io.fd_, offset, rust::Slice( + reinterpret_cast(io.buf_), io.size_), io.io_timeout_ms_, status); + } else { + return service->read(io.fd_, offset, io.size_, io.io_timeout_ms_, status); + } + }(); + if (OB_SUCC(ret = log_tmp_file_status(status, append ? "append" : "read", io.fd_))) { + handle.impl_ = request.into_raw(); + handle.buf_ = append ? nullptr : io.buf_; + handle.size_ = io.size_; + handle.fd_ = io.fd_; + } + } + return ret; + } +}; + +ObTmpFileIOInfo::ObTmpFileIOInfo() +{ + reset(); +} + +void ObTmpFileIOInfo::reset() +{ + fd_ = -1; + dir_id_ = 0; + buf_ = nullptr; + size_ = 0; + io_timeout_ms_ = DEFAULT_IO_WAIT_TIME_MS; +} + +bool ObTmpFileIOInfo::is_valid() const +{ + return fd_ >= 0 && size_ > 0 && static_cast(size_) <= std::numeric_limits::max() + && OB_NOT_NULL(buf_) && io_timeout_ms_ >= 0; +} + +ObTmpFileIOHandle::ObTmpFileIOHandle() + : impl_(nullptr), buf_(nullptr), size_(0), fd_(-1) +{ +} + +ObTmpFileIOHandle::~ObTmpFileIOHandle() +{ + reset(); +} + +void ObTmpFileIOHandle::reset() +{ + if (is_valid()) { + auto request = rust::Box::from_raw( + static_cast(std::exchange(impl_, nullptr))); + } + buf_ = nullptr; + size_ = 0; + fd_ = -1; +} + +int ObTmpFileIOHandle::wait() +{ + int ret = OB_SUCCESS; + auto *request = static_cast(impl_); + if (OB_ISNULL(request)) { + ret = OB_NOT_INIT; + } else { + const bool pending_read = OB_NOT_NULL(buf_) && !request->is_finished(); + if (OB_FAIL(log_tmp_file_status(request->wait(), "wait", fd_))) { + } else if (pending_read) { + ret = convert_tmp_file_status(request->copy_read( + rust::Slice(reinterpret_cast(buf_), size_))); + } + } + return ret; +} + +bool ObTmpFileIOHandle::is_valid() const +{ + return OB_NOT_NULL(impl_); +} + +char *ObTmpFileIOHandle::get_buffer() +{ + return buf_; +} + +int64_t ObTmpFileIOHandle::get_done_size() const +{ + const auto *request = static_cast(impl_); + return OB_ISNULL(request) ? -1 : static_cast(request->done()); +} + +bool ObTmpFileIOHandle::is_finished() const +{ + const auto *request = static_cast(impl_); + return OB_NOT_NULL(request) && request->is_finished(); +} + +int tmp_file_alloc_dir(int64_t &dir_id) +{ + const auto *service = tmp_file_service(); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->new_group(dir_id)); +} + +int tmp_file_open(int64_t &fd, const int64_t dir_id) +{ + const auto *service = tmp_file_service(); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->open(dir_id, fd)); +} + +int tmp_file_remove(const int64_t fd) +{ + const auto *service = tmp_file_service(); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->close(fd)); +} + +int tmp_file_aio_read(const ObTmpFileIOInfo &io, ObTmpFileIOHandle &handle) +{ + return ObTmpFileAccess::submit(io, -1, ObTmpFileAccess::Operation::READ, handle); +} + +int tmp_file_aio_pread(const ObTmpFileIOInfo &io, const int64_t offset, ObTmpFileIOHandle &handle) +{ + return offset < 0 ? OB_INVALID_ARGUMENT : ObTmpFileAccess::submit(io, offset, ObTmpFileAccess::Operation::READ, handle); +} + +int tmp_file_pread(const ObTmpFileIOInfo &io, const int64_t offset, ObTmpFileIOHandle &handle) +{ + return offset < 0 ? OB_INVALID_ARGUMENT : ObTmpFileAccess::submit(io, offset, ObTmpFileAccess::Operation::PREAD, handle); +} + +int tmp_file_aio_write(const ObTmpFileIOInfo &io, ObTmpFileIOHandle &handle) +{ + return ObTmpFileAccess::submit(io, -1, ObTmpFileAccess::Operation::APPEND, handle); +} + +int tmp_file_write(const ObTmpFileIOInfo &io) +{ + ObTmpFileIOHandle handle; + const int ret = tmp_file_aio_write(io, handle); + return OB_SUCCESS == ret ? handle.wait() : ret; +} + +int tmp_file_truncate(const int64_t fd, const int64_t offset) +{ + const auto *service = tmp_file_service(); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->reclaim(fd, offset)); +} + +int tmp_file_seal(const int64_t fd) +{ + const auto *service = tmp_file_service(); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->seal(fd)); +} + +int tmp_file_get_size(const int64_t fd, int64_t &size) +{ + int ret = OB_SUCCESS; + const auto *service = tmp_file_service(); + tmp_file::rust_io::Snapshot snapshot{}; + if (OB_ISNULL(service)) { + ret = OB_NOT_INIT; + } else if (OB_FAIL(convert_tmp_file_status(service->snapshot(fd, snapshot)))) { + } else { + size = snapshot.len; + } + return ret; +} + +} // namespace data_plane +} // namespace oceanbase diff --git a/src/storage/tmp_file/tmp_file_service.h b/src/storage/tmp_file/tmp_file_service.h new file mode 100644 index 0000000000..d1fe2e8d9e --- /dev/null +++ b/src/storage/tmp_file/tmp_file_service.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 OceanBase. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include + +namespace oceanbase +{ +namespace common +{ +template class ObIArray; +} +namespace tmp_file +{ +namespace rust_io { struct Service; } + +struct FileInfo +{ + int64_t fd_; + int64_t dir_id_; + int64_t size_; + int64_t prefix_; + int64_t writes_; + int64_t reads_; + int64_t read_bytes_; +}; + +class ObTmpFileManager +{ +public: + ObTmpFileManager() = default; + ~ObTmpFileManager() { destroy(); } + static int server_module_init(ObTmpFileManager *&manager); + void reload_config(); + void shutdown(); + void destroy(); + + const rust_io::Service *service() const { return service_; } + int get_tmp_file_disk_usage(int64_t &data_bytes, int64_t &occupied_bytes) const; + int get_tmp_file_fds(common::ObIArray &ids) const; + int get_tmp_file_info(int64_t fd, FileInfo &info) const; + +private: + ObTmpFileManager(const ObTmpFileManager &) = delete; + ObTmpFileManager &operator=(const ObTmpFileManager &) = delete; + rust_io::Service *service_ = nullptr; +}; + +} // namespace tmp_file +} // namespace oceanbase diff --git a/tests/mysqltest/cases/r/tmp_file_spill.result b/tests/mysqltest/cases/r/tmp_file_spill.result new file mode 100644 index 0000000000..a36116a11d --- /dev/null +++ b/tests/mysqltest/cases/r/tmp_file_spill.result @@ -0,0 +1,7 @@ +SELECT COUNT(*), COUNT(next_id), MIN(next_id), MAX(next_id), SUM(next_id) +FROM (SELECT LEAD(id, 128) OVER (ORDER BY sort_key) AS next_id FROM tmp_spill_rows) ordered_rows; +ERROR HY000: tmp file exceeds disk quota +SELECT COUNT(*), COUNT(next_id), MIN(next_id), MAX(next_id), SUM(next_id) +FROM (SELECT LEAD(id, 128) OVER (ORDER BY sort_key) AS next_id FROM tmp_spill_rows) ordered_rows; +COUNT(*) COUNT(next_id) MIN(next_id) MAX(next_id) SUM(next_id) +100000 99872 0 99871 4987158256 diff --git a/tests/mysqltest/cases/t/tmp_file_spill.test b/tests/mysqltest/cases/t/tmp_file_spill.test new file mode 100644 index 0000000000..2a26ba79bb --- /dev/null +++ b/tests/mysqltest/cases/t/tmp_file_spill.test @@ -0,0 +1,31 @@ +--disable_query_log +CREATE TABLE tmp_spill_digits (d INT PRIMARY KEY); +INSERT INTO tmp_spill_digits VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +CREATE TABLE tmp_spill_rows (id INT PRIMARY KEY, sort_key VARCHAR(512) NOT NULL); +INSERT INTO tmp_spill_rows +SELECT n, CONCAT(LPAD(100000 - n, 8, '0'), REPEAT(CHAR(65 + MOD(n, 26)), 480)) +FROM ( + SELECT a.d + 10*b.d + 100*c.d + 1000*e.d + 10000*f.d AS n + FROM tmp_spill_digits a, tmp_spill_digits b, tmp_spill_digits c, + tmp_spill_digits e, tmp_spill_digits f +) input_rows; +ALTER SYSTEM SET workarea_size_policy = 'MANUAL'; +ALTER SYSTEM SET _sort_area_size = '2M'; +SET SESSION ob_query_timeout = 120000000; +ALTER SYSTEM SET temporary_file_max_disk_size = '1M'; +--enable_query_log + +--error 9135 +SELECT COUNT(*), COUNT(next_id), MIN(next_id), MAX(next_id), SUM(next_id) +FROM (SELECT LEAD(id, 128) OVER (ORDER BY sort_key) AS next_id FROM tmp_spill_rows) ordered_rows; + +--disable_query_log +ALTER SYSTEM SET temporary_file_max_disk_size = '0M'; +--enable_query_log +SELECT COUNT(*), COUNT(next_id), MIN(next_id), MAX(next_id), SUM(next_id) +FROM (SELECT LEAD(id, 128) OVER (ORDER BY sort_key) AS next_id FROM tmp_spill_rows) ordered_rows; + +--disable_query_log +ALTER SYSTEM SET _sort_area_size = '32M'; +ALTER SYSTEM SET workarea_size_policy = 'AUTO'; +DROP TABLE tmp_spill_rows, tmp_spill_digits; From c842a76859e93e80ba3b80129104cc9c5d079a5b Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 00:19:36 +0800 Subject: [PATCH 2/7] fix(storage): clean spill files on initialize-only exit --- src/observer/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/observer/main.cpp b/src/observer/main.cpp index bbf1344abf..833cb4e053 100644 --- a/src/observer/main.cpp +++ b/src/observer/main.cpp @@ -64,6 +64,7 @@ static void seekdb_cov_init_profile_file(int argc, char **argv) #include "observer/ob_signal_handle.h" #include "share/config/ob_server_config.h" #include "share/ob_version.h" +#include "storage/tmp_file/tmp_file_service.h" #include #ifndef _WIN32 #include @@ -710,6 +711,9 @@ int inner_main(int argc, char *argv[]) } if (initialize) { LOG_INFO("seekdb starts in initialize mode, exit now", K(initialize)); + if (auto *tmp_files = observer.tmp_file_manager(); OB_NOT_NULL(tmp_files)) { + tmp_files->shutdown(); + } _exit(OB_SUCC(ret) ? 0 : 1); } if (OB_FAIL(ret)) { From 0d05b40545eb3f2d7633bac489eb59b613c8932a Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 00:20:02 +0800 Subject: [PATCH 3/7] fix(storage): anchor temporary spill cleanup to the instance directory --- rust/tmp-file/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/tmp-file/src/lib.rs b/rust/tmp-file/src/lib.rs index 6d259335b9..d10e70caef 100644 --- a/rust/tmp-file/src/lib.rs +++ b/rust/tmp-file/src/lib.rs @@ -355,6 +355,7 @@ impl Engine { return Err(Error::Invalid); } fs::create_dir_all(root)?; + let root = fs::canonicalize(root)?; let lock = OpenOptions::new() .read(true) .write(true) From 2e750f371dbab66a35c2808212c007151531e621 Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 01:07:09 +0800 Subject: [PATCH 4/7] perf(storage): reuse a bounded set of spill segment handles --- rust/tmp-file/src/lib.rs | 61 ++++++++++++++++++++++++++------------ rust/tmp-file/src/tests.rs | 41 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 19 deletions(-) diff --git a/rust/tmp-file/src/lib.rs b/rust/tmp-file/src/lib.rs index d10e70caef..6d641d15dd 100644 --- a/rust/tmp-file/src/lib.rs +++ b/rust/tmp-file/src/lib.rs @@ -112,10 +112,13 @@ impl Drop for Charge { } } +const MAX_RETAINED_SEGMENT_FILES: u64 = 64; + struct Directory { path: PathBuf, _lock: file_io::ExclusiveFile, disk: Quota, + retained_files: Quota, min_free_space: u64, } @@ -130,9 +133,31 @@ struct Segment { path: PathBuf, directory: Arc, charged: AtomicU64, + file: Mutex>, } impl Segment { + fn with_file(&self, create: bool, io: impl FnOnce(&File) -> io::Result) -> io::Result { + let mut retained = self.file.lock().unwrap(); + if let Some(file) = retained.as_ref() { + return io(file); + } + let file = OpenOptions::new() + .read(true) + .write(true) + .create(create) + .truncate(false) + .open(&self.path)?; + if self.directory.retained_files.reserve(1) { + // Keep operations serialized on the retained handle, including platforms + // whose positioned operations also update the file cursor. + io(retained.insert(file)) + } else { + drop(retained); + io(&file) + } + } + // Only the file's single admitted append can grow any of its segments. fn reserve_through(&self, end: u64) -> Result<()> { let charged = self.charged.load(Ordering::Relaxed); @@ -159,13 +184,7 @@ impl Segment { fn rollback_to(&self, len: u64) { let charged = self.charged.load(Ordering::Relaxed); - if charged > len - && OpenOptions::new() - .write(true) - .open(&self.path) - .and_then(|file| file.set_len(len)) - .is_ok() - { + if charged > len && self.with_file(false, |file| file.set_len(len)).is_ok() { self.charged.store(len, Ordering::Relaxed); self.directory.disk.release(charged - len); } @@ -174,6 +193,10 @@ impl Segment { impl Drop for Segment { fn drop(&mut self) { + if let Some(file) = self.file.get_mut().unwrap().take() { + drop(file); + self.directory.retained_files.release(1); + } // Keep the charge when deletion fails. The directory owner will retry. match fs::remove_file(&self.path) { Ok(()) => self @@ -311,8 +334,9 @@ impl ReadPlan { let offset = pos % self.segment_size; let size = (self.end - pos).min(self.segment_size - offset); let first = (pos - self.start) as usize; - let source = File::open(&segment.path)?; - file_io::read_exact_at(&source, &mut dst[first..first + size as usize], offset)?; + segment.with_file(false, |source| { + file_io::read_exact_at(source, &mut dst[first..first + size as usize], offset) + })?; pos += size; } check() @@ -380,6 +404,7 @@ impl Engine { path, _lock: lock, disk: Quota::new(options.disk_limit), + retained_files: Quota::new(MAX_RETAINED_SEGMENT_FILES), min_free_space: options.min_free_space, }); let runtime = Builder::new_current_thread() @@ -559,21 +584,19 @@ impl Engine { path: directory.path.join(format!("{}-{index}", file.id.0)), directory: directory.clone(), charged: AtomicU64::new(0), + file: Mutex::new(None), }) }) .clone(); segment.reserve_through(offset + size)?; - let target = OpenOptions::new() - .write(true) - .create(true) - .truncate(false) - .open(&segment.path)?; let first = (pos - start) as usize; - file_io::write_all_at( - &target, - &buffer.bytes[first..first + size as usize], - offset, - )?; + segment.with_file(true, |target| { + file_io::write_all_at( + target, + &buffer.bytes[first..first + size as usize], + offset, + ) + })?; pos += size; } Ok(buffer.bytes.len()) diff --git a/rust/tmp-file/src/tests.rs b/rust/tmp-file/src/tests.rs index b598ab1e11..8fb43cb0b9 100644 --- a/rust/tmp-file/src/tests.rs +++ b/rust/tmp-file/src/tests.rs @@ -445,3 +445,44 @@ fn cached_positioned_reads_respect_prefix_reclamation_and_close() { assert_eq!(engine.usage().cache_bytes, 0); assert_eq!(engine.usage().disk_bytes, 0); } + +#[test] +fn limits_open_segments_and_reuses_reclaimed_slots() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + segment_size: 1, + ..options() + }, + ) + .unwrap(); + let file = engine.open(0).unwrap(); + let bytes = vec![3; MAX_RETAINED_SEGMENT_FILES as usize + 1]; + engine + .append(file, &bytes, deadline()) + .unwrap() + .wait() + .unwrap(); + assert_eq!( + engine.directory.retained_files.used(), + MAX_RETAINED_SEGMENT_FILES + ); + + let mut last = [0]; + let offset = MAX_RETAINED_SEGMENT_FILES; + engine.read_at(file, offset, &mut last, deadline()).unwrap(); + assert_eq!(last, [3]); + assert_eq!( + engine.directory.retained_files.used(), + MAX_RETAINED_SEGMENT_FILES + ); + + engine.reclaim_prefix(file, offset).unwrap(); + assert_eq!(engine.directory.retained_files.used(), 0); + engine.read_at(file, offset, &mut last, deadline()).unwrap(); + assert_eq!(last, [3]); + assert_eq!(engine.directory.retained_files.used(), 1); + engine.close(file).unwrap(); + assert_eq!(engine.directory.retained_files.used(), 0); +} From 6d74f50543b756edb4f9d222e3270ae737aecae8 Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 15:58:30 +0800 Subject: [PATCH 5/7] perf(storage): batch Rust temporary file writes --- rust/tmp-file/src/bridge.rs | 20 +- rust/tmp-file/src/lib.rs | 632 ++++++++++++++---- rust/tmp-file/src/tests.rs | 322 ++++++--- src/sql/engine/basic/ob_chunk_datum_store.cpp | 63 ++ src/sql/engine/basic/ob_chunk_datum_store.h | 7 + src/sql/engine/sort/ob_sort_op_impl.cpp | 4 + .../window_function/ob_window_function_op.cpp | 30 + src/storage/tmp_file/tmp_file_service.cpp | 4 +- 8 files changed, 860 insertions(+), 222 deletions(-) diff --git a/rust/tmp-file/src/bridge.rs b/rust/tmp-file/src/bridge.rs index b88a9e49cd..75392197ea 100644 --- a/rust/tmp-file/src/bridge.rs +++ b/rust/tmp-file/src/bridge.rs @@ -53,6 +53,7 @@ mod ffi { struct Usage { disk_bytes: u64, buffer_bytes: u64, + write_buffer_bytes: u64, cache_bytes: u64, disk_limit: u64, } @@ -70,7 +71,7 @@ mod ffi { fn new_group(self: &Service, id: &mut i64) -> Status; fn open(self: &Service, group: i64, id: &mut i64) -> Status; fn close(self: &Service, id: i64) -> Status; - fn seal(self: &Service, id: i64) -> Status; + fn seal(self: &Service, id: i64, timeout_ms: u64) -> Status; fn reclaim(self: &Service, id: i64, offset: i64) -> Status; fn snapshot(self: &Service, id: i64, snapshot: &mut Snapshot) -> Status; fn files(self: &Service) -> Vec; @@ -201,8 +202,10 @@ impl Service { self.engine().close(FileId::from_raw(id as u64)).into() } - fn seal(&self, id: i64) -> Status { - self.engine().seal(FileId::from_raw(id as u64)).into() + fn seal(&self, id: i64, timeout_ms: u64) -> Status { + self.engine() + .seal(FileId::from_raw(id as u64), deadline(timeout_ms)) + .into() } fn reclaim(&self, id: i64, offset: i64) -> Status { @@ -241,6 +244,7 @@ impl Service { Usage { disk_bytes: usage.disk_bytes, buffer_bytes: usage.buffer_bytes, + write_buffer_bytes: usage.write_buffer_bytes, cache_bytes: usage.cache_bytes, disk_limit: usage.disk_limit, } @@ -259,7 +263,7 @@ impl Service { IoRequest::submitted( self.engine() .append(FileId::from_raw(id as u64), data, deadline(timeout_ms)) - .map(Pending::Write), + .map(Pending::AcceptedWrite), status, ) } @@ -317,7 +321,8 @@ fn deadline(timeout_ms: u64) -> Instant { enum Pending { Read(Request), - Write(Request), + // C++ exposes the accepted byte count when the caller waits on the handle. + AcceptedWrite(usize), } pub struct IoRequest { @@ -354,7 +359,10 @@ impl IoRequest { self.done = buffer.as_ref().len(); self.buffer = Some(buffer); }), - Pending::Write(write) => write.wait().map(|done| self.done = done), + Pending::AcceptedWrite(done) => { + self.done = done; + Ok(()) + } } .into(); } diff --git a/rust/tmp-file/src/lib.rs b/rust/tmp-file/src/lib.rs index 6d641d15dd..a04c331742 100644 --- a/rust/tmp-file/src/lib.rs +++ b/rust/tmp-file/src/lib.rs @@ -61,6 +61,9 @@ impl From for Error { type Result = std::result::Result; +const WRITE_BUFFER_SIZE: usize = 1024 * 1024; +const WRITE_BUFFER_LIMIT: u64 = 16 * 1024 * 1024; + pub struct Options { pub segment_size: u64, pub disk_limit: u64, @@ -73,6 +76,7 @@ pub struct Options { struct Quota { used: AtomicU64, limit: AtomicU64, + available: Option<(Mutex, Condvar)>, } impl Quota { @@ -80,9 +84,48 @@ impl Quota { Self { used: AtomicU64::new(0), limit: AtomicU64::new(limit), + available: None, + } + } + + fn notifying(limit: u64) -> Self { + Self { + available: Some((Mutex::new(0), Condvar::new())), + ..Self::new(limit) + } + } + + fn notify(&self) { + if let Some((lock, ready)) = &self.available { + let mut generation = lock.lock().unwrap(); + *generation = generation.wrapping_add(1); + ready.notify_all(); } } + fn generation(&self) -> u64 { + *self.available.as_ref().unwrap().0.lock().unwrap() + } + + fn wait_for(&self, generation: u64, amount: u64, deadline: Instant, closed: &AtomicBool) { + let (lock, ready) = self.available.as_ref().unwrap(); + let guard = lock.lock().unwrap(); + let remaining = deadline.saturating_duration_since(Instant::now()); + drop( + ready + .wait_timeout_while(guard, remaining, |current| { + *current == generation + && self + .limit + .load(Ordering::Acquire) + .saturating_sub(self.used()) + < amount + && !closed.load(Ordering::Acquire) + }) + .unwrap(), + ); + } + fn reserve(&self, bytes: u64) -> bool { self.used .try_update(Ordering::AcqRel, Ordering::Acquire, |used| { @@ -94,6 +137,7 @@ impl Quota { fn release(&self, bytes: u64) { self.used.fetch_sub(bytes, Ordering::AcqRel); + self.notify(); } fn used(&self) -> u64 { @@ -158,33 +202,20 @@ impl Segment { } } - // Only the file's single admitted append can grow any of its segments. - fn reserve_through(&self, end: u64) -> Result<()> { - let charged = self.charged.load(Ordering::Relaxed); - if end > charged { - if !self.directory.disk.reserve(end - charged) { - return Err(Error::DiskQuota); - } - if self.directory.min_free_space > 0 { - let available = file_io::space(&self.directory.path).map(|space| space.available); - match available { - Ok(bytes) - if bytes >= self.directory.min_free_space.saturating_add(end - charged) => { - } - other => { - self.directory.disk.release(end - charged); - return Err(other.err().map_or(Error::DiskFull, Error::Io)); - } - } - } - self.charged.store(end, Ordering::Relaxed); - } - Ok(()) - } - fn rollback_to(&self, len: u64) { let charged = self.charged.load(Ordering::Relaxed); - if charged > len && self.with_file(false, |file| file.set_len(len)).is_ok() { + if charged <= len { + return; + } + let truncated = self.with_file(false, |file| { + if file.metadata()?.len() > len { + file.set_len(len)?; + } + Ok(()) + }); + if truncated.is_ok() + || truncated.is_err_and(|error| error.kind() == io::ErrorKind::NotFound) + { self.charged.store(len, Ordering::Relaxed); self.directory.disk.release(charged - len); } @@ -222,8 +253,54 @@ struct CachedRead { data: Arc, } +struct Tail { + start: u64, + data: Arc, +} + +impl Tail { + fn end(&self) -> u64 { + self.start + self.data.bytes.len() as u64 + } +} + +enum Flush { + Pending(Tail), + Failed(Option, FlushError), +} + +enum FlushError { + DiskFull, + Io(io::Error), +} + +impl FlushError { + fn snapshot(&self) -> Error { + match self { + Self::DiskFull => Error::DiskFull, + Self::Io(error) => Error::Io( + error + .raw_os_error() + .map_or_else(|| error.kind().into(), io::Error::from_raw_os_error), + ), + } + } +} + +impl Flush { + fn tail(&self) -> Option<&Tail> { + match self { + Self::Pending(tail) => Some(tail), + Self::Failed(tail, _) => tail.as_ref(), + } + } +} + #[derive(Default)] struct FileState { + tail: Option, + flush: Option, + rollback: bool, segments: BTreeMap>, read_cache: VecDeque, end: u64, @@ -237,6 +314,27 @@ struct FileState { } impl FileState { + fn oldest_tail(&self) -> Option<&Tail> { + self.flush.as_ref().and_then(Flush::tail) + } + + fn memory_start(&self, fallback: u64) -> u64 { + self.oldest_tail() + .or(self.tail.as_ref()) + .map_or(fallback, |tail| tail.start) + } + + fn flush_status(&self) -> Result<()> { + match self.flush.as_ref() { + Some(Flush::Failed(_, error)) => Err(error.snapshot()), + _ => Ok(()), + } + } + + fn flush_pending(&self) -> bool { + matches!(self.flush, Some(Flush::Pending(_))) + } + fn lookup_read(&mut self, offset: u64, len: usize) -> Option> { let index = self .read_cache @@ -269,9 +367,107 @@ struct SpillFile { id: FileId, group: i64, state: Mutex, + flushed: Condvar, + closed: AtomicBool, } impl SpillFile { + // Reservation covers published bytes and the one append currently being staged. + fn reserve_append( + &self, + state: &mut FileState, + end: u64, + segment_size: u64, + directory: &Arc, + ) -> Result<()> { + let start = state.end; + let first = start / segment_size; + let last = (end - 1) / segment_size; + let charged = state + .segments + .get(&first) + .map_or(0, |segment| segment.charged.load(Ordering::Relaxed)); + let reserve = (end - first * segment_size).saturating_sub(charged); + if !directory.disk.reserve(reserve) { + return Err(Error::DiskQuota); + } + for index in first..=last { + let segment = state.segments.entry(index).or_insert_with(|| { + Arc::new(Segment { + path: directory.path.join(format!("{}-{index}", self.id.0)), + directory: directory.clone(), + charged: AtomicU64::new(0), + file: Mutex::new(None), + }) + }); + let next = (end - index * segment_size).min(segment_size); + segment.charged.fetch_max(next, Ordering::Relaxed); + } + Ok(()) + } + + fn complete_rollback(&self, end: u64, segment_size: u64) { + self.rollback_disk(end, segment_size); + let mut state = self.state.lock().unwrap(); + state.rollback = false; + state.appending = false; + self.flushed.notify_all(); + } + + fn abort_append(&self, mut state: std::sync::MutexGuard<'_, FileState>, segment_size: u64) { + let end = state.end; + let prefix = state.prefix; + if let Some(tail) = &mut state.tail { + let committed = end.saturating_sub(tail.start) as usize; + Arc::get_mut(&mut tail.data) + .unwrap() + .bytes + .truncate(committed); + if committed == 0 || prefix >= tail.end() { + state.tail = None; + } + } + state.rollback = true; + let pending = state.flush_pending(); + drop(state); + if !pending { + self.complete_rollback(end, segment_size); + } + } + + fn rollback_disk(&self, start: u64, segment_size: u64) { + let (abandoned, tail) = { + let mut state = self.state.lock().unwrap(); + let abandoned = state.segments.split_off(&start.div_ceil(segment_size)); + let tail = state.segments.get(&(start / segment_size)).cloned(); + (abandoned, tail) + }; + drop(abandoned); + if let Some(tail) = tail { + tail.rollback_to(start % segment_size); + } + } + + fn mark_closed(&self) { + let _state = self.state.lock().unwrap(); + self.closed.store(true, Ordering::Release); + self.flushed.notify_all(); + } + + fn wait_for_flush<'a>( + &self, + state: std::sync::MutexGuard<'a, FileState>, + deadline: Instant, + ) -> std::sync::MutexGuard<'a, FileState> { + let remaining = deadline.saturating_duration_since(Instant::now()); + self.flushed + .wait_timeout_while(state, remaining, |state| { + state.flush_pending() && !self.closed.load(Ordering::Acquire) + }) + .unwrap() + .0 + } + fn record_read(&self, len: usize) { let mut state = self.state.lock().unwrap(); state.reads = state.reads.saturating_add(1); @@ -282,6 +478,7 @@ impl SpillFile { struct ReadPlan { start: u64, data_start: u64, + disk_end: u64, end: u64, segment_size: u64, segments: Vec>, @@ -297,9 +494,10 @@ impl ReadPlan { } let end = start + (state.end - start).min(size as u64); let data_start = start.max(state.prefix).min(end); - let segments = if data_start < end { + let disk_end = state.memory_start(end).clamp(data_start, end); + let segments = if data_start < disk_end { let first = data_start / segment_size; - let last = (end - 1) / segment_size; + let last = (disk_end - 1) / segment_size; let segments: Vec<_> = state .segments .range(first..=last) @@ -315,6 +513,7 @@ impl ReadPlan { Ok(Self { start, data_start, + disk_end, end, segment_size, segments, @@ -325,6 +524,22 @@ impl ReadPlan { (self.end - self.start) as usize } + fn copy_tail(&self, state: &FileState, dst: &mut [u8]) { + for tail in [state.oldest_tail(), state.tail.as_ref()] + .into_iter() + .flatten() + { + let start = self.disk_end.max(tail.start); + let end = self.end.min(tail.end()); + if start < end { + let offset = (start - tail.start) as usize; + let size = (end - start) as usize; + let first = (start - self.start) as usize; + dst[first..first + size].copy_from_slice(&tail.data.bytes[offset..offset + size]); + } + } + } + fn read_into(&self, dst: &mut [u8], check: impl Fn() -> Result<()>) -> Result<()> { // Reads of the discarded prefix retain their original zero-fill semantics. dst[..(self.data_start - self.start) as usize].fill(0); @@ -332,7 +547,7 @@ impl ReadPlan { for segment in &self.segments { check()?; let offset = pos % self.segment_size; - let size = (self.end - pos).min(self.segment_size - offset); + let size = (self.disk_end - pos).min(self.segment_size - offset); let first = (pos - self.start) as usize; segment.with_file(false, |source| { file_io::read_exact_at(source, &mut dst[first..first + size as usize], offset) @@ -343,15 +558,65 @@ impl ReadPlan { } } +fn write_tail(file: &SpillFile, start: u64, bytes: &[u8], segment_size: u64) -> Result<()> { + let end = start + bytes.len() as u64; + let mut pos = start; + while pos < end { + let (segment, offset) = { + let state = file.state.lock().unwrap(); + pos = pos.max(state.prefix); + if pos >= end || file.closed.load(Ordering::Acquire) { + break; + } + let index = pos / segment_size; + let segment = state + .segments + .get(&index) + .expect("the append reserves each segment") + .clone(); + (segment, pos - index * segment_size) + }; + let size = (end - pos).min(segment_size - offset); + let directory = &segment.directory; + if directory.min_free_space > 0 { + let space = file_io::space(&directory.path)?; + if space.available < directory.min_free_space.saturating_add(size) { + return Err(Error::DiskFull); + } + } + let first = (pos - start) as usize; + segment.with_file(true, |target| { + if cfg!(target_os = "linux") && size >= 128 * 1024 { + match file_io::allocate(target, offset..offset + size, file_io::Allocation::Reserve) + { + Ok(()) => (), + Err(error) if error.kind() == io::ErrorKind::Unsupported => (), + Err(error) => return Err(error), + } + } + file_io::write_all_at(target, &bytes[first..first + size as usize], offset) + })?; + pos += size; + } + Ok(()) +} + +struct WriteBufferBudget { + capacity: usize, + quota: Arc, +} + pub struct Engine { directory: Arc, segment_size: u64, buffer: Arc, + write_buffer: WriteBufferBudget, read_cache: Arc, requests: Arc, files: Mutex>>, next_group: AtomicU64, runtime: RwLock>, + stopping: AtomicBool, } #[derive(Debug, Eq, PartialEq)] @@ -369,6 +634,7 @@ pub struct FileSnapshot { pub struct Usage { pub disk_bytes: u64, pub buffer_bytes: u64, + pub write_buffer_bytes: u64, pub cache_bytes: u64, pub disk_limit: u64, } @@ -415,14 +681,28 @@ impl Engine { directory, segment_size: options.segment_size, buffer: Arc::new(Quota::new(options.buffer_limit)), + write_buffer: WriteBufferBudget { + capacity: WRITE_BUFFER_SIZE, + quota: Arc::new(Quota::notifying(WRITE_BUFFER_LIMIT)), + }, read_cache: Arc::new(Quota::new(cache_limit(options.buffer_limit))), requests: Arc::new(Quota::new(options.max_requests)), files: Mutex::new(HashMap::new()), next_group: AtomicU64::new(1), runtime: RwLock::new(Some(runtime)), + stopping: AtomicBool::new(false), }) } + #[cfg(test)] + fn with_tail_budget(mut self, capacity: usize, budget: u64) -> Self { + self.write_buffer = WriteBufferBudget { + capacity, + quota: Arc::new(Quota::notifying(budget)), + }; + self + } + pub fn new_group(&self) -> Result { let _runtime = self.active()?; next_id(&self.next_group).map(|id| id as i64) @@ -437,14 +717,18 @@ impl Engine { id, group, state: Mutex::default(), + flushed: Condvar::new(), + closed: AtomicBool::new(false), }), ); Ok(id) } pub fn close(&self, id: FileId) -> Result<()> { - let removed = self.files.lock().unwrap().remove(&id); - drop(removed); + if let Some(file) = self.files.lock().unwrap().remove(&id) { + file.mark_closed(); + self.write_buffer.quota.notify(); + } Ok(()) } @@ -479,6 +763,7 @@ impl Engine { Usage { disk_bytes: self.directory.disk.used(), buffer_bytes: self.buffer.used(), + write_buffer_bytes: self.write_buffer.quota.used(), cache_bytes: self.read_cache.used(), disk_limit: self.directory.disk.limit.load(Ordering::Acquire), } @@ -499,13 +784,31 @@ impl Engine { } } - pub fn seal(&self, id: FileId) -> Result<()> { + pub fn seal(&self, id: FileId, deadline: Instant) -> Result<()> { + let runtime = self.active()?; + let runtime = runtime.as_ref().unwrap(); let file = self.file(id)?; let mut state = file.state.lock().unwrap(); if state.appending { return Err(Error::Busy); } state.sealed = true; + loop { + if file.closed.load(Ordering::Acquire) { + return Err(Error::Closed); + } + state.flush_status()?; + if !state.flush_pending() && state.tail.is_none() { + break; + } + if Instant::now() >= deadline { + return Err(Error::Timeout); + } + if !state.flush_pending() { + self.flush_tail(runtime, &file, &mut state); + } + state = file.wait_for_flush(state, deadline); + } if state.prefix == state.end { let removed = std::mem::take(&mut state.segments); drop(state); @@ -524,6 +827,14 @@ impl Engine { let prefix = state.prefix; state.cursor = state.cursor.max(prefix); state.read_cache.retain(|entry| entry.offset >= prefix); + if prefix == state.end && !state.appending { + state.tail = None; + } + if let Some(Flush::Failed(tail, _)) = &mut state.flush { + if tail.as_ref().is_some_and(|tail| tail.end() <= prefix) { + *tail = None; + } + } let keep = state.prefix / self.segment_size; let remaining = if state.sealed && state.prefix == state.end { BTreeMap::new() @@ -536,106 +847,153 @@ impl Engine { Ok(()) } - pub fn append(&self, id: FileId, bytes: &[u8], deadline: Instant) -> Result> { + fn flush_tail(&self, runtime: &Runtime, file: &Arc, state: &mut FileState) { + let tail = state.tail.take().unwrap(); + let start = tail.start; + let data = tail.data.clone(); + state.flush = Some(Flush::Pending(tail)); + let file = file.clone(); + let segment_size = self.segment_size; + runtime.spawn_blocking(move || { + let result = write_tail(&file, start, &data.bytes, segment_size); + let quota = result.is_err().then(|| data._charge.quota.clone()); + drop(data); + let mut state = file.state.lock().unwrap(); + let Some(Flush::Pending(old)) = state.flush.take() else { + unreachable!("only the worker completes a pending flush"); + }; + if let Err(error) = result { + let error = match error { + Error::DiskFull => FlushError::DiskFull, + Error::Io(error) => FlushError::Io(error), + _ => unreachable!("writeback reports storage errors"), + }; + let visible = (old.start < state.end && old.end() > state.prefix).then_some(old); + state.flush = Some(Flush::Failed(visible, error)); + } + if let Some(quota) = quota { + quota.notify(); + } + if state.rollback { + let end = state.end; + drop(state); + file.complete_rollback(end, segment_size); + } else { + file.flushed.notify_all(); + } + }); + } + + fn flush_for_capacity(&self, runtime: &Runtime) { + let files: Vec<_> = self.files.lock().unwrap().values().cloned().collect(); + for file in files { + let mut state = file.state.lock().unwrap(); + if state.flush.is_none() + && state.tail.is_some() + && !state.rollback + && !file.closed.load(Ordering::Acquire) + { + self.flush_tail(runtime, &file, &mut state); + return; + } + } + } + + pub fn append(&self, id: FileId, bytes: &[u8], deadline: Instant) -> Result { if bytes.is_empty() { return Err(Error::Invalid); } let runtime = self.active()?; - let slot = self.request_slot(deadline)?; + let runtime = runtime.as_ref().unwrap(); + let _slot = self.request_slot(deadline)?; + if bytes.len() as u64 > self.buffer.limit.load(Ordering::Acquire) { + return Err(Error::BufferQuota); + } let file = self.file(id)?; - let mut buffer = Buffer::new(&self.buffer, bytes.len())?; - buffer.bytes.extend_from_slice(bytes); - let segment_size = self.segment_size; - let directory = self.directory.clone(); let mut state = file.state.lock().unwrap(); + if file.closed.load(Ordering::Acquire) { + return Err(Error::Closed); + } + state.flush_status()?; if state.sealed { return Err(Error::Sealed); } if state.appending { return Err(Error::Busy); } - let start = state.end; - let end = start + let end = state + .end .checked_add(bytes.len() as u64) .filter(|&end| end <= i64::MAX as u64) .ok_or(Error::Invalid)?; + file.reserve_append(&mut state, end, self.segment_size, &self.directory)?; state.appending = true; - drop(state); - Ok(Self::submit( - runtime.as_ref().unwrap(), - slot, - deadline, - move |completion, slot| { - let result = (|| { - let mut pos = start; - while pos < end { - completion.control.check()?; - let index = pos / segment_size; - let offset = pos % segment_size; - let size = (end - pos).min(segment_size - offset); - let segment = file - .state - .lock() - .unwrap() - .segments - .entry(index) - .or_insert_with(|| { - Arc::new(Segment { - path: directory.path.join(format!("{}-{index}", file.id.0)), - directory: directory.clone(), - charged: AtomicU64::new(0), - file: Mutex::new(None), - }) - }) - .clone(); - segment.reserve_through(offset + size)?; - let first = (pos - start) as usize; - segment.with_file(true, |target| { - file_io::write_all_at( - target, - &buffer.bytes[first..first + size as usize], - offset, - ) - })?; - pos += size; + + let mut consumed = 0; + loop { + let error = if file.closed.load(Ordering::Acquire) { + Some(Error::Closed) + } else if Instant::now() >= deadline { + Some(Error::Timeout) + } else { + state.flush_status().err() + }; + if let Some(error) = error { + file.abort_append(state, self.segment_size); + return Err(error); + } + if consumed == bytes.len() { + state.end = end; + state.writes = state.writes.saturating_add(1); + state.appending = false; + return Ok(consumed); + } + + if state.tail.is_none() { + let budget = &self.write_buffer; + let generation = budget.quota.generation(); + match Buffer::try_new(&budget.quota, budget.capacity) { + Ok(Some(data)) => { + let start = state.end + consumed as u64; + state.tail = Some(Tail { + start, + data: Arc::new(data), + }); } - Ok(buffer.bytes.len()) - })(); - drop(buffer); - let error = { - let mut ready = completion.result.lock().unwrap(); - match completion.control.check().and(result) { - Ok(written) => { - let mut state = file.state.lock().unwrap(); - state.end = end; - state.writes = state.writes.saturating_add(1); - state.appending = false; - drop(slot); - *ready = Some(Ok(written)); - completion.ready.notify_all(); - return; - } - Err(error) => error, + Ok(None) => { + drop(state); + self.flush_for_capacity(runtime); + budget.quota.wait_for( + generation, + budget.capacity as u64, + deadline, + &file.closed, + ); + state = file.state.lock().unwrap(); + continue; + } + Err(error) => { + file.abort_append(state, self.segment_size); + return Err(error); } - }; - - // Keep append admission closed while the abandoned suffix is removed. - // The completion mutex remains free so timeout and cancellation can return. - let (abandoned, tail) = { - let mut state = file.state.lock().unwrap(); - let abandoned = state.segments.split_off(&start.div_ceil(segment_size)); - let tail = state.segments.get(&(start / segment_size)).cloned(); - (abandoned, tail) - }; - drop(abandoned); - if let Some(tail) = tail { - tail.rollback_to(start % segment_size); } - file.state.lock().unwrap().appending = false; - drop(slot); - completion.publish(Err(error), |_| {}); - }, - )) + } + let tail = state.tail.as_mut().unwrap(); + let data = Arc::get_mut(&mut tail.data).unwrap(); + let available = self.write_buffer.capacity - data.bytes.len(); + if available == 0 { + if state.flush_pending() { + state = file.wait_for_flush(state, deadline); + } else { + self.flush_tail(runtime, &file, &mut state); + } + continue; + } + let size = available.min(bytes.len() - consumed); + data.bytes + .extend_from_slice(&bytes[consumed..consumed + size]); + consumed += size; + } } /// None reserves a range at the sequential cursor. Explicit offsets leave it unchanged. @@ -650,6 +1008,9 @@ impl Engine { let slot = self.request_slot(deadline)?; let file = self.file(id)?; let mut state = file.state.lock().unwrap(); + if file.closed.load(Ordering::Acquire) { + return Err(Error::Closed); + } let plan = ReadPlan::new( &state, offset.unwrap_or(state.cursor), @@ -658,10 +1019,20 @@ impl Engine { )?; let mut buffer = Buffer::new(&self.buffer, plan.len())?; buffer.bytes.resize(plan.len(), 0); + plan.copy_tail(&state, &mut buffer.bytes); if offset.is_none() { state.cursor = plan.end; } drop(state); + if plan.segments.is_empty() && plan.disk_end < plan.end { + let result = if Instant::now() >= deadline { + Err(Error::Timeout) + } else { + file.record_read(plan.len()); + Ok(buffer) + }; + return Ok(Request::completed(result, deadline)); + } Ok(Self::submit( runtime.as_ref().unwrap(), slot, @@ -703,9 +1074,13 @@ impl Engine { } }; let mut state = file.state.lock().unwrap(); + if file.closed.load(Ordering::Acquire) { + return Err(Error::Closed); + } let requested = (state.end.saturating_sub(offset)).min(dst.len() as u64) as usize; - let cacheable = - offset >= state.prefix && (MIN_CACHED_READ..=MAX_CACHED_READ).contains(&requested); + let cacheable = offset >= state.prefix + && offset + requested as u64 <= state.memory_start(state.end) + && (MIN_CACHED_READ..=MAX_CACHED_READ).contains(&requested); if cacheable { if let Some(data) = state.lookup_read(offset, requested) { drop(state); @@ -716,6 +1091,7 @@ impl Engine { } } let plan = ReadPlan::new(&state, offset, dst.len(), self.segment_size)?; + plan.copy_tail(&state, dst); drop(state); let len = plan.len(); plan.read_into(&mut dst[..len], check_deadline)?; @@ -731,7 +1107,7 @@ impl Engine { fn active(&self) -> Result>> { let runtime = self.runtime.read().unwrap(); - if runtime.is_some() { + if runtime.is_some() && !self.stopping.load(Ordering::Acquire) { Ok(runtime) } else { Err(Error::Closed) @@ -741,6 +1117,11 @@ impl Engine { /// Stops admission, joins accepted I/O, and removes this instance's segments. /// The directory lock remains held until the engine is dropped. pub fn shutdown(&self) -> Result<()> { + self.stopping.store(true, Ordering::Release); + for file in self.files.lock().unwrap().values() { + file.mark_closed(); + } + self.write_buffer.quota.notify(); let mut runtime = self.runtime.write().unwrap(); if let Some(runtime) = runtime.take() { if tokio::runtime::Handle::try_current().is_ok() { @@ -826,9 +1207,13 @@ pub struct Buffer { impl Buffer { fn new(quota: &Arc, len: usize) -> Result { + Self::try_new(quota, len)?.ok_or(Error::BufferQuota) + } + + fn try_new(quota: &Arc, len: usize) -> Result> { let amount = len as u64; if !quota.reserve(amount) { - return Err(Error::BufferQuota); + return Ok(None); } let charge = Charge { quota: quota.clone(), @@ -838,10 +1223,10 @@ impl Buffer { bytes .try_reserve_exact(len) .map_err(|_| Error::BufferQuota)?; - Ok(Self { + Ok(Some(Self { bytes, _charge: charge, - }) + })) } } @@ -891,6 +1276,17 @@ impl Completion { pub struct Request(Arc>); impl Request { + fn completed(result: Result, deadline: Instant) -> Self { + Self(Arc::new(Completion { + control: Control { + deadline, + canceled: AtomicBool::new(false), + }, + result: Mutex::new(Some(result)), + ready: Condvar::new(), + })) + } + pub fn cancel(&self) { let _result = self.0.result.lock().unwrap(); self.0.control.canceled.store(true, Ordering::Release); diff --git a/rust/tmp-file/src/tests.rs b/rust/tmp-file/src/tests.rs index 8fb43cb0b9..b0c7cb205f 100644 --- a/rust/tmp-file/src/tests.rs +++ b/rust/tmp-file/src/tests.rs @@ -60,16 +60,9 @@ fn seal_and_reclaim_preserve_logical_offsets() { let id = engine.open(0).unwrap(); let bytes: Vec<_> = (0..12500).map(|i| (i % 251) as u8).collect(); for chunk in bytes.chunks(1800) { - assert_eq!( - engine - .append(id, chunk, deadline()) - .unwrap() - .wait() - .unwrap(), - chunk.len() - ); + assert_eq!(engine.append(id, chunk, deadline()).unwrap(), chunk.len()); } - engine.seal(id).unwrap(); + engine.seal(id, deadline()).unwrap(); assert!(matches!( engine.append(id, b"x", deadline()), Err(Error::Sealed) @@ -148,21 +141,10 @@ fn quota_failure_can_be_retried_after_another_file_closes() { .unwrap(); let first = engine.open(0).unwrap(); let second = engine.open(0).unwrap(); - engine - .append(first, &[1; 1024], deadline()) - .unwrap() - .wait() - .unwrap(); - engine - .append(second, &[2; 1000], deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(first, &[1; 1024], deadline()).unwrap(); + engine.append(second, &[2; 1000], deadline()).unwrap(); assert!(matches!( - engine - .append(second, &[3; 7100], deadline()) - .unwrap() - .wait(), + engine.append(second, &[3; 7100], deadline()), Err(Error::DiskQuota) )); assert_eq!(engine.snapshot(second).unwrap().len, 1000); @@ -176,11 +158,7 @@ fn quota_failure_can_be_retried_after_another_file_closes() { &[2; 1000] ); engine.close(first).unwrap(); - engine - .append(second, &[3; 7100], deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(second, &[3; 7100], deadline()).unwrap(); assert_eq!(engine.usage().disk_bytes, 8100); assert_eq!( engine @@ -205,11 +183,8 @@ fn close_and_prefix_reclaim_keep_admitted_reads_alive() { ) .unwrap(); let id = engine.open(0).unwrap(); - engine - .append(id, &[2; 8192], deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(id, &[2; 8192], deadline()).unwrap(); + engine.seal(id, deadline()).unwrap(); let (send, receive) = std::sync::mpsc::channel(); let gate = engine .runtime @@ -236,7 +211,7 @@ fn close_and_prefix_reclaim_keep_admitted_reads_alive() { } #[test] -fn timeout_and_cancel_do_not_commit_queued_appends() { +fn timeout_rolls_back_a_partly_staged_append_after_the_worker_exits() { let root = TestDir::new(); let engine = Engine::new( &root.0, @@ -245,9 +220,10 @@ fn timeout_and_cancel_do_not_commit_queued_appends() { ..options() }, ) - .unwrap(); - let first = engine.open(0).unwrap(); - let second = engine.open(0).unwrap(); + .unwrap() + .with_tail_budget(1024, 2048); + let id = engine.open(0).unwrap(); + engine.append(id, &[1; 512], deadline()).unwrap(); let (send, receive) = std::sync::mpsc::channel(); let gate = engine .runtime @@ -256,22 +232,37 @@ fn timeout_and_cancel_do_not_commit_queued_appends() { .as_ref() .unwrap() .spawn_blocking(move || receive.recv().unwrap()); - let timed = engine - .append( - first, - &[1; 2000], - Instant::now() + Duration::from_millis(100), - ) - .unwrap(); - let canceled = engine.append(second, &[2; 2000], deadline()).unwrap(); - canceled.cancel(); - assert!(matches!(canceled.wait(), Err(Error::Canceled))); - assert!(matches!(timed.wait(), Err(Error::Timeout))); - assert_eq!(engine.usage().buffer_bytes, 4000); + + let short = Instant::now() + Duration::from_millis(50); + assert!(matches!( + engine.append(id, &[2; 3000], short), + Err(Error::Timeout) + )); + assert_eq!(engine.snapshot(id).unwrap().len, 512); + let mut dst = [0; 1024]; + assert_eq!(engine.read_at(id, 0, &mut dst, deadline()).unwrap(), 512); + assert_eq!(&dst[..512], &[1; 512]); + send.send(()).unwrap(); drop(gate); - drop(engine); - assert!(!root.0.join("segments").exists()); + let until = deadline(); + loop { + match engine.seal(id, until) { + Ok(()) => break, + Err(Error::Busy) if Instant::now() < until => std::thread::yield_now(), + result => panic!("rollback did not complete: {result:?}"), + } + } + assert_eq!(engine.usage().disk_bytes, 512); + assert_eq!(engine.usage().write_buffer_bytes, 0); + assert_eq!( + fs::metadata(engine.directory.path.join(format!("{}-0", id.as_raw()))) + .unwrap() + .len(), + 512 + ); + assert_eq!(engine.read_at(id, 0, &mut dst, deadline()).unwrap(), 512); + assert_eq!(&dst[..512], &[1; 512]); } #[test] @@ -290,26 +281,53 @@ fn startup_owns_and_cleans_only_the_reserved_directory() { #[cfg(target_os = "linux")] #[test] -fn enospc_does_not_commit_or_leak_reserved_disk_bytes() { - use std::os::unix::fs::symlink; - +fn enospc_during_a_large_append_preserves_published_data_and_quota() { let root = TestDir::new(); - let engine = Engine::new(&root.0, options()).unwrap(); + let engine = Engine::new( + &root.0, + Options { + segment_size: 1024, + ..options() + }, + ) + .unwrap() + .with_tail_budget(512, 1024); let file = engine.open(0).unwrap(); - let path = engine.directory.path.join(format!("{}-0", file.as_raw())); - symlink("/dev/full", &path).unwrap(); + engine.append(file, &[1; 300], deadline()).unwrap(); + let path = engine.directory.path.join(format!("{}-1", file.as_raw())); + std::os::unix::fs::symlink("/dev/full", &path).unwrap(); + assert!(matches!( - engine.append(file, b"spill", deadline()).unwrap().wait(), + engine.append(file, &[2; 3000], deadline()), Err(Error::Io(error)) if error.kind() == io::ErrorKind::StorageFull )); - assert_eq!(engine.snapshot(file).unwrap().len, 0); - assert_eq!(engine.usage().disk_bytes, 0); + assert_eq!(engine.snapshot(file).unwrap().len, 300); + assert_eq!(engine.usage().disk_bytes, 300); assert!(!path.exists()); - engine - .append(file, b"retry", deadline()) - .unwrap() - .wait() - .unwrap(); + let mut dst = [0; 512]; + assert_eq!(engine.read_at(file, 0, &mut dst, deadline()).unwrap(), 300); + assert_eq!(&dst[..300], &[1; 300]); + engine.close(file).unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 0); +} + +#[cfg(target_os = "linux")] +#[test] +fn seal_reports_disk_full_for_a_previously_acknowledged_buffer() { + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()).unwrap(); + let id = engine.open(0).unwrap(); + let path = engine.directory.path.join(format!("{}-0", id.as_raw())); + std::os::unix::fs::symlink("/dev/full", &path).unwrap(); + engine.append(id, b"spill", deadline()).unwrap(); + assert!(matches!(engine.seal(id, deadline()), Err(Error::Io(error)) + if error.kind() == io::ErrorKind::StorageFull)); + let mut bytes = [0; 5]; + assert_eq!(engine.read_at(id, 0, &mut bytes, deadline()).unwrap(), 5); + assert_eq!(&bytes, b"spill"); + engine.close(id).unwrap(); + assert_eq!(engine.usage().disk_bytes, 0); + assert_eq!(engine.usage().write_buffer_bytes, 0); } #[test] @@ -326,11 +344,7 @@ fn growing_and_consuming_a_file_reuses_a_fixed_quota() { let file = engine.open(0).unwrap(); for index in 0..256 { let data = [index as u8; 4096]; - engine - .append(file, &data, deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(file, &data, deadline()).unwrap(); let offset = index * 4096; assert_eq!( engine @@ -355,14 +369,10 @@ fn runtime_quota_changes_apply_to_subsequent_reservations() { let root = TestDir::new(); let engine = Engine::new(&root.0, options()).unwrap(); let file = engine.open(0).unwrap(); - engine - .append(file, b"row", deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(file, b"row", deadline()).unwrap(); engine.configure(3, 8192); assert!(matches!( - engine.append(file, b"x", deadline()).unwrap().wait(), + engine.append(file, b"x", deadline()), Err(Error::DiskQuota) )); engine.configure(8192, 3); @@ -370,11 +380,7 @@ fn runtime_quota_changes_apply_to_subsequent_reservations() { engine.append(file, b"1234", deadline()), Err(Error::BufferQuota) )); - engine - .append(file, b"abc", deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(file, b"abc", deadline()).unwrap(); assert_eq!(engine.snapshot(file).unwrap().len, 6); } @@ -383,11 +389,7 @@ fn synchronous_reads_borrow_the_destination_and_preserve_the_cursor() { let root = TestDir::new(); let engine = Engine::new(&root.0, options()).unwrap(); let id = engine.open(0).unwrap(); - engine - .append(id, &[5; 8192], deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(id, &[5; 8192], deadline()).unwrap(); engine.reclaim_prefix(id, 4096).unwrap(); let mut dst = [99; 12]; assert_eq!(engine.read_at(id, 4090, &mut dst, deadline()).unwrap(), 12); @@ -422,11 +424,8 @@ fn cached_positioned_reads_respect_prefix_reclamation_and_close() { .unwrap(); let file = engine.open(0).unwrap(); let src = vec![7; 2 * len]; - engine - .append(file, &src, deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(file, &src, deadline()).unwrap(); + engine.seal(file, deadline()).unwrap(); let mut dst = vec![0; len]; engine.read_at(file, 0, &mut dst, deadline()).unwrap(); assert_eq!(engine.usage().cache_bytes, len as u64); @@ -459,11 +458,8 @@ fn limits_open_segments_and_reuses_reclaimed_slots() { .unwrap(); let file = engine.open(0).unwrap(); let bytes = vec![3; MAX_RETAINED_SEGMENT_FILES as usize + 1]; - engine - .append(file, &bytes, deadline()) - .unwrap() - .wait() - .unwrap(); + engine.append(file, &bytes, deadline()).unwrap(); + engine.seal(file, deadline()).unwrap(); assert_eq!( engine.directory.retained_files.used(), MAX_RETAINED_SEGMENT_FILES @@ -486,3 +482,137 @@ fn limits_open_segments_and_reuses_reclaimed_slots() { engine.close(file).unwrap(); assert_eq!(engine.directory.retained_files.used(), 0); } + +#[test] +fn an_idle_file_yields_its_partial_buffer_when_the_instance_is_full() { + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()) + .unwrap() + .with_tail_budget(1024, 1024); + let first = engine.open(0).unwrap(); + let second = engine.open(0).unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 0); + engine.append(first, &[7; 256], deadline()).unwrap(); + engine.append(second, &[9; 256], deadline()).unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 1024); + let path = engine.directory.path.join(format!("{}-0", first.as_raw())); + assert_eq!(fs::metadata(path).unwrap().len(), 256); + let mut dst = [0; 256]; + assert_eq!(engine.read_at(first, 0, &mut dst, deadline()).unwrap(), 256); + assert_eq!(dst, [7; 256]); + assert_eq!( + engine.read_at(second, 0, &mut dst, deadline()).unwrap(), + 256 + ); + assert_eq!(dst, [9; 256]); + engine.close(first).unwrap(); + engine.close(second).unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 0); + assert_eq!(engine.usage().disk_bytes, 0); +} + +#[test] +fn one_append_larger_than_the_instance_budget_uses_the_same_buffers() { + let root = TestDir::new(); + let engine = Engine::new(&root.0, options()) + .unwrap() + .with_tail_budget(1024, 2048); + let id = engine.open(0).unwrap(); + let data: Vec<_> = (0..8600).map(|n| (n % 251) as u8).collect(); + assert_eq!(engine.append(id, &data, deadline()).unwrap(), data.len()); + assert_eq!(engine.snapshot(id).unwrap().len, data.len() as u64); + assert!(engine.usage().write_buffer_bytes <= 2048); + let mut dst = vec![0; data.len()]; + assert_eq!( + engine.read_at(id, 0, &mut dst, deadline()).unwrap(), + data.len() + ); + assert_eq!(dst, data); + engine.seal(id, deadline()).unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 0); +} + +#[test] +fn concurrent_writers_share_a_pool_smaller_than_their_combined_appends() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + disk_limit: 128 * 1024, + ..options() + }, + ) + .unwrap() + .with_tail_budget(1024, 4096); + let start = std::sync::Barrier::new(8); + std::thread::scope(|scope| { + let handles: Vec<_> = (1..=8) + .map(|value| { + let engine = &engine; + let start = &start; + scope.spawn(move || { + let file = engine.open(0).unwrap(); + start.wait(); + let data = [value; 5600]; + assert_eq!(engine.append(file, &data, deadline()).unwrap(), data.len()); + let mut dst = [0; 5600]; + assert_eq!( + engine.read_at(file, 0, &mut dst, deadline()).unwrap(), + data.len() + ); + assert_eq!(dst, data); + assert!(engine.usage().write_buffer_bytes <= 4096); + engine.close(file).unwrap(); + }) + }) + .collect(); + for handle in handles { + handle.join().unwrap(); + } + }); + engine.shutdown().unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 0); + assert_eq!(engine.usage().disk_bytes, 0); +} + +#[test] +fn shutdown_wakes_a_writer_waiting_on_the_full_pool() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + workers: 1, + ..options() + }, + ) + .unwrap() + .with_tail_budget(1024, 1024); + let occupied = engine.open(0).unwrap(); + let waiting = engine.open(0).unwrap(); + engine.append(occupied, &[1; 1024], deadline()).unwrap(); + let (send, receive) = std::sync::mpsc::channel(); + let gate = engine + .runtime + .read() + .unwrap() + .as_ref() + .unwrap() + .spawn_blocking(move || receive.recv().unwrap()); + std::thread::scope(|scope| { + let writer = scope.spawn(|| engine.append(waiting, &[2; 512], deadline())); + let file = engine.file(waiting).unwrap(); + let until = deadline(); + while !file.state.lock().unwrap().appending { + assert!(Instant::now() < until); + std::thread::yield_now(); + } + let shutdown = scope.spawn(|| engine.shutdown()); + let result = writer.join(); + send.send(()).unwrap(); + drop(gate); + assert!(matches!(result.unwrap(), Err(Error::Closed))); + shutdown.join().unwrap().unwrap(); + }); + assert_eq!(engine.usage().write_buffer_bytes, 0); + assert_eq!(engine.usage().disk_bytes, 0); +} diff --git a/src/sql/engine/basic/ob_chunk_datum_store.cpp b/src/sql/engine/basic/ob_chunk_datum_store.cpp index 32c8d2d0ce..10b2c8804f 100644 --- a/src/sql/engine/basic/ob_chunk_datum_store.cpp +++ b/src/sql/engine/basic/ob_chunk_datum_store.cpp @@ -22,6 +22,8 @@ #include "sql/engine/basic/ob_chunk_row_store.h" #include "sql/engine/ob_exec_context.h" +#include + namespace oceanbase { using namespace common; @@ -29,6 +31,13 @@ using namespace common; namespace sql { +namespace +{ +constexpr int64_t WRITE_BATCH_CAPACITY = 1L << 20; +constexpr int64_t MAX_WRITE_BATCHES = (4L << 20) / WRITE_BATCH_CAPACITY; +std::atomic active_write_batches{0}; +} + int ObChunkDatumStore::BlockBuffer::init(char *buf, const int64_t buf_size) { return ObChunkStoreUtil::init_buffer(*this, buf, buf_size); @@ -495,6 +504,7 @@ int ObChunkDatumStore::init(int64_t mem_limit, void ObChunkDatumStore::reset() { int ret = OB_SUCCESS; + free_write_batch(); if (is_file_open()) { aio_write_handle_.reset(); if (OB_FAIL(data_plane::tmp_file_remove(io_.fd_))) { @@ -1642,7 +1652,60 @@ int ObChunkDatumStore::alloc_dir_id() return ObChunkStoreUtil::ensure_dir_id(io_.dir_id_); } +void ObChunkDatumStore::start_write_batch() +{ + if (nullptr == write_batch_) { + if (active_write_batches.fetch_add(1, std::memory_order_relaxed) < MAX_WRITE_BATCHES) { + write_batch_ = static_cast(allocator_->alloc(WRITE_BATCH_CAPACITY)); + } + if (nullptr == write_batch_) { + active_write_batches.fetch_sub(1, std::memory_order_relaxed); + } + } +} + +void ObChunkDatumStore::free_write_batch() +{ + if (nullptr != write_batch_) { + allocator_->free(write_batch_); + write_batch_ = nullptr; + write_batch_size_ = 0; + active_write_batches.fetch_sub(1, std::memory_order_relaxed); + } +} + +int ObChunkDatumStore::flush_write_batch() +{ + int ret = OB_SUCCESS; + if (write_batch_size_ > 0 && OB_SUCC(ret = submit_file_write(write_batch_, write_batch_size_))) { + write_batch_size_ = 0; + } + return ret; +} + +int ObChunkDatumStore::finish_write_batch() +{ + const int ret = flush_write_batch(); + free_write_batch(); + return ret; +} + int ObChunkDatumStore::write_file(void *buf, int64_t size) +{ + int ret = OB_SUCCESS; + if (nullptr == write_batch_ || size <= 0 || nullptr == buf) { + ret = submit_file_write(buf, size); + } else if (size > WRITE_BATCH_CAPACITY - write_batch_size_ && OB_FAIL(flush_write_batch())) { + } else if (size >= WRITE_BATCH_CAPACITY) { + ret = submit_file_write(buf, size); + } else { + MEMCPY(write_batch_ + write_batch_size_, buf, size); + write_batch_size_ += size; + } + return ret; +} + +int ObChunkDatumStore::submit_file_write(void *buf, int64_t size) { int ret = OB_SUCCESS; int64_t timeout_ms = 0; diff --git a/src/sql/engine/basic/ob_chunk_datum_store.h b/src/sql/engine/basic/ob_chunk_datum_store.h index 97b1add5f1..cbc62d8e00 100644 --- a/src/sql/engine/basic/ob_chunk_datum_store.h +++ b/src/sql/engine/basic/ob_chunk_datum_store.h @@ -929,6 +929,8 @@ class ObChunkDatumStore void set_allocator(common::ObIAllocator &alloc) { allocator_ = &alloc; } + void start_write_batch(); + int finish_write_batch(); void reset(); /// begin iterator @@ -1082,6 +1084,9 @@ class ObChunkDatumStore inline int dump_one_block(BlockBuffer *item); int write_file(void *buf, int64_t size); + int submit_file_write(void *buf, int64_t size); + int flush_write_batch(); + void free_write_batch(); int aio_read_file(void *buf, const int64_t size, const int64_t offset, @@ -1142,6 +1147,8 @@ class ObChunkDatumStore ObSqlMemoryCallback *callback_; BatchCtx *batch_ctx_; Block *tmp_dump_blk_; + char *write_batch_ = nullptr; + int64_t write_batch_size_ = 0; DISALLOW_COPY_AND_ASSIGN(ObChunkDatumStore); }; diff --git a/src/sql/engine/sort/ob_sort_op_impl.cpp b/src/sql/engine/sort/ob_sort_op_impl.cpp index 3f19c7d014..34bd7cce23 100644 --- a/src/sql/engine/sort/ob_sort_op_impl.cpp +++ b/src/sql/engine/sort/ob_sort_op_impl.cpp @@ -956,6 +956,9 @@ int ObSortOpImpl::build_chunk(const int64_t level, Input &input, int64_t extra_s chunk->datum_store_.set_allocator(mem_context_->get_malloc_allocator()); chunk->datum_store_.set_callback(&sql_mem_processor_); chunk->datum_store_.set_io_event_observer(io_event_observer_); + if (!use_compact_store()) { + chunk->datum_store_.datum_store_.start_write_batch(); + } int64_t total_size = 0; while (OB_SUCC(ret)) { if (use_heap_sort_ && !is_fetch_with_ties_ && stored_row_cnt >= topn_cnt_) { @@ -979,6 +982,7 @@ int ObSortOpImpl::build_chunk(const int64_t level, Input &input, int64_t extra_s // Must force dump first, then finish dump is effective if (OB_FAIL(ret)) { } else if (OB_FAIL(chunk->datum_store_.dump(false, true))) { + } else if (OB_FAIL(chunk->datum_store_.datum_store_.finish_write_batch())) { } else if (OB_FAIL(chunk->datum_store_.finish_add_row(true/*+ need dump */))) { } else { const int64_t sort_io_time = ObTimeUtility::fast_current_time() - curr_time; diff --git a/src/sql/engine/window_function/ob_window_function_op.cpp b/src/sql/engine/window_function/ob_window_function_op.cpp index f2126ef5b5..643c70c176 100644 --- a/src/sql/engine/window_function/ob_window_function_op.cpp +++ b/src/sql/engine/window_function/ob_window_function_op.cpp @@ -3528,6 +3528,36 @@ int ObWindowFunctionOp::output_batch_rows(const int64_t output_row_cnt) int ObWindowFunctionOp::inner_get_next_batch(const int64_t max_row_cnt) { int ret = OB_SUCCESS; + if (!MY_SPEC.single_part_parallel_ && !MY_SPEC.range_dist_parallel_ + && ObWindowFunctionSpec::NORMAL == MY_SPEC.get_role_type() + && MY_SPEC.wf_infos_.count() == 1) { + const WinFuncInfo &info = MY_SPEC.wf_infos_.at(0); + if (T_WIN_FUN_ROW_NUMBER == info.func_type_ && info.partition_exprs_.empty() + && info.upper_.is_unbounded_ && info.upper_.is_preceding_ + && info.lower_.is_unbounded_ && !info.lower_.is_preceding_ + && info.expr_->is_batch_result()) { + // The next row number depends only on the count of preceding rows. + clear_evaluated_flag(); + const ObBatchRows *child_rows = nullptr; + if (OB_SUCC(ret = child_->get_next_batch(max_row_cnt, child_rows))) { + brs_.size_ = child_rows->size_; + brs_.end_ = child_rows->end_; + brs_.all_rows_active_ = child_rows->all_rows_active_; + brs_.skip_->deep_copy(*child_rows->skip_, brs_.size_); + ObEvalCtx::BatchInfoScopeGuard guard(eval_ctx_); + guard.set_batch_size(brs_.size_); + for (int64_t i = 0; i < brs_.size_; ++i) { + if (!brs_.skip_->at(i)) { + guard.set_batch_idx(i); + info.expr_->locate_datum_for_write(eval_ctx_).set_int(++last_output_row_idx_ + 1); + } + } + info.expr_->get_eval_info(eval_ctx_).cnt_ = brs_.size_; + info.expr_->set_evaluated_projected(eval_ctx_); + } + return ret; + } + } do { switch (stat_) { case ProcessStatus::PARTIAL: { diff --git a/src/storage/tmp_file/tmp_file_service.cpp b/src/storage/tmp_file/tmp_file_service.cpp index 764b8da733..db00d49c47 100644 --- a/src/storage/tmp_file/tmp_file_service.cpp +++ b/src/storage/tmp_file/tmp_file_service.cpp @@ -184,7 +184,7 @@ class ObTmpFileAccess { int ret = OB_SUCCESS; const Service *service = tmp_file_service(); - if (!io.is_valid() || offset < -1) { + if (!io.is_valid()) { ret = OB_INVALID_ARGUMENT; } else if (OB_ISNULL(service)) { ret = OB_NOT_INIT; @@ -350,7 +350,7 @@ int tmp_file_truncate(const int64_t fd, const int64_t offset) int tmp_file_seal(const int64_t fd) { const auto *service = tmp_file_service(); - return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->seal(fd)); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->seal(fd, DEFAULT_IO_WAIT_TIME_MS)); } int tmp_file_get_size(const int64_t fd, int64_t &size) From 5530ecc8e71ae809e2a7701eaca917232fcd3334 Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 16:59:05 +0800 Subject: [PATCH 6/7] fix(storage): release flushed buffers before waking waiters --- rust/tmp-file/src/lib.rs | 2 ++ rust/tmp-file/src/tests.rs | 35 +++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/rust/tmp-file/src/lib.rs b/rust/tmp-file/src/lib.rs index a04c331742..0bada2338b 100644 --- a/rust/tmp-file/src/lib.rs +++ b/rust/tmp-file/src/lib.rs @@ -870,6 +870,8 @@ impl Engine { }; let visible = (old.start < state.end && old.end() > state.prefix).then_some(old); state.flush = Some(Flush::Failed(visible, error)); + } else { + drop(old); } if let Some(quota) = quota { quota.notify(); diff --git a/rust/tmp-file/src/tests.rs b/rust/tmp-file/src/tests.rs index b0c7cb205f..bedf845745 100644 --- a/rust/tmp-file/src/tests.rs +++ b/rust/tmp-file/src/tests.rs @@ -53,6 +53,28 @@ fn deadline() -> Instant { Instant::now() + Duration::from_secs(10) } +fn assert_closed_files_are_reclaimed(engine: &Engine) { + assert!(engine.files().is_empty()); + // An admitted I/O job may still own a closed file as it exits. + let until = deadline(); + loop { + let usage = engine.usage(); + if usage.disk_bytes == 0 + && usage.write_buffer_bytes == 0 + && usage.cache_bytes == 0 + && engine.directory.retained_files.used() == 0 + { + break; + } + assert!( + Instant::now() < until, + "closed files still hold resources: {usage:?}" + ); + std::thread::sleep(Duration::from_millis(1)); + } + assert_eq!(fs::read_dir(&engine.directory.path).unwrap().count(), 0); +} + #[test] fn seal_and_reclaim_preserve_logical_offsets() { let root = TestDir::new(); @@ -308,7 +330,7 @@ fn enospc_during_a_large_append_preserves_published_data_and_quota() { assert_eq!(engine.read_at(file, 0, &mut dst, deadline()).unwrap(), 300); assert_eq!(&dst[..300], &[1; 300]); engine.close(file).unwrap(); - assert_eq!(engine.usage().write_buffer_bytes, 0); + assert_closed_files_are_reclaimed(&engine); } #[cfg(target_os = "linux")] @@ -326,8 +348,7 @@ fn seal_reports_disk_full_for_a_previously_acknowledged_buffer() { assert_eq!(engine.read_at(id, 0, &mut bytes, deadline()).unwrap(), 5); assert_eq!(&bytes, b"spill"); engine.close(id).unwrap(); - assert_eq!(engine.usage().disk_bytes, 0); - assert_eq!(engine.usage().write_buffer_bytes, 0); + assert_closed_files_are_reclaimed(&engine); } #[test] @@ -441,8 +462,7 @@ fn cached_positioned_reads_respect_prefix_reclamation_and_close() { .unwrap(); assert_eq!(engine.usage().cache_bytes, len as u64); engine.close(file).unwrap(); - assert_eq!(engine.usage().cache_bytes, 0); - assert_eq!(engine.usage().disk_bytes, 0); + assert_closed_files_are_reclaimed(&engine); } #[test] @@ -480,7 +500,7 @@ fn limits_open_segments_and_reuses_reclaimed_slots() { assert_eq!(last, [3]); assert_eq!(engine.directory.retained_files.used(), 1); engine.close(file).unwrap(); - assert_eq!(engine.directory.retained_files.used(), 0); + assert_closed_files_are_reclaimed(&engine); } #[test] @@ -507,8 +527,7 @@ fn an_idle_file_yields_its_partial_buffer_when_the_instance_is_full() { assert_eq!(dst, [9; 256]); engine.close(first).unwrap(); engine.close(second).unwrap(); - assert_eq!(engine.usage().write_buffer_bytes, 0); - assert_eq!(engine.usage().disk_bytes, 0); + assert_closed_files_are_reclaimed(&engine); } #[test] From 75d1cdea40ad74c099f49f2b560c71c3c03b751b Mon Sep 17 00:00:00 2001 From: "nijia.nj" Date: Tue, 1 Dec 2026 18:12:29 +0800 Subject: [PATCH 7/7] fix(storage): preserve wide spills and the query deadline --- rust/tmp-file/src/bridge.rs | 59 ++++++------------- rust/tmp-file/src/lib.rs | 30 +++++++--- rust/tmp-file/src/tests.rs | 53 ++++++++++++++++- .../api/data_plane/tmp_file/ob_tmp_file.h | 2 +- src/sql/engine/basic/ob_temp_block_store.cpp | 6 +- src/storage/tmp_file/tmp_file_service.cpp | 14 +++-- .../cases/r/tmp_file_wide_spill.result | 11 ++++ .../cases/t/tmp_file_wide_spill.test | 28 +++++++++ 8 files changed, 141 insertions(+), 62 deletions(-) create mode 100644 tests/mysqltest/cases/r/tmp_file_wide_spill.result create mode 100644 tests/mysqltest/cases/t/tmp_file_wide_spill.test diff --git a/rust/tmp-file/src/bridge.rs b/rust/tmp-file/src/bridge.rs index 75392197ea..d6e34eedf1 100644 --- a/rust/tmp-file/src/bridge.rs +++ b/rust/tmp-file/src/bridge.rs @@ -89,16 +89,8 @@ mod ffi { self: &Service, id: i64, offset: i64, - size: usize, - timeout_ms: u64, - status: &mut Status, - ) -> Box; - - fn read_at( - self: &Service, - id: i64, - offset: u64, dst: &mut [u8], + prefetch: bool, timeout_ms: u64, status: &mut Status, ) -> Box; @@ -268,22 +260,31 @@ impl Service { ) } - fn read_at( + fn read( &self, id: i64, - offset: u64, + offset: i64, dst: &mut [u8], + prefetch: bool, timeout_ms: u64, status: &mut Status, ) -> Box { - let result = self.engine().read_at( - FileId::from_raw(id as u64), - offset, - dst, - deadline(timeout_ms), - ); + let id = FileId::from_raw(id as u64); + let offset = u64::try_from(offset).ok(); + let deadline = deadline(timeout_ms); + let engine = self.engine(); + if prefetch { + match engine.read(id, offset, dst.len(), deadline) { + // Use the caller's buffer if prefetch would exceed the shared budget. + Err(Error::BufferQuota) => (), + result => return IoRequest::submitted(result.map(Pending::Read), status), + } + } let mut done = 0; - *status = result.map(|len| done = len).into(); + *status = engine + .read_into(id, offset, dst, deadline) + .map(|len| done = len) + .into(); Box::new(IoRequest { pending: None, buffer: None, @@ -291,28 +292,6 @@ impl Service { status: *status, }) } - - fn read( - &self, - id: i64, - offset: i64, - size: usize, - timeout_ms: u64, - status: &mut Status, - ) -> Box { - let offset = u64::try_from(offset).ok(); - IoRequest::submitted( - self.engine() - .read( - FileId::from_raw(id as u64), - offset, - size, - deadline(timeout_ms), - ) - .map(Pending::Read), - status, - ) - } } fn deadline(timeout_ms: u64) -> Instant { diff --git a/rust/tmp-file/src/lib.rs b/rust/tmp-file/src/lib.rs index 0bada2338b..46408a8dbb 100644 --- a/rust/tmp-file/src/lib.rs +++ b/rust/tmp-file/src/lib.rs @@ -908,9 +908,6 @@ impl Engine { let runtime = self.active()?; let runtime = runtime.as_ref().unwrap(); let _slot = self.request_slot(deadline)?; - if bytes.len() as u64 > self.buffer.limit.load(Ordering::Acquire) { - return Err(Error::BufferQuota); - } let file = self.file(id)?; let mut state = file.state.lock().unwrap(); if file.closed.load(Ordering::Acquire) { @@ -1064,6 +1061,16 @@ impl Engine { offset: u64, dst: &mut [u8], deadline: Instant, + ) -> Result { + self.read_into(id, Some(offset), dst, deadline) + } + + fn read_into( + &self, + id: FileId, + offset: Option, + dst: &mut [u8], + deadline: Instant, ) -> Result { let _runtime = self.active()?; let _slot = self.request_slot(deadline)?; @@ -1079,12 +1086,14 @@ impl Engine { if file.closed.load(Ordering::Acquire) { return Err(Error::Closed); } - let requested = (state.end.saturating_sub(offset)).min(dst.len() as u64) as usize; - let cacheable = offset >= state.prefix - && offset + requested as u64 <= state.memory_start(state.end) + let start = offset.unwrap_or(state.cursor); + let requested = (state.end.saturating_sub(start)).min(dst.len() as u64) as usize; + let cacheable = offset.is_some() + && start >= state.prefix + && start + requested as u64 <= state.memory_start(state.end) && (MIN_CACHED_READ..=MAX_CACHED_READ).contains(&requested); if cacheable { - if let Some(data) = state.lookup_read(offset, requested) { + if let Some(data) = state.lookup_read(start, requested) { drop(state); dst[..requested].copy_from_slice(data.as_ref().as_ref()); check_deadline()?; @@ -1092,8 +1101,11 @@ impl Engine { return Ok(requested); } } - let plan = ReadPlan::new(&state, offset, dst.len(), self.segment_size)?; + let plan = ReadPlan::new(&state, start, dst.len(), self.segment_size)?; plan.copy_tail(&state, dst); + if offset.is_none() { + state.cursor = plan.end; + } drop(state); let len = plan.len(); plan.read_into(&mut dst[..len], check_deadline)?; @@ -1101,7 +1113,7 @@ impl Engine { file.state .lock() .unwrap() - .cache_read(offset, &dst[..len], &self.read_cache); + .cache_read(start, &dst[..len], &self.read_cache); } file.record_read(len); Ok(len) diff --git a/rust/tmp-file/src/tests.rs b/rust/tmp-file/src/tests.rs index bedf845745..855a763234 100644 --- a/rust/tmp-file/src/tests.rs +++ b/rust/tmp-file/src/tests.rs @@ -397,12 +397,25 @@ fn runtime_quota_changes_apply_to_subsequent_reservations() { Err(Error::DiskQuota) )); engine.configure(8192, 3); + engine.append(file, b"abc", deadline()).unwrap(); + assert_eq!(engine.snapshot(file).unwrap().len, 6); assert!(matches!( - engine.append(file, b"1234", deadline()), + engine.read(file, None, 6, deadline()), Err(Error::BufferQuota) )); - engine.append(file, b"abc", deadline()).unwrap(); - assert_eq!(engine.snapshot(file).unwrap().len, 6); + let mut bytes = [0; 6]; + assert_eq!( + engine + .read_into(file, None, &mut bytes, deadline()) + .unwrap(), + 6 + ); + assert_eq!(&bytes, b"rowabc"); + assert!(matches!( + engine.read(file, None, 1, deadline()), + Err(Error::End) + )); + assert_eq!(engine.usage().buffer_bytes, 0); } #[test] @@ -536,6 +549,7 @@ fn one_append_larger_than_the_instance_budget_uses_the_same_buffers() { let engine = Engine::new(&root.0, options()) .unwrap() .with_tail_budget(1024, 2048); + engine.configure(options().disk_limit, 1024); let id = engine.open(0).unwrap(); let data: Vec<_> = (0..8600).map(|n| (n % 251) as u8).collect(); assert_eq!(engine.append(id, &data, deadline()).unwrap(), data.len()); @@ -551,6 +565,39 @@ fn one_append_larger_than_the_instance_budget_uses_the_same_buffers() { assert_eq!(engine.usage().write_buffer_bytes, 0); } +#[test] +fn seal_times_out_while_writeback_is_queued() { + let root = TestDir::new(); + let engine = Engine::new( + &root.0, + Options { + workers: 1, + ..options() + }, + ) + .unwrap(); + let file = engine.open(0).unwrap(); + engine.append(file, b"spill", deadline()).unwrap(); + let (send, receive) = std::sync::mpsc::channel(); + let gate = engine + .runtime + .read() + .unwrap() + .as_ref() + .unwrap() + .spawn_blocking(move || receive.recv()); + + let result = engine.seal(file, Instant::now() + Duration::from_millis(30)); + send.send(()).unwrap(); + drop(gate); + assert!(matches!(result, Err(Error::Timeout))); + engine.seal(file, deadline()).unwrap(); + assert_eq!(engine.usage().write_buffer_bytes, 0); + let mut bytes = [0; 5]; + assert_eq!(engine.read_at(file, 0, &mut bytes, deadline()).unwrap(), 5); + assert_eq!(&bytes, b"spill"); +} + #[test] fn concurrent_writers_share_a_pool_smaller_than_their_combined_appends() { let root = TestDir::new(); diff --git a/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h b/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h index c4124a5adb..9a9881f838 100644 --- a/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h +++ b/src/data_plane/api/data_plane/tmp_file/ob_tmp_file.h @@ -86,7 +86,7 @@ int tmp_file_pread(const ObTmpFileIOInfo &io_info, int tmp_file_aio_write(const ObTmpFileIOInfo &io_info, ObTmpFileIOHandle &io_handle); int tmp_file_write(const ObTmpFileIOInfo &io_info); int tmp_file_truncate(int64_t fd, int64_t offset); -int tmp_file_seal(int64_t fd); +int tmp_file_seal(int64_t fd, int64_t timeout_ms); int tmp_file_get_size(int64_t fd, int64_t &file_size); } // namespace data_plane diff --git a/src/sql/engine/basic/ob_temp_block_store.cpp b/src/sql/engine/basic/ob_temp_block_store.cpp index 153b5a58d4..aa40809f16 100644 --- a/src/sql/engine/basic/ob_temp_block_store.cpp +++ b/src/sql/engine/basic/ob_temp_block_store.cpp @@ -175,9 +175,9 @@ int ObTempBlockStore::finish_add_row(bool need_dump /*true*/) } else { int64_t timeout_ms = 0; const uint64_t begin_io_dump_time = rdtsc(); - if (OB_FAIL(get_timeout(timeout_ms))) { - } else if (write_io_handle_.is_valid() && OB_FAIL(write_io_handle_.wait())) { - } else if (OB_FAIL(data_plane::tmp_file_seal(io_.fd_))) { + if (write_io_handle_.is_valid() && OB_FAIL(write_io_handle_.wait())) { + } else if (OB_FAIL(get_timeout(timeout_ms))) { + } else if (OB_FAIL(data_plane::tmp_file_seal(io_.fd_, timeout_ms))) { } if (OB_LIKELY(nullptr != io_observer_)) { io_observer_->on_write_io(rdtsc() - begin_io_dump_time); diff --git a/src/storage/tmp_file/tmp_file_service.cpp b/src/storage/tmp_file/tmp_file_service.cpp index db00d49c47..a9687f72b0 100644 --- a/src/storage/tmp_file/tmp_file_service.cpp +++ b/src/storage/tmp_file/tmp_file_service.cpp @@ -198,11 +198,10 @@ class ObTmpFileAccess if (append) { return service->append(io.fd_, rust::Slice( reinterpret_cast(io.buf_), io.size_), io.io_timeout_ms_, status); - } else if (Operation::PREAD == operation) { - return service->read_at(io.fd_, offset, rust::Slice( - reinterpret_cast(io.buf_), io.size_), io.io_timeout_ms_, status); } else { - return service->read(io.fd_, offset, io.size_, io.io_timeout_ms_, status); + return service->read(io.fd_, offset, rust::Slice( + reinterpret_cast(io.buf_), io.size_), Operation::READ == operation, + io.io_timeout_ms_, status); } }(); if (OB_SUCC(ret = log_tmp_file_status(status, append ? "append" : "read", io.fd_))) { @@ -347,10 +346,13 @@ int tmp_file_truncate(const int64_t fd, const int64_t offset) return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->reclaim(fd, offset)); } -int tmp_file_seal(const int64_t fd) +int tmp_file_seal(const int64_t fd, const int64_t timeout_ms) { + if (timeout_ms < 0) { + return OB_INVALID_ARGUMENT; + } const auto *service = tmp_file_service(); - return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->seal(fd, DEFAULT_IO_WAIT_TIME_MS)); + return OB_ISNULL(service) ? OB_NOT_INIT : convert_tmp_file_status(service->seal(fd, timeout_ms)); } int tmp_file_get_size(const int64_t fd, int64_t &size) diff --git a/tests/mysqltest/cases/r/tmp_file_wide_spill.result b/tests/mysqltest/cases/r/tmp_file_wide_spill.result new file mode 100644 index 0000000000..734cd70e3c --- /dev/null +++ b/tests/mysqltest/cases/r/tmp_file_wide_spill.result @@ -0,0 +1,11 @@ +SELECT id, LENGTH(sort_key) AS key_bytes, next_id +FROM ( +SELECT id, REPEAT(CHAR(64 + id), 47185920) AS sort_key, +LEAD(id) OVER (ORDER BY REPEAT(CHAR(64 + id), 47185920)) AS next_id +FROM tmp_wide_spill_ids +) ordered_rows +ORDER BY id; +id key_bytes next_id +1 47185920 2 +2 47185920 3 +3 47185920 NULL diff --git a/tests/mysqltest/cases/t/tmp_file_wide_spill.test b/tests/mysqltest/cases/t/tmp_file_wide_spill.test new file mode 100644 index 0000000000..eab19f4cb5 --- /dev/null +++ b/tests/mysqltest/cases/t/tmp_file_wide_spill.test @@ -0,0 +1,28 @@ +--disable_query_log +CREATE TABLE tmp_wide_spill_ids (id INT PRIMARY KEY); +INSERT INTO tmp_wide_spill_ids VALUES (1), (2), (3); +SET GLOBAL max_allowed_packet = 134217728; +ALTER SYSTEM SET workarea_size_policy = 'MANUAL'; +ALTER SYSTEM SET _sort_area_size = '2M'; +ALTER SYSTEM SET _temporary_file_io_area_size = 0; +connect (wide_spill,$OBMYSQL_MS0,$OBMYSQL_USR,$OBMYSQL_PWD,test,$OBMYSQL_PORT); +connection wide_spill; +SET SESSION ob_query_timeout = 120000000; +--enable_query_log + +SELECT id, LENGTH(sort_key) AS key_bytes, next_id +FROM ( + SELECT id, REPEAT(CHAR(64 + id), 47185920) AS sort_key, + LEAD(id) OVER (ORDER BY REPEAT(CHAR(64 + id), 47185920)) AS next_id + FROM tmp_wide_spill_ids +) ordered_rows +ORDER BY id; + +--disable_query_log +disconnect wide_spill; +connection default; +ALTER SYSTEM SET _temporary_file_io_area_size = 1; +ALTER SYSTEM SET _sort_area_size = '32M'; +ALTER SYSTEM SET workarea_size_policy = 'AUTO'; +SET GLOBAL max_allowed_packet = DEFAULT; +DROP TABLE tmp_wide_spill_ids;