Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Aug 5, 2024
1 parent 21b845a commit 5b88e18
Show file tree
Hide file tree
Showing 105 changed files with 385 additions and 383 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/lint_and_test_cpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ jobs:

iwyu:
name: IWYU
needs: cpp_clang_format_linter
needs:
- cpp_clang_format_linter
- cpp_clang_tidy_linter
runs-on: ubuntu-latest
env:
USE_JEMALLOC: OFF
Expand Down
6 changes: 3 additions & 3 deletions src/base/pegasus_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <string>
#include <vector>

#include "absl/strings/string_view.h"
#include <string_view>
#include "utils/flags.h"

DSN_DECLARE_bool(encrypt_data_at_rest);
Expand Down Expand Up @@ -122,9 +122,9 @@ const std::string &redact_sensitive_string(const T &src)
}
}

inline absl::string_view to_string_view(rocksdb::Slice s) { return {s.data(), s.size()}; }
inline std::string_view to_string_view(rocksdb::Slice s) { return {s.data(), s.size()}; }

inline rocksdb::Slice to_rocksdb_slice(absl::string_view s) { return {s.data(), s.size()}; }
inline rocksdb::Slice to_rocksdb_slice(std::string_view s) { return {s.data(), s.size()}; }

} // namespace utils
} // namespace pegasus
18 changes: 9 additions & 9 deletions src/base/pegasus_value_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "utils/blob.h"
#include "utils/endians.h"
#include "utils/fmt_logging.h"
#include "absl/strings/string_view.h"
#include <string_view>
#include "value_field.h"

namespace pegasus {
Expand All @@ -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, absl::string_view value)
inline uint32_t pegasus_extract_expire_ts(uint32_t version, std::string_view value)
{
CHECK_LE(version, PEGASUS_DATA_VERSION_MAX);
return dsn::data_input(value).read_u32();
Expand All @@ -76,15 +76,15 @@ pegasus_extract_user_data(uint32_t version, std::string &&raw_value, ::dsn::blob
if (version == 1) {
input.skip(sizeof(uint64_t));
}
absl::string_view view = input.read_str();
std::string_view view = input.read_str();

// tricky code to avoid memory copy
std::shared_ptr<char> buf(const_cast<char *>(view.data()), [s](char *) { delete s; });
user_data.assign(std::move(buf), 0, static_cast<unsigned int>(view.length()));
}

/// Extracts timetag from a v1 value.
inline uint64_t pegasus_extract_timetag(int version, absl::string_view value)
inline uint64_t pegasus_extract_timetag(int version, std::string_view value)
{
CHECK_EQ(version, 1);

Expand Down Expand Up @@ -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,
absl::string_view raw_value)
std::string_view raw_value)
{
return check_if_ts_expired(epoch_now,
pegasus_extract_expire_ts(value_schema_version, raw_value));
Expand All @@ -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,
absl::string_view user_data,
std::string_view user_data,
uint32_t expire_ts,
uint64_t timetag)
{
Expand All @@ -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, absl::string_view user_data)
rocksdb::SliceParts generate_value_v0(uint32_t expire_ts, std::string_view user_data)
{
_write_buf.resize(sizeof(uint32_t));
_write_slices.clear();
Expand Down Expand Up @@ -210,7 +210,7 @@ class pegasus_value_generator
///
/// \internal
rocksdb::SliceParts
generate_value_v1(uint32_t expire_ts, uint64_t timetag, absl::string_view user_data)
generate_value_v1(uint32_t expire_ts, uint64_t timetag, std::string_view user_data)
{
_write_buf.resize(sizeof(uint32_t) + sizeof(uint64_t));
_write_slices.clear();
Expand Down Expand Up @@ -258,7 +258,7 @@ class value_schema
public:
virtual ~value_schema() = default;

virtual std::unique_ptr<value_field> extract_field(absl::string_view value,
virtual std::unique_ptr<value_field> extract_field(std::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
Expand Down
4 changes: 2 additions & 2 deletions src/base/test/value_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#include "base/value_schema_manager.h"
#include "gtest/gtest.h"
#include "pegasus_value_schema.h"
#include "absl/strings/string_view.h"
#include <string_view>
#include "value_field.h"

using namespace pegasus;

extern std::string generate_value(value_schema *schema,
uint32_t expire_ts,
uint64_t time_tag,
absl::string_view user_data);
std::string_view user_data);

TEST(value_schema_manager, get_latest_value_schema)
{
Expand Down
4 changes: 2 additions & 2 deletions src/base/test/value_schema_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "base/value_schema_manager.h"
#include "gtest/gtest.h"
#include "utils/blob.h"
#include "absl/strings/string_view.h"
#include <string_view>
#include "value_field.h"

using namespace pegasus;
Expand All @@ -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,
absl::string_view user_data)
std::string_view user_data)
{
std::string write_buf;
std::vector<rocksdb::Slice> write_slices;
Expand Down
4 changes: 2 additions & 2 deletions src/base/value_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ struct time_tag_field : public value_field

struct user_data_field : public value_field
{
explicit user_data_field(absl::string_view data) : user_data(data) {}
explicit user_data_field(std::string_view data) : user_data(data) {}
value_field_type type() { return value_field_type::USER_DATA; }

absl::string_view user_data;
std::string_view user_data;
};
} // namespace pegasus
2 changes: 1 addition & 1 deletion src/base/value_schema_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void value_schema_manager::register_schema(std::unique_ptr<value_schema> schema)
}

value_schema *value_schema_manager::get_value_schema(uint32_t meta_cf_data_version,
absl::string_view value) const
std::string_view value) const
{
dsn::data_input input(value);
uint8_t first_byte = input.read_u8();
Expand Down
4 changes: 2 additions & 2 deletions src/base/value_schema_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "pegasus_value_schema.h"
#include "utils/singleton.h"
#include "absl/strings/string_view.h"
#include <string_view>

namespace pegasus {

Expand All @@ -35,7 +35,7 @@ class value_schema_manager : public dsn::utils::singleton<value_schema_manager>
void register_schema(std::unique_ptr<value_schema> 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, absl::string_view value) const;
value_schema *get_value_schema(uint32_t meta_cf_data_version, std::string_view value) const;
value_schema *get_value_schema(uint32_t version) const;
value_schema *get_latest_value_schema() const;

Expand Down
6 changes: 3 additions & 3 deletions src/base/value_schema_v0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "utils/ports.h"

namespace pegasus {
std::unique_ptr<value_field> value_schema_v0::extract_field(absl::string_view value,
std::unique_ptr<value_field> value_schema_v0::extract_field(std::string_view value,
value_field_type type)
{
std::unique_ptr<value_field> field = nullptr;
Expand Down Expand Up @@ -80,14 +80,14 @@ rocksdb::SliceParts value_schema_v0::generate_value(const value_params &params)
params.write_slices.clear();
params.write_slices.emplace_back(params.write_buf.data(), params.write_buf.size());

absl::string_view user_data = data_field->user_data;
std::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 {&params.write_slices[0], static_cast<int>(params.write_slices.size())};
}

std::unique_ptr<value_field> value_schema_v0::extract_timestamp(absl::string_view value)
std::unique_ptr<value_field> value_schema_v0::extract_timestamp(std::string_view value)
{
uint32_t expire_ts = dsn::data_input(value).read_u32();
return std::make_unique<expire_timestamp_field>(expire_ts);
Expand Down
6 changes: 3 additions & 3 deletions src/base/value_schema_v0.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "pegasus_value_schema.h"
#include "utils/blob.h"
#include "absl/strings/string_view.h"
#include <string_view>
#include "value_field.h"

namespace pegasus {
Expand All @@ -37,15 +37,15 @@ class value_schema_v0 : public value_schema
public:
value_schema_v0() = default;

std::unique_ptr<value_field> extract_field(absl::string_view value,
std::unique_ptr<value_field> extract_field(std::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<value_field> field) override;
rocksdb::SliceParts generate_value(const value_params &params) override;
data_version version() const override { return data_version::VERSION_0; }

private:
std::unique_ptr<value_field> extract_timestamp(absl::string_view value);
std::unique_ptr<value_field> extract_timestamp(std::string_view value);
void update_expire_ts(std::string &value, std::unique_ptr<value_field> field);
};
} // namespace pegasus
8 changes: 4 additions & 4 deletions src/base/value_schema_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "utils/ports.h"

namespace pegasus {
std::unique_ptr<value_field> value_schema_v1::extract_field(absl::string_view value,
std::unique_ptr<value_field> value_schema_v1::extract_field(std::string_view value,
value_field_type type)
{
std::unique_ptr<value_field> field = nullptr;
Expand Down Expand Up @@ -88,20 +88,20 @@ rocksdb::SliceParts value_schema_v1::generate_value(const value_params &params)
params.write_slices.clear();
params.write_slices.emplace_back(params.write_buf.data(), params.write_buf.size());

absl::string_view user_data = data_field->user_data;
std::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 {&params.write_slices[0], static_cast<int>(params.write_slices.size())};
}

std::unique_ptr<value_field> value_schema_v1::extract_timestamp(absl::string_view value)
std::unique_ptr<value_field> value_schema_v1::extract_timestamp(std::string_view value)
{
uint32_t expire_ts = dsn::data_input(value).read_u32();
return std::make_unique<expire_timestamp_field>(expire_ts);
}

std::unique_ptr<value_field> value_schema_v1::extract_time_tag(absl::string_view value)
std::unique_ptr<value_field> value_schema_v1::extract_time_tag(std::string_view value)
{
dsn::data_input input(value);
input.skip(sizeof(uint32_t));
Expand Down
8 changes: 4 additions & 4 deletions src/base/value_schema_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "pegasus_value_schema.h"
#include "utils/blob.h"
#include "absl/strings/string_view.h"
#include <string_view>
#include "value_field.h"

namespace pegasus {
Expand All @@ -37,16 +37,16 @@ class value_schema_v1 : public value_schema
public:
value_schema_v1() = default;

std::unique_ptr<value_field> extract_field(absl::string_view value,
std::unique_ptr<value_field> extract_field(std::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<value_field> field) override;
rocksdb::SliceParts generate_value(const value_params &params) override;
data_version version() const override { return data_version::VERSION_1; }

private:
std::unique_ptr<value_field> extract_timestamp(absl::string_view value);
std::unique_ptr<value_field> extract_time_tag(absl::string_view value);
std::unique_ptr<value_field> extract_timestamp(std::string_view value);
std::unique_ptr<value_field> extract_time_tag(std::string_view value);
void update_expire_ts(std::string &value, std::unique_ptr<value_field> field);
};

Expand Down
8 changes: 4 additions & 4 deletions src/base/value_schema_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace pegasus {

std::unique_ptr<value_field> value_schema_v2::extract_field(absl::string_view value,
std::unique_ptr<value_field> value_schema_v2::extract_field(std::string_view value,
value_field_type type)
{
std::unique_ptr<value_field> field = nullptr;
Expand Down Expand Up @@ -91,21 +91,21 @@ rocksdb::SliceParts value_schema_v2::generate_value(const value_params &params)
params.write_slices.clear();
params.write_slices.emplace_back(params.write_buf.data(), params.write_buf.size());

absl::string_view user_data = data_field->user_data;
std::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 {&params.write_slices[0], static_cast<int>(params.write_slices.size())};
}

std::unique_ptr<value_field> value_schema_v2::extract_timestamp(absl::string_view value)
std::unique_ptr<value_field> value_schema_v2::extract_timestamp(std::string_view value)
{
dsn::data_input input(value);
input.skip(sizeof(uint8_t));
return std::make_unique<expire_timestamp_field>(input.read_u32());
}

std::unique_ptr<value_field> value_schema_v2::extract_time_tag(absl::string_view value)
std::unique_ptr<value_field> value_schema_v2::extract_time_tag(std::string_view value)
{
dsn::data_input input(value);
input.skip(sizeof(uint8_t));
Expand Down
8 changes: 4 additions & 4 deletions src/base/value_schema_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "pegasus_value_schema.h"
#include "utils/blob.h"
#include "absl/strings/string_view.h"
#include <string_view>
#include "value_field.h"

namespace pegasus {
Expand All @@ -38,16 +38,16 @@ class value_schema_v2 : public value_schema
public:
value_schema_v2() = default;

std::unique_ptr<value_field> extract_field(absl::string_view value,
std::unique_ptr<value_field> extract_field(std::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<value_field> field) override;
rocksdb::SliceParts generate_value(const value_params &params) override;
data_version version() const override { return data_version::VERSION_2; }

private:
std::unique_ptr<value_field> extract_timestamp(absl::string_view value);
std::unique_ptr<value_field> extract_time_tag(absl::string_view value);
std::unique_ptr<value_field> extract_timestamp(std::string_view value);
std::unique_ptr<value_field> extract_time_tag(std::string_view value);
void update_expire_ts(std::string &value, std::unique_ptr<value_field> field);
};
} // namespace pegasus
4 changes: 2 additions & 2 deletions src/block_service/local/local_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <type_traits>
#include <utility>

#include "absl/strings/string_view.h"
#include <string_view>
#include "local_service.h"
#include "nlohmann/json.hpp"
#include "rocksdb/slice.h"
Expand Down Expand Up @@ -279,7 +279,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", [=](absl::string_view) {
FAIL_POINT_INJECT_F("mock_local_service_write_failed", [=](std::string_view) {
auto write_failed = [=]() {
write_response resp;
resp.err = ERR_FS_INTERNAL;
Expand Down
2 changes: 1 addition & 1 deletion src/client/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ void replication_ddl_client::end_meta_request(const rpc_response_task_ptr &callb
error_code err, dsn::message_ex *request, dsn::message_ex *response) mutable {
FAIL_POINT_INJECT_NOT_RETURN_F(
"ddl_client_request_meta",
[&err, this](absl::string_view str) { err = pop_mock_error(); });
[&err, this](std::string_view str) { err = pop_mock_error(); });

end_meta_request(callback, attempt_count + 1, err, request, response);
});
Expand Down
Loading

0 comments on commit 5b88e18

Please sign in to comment.