Skip to content

Commit

Permalink
refactor(absl): Use the abseil in thirdparty instead of the internal …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
acelyc111 authored Nov 27, 2023
1 parent 75744cb commit 79cd226
Show file tree
Hide file tree
Showing 114 changed files with 474 additions and 2,188 deletions.
10 changes: 0 additions & 10 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
26 changes: 0 additions & 26 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -29,7 +29,7 @@
#include <vector>

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

DSN_DECLARE_bool(encrypt_data_at_rest);

Expand Down Expand Up @@ -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
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 "utils/string_view.h"
#include "absl/strings/string_view.h"
#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, 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();
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));
}
dsn::string_view view = input.read_str();
absl::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, dsn::string_view value)
inline uint64_t pegasus_extract_timetag(int version, absl::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,
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));
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,
dsn::string_view user_data,
absl::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, 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();
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, 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();
Expand Down Expand Up @@ -258,7 +258,7 @@ class value_schema
public:
virtual ~value_schema() = default;

virtual std::unique_ptr<value_field> extract_field(dsn::string_view value,
virtual std::unique_ptr<value_field> 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
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 "utils/string_view.h"
#include "absl/strings/string_view.h"
#include "value_field.h"

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)
{
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 "utils/string_view.h"
#include "absl/strings/string_view.h"
#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,
dsn::string_view user_data)
absl::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(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
3 changes: 2 additions & 1 deletion src/base/value_schema_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "value_schema_manager.h"

#include <absl/strings/string_view.h>
#include <iterator>
#include <utility>

Expand Down Expand Up @@ -46,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,
dsn::string_view value) const
absl::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 "utils/string_view.h"
#include "absl/strings/string_view.h"

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, 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;

Expand Down
7 changes: 4 additions & 3 deletions src/base/value_schema_v0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "value_schema_v0.h"

#include <absl/strings/string_view.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
Expand All @@ -31,7 +32,7 @@
#include "utils/ports.h"

namespace pegasus {
std::unique_ptr<value_field> value_schema_v0::extract_field(dsn::string_view value,
std::unique_ptr<value_field> value_schema_v0::extract_field(absl::string_view value,
value_field_type type)
{
std::unique_ptr<value_field> field = nullptr;
Expand Down Expand Up @@ -79,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());

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 {&params.write_slices[0], static_cast<int>(params.write_slices.size())};
}

std::unique_ptr<value_field> value_schema_v0::extract_timestamp(dsn::string_view value)
std::unique_ptr<value_field> value_schema_v0::extract_timestamp(absl::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 "utils/string_view.h"
#include "absl/strings/string_view.h"
#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(dsn::string_view value,
std::unique_ptr<value_field> 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<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(dsn::string_view value);
std::unique_ptr<value_field> extract_timestamp(absl::string_view value);
void update_expire_ts(std::string &value, std::unique_ptr<value_field> field);
};
} // namespace pegasus
9 changes: 5 additions & 4 deletions src/base/value_schema_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "value_schema_v1.h"

#include <absl/strings/string_view.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
Expand All @@ -31,7 +32,7 @@
#include "utils/ports.h"

namespace pegasus {
std::unique_ptr<value_field> value_schema_v1::extract_field(dsn::string_view value,
std::unique_ptr<value_field> value_schema_v1::extract_field(absl::string_view value,
value_field_type type)
{
std::unique_ptr<value_field> field = nullptr;
Expand Down Expand Up @@ -87,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());

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 {&params.write_slices[0], static_cast<int>(params.write_slices.size())};
}

std::unique_ptr<value_field> value_schema_v1::extract_timestamp(dsn::string_view value)
std::unique_ptr<value_field> value_schema_v1::extract_timestamp(absl::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(dsn::string_view value)
std::unique_ptr<value_field> value_schema_v1::extract_time_tag(absl::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 "utils/string_view.h"
#include "absl/strings/string_view.h"
#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(dsn::string_view value,
std::unique_ptr<value_field> 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<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(dsn::string_view value);
std::unique_ptr<value_field> extract_time_tag(dsn::string_view value);
std::unique_ptr<value_field> extract_timestamp(absl::string_view value);
std::unique_ptr<value_field> extract_time_tag(absl::string_view value);
void update_expire_ts(std::string &value, std::unique_ptr<value_field> field);
};

Expand Down
Loading

0 comments on commit 79cd226

Please sign in to comment.