From 79cd226d930e687acd48d9332f3840457a96653a Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Mon, 27 Nov 2023 11:04:19 +0800 Subject: [PATCH] refactor(absl): Use the abseil in thirdparty instead of the internal copied one (#1694) For historical reasons, we copied some Abeil-cpp code into Pegasus to use features like string_view, make_unique, apply and etc. The Abeil library has been introduced into Pegasus as a thirdparty in previous patches, so we can use it directly. This patch has the following changes: - Remove the abseil files copied to Pegasus including: - src/utils/absl/base/internal/invoke.h - src/utils/absl/utility/utility.h - src/utils/memutil.h - src/utils/smart_pointers.h - src/utils/string_view.cpp - src/utils/string_view.h - src/utils/test/memutil_test.cpp - src/utils/test/smart_pointers_test.cpp - src/utils/test/string_view_test.cpp - Update license related files(.licenserc.yaml and LICENSE) - Use std::make_unique explicitly. - Add a function to_string_view(), then dsn::blob is possible to transfer to absl::string_view. --- .licenserc.yaml | 10 - LICENSE | 26 -- src/base/pegasus_utils.h | 6 +- src/base/pegasus_value_schema.h | 18 +- src/base/test/value_manager_test.cpp | 4 +- src/base/test/value_schema_test.cpp | 4 +- src/base/value_field.h | 4 +- src/base/value_schema_manager.cpp | 3 +- src/base/value_schema_manager.h | 4 +- src/base/value_schema_v0.cpp | 7 +- src/base/value_schema_v0.h | 6 +- src/base/value_schema_v1.cpp | 9 +- src/base/value_schema_v1.h | 8 +- src/base/value_schema_v2.cpp | 9 +- src/base/value_schema_v2.h | 8 +- src/block_service/local/local_service.cpp | 4 +- src/client/replication_ddl_client.cpp | 2 +- src/client/replication_ddl_client.h | 6 +- src/client_lib/pegasus_client_impl.cpp | 8 +- src/common/fs_manager.cpp | 14 +- src/common/fs_manager.h | 12 +- src/common/replication_common.cpp | 1 + .../serialization_helper/thrift_helper.h | 6 +- src/http/http_client.cpp | 6 +- src/http/http_client.h | 8 +- src/http/uri_decoder.cpp | 6 +- src/http/uri_decoder.h | 4 +- src/meta/app_env_validator.cpp | 1 + .../duplication/meta_duplication_service.cpp | 17 +- src/meta/load_balance_policy.cpp | 5 +- src/meta/meta_bulk_load_ingestion_context.cpp | 17 +- src/meta/meta_bulk_load_service.cpp | 21 +- src/meta/meta_server_failure_detector.cpp | 4 +- src/nfs/nfs_server_impl.cpp | 1 + src/redis_protocol/proxy_lib/redis_parser.cpp | 20 +- src/replica/bulk_load/replica_bulk_loader.cpp | 4 +- src/replica/disk_cleaner.cpp | 4 +- .../duplication/duplication_pipeline.cpp | 5 +- .../duplication/load_from_private_log.cpp | 19 +- src/replica/duplication/mutation_batch.cpp | 7 +- src/replica/duplication/mutation_duplicator.h | 6 +- src/replica/duplication/replica_follower.cpp | 9 +- .../duplication/test/duplication_test_base.h | 2 +- src/replica/log_file_stream.h | 2 +- src/replica/mutation_log_replay.cpp | 4 +- src/replica/mutation_log_utils.cpp | 7 +- src/replica/mutation_log_utils.h | 4 +- src/replica/replica.cpp | 1 - src/replica/replica_base.h | 4 +- src/replica/replica_check.cpp | 6 +- src/replica/replica_config.cpp | 4 +- src/replica/replica_disk_migrator.cpp | 8 +- src/replica/replica_stub.cpp | 14 +- src/replica/replication_app_base.cpp | 5 +- src/replica/split/replica_split_manager.cpp | 28 +- src/replica/test/replica_test_base.h | 1 - src/runtime/pipeline.h | 2 +- .../ranger/ranger_resource_policy_manager.cpp | 3 +- src/runtime/rpc/rpc_address.cpp | 4 +- src/runtime/rpc/thrift_message_parser.cpp | 6 +- src/runtime/security/sasl_client_wrapper.cpp | 8 +- src/runtime/security/sasl_server_wrapper.cpp | 8 +- src/runtime/security/sasl_wrapper.cpp | 4 +- src/runtime/task/task.h | 2 +- src/server/compaction_filter_rule.cpp | 26 +- src/server/compaction_filter_rule.h | 26 +- src/server/compaction_operation.cpp | 19 +- src/server/compaction_operation.h | 27 +- src/server/hotkey_collector.cpp | 17 +- src/server/hotkey_collector.h | 4 +- src/server/hotspot_partition_calculator.cpp | 4 +- src/server/key_ttl_compaction_filter.h | 4 +- src/server/pegasus_mutation_duplicator.cpp | 14 +- src/server/pegasus_mutation_duplicator.h | 6 +- src/server/pegasus_server_impl.cpp | 5 +- src/server/pegasus_write_service_impl.h | 56 ++- src/server/rocksdb_wrapper.cpp | 23 +- src/server/rocksdb_wrapper.h | 14 +- src/server/test/hotkey_collector_test.cpp | 3 +- .../test/pegasus_mutation_duplicator_test.cpp | 1 + .../test/pegasus_write_service_impl_test.cpp | 14 +- src/server/test/rocksdb_wrapper_test.cpp | 38 +- src/shell/command_helper.h | 4 +- src/shell/command_output.h | 1 - src/shell/commands.h | 2 +- src/utils/absl/base/internal/invoke.h | 218 --------- src/utils/absl/utility/utility.h | 207 -------- src/utils/binary_writer.h | 1 + src/utils/blob.h | 7 +- src/utils/endians.h | 6 +- src/utils/errors.h | 9 +- src/utils/fail_point.cpp | 10 +- src/utils/fail_point.h | 6 +- src/utils/fail_point_impl.h | 10 +- src/utils/filesystem.cpp | 14 +- src/utils/join_point.h | 3 +- src/utils/memutil.h | 25 - src/utils/metrics.cpp | 1 + src/utils/metrics.h | 14 +- src/utils/simple_logger.cpp | 4 +- src/utils/smart_pointers.h | 132 ------ src/utils/string_conv.h | 18 +- src/utils/string_view.cpp | 106 ----- src/utils/string_view.h | 433 ----------------- src/utils/test/configuration.cpp | 2 +- src/utils/test/endian_test.cpp | 1 - src/utils/test/fail_point_test.cpp | 8 +- src/utils/test/fmt_logging_test.cpp | 6 +- src/utils/test/memutil_test.cpp | 33 -- src/utils/test/smart_pointers_test.cpp | 117 ----- src/utils/test/string_conv_test.cpp | 46 +- src/utils/test/string_view_test.cpp | 440 ------------------ src/utils/throttling_controller.cpp | 1 + src/utils/time_utils.h | 6 +- 114 files changed, 474 insertions(+), 2188 deletions(-) delete mode 100644 src/utils/absl/base/internal/invoke.h delete mode 100644 src/utils/absl/utility/utility.h delete mode 100644 src/utils/memutil.h delete mode 100644 src/utils/smart_pointers.h delete mode 100644 src/utils/string_view.cpp delete mode 100644 src/utils/string_view.h delete mode 100644 src/utils/test/memutil_test.cpp delete mode 100644 src/utils/test/smart_pointers_test.cpp delete mode 100644 src/utils/test/string_view_test.cpp diff --git a/.licenserc.yaml b/.licenserc.yaml index 15a2e4b78b..3bb82270bc 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -103,16 +103,6 @@ header: - 'src/utils/test/autoref_ptr_test.cpp' # Copyright (c) 2006-2009 The Chromium Authors - 'src/utils/safe_strerror_posix.cpp' - # Copyright 2017 The Abseil Authors - - 'src/utils/absl/base/internal/invoke.h' - - 'src/utils/absl/utility/utility.h' - - 'src/utils/memutil.h' - - 'src/utils/smart_pointers.h' - - 'src/utils/string_view.cpp' - - 'src/utils/string_view.h' - - 'src/utils/test/memutil_test.cpp' - - 'src/utils/test/smart_pointers_test.cpp' - - 'src/utils/test/string_view_test.cpp' # Copyright (c) 2010-2011, Rob Jansen - 'cmake_modules/FindRT.cmake' - 'cmake_modules/FindDL.cmake' diff --git a/LICENSE b/LICENSE index 06453d0c0f..c89dd134d9 100644 --- a/LICENSE +++ b/LICENSE @@ -360,32 +360,6 @@ src/shell/argh.h - BSD-3-Clause License -------------------------------------------------------------------------------- -src/utils/absl/base/internal/invoke.h - Apache 2.0 License -src/utils/absl/utility/utility.h -src/utils/memutil.h -src/utils/smart_pointers.h -src/utils/string_view.cpp -src/utils/string_view.h -src/utils/test/memutil_test.cpp -src/utils/test/smart_pointers_test.cpp -src/utils/test/string_view_test.cpp - -Copyright 2017 The Abseil Authors. - -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. - --------------------------------------------------------------------------------- - src/utils/safe_strerror_posix.cpp - BSD-3-Clause License Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. diff --git a/src/base/pegasus_utils.h b/src/base/pegasus_utils.h index 20c65b926e..0df0bee3e4 100644 --- a/src/base/pegasus_utils.h +++ b/src/base/pegasus_utils.h @@ -29,7 +29,7 @@ #include #include "utils/flags.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" DSN_DECLARE_bool(encrypt_data_at_rest); @@ -129,9 +129,9 @@ const std::string &redact_sensitive_string(const T &src) } } -inline dsn::string_view to_string_view(rocksdb::Slice s) { return {s.data(), s.size()}; } +inline absl::string_view to_string_view(rocksdb::Slice s) { return {s.data(), s.size()}; } -inline rocksdb::Slice to_rocksdb_slice(dsn::string_view s) { return {s.data(), s.size()}; } +inline rocksdb::Slice to_rocksdb_slice(absl::string_view s) { return {s.data(), s.size()}; } } // namespace utils } // namespace pegasus diff --git a/src/base/pegasus_value_schema.h b/src/base/pegasus_value_schema.h index f268a8c423..d8f651b163 100644 --- a/src/base/pegasus_value_schema.h +++ b/src/base/pegasus_value_schema.h @@ -32,7 +32,7 @@ #include "utils/blob.h" #include "utils/endians.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "value_field.h" namespace pegasus { @@ -55,7 +55,7 @@ inline uint64_t extract_timestamp_from_timetag(uint64_t timetag) /// Extracts expire_ts from rocksdb value with given version. /// The value schema must be in v0 or v1. /// \return expire_ts in host endian -inline uint32_t pegasus_extract_expire_ts(uint32_t version, dsn::string_view value) +inline uint32_t pegasus_extract_expire_ts(uint32_t version, absl::string_view value) { CHECK_LE(version, PEGASUS_DATA_VERSION_MAX); return dsn::data_input(value).read_u32(); @@ -76,7 +76,7 @@ pegasus_extract_user_data(uint32_t version, std::string &&raw_value, ::dsn::blob if (version == 1) { input.skip(sizeof(uint64_t)); } - dsn::string_view view = input.read_str(); + absl::string_view view = input.read_str(); // tricky code to avoid memory copy std::shared_ptr buf(const_cast(view.data()), [s](char *) { delete s; }); @@ -84,7 +84,7 @@ pegasus_extract_user_data(uint32_t version, std::string &&raw_value, ::dsn::blob } /// Extracts timetag from a v1 value. -inline uint64_t pegasus_extract_timetag(int version, dsn::string_view value) +inline uint64_t pegasus_extract_timetag(int version, absl::string_view value) { CHECK_EQ(version, 1); @@ -118,7 +118,7 @@ inline bool check_if_ts_expired(uint32_t epoch_now, uint32_t expire_ts) /// \return true if expired inline bool check_if_record_expired(uint32_t value_schema_version, uint32_t epoch_now, - dsn::string_view raw_value) + absl::string_view raw_value) { return check_if_ts_expired(epoch_now, pegasus_extract_expire_ts(value_schema_version, raw_value)); @@ -136,7 +136,7 @@ class pegasus_value_generator /// A higher level utility for generating value with given version. /// The value schema must be in v0 or v1. rocksdb::SliceParts generate_value(uint32_t value_schema_version, - dsn::string_view user_data, + absl::string_view user_data, uint32_t expire_ts, uint64_t timetag) { @@ -157,7 +157,7 @@ class pegasus_value_generator /// /// rocksdb value (ver 0) = [expire_ts(uint32_t)] [user_data(bytes)] /// \internal - rocksdb::SliceParts generate_value_v0(uint32_t expire_ts, dsn::string_view user_data) + rocksdb::SliceParts generate_value_v0(uint32_t expire_ts, absl::string_view user_data) { _write_buf.resize(sizeof(uint32_t)); _write_slices.clear(); @@ -210,7 +210,7 @@ class pegasus_value_generator /// /// \internal rocksdb::SliceParts - generate_value_v1(uint32_t expire_ts, uint64_t timetag, dsn::string_view user_data) + generate_value_v1(uint32_t expire_ts, uint64_t timetag, absl::string_view user_data) { _write_buf.resize(sizeof(uint32_t) + sizeof(uint64_t)); _write_slices.clear(); @@ -258,7 +258,7 @@ class value_schema public: virtual ~value_schema() = default; - virtual std::unique_ptr extract_field(dsn::string_view value, + virtual std::unique_ptr extract_field(absl::string_view value, value_field_type type) = 0; /// Extracts user value from the raw rocksdb value. /// In order to avoid data copy, the ownership of `raw_value` will be transferred diff --git a/src/base/test/value_manager_test.cpp b/src/base/test/value_manager_test.cpp index 3fbf25e3f2..35c1ce488c 100644 --- a/src/base/test/value_manager_test.cpp +++ b/src/base/test/value_manager_test.cpp @@ -23,7 +23,7 @@ #include "base/value_schema_manager.h" #include "gtest/gtest.h" #include "pegasus_value_schema.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "value_field.h" using namespace pegasus; @@ -31,7 +31,7 @@ using namespace pegasus; extern std::string generate_value(value_schema *schema, uint32_t expire_ts, uint64_t time_tag, - dsn::string_view user_data); + absl::string_view user_data); TEST(value_schema_manager, get_latest_value_schema) { diff --git a/src/base/test/value_schema_test.cpp b/src/base/test/value_schema_test.cpp index 5c1fc0804e..07ecf5f547 100644 --- a/src/base/test/value_schema_test.cpp +++ b/src/base/test/value_schema_test.cpp @@ -30,7 +30,7 @@ #include "base/value_schema_manager.h" #include "gtest/gtest.h" #include "utils/blob.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "value_field.h" using namespace pegasus; @@ -52,7 +52,7 @@ uint64_t extract_time_tag(value_schema *schema, const std::string &raw_value) std::string generate_value(value_schema *schema, uint32_t expire_ts, uint64_t time_tag, - dsn::string_view user_data) + absl::string_view user_data) { std::string write_buf; std::vector write_slices; diff --git a/src/base/value_field.h b/src/base/value_field.h index eaa287c632..11e99b8939 100644 --- a/src/base/value_field.h +++ b/src/base/value_field.h @@ -56,9 +56,9 @@ struct time_tag_field : public value_field struct user_data_field : public value_field { - explicit user_data_field(dsn::string_view data) : user_data(data) {} + explicit user_data_field(absl::string_view data) : user_data(data) {} value_field_type type() { return value_field_type::USER_DATA; } - dsn::string_view user_data; + absl::string_view user_data; }; } // namespace pegasus diff --git a/src/base/value_schema_manager.cpp b/src/base/value_schema_manager.cpp index ba5213ef27..2ce2f1db66 100644 --- a/src/base/value_schema_manager.cpp +++ b/src/base/value_schema_manager.cpp @@ -19,6 +19,7 @@ #include "value_schema_manager.h" +#include #include #include @@ -46,7 +47,7 @@ void value_schema_manager::register_schema(std::unique_ptr schema) } value_schema *value_schema_manager::get_value_schema(uint32_t meta_cf_data_version, - dsn::string_view value) const + absl::string_view value) const { dsn::data_input input(value); uint8_t first_byte = input.read_u8(); diff --git a/src/base/value_schema_manager.h b/src/base/value_schema_manager.h index a46006d2cb..5afeef5740 100644 --- a/src/base/value_schema_manager.h +++ b/src/base/value_schema_manager.h @@ -25,7 +25,7 @@ #include "pegasus_value_schema.h" #include "utils/singleton.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace pegasus { @@ -35,7 +35,7 @@ class value_schema_manager : public dsn::utils::singleton void register_schema(std::unique_ptr schema); /// using the raw value in rocksdb and data version stored in meta column family to get data /// version - value_schema *get_value_schema(uint32_t meta_cf_data_version, dsn::string_view value) const; + value_schema *get_value_schema(uint32_t meta_cf_data_version, absl::string_view value) const; value_schema *get_value_schema(uint32_t version) const; value_schema *get_latest_value_schema() const; diff --git a/src/base/value_schema_v0.cpp b/src/base/value_schema_v0.cpp index 27ca624cb2..b7cc30b5dc 100644 --- a/src/base/value_schema_v0.cpp +++ b/src/base/value_schema_v0.cpp @@ -19,6 +19,7 @@ #include "value_schema_v0.h" +#include #include #include #include @@ -31,7 +32,7 @@ #include "utils/ports.h" namespace pegasus { -std::unique_ptr value_schema_v0::extract_field(dsn::string_view value, +std::unique_ptr value_schema_v0::extract_field(absl::string_view value, value_field_type type) { std::unique_ptr field = nullptr; @@ -79,14 +80,14 @@ rocksdb::SliceParts value_schema_v0::generate_value(const value_params ¶ms) params.write_slices.clear(); params.write_slices.emplace_back(params.write_buf.data(), params.write_buf.size()); - dsn::string_view user_data = data_field->user_data; + absl::string_view user_data = data_field->user_data; if (user_data.length() > 0) { params.write_slices.emplace_back(user_data.data(), user_data.length()); } return {¶ms.write_slices[0], static_cast(params.write_slices.size())}; } -std::unique_ptr value_schema_v0::extract_timestamp(dsn::string_view value) +std::unique_ptr value_schema_v0::extract_timestamp(absl::string_view value) { uint32_t expire_ts = dsn::data_input(value).read_u32(); return std::make_unique(expire_ts); diff --git a/src/base/value_schema_v0.h b/src/base/value_schema_v0.h index 14f5891694..683afe8f92 100644 --- a/src/base/value_schema_v0.h +++ b/src/base/value_schema_v0.h @@ -25,7 +25,7 @@ #include "pegasus_value_schema.h" #include "utils/blob.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "value_field.h" namespace pegasus { @@ -37,7 +37,7 @@ class value_schema_v0 : public value_schema public: value_schema_v0() = default; - std::unique_ptr extract_field(dsn::string_view value, + std::unique_ptr extract_field(absl::string_view value, value_field_type type) override; dsn::blob extract_user_data(std::string &&value) override; void update_field(std::string &value, std::unique_ptr field) override; @@ -45,7 +45,7 @@ class value_schema_v0 : public value_schema data_version version() const override { return data_version::VERSION_0; } private: - std::unique_ptr extract_timestamp(dsn::string_view value); + std::unique_ptr extract_timestamp(absl::string_view value); void update_expire_ts(std::string &value, std::unique_ptr field); }; } // namespace pegasus diff --git a/src/base/value_schema_v1.cpp b/src/base/value_schema_v1.cpp index 8871f173df..9e00369176 100644 --- a/src/base/value_schema_v1.cpp +++ b/src/base/value_schema_v1.cpp @@ -19,6 +19,7 @@ #include "value_schema_v1.h" +#include #include #include #include @@ -31,7 +32,7 @@ #include "utils/ports.h" namespace pegasus { -std::unique_ptr value_schema_v1::extract_field(dsn::string_view value, +std::unique_ptr value_schema_v1::extract_field(absl::string_view value, value_field_type type) { std::unique_ptr field = nullptr; @@ -87,20 +88,20 @@ rocksdb::SliceParts value_schema_v1::generate_value(const value_params ¶ms) params.write_slices.clear(); params.write_slices.emplace_back(params.write_buf.data(), params.write_buf.size()); - dsn::string_view user_data = data_field->user_data; + absl::string_view user_data = data_field->user_data; if (user_data.length() > 0) { params.write_slices.emplace_back(user_data.data(), user_data.length()); } return {¶ms.write_slices[0], static_cast(params.write_slices.size())}; } -std::unique_ptr value_schema_v1::extract_timestamp(dsn::string_view value) +std::unique_ptr value_schema_v1::extract_timestamp(absl::string_view value) { uint32_t expire_ts = dsn::data_input(value).read_u32(); return std::make_unique(expire_ts); } -std::unique_ptr value_schema_v1::extract_time_tag(dsn::string_view value) +std::unique_ptr value_schema_v1::extract_time_tag(absl::string_view value) { dsn::data_input input(value); input.skip(sizeof(uint32_t)); diff --git a/src/base/value_schema_v1.h b/src/base/value_schema_v1.h index 605551883f..7811b49f6b 100644 --- a/src/base/value_schema_v1.h +++ b/src/base/value_schema_v1.h @@ -25,7 +25,7 @@ #include "pegasus_value_schema.h" #include "utils/blob.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "value_field.h" namespace pegasus { @@ -37,7 +37,7 @@ class value_schema_v1 : public value_schema public: value_schema_v1() = default; - std::unique_ptr extract_field(dsn::string_view value, + std::unique_ptr extract_field(absl::string_view value, value_field_type type) override; dsn::blob extract_user_data(std::string &&value) override; void update_field(std::string &value, std::unique_ptr field) override; @@ -45,8 +45,8 @@ class value_schema_v1 : public value_schema data_version version() const override { return data_version::VERSION_1; } private: - std::unique_ptr extract_timestamp(dsn::string_view value); - std::unique_ptr extract_time_tag(dsn::string_view value); + std::unique_ptr extract_timestamp(absl::string_view value); + std::unique_ptr extract_time_tag(absl::string_view value); void update_expire_ts(std::string &value, std::unique_ptr field); }; diff --git a/src/base/value_schema_v2.cpp b/src/base/value_schema_v2.cpp index bab5f0ecd3..400cad75e7 100644 --- a/src/base/value_schema_v2.cpp +++ b/src/base/value_schema_v2.cpp @@ -19,6 +19,7 @@ #include "value_schema_v2.h" +#include #include #include #include @@ -32,7 +33,7 @@ namespace pegasus { -std::unique_ptr value_schema_v2::extract_field(dsn::string_view value, +std::unique_ptr value_schema_v2::extract_field(absl::string_view value, value_field_type type) { std::unique_ptr field = nullptr; @@ -90,21 +91,21 @@ rocksdb::SliceParts value_schema_v2::generate_value(const value_params ¶ms) params.write_slices.clear(); params.write_slices.emplace_back(params.write_buf.data(), params.write_buf.size()); - dsn::string_view user_data = data_field->user_data; + absl::string_view user_data = data_field->user_data; if (user_data.length() > 0) { params.write_slices.emplace_back(user_data.data(), user_data.length()); } return {¶ms.write_slices[0], static_cast(params.write_slices.size())}; } -std::unique_ptr value_schema_v2::extract_timestamp(dsn::string_view value) +std::unique_ptr value_schema_v2::extract_timestamp(absl::string_view value) { dsn::data_input input(value); input.skip(sizeof(uint8_t)); return std::make_unique(input.read_u32()); } -std::unique_ptr value_schema_v2::extract_time_tag(dsn::string_view value) +std::unique_ptr value_schema_v2::extract_time_tag(absl::string_view value) { dsn::data_input input(value); input.skip(sizeof(uint8_t)); diff --git a/src/base/value_schema_v2.h b/src/base/value_schema_v2.h index 3c25696b3e..c3101baf3a 100644 --- a/src/base/value_schema_v2.h +++ b/src/base/value_schema_v2.h @@ -25,7 +25,7 @@ #include "pegasus_value_schema.h" #include "utils/blob.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "value_field.h" namespace pegasus { @@ -38,7 +38,7 @@ class value_schema_v2 : public value_schema public: value_schema_v2() = default; - std::unique_ptr extract_field(dsn::string_view value, + std::unique_ptr extract_field(absl::string_view value, value_field_type type) override; dsn::blob extract_user_data(std::string &&value) override; void update_field(std::string &value, std::unique_ptr field) override; @@ -46,8 +46,8 @@ class value_schema_v2 : public value_schema data_version version() const override { return data_version::VERSION_2; } private: - std::unique_ptr extract_timestamp(dsn::string_view value); - std::unique_ptr extract_time_tag(dsn::string_view value); + std::unique_ptr extract_timestamp(absl::string_view value); + std::unique_ptr extract_time_tag(absl::string_view value); void update_expire_ts(std::string &value, std::unique_ptr field); }; } // namespace pegasus diff --git a/src/block_service/local/local_service.cpp b/src/block_service/local/local_service.cpp index ccccea7d82..ad71e2a613 100644 --- a/src/block_service/local/local_service.cpp +++ b/src/block_service/local/local_service.cpp @@ -36,7 +36,7 @@ #include "utils/filesystem.h" #include "utils/flags.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" DSN_DECLARE_bool(enable_direct_io); @@ -318,7 +318,7 @@ dsn::task_ptr local_file_object::write(const write_request &req, write_future_ptr tsk(new write_future(code, cb, 0)); tsk->set_tracker(tracker); - FAIL_POINT_INJECT_F("mock_local_service_write_failed", [=](dsn::string_view) { + FAIL_POINT_INJECT_F("mock_local_service_write_failed", [=](absl::string_view) { auto write_failed = [=]() { write_response resp; resp.err = ERR_FS_INTERNAL; diff --git a/src/client/replication_ddl_client.cpp b/src/client/replication_ddl_client.cpp index 023464251c..32a7809825 100644 --- a/src/client/replication_ddl_client.cpp +++ b/src/client/replication_ddl_client.cpp @@ -1442,7 +1442,7 @@ void replication_ddl_client::end_meta_request(const rpc_response_task_ptr &callb FAIL_POINT_INJECT_NOT_RETURN_F( "ddl_client_request_meta", - [&err, this](dsn::string_view str) { err = pop_mock_error(); }); + [&err, this](absl::string_view str) { err = pop_mock_error(); }); end_meta_request(callback, attempt_count + 1, err, request, response); }); diff --git a/src/client/replication_ddl_client.h b/src/client/replication_ddl_client.h index d9cec40d29..7a32dc8510 100644 --- a/src/client/replication_ddl_client.h +++ b/src/client/replication_ddl_client.h @@ -58,7 +58,7 @@ #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/ports.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" DSN_DECLARE_uint32(ddl_client_max_attempt_count); DSN_DECLARE_uint32(ddl_client_retry_interval_ms); @@ -293,7 +293,7 @@ class replication_ddl_client FAIL_POINT_INJECT_NOT_RETURN_F( "ddl_client_request_meta", - [&err, this](dsn::string_view str) { err = pop_mock_error(); }); + [&err, this](absl::string_view str) { err = pop_mock_error(); }); end_meta_request(std::move(task), 1, err, request, response); }); @@ -334,7 +334,7 @@ class replication_ddl_client FAIL_POINT_INJECT_NOT_RETURN_F( "ddl_client_request_meta", - [&resp, this](dsn::string_view str) { resp.err = pop_mock_error(); }); + [&resp, this](absl::string_view str) { resp.err = pop_mock_error(); }); LOG_INFO("received response from meta server: rpc_code={}, err={}, attempt_count={}, " "max_attempt_count={}", diff --git a/src/client_lib/pegasus_client_impl.cpp b/src/client_lib/pegasus_client_impl.cpp index a390e23c32..177477beb4 100644 --- a/src/client_lib/pegasus_client_impl.cpp +++ b/src/client_lib/pegasus_client_impl.cpp @@ -40,7 +40,7 @@ #include "runtime/task/task_code.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/synchronize.h" #include "utils/threadpool_code.h" #include "utils/utils.h" @@ -1181,12 +1181,12 @@ int pegasus_client_impl::get_scanner(const std::string &hash_key, pegasus_generate_key(prefix_start, hash_key, o.sort_key_filter_pattern); pegasus_generate_next_blob(prefix_stop, hash_key, o.sort_key_filter_pattern); - if (::dsn::string_view(prefix_start).compare(start) > 0) { + if (prefix_start.to_string_view() > start.to_string_view()) { start = std::move(prefix_start); o.start_inclusive = true; } - if (::dsn::string_view(prefix_stop).compare(stop) <= 0) { + if (prefix_stop.to_string_view() <= stop.to_string_view()) { stop = std::move(prefix_stop); o.stop_inclusive = false; } @@ -1194,7 +1194,7 @@ int pegasus_client_impl::get_scanner(const std::string &hash_key, // check if range is empty std::vector v; - int c = ::dsn::string_view(start).compare(stop); + int c = start.to_string_view().compare(stop.to_string_view()); if (c < 0 || (c == 0 && o.start_inclusive && o.stop_inclusive)) { v.push_back(pegasus_key_hash(start)); } diff --git a/src/common/fs_manager.cpp b/src/common/fs_manager.cpp index 362b29ba87..f1e9a11810 100644 --- a/src/common/fs_manager.cpp +++ b/src/common/fs_manager.cpp @@ -51,7 +51,7 @@ #include "utils/filesystem.h" #include "utils/fmt_logging.h" #include "utils/ports.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -101,7 +101,7 @@ uint64_t dir_node::replicas_count(app_id id) const return iter->second.size(); } -std::string dir_node::replica_dir(dsn::string_view app_type, const dsn::gpid &pid) const +std::string dir_node::replica_dir(absl::string_view app_type, const dsn::gpid &pid) const { return utils::filesystem::path_combine(full_dir, fmt::format("{}.{}", pid, app_type)); } @@ -126,7 +126,7 @@ uint64_t dir_node::remove(const gpid &pid) void dir_node::update_disk_stat() { - FAIL_POINT_INJECT_F("update_disk_stat", [](string_view) { return; }); + FAIL_POINT_INJECT_F("update_disk_stat", [](absl::string_view) { return; }); dsn::utils::filesystem::disk_space_info dsi; if (!dsn::utils::filesystem::get_disk_space_info(full_dir, dsi)) { @@ -317,7 +317,7 @@ dir_node *fs_manager::find_best_dir_for_new_replica(const gpid &pid) const } void fs_manager::specify_dir_for_new_replica_for_test(dir_node *specified_dn, - dsn::string_view app_type, + absl::string_view app_type, const dsn::gpid &pid) const { bool dn_found = false; @@ -417,7 +417,7 @@ bool fs_manager::is_dir_node_exist(const std::string &data_dir, const std::strin return false; } -dir_node *fs_manager::find_replica_dir(dsn::string_view app_type, gpid pid) +dir_node *fs_manager::find_replica_dir(absl::string_view app_type, gpid pid) { std::string replica_dir; dir_node *replica_dn = nullptr; @@ -441,7 +441,7 @@ dir_node *fs_manager::find_replica_dir(dsn::string_view app_type, gpid pid) return replica_dn; } -dir_node *fs_manager::create_replica_dir_if_necessary(dsn::string_view app_type, gpid pid) +dir_node *fs_manager::create_replica_dir_if_necessary(absl::string_view app_type, gpid pid) { // Try to find the replica directory. auto replica_dn = find_replica_dir(app_type, pid); @@ -473,7 +473,7 @@ dir_node *fs_manager::create_replica_dir_if_necessary(dsn::string_view app_type, return replica_dn; } -dir_node *fs_manager::create_child_replica_dir(dsn::string_view app_type, +dir_node *fs_manager::create_child_replica_dir(absl::string_view app_type, gpid child_pid, const std::string &parent_dir) { diff --git a/src/common/fs_manager.h b/src/common/fs_manager.h index a8985f22ef..7b7f03f516 100644 --- a/src/common/fs_manager.h +++ b/src/common/fs_manager.h @@ -31,7 +31,7 @@ #include "perf_counter/perf_counter_wrapper.h" #include "utils/error_code.h" #include "utils/flags.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/zlocks.h" namespace dsn { @@ -78,7 +78,7 @@ struct dir_node uint64_t replicas_count() const; // Construct the replica dir for the given 'app_type' and 'pid'. // NOTE: Just construct the string, the directory will not be created. - std::string replica_dir(dsn::string_view app_type, const dsn::gpid &pid) const; + std::string replica_dir(absl::string_view app_type, const dsn::gpid &pid) const; bool has(const dsn::gpid &pid) const; uint64_t remove(const dsn::gpid &pid); void update_disk_stat(); @@ -104,18 +104,18 @@ class fs_manager // dir_nodes. // NOTE: only used in test. void specify_dir_for_new_replica_for_test(dir_node *specified_dn, - dsn::string_view app_type, + absl::string_view app_type, const dsn::gpid &pid) const; void add_replica(const dsn::gpid &pid, const std::string &pid_dir); // Find the replica instance directory. - dir_node *find_replica_dir(dsn::string_view app_type, gpid pid); + dir_node *find_replica_dir(absl::string_view app_type, gpid pid); // Similar to the above, but it will create a new directory if not found. - dir_node *create_replica_dir_if_necessary(dsn::string_view app_type, gpid pid); + dir_node *create_replica_dir_if_necessary(absl::string_view app_type, gpid pid); // Similar to the above, and will create a directory for the child on the same dir_node // of parent. // During partition split, we should guarantee child replica and parent replica share the // same data dir. - dir_node *create_child_replica_dir(dsn::string_view app_type, + dir_node *create_child_replica_dir(absl::string_view app_type, gpid child_pid, const std::string &parent_dir); void remove_replica(const dsn::gpid &pid); diff --git a/src/common/replication_common.cpp b/src/common/replication_common.cpp index 1afe9d49fe..45c503e2ca 100644 --- a/src/common/replication_common.cpp +++ b/src/common/replication_common.cpp @@ -26,6 +26,7 @@ #include "common/replication_common.h" +// IWYU pragma: no_include #include #include #include diff --git a/src/common/serialization_helper/thrift_helper.h b/src/common/serialization_helper/thrift_helper.h index fe937d588a..83d32ac93b 100644 --- a/src/common/serialization_helper/thrift_helper.h +++ b/src/common/serialization_helper/thrift_helper.h @@ -38,7 +38,7 @@ #include #include -#include "utils/string_view.h" +#include "absl/strings/string_view.h" using namespace ::apache::thrift::transport; namespace dsn { @@ -499,7 +499,7 @@ inline uint32_t task_code::write(apache::thrift::protocol::TProtocol *oprot) con dynamic_cast(oprot); if (binary_proto != nullptr) { // the protocol is binary protocol - return binary_proto->writeString(string_view(name)); + return binary_proto->writeString(absl::string_view(name)); } else { // the protocol is json protocol uint32_t xfer = 0; @@ -567,7 +567,7 @@ inline uint32_t error_code::write(apache::thrift::protocol::TProtocol *oprot) co dynamic_cast(oprot); if (binary_proto != nullptr) { // the protocol is binary protocol - return binary_proto->writeString(string_view(name)); + return binary_proto->writeString(absl::string_view(name)); } else { // the protocol is json protocol uint32_t xfer = 0; diff --git a/src/http/http_client.cpp b/src/http/http_client.cpp index 41e6b7f426..a1c64e006f 100644 --- a/src/http/http_client.cpp +++ b/src/http/http_client.cpp @@ -264,15 +264,15 @@ void http_client::free_header_list() _header_list = nullptr; } -void http_client::set_header_field(dsn::string_view key, dsn::string_view val) +void http_client::set_header_field(absl::string_view key, absl::string_view val) { _header_fields[std::string(key)] = std::string(val); _header_changed = true; } -void http_client::set_accept(dsn::string_view val) { set_header_field("Accept", val); } +void http_client::set_accept(absl::string_view val) { set_header_field("Accept", val); } -void http_client::set_content_type(dsn::string_view val) { set_header_field("Content-Type", val); } +void http_client::set_content_type(absl::string_view val) { set_header_field("Content-Type", val); } dsn::error_s http_client::process_header() { diff --git a/src/http/http_client.h b/src/http/http_client.h index fe4b0ed18a..f9f8dfa312 100644 --- a/src/http/http_client.h +++ b/src/http/http_client.h @@ -26,7 +26,7 @@ #include "http/http_method.h" #include "utils/errors.h" #include "utils/ports.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { @@ -98,8 +98,8 @@ class http_client // Operations for the header fields. void clear_header_fields(); - void set_accept(dsn::string_view val); - void set_content_type(dsn::string_view val); + void set_accept(absl::string_view val); + void set_content_type(absl::string_view val); // Submit request to remote http service, with response processed by callback function. // @@ -134,7 +134,7 @@ class http_client dsn::error_s set_method(http_method method); void free_header_list(); - void set_header_field(dsn::string_view key, dsn::string_view val); + void set_header_field(absl::string_view key, absl::string_view val); dsn::error_s process_header(); // The size of a buffer that is used by libcurl to store human readable diff --git a/src/http/uri_decoder.cpp b/src/http/uri_decoder.cpp index 1dfa216ee4..d6a1a1de9f 100644 --- a/src/http/uri_decoder.cpp +++ b/src/http/uri_decoder.cpp @@ -40,7 +40,7 @@ error_with from_hex(const char c) } } -error_with decode_char(const string_view &hex) +error_with decode_char(const absl::string_view &hex) { CHECK_EQ(2, hex.size()); @@ -53,7 +53,7 @@ error_with decode_char(const string_view &hex) return error_s::make(ERR_INVALID_PARAMETERS); } -error_with decode(const string_view &encoded_uri) +error_with decode(const absl::string_view &encoded_uri) { std::string decoded_uri; for (size_t i = 0; i < encoded_uri.size(); ++i) { @@ -64,7 +64,7 @@ error_with decode(const string_view &encoded_uri) "Encountered partial escape sequence at end of string"); } - const string_view encoded_char(encoded_uri.data() + i + 1, 2); + const absl::string_view encoded_char(encoded_uri.data() + i + 1, 2); auto decoded_char = decode_char(encoded_char); if (!decoded_char.is_ok()) { return error_s::make( diff --git a/src/http/uri_decoder.h b/src/http/uri_decoder.h index 0bd035aeba..b1d28a13ba 100644 --- a/src/http/uri_decoder.h +++ b/src/http/uri_decoder.h @@ -20,14 +20,14 @@ #include #include "utils/errors.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace uri { /// \brief Decodes a sequence according to the percent decoding rules. /// \returns the decoded uri path -error_with decode(const string_view &encoded_uri); +error_with decode(const absl::string_view &encoded_uri); } // namespace uri } // namespace dsn diff --git a/src/meta/app_env_validator.cpp b/src/meta/app_env_validator.cpp index 7f197f5a0f..e068022a09 100644 --- a/src/meta/app_env_validator.cpp +++ b/src/meta/app_env_validator.cpp @@ -17,6 +17,7 @@ #include "app_env_validator.h" +// IWYU pragma: no_include #include #include #include diff --git a/src/meta/duplication/meta_duplication_service.cpp b/src/meta/duplication/meta_duplication_service.cpp index 4d51bac70c..fd1d034f17 100644 --- a/src/meta/duplication/meta_duplication_service.cpp +++ b/src/meta/duplication/meta_duplication_service.cpp @@ -47,7 +47,7 @@ #include "utils/fmt_logging.h" #include "utils/ports.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/zlocks.h" namespace dsn { @@ -370,18 +370,19 @@ void meta_duplication_service::create_follower_app_for_duplication( _meta_svc->tracker(), [=](error_code err, configuration_create_app_response &&resp) mutable { FAIL_POINT_INJECT_NOT_RETURN_F("update_app_request_ok", - [&](string_view s) -> void { err = ERR_OK; }); + [&](absl::string_view s) -> void { err = ERR_OK; }); error_code create_err = err == ERR_OK ? resp.err : err; error_code update_err = ERR_NO_NEED_OPERATE; - FAIL_POINT_INJECT_NOT_RETURN_F("persist_dup_status_failed", - [&](string_view s) -> void { create_err = ERR_OK; }); + FAIL_POINT_INJECT_NOT_RETURN_F( + "persist_dup_status_failed", + [&](absl::string_view s) -> void { create_err = ERR_OK; }); if (create_err == ERR_OK) { update_err = dup->alter_status(duplication_status::DS_APP); } FAIL_POINT_INJECT_F("persist_dup_status_failed", - [&](string_view s) -> void { return; }); + [&](absl::string_view s) -> void { return; }); if (update_err == ERR_OK) { blob value = dup->to_json_blob(); // Note: this function is `async`, it may not be persisted completed @@ -418,7 +419,7 @@ void meta_duplication_service::check_follower_app_if_create_completed( msg, _meta_svc->tracker(), [=](error_code err, query_cfg_response &&resp) mutable { - FAIL_POINT_INJECT_NOT_RETURN_F("create_app_ok", [&](string_view s) -> void { + FAIL_POINT_INJECT_NOT_RETURN_F("create_app_ok", [&](absl::string_view s) -> void { err = ERR_OK; int count = dup->partition_count; while (count-- > 0) { @@ -464,7 +465,7 @@ void meta_duplication_service::check_follower_app_if_create_completed( } FAIL_POINT_INJECT_F("persist_dup_status_failed", - [&](string_view s) -> void { return; }); + [&](absl::string_view s) -> void { return; }); if (update_err == ERR_OK) { blob value = dup->to_json_blob(); // Note: this function is `async`, it may not be persisted completed @@ -612,7 +613,7 @@ void meta_duplication_service::do_restore_duplication_progress( } int64_t confirmed_decree = invalid_decree; - if (!buf2int64(value, confirmed_decree)) { + if (!buf2int64(value.to_string_view(), confirmed_decree)) { LOG_ERROR("[{}] invalid confirmed_decree {} on partition_idx {}", dup->log_prefix(), value.to_string(), diff --git a/src/meta/load_balance_policy.cpp b/src/meta/load_balance_policy.cpp index 69968ac65f..61e8464799 100644 --- a/src/meta/load_balance_policy.cpp +++ b/src/meta/load_balance_policy.cpp @@ -34,7 +34,7 @@ #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" namespace dsn { @@ -130,7 +130,8 @@ generate_balancer_request(const app_mapper &apps, const rpc_address &from, const rpc_address &to) { - FAIL_POINT_INJECT_F("generate_balancer_request", [](string_view name) { return nullptr; }); + FAIL_POINT_INJECT_F("generate_balancer_request", + [](absl::string_view name) { return nullptr; }); configuration_balancer_request result; result.gpid = pc.pid; diff --git a/src/meta/meta_bulk_load_ingestion_context.cpp b/src/meta/meta_bulk_load_ingestion_context.cpp index ade83d3e9c..8ab82495ab 100644 --- a/src/meta/meta_bulk_load_ingestion_context.cpp +++ b/src/meta/meta_bulk_load_ingestion_context.cpp @@ -26,7 +26,7 @@ #include "utils/fail_point.h" #include "utils/fmt_logging.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -72,11 +72,12 @@ void ingestion_context::node_context::init_disk(const std::string &disk_tag) uint32_t ingestion_context::node_context::get_max_disk_ingestion_count( const uint32_t max_node_ingestion_count) const { - FAIL_POINT_INJECT_F("ingestion_node_context_disk_count", [](string_view count_str) -> uint32_t { - uint32_t count = 0; - buf2uint32(count_str, count); - return count; - }); + FAIL_POINT_INJECT_F("ingestion_node_context_disk_count", + [](absl::string_view count_str) -> uint32_t { + uint32_t count = 0; + buf2uint32(count_str, count); + return count; + }); const auto node_disk_count = disk_ingesting_counts.size() > FLAGS_bulk_load_node_min_disk_count ? disk_ingesting_counts.size() @@ -122,7 +123,7 @@ void ingestion_context::node_context::decrease(const std::string &disk_tag) bool ingestion_context::try_partition_ingestion(const partition_configuration &config, const config_context &cc) { - FAIL_POINT_INJECT_F("ingestion_try_partition_ingestion", [=](string_view) -> bool { + FAIL_POINT_INJECT_F("ingestion_try_partition_ingestion", [=](absl::string_view) -> bool { auto info = partition_node_info(); info.pid = config.pid; _running_partitions[config.pid] = info; @@ -157,7 +158,7 @@ void ingestion_context::add_partition(const partition_node_info &info) void ingestion_context::remove_partition(const gpid &pid) { FAIL_POINT_INJECT_F("ingestion_context_remove_partition", - [=](string_view) { _running_partitions.erase(pid); }); + [=](absl::string_view) { _running_partitions.erase(pid); }); if (_running_partitions.find(pid) == _running_partitions.end()) { return; diff --git a/src/meta/meta_bulk_load_service.cpp b/src/meta/meta_bulk_load_service.cpp index cf559a1d10..1f3cc05d40 100644 --- a/src/meta/meta_bulk_load_service.cpp +++ b/src/meta/meta_bulk_load_service.cpp @@ -48,9 +48,8 @@ #include "utils/chrono_literals.h" #include "utils/fail_point.h" #include "utils/fmt_logging.h" -#include "utils/smart_pointers.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -86,7 +85,7 @@ bulk_load_service::bulk_load_service(meta_service *meta_svc, const std::string & void bulk_load_service::initialize_bulk_load_service() { _sync_bulk_load_storage = - make_unique(_meta_svc->get_remote_storage(), &_sync_tracker); + std::make_unique(_meta_svc->get_remote_storage(), &_sync_tracker); _ingestion_context = std::make_unique(); create_bulk_load_root_dir(); @@ -99,7 +98,7 @@ void bulk_load_service::initialize_bulk_load_service() void bulk_load_service::on_start_bulk_load(start_bulk_load_rpc rpc) { FAIL_POINT_INJECT_F("meta_on_start_bulk_load", - [=](dsn::string_view) { rpc.response().err = ERR_OK; }); + [=](absl::string_view) { rpc.response().err = ERR_OK; }); const auto &request = rpc.request(); auto &response = rpc.response(); @@ -168,7 +167,7 @@ bulk_load_service::check_bulk_load_request_params(const start_bulk_load_request std::string &hint_msg) { FAIL_POINT_INJECT_F("meta_check_bulk_load_request_params", - [](dsn::string_view) -> error_code { return ERR_OK; }); + [](absl::string_view) -> error_code { return ERR_OK; }); if (!validate_ingest_behind(envs, request.ingest_behind)) { hint_msg = fmt::format("inconsistent ingestion behind option"); @@ -409,7 +408,7 @@ bool bulk_load_service::check_partition_status( // ThreadPool: THREAD_POOL_META_STATE void bulk_load_service::partition_bulk_load(const std::string &app_name, const gpid &pid) { - FAIL_POINT_INJECT_F("meta_bulk_load_partition_bulk_load", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("meta_bulk_load_partition_bulk_load", [](absl::string_view) {}); partition_configuration pconfig; if (!check_partition_status(app_name, @@ -571,7 +570,7 @@ void bulk_load_service::on_partition_bulk_load_reply(error_code err, // ThreadPool: THREAD_POOL_META_STATE void bulk_load_service::try_resend_bulk_load_request(const std::string &app_name, const gpid &pid) { - FAIL_POINT_INJECT_F("meta_bulk_load_resend_request", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("meta_bulk_load_resend_request", [](absl::string_view) {}); zauto_read_lock l(_lock); if (is_app_bulk_loading_unlocked(pid.get_app_id())) { tasking::enqueue(LPC_META_STATE_NORMAL, @@ -1081,7 +1080,7 @@ void bulk_load_service::update_app_status_on_remote_storage_unlocked( int32_t app_id, bulk_load_status::type new_status, error_code err, bool should_send_request) { FAIL_POINT_INJECT_F("meta_update_app_status_on_remote_storage_unlocked", - [](dsn::string_view) {}); + [](absl::string_view) {}); app_bulk_load_info ainfo = _app_bulk_load_info[app_id]; auto old_status = ainfo.status; @@ -1213,7 +1212,7 @@ bool bulk_load_service::check_ever_ingestion_succeed(const partition_configurati // ThreadPool: THREAD_POOL_META_STATE void bulk_load_service::partition_ingestion(const std::string &app_name, const gpid &pid) { - FAIL_POINT_INJECT_F("meta_bulk_load_partition_ingestion", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("meta_bulk_load_partition_ingestion", [](absl::string_view) {}); auto app_status = get_app_bulk_load_status(pid.get_app_id()); if (app_status != bulk_load_status::BLS_INGESTING) { @@ -1645,7 +1644,7 @@ void bulk_load_service::on_clear_bulk_load(clear_bulk_load_rpc rpc) void bulk_load_service::do_clear_app_bulk_load_result(int32_t app_id, clear_bulk_load_rpc rpc) { FAIL_POINT_INJECT_F("meta_do_clear_app_bulk_load_result", - [rpc](dsn::string_view) { rpc.response().err = ERR_OK; }); + [rpc](absl::string_view) { rpc.response().err = ERR_OK; }); std::string bulk_load_path = get_app_bulk_load_path(app_id); _meta_svc->get_meta_storage()->delete_node_recursively( std::move(bulk_load_path), [this, app_id, bulk_load_path, rpc]() { @@ -1739,7 +1738,7 @@ void bulk_load_service::do_sync_partition(const gpid &pid, std::string &partitio // ThreadPool: THREAD_POOL_META_SERVER void bulk_load_service::try_to_continue_bulk_load() { - FAIL_POINT_INJECT_F("meta_try_to_continue_bulk_load", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("meta_try_to_continue_bulk_load", [](absl::string_view) {}); zauto_read_lock l(_lock); for (const auto app_id : _bulk_load_app_id) { app_bulk_load_info ainfo = _app_bulk_load_info[app_id]; diff --git a/src/meta/meta_server_failure_detector.cpp b/src/meta/meta_server_failure_detector.cpp index 83cafc183c..0e76c3a263 100644 --- a/src/meta/meta_server_failure_detector.cpp +++ b/src/meta/meta_server_failure_detector.cpp @@ -44,7 +44,7 @@ #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" DSN_DEFINE_int32(meta_server, max_succssive_unstable_restart, @@ -101,7 +101,7 @@ void meta_server_failure_detector::on_worker_connected(rpc_address node) bool meta_server_failure_detector::get_leader(rpc_address *leader) { - FAIL_POINT_INJECT_F("meta_server_failure_detector_get_leader", [leader](dsn::string_view str) { + FAIL_POINT_INJECT_F("meta_server_failure_detector_get_leader", [leader](absl::string_view str) { /// the format of str is : true#{ip}:{port} or false#{ip}:{port} auto pos = str.find("#"); // get leader addr diff --git a/src/nfs/nfs_server_impl.cpp b/src/nfs/nfs_server_impl.cpp index c4bcf7a2e4..fc7f9b6421 100644 --- a/src/nfs/nfs_server_impl.cpp +++ b/src/nfs/nfs_server_impl.cpp @@ -26,6 +26,7 @@ #include "nfs/nfs_server_impl.h" +// IWYU pragma: no_include #include #include #include diff --git a/src/redis_protocol/proxy_lib/redis_parser.cpp b/src/redis_protocol/proxy_lib/redis_parser.cpp index 8712f23457..d1696a25da 100644 --- a/src/redis_protocol/proxy_lib/redis_parser.cpp +++ b/src/redis_protocol/proxy_lib/redis_parser.cpp @@ -45,7 +45,7 @@ #include "utils/fmt_logging.h" #include "utils/ports.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" #include "utils/utils.h" @@ -206,7 +206,7 @@ void redis_parser::eat_all(char *dest, size_t length) bool redis_parser::end_array_size() { int32_t count = 0; - if (dsn_unlikely(!dsn::buf2int32(dsn::string_view(_current_size), count))) { + if (dsn_unlikely(!dsn::buf2int32(absl::string_view(_current_size), count))) { LOG_ERROR( "{}: invalid size string \"{}\"", _remote_address.to_string(), _current_size.c_str()); return false; @@ -244,8 +244,7 @@ void redis_parser::append_current_bulk_string() bool redis_parser::end_bulk_string_size() { int32_t length = 0; - if (dsn_unlikely(!dsn::buf2int32( - dsn::string_view(_current_size.c_str(), _current_size.length()), length))) { + if (dsn_unlikely(!dsn::buf2int32(absl::string_view(_current_size), length))) { LOG_ERROR( "{}: invalid size string \"{}\"", _remote_address.to_string(), _current_size.c_str()); return false; @@ -545,9 +544,8 @@ void redis_parser::setex(message_entry &entry) simple_error_reply(entry, "wrong number of arguments for 'setex' command"); } else { LOG_DEBUG_PREFIX("send SETEX command seqid({})", entry.sequence_id); - ::dsn::blob &ttl_blob = redis_req.sub_requests[2].data; int ttl_seconds; - if (!dsn::buf2int32(ttl_blob, ttl_seconds)) { + if (!dsn::buf2int32(redis_req.sub_requests[2].data.to_string_view(), ttl_seconds)) { simple_error_reply(entry, "value is not an integer or out of range"); return; } @@ -935,7 +933,7 @@ void redis_parser::counter_internal(message_entry &entry) simple_error_reply(entry, fmt::format("wrong number of arguments for '{}'", command)); return; } - if (!dsn::buf2int64(entry.request.sub_requests[2].data, increment)) { + if (!dsn::buf2int64(entry.request.sub_requests[2].data.to_string_view(), increment)) { LOG_WARNING("{}: command {} seqid({}) with invalid 'increment': {}", _remote_address, command, @@ -1177,12 +1175,12 @@ void redis_parser::geo_add(message_entry &entry) }; for (int i = 0; i < member_count; ++i) { - dsn::string_view lng_degree_str(redis_request.sub_requests[2 + i * 3].data); - dsn::string_view lat_degree_str(redis_request.sub_requests[2 + i * 3 + 1].data); double lng_degree; double lat_degree; - if (dsn::buf2double(lng_degree_str, lng_degree) && - dsn::buf2double(lat_degree_str, lat_degree)) { + if (dsn::buf2double(redis_request.sub_requests[2 + i * 3].data.to_string_view(), + lng_degree) && + dsn::buf2double(redis_request.sub_requests[2 + i * 3 + 1].data.to_string_view(), + lat_degree)) { const std::string &hashkey = redis_request.sub_requests[2 + i * 3 + 2].data.to_string(); _geo_client->async_set(hashkey, "", lat_degree, lng_degree, set_latlng_callback, 2000); } else if (set_count->fetch_sub(1) == 1) { diff --git a/src/replica/bulk_load/replica_bulk_loader.cpp b/src/replica/bulk_load/replica_bulk_loader.cpp index fcf5c0bf84..950a0a7343 100644 --- a/src/replica/bulk_load/replica_bulk_loader.cpp +++ b/src/replica/bulk_load/replica_bulk_loader.cpp @@ -51,7 +51,7 @@ #include "utils/filesystem.h" #include "utils/fmt_logging.h" #include "utils/ports.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/thread_access_checker.h" namespace dsn { @@ -442,7 +442,7 @@ void replica_bulk_loader::download_files(const std::string &provider_name, const std::string &remote_dir, const std::string &local_dir) { - FAIL_POINT_INJECT_F("replica_bulk_loader_download_files", [](string_view) {}); + FAIL_POINT_INJECT_F("replica_bulk_loader_download_files", [](absl::string_view) {}); LOG_INFO_PREFIX("start to download files"); dist::block_service::block_filesystem *fs = diff --git a/src/replica/disk_cleaner.cpp b/src/replica/disk_cleaner.cpp index cc9ffeb661..a4cc0d9f55 100644 --- a/src/replica/disk_cleaner.cpp +++ b/src/replica/disk_cleaner.cpp @@ -36,7 +36,7 @@ #include "utils/fmt_logging.h" #include "utils/macros.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -149,7 +149,7 @@ bool parse_timestamp_us(const std::string &name, size_t suffix_size, uint64_t &t } const auto ok = - dsn::buf2uint64(dsn::string_view(name.data() + begin_idx, length), timestamp_us); + dsn::buf2uint64(absl::string_view(name.data() + begin_idx, length), timestamp_us); return ok ? timestamp_us > MIN_TIMESTAMP_US : false; } diff --git a/src/replica/duplication/duplication_pipeline.cpp b/src/replica/duplication/duplication_pipeline.cpp index 02a818bd94..d753e40d14 100644 --- a/src/replica/duplication/duplication_pipeline.cpp +++ b/src/replica/duplication/duplication_pipeline.cpp @@ -17,8 +17,10 @@ #include "duplication_pipeline.h" +#include #include #include +#include #include #include "dsn.layer2_types.h" @@ -33,7 +35,6 @@ #include "utils/fmt_logging.h" namespace dsn { -class string_view; namespace replication { @@ -42,7 +43,7 @@ namespace replication { // // /*static*/ std::function( - replica_base *, string_view /*remote cluster*/, string_view /*app*/)> + replica_base *, absl::string_view /*remote cluster*/, absl::string_view /*app*/)> mutation_duplicator::creator; // // diff --git a/src/replica/duplication/load_from_private_log.cpp b/src/replica/duplication/load_from_private_log.cpp index d3d88a075d..9bd35c9fc4 100644 --- a/src/replica/duplication/load_from_private_log.cpp +++ b/src/replica/duplication/load_from_private_log.cpp @@ -17,8 +17,10 @@ #include #include +#include #include +#include "absl/strings/string_view.h" #include "common/duplication_common.h" #include "duplication_types.h" #include "load_from_private_log.h" @@ -34,7 +36,6 @@ #include "utils/fail_point.h" #include "utils/fmt_logging.h" #include "utils/ports.h" -#include "utils/string_view.h" namespace dsn { namespace replication { @@ -96,13 +97,15 @@ void load_from_private_log::run() _duplicator->progress().confirmed_decree); repeat(1_s); - FAIL_POINT_INJECT_NOT_RETURN_F("duplication_sync_complete", [&](string_view s) -> void { - if (_duplicator->progress().confirmed_decree == invalid_decree) { - // set_confirmed_decree(9), the value must be equal (decree_start of - // `test_start_duplication` in `load_from_private_log_test.cpp`) -1 - _duplicator->update_progress(_duplicator->progress().set_confirmed_decree(9)); - } - }); + FAIL_POINT_INJECT_NOT_RETURN_F( + "duplication_sync_complete", [&](absl::string_view s) -> void { + if (_duplicator->progress().confirmed_decree == invalid_decree) { + // set_confirmed_decree(9), the value must be equal (decree_start of + // `test_start_duplication` in `load_from_private_log_test.cpp`) -1 + _duplicator->update_progress( + _duplicator->progress().set_confirmed_decree(9)); + } + }); return; } else { _mutation_batch.reset_mutation_buffer(_duplicator->progress().confirmed_decree); diff --git a/src/replica/duplication/mutation_batch.cpp b/src/replica/duplication/mutation_batch.cpp index 852a8ff127..4ab77ea69b 100644 --- a/src/replica/duplication/mutation_batch.cpp +++ b/src/replica/duplication/mutation_batch.cpp @@ -35,8 +35,7 @@ #include "utils/blob.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" -#include "utils/smart_pointers.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -149,8 +148,8 @@ mutation_batch::mutation_batch(replica_duplicator *r) : replica_base(r) // This helps for debugging. replica_base base( r->get_gpid(), std::string("mutation_batch@") + r->replica_name(), r->app_name()); - _mutation_buffer = - make_unique(&base, 0, PREPARE_LIST_NUM_ENTRIES, [this](mutation_ptr &mu) { + _mutation_buffer = std::make_unique( + &base, 0, PREPARE_LIST_NUM_ENTRIES, [this](mutation_ptr &mu) { // committer add_mutation_if_valid(mu, _start_decree); }); diff --git a/src/replica/duplication/mutation_duplicator.h b/src/replica/duplication/mutation_duplicator.h index a5b3a4df67..b1c29e00fa 100644 --- a/src/replica/duplication/mutation_duplicator.h +++ b/src/replica/duplication/mutation_duplicator.h @@ -68,7 +68,7 @@ class mutation_duplicator : public replica_base // Singleton creator of mutation_duplicator. static std::function( - replica_base *, string_view /*remote cluster*/, string_view /*app name*/)> + replica_base *, absl::string_view /*remote cluster*/, absl::string_view /*app name*/)> creator; explicit mutation_duplicator(replica_base *r) : replica_base(r) {} @@ -83,8 +83,8 @@ class mutation_duplicator : public replica_base pipeline::environment _env; }; -inline std::unique_ptr -new_mutation_duplicator(replica_base *r, string_view remote_cluster_address, string_view app) +inline std::unique_ptr new_mutation_duplicator( + replica_base *r, absl::string_view remote_cluster_address, absl::string_view app) { return mutation_duplicator::creator(r, remote_cluster_address, app); } diff --git a/src/replica/duplication/replica_follower.cpp b/src/replica/duplication/replica_follower.cpp index f5a29b94dd..1414930223 100644 --- a/src/replica/duplication/replica_follower.cpp +++ b/src/replica/duplication/replica_follower.cpp @@ -40,7 +40,7 @@ #include "utils/filesystem.h" #include "utils/fmt_logging.h" #include "utils/ports.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" namespace dsn { @@ -119,12 +119,13 @@ void replica_follower::async_duplicate_checkpoint_from_master_replica() RPC_CM_QUERY_PARTITION_CONFIG_BY_INDEX, 0, get_gpid().thread_hash()); dsn::marshall(msg, meta_config_request); rpc::call(meta_servers, msg, &_tracker, [&](error_code err, query_cfg_response &&resp) mutable { - FAIL_POINT_INJECT_F("duplicate_checkpoint_ok", [&](string_view s) -> void { + FAIL_POINT_INJECT_F("duplicate_checkpoint_ok", [&](absl::string_view s) -> void { _tracker.set_tasks_success(); return; }); - FAIL_POINT_INJECT_F("duplicate_checkpoint_failed", [&](string_view s) -> void { return; }); + FAIL_POINT_INJECT_F("duplicate_checkpoint_failed", + [&](absl::string_view s) -> void { return; }); if (update_master_replica_config(err, std::move(resp)) == ERR_OK) { copy_master_replica_checkpoint(); } @@ -247,7 +248,7 @@ void replica_follower::nfs_copy_remote_files(const rpc_address &remote_node, &_tracker, [&, remote_dir](error_code err, size_t size) mutable { FAIL_POINT_INJECT_NOT_RETURN_F("nfs_copy_ok", - [&](string_view s) -> void { err = ERR_OK; }); + [&](absl::string_view s) -> void { err = ERR_OK; }); if (dsn_unlikely(err != ERR_OK)) { LOG_ERROR_PREFIX("nfs copy master[{}] checkpoint failed: checkpoint = {}, err = {}", diff --git a/src/replica/duplication/test/duplication_test_base.h b/src/replica/duplication/test/duplication_test_base.h index 4152a9a370..eb914f38e0 100644 --- a/src/replica/duplication/test/duplication_test_base.h +++ b/src/replica/duplication/test/duplication_test_base.h @@ -34,7 +34,7 @@ class duplication_test_base : public replica_test_base public: duplication_test_base() { - mutation_duplicator::creator = [](replica_base *r, dsn::string_view, dsn::string_view) { + mutation_duplicator::creator = [](replica_base *r, absl::string_view, absl::string_view) { return std::make_unique(r); }; stub->_duplication_sync_timer = std::make_unique(stub.get()); diff --git a/src/replica/log_file_stream.h b/src/replica/log_file_stream.h index b31a5047c6..3b901aed73 100644 --- a/src/replica/log_file_stream.h +++ b/src/replica/log_file_stream.h @@ -66,7 +66,7 @@ class log_file::file_streamer fill_buffers(); } - // TODO(wutao1): use string_view instead of using blob. + // TODO(wutao1): use absl::string_view instead of using blob. // WARNING: the resulted blob is not guaranteed to be reference counted. // possible error_code: // ERR_OK result would always size as expected diff --git a/src/replica/mutation_log_replay.cpp b/src/replica/mutation_log_replay.cpp index e6f4afadd1..126d19cdfc 100644 --- a/src/replica/mutation_log_replay.cpp +++ b/src/replica/mutation_log_replay.cpp @@ -38,7 +38,7 @@ #include "utils/errors.h" #include "utils/fail_point.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -77,7 +77,7 @@ namespace replication { size_t start_offset, int64_t &end_offset) { - FAIL_POINT_INJECT_F("mutation_log_replay_block", [](string_view) -> error_s { + FAIL_POINT_INJECT_F("mutation_log_replay_block", [](absl::string_view) -> error_s { return error_s::make(ERR_INCOMPLETE_DATA, "mutation_log_replay_block"); }); diff --git a/src/replica/mutation_log_utils.cpp b/src/replica/mutation_log_utils.cpp index 46c32b4df9..9fed18ab8b 100644 --- a/src/replica/mutation_log_utils.cpp +++ b/src/replica/mutation_log_utils.cpp @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include #include #include @@ -36,9 +37,9 @@ namespace dsn { namespace replication { namespace log_utils { -/*extern*/ error_s open_read(string_view path, /*out*/ log_file_ptr &file) +/*extern*/ error_s open_read(absl::string_view path, /*out*/ log_file_ptr &file) { - FAIL_POINT_INJECT_F("open_read", [](string_view) -> error_s { + FAIL_POINT_INJECT_F("open_read", [](absl::string_view) -> error_s { return error_s::make(ERR_FILE_OPERATION_FAILED, "open_read"); }); @@ -52,7 +53,7 @@ namespace log_utils { /*extern*/ error_s list_all_files(const std::string &dir, /*out*/ std::vector &files) { - FAIL_POINT_INJECT_F("list_all_files", [](string_view) -> error_s { + FAIL_POINT_INJECT_F("list_all_files", [](absl::string_view) -> error_s { return error_s::make(ERR_FILE_OPERATION_FAILED, "list_all_files"); }); diff --git a/src/replica/mutation_log_utils.h b/src/replica/mutation_log_utils.h index 9673546f82..fafa4fbf56 100644 --- a/src/replica/mutation_log_utils.h +++ b/src/replica/mutation_log_utils.h @@ -34,13 +34,13 @@ #include "replica/mutation_log.h" #include "utils/autoref_ptr.h" #include "utils/errors.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { namespace log_utils { -extern error_s open_read(string_view path, /*out*/ log_file_ptr &file); +extern error_s open_read(absl::string_view path, /*out*/ log_file_ptr &file); extern error_s list_all_files(const std::string &dir, /*out*/ std::vector &files); diff --git a/src/replica/replica.cpp b/src/replica/replica.cpp index b99a3c4219..38cc478ad7 100644 --- a/src/replica/replica.cpp +++ b/src/replica/replica.cpp @@ -61,7 +61,6 @@ #include "utils/latency_tracer.h" #include "utils/ports.h" #include "utils/rand.h" -#include "utils/string_view.h" namespace dsn { namespace replication { diff --git a/src/replica/replica_base.h b/src/replica/replica_base.h index 64f294e87c..325f0905df 100644 --- a/src/replica/replica_base.h +++ b/src/replica/replica_base.h @@ -27,7 +27,7 @@ #pragma once #include "common/gpid.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -35,7 +35,7 @@ namespace replication { /// Base class for types that are one-instance-per-replica. struct replica_base { - replica_base(gpid id, string_view name, string_view app_name) + replica_base(gpid id, absl::string_view name, absl::string_view app_name) : _gpid(id), _name(name), _app_name(app_name) { } diff --git a/src/replica/replica_check.cpp b/src/replica/replica_check.cpp index bf4b0bff85..1565e55d96 100644 --- a/src/replica/replica_check.cpp +++ b/src/replica/replica_check.cpp @@ -67,7 +67,7 @@ #include "utils/fail_point.h" #include "utils/flags.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/thread_access_checker.h" namespace dsn { @@ -82,7 +82,7 @@ DSN_DECLARE_bool(empty_write_disabled); void replica::init_group_check() { - FAIL_POINT_INJECT_F("replica_init_group_check", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_init_group_check", [](absl::string_view) {}); _checker.only_one_thread_access(); @@ -102,7 +102,7 @@ void replica::init_group_check() void replica::broadcast_group_check() { - FAIL_POINT_INJECT_F("replica_broadcast_group_check", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_broadcast_group_check", [](absl::string_view) {}); CHECK_NOTNULL(_primary_states.group_check_task, ""); diff --git a/src/replica/replica_config.cpp b/src/replica/replica_config.cpp index db4d7f103f..ed438636f2 100644 --- a/src/replica/replica_config.cpp +++ b/src/replica/replica_config.cpp @@ -79,7 +79,7 @@ #include "utils/fail_point.h" #include "utils/fmt_logging.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" #include "utils/thread_access_checker.h" @@ -663,7 +663,7 @@ bool replica::is_same_ballot_status_change_allowed(partition_status::type olds, bool replica::update_local_configuration(const replica_configuration &config, bool same_ballot /* = false*/) { - FAIL_POINT_INJECT_F("replica_update_local_configuration", [=](dsn::string_view) -> bool { + FAIL_POINT_INJECT_F("replica_update_local_configuration", [=](absl::string_view) -> bool { auto old_status = status(); _config = config; LOG_INFO_PREFIX( diff --git a/src/replica/replica_disk_migrator.cpp b/src/replica/replica_disk_migrator.cpp index e1fecba808..0cd8a12ccc 100644 --- a/src/replica/replica_disk_migrator.cpp +++ b/src/replica/replica_disk_migrator.cpp @@ -34,7 +34,7 @@ #include "utils/fail_point.h" #include "utils/filesystem.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/thread_access_checker.h" namespace dsn { @@ -164,7 +164,7 @@ void replica_disk_migrator::migrate_replica(const replica_disk_migrate_request & // THREAD_POOL_REPLICATION_LONG bool replica_disk_migrator::init_target_dir(const replica_disk_migrate_request &req) { - FAIL_POINT_INJECT_F("init_target_dir", [this](string_view) -> bool { + FAIL_POINT_INJECT_F("init_target_dir", [this](absl::string_view) -> bool { reset_status(); return false; }); @@ -210,7 +210,7 @@ bool replica_disk_migrator::init_target_dir(const replica_disk_migrate_request & // THREAD_POOL_REPLICATION_LONG bool replica_disk_migrator::migrate_replica_checkpoint(const replica_disk_migrate_request &req) { - FAIL_POINT_INJECT_F("migrate_replica_checkpoint", [this](string_view) -> bool { + FAIL_POINT_INJECT_F("migrate_replica_checkpoint", [this](absl::string_view) -> bool { reset_status(); return false; }); @@ -246,7 +246,7 @@ bool replica_disk_migrator::migrate_replica_checkpoint(const replica_disk_migrat // THREAD_POOL_REPLICATION_LONG bool replica_disk_migrator::migrate_replica_app_info(const replica_disk_migrate_request &req) { - FAIL_POINT_INJECT_F("migrate_replica_app_info", [this](string_view) -> bool { + FAIL_POINT_INJECT_F("migrate_replica_app_info", [this](absl::string_view) -> bool { reset_status(); return false; }); diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index e1815b48bf..dc5a30899b 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -86,7 +86,7 @@ #include "utils/process_utils.h" #include "utils/rand.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" #include "utils/synchronize.h" #ifdef DSN_ENABLE_GPERF @@ -1925,7 +1925,7 @@ void replica_stub::flush_replicas_for_slog_gc(const replica_gc_info_map &replica bool mock_flush = false; FAIL_POINT_INJECT_NOT_RETURN_F( - "mock_flush_replicas_for_slog_gc", [&mock_flush, this, i](dsn::string_view str) { + "mock_flush_replicas_for_slog_gc", [&mock_flush, this, i](absl::string_view str) { CHECK(buf2bool(str, mock_flush), "invalid mock_flush_replicas_for_slog_gc toggle, should be true or false: {}", str); @@ -2167,7 +2167,7 @@ void replica_stub::open_replica( dsn::utils::filesystem::rename_path(origin_tmp_dir, origin_dir); rep = load_replica(origin_dn, origin_dir.c_str()); - FAIL_POINT_INJECT_F("mock_replica_load", [&](string_view) -> void {}); + FAIL_POINT_INJECT_F("mock_replica_load", [&](absl::string_view) -> void {}); } } } @@ -2309,7 +2309,8 @@ replica *replica_stub::new_replica(gpid gpid, replica *replica_stub::load_replica(dir_node *dn, const char *dir) { - FAIL_POINT_INJECT_F("mock_replica_load", [&](string_view) -> replica * { return nullptr; }); + FAIL_POINT_INJECT_F("mock_replica_load", + [&](absl::string_view) -> replica * { return nullptr; }); char splitters[] = {'\\', '/', 0}; std::string name = utils::get_last_component(std::string(dir), splitters); @@ -3017,7 +3018,7 @@ replica_ptr replica_stub::create_child_replica_if_not_found(gpid child_pid, const std::string &parent_dir) { FAIL_POINT_INJECT_F( - "replica_stub_create_child_replica_if_not_found", [=](dsn::string_view) -> replica_ptr { + "replica_stub_create_child_replica_if_not_found", [=](absl::string_view) -> replica_ptr { const auto dn = _fs_manager.create_child_replica_dir(app->app_type, child_pid, parent_dir); CHECK_NOTNULL(dn, ""); @@ -3062,7 +3063,8 @@ void replica_stub::split_replica_error_handler(gpid pid, local_execution handler dsn::error_code replica_stub::split_replica_exec(dsn::task_code code, gpid pid, local_execution handler) { - FAIL_POINT_INJECT_F("replica_stub_split_replica_exec", [](dsn::string_view) { return ERR_OK; }); + FAIL_POINT_INJECT_F("replica_stub_split_replica_exec", + [](absl::string_view) { return ERR_OK; }); replica_ptr replica = pid.get_app_id() == 0 ? nullptr : get_replica(pid); if (replica && handler) { tasking::enqueue(code, diff --git a/src/replica/replication_app_base.cpp b/src/replica/replication_app_base.cpp index 7bb4a7423b..6085bffc18 100644 --- a/src/replica/replication_app_base.cpp +++ b/src/replica/replication_app_base.cpp @@ -58,7 +58,7 @@ #include "utils/filesystem.h" #include "utils/fmt_logging.h" #include "utils/latency_tracer.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { @@ -345,7 +345,8 @@ int replication_app_base::on_batched_write_requests(int64_t decree, error_code replication_app_base::apply_mutation(const mutation *mu) { - FAIL_POINT_INJECT_F("replication_app_base_apply_mutation", [](string_view) { return ERR_OK; }); + FAIL_POINT_INJECT_F("replication_app_base_apply_mutation", + [](absl::string_view) { return ERR_OK; }); CHECK_EQ_PREFIX(mu->data.header.decree, last_committed_decree() + 1); CHECK_EQ_PREFIX(mu->data.updates.size(), mu->client_requests.size()); diff --git a/src/replica/split/replica_split_manager.cpp b/src/replica/split/replica_split_manager.cpp index 0c63a5ebf9..47825cf0da 100644 --- a/src/replica/split/replica_split_manager.cpp +++ b/src/replica/split/replica_split_manager.cpp @@ -48,7 +48,7 @@ #include "utils/filesystem.h" #include "utils/flags.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/thread_access_checker.h" namespace dsn { @@ -132,7 +132,7 @@ void replica_split_manager::child_init_replica(gpid parent_gpid, rpc_address primary_address, ballot init_ballot) // on child partition { - FAIL_POINT_INJECT_F("replica_child_init_replica", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_child_init_replica", [](absl::string_view) {}); if (status() != partition_status::PS_INACTIVE) { LOG_WARNING_PREFIX("wrong status({})", enum_to_string(status())); @@ -178,7 +178,7 @@ void replica_split_manager::child_init_replica(gpid parent_gpid, // ThreadPool: THREAD_POOL_REPLICATION void replica_split_manager::child_check_split_context() // on child partition { - FAIL_POINT_INJECT_F("replica_child_check_split_context", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_child_check_split_context", [](absl::string_view) {}); if (status() != partition_status::PS_PARTITION_SPLIT) { LOG_ERROR_PREFIX("wrong status({})", enum_to_string(status())); @@ -206,7 +206,7 @@ void replica_split_manager::child_check_split_context() // on child partition // ThreadPool: THREAD_POOL_REPLICATION bool replica_split_manager::parent_check_states() // on parent partition { - FAIL_POINT_INJECT_F("replica_parent_check_states", [](dsn::string_view) { return true; }); + FAIL_POINT_INJECT_F("replica_parent_check_states", [](absl::string_view) { return true; }); if (_split_status != split_status::SPLITTING || _child_init_ballot != get_ballot() || _child_gpid.get_app_id() == 0 || @@ -347,7 +347,7 @@ void replica_split_manager::child_learn_states(learn_state lstate, uint64_t total_file_size, decree last_committed_decree) // on child partition { - FAIL_POINT_INJECT_F("replica_child_learn_states", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_child_learn_states", [](absl::string_view) {}); if (status() != partition_status::PS_PARTITION_SPLIT) { LOG_ERROR_PREFIX("wrong status({})", enum_to_string(status())); @@ -415,7 +415,7 @@ replica_split_manager::child_apply_private_logs(std::vector plog_fi uint64_t total_file_size, decree last_committed_decree) // on child partition { - FAIL_POINT_INJECT_F("replica_child_apply_private_logs", [](dsn::string_view arg) { + FAIL_POINT_INJECT_F("replica_child_apply_private_logs", [](absl::string_view arg) { return error_code::try_get(arg.data(), ERR_OK); }); @@ -507,7 +507,7 @@ replica_split_manager::child_apply_private_logs(std::vector plog_fi // ThreadPool: THREAD_POOL_REPLICATION void replica_split_manager::child_catch_up_states() // on child partition { - FAIL_POINT_INJECT_F("replica_child_catch_up_states", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_child_catch_up_states", [](absl::string_view) {}); if (status() != partition_status::PS_PARTITION_SPLIT) { LOG_ERROR_PREFIX("wrong status, status is {}", enum_to_string(status())); @@ -572,7 +572,7 @@ void replica_split_manager::child_catch_up_states() // on child partition // ThreadPool: THREAD_POOL_REPLICATION void replica_split_manager::child_notify_catch_up() // on child partition { - FAIL_POINT_INJECT_F("replica_child_notify_catch_up", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_child_notify_catch_up", [](absl::string_view) {}); std::unique_ptr request = std::make_unique(); request->parent_gpid = _replica->_split_states.parent_gpid; @@ -689,7 +689,7 @@ void replica_split_manager::parent_handle_child_catch_up( // ThreadPool: THREAD_POOL_REPLICATION void replica_split_manager::parent_check_sync_point_commit(decree sync_point) // on primary parent { - FAIL_POINT_INJECT_F("replica_parent_check_sync_point_commit", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_parent_check_sync_point_commit", [](absl::string_view) {}); if (status() != partition_status::PS_PRIMARY) { LOG_ERROR_PREFIX("wrong status({})", enum_to_string(status())); parent_handle_split_error("check_sync_point_commit failed, primary changed", false); @@ -755,7 +755,7 @@ void replica_split_manager::parent_send_update_partition_count_request( int32_t new_partition_count, std::shared_ptr> ¬_replied_addresses) // on primary parent { - FAIL_POINT_INJECT_F("replica_parent_update_partition_count_request", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_parent_update_partition_count_request", [](absl::string_view) {}); CHECK_EQ_PREFIX(status(), partition_status::PS_PRIMARY); @@ -912,7 +912,7 @@ void replica_split_manager::on_update_child_group_partition_count_reply( // ThreadPool: THREAD_POOL_REPLICATION void replica_split_manager::register_child_on_meta(ballot b) // on primary parent { - FAIL_POINT_INJECT_F("replica_register_child_on_meta", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_register_child_on_meta", [](absl::string_view) {}); if (status() != partition_status::PS_PRIMARY || _split_status != split_status::SPLITTING) { LOG_ERROR_PREFIX( @@ -961,7 +961,7 @@ void replica_split_manager::register_child_on_meta(ballot b) // on primary paren void replica_split_manager::parent_send_register_request( const register_child_request &request) // on primary parent { - FAIL_POINT_INJECT_F("replica_parent_send_register_request", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_parent_send_register_request", [](absl::string_view) {}); CHECK_EQ_PREFIX(status(), partition_status::PS_INACTIVE); LOG_INFO_PREFIX( @@ -990,7 +990,7 @@ void replica_split_manager::on_register_child_on_meta_reply( const register_child_request &request, const register_child_response &response) // on primary parent { - FAIL_POINT_INJECT_F("replica_on_register_child_on_meta_reply", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_on_register_child_on_meta_reply", [](absl::string_view) {}); _replica->_checker.only_one_thread_access(); @@ -1464,7 +1464,7 @@ void replica_split_manager::primary_parent_handle_stop_split( void replica_split_manager::parent_send_notify_stop_request( split_status::type meta_split_status) // on primary parent { - FAIL_POINT_INJECT_F("replica_parent_send_notify_stop_request", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("replica_parent_send_notify_stop_request", [](absl::string_view) {}); rpc_address meta_address(_stub->_failure_detector->get_servers()); std::unique_ptr req = std::make_unique(); req->app_name = _replica->_app_info.app_name; diff --git a/src/replica/test/replica_test_base.h b/src/replica/test/replica_test_base.h index 17bb9adf14..9296e2a4e0 100644 --- a/src/replica/test/replica_test_base.h +++ b/src/replica/test/replica_test_base.h @@ -34,7 +34,6 @@ #include "test_util/test_util.h" #include "utils/errors.h" #include "utils/filesystem.h" -#include "utils/smart_pointers.h" namespace dsn { namespace replication { diff --git a/src/runtime/pipeline.h b/src/runtime/pipeline.h index 0fcf535ba9..e4dbcd8d84 100644 --- a/src/runtime/pipeline.h +++ b/src/runtime/pipeline.h @@ -19,11 +19,11 @@ #pragma once +#include #include "runtime/task/task_code.h" #include "runtime/task/task_tracker.h" #include "runtime/task/async_calls.h" #include "utils/chrono_literals.h" -#include "utils/absl/utility/utility.h" namespace dsn { namespace pipeline { diff --git a/src/runtime/ranger/ranger_resource_policy_manager.cpp b/src/runtime/ranger/ranger_resource_policy_manager.cpp index df3172b93b..4bc5ee54ff 100644 --- a/src/runtime/ranger/ranger_resource_policy_manager.cpp +++ b/src/runtime/ranger/ranger_resource_policy_manager.cpp @@ -54,7 +54,6 @@ #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/process_utils.h" -#include "utils/smart_pointers.h" #include "utils/strings.h" namespace dsn { @@ -581,7 +580,7 @@ dsn::error_code ranger_resource_policy_manager::sync_policies_to_app_envs() } std::string table_name = get_table_name_from_app_name(app.app_name); - auto req = dsn::make_unique(); + auto req = std::make_unique(); req->__set_app_name(app.app_name); req->__set_keys( {dsn::replication::replica_envs::REPLICA_ACCESS_CONTROLLER_RANGER_POLICIES}); diff --git a/src/runtime/rpc/rpc_address.cpp b/src/runtime/rpc/rpc_address.cpp index fd3987536b..1eb8b8c445 100644 --- a/src/runtime/rpc/rpc_address.cpp +++ b/src/runtime/rpc/rpc_address.cpp @@ -38,7 +38,7 @@ #include "utils/fmt_logging.h" #include "utils/ports.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" namespace dsn { @@ -80,7 +80,7 @@ bool rpc_address::is_site_local_address(uint32_t ip_net) /*static*/ bool rpc_address::is_docker_netcard(const char *netcard_interface, uint32_t ip_net) { - if (string_view(netcard_interface).find("docker") != string_view::npos) { + if (absl::string_view(netcard_interface).find("docker") != absl::string_view::npos) { return true; } uint32_t iphost = ntohl(ip_net); diff --git a/src/runtime/rpc/thrift_message_parser.cpp b/src/runtime/rpc/thrift_message_parser.cpp index e01d342d80..08bbfcb872 100644 --- a/src/runtime/rpc/thrift_message_parser.cpp +++ b/src/runtime/rpc/thrift_message_parser.cpp @@ -46,7 +46,7 @@ #include "utils/endians.h" #include "utils/fmt_logging.h" #include "utils/fmt_utils.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" namespace dsn { @@ -158,7 +158,7 @@ bool thrift_message_parser::parse_request_header(message_reader *reader, int &re } // The first 4 bytes is "THFT" - data_input input(buf); + data_input input(buf.to_string_view()); if (!utils::mequals(buf.data(), "THFT", 4)) { LOG_ERROR("hdr_type mismatch {}", message_parser::get_debug_string(buf.data())); read_next = -1; @@ -340,7 +340,7 @@ void thrift_message_parser::prepare_on_send(message_ex *msg) // first total length, but we don't know the length, so firstly we put a placeholder header_proto.writeI32(0); // then the error_message - header_proto.writeString(string_view(header->server.error_name)); + header_proto.writeString(absl::string_view(header->server.error_name)); // then the thrift message begin header_proto.writeMessageBegin( header->rpc_name, ::apache::thrift::protocol::T_REPLY, header->id); diff --git a/src/runtime/security/sasl_client_wrapper.cpp b/src/runtime/security/sasl_client_wrapper.cpp index ccf5b563ef..462f8db1be 100644 --- a/src/runtime/security/sasl_client_wrapper.cpp +++ b/src/runtime/security/sasl_client_wrapper.cpp @@ -23,7 +23,7 @@ #include "utils/error_code.h" #include "utils/fail_point.h" #include "utils/flags.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace security { @@ -32,7 +32,7 @@ DSN_DECLARE_string(service_name); error_s sasl_client_wrapper::init() { - FAIL_POINT_INJECT_F("sasl_client_wrapper_init", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_client_wrapper_init", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); @@ -44,7 +44,7 @@ error_s sasl_client_wrapper::init() error_s sasl_client_wrapper::start(const std::string &mechanism, const blob &input, blob &output) { - FAIL_POINT_INJECT_F("sasl_client_wrapper_start", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_client_wrapper_start", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); @@ -61,7 +61,7 @@ error_s sasl_client_wrapper::start(const std::string &mechanism, const blob &inp error_s sasl_client_wrapper::step(const blob &input, blob &output) { - FAIL_POINT_INJECT_F("sasl_client_wrapper_step", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_client_wrapper_step", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); diff --git a/src/runtime/security/sasl_server_wrapper.cpp b/src/runtime/security/sasl_server_wrapper.cpp index 5772071fcc..c8bed00f82 100644 --- a/src/runtime/security/sasl_server_wrapper.cpp +++ b/src/runtime/security/sasl_server_wrapper.cpp @@ -23,7 +23,7 @@ #include "utils/error_code.h" #include "utils/fail_point.h" #include "utils/flags.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace security { @@ -32,7 +32,7 @@ DSN_DECLARE_string(service_name); error_s sasl_server_wrapper::init() { - FAIL_POINT_INJECT_F("sasl_server_wrapper_init", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_server_wrapper_init", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); @@ -44,7 +44,7 @@ error_s sasl_server_wrapper::init() error_s sasl_server_wrapper::start(const std::string &mechanism, const blob &input, blob &output) { - FAIL_POINT_INJECT_F("sasl_server_wrapper_start", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_server_wrapper_start", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); @@ -60,7 +60,7 @@ error_s sasl_server_wrapper::start(const std::string &mechanism, const blob &inp error_s sasl_server_wrapper::step(const blob &input, blob &output) { - FAIL_POINT_INJECT_F("sasl_server_wrapper_step", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_server_wrapper_step", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); diff --git a/src/runtime/security/sasl_wrapper.cpp b/src/runtime/security/sasl_wrapper.cpp index 3c1054b1d7..14c28f7b95 100644 --- a/src/runtime/security/sasl_wrapper.cpp +++ b/src/runtime/security/sasl_wrapper.cpp @@ -23,7 +23,7 @@ #include "sasl_server_wrapper.h" #include "utils/error_code.h" #include "utils/fail_point.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace security { @@ -44,7 +44,7 @@ sasl_wrapper::~sasl_wrapper() error_s sasl_wrapper::retrieve_username(std::string &output) { - FAIL_POINT_INJECT_F("sasl_wrapper_retrieve_username", [](dsn::string_view str) { + FAIL_POINT_INJECT_F("sasl_wrapper_retrieve_username", [](absl::string_view str) { error_code err = error_code::try_get(str.data(), ERR_UNKNOWN); return error_s::make(err); }); diff --git a/src/runtime/task/task.h b/src/runtime/task/task.h index 53838d8196..4e2f70ed6e 100644 --- a/src/runtime/task/task.h +++ b/src/runtime/task/task.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include #include #include @@ -41,7 +42,6 @@ #include "runtime/task/task_code.h" #include "task_spec.h" #include "task_tracker.h" -#include "utils/absl/utility/utility.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" #include "utils/extensible_object.h" diff --git a/src/server/compaction_filter_rule.cpp b/src/server/compaction_filter_rule.cpp index f434f7a176..cf369da96b 100644 --- a/src/server/compaction_filter_rule.cpp +++ b/src/server/compaction_filter_rule.cpp @@ -22,14 +22,14 @@ #include "base/pegasus_utils.h" #include "base/pegasus_value_schema.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" namespace pegasus { namespace server { -bool string_pattern_match(dsn::string_view value, +bool string_pattern_match(absl::string_view value, string_match_type type, - dsn::string_view filter_pattern) + absl::string_view filter_pattern) { if (filter_pattern.empty()) return false; @@ -38,7 +38,7 @@ bool string_pattern_match(dsn::string_view value, switch (type) { case string_match_type::SMT_MATCH_ANYWHERE: - return value.find(filter_pattern) != dsn::string_view::npos; + return value.find(filter_pattern) != absl::string_view::npos; case string_match_type::SMT_MATCH_PREFIX: return dsn::utils::mequals(value.data(), filter_pattern.data(), filter_pattern.length()); case string_match_type::SMT_MATCH_POSTFIX: @@ -53,27 +53,27 @@ bool string_pattern_match(dsn::string_view value, hashkey_pattern_rule::hashkey_pattern_rule(uint32_t data_version) {} -bool hashkey_pattern_rule::match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const +bool hashkey_pattern_rule::match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const { return string_pattern_match(hash_key, match_type, pattern); } sortkey_pattern_rule::sortkey_pattern_rule(uint32_t data_version) {} -bool sortkey_pattern_rule::match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const +bool sortkey_pattern_rule::match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const { return string_pattern_match(sort_key, match_type, pattern); } ttl_range_rule::ttl_range_rule(uint32_t data_version) : data_version(data_version) {} -bool ttl_range_rule::match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const +bool ttl_range_rule::match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const { uint32_t expire_ts = pegasus_extract_expire_ts(data_version, existing_value); // if start_ttl and stop_ttl = 0, it means we want to delete keys which have no ttl diff --git a/src/server/compaction_filter_rule.h b/src/server/compaction_filter_rule.h index 14c157731a..be211ba6b0 100644 --- a/src/server/compaction_filter_rule.h +++ b/src/server/compaction_filter_rule.h @@ -30,7 +30,7 @@ #include "utils/enum_helper.h" #include "utils/factory_store.h" #include "utils/fmt_utils.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace pegasus { namespace server { @@ -76,9 +76,9 @@ class compaction_filter_rule // TODO(zhaoliwei): we can use `value_filed` to replace existing_value in the later, // after the refactor of value schema - virtual bool match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const = 0; + virtual bool match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const = 0; }; enum string_match_type @@ -102,9 +102,9 @@ class hashkey_pattern_rule : public compaction_filter_rule public: hashkey_pattern_rule(uint32_t data_version = VERSION_MAX); - bool match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const; + bool match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const; DEFINE_JSON_SERIALIZATION(pattern, match_type) private: @@ -124,9 +124,9 @@ class sortkey_pattern_rule : public compaction_filter_rule public: sortkey_pattern_rule(uint32_t data_version = VERSION_MAX); - bool match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const; + bool match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const; DEFINE_JSON_SERIALIZATION(pattern, match_type) private: @@ -144,9 +144,9 @@ class ttl_range_rule : public compaction_filter_rule public: explicit ttl_range_rule(uint32_t data_version); - bool match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const; + bool match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const; DEFINE_JSON_SERIALIZATION(start_ttl, stop_ttl) private: diff --git a/src/server/compaction_operation.cpp b/src/server/compaction_operation.cpp index 89abf5174d..5c139073c1 100644 --- a/src/server/compaction_operation.cpp +++ b/src/server/compaction_operation.cpp @@ -17,6 +17,7 @@ * under the License. */ +#include #include #include "base/pegasus_utils.h" @@ -29,9 +30,9 @@ namespace pegasus { namespace server { compaction_operation::~compaction_operation() = default; -bool compaction_operation::all_rules_match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const +bool compaction_operation::all_rules_match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const { if (rules.empty()) { return false; @@ -54,9 +55,9 @@ delete_key::delete_key(filter_rules &&rules, uint32_t data_version) delete_key::delete_key(uint32_t data_version) : compaction_operation(data_version) {} -bool delete_key::filter(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value, +bool delete_key::filter(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value, std::string *new_value, bool *value_changed) const { @@ -73,9 +74,9 @@ update_ttl::update_ttl(filter_rules &&rules, uint32_t data_version) update_ttl::update_ttl(uint32_t data_version) : compaction_operation(data_version) {} -bool update_ttl::filter(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value, +bool update_ttl::filter(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value, std::string *new_value, bool *value_changed) const { diff --git a/src/server/compaction_operation.h b/src/server/compaction_operation.h index c972c3675f..d7c9d811eb 100644 --- a/src/server/compaction_operation.h +++ b/src/server/compaction_operation.h @@ -21,17 +21,18 @@ #include #include +#include #include #include #include #include +#include "absl/strings/string_view.h" #include "common/json_helper.h" #include "compaction_filter_rule.h" #include "utils/blob.h" #include "utils/enum_helper.h" #include "utils/factory_store.h" -#include "utils/string_view.h" namespace pegasus { namespace server { @@ -74,18 +75,18 @@ class compaction_operation explicit compaction_operation(uint32_t data_version) : data_version(data_version) {} virtual ~compaction_operation() = 0; - bool all_rules_match(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value) const; + bool all_rules_match(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value) const; void set_rules(filter_rules &&rules); /** * @return false indicates that this key-value should be removed * If you want to modify the existing_value, you can pass it back through new_value and * value_changed needs to be set to true in this case. */ - virtual bool filter(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value, + virtual bool filter(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value, std::string *new_value, bool *value_changed) const = 0; @@ -105,9 +106,9 @@ class delete_key : public compaction_operation delete_key(filter_rules &&rules, uint32_t data_version); explicit delete_key(uint32_t data_version); - bool filter(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value, + bool filter(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value, std::string *new_value, bool *value_changed) const; @@ -153,9 +154,9 @@ class update_ttl : public compaction_operation update_ttl(filter_rules &&rules, uint32_t data_version); explicit update_ttl(uint32_t data_version); - bool filter(dsn::string_view hash_key, - dsn::string_view sort_key, - dsn::string_view existing_value, + bool filter(absl::string_view hash_key, + absl::string_view sort_key, + absl::string_view existing_value, std::string *new_value, bool *value_changed) const; DEFINE_JSON_SERIALIZATION(type, value) diff --git a/src/server/hotkey_collector.cpp b/src/server/hotkey_collector.cpp index 618c2c18ff..5fb5ad397a 100644 --- a/src/server/hotkey_collector.cpp +++ b/src/server/hotkey_collector.cpp @@ -17,6 +17,7 @@ #include "hotkey_collector.h" +#include #include // IWYU pragma: no_include #include @@ -128,7 +129,7 @@ find_outlier_index(const std::vector &captured_keys, int threshold, in // TODO: (Tangyanzhao) replace it to xxhash -/*extern*/ int get_bucket_id(dsn::string_view data, int bucket_num) +/*extern*/ int get_bucket_id(absl::string_view data, int bucket_num) { return static_cast(boost::hash_range(data.begin(), data.end()) % bucket_num); } @@ -344,7 +345,7 @@ hotkey_coarse_data_collector::hotkey_coarse_data_collector(replica_base *base, void hotkey_coarse_data_collector::capture_data(const dsn::blob &hash_key, uint64_t weight) { - _hash_buckets[get_bucket_id(hash_key, _hash_bucket_num)].fetch_add(weight); + _hash_buckets[get_bucket_id(hash_key.to_string_view(), _hash_bucket_num)].fetch_add(weight); } void hotkey_coarse_data_collector::analyse_data(detect_hotkey_result &result) @@ -386,7 +387,7 @@ void hotkey_fine_data_collector::change_target_bucket(int target_bucket_index) void hotkey_fine_data_collector::capture_data(const dsn::blob &hash_key, uint64_t weight) { - if (get_bucket_id(hash_key, _hash_bucket_num) != _target_bucket_index.load()) { + if (get_bucket_id(hash_key.to_string_view(), _hash_bucket_num) != _target_bucket_index.load()) { return; } // abandon the key if enqueue failed (possibly because not enough room to enqueue) @@ -397,7 +398,7 @@ struct blob_hash { std::size_t operator()(const dsn::blob &str) const { - dsn::string_view cp(str); + absl::string_view cp = str.to_string_view(); return boost::hash_range(cp.begin(), cp.end()); } }; @@ -406,7 +407,7 @@ struct blob_equal { std::size_t operator()(const dsn::blob &lhs, const dsn::blob &rhs) const { - return dsn::string_view(lhs) == dsn::string_view(rhs); + return lhs.to_string_view() == rhs.to_string_view(); } }; @@ -428,13 +429,13 @@ void hotkey_fine_data_collector::analyse_data(detect_hotkey_result &result) // the weight of all the collected hash keys std::vector weights; weights.reserve(hash_keys_weight.size()); - dsn::string_view weight_max_key; // the hashkey with the max weight - uint64_t weight_max = 0; // the max weight by far + absl::string_view weight_max_key; // the hashkey with the max weight + uint64_t weight_max = 0; // the max weight by far for (const auto &iter : hash_keys_weight) { weights.push_back(iter.second); if (iter.second > weight_max) { weight_max = iter.second; - weight_max_key = iter.first; + weight_max_key = iter.first.to_string_view(); } } diff --git a/src/server/hotkey_collector.h b/src/server/hotkey_collector.h index 1db427999c..826bf157b8 100644 --- a/src/server/hotkey_collector.h +++ b/src/server/hotkey_collector.h @@ -29,7 +29,7 @@ #include "replica/replica_base.h" #include "replica_admin_types.h" #include "utils/blob.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace pegasus { namespace server { @@ -50,7 +50,7 @@ struct detect_hotkey_result } }; -extern int get_bucket_id(dsn::string_view data, int bucket_num); +extern int get_bucket_id(absl::string_view data, int bucket_num); extern bool find_outlier_index(const std::vector &captured_keys, int threshold, int &hot_index); diff --git a/src/server/hotspot_partition_calculator.cpp b/src/server/hotspot_partition_calculator.cpp index 59ffce7b63..3792540332 100644 --- a/src/server/hotspot_partition_calculator.cpp +++ b/src/server/hotspot_partition_calculator.cpp @@ -33,7 +33,7 @@ #include "utils/fail_point.h" #include "utils/flags.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" struct row_data; @@ -212,7 +212,7 @@ void hotspot_partition_calculator::send_detect_hotkey_request( const dsn::replication::hotkey_type::type hotkey_type, const dsn::replication::detect_action::type action) { - FAIL_POINT_INJECT_F("send_detect_hotkey_request", [](dsn::string_view) {}); + FAIL_POINT_INJECT_F("send_detect_hotkey_request", [](absl::string_view) {}); int app_id = -1; int partition_count = -1; diff --git a/src/server/key_ttl_compaction_filter.h b/src/server/key_ttl_compaction_filter.h index d7448a5e23..8df418de9d 100644 --- a/src/server/key_ttl_compaction_filter.h +++ b/src/server/key_ttl_compaction_filter.h @@ -79,7 +79,7 @@ class KeyWithTTLCompactionFilter : public rocksdb::CompactionFilter } if (!_user_specified_operations.empty()) { - dsn::string_view value_view = utils::to_string_view(existing_value); + absl::string_view value_view = utils::to_string_view(existing_value); if (*value_changed) { value_view = *new_value; } @@ -92,7 +92,7 @@ class KeyWithTTLCompactionFilter : public rocksdb::CompactionFilter } bool user_specified_operation_filter(const rocksdb::Slice &key, - dsn::string_view existing_value, + absl::string_view existing_value, std::string *new_value, bool *value_changed) const { diff --git a/src/server/pegasus_mutation_duplicator.cpp b/src/server/pegasus_mutation_duplicator.cpp index 87c1adbf3e..8fc76e574a 100644 --- a/src/server/pegasus_mutation_duplicator.cpp +++ b/src/server/pegasus_mutation_duplicator.cpp @@ -19,6 +19,7 @@ #include "pegasus_mutation_duplicator.h" +#include #include #include #include @@ -55,10 +56,11 @@ struct replica_base; /// static definition of mutation_duplicator::creator. /*static*/ std::function( - replica_base *, string_view, string_view)> - mutation_duplicator::creator = [](replica_base *r, string_view remote, string_view app) { - return std::make_unique(r, remote, app); - }; + replica_base *, absl::string_view, absl::string_view)> + mutation_duplicator::creator = + [](replica_base *r, absl::string_view remote, absl::string_view app) { + return std::make_unique(r, remote, app); + }; } // namespace replication } // namespace dsn @@ -95,8 +97,8 @@ using namespace dsn::literals::chrono_literals; } pegasus_mutation_duplicator::pegasus_mutation_duplicator(dsn::replication::replica_base *r, - dsn::string_view remote_cluster, - dsn::string_view app) + absl::string_view remote_cluster, + absl::string_view app) : mutation_duplicator(r), _remote_cluster(remote_cluster) { // initialize pegasus-client when this class is first time used. diff --git a/src/server/pegasus_mutation_duplicator.h b/src/server/pegasus_mutation_duplicator.h index 2107cda5b0..b610e0c07e 100644 --- a/src/server/pegasus_mutation_duplicator.h +++ b/src/server/pegasus_mutation_duplicator.h @@ -32,7 +32,7 @@ #include "runtime/task/task_code.h" #include "runtime/task/task_tracker.h" #include "utils/chrono_literals.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/zlocks.h" namespace dsn { @@ -61,8 +61,8 @@ class pegasus_mutation_duplicator : public dsn::replication::mutation_duplicator public: pegasus_mutation_duplicator(dsn::replication::replica_base *r, - dsn::string_view remote_cluster, - dsn::string_view app); + absl::string_view remote_cluster, + absl::string_view app); void duplicate(mutation_tuple_set muts, callback cb) override; diff --git a/src/server/pegasus_server_impl.cpp b/src/server/pegasus_server_impl.cpp index 32d6b0e3ce..11a1d14db7 100644 --- a/src/server/pegasus_server_impl.cpp +++ b/src/server/pegasus_server_impl.cpp @@ -82,7 +82,7 @@ #include "utils/fmt_logging.h" #include "utils/ports.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" #include "utils/threadpool_code.h" #include "utils/token_bucket_throttling_controller.h" @@ -2303,7 +2303,8 @@ bool pegasus_server_impl::validate_filter(::dsn::apps::filter_type::type filter_ if (value.length() < filter_pattern.length()) return false; if (filter_type == ::dsn::apps::filter_type::FT_MATCH_ANYWHERE) { - return dsn::string_view(value).find(filter_pattern) != dsn::string_view::npos; + return value.to_string_view().find(filter_pattern.to_string_view()) != + absl::string_view::npos; } else if (filter_type == ::dsn::apps::filter_type::FT_MATCH_PREFIX) { return dsn::utils::mequals( value.data(), filter_pattern.data(), filter_pattern.length()); diff --git a/src/server/pegasus_write_service_impl.h b/src/server/pegasus_write_service_impl.h index fa4c44e4ab..f3227da145 100644 --- a/src/server/pegasus_write_service_impl.h +++ b/src/server/pegasus_write_service_impl.h @@ -101,7 +101,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base int empty_put(int64_t decree) { int err = - _rocksdb_wrapper->write_batch_put(decree, dsn::string_view(), dsn::string_view(), 0); + _rocksdb_wrapper->write_batch_put(decree, absl::string_view(), absl::string_view(), 0); auto cleanup = dsn::defer([this]() { _rocksdb_wrapper->clear_up_write_batch(); }); if (err != rocksdb::Status::kOk) { return err; @@ -133,8 +133,9 @@ class pegasus_write_service::impl : public dsn::replication::replica_base for (auto &kv : update.kvs) { resp.error = _rocksdb_wrapper->write_batch_put_ctx( ctx, - composite_raw_key(update.hash_key, kv.key), - kv.value, + composite_raw_key(update.hash_key.to_string_view(), kv.key.to_string_view()) + .to_string_view(), + kv.value.to_string_view(), static_cast(update.expire_ts_seconds)); if (resp.error) { return resp.error; @@ -166,7 +167,9 @@ class pegasus_write_service::impl : public dsn::replication::replica_base auto cleanup = dsn::defer([this]() { _rocksdb_wrapper->clear_up_write_batch(); }); for (auto &sort_key : update.sort_keys) { resp.error = _rocksdb_wrapper->write_batch_delete( - decree, composite_raw_key(update.hash_key, sort_key)); + decree, + composite_raw_key(update.hash_key.to_string_view(), sort_key.to_string_view()) + .to_string_view()); if (resp.error) { return resp.error; } @@ -186,7 +189,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base resp.decree = decree; resp.server = _primary_address; - dsn::string_view raw_key(update.key.data(), update.key.length()); + absl::string_view raw_key = update.key.to_string_view(); int64_t new_value = 0; uint32_t new_expire_ts = 0; db_get_context get_ctx; @@ -212,7 +215,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base new_value = update.increment; } else { int64_t old_value_int; - if (!dsn::buf2int64(old_value, old_value_int)) { + if (!dsn::buf2int64(old_value.to_string_view(), old_value_int)) { // invalid old value LOG_ERROR_PREFIX("incr failed: decree = {}, error = " "old value \"{}\" is not an integer or out of range", @@ -249,7 +252,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base auto cleanup = dsn::defer([this]() { _rocksdb_wrapper->clear_up_write_batch(); }); resp.error = _rocksdb_wrapper->write_batch_put( - decree, update.key, std::to_string(new_value), new_expire_ts); + decree, update.key.to_string_view(), std::to_string(new_value), new_expire_ts); if (resp.error) { return resp.error; } @@ -283,7 +286,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base pegasus_generate_key(check_key, update.hash_key, update.check_sort_key); db_get_context get_context; - dsn::string_view check_raw_key(check_key.data(), check_key.length()); + absl::string_view check_raw_key = check_key.to_string_view(); int err = _rocksdb_wrapper->get(check_raw_key, &get_context); if (err != rocksdb::Status::kOk) { // read check value failed @@ -329,13 +332,13 @@ class pegasus_write_service::impl : public dsn::replication::replica_base } resp.error = _rocksdb_wrapper->write_batch_put( decree, - set_key, - update.set_value, + set_key.to_string_view(), + update.set_value.to_string_view(), static_cast(update.set_expire_ts_seconds)); } else { // check not passed, write empty record to update rocksdb's last flushed decree resp.error = _rocksdb_wrapper->write_batch_put( - decree, dsn::string_view(), dsn::string_view(), 0); + decree, absl::string_view(), absl::string_view(), 0); } auto cleanup = dsn::defer([this]() { _rocksdb_wrapper->clear_up_write_batch(); }); @@ -403,7 +406,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base pegasus_generate_key(check_key, update.hash_key, update.check_sort_key); db_get_context get_context; - dsn::string_view check_raw_key(check_key.data(), check_key.length()); + absl::string_view check_raw_key = check_key.to_string_view(); int err = _rocksdb_wrapper->get(check_raw_key, &get_context); if (err != rocksdb::Status::kOk) { // read check value failed @@ -445,10 +448,13 @@ class pegasus_write_service::impl : public dsn::replication::replica_base pegasus_generate_key(key, update.hash_key, m.sort_key); if (m.operation == ::dsn::apps::mutate_operation::MO_PUT) { resp.error = _rocksdb_wrapper->write_batch_put( - decree, key, m.value, static_cast(m.set_expire_ts_seconds)); + decree, + key.to_string_view(), + m.value.to_string_view(), + static_cast(m.set_expire_ts_seconds)); } else { CHECK_EQ(m.operation, ::dsn::apps::mutate_operation::MO_DELETE); - resp.error = _rocksdb_wrapper->write_batch_delete(decree, key); + resp.error = _rocksdb_wrapper->write_batch_delete(decree, key.to_string_view()); } // in case of failure, cancel mutations @@ -458,7 +464,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base } else { // check not passed, write empty record to update rocksdb's last flushed decree resp.error = _rocksdb_wrapper->write_batch_put( - decree, dsn::string_view(), dsn::string_view(), 0); + decree, absl::string_view(), absl::string_view(), 0); } auto cleanup = dsn::defer([this]() { _rocksdb_wrapper->clear_up_write_batch(); }); @@ -521,15 +527,18 @@ class pegasus_write_service::impl : public dsn::replication::replica_base const dsn::apps::update_request &update, dsn::apps::update_response &resp) { - resp.error = _rocksdb_wrapper->write_batch_put_ctx( - ctx, update.key, update.value, static_cast(update.expire_ts_seconds)); + resp.error = + _rocksdb_wrapper->write_batch_put_ctx(ctx, + update.key.to_string_view(), + update.value.to_string_view(), + static_cast(update.expire_ts_seconds)); _update_responses.emplace_back(&resp); return resp.error; } int batch_remove(int64_t decree, const dsn::blob &key, dsn::apps::update_response &resp) { - resp.error = _rocksdb_wrapper->write_batch_delete(decree, key); + resp.error = _rocksdb_wrapper->write_batch_delete(decree, key.to_string_view()); _update_responses.emplace_back(&resp); return resp.error; } @@ -564,7 +573,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base _rocksdb_wrapper->clear_up_write_batch(); } - static dsn::blob composite_raw_key(dsn::string_view hash_key, dsn::string_view sort_key) + static dsn::blob composite_raw_key(absl::string_view hash_key, absl::string_view sort_key) { dsn::blob raw_key; pegasus_generate_key(raw_key, hash_key, sort_key); @@ -610,7 +619,8 @@ class pegasus_write_service::impl : public dsn::replication::replica_base if (value.length() < check_operand.length()) return false; if (check_type == ::dsn::apps::cas_check_type::CT_VALUE_MATCH_ANYWHERE) { - return dsn::string_view(value).find(check_operand) != dsn::string_view::npos; + return value.to_string_view().find(check_operand.to_string_view()) != + absl::string_view::npos; } else if (check_type == ::dsn::apps::cas_check_type::CT_VALUE_MATCH_PREFIX) { return dsn::utils::mequals( value.data(), check_operand.data(), check_operand.length()); @@ -627,7 +637,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base case ::dsn::apps::cas_check_type::CT_VALUE_BYTES_GREATER: { if (!value_exist) return false; - int c = dsn::string_view(value).compare(dsn::string_view(check_operand)); + int c = value.to_string_view().compare(check_operand.to_string_view()); if (c < 0) { return check_type <= ::dsn::apps::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL; } else if (c == 0) { @@ -645,7 +655,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base if (!value_exist) return false; int64_t check_value_int; - if (!dsn::buf2int64(value, check_value_int)) { + if (!dsn::buf2int64(value.to_string_view(), check_value_int)) { // invalid check value LOG_ERROR_PREFIX("check failed: decree = {}, error = " "check value \"{}\" is not an integer or out of range", @@ -655,7 +665,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base return false; } int64_t check_operand_int; - if (!dsn::buf2int64(check_operand, check_operand_int)) { + if (!dsn::buf2int64(check_operand.to_string_view(), check_operand_int)) { // invalid check operand LOG_ERROR_PREFIX("check failed: decree = {}, error = " "check operand \"{}\" is not an integer or out of range", diff --git a/src/server/rocksdb_wrapper.cpp b/src/server/rocksdb_wrapper.cpp index 3fe882a420..bf95f81c08 100644 --- a/src/server/rocksdb_wrapper.cpp +++ b/src/server/rocksdb_wrapper.cpp @@ -19,6 +19,7 @@ #include "rocksdb_wrapper.h" +#include #include #include #include @@ -71,9 +72,9 @@ rocksdb_wrapper::rocksdb_wrapper(pegasus_server_impl *server) _wt_opts->disableWAL = true; } -int rocksdb_wrapper::get(dsn::string_view raw_key, /*out*/ db_get_context *ctx) +int rocksdb_wrapper::get(absl::string_view raw_key, /*out*/ db_get_context *ctx) { - FAIL_POINT_INJECT_F("db_get", [](dsn::string_view) -> int { return FAIL_DB_GET; }); + FAIL_POINT_INJECT_F("db_get", [](absl::string_view) -> int { return FAIL_DB_GET; }); rocksdb::Status s = _db->Get(_rd_opts, utils::to_rocksdb_slice(raw_key), &(ctx->raw_value)); if (dsn_likely(s.ok())) { @@ -102,20 +103,20 @@ int rocksdb_wrapper::get(dsn::string_view raw_key, /*out*/ db_get_context *ctx) } int rocksdb_wrapper::write_batch_put(int64_t decree, - dsn::string_view raw_key, - dsn::string_view value, + absl::string_view raw_key, + absl::string_view value, uint32_t expire_sec) { return write_batch_put_ctx(db_write_context::empty(decree), raw_key, value, expire_sec); } int rocksdb_wrapper::write_batch_put_ctx(const db_write_context &ctx, - dsn::string_view raw_key, - dsn::string_view value, + absl::string_view raw_key, + absl::string_view value, uint32_t expire_sec) { FAIL_POINT_INJECT_F("db_write_batch_put", - [](dsn::string_view) -> int { return FAIL_DB_WRITE_BATCH_PUT; }); + [](absl::string_view) -> int { return FAIL_DB_WRITE_BATCH_PUT; }); uint64_t new_timetag = ctx.remote_timetag; if (!ctx.is_duplicated_write()) { // local write @@ -139,7 +140,7 @@ int rocksdb_wrapper::write_batch_put_ctx(const db_write_context &ctx, if (local_timetag >= new_timetag) { // ignore this stale update with lower timetag, // and write an empty record instead - raw_key = value = dsn::string_view(); + raw_key = value = absl::string_view(); } } } @@ -171,7 +172,7 @@ int rocksdb_wrapper::write(int64_t decree) return FLAGS_inject_write_error_for_test; } - FAIL_POINT_INJECT_F("db_write", [](dsn::string_view) -> int { return FAIL_DB_WRITE; }); + FAIL_POINT_INJECT_F("db_write", [](absl::string_view) -> int { return FAIL_DB_WRITE; }); rocksdb::Status status = _write_batch->Put(_meta_cf, meta_store::LAST_FLUSHED_DECREE, std::to_string(decree)); @@ -190,10 +191,10 @@ int rocksdb_wrapper::write(int64_t decree) return status.code(); } -int rocksdb_wrapper::write_batch_delete(int64_t decree, dsn::string_view raw_key) +int rocksdb_wrapper::write_batch_delete(int64_t decree, absl::string_view raw_key) { FAIL_POINT_INJECT_F("db_write_batch_delete", - [](dsn::string_view) -> int { return FAIL_DB_WRITE_BATCH_DELETE; }); + [](absl::string_view) -> int { return FAIL_DB_WRITE_BATCH_DELETE; }); rocksdb::Status s = _write_batch->Delete(utils::to_rocksdb_slice(raw_key)); if (dsn_unlikely(!s.ok())) { diff --git a/src/server/rocksdb_wrapper.h b/src/server/rocksdb_wrapper.h index e3c713512d..dcb27cb855 100644 --- a/src/server/rocksdb_wrapper.h +++ b/src/server/rocksdb_wrapper.h @@ -29,7 +29,7 @@ #include "pegasus_value_schema.h" #include "replica/replica_base.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace rocksdb { class ColumnFamilyHandle; @@ -57,18 +57,18 @@ class rocksdb_wrapper : public dsn::replication::replica_base /// is returned. /// \result ctx.expired=true if record expired. Still rocksdb::Status::kOk is returned. /// \result ctx.found=false if record is not found. Still rocksdb::Status::kOk is returned. - int get(dsn::string_view raw_key, /*out*/ db_get_context *ctx); + int get(absl::string_view raw_key, /*out*/ db_get_context *ctx); int write_batch_put(int64_t decree, - dsn::string_view raw_key, - dsn::string_view value, + absl::string_view raw_key, + absl::string_view value, uint32_t expire_sec); int write_batch_put_ctx(const db_write_context &ctx, - dsn::string_view raw_key, - dsn::string_view value, + absl::string_view raw_key, + absl::string_view value, uint32_t expire_sec); int write(int64_t decree); - int write_batch_delete(int64_t decree, dsn::string_view raw_key); + int write_batch_delete(int64_t decree, absl::string_view raw_key); void clear_up_write_batch(); int ingest_files(int64_t decree, const std::vector &sst_file_list, diff --git a/src/server/test/hotkey_collector_test.cpp b/src/server/test/hotkey_collector_test.cpp index 1316dad7ad..a888288352 100644 --- a/src/server/test/hotkey_collector_test.cpp +++ b/src/server/test/hotkey_collector_test.cpp @@ -17,6 +17,7 @@ #include "server/hotkey_collector.h" +#include #include #include #include @@ -69,7 +70,7 @@ TEST(hotkey_collector_public_func_test, get_bucket_id_test) { int bucket_id = -1; for (int i = 0; i < 1000000; i++) { - bucket_id = get_bucket_id(dsn::blob::create_from_bytes(generate_hash_key_by_random(false)), + bucket_id = get_bucket_id(absl::string_view(generate_hash_key_by_random(false)), FLAGS_hotkey_buckets_num); ASSERT_GE(bucket_id, 0); ASSERT_LT(bucket_id, FLAGS_hotkey_buckets_num); diff --git a/src/server/test/pegasus_mutation_duplicator_test.cpp b/src/server/test/pegasus_mutation_duplicator_test.cpp index 34062ab0cf..1bfa6c8900 100644 --- a/src/server/test/pegasus_mutation_duplicator_test.cpp +++ b/src/server/test/pegasus_mutation_duplicator_test.cpp @@ -19,6 +19,7 @@ #include "server/pegasus_mutation_duplicator.h" +#include #include #include #include diff --git a/src/server/test/pegasus_write_service_impl_test.cpp b/src/server/test/pegasus_write_service_impl_test.cpp index a64e1e9164..e03b733a66 100644 --- a/src/server/test/pegasus_write_service_impl_test.cpp +++ b/src/server/test/pegasus_write_service_impl_test.cpp @@ -34,7 +34,7 @@ #include "server/rocksdb_wrapper.h" #include "utils/blob.h" #include "utils/fail_point.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace pegasus { namespace server { @@ -55,7 +55,7 @@ class pegasus_write_service_impl_test : public pegasus_server_test_base _rocksdb_wrapper = _write_impl->_rocksdb_wrapper.get(); } - int db_get(dsn::string_view raw_key, db_get_context *get_ctx) + int db_get(absl::string_view raw_key, db_get_context *get_ctx) { return _rocksdb_wrapper->get(raw_key, get_ctx); } @@ -79,7 +79,7 @@ class incr_test : public pegasus_write_service_impl_test { pegasus_write_service_impl_test::SetUp(); pegasus::pegasus_generate_key( - req.key, dsn::string_view("hash_key"), dsn::string_view("sort_key")); + req.key, absl::string_view("hash_key"), absl::string_view("sort_key")); } dsn::apps::incr_request req; @@ -92,14 +92,14 @@ TEST_P(incr_test, incr_on_absent_record) { // ensure key is absent db_get_context get_ctx; - db_get(req.key, &get_ctx); + db_get(req.key.to_string_view(), &get_ctx); ASSERT_FALSE(get_ctx.found); req.increment = 100; _write_impl->incr(0, req, resp); ASSERT_EQ(resp.new_value, 100); - db_get(req.key, &get_ctx); + db_get(req.key.to_string_view(), &get_ctx); ASSERT_TRUE(get_ctx.found); } @@ -169,7 +169,7 @@ TEST_P(incr_test, incr_on_expire_record) // check whether the key is expired db_get_context get_ctx; - db_get(req.key, &get_ctx); + db_get(req.key.to_string_view(), &get_ctx); ASSERT_TRUE(get_ctx.expired); // incr the expired key @@ -178,7 +178,7 @@ TEST_P(incr_test, incr_on_expire_record) _write_impl->incr(0, req, resp); ASSERT_EQ(resp.new_value, 100); - db_get(req.key, &get_ctx); + db_get(req.key.to_string_view(), &get_ctx); ASSERT_TRUE(get_ctx.found); } } // namespace server diff --git a/src/server/test/rocksdb_wrapper_test.cpp b/src/server/test/rocksdb_wrapper_test.cpp index 34a9920509..de85810a02 100644 --- a/src/server/test/rocksdb_wrapper_test.cpp +++ b/src/server/test/rocksdb_wrapper_test.cpp @@ -39,7 +39,7 @@ #include "utils/blob.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace pegasus { namespace server { @@ -60,16 +60,16 @@ class rocksdb_wrapper_test : public pegasus_server_test_base _rocksdb_wrapper = _server_write->_write_svc->_impl->_rocksdb_wrapper.get(); pegasus::pegasus_generate_key( - _raw_key, dsn::string_view("hash_key"), dsn::string_view("sort_key")); + _raw_key, absl::string_view("hash_key"), absl::string_view("sort_key")); } void single_set(db_write_context write_ctx, dsn::blob raw_key, - dsn::string_view user_value, + absl::string_view user_value, int32_t expire_ts_seconds) { ASSERT_EQ(_rocksdb_wrapper->write_batch_put_ctx( - write_ctx, raw_key, user_value, expire_ts_seconds), + write_ctx, raw_key.to_string_view(), user_value, expire_ts_seconds), 0); ASSERT_EQ(_rocksdb_wrapper->write(0), 0); _rocksdb_wrapper->clear_up_write_batch(); @@ -93,7 +93,7 @@ class rocksdb_wrapper_test : public pegasus_server_test_base SetUp(); } - uint64_t read_timestamp_from(dsn::string_view raw_value) + uint64_t read_timestamp_from(absl::string_view raw_value) { uint64_t local_timetag = pegasus_extract_timetag(_rocksdb_wrapper->_pegasus_data_version, raw_value); @@ -107,7 +107,7 @@ TEST_P(rocksdb_wrapper_test, get) { // not found db_get_context get_ctx1; - _rocksdb_wrapper->get(_raw_key, &get_ctx1); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx1); ASSERT_FALSE(get_ctx1.found); // expired @@ -116,7 +116,7 @@ TEST_P(rocksdb_wrapper_test, get) std::string value = "abc"; single_set(write_ctx, _raw_key, value, expired_ts); db_get_context get_ctx2; - _rocksdb_wrapper->get(_raw_key, &get_ctx2); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx2); ASSERT_TRUE(get_ctx2.found); ASSERT_TRUE(get_ctx2.expired); ASSERT_EQ(get_ctx2.expire_ts, expired_ts); @@ -125,14 +125,14 @@ TEST_P(rocksdb_wrapper_test, get) expired_ts = INT32_MAX; db_get_context get_ctx3; single_set(write_ctx, _raw_key, value, expired_ts); - _rocksdb_wrapper->get(_raw_key, &get_ctx3); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx3); ASSERT_TRUE(get_ctx2.found); ASSERT_FALSE(get_ctx3.expired); ASSERT_EQ(get_ctx3.expire_ts, expired_ts); dsn::blob user_value; pegasus_extract_user_data( _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx3.raw_value), user_value); - ASSERT_EQ(user_value, value); + ASSERT_EQ(user_value.to_string(), value); } TEST_P(rocksdb_wrapper_test, put_verify_timetag) @@ -147,14 +147,14 @@ TEST_P(rocksdb_wrapper_test, put_verify_timetag) single_set(ctx, _raw_key, value, 0); db_get_context get_ctx1; - _rocksdb_wrapper->get(_raw_key, &get_ctx1); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx1); ASSERT_TRUE(get_ctx1.found); ASSERT_FALSE(get_ctx1.expired); ASSERT_EQ(read_timestamp_from(get_ctx1.raw_value), timestamp); dsn::blob user_value; pegasus_extract_user_data( _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx1.raw_value), user_value); - ASSERT_EQ(user_value, value); + ASSERT_EQ(user_value.to_string(), value); /// insert timestamp 15, which overwrites the previous record timestamp = 15; @@ -163,13 +163,13 @@ TEST_P(rocksdb_wrapper_test, put_verify_timetag) single_set(ctx, _raw_key, value, 0); db_get_context get_ctx2; - _rocksdb_wrapper->get(_raw_key, &get_ctx2); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx2); ASSERT_TRUE(get_ctx2.found); ASSERT_FALSE(get_ctx2.expired); ASSERT_EQ(read_timestamp_from(get_ctx2.raw_value), timestamp); pegasus_extract_user_data( _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx2.raw_value), user_value); - ASSERT_EQ(user_value, value); + ASSERT_EQ(user_value.to_string(), value); /// insert timestamp 15 from remote, which will overwrite the previous record, /// since its cluster id is larger (current cluster_id=1) @@ -180,13 +180,13 @@ TEST_P(rocksdb_wrapper_test, put_verify_timetag) single_set(ctx, _raw_key, value, 0); db_get_context get_ctx3; - _rocksdb_wrapper->get(_raw_key, &get_ctx3); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx3); ASSERT_TRUE(get_ctx3.found); ASSERT_FALSE(get_ctx3.expired); ASSERT_EQ(read_timestamp_from(get_ctx3.raw_value), timestamp); pegasus_extract_user_data( _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx3.raw_value), user_value); - ASSERT_EQ(user_value, value); + ASSERT_EQ(user_value.to_string(), value); /// write retry single_set(ctx, _raw_key, value, 0); @@ -199,13 +199,13 @@ TEST_P(rocksdb_wrapper_test, put_verify_timetag) single_set(ctx, _raw_key, value, 0); db_get_context get_ctx4; - _rocksdb_wrapper->get(_raw_key, &get_ctx4); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx4); ASSERT_TRUE(get_ctx4.found); ASSERT_FALSE(get_ctx4.expired); ASSERT_EQ(read_timestamp_from(get_ctx4.raw_value), timestamp); pegasus_extract_user_data( _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx4.raw_value), user_value); - ASSERT_EQ(user_value, value); + ASSERT_EQ(user_value.to_string(), value); // write retry single_set(ctx, _raw_key, value, 0); @@ -224,13 +224,13 @@ TEST_P(rocksdb_wrapper_test, verify_timetag_compatible_with_version_0) single_set(ctx, _raw_key, value, 0); db_get_context get_ctx; - _rocksdb_wrapper->get(_raw_key, &get_ctx); + _rocksdb_wrapper->get(_raw_key.to_string_view(), &get_ctx); ASSERT_TRUE(get_ctx.found); ASSERT_FALSE(get_ctx.expired); dsn::blob user_value; pegasus_extract_user_data( _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx.raw_value), user_value); - ASSERT_EQ(user_value, value); + ASSERT_EQ(user_value.to_string(), value); } } // namespace server } // namespace pegasus diff --git a/src/shell/command_helper.h b/src/shell/command_helper.h index 585a64f9c0..3b030a1fc8 100644 --- a/src/shell/command_helper.h +++ b/src/shell/command_helper.h @@ -50,7 +50,7 @@ #include "remote_cmd/remote_command.h" #include "tools/mutation_log_tool.h" #include "utils/fmt_utils.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" #include "utils/synchronize.h" #include "utils/time_utils.h" @@ -253,7 +253,7 @@ inline bool validate_filter(pegasus::pegasus_client::filter_type filter_type, if (value.length() < filter_pattern.length()) return false; if (filter_type == pegasus::pegasus_client::FT_MATCH_ANYWHERE) { - return dsn::string_view(value).find(filter_pattern) != dsn::string_view::npos; + return absl::string_view(value).find(filter_pattern) != absl::string_view::npos; } else if (filter_type == pegasus::pegasus_client::FT_MATCH_PREFIX) { return dsn::utils::mequals( value.data(), filter_pattern.data(), filter_pattern.length()); diff --git a/src/shell/command_output.h b/src/shell/command_output.h index 737f558b57..f78d62da10 100644 --- a/src/shell/command_output.h +++ b/src/shell/command_output.h @@ -18,7 +18,6 @@ */ #include "shell/commands.h" -#include "utils/smart_pointers.h" class command_output { diff --git a/src/shell/commands.h b/src/shell/commands.h index 1245f1d3af..a5faa1b713 100644 --- a/src/shell/commands.h +++ b/src/shell/commands.h @@ -29,7 +29,7 @@ #include "utils/filesystem.h" #include "utils/output_utils.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "client/replication_ddl_client.h" #include "tools/mutation_log_tool.h" diff --git a/src/utils/absl/base/internal/invoke.h b/src/utils/absl/base/internal/invoke.h deleted file mode 100644 index b05724ac58..0000000000 --- a/src/utils/absl/base/internal/invoke.h +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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. -// -// absl::base_internal::Invoke(f, args...) is an implementation of -// INVOKE(f, args...) from section [func.require] of the C++ standard. -// -// [func.require] -// Define INVOKE (f, t1, t2, ..., tN) as follows: -// 1. (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T -// and t1 is an object of type T or a reference to an object of type T or a -// reference to an object of a type derived from T; -// 2. ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a -// class T and t1 is not one of the types described in the previous item; -// 3. t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is -// an object of type T or a reference to an object of type T or a reference -// to an object of a type derived from T; -// 4. (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 -// is not one of the types described in the previous item; -// 5. f(t1, t2, ..., tN) in all other cases. -// -// The implementation is SFINAE-friendly: substitution failure within Invoke() -// isn't an error. - -#ifndef ABSL_BASE_INTERNAL_INVOKE_H_ -#define ABSL_BASE_INTERNAL_INVOKE_H_ - -#include -#include -#include - -// The following code is internal implementation detail. See the comment at the -// top of this file for the API documentation. - -// make namespace absl internal of dsn to solve redefine error with absl in s2geometry -namespace dsn { -namespace absl { -namespace base_internal { - -// The five classes below each implement one of the clauses from the definition -// of INVOKE. The inner class template Accept checks whether the -// clause is applicable; static function template Invoke(f, args...) does the -// invocation. -// -// By separating the clause selection logic from invocation we make sure that -// Invoke() does exactly what the standard says. - -template -struct StrippedAccept -{ - template - struct Accept - : Derived::template AcceptImpl< - typename std::remove_cv::type>::type...> - { - }; -}; - -// (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T -// and t1 is an object of type T or a reference to an object of type T or a -// reference to an object of a type derived from T. -struct MemFunAndRef : StrippedAccept -{ - template - struct AcceptImpl : std::false_type - { - }; - - template - struct AcceptImpl : std::is_base_of - { - }; - - template - struct AcceptImpl : std::is_base_of - { - }; - - template - static decltype((std::declval().*std::declval())(std::declval()...)) - Invoke(MemFun &&mem_fun, Obj &&obj, Args &&... args) - { - return (std::forward(obj).*std::forward(mem_fun))(std::forward(args)...); - } -}; - -// ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a -// class T and t1 is not one of the types described in the previous item. -struct MemFunAndPtr : StrippedAccept -{ - template - struct AcceptImpl : std::false_type - { - }; - - template - struct AcceptImpl - : std::integral_constant::value> - { - }; - - template - struct AcceptImpl - : std::integral_constant::value> - { - }; - - template - static decltype(((*std::declval()).*std::declval())(std::declval()...)) - Invoke(MemFun &&mem_fun, Ptr &&ptr, Args &&... args) - { - return ((*std::forward(ptr)).* - std::forward(mem_fun))(std::forward(args)...); - } -}; - -// t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is -// an object of type T or a reference to an object of type T or a reference -// to an object of a type derived from T. -struct DataMemAndRef : StrippedAccept -{ - template - struct AcceptImpl : std::false_type - { - }; - - template - struct AcceptImpl : std::is_base_of - { - }; - - template - static decltype(std::declval().*std::declval()) Invoke(DataMem &&data_mem, - Ref &&ref) - { - return std::forward(ref).*std::forward(data_mem); - } -}; - -// (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 -// is not one of the types described in the previous item. -struct DataMemAndPtr : StrippedAccept -{ - template - struct AcceptImpl : std::false_type - { - }; - - template - struct AcceptImpl : std::integral_constant::value> - { - }; - - template - static decltype((*std::declval()).*std::declval()) Invoke(DataMem &&data_mem, - Ptr &&ptr) - { - return (*std::forward(ptr)).*std::forward(data_mem); - } -}; - -// f(t1, t2, ..., tN) in all other cases. -struct Callable -{ - // Callable doesn't have Accept because it's the last clause that gets picked - // when none of the previous clauses are applicable. - template - static decltype(std::declval()(std::declval()...)) Invoke(F &&f, Args &&... args) - { - return std::forward(f)(std::forward(args)...); - } -}; - -// Resolves to the first matching clause. -template -struct Invoker -{ - typedef typename std::conditional< - MemFunAndRef::Accept::value, - MemFunAndRef, - typename std::conditional< - MemFunAndPtr::Accept::value, - MemFunAndPtr, - typename std::conditional< - DataMemAndRef::Accept::value, - DataMemAndRef, - typename std::conditional::value, - DataMemAndPtr, - Callable>::type>::type>::type>::type type; -}; - -// The result type of Invoke. -template -using InvokeT = - decltype(Invoker::type::Invoke(std::declval(), std::declval()...)); - -// Invoke(f, args...) is an implementation of INVOKE(f, args...) from section -// [func.require] of the C++ standard. -template -InvokeT Invoke(F &&f, Args &&... args) -{ - return Invoker::type::Invoke(std::forward(f), std::forward(args)...); -} -} // namespace base_internal -} // namespace absl -} // namespace dsn - -#endif // ABSL_BASE_INTERNAL_INVOKE_H_ diff --git a/src/utils/absl/utility/utility.h b/src/utils/absl/utility/utility.h deleted file mode 100644 index 10f03b1e8c..0000000000 --- a/src/utils/absl/utility/utility.h +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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. -// -// This header file contains C++11 versions of standard header -// abstractions available within C++14 and C++17, and are designed to be drop-in -// replacement for code compliant with C++14 and C++17. -// -// The following abstractions are defined: -// -// * integer_sequence == std::integer_sequence -// * index_sequence == std::index_sequence -// * make_integer_sequence == std::make_integer_sequence -// * make_index_sequence == std::make_index_sequence -// * index_sequence_for == std::index_sequence_for -// * apply == std::apply -// -// This header file also provides the tag types `in_place_t`, `in_place_type_t`, -// and `in_place_index_t`, as well as the constant `in_place`, and -// `constexpr` `std::move()` and `std::forward()` implementations in C++11. -// -// References: -// -// http://en.cppreference.com/w/cpp/utility/integer_sequence -// http://en.cppreference.com/w/cpp/utility/apply -// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html -// - -#ifndef ABSL_UTILITY_UTILITY_H_ -#define ABSL_UTILITY_UTILITY_H_ - -#include -#include -#include -#include - -#include "utils/absl/base/internal/invoke.h" - -// make namespace absl internal of dsn to solve redefine error with absl in s2geometry -namespace dsn { -namespace absl { - -// integer_sequence -// -// Class template representing a compile-time integer sequence. An instantiation -// of `integer_sequence` has a sequence of integers encoded in its -// type through its template arguments (which is a common need when -// working with C++11 variadic templates). `absl::integer_sequence` is designed -// to be a drop-in replacement for C++14's `std::integer_sequence`. -// -// Example: -// -// template< class T, T... Ints > -// void user_function(integer_sequence); -// -// int main() -// { -// // user_function's `T` will be deduced to `int` and `Ints...` -// // will be deduced to `0, 1, 2, 3, 4`. -// user_function(make_integer_sequence()); -// } -template -struct integer_sequence -{ - using value_type = T; - static constexpr size_t size() noexcept { return sizeof...(Ints); } -}; - -// index_sequence -// -// A helper template for an `integer_sequence` of `size_t`, -// `absl::index_sequence` is designed to be a drop-in replacement for C++14's -// `std::index_sequence`. -template -using index_sequence = integer_sequence; - -namespace utility_internal { - -template -struct Extend; - -// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. -template -struct Extend, SeqSize, 0> -{ - using type = integer_sequence; -}; - -template -struct Extend, SeqSize, 1> -{ - using type = integer_sequence; -}; - -// Recursion helper for 'make_integer_sequence'. -// 'Gen::type' is an alias for 'integer_sequence'. -template -struct Gen -{ - using type = typename Extend::type, N / 2, N % 2>::type; -}; - -template -struct Gen -{ - using type = integer_sequence; -}; - -} // namespace utility_internal - -// Compile-time sequences of integers - -// make_integer_sequence -// -// This template alias is equivalent to -// `integer_sequence`, and is designed to be a drop-in -// replacement for C++14's `std::make_integer_sequence`. -template -using make_integer_sequence = typename utility_internal::Gen::type; - -// make_index_sequence -// -// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, -// and is designed to be a drop-in replacement for C++14's -// `std::make_index_sequence`. -template -using make_index_sequence = make_integer_sequence; - -// index_sequence_for -// -// Converts a typename pack into an index sequence of the same length, and -// is designed to be a drop-in replacement for C++14's -// `std::index_sequence_for()` -template -using index_sequence_for = make_index_sequence; - -namespace utility_internal { -// Helper method for expanding tuple into a called method. -template -auto apply_helper(Functor &&functor, Tuple &&t, index_sequence) - -> decltype(absl::base_internal::Invoke(std::forward(functor), - std::get(std::forward(t))...)) -{ - return absl::base_internal::Invoke(std::forward(functor), - std::get(std::forward(t))...); -} - -} // namespace utility_internal - -// apply -// -// Invokes a Callable using elements of a tuple as its arguments. -// Each element of the tuple corresponds to an argument of the call (in order). -// Both the Callable argument and the tuple argument are perfect-forwarded. -// For member-function Callables, the first tuple element acts as the `this` -// pointer. `absl::apply` is designed to be a drop-in replacement for C++17's -// `std::apply`. Unlike C++17's `std::apply`, this is not currently `constexpr`. -// -// Example: -// -// class Foo{void Bar(int);}; -// void user_function(int, std::string); -// void user_function(std::unique_ptr); -// -// int main() -// { -// std::tuple tuple1(42, "bar"); -// // Invokes the user function overload on int, std::string. -// absl::apply(&user_function, tuple1); -// -// auto foo = absl::make_unique(); -// std::tuple tuple2(foo.get(), 42); -// // Invokes the method Bar on foo with one argument 42. -// absl::apply(&Foo::Bar, foo.get(), 42); -// -// std::tuple> tuple3(absl::make_unique()); -// // Invokes the user function that takes ownership of the unique -// // pointer. -// absl::apply(&user_function, std::move(tuple)); -// } -template -auto apply(Functor &&functor, Tuple &&t) -> decltype(utility_internal::apply_helper( - std::forward(functor), - std::forward(t), - absl::make_index_sequence< - std::tuple_size::type>::value>{})) -{ - return utility_internal::apply_helper( - std::forward(functor), - std::forward(t), - absl::make_index_sequence< - std::tuple_size::type>::value>{}); -} -} // namespace absl -} // namespace dsn - -#endif // ABSL_UTILITY_UTILITY_H_ diff --git a/src/utils/binary_writer.h b/src/utils/binary_writer.h index 8ddfa2648d..eb33adf8ae 100644 --- a/src/utils/binary_writer.h +++ b/src/utils/binary_writer.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include diff --git a/src/utils/blob.h b/src/utils/blob.h index 2e6cf06d48..29b24f6191 100644 --- a/src/utils/blob.h +++ b/src/utils/blob.h @@ -29,6 +29,7 @@ #include #include +#include "absl/strings/string_view.h" #include #include @@ -57,7 +58,7 @@ class blob { } - /// NOTE: Use dsn::string_view whenever possible. + /// NOTE: Use absl::string_view whenever possible. /// blob is designed for shared buffer, never use it as constant view. /// Maybe we could deprecate this function in the future. blob(const char *buffer, int offset, unsigned int length) @@ -98,7 +99,7 @@ class blob _length = length; } - /// Deprecated. Use dsn::string_view whenever possible. + /// Deprecated. Use absl::string_view whenever possible. void assign(const char *buffer, int offset, unsigned int length) { _holder = nullptr; @@ -157,6 +158,8 @@ class blob return std::string(_data, _length); } + absl::string_view to_string_view() const { return absl::string_view(_data, _length); } + uint32_t read(::apache::thrift::protocol::TProtocol *iprot); uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; diff --git a/src/utils/endians.h b/src/utils/endians.h index 7b6d0465d2..f41a4b7759 100644 --- a/src/utils/endians.h +++ b/src/utils/endians.h @@ -23,7 +23,7 @@ #include "api_utilities.h" #include "fmt_logging.h" #include "ports.h" -#include "string_view.h" +#include "absl/strings/string_view.h" namespace dsn { @@ -108,7 +108,7 @@ class data_output class data_input { public: - explicit data_input(string_view s) : _p(s.data()), _size(s.size()) {} + explicit data_input(absl::string_view s) : _p(s.data()), _size(s.size()) {} uint8_t read_u8() { return read_unsigned(); } @@ -118,7 +118,7 @@ class data_input uint64_t read_u64() { return read_unsigned(); } - string_view read_str() { return {_p, _size}; } + absl::string_view read_str() { return {_p, _size}; } void skip(size_t sz) { diff --git a/src/utils/errors.h b/src/utils/errors.h index ce36befca9..e8ac9aee91 100644 --- a/src/utils/errors.h +++ b/src/utils/errors.h @@ -33,8 +33,7 @@ #include "utils/fmt_logging.h" #include "utils/fmt_utils.h" #include "utils/ports.h" -#include "utils/smart_pointers.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { @@ -73,7 +72,7 @@ class error_s error_s(error_s &&rhs) noexcept = default; error_s &operator=(error_s &&) noexcept = default; - static error_s make(error_code code, dsn::string_view reason) { return error_s(code, reason); } + static error_s make(error_code code, absl::string_view reason) { return error_s(code, reason); } static error_s make(error_code code) { @@ -146,14 +145,14 @@ class error_s } private: - error_s(error_code code, dsn::string_view msg) noexcept : _info(new error_info(code, msg)) {} + error_s(error_code code, absl::string_view msg) noexcept : _info(new error_info(code, msg)) {} struct error_info { error_code code; std::string msg; // TODO(wutao1): use raw char* to improve performance? - error_info(error_code c, dsn::string_view s) : code(c), msg(s) {} + error_info(error_code c, absl::string_view s) : code(c), msg(s) {} }; void copy(const error_s &rhs) diff --git a/src/utils/fail_point.cpp b/src/utils/fail_point.cpp index 571e16d18c..75287d6dd1 100644 --- a/src/utils/fail_point.cpp +++ b/src/utils/fail_point.cpp @@ -48,14 +48,14 @@ #include "utils/fail_point.h" #include "utils/fmt_logging.h" #include "utils/rand.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace fail { static fail_point_registry REGISTRY; -/*extern*/ const std::string *eval(string_view name) +/*extern*/ const std::string *eval(absl::string_view name) { fail_point *p = REGISTRY.try_get(name); if (!p) { @@ -81,7 +81,7 @@ inline const char *task_type_to_string(fail_point::task_type t) } } -/*extern*/ void cfg(string_view name, string_view action) +/*extern*/ void cfg(absl::string_view name, absl::string_view action) { fail_point &p = REGISTRY.create_if_not_exists(name); p.set_action(action); @@ -103,14 +103,14 @@ inline const char *task_type_to_string(fail_point::task_type t) _S_FAIL_POINT_ENABLED = false; } -void fail_point::set_action(string_view action) +void fail_point::set_action(absl::string_view action) { if (!parse_from_string(action)) { LOG_FATAL("unrecognized command: {}", action); } } -bool fail_point::parse_from_string(string_view action) +bool fail_point::parse_from_string(absl::string_view action) { _max_cnt = -1; _freq = 100; diff --git a/src/utils/fail_point.h b/src/utils/fail_point.h index 8157c8f277..663dcbd5a3 100644 --- a/src/utils/fail_point.h +++ b/src/utils/fail_point.h @@ -36,7 +36,7 @@ #include #include "utils/ports.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" // The only entry to define a fail point with `return` function: lambda function must be // return non-void type. When a fail point is defined, it's referenced via the name. @@ -75,14 +75,14 @@ namespace dsn { namespace fail { -extern const std::string *eval(dsn::string_view name); +extern const std::string *eval(absl::string_view name); /// Set new actions to a fail point at runtime. /// The format of an action is `[p%][cnt*]task[(arg)]`. `p%` is the expected probability that /// the action is triggered, and `cnt*` is the max times the action can be triggered. /// For example, `20%3*print(still alive!)` means the fail point has 20% chance to print a /// message "still alive!". And the message will be printed at most 3 times. -extern void cfg(dsn::string_view name, dsn::string_view action); +extern void cfg(absl::string_view name, absl::string_view action); extern void setup(); diff --git a/src/utils/fail_point_impl.h b/src/utils/fail_point_impl.h index 22212e41d9..75ad2ef399 100644 --- a/src/utils/fail_point_impl.h +++ b/src/utils/fail_point_impl.h @@ -61,11 +61,11 @@ struct fail_point Void, }; - void set_action(string_view action); + void set_action(absl::string_view action); const std::string *eval(); - explicit fail_point(string_view name) : _name(name) {} + explicit fail_point(absl::string_view name) : _name(name) {} /// for test only fail_point(task_type t, std::string arg, int freq, int max_cnt) @@ -76,7 +76,7 @@ struct fail_point /// for test only fail_point() = default; - bool parse_from_string(string_view action); + bool parse_from_string(absl::string_view action); friend inline bool operator==(const fail_point &p1, const fail_point &p2) { @@ -103,7 +103,7 @@ USER_DEFINED_ENUM_FORMATTER(fail_point::task_type) struct fail_point_registry { - fail_point &create_if_not_exists(string_view name) + fail_point &create_if_not_exists(absl::string_view name) { std::lock_guard guard(_mu); @@ -111,7 +111,7 @@ struct fail_point_registry return it->second; } - fail_point *try_get(string_view name) + fail_point *try_get(absl::string_view name) { std::lock_guard guard(_mu); diff --git a/src/utils/filesystem.cpp b/src/utils/filesystem.cpp index 48528e61fd..9f3d773805 100644 --- a/src/utils/filesystem.cpp +++ b/src/utils/filesystem.cpp @@ -57,7 +57,7 @@ #include "utils/fmt_logging.h" #include "utils/ports.h" #include "utils/safe_strerror_posix.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #define getcwd_ getcwd #define rmdir_ rmdir @@ -637,9 +637,9 @@ error_code get_process_image_path(int pid, std::string &path) bool get_disk_space_info(const std::string &path, disk_space_info &info) { - FAIL_POINT_INJECT_F("filesystem_get_disk_space_info", [&info](string_view str) { + FAIL_POINT_INJECT_F("filesystem_get_disk_space_info", [&info](absl::string_view str) { info.capacity = 100 * 1024 * 1024; - if (str.find("insufficient") != string_view::npos) { + if (str.find("insufficient") != absl::string_view::npos) { info.available = 512 * 1024; } else { info.available = 50 * 1024 * 1024; @@ -839,11 +839,11 @@ bool verify_file_size(const std::string &fname, FileDataType type, const int64_t bool create_directory(const std::string &path, std::string &absolute_path, std::string &err_msg) { - FAIL_POINT_INJECT_F("filesystem_create_directory", [path](string_view str) { + FAIL_POINT_INJECT_F("filesystem_create_directory", [path](absl::string_view str) { // when str contains 'false', and path contains broken_disk_dir, mock create fail(return // false) std::string broken_disk_dir = "disk1"; - return str.find("false") == string_view::npos || + return str.find("false") == absl::string_view::npos || path.find(broken_disk_dir) == std::string::npos; }); @@ -860,11 +860,11 @@ bool create_directory(const std::string &path, std::string &absolute_path, std:: bool check_dir_rw(const std::string &path, std::string &err_msg) { - FAIL_POINT_INJECT_F("filesystem_check_dir_rw", [path](string_view str) { + FAIL_POINT_INJECT_F("filesystem_check_dir_rw", [path](absl::string_view str) { // when str contains 'false', and path contains broken_disk_dir, mock check fail(return // false) std::string broken_disk_dir = "disk1"; - return str.find("false") == string_view::npos || + return str.find("false") == absl::string_view::npos || path.find(broken_disk_dir) == std::string::npos; }); diff --git a/src/utils/join_point.h b/src/utils/join_point.h index e095cf4970..1fd45fafd4 100644 --- a/src/utils/join_point.h +++ b/src/utils/join_point.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include @@ -33,8 +34,6 @@ #include #include -#include "utils/absl/utility/utility.h" - namespace dsn { // A join_point instance is a set of lambdas with the identical function signature. diff --git a/src/utils/memutil.h b/src/utils/memutil.h deleted file mode 100644 index f53d322471..0000000000 --- a/src/utils/memutil.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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 - -namespace dsn { -namespace strings_internal { - -// This is significantly faster for case-sensitive matches with very -// few possible matches. See unit test for benchmarks. -const char *memmatch(const char *phaystack, size_t haylen, const char *pneedle, size_t neelen); - -} // namespace strings_internal -} // namespace dsn diff --git a/src/utils/metrics.cpp b/src/utils/metrics.cpp index b5800d3cd1..a0cc1ead4c 100644 --- a/src/utils/metrics.cpp +++ b/src/utils/metrics.cpp @@ -17,6 +17,7 @@ #include "utils/metrics.h" +#include #include #include #include diff --git a/src/utils/metrics.h b/src/utils/metrics.h index 75afc31d89..d3e0c8a5ac 100644 --- a/src/utils/metrics.h +++ b/src/utils/metrics.h @@ -50,7 +50,7 @@ #include "utils/nth_element.h" #include "utils/ports.h" #include "utils/singleton.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/synchronize.h" namespace boost { @@ -576,22 +576,22 @@ class metric_prototype public: struct ctor_args { - const string_view entity_type; + const absl::string_view entity_type; const metric_type type; - const string_view name; + const absl::string_view name; const metric_unit unit; - const string_view desc; + const absl::string_view desc; }; - string_view entity_type() const { return _args.entity_type; } + absl::string_view entity_type() const { return _args.entity_type; } metric_type type() const { return _args.type; } - string_view name() const { return _args.name; } + absl::string_view name() const { return _args.name; } metric_unit unit() const { return _args.unit; } - string_view description() const { return _args.desc; } + absl::string_view description() const { return _args.desc; } protected: explicit metric_prototype(const ctor_args &args); diff --git a/src/utils/simple_logger.cpp b/src/utils/simple_logger.cpp index f4c90789a8..afcaf2031d 100644 --- a/src/utils/simple_logger.cpp +++ b/src/utils/simple_logger.cpp @@ -44,7 +44,7 @@ #include "utils/ports.h" #include "utils/process_utils.h" #include "utils/string_conv.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" #include "utils/strings.h" #include "utils/time_utils.h" @@ -105,7 +105,7 @@ inline void process_fatal_log(dsn_log_level_t log_level) } bool coredump = true; - FAIL_POINT_INJECT_NOT_RETURN_F("coredump_for_fatal_log", [&coredump](dsn::string_view str) { + FAIL_POINT_INJECT_NOT_RETURN_F("coredump_for_fatal_log", [&coredump](absl::string_view str) { CHECK(buf2bool(str, coredump), "invalid coredump toggle for fatal log, should be true or false: {}", str); diff --git a/src/utils/smart_pointers.h b/src/utils/smart_pointers.h deleted file mode 100644 index 62e8423e8c..0000000000 --- a/src/utils/smart_pointers.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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 -#include - -namespace dsn { - -namespace memory_internal { - -// Traits to select proper overload and return type for `absl::make_unique<>`. -template -struct MakeUniqueResult -{ - using scalar = std::unique_ptr; -}; -template -struct MakeUniqueResult -{ - using array = std::unique_ptr; -}; -template -struct MakeUniqueResult -{ - using invalid = void; -}; - -} // namespace memory_internal - -#if __cplusplus >= 201402L || defined(_MSC_VER) -using std::make_unique; -#else -// ----------------------------------------------------------------------------- -// Function Template: std::make_unique() -// ----------------------------------------------------------------------------- -// -// Creates a `std::unique_ptr<>`, while avoiding issues creating temporaries -// during the construction process. `absl::make_unique<>` also avoids redundant -// type declarations, by avoiding the need to explicitly use the `new` operator. -// -// This implementation of `absl::make_unique<>` is designed for C++11 code and -// will be replaced in C++14 by the equivalent `std::make_unique<>` abstraction. -// `absl::make_unique<>` is designed to be 100% compatible with -// `std::make_unique<>` so that the eventual migration will involve a simple -// rename operation. -// -// For more background on why `std::unique_ptr(new T(a,b))` is problematic, -// see Herb Sutter's explanation on -// (Exception-Safe Function Calls)[http://herbsutter.com/gotw/_102/]. -// (In general, reviewers should treat `new T(a,b)` with scrutiny.) -// -// Example usage: -// -// auto p = std::make_unique(args...); // 'p' is a std::unique_ptr -// auto pa = std::make_unique(5); // 'pa' is a std::unique_ptr -// -// Three overloads of `absl::make_unique` are required: -// -// - For non-array T: -// -// Allocates a T with `new T(std::forward args...)`, -// forwarding all `args` to T's constructor. -// Returns a `std::unique_ptr` owning that object. -// -// - For an array of unknown bounds T[]: -// -// `absl::make_unique<>` will allocate an array T of type U[] with -// `new U[n]()` and return a `std::unique_ptr` owning that array. -// -// Note that 'U[n]()' is different from 'U[n]', and elements will be -// value-initialized. Note as well that `std::unique_ptr` will perform its -// own destruction of the array elements upon leaving scope, even though -// the array [] does not have a default destructor. -// -// NOTE: an array of unknown bounds T[] may still be (and often will be) -// initialized to have a size, and will still use this overload. E.g: -// -// auto my_array = absl::make_unique(10); -// -// - For an array of known bounds T[N]: -// -// `absl::make_unique<>` is deleted (like with `std::make_unique<>`) as -// this overload is not useful. -// -// NOTE: an array of known bounds T[N] is not considered a useful -// construction, and may cause undefined behavior in templates. E.g: -// -// auto my_array = absl::make_unique(); -// -// In those cases, of course, you can still use the overload above and -// simply initialize it to its desired size: -// -// auto my_array = absl::make_unique(10); - -// `absl::make_unique` overload for non-array types. -template -typename memory_internal::MakeUniqueResult::scalar std::make_unique(Args &&... args) -{ - return std::unique_ptr(new T(std::forward(args)...)); -} - -// `absl::make_unique` overload for an array T[] of unknown bounds. -// The array allocation needs to use the `new T[size]` form and cannot take -// element constructor arguments. The `std::unique_ptr` will manage destructing -// these array elements. -template -typename memory_internal::MakeUniqueResult::array std::make_unique(size_t n) -{ - return std::unique_ptr(new typename std::remove_extent::type[n]); -} - -// `absl::make_unique` overload for an array T[N] of known bounds. -// This construction will be rejected. -template -typename memory_internal::MakeUniqueResult::invalid -std::make_unique(Args &&... /* args */) = delete; -#endif - -} // namespace dsn diff --git a/src/utils/string_conv.h b/src/utils/string_conv.h index 35a5ca8b3c..1418e0925c 100644 --- a/src/utils/string_conv.h +++ b/src/utils/string_conv.h @@ -27,14 +27,14 @@ #include #include -#include "string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace internal { template -bool buf2signed(string_view buf, T &result) +bool buf2signed(absl::string_view buf, T &result) { static_assert(std::is_signed::value, "buf2signed works only with signed integer"); @@ -65,7 +65,7 @@ bool buf2signed(string_view buf, T &result) } template -bool buf2unsigned(string_view buf, T &result) +bool buf2unsigned(absl::string_view buf, T &result) { static_assert(std::is_unsigned::value, "buf2unsigned works only with unsigned integer"); @@ -104,27 +104,27 @@ bool buf2unsigned(string_view buf, T &result) /// buf2*: `result` will keep unmodified if false is returned. -inline bool buf2int32(string_view buf, int32_t &result) +inline bool buf2int32(absl::string_view buf, int32_t &result) { return internal::buf2signed(buf, result); } -inline bool buf2int64(string_view buf, int64_t &result) +inline bool buf2int64(absl::string_view buf, int64_t &result) { return internal::buf2signed(buf, result); } -inline bool buf2uint32(string_view buf, uint32_t &result) +inline bool buf2uint32(absl::string_view buf, uint32_t &result) { return internal::buf2unsigned(buf, result); } -inline bool buf2uint64(string_view buf, uint64_t &result) +inline bool buf2uint64(absl::string_view buf, uint64_t &result) { return internal::buf2unsigned(buf, result); } -inline bool buf2bool(string_view buf, bool &result, bool ignore_case = true) +inline bool buf2bool(absl::string_view buf, bool &result, bool ignore_case = true) { std::string data(buf.data(), buf.length()); if (ignore_case) { @@ -141,7 +141,7 @@ inline bool buf2bool(string_view buf, bool &result, bool ignore_case = true) return false; } -inline bool buf2double(string_view buf, double &result) +inline bool buf2double(absl::string_view buf, double &result) { if (buf.empty()) { return false; diff --git a/src/utils/string_view.cpp b/src/utils/string_view.cpp deleted file mode 100644 index d49fffea56..0000000000 --- a/src/utils/string_view.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// -// Copyright 2017 The Abseil Authors. -// -// 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 "string_view.h" - -#include - -#include "utils/blob.h" -#include "utils/memutil.h" -#include "utils/strings.h" - -namespace dsn { - -namespace { -void WritePadding(std::ostream &o, size_t pad) -{ - char fill_buf[32]; - memset(fill_buf, o.fill(), sizeof(fill_buf)); - while (pad) { - size_t n = std::min(pad, sizeof(fill_buf)); - o.write(fill_buf, n); - pad -= n; - } -} -} // namespace - -std::ostream &operator<<(std::ostream &o, string_view piece) -{ - std::ostream::sentry sentry(o); - if (sentry) { - size_t lpad = 0; - size_t rpad = 0; - if (static_cast(o.width()) > piece.size()) { - size_t pad = o.width() - piece.size(); - if ((o.flags() & o.adjustfield) == o.left) { - rpad = pad; - } else { - lpad = pad; - } - } - if (lpad) - WritePadding(o, lpad); - o.write(piece.data(), piece.size()); - if (rpad) - WritePadding(o, rpad); - o.width(0); - } - return o; -} - -namespace strings_internal { - -// This is significantly faster for case-sensitive matches with very -// few possible matches. See unit test for benchmarks. -const char *memmatch(const char *phaystack, size_t haylen, const char *pneedle, size_t neelen) -{ - if (0 == neelen) { - return phaystack; // even if haylen is 0 - } - if (haylen < neelen) - return nullptr; - - const char *match; - const char *hayend = phaystack + haylen - neelen + 1; - // A static cast is used here to work around the fact that memchr returns - // a void* on Posix-compliant systems and const void* on Windows. - while ((match = static_cast(memchr(phaystack, pneedle[0], hayend - phaystack)))) { - if (utils::mequals(match, pneedle, neelen)) { - return match; - } else { - phaystack = match + 1; - } - } - return nullptr; -} - -} // namespace strings_internal - -string_view::string_view(const blob &buf) noexcept : ptr_(buf.data()), length_(buf.length()) {} - -string_view::size_type string_view::find(string_view s, size_type pos) const noexcept -{ - if (empty() || pos > length_) { - if (empty() && pos == 0 && s.empty()) - return 0; - return npos; - } - const char *result = strings_internal::memmatch(ptr_ + pos, length_ - pos, s.ptr_, s.length_); - return result ? result - ptr_ : npos; -} - -constexpr string_view::size_type string_view::npos; - -} // namespace dsn diff --git a/src/utils/string_view.h b/src/utils/string_view.h deleted file mode 100644 index ab867448e2..0000000000 --- a/src/utils/string_view.h +++ /dev/null @@ -1,433 +0,0 @@ -// -// Copyright 2017 The Abseil Authors. -// -// 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. -// -// ----------------------------------------------------------------------------- -// File: string_view.h -// ----------------------------------------------------------------------------- -// -// This file contains the definition of the `dsn::string_view` class. A -// `string_view` points to a contiguous span of characters, often part or all of -// another `std::string`, double-quoted std::string literal, character array, or even -// another `string_view`. -// -// This `dsn::string_view` abstraction is designed to be a drop-in -// replacement for the C++17 `std::string_view` abstraction. -// -// --- Update(wutao1) --- -// -// This file is copied from abseil, though in order to maintain minimum -// dependencies, abseil is not an requirement. The dsn::string_view consists of only -// a subset of functions that std::string_view and absl::string_view provide, so that -// we can keep this module lightweight, but reducing the generality. -// -// dsn::string_view also supports view of dsn::blob, which can also function as a constant -// view. However, dsn::blob is not designed to be as lightweight as dsn::string_view -// since it requires at least one atomic operation to copy the internal std::shared_ptr. -// So in most cases where data is immutable, using dsn::string_view over dsn::blob will -// be a more proper choice. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "ports.h" -#include "utils/fmt_utils.h" - -namespace dsn { - -class blob; - -// dsn::string_view -// -// A `string_view` provides a lightweight view into the std::string data provided by -// a `std::string`, double-quoted std::string literal, character array, or even -// another `string_view`. A `string_view` does *not* own the std::string to which it -// points, and that data cannot be modified through the view. -// -// You can use `string_view` as a function or method parameter anywhere a -// parameter can receive a double-quoted std::string literal, `const char*`, -// `std::string`, or another `absl::string_view` argument with no need to copy -// the std::string data. Systematic use of `string_view` within function arguments -// reduces data copies and `strlen()` calls. -// -// Because of its small size, prefer passing `string_view` by value: -// -// void MyFunction(dsn::string_view arg); -// -// If circumstances require, you may also pass one by const reference: -// -// void MyFunction(const dsn::string_view& arg); // not preferred -// -// Passing by value generates slightly smaller code for many architectures. -// -// In either case, the source data of the `string_view` must outlive the -// `string_view` itself. -// -// A `string_view` is also suitable for local variables if you know that the -// lifetime of the underlying object is longer than the lifetime of your -// `string_view` variable. However, beware of binding a `string_view` to a -// temporary value: -// -// // BAD use of string_view: lifetime problem -// dsn::string_view sv = obj.ReturnAString(); -// -// // GOOD use of string_view: str outlives sv -// std::string str = obj.ReturnAString(); -// dsn::string_view sv = str; -// -// Due to lifetime issues, a `string_view` is sometimes a poor choice for a -// return value and usually a poor choice for a data member. If you do use a -// `string_view` this way, it is your responsibility to ensure that the object -// pointed to by the `string_view` outlives the `string_view`. -// -// A `string_view` may represent a whole std::string or just part of a std::string. For -// example, when splitting a std::string, `std::vector` is a -// natural data type for the output. -// -// -// When constructed from a source which is nul-terminated, the `string_view` -// itself will not include the nul-terminator unless a specific size (including -// the nul) is passed to the constructor. As a result, common idioms that work -// on nul-terminated strings do not work on `string_view` objects. If you write -// code that scans a `string_view`, you must check its length rather than test -// for nul, for example. Note, however, that nuls may still be embedded within -// a `string_view` explicitly. -// -// You may create a null `string_view` in two ways: -// -// dsn::string_view sv(); -// dsn::string_view sv(nullptr, 0); -// -// For the above, `sv.data() == nullptr`, `sv.length() == 0`, and -// `sv.empty() == true`. Also, if you create a `string_view` with a non-null -// pointer then `sv.data() != nullptr`. Thus, you can use `string_view()` to -// signal an undefined value that is different from other `string_view` values -// in a similar fashion to how `const char* p1 = nullptr;` is different from -// `const char* p2 = "";`. However, in practice, it is not recommended to rely -// on this behavior. -// -// Be careful not to confuse a null `string_view` with an empty one. A null -// `string_view` is an empty `string_view`, but some empty `string_view`s are -// not null. Prefer checking for emptiness over checking for null. -// -// There are many ways to create an empty string_view: -// -// const char* nullcp = nullptr; -// // string_view.size() will return 0 in all cases. -// dsn::string_view(); -// dsn::string_view(nullcp, 0); -// dsn::string_view(""); -// dsn::string_view("", 0); -// dsn::string_view("abcdef", 0); -// dsn::string_view("abcdef" + 6, 0); -// -// All empty `string_view` objects whether null or not, are equal: -// -// dsn::string_view() == dsn::string_view("", 0) -// dsn::string_view(nullptr, 0) == dsn::string_view("abcdef"+6, 0) -class string_view -{ -public: - using traits_type = std::char_traits; - using value_type = char; - using pointer = char *; - using const_pointer = const char *; - using reference = char &; - using const_reference = const char &; - using const_iterator = const char *; - using iterator = const_iterator; - using const_reverse_iterator = std::reverse_iterator; - using reverse_iterator = const_reverse_iterator; - using size_type = size_t; - using difference_type = std::ptrdiff_t; - - static constexpr size_type npos = static_cast(-1); - - // Null `string_view` constructor - constexpr string_view() noexcept : ptr_(nullptr), length_(0) {} - - // Implicit constructors - - template - string_view( // NOLINT(runtime/explicit) - const std::basic_string, Allocator> &str) noexcept - : ptr_(str.data()), length_(str.size()) - { - } - - string_view(const blob &buf) noexcept; // NOLINT(runtime/explicit) - - constexpr string_view(const char *str) // NOLINT(runtime/explicit) - : ptr_(str), - length_(str == nullptr ? 0 : traits_type::length(str)) - { - } - - // Implicit constructor of a `string_view` from a `const char*` and length. - constexpr string_view(const char *data, size_type len) : ptr_(data), length_(len) {} - - // NOTE: Harmlessly omitted to work around gdb bug. - // constexpr string_view(const string_view&) noexcept = default; - // string_view& operator=(const string_view&) noexcept = default; - - // Iterators - - // string_view::begin() - // - // Returns an iterator pointing to the first character at the beginning of the - // `string_view`, or `end()` if the `string_view` is empty. - constexpr const_iterator begin() const noexcept { return ptr_; } - - // string_view::end() - // - // Returns an iterator pointing just beyond the last character at the end of - // the `string_view`. This iterator acts as a placeholder; attempting to - // access it results in undefined behavior. - constexpr const_iterator end() const noexcept { return ptr_ + length_; } - - // string_view::cbegin() - // - // Returns a const iterator pointing to the first character at the beginning - // of the `string_view`, or `end()` if the `string_view` is empty. - constexpr const_iterator cbegin() const noexcept { return begin(); } - - // string_view::cend() - // - // Returns a const iterator pointing just beyond the last character at the end - // of the `string_view`. This pointer acts as a placeholder; attempting to - // access its element results in undefined behavior. - constexpr const_iterator cend() const noexcept { return end(); } - - // string_view::rbegin() - // - // Returns a reverse iterator pointing to the last character at the end of the - // `string_view`, or `rend()` if the `string_view` is empty. - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } - - // string_view::rend() - // - // Returns a reverse iterator pointing just before the first character at the - // beginning of the `string_view`. This pointer acts as a placeholder; - // attempting to access its element results in undefined behavior. - const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } - - // string_view::crbegin() - // - // Returns a const reverse iterator pointing to the last character at the end - // of the `string_view`, or `crend()` if the `string_view` is empty. - const_reverse_iterator crbegin() const noexcept { return rbegin(); } - - // string_view::crend() - // - // Returns a const reverse iterator pointing just before the first character - // at the beginning of the `string_view`. This pointer acts as a placeholder; - // attempting to access its element results in undefined behavior. - const_reverse_iterator crend() const noexcept { return rend(); } - - // Capacity Utilities - - // string_view::size() - // - // Returns the number of characters in the `string_view`. - constexpr size_type size() const noexcept { return length_; } - - // string_view::length() - // - // Returns the number of characters in the `string_view`. Alias for `size()`. - constexpr size_type length() const noexcept { return size(); } - - // string_view::empty() - // - // Checks if the `string_view` is empty (refers to no characters). - constexpr bool empty() const noexcept { return length_ == 0; } - - // std::string:view::operator[] - // - // Returns the ith element of an `string_view` using the array operator. - // Note that this operator does not perform any bounds checking. - constexpr const_reference operator[](size_type i) const { return ptr_[i]; } - - // string_view::front() - // - // Returns the first element of a `string_view`. - constexpr const_reference front() const { return ptr_[0]; } - - // string_view::back() - // - // Returns the last element of a `string_view`. - constexpr const_reference back() const { return ptr_[size() - 1]; } - - // string_view::data() - // - // Returns a pointer to the underlying character array (which is of course - // stored elsewhere). Note that `string_view::data()` may contain embedded nul - // characters, but the returned buffer may or may not be nul-terminated; - // therefore, do not pass `data()` to a routine that expects a nul-terminated - // std::string. - constexpr const_pointer data() const noexcept { return ptr_; } - - // Modifiers - - // string_view::remove_prefix() - // - // Removes the first `n` characters from the `string_view`. Note that the - // underlying std::string is not changed, only the view. - void remove_prefix(size_type n) - { - assert(n <= length_); - ptr_ += n; - length_ -= n; - } - - // string_view::remove_suffix() - // - // Removes the last `n` characters from the `string_view`. Note that the - // underlying std::string is not changed, only the view. - void remove_suffix(size_type n) - { - assert(n <= length_); - length_ -= n; - } - - // string_view::swap() - // - // Swaps this `string_view` with another `string_view`. - void swap(string_view &s) noexcept - { - auto t = *this; - *this = s; - s = t; - } - - // Explicit conversion operators - - // Converts to `std::basic_string`. - template - explicit operator std::basic_string() const - { - if (!data()) - return {}; - return std::basic_string(data(), size()); - } - - // string_view::substr() - // - // Returns a "substring" of the `string_view` (at offset `pos` and length - // `n`) as another string_view. This function throws `std::out_of_bounds` if - // `pos > size'. - string_view substr(size_type pos, size_type n = npos) const - { - if (dsn_unlikely(pos > length_)) - throw std::out_of_range("absl::string_view::substr"); - n = std::min(n, length_ - pos); - return string_view(ptr_ + pos, n); - } - - // string_view::compare() - // - // Performs a lexicographical comparison between the `string_view` and - // another `dsn::string_view), returning -1 if `this` is less than, 0 if - // `this` is equal to, and 1 if `this` is greater than the passed std::string - // view. Note that in the case of data equality, a further comparison is made - // on the respective sizes of the two `string_view`s to determine which is - // smaller, equal, or greater. - int compare(string_view x) const noexcept - { - auto min_length = std::min(length_, x.length_); - if (min_length > 0) { - int r = std::memcmp(ptr_, x.ptr_, min_length); - if (r < 0) - return -1; - if (r > 0) - return 1; - } - if (length_ < x.length_) - return -1; - if (length_ > x.length_) - return 1; - return 0; - } - - // Overload of `string_view::compare()` for comparing a substring of the - // 'string_view` and another `absl::string_view`. - int compare(size_type pos1, size_type count1, string_view v) const - { - return substr(pos1, count1).compare(v); - } - - // Overload of `string_view::compare()` for comparing a substring of the - // `string_view` and a substring of another `absl::string_view`. - int - compare(size_type pos1, size_type count1, string_view v, size_type pos2, size_type count2) const - { - return substr(pos1, count1).compare(v.substr(pos2, count2)); - } - - // Overload of `string_view::compare()` for comparing a `string_view` and a - // a different C-style std::string `s`. - int compare(const char *s) const { return compare(string_view(s)); } - - // Overload of `string_view::compare()` for comparing a substring of the - // `string_view` and a different std::string C-style std::string `s`. - int compare(size_type pos1, size_type count1, const char *s) const - { - return substr(pos1, count1).compare(string_view(s)); - } - - // Overload of `string_view::compare()` for comparing a substring of the - // `string_view` and a substring of a different C-style std::string `s`. - int compare(size_type pos1, size_type count1, const char *s, size_type count2) const - { - return substr(pos1, count1).compare(string_view(s, count2)); - } - - // string_view::find() - // - // Finds the first occurrence of the substring `s` within the `string_view`, - // returning the position of the first character's match, or `npos` if no - // match was found. - size_type find(string_view s, size_type pos = 0) const noexcept; - -private: - const char *ptr_; - size_type length_; -}; - -// This large function is defined inline so that in a fairly common case where -// one of the arguments is a literal, the compiler can elide a lot of the -// following comparisons. -inline bool operator==(string_view x, string_view y) noexcept -{ - auto len = x.size(); - if (len != y.size()) { - return false; - } - return x.data() == y.data() || len <= 0 || std::memcmp(x.data(), y.data(), len) == 0; -} - -inline bool operator!=(string_view x, string_view y) noexcept { return !(x == y); } - -// IO Insertion Operator -std::ostream &operator<<(std::ostream &o, string_view piece); - -} // namespace dsn - -USER_DEFINED_STRUCTURE_FORMATTER(::dsn::string_view); diff --git a/src/utils/test/configuration.cpp b/src/utils/test/configuration.cpp index 1930503ae6..4d3d9d757f 100644 --- a/src/utils/test/configuration.cpp +++ b/src/utils/test/configuration.cpp @@ -36,7 +36,7 @@ #include "gtest/gtest.h" #include "utils/configuration.h" -#include "utils/string_view.h" +#include "utils/string_conv.h" using namespace ::dsn; diff --git a/src/utils/test/endian_test.cpp b/src/utils/test/endian_test.cpp index 92533fd67e..6dc8462707 100644 --- a/src/utils/test/endian_test.cpp +++ b/src/utils/test/endian_test.cpp @@ -21,7 +21,6 @@ #include "gtest/gtest.h" #include "utils/endians.h" -#include "utils/string_view.h" using namespace dsn; diff --git a/src/utils/test/fail_point_test.cpp b/src/utils/test/fail_point_test.cpp index 743a3f66b9..62b1c0c507 100644 --- a/src/utils/test/fail_point_test.cpp +++ b/src/utils/test/fail_point_test.cpp @@ -33,7 +33,7 @@ #include "gtest/gtest.h" #include "utils/fail_point.h" #include "utils/fail_point_impl.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace fail { @@ -119,12 +119,12 @@ TEST(fail_point, parse) int test_func() { - FAIL_POINT_INJECT_F("test_1", [](string_view str) -> int { + FAIL_POINT_INJECT_F("test_1", [](absl::string_view str) -> int { EXPECT_EQ(str, "1"); return 1; }); - FAIL_POINT_INJECT_F("test_2", [](string_view str) -> int { + FAIL_POINT_INJECT_F("test_2", [](absl::string_view str) -> int { EXPECT_EQ(str, "2"); return 2; }); @@ -148,7 +148,7 @@ TEST(fail_point, macro_use) void test_func_return_void(int &a) { - FAIL_POINT_INJECT_F("test_1", [](string_view str) {}); + FAIL_POINT_INJECT_F("test_1", [](absl::string_view str) {}); a++; } TEST(fail_point, return_void) diff --git a/src/utils/test/fmt_logging_test.cpp b/src/utils/test/fmt_logging_test.cpp index 876d9b0a89..95e7d0dfd9 100644 --- a/src/utils/test/fmt_logging_test.cpp +++ b/src/utils/test/fmt_logging_test.cpp @@ -33,7 +33,7 @@ #include "runtime/task/task_code.h" #include "utils/error_code.h" #include "utils/errors.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace replication { @@ -45,8 +45,8 @@ TEST(fmt_logging, basic) ASSERT_EQ(fmt::format("{}", error_s::make(ERR_TIMEOUT, "yes")), "ERR_TIMEOUT: yes"); ASSERT_EQ(fmt::format("{}", ERR_OK), "ERR_OK"); ASSERT_EQ(fmt::format("{}", LPC_REPLICATION_LOW), "LPC_REPLICATION_LOW"); - ASSERT_EQ(string_view("yes"), "yes"); - ASSERT_EQ(fmt::format("{}", string_view("yes\0yes")), "yes\0yes"); + ASSERT_EQ(absl::string_view("yes"), "yes"); + ASSERT_EQ(fmt::format("{}", absl::string_view("yes\0yes")), "yes\0yes"); } } // namespace replication diff --git a/src/utils/test/memutil_test.cpp b/src/utils/test/memutil_test.cpp deleted file mode 100644 index 91d8fa51cf..0000000000 --- a/src/utils/test/memutil_test.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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. - -// Unit test for memutil.cc - -#include "utils/memutil.h" - -#include - -#include "gtest/gtest.h" - -TEST(MemUtilTest, memmatch) -{ - const char kHaystack[] = "0123456789"; - EXPECT_EQ(dsn::strings_internal::memmatch(kHaystack, 0, "", 0), kHaystack); - EXPECT_EQ(dsn::strings_internal::memmatch(kHaystack, 10, "012", 3), kHaystack); - EXPECT_EQ(dsn::strings_internal::memmatch(kHaystack, 10, "0xx", 1), kHaystack); - EXPECT_EQ(dsn::strings_internal::memmatch(kHaystack, 10, "789", 3), kHaystack + 7); - EXPECT_EQ(dsn::strings_internal::memmatch(kHaystack, 10, "9xx", 1), kHaystack + 9); - EXPECT_TRUE(dsn::strings_internal::memmatch(kHaystack, 10, "9xx", 3) == nullptr); - EXPECT_TRUE(dsn::strings_internal::memmatch(kHaystack, 10, "xxx", 1) == nullptr); -} diff --git a/src/utils/test/smart_pointers_test.cpp b/src/utils/test/smart_pointers_test.cpp deleted file mode 100644 index 7c36a01cc6..0000000000 --- a/src/utils/test/smart_pointers_test.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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 "utils/smart_pointers.h" - -#include -#include -#include -#include - -#include "gtest/gtest.h" - -using namespace dsn; - -TEST(MakeUniqueTest, Basic) -{ - std::unique_ptr p = std::make_unique(); - EXPECT_EQ("", *p); - p = std::make_unique("hi"); - EXPECT_EQ("hi", *p); -} - -struct MoveOnly -{ - MoveOnly() = default; - explicit MoveOnly(int i1) : ip1{new int{i1}} {} - MoveOnly(int i1, int i2) : ip1{new int{i1}}, ip2{new int{i2}} {} - std::unique_ptr ip1; - std::unique_ptr ip2; -}; - -struct AcceptMoveOnly -{ - explicit AcceptMoveOnly(MoveOnly m) : m_(std::move(m)) {} - MoveOnly m_; -}; - -TEST(MakeUniqueTest, MoveOnlyTypeAndValue) -{ - using ExpectedType = std::unique_ptr; - { - auto p = std::make_unique(); - static_assert(std::is_same::value, "unexpected return type"); - EXPECT_TRUE(!p->ip1); - EXPECT_TRUE(!p->ip2); - } - { - auto p = std::make_unique(1); - static_assert(std::is_same::value, "unexpected return type"); - EXPECT_TRUE(p->ip1 && *p->ip1 == 1); - EXPECT_TRUE(!p->ip2); - } - { - auto p = std::make_unique(1, 2); - static_assert(std::is_same::value, "unexpected return type"); - EXPECT_TRUE(p->ip1 && *p->ip1 == 1); - EXPECT_TRUE(p->ip2 && *p->ip2 == 2); - } -} - -TEST(MakeUniqueTest, AcceptMoveOnly) -{ - auto p = std::make_unique(MoveOnly()); - p = std::unique_ptr(new AcceptMoveOnly(MoveOnly())); -} - -struct ArrayWatch -{ - void *operator new[](size_t n) - { - allocs().push_back(n); - return ::operator new[](n); - } - void operator delete[](void *p) { return ::operator delete[](p); } - static std::vector &allocs() - { - static auto &v = *new std::vector; - return v; - } -}; - -TEST(Make_UniqueTest, Array) -{ - // Ensure state is clean before we start so that these tests - // are order-agnostic. - ArrayWatch::allocs().clear(); - - auto p = std::make_unique(5); - static_assert(std::is_same>::value, - "unexpected return type"); - - // TODO(wutao1): fix this. EXPECT_THAT is not available since it's an gmock macro, - // but we do not depend on gmock. - // EXPECT_THAT(ArrayWatch::allocs(), ElementsAre(5 * sizeof(ArrayWatch))); -} - -TEST(Make_UniqueTest, NotAmbiguousWithStdMakeUnique) -{ - // Ensure that std::make_unique is not ambiguous with std::make_unique. - // In C++14 mode, the below call to std::make_unique has both types as candidates. - struct TakesStdType - { - explicit TakesStdType(const std::vector &vec) {} - }; - make_unique(std::vector()); -} diff --git a/src/utils/test/string_conv_test.cpp b/src/utils/test/string_conv_test.cpp index e7a2c26bc1..c9fd5fc2d7 100644 --- a/src/utils/test/string_conv_test.cpp +++ b/src/utils/test/string_conv_test.cpp @@ -27,7 +27,7 @@ #include "utils/string_conv.h" #include "gtest/gtest.h" -#include "utils/string_view.h" +#include "absl/strings/string_view.h" TEST(string_conv, buf2bool) { @@ -50,13 +50,13 @@ TEST(string_conv, buf2bool) ASSERT_FALSE(dsn::buf2bool("TrUe", result, false)); std::string str("true\0false", 10); - ASSERT_FALSE(dsn::buf2bool(dsn::string_view(str.data(), 3), result)); - ASSERT_TRUE(dsn::buf2bool(dsn::string_view(str.data(), 4), result)); + ASSERT_FALSE(dsn::buf2bool(absl::string_view(str.data(), 3), result)); + ASSERT_TRUE(dsn::buf2bool(absl::string_view(str.data(), 4), result)); ASSERT_EQ(result, true); - ASSERT_FALSE(dsn::buf2bool(dsn::string_view(str.data(), 5), result)); - ASSERT_FALSE(dsn::buf2bool(dsn::string_view(str.data(), 6), result)); - ASSERT_FALSE(dsn::buf2bool(dsn::string_view(str.data() + 5, 4), result)); - ASSERT_TRUE(dsn::buf2bool(dsn::string_view(str.data() + 5, 5), result)); + ASSERT_FALSE(dsn::buf2bool(absl::string_view(str.data(), 5), result)); + ASSERT_FALSE(dsn::buf2bool(absl::string_view(str.data(), 6), result)); + ASSERT_FALSE(dsn::buf2bool(absl::string_view(str.data() + 5, 4), result)); + ASSERT_TRUE(dsn::buf2bool(absl::string_view(str.data() + 5, 5), result)); ASSERT_EQ(result, false); } @@ -92,12 +92,12 @@ TEST(string_conv, buf2int32) // "\045" is "%", so the string length=5, otherwise(2th argument > 5) it will be reported // "global-buffer-overflow" error under AddressSanitizer check std::string str("123\0456", 5); - ASSERT_TRUE(dsn::buf2int32(dsn::string_view(str.data(), 2), result)); + ASSERT_TRUE(dsn::buf2int32(absl::string_view(str.data(), 2), result)); ASSERT_EQ(result, 12); - ASSERT_TRUE(dsn::buf2int32(dsn::string_view(str.data(), 3), result)); + ASSERT_TRUE(dsn::buf2int32(absl::string_view(str.data(), 3), result)); ASSERT_EQ(result, 123); - ASSERT_FALSE(dsn::buf2int32(dsn::string_view(str.data(), 4), result)); - ASSERT_FALSE(dsn::buf2int32(dsn::string_view(str.data(), 5), result)); + ASSERT_FALSE(dsn::buf2int32(absl::string_view(str.data(), 4), result)); + ASSERT_FALSE(dsn::buf2int32(absl::string_view(str.data(), 5), result)); } TEST(string_conv, buf2int64) @@ -139,12 +139,12 @@ TEST(string_conv, buf2int64) // "\045" is "%", so the string length=5, otherwise(2th argument > 5) it will be reported // "global-buffer-overflow" error under AddressSanitizer check std::string str("123\0456", 5); - ASSERT_TRUE(dsn::buf2int64(dsn::string_view(str.data(), 2), result)); + ASSERT_TRUE(dsn::buf2int64(absl::string_view(str.data(), 2), result)); ASSERT_EQ(result, 12); - ASSERT_TRUE(dsn::buf2int64(dsn::string_view(str.data(), 3), result)); + ASSERT_TRUE(dsn::buf2int64(absl::string_view(str.data(), 3), result)); ASSERT_EQ(result, 123); - ASSERT_FALSE(dsn::buf2int64(dsn::string_view(str.data(), 4), result)); - ASSERT_FALSE(dsn::buf2int64(dsn::string_view(str.data(), 5), result)); + ASSERT_FALSE(dsn::buf2int64(absl::string_view(str.data(), 4), result)); + ASSERT_FALSE(dsn::buf2int64(absl::string_view(str.data(), 5), result)); } TEST(string_conv, buf2uint64) @@ -183,12 +183,12 @@ TEST(string_conv, buf2uint64) // "\045" is "%", so the string length=5, otherwise(2th argument > 5) it will be reported // "global-buffer-overflow" error under AddressSanitizer check std::string str("123\0456", 5); - ASSERT_TRUE(dsn::buf2uint64(dsn::string_view(str.data(), 2), result)); + ASSERT_TRUE(dsn::buf2uint64(absl::string_view(str.data(), 2), result)); ASSERT_EQ(result, 12); - ASSERT_TRUE(dsn::buf2uint64(dsn::string_view(str.data(), 3), result)); + ASSERT_TRUE(dsn::buf2uint64(absl::string_view(str.data(), 3), result)); ASSERT_EQ(result, 123); - ASSERT_FALSE(dsn::buf2uint64(dsn::string_view(str.data(), 4), result)); - ASSERT_FALSE(dsn::buf2uint64(dsn::string_view(str.data(), 5), result)); + ASSERT_FALSE(dsn::buf2uint64(absl::string_view(str.data(), 4), result)); + ASSERT_FALSE(dsn::buf2uint64(absl::string_view(str.data(), 5), result)); } TEST(string_conv, buf2uint32) @@ -229,12 +229,12 @@ TEST(string_conv, buf2uint32) // "\045" is "%", so the string length=5, otherwise(2th argument > 5) it will be reported // "global-buffer-overflow" error under AddressSanitizer check std::string str("123\0456", 5); - ASSERT_TRUE(dsn::buf2uint32(dsn::string_view(str.data(), 2), result)); + ASSERT_TRUE(dsn::buf2uint32(absl::string_view(str.data(), 2), result)); ASSERT_EQ(result, 12); - ASSERT_TRUE(dsn::buf2uint32(dsn::string_view(str.data(), 3), result)); + ASSERT_TRUE(dsn::buf2uint32(absl::string_view(str.data(), 3), result)); ASSERT_EQ(result, 123); - ASSERT_FALSE(dsn::buf2uint32(dsn::string_view(str.data(), 4), result)); - ASSERT_FALSE(dsn::buf2uint32(dsn::string_view(str.data(), 5), result)); + ASSERT_FALSE(dsn::buf2uint32(absl::string_view(str.data(), 4), result)); + ASSERT_FALSE(dsn::buf2uint32(absl::string_view(str.data(), 5), result)); } TEST(string_conv, int64_partial) diff --git a/src/utils/test/string_view_test.cpp b/src/utils/test/string_view_test.cpp deleted file mode 100644 index 4a757988c4..0000000000 --- a/src/utils/test/string_view_test.cpp +++ /dev/null @@ -1,440 +0,0 @@ -// Copyright 2017 The Abseil Authors. -// -// 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 "utils/string_view.h" - -#include -#include -#include - -#include "gtest/gtest.h" - -namespace { - -// Separated from STL1() because some compilers produce an overly -// large stack frame for the combined function. -TEST(StringViewTest, STL2) -{ - const dsn::string_view a("abcdefghijklmnopqrstuvwxyz"); - const dsn::string_view b("abc"); - const dsn::string_view c("xyz"); - dsn::string_view d("foobar"); - const dsn::string_view e; - const dsn::string_view f("123" - "\0" - "456", - 7); - - d = dsn::string_view(); - EXPECT_EQ(d.size(), 0); - EXPECT_TRUE(d.empty()); - EXPECT_TRUE(d.data() == nullptr); - EXPECT_TRUE(d.begin() == d.end()); - - EXPECT_EQ(a.find(b), 0); - EXPECT_EQ(a.find(b, 1), dsn::string_view::npos); - EXPECT_EQ(a.find(c), 23); - EXPECT_EQ(a.find(c, 9), 23); - EXPECT_EQ(a.find(c, dsn::string_view::npos), dsn::string_view::npos); - EXPECT_EQ(b.find(c), dsn::string_view::npos); - EXPECT_EQ(b.find(c, dsn::string_view::npos), dsn::string_view::npos); - EXPECT_EQ(a.find(d), 0); - EXPECT_EQ(a.find(e), 0); - EXPECT_EQ(a.find(d, 12), 12); - EXPECT_EQ(a.find(e, 17), 17); - dsn::string_view g("xx not found bb"); - EXPECT_EQ(a.find(g), dsn::string_view::npos); - // empty std::string nonsense - EXPECT_EQ(d.find(b), dsn::string_view::npos); - EXPECT_EQ(e.find(b), dsn::string_view::npos); - EXPECT_EQ(d.find(b, 4), dsn::string_view::npos); - EXPECT_EQ(e.find(b, 7), dsn::string_view::npos); - - size_t empty_search_pos = std::string().find(std::string()); - EXPECT_EQ(d.find(d), empty_search_pos); - EXPECT_EQ(d.find(e), empty_search_pos); - EXPECT_EQ(e.find(d), empty_search_pos); - EXPECT_EQ(e.find(e), empty_search_pos); - EXPECT_EQ(d.find(d, 4), std::string().find(std::string(), 4)); - EXPECT_EQ(d.find(e, 4), std::string().find(std::string(), 4)); - EXPECT_EQ(e.find(d, 4), std::string().find(std::string(), 4)); - EXPECT_EQ(e.find(e, 4), std::string().find(std::string(), 4)); -} - -// Continued from STL2 -TEST(StringViewTest, STL2Substr) -{ - const dsn::string_view a("abcdefghijklmnopqrstuvwxyz"); - const dsn::string_view b("abc"); - const dsn::string_view c("xyz"); - dsn::string_view d("foobar"); - const dsn::string_view e; - - d = dsn::string_view(); - EXPECT_EQ(a.substr(0, 3), b); - EXPECT_EQ(a.substr(23), c); - EXPECT_EQ(a.substr(23, 3), c); - EXPECT_EQ(a.substr(23, 99), c); - EXPECT_EQ(a.substr(0), a); - EXPECT_EQ(a.substr(3, 2), "de"); - // empty std::string nonsense - EXPECT_EQ(d.substr(0, 99), e); - // use of npos - EXPECT_EQ(a.substr(0, dsn::string_view::npos), a); - EXPECT_EQ(a.substr(23, dsn::string_view::npos), c); - - EXPECT_THROW(a.substr(99, 2), std::out_of_range); -} - -TEST(StringViewTest, Ctor) -{ - { - // Null. - dsn::string_view s10; - EXPECT_TRUE(s10.data() == nullptr); - EXPECT_EQ(0, s10.length()); - } - - { - // const char* without length. - const char *hello = "hello"; - dsn::string_view s20(hello); - EXPECT_TRUE(s20.data() == hello); - EXPECT_EQ(5, s20.length()); - - // const char* with length. - dsn::string_view s21(hello, 4); - EXPECT_TRUE(s21.data() == hello); - EXPECT_EQ(4, s21.length()); - - // Not recommended, but valid C++ - dsn::string_view s22(hello, 6); - EXPECT_TRUE(s22.data() == hello); - EXPECT_EQ(6, s22.length()); - } - - { - // std::string. - std::string hola = "hola"; - dsn::string_view s30(hola); - EXPECT_TRUE(s30.data() == hola.data()); - EXPECT_EQ(4, s30.length()); - - // std::string with embedded '\0'. - hola.push_back('\0'); - hola.append("h2"); - hola.push_back('\0'); - dsn::string_view s31(hola); - EXPECT_TRUE(s31.data() == hola.data()); - EXPECT_EQ(8, s31.length()); - } -} - -TEST(StringViewTest, Swap) -{ - dsn::string_view a("a"); - dsn::string_view b("bbb"); - EXPECT_TRUE(noexcept(a.swap(b))); - a.swap(b); - EXPECT_EQ(a, "bbb"); - EXPECT_EQ(b, "a"); - a.swap(b); - EXPECT_EQ(a, "a"); - EXPECT_EQ(b, "bbb"); -} - -#define EXPECT_COMPARE_TRUE(op, x, y) \ - EXPECT_TRUE(dsn::string_view((x)) op dsn::string_view((y))); \ - EXPECT_TRUE(dsn::string_view((x)).compare(dsn::string_view((y))) op 0) - -#define EXPECT_COMPARE_FALSE(op, x, y) \ - EXPECT_FALSE(dsn::string_view((x)) op dsn::string_view((y))); \ - EXPECT_FALSE(dsn::string_view((x)).compare(dsn::string_view((y))) op 0) - -TEST(StringViewTest, ComparisonOperators) -{ - EXPECT_COMPARE_FALSE(==, "a", ""); - EXPECT_COMPARE_FALSE(==, "", "a"); - EXPECT_COMPARE_FALSE(==, "a", "b"); - EXPECT_COMPARE_FALSE(==, "a", "aa"); - EXPECT_COMPARE_FALSE(==, "aa", "a"); - - EXPECT_COMPARE_TRUE(==, "", ""); - EXPECT_COMPARE_TRUE(==, "", dsn::string_view()); - EXPECT_COMPARE_TRUE(==, dsn::string_view(), ""); - EXPECT_COMPARE_TRUE(==, "a", "a"); - EXPECT_COMPARE_TRUE(==, "aa", "aa"); - - EXPECT_COMPARE_FALSE(!=, "", ""); - EXPECT_COMPARE_FALSE(!=, "a", "a"); - EXPECT_COMPARE_FALSE(!=, "aa", "aa"); - - EXPECT_COMPARE_TRUE(!=, "a", ""); - EXPECT_COMPARE_TRUE(!=, "", "a"); - EXPECT_COMPARE_TRUE(!=, "a", "b"); - EXPECT_COMPARE_TRUE(!=, "a", "aa"); - EXPECT_COMPARE_TRUE(!=, "aa", "a"); -} - -TEST(StringViewTest, STL1) -{ - const dsn::string_view a("abcdefghijklmnopqrstuvwxyz"); - const dsn::string_view b("abc"); - const dsn::string_view c("xyz"); - const dsn::string_view d("foobar"); - const dsn::string_view e; - std::string temp("123"); - temp += '\0'; - temp += "456"; - const dsn::string_view f(temp); - - EXPECT_EQ(a[6], 'g'); - EXPECT_EQ(b[0], 'a'); - EXPECT_EQ(c[2], 'z'); - EXPECT_EQ(f[3], '\0'); - EXPECT_EQ(f[5], '5'); - - EXPECT_EQ(*d.data(), 'f'); - EXPECT_EQ(d.data()[5], 'r'); - EXPECT_TRUE(e.data() == nullptr); - - EXPECT_EQ(*a.begin(), 'a'); - EXPECT_EQ(*(b.begin() + 2), 'c'); - EXPECT_EQ(*(c.end() - 1), 'z'); - - EXPECT_EQ(*a.rbegin(), 'z'); - EXPECT_EQ(*(b.rbegin() + 2), 'a'); - EXPECT_EQ(*(c.rend() - 1), 'x'); - EXPECT_TRUE(a.rbegin() + 26 == a.rend()); - - EXPECT_EQ(a.size(), 26); - EXPECT_EQ(b.size(), 3); - EXPECT_EQ(c.size(), 3); - EXPECT_EQ(d.size(), 6); - EXPECT_EQ(e.size(), 0); - EXPECT_EQ(f.size(), 7); - - EXPECT_TRUE(!d.empty()); - EXPECT_TRUE(d.begin() != d.end()); - EXPECT_TRUE(d.begin() + 6 == d.end()); - - EXPECT_TRUE(e.empty()); - EXPECT_TRUE(e.begin() == e.end()); -} - -TEST(StringViewTest, Remove) -{ - dsn::string_view a("foobar"); - std::string s1("123"); - s1 += '\0'; - s1 += "456"; - dsn::string_view b(s1); - dsn::string_view e; - std::string s2; - - // remove_prefix - dsn::string_view c(a); - c.remove_prefix(3); - EXPECT_EQ(c, "bar"); - c = a; - c.remove_prefix(0); - EXPECT_EQ(c, a); - c.remove_prefix(c.size()); - EXPECT_EQ(c, e); - - // remove_suffix - c = a; - c.remove_suffix(3); - EXPECT_EQ(c, "foo"); - c = a; - c.remove_suffix(0); - EXPECT_EQ(c, a); - c.remove_suffix(c.size()); - EXPECT_EQ(c, e); -} - -TEST(StringViewTest, Set) -{ - dsn::string_view a("foobar"); - dsn::string_view empty; - dsn::string_view b; - - // set - b = dsn::string_view("foobar", 6); - EXPECT_EQ(b, a); - b = dsn::string_view("foobar", 0); - EXPECT_EQ(b, empty); - b = dsn::string_view("foobar", 7); - EXPECT_NE(b, a); - - b = dsn::string_view("foobar"); - EXPECT_EQ(b, a); -} - -TEST(StringViewTest, FrontBack) -{ - static const char arr[] = "abcd"; - const dsn::string_view csp(arr, 4); - EXPECT_EQ(&arr[0], &csp.front()); - EXPECT_EQ(&arr[3], &csp.back()); -} - -TEST(StringViewTest, FrontBackSingleChar) -{ - static const char c = 'a'; - const dsn::string_view csp(&c, 1); - EXPECT_EQ(&c, &csp.front()); - EXPECT_EQ(&c, &csp.back()); -} - -TEST(StringViewTest, NULLInput) -{ - dsn::string_view s; - EXPECT_EQ(s.data(), nullptr); - EXPECT_EQ(s.size(), 0); - - s = dsn::string_view(nullptr); - EXPECT_EQ(s.data(), nullptr); - EXPECT_EQ(s.size(), 0); - - EXPECT_EQ("", std::string(s)); -} - -TEST(StringViewTest, ExplicitConversionOperator) -{ - dsn::string_view sp = "hi"; - EXPECT_EQ(sp, std::string(sp)); -} - -TEST(StringViewTest, Noexcept) -{ - EXPECT_TRUE((std::is_nothrow_constructible::value)); - EXPECT_TRUE((std::is_nothrow_constructible::value)); - EXPECT_TRUE(std::is_nothrow_constructible::value); - constexpr dsn::string_view sp; - EXPECT_TRUE(noexcept(sp.begin())); - EXPECT_TRUE(noexcept(sp.end())); - EXPECT_TRUE(noexcept(sp.cbegin())); - EXPECT_TRUE(noexcept(sp.cend())); - EXPECT_TRUE(noexcept(sp.rbegin())); - EXPECT_TRUE(noexcept(sp.rend())); - EXPECT_TRUE(noexcept(sp.crbegin())); - EXPECT_TRUE(noexcept(sp.crend())); - EXPECT_TRUE(noexcept(sp.size())); - EXPECT_TRUE(noexcept(sp.length())); - EXPECT_TRUE(noexcept(sp.empty())); - EXPECT_TRUE(noexcept(sp.data())); - EXPECT_TRUE(noexcept(sp.compare(sp))); - EXPECT_TRUE(noexcept(sp.find(sp))); -} - -TEST(StringViewTest, HeterogenousStringViewEquals) -{ - EXPECT_EQ(dsn::string_view("hello"), std::string("hello")); - EXPECT_EQ("hello", dsn::string_view("hello")); -} - -TEST(StringViewTest, FindConformance) -{ - struct - { - std::string haystack; - std::string needle; - } specs[] = { - {"", ""}, - {"", "a"}, - {"a", ""}, - {"a", "a"}, - {"a", "b"}, - {"aa", ""}, - {"aa", "a"}, - {"aa", "b"}, - {"ab", "a"}, - {"ab", "b"}, - {"abcd", ""}, - {"abcd", "a"}, - {"abcd", "d"}, - {"abcd", "ab"}, - {"abcd", "bc"}, - {"abcd", "cd"}, - {"abcd", "abcd"}, - }; - for (const auto &s : specs) { - SCOPED_TRACE(s.haystack); - SCOPED_TRACE(s.needle); - std::string st = s.haystack; - dsn::string_view sp = s.haystack; - for (size_t i = 0; i <= sp.size(); ++i) { - size_t pos = (i == sp.size()) ? dsn::string_view::npos : i; - SCOPED_TRACE(pos); - EXPECT_EQ(sp.find(s.needle, pos), st.find(s.needle, pos)); - } - } -} - -class StringViewStreamTest : public ::testing::Test -{ -public: - // Set negative 'width' for right justification. - template - std::string Pad(const T &s, int width, char fill = 0) - { - std::ostringstream oss; - if (fill != 0) { - oss << std::setfill(fill); - } - if (width < 0) { - width = -width; - oss << std::right; - } - oss << std::setw(width) << s; - return oss.str(); - } -}; - -TEST_F(StringViewStreamTest, Padding) -{ - std::string s("hello"); - dsn::string_view sp(s); - for (int w = -64; w < 64; ++w) { - SCOPED_TRACE(w); - EXPECT_EQ(Pad(s, w), Pad(sp, w)); - } - for (int w = -64; w < 64; ++w) { - SCOPED_TRACE(w); - EXPECT_EQ(Pad(s, w, '#'), Pad(sp, w, '#')); - } -} - -TEST_F(StringViewStreamTest, ResetsWidth) -{ - // Width should reset after one formatted write. - // If we weren't resetting width after formatting the string_view, - // we'd have width=5 carrying over to the printing of the "]", - // creating "[###hi####]". - std::string s = "hi"; - dsn::string_view sp = s; - { - std::ostringstream oss; - oss << "[" << std::setfill('#') << std::setw(5) << s << "]"; - ASSERT_EQ("[###hi]", oss.str()); - } - { - std::ostringstream oss; - oss << "[" << std::setfill('#') << std::setw(5) << sp << "]"; - EXPECT_EQ("[###hi]", oss.str()); - } -} - -} // namespace diff --git a/src/utils/throttling_controller.cpp b/src/utils/throttling_controller.cpp index 69cb28644a..2350adb5a0 100644 --- a/src/utils/throttling_controller.cpp +++ b/src/utils/throttling_controller.cpp @@ -17,6 +17,7 @@ #include "throttling_controller.h" +// IWYU pragma: no_include #include #include #include diff --git a/src/utils/time_utils.h b/src/utils/time_utils.h index a47ba594cd..5a0a2eb68d 100644 --- a/src/utils/time_utils.h +++ b/src/utils/time_utils.h @@ -32,7 +32,7 @@ #include #include -#include "string_view.h" +#include "absl/strings/string_view.h" namespace dsn { namespace utils { @@ -108,7 +108,7 @@ inline int64_t get_unix_sec_today_midnight() // `hh:mm` (range in [00:00, 23:59]) to seconds since 00:00:00 // eg. `01:00` => `3600` // Return: -1 when invalid -inline int hh_mm_to_seconds(dsn::string_view hhmm) +inline int hh_mm_to_seconds(absl::string_view hhmm) { int hour = 0, min = 0, sec = -1; if (::sscanf(hhmm.data(), "%d:%d", &hour, &min) == 2 && (0 <= hour && hour <= 23) && @@ -121,7 +121,7 @@ inline int hh_mm_to_seconds(dsn::string_view hhmm) // local time `hh:mm` to unix timestamp. // eg. `18:10` => `1525947000` when called on May 10, 2018, CST // Return: -1 when invalid -inline int64_t hh_mm_today_to_unix_sec(string_view hhmm_of_day) +inline int64_t hh_mm_today_to_unix_sec(absl::string_view hhmm_of_day) { int sec_of_day = hh_mm_to_seconds(hhmm_of_day); if (sec_of_day == -1) {