2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 21:59:46 +00:00
|
|
|
//
|
2013-08-13 21:04:56 +00:00
|
|
|
// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2021-09-27 14:42:36 +00:00
|
|
|
#include "rocksdb/slice.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-07-01 23:13:49 +00:00
|
|
|
#include <algorithm>
|
2021-09-27 14:42:36 +00:00
|
|
|
|
|
|
|
#include "rocksdb/convenience.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/slice_transform.h"
|
2021-09-27 14:42:36 +00:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
|
|
|
#include "rocksdb/utilities/options_type.h"
|
2014-11-25 04:44:49 +00:00
|
|
|
#include "util/string_util.h"
|
2013-08-13 21:04:56 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2013-08-13 21:04:56 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class FixedPrefixTransform : public SliceTransform {
|
|
|
|
private:
|
|
|
|
size_t prefix_len_;
|
2022-01-27 18:04:35 +00:00
|
|
|
std::string id_;
|
2013-08-13 21:04:56 +00:00
|
|
|
|
|
|
|
public:
|
2021-09-27 14:42:36 +00:00
|
|
|
explicit FixedPrefixTransform(size_t prefix_len) : prefix_len_(prefix_len) {
|
2022-05-06 20:03:58 +00:00
|
|
|
id_ = std::string(kClassName()) + "." + std::to_string(prefix_len_);
|
2021-09-27 14:42:36 +00:00
|
|
|
}
|
2013-08-13 21:04:56 +00:00
|
|
|
|
2021-09-27 14:42:36 +00:00
|
|
|
static const char* kClassName() { return "rocksdb.FixedPrefix"; }
|
|
|
|
static const char* kNickName() { return "fixed"; }
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
const char* NickName() const override { return kNickName(); }
|
|
|
|
|
2022-01-27 18:04:35 +00:00
|
|
|
bool IsInstanceOf(const std::string& name) const override {
|
|
|
|
if (name == id_) {
|
|
|
|
return true;
|
|
|
|
} else if (StartsWith(name, kNickName())) {
|
2022-05-06 20:03:58 +00:00
|
|
|
std::string alt_id =
|
|
|
|
std::string(kNickName()) + ":" + std::to_string(prefix_len_);
|
2022-01-27 18:04:35 +00:00
|
|
|
if (name == alt_id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SliceTransform::IsInstanceOf(name);
|
2021-09-27 14:42:36 +00:00
|
|
|
}
|
2013-08-13 21:04:56 +00:00
|
|
|
|
2022-01-27 18:04:35 +00:00
|
|
|
std::string GetId() const override { return id_; }
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Slice Transform(const Slice& src) const override {
|
2013-08-13 21:04:56 +00:00
|
|
|
assert(InDomain(src));
|
|
|
|
return Slice(src.data(), prefix_len_);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InDomain(const Slice& src) const override {
|
2013-08-13 21:04:56 +00:00
|
|
|
return (src.size() >= prefix_len_);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InRange(const Slice& dst) const override {
|
2013-08-13 21:04:56 +00:00
|
|
|
return (dst.size() == prefix_len_);
|
|
|
|
}
|
2015-01-21 19:09:56 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool FullLengthEnabled(size_t* len) const override {
|
2018-06-26 22:56:26 +00:00
|
|
|
*len = prefix_len_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool SameResultWhenAppended(const Slice& prefix) const override {
|
2015-01-21 19:09:56 +00:00
|
|
|
return InDomain(prefix);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CappedPrefixTransform : public SliceTransform {
|
|
|
|
private:
|
|
|
|
size_t cap_len_;
|
2022-01-27 18:04:35 +00:00
|
|
|
std::string id_;
|
2015-01-21 19:09:56 +00:00
|
|
|
|
|
|
|
public:
|
2021-09-27 14:42:36 +00:00
|
|
|
explicit CappedPrefixTransform(size_t cap_len) : cap_len_(cap_len) {
|
2022-05-06 20:03:58 +00:00
|
|
|
id_ = std::string(kClassName()) + "." + std::to_string(cap_len_);
|
2021-09-27 14:42:36 +00:00
|
|
|
}
|
2015-01-21 19:09:56 +00:00
|
|
|
|
2021-09-27 14:42:36 +00:00
|
|
|
static const char* kClassName() { return "rocksdb.CappedPrefix"; }
|
|
|
|
static const char* kNickName() { return "capped"; }
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
const char* NickName() const override { return kNickName(); }
|
2022-01-27 18:04:35 +00:00
|
|
|
std::string GetId() const override { return id_; }
|
|
|
|
|
|
|
|
bool IsInstanceOf(const std::string& name) const override {
|
|
|
|
if (name == id_) {
|
|
|
|
return true;
|
|
|
|
} else if (StartsWith(name, kNickName())) {
|
2022-05-06 20:03:58 +00:00
|
|
|
std::string alt_id =
|
|
|
|
std::string(kNickName()) + ":" + std::to_string(cap_len_);
|
2022-01-27 18:04:35 +00:00
|
|
|
if (name == alt_id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SliceTransform::IsInstanceOf(name);
|
2021-09-27 14:42:36 +00:00
|
|
|
}
|
2015-01-21 19:09:56 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Slice Transform(const Slice& src) const override {
|
2015-01-21 19:09:56 +00:00
|
|
|
assert(InDomain(src));
|
|
|
|
return Slice(src.data(), std::min(cap_len_, src.size()));
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InDomain(const Slice& /*src*/) const override { return true; }
|
2015-01-21 19:09:56 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InRange(const Slice& dst) const override {
|
2015-01-21 19:09:56 +00:00
|
|
|
return (dst.size() <= cap_len_);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool FullLengthEnabled(size_t* len) const override {
|
2018-06-26 22:56:26 +00:00
|
|
|
*len = cap_len_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool SameResultWhenAppended(const Slice& prefix) const override {
|
2015-01-21 19:09:56 +00:00
|
|
|
return prefix.size() >= cap_len_;
|
|
|
|
}
|
2013-08-13 21:04:56 +00:00
|
|
|
};
|
2013-08-23 06:10:02 +00:00
|
|
|
|
|
|
|
class NoopTransform : public SliceTransform {
|
|
|
|
public:
|
|
|
|
explicit NoopTransform() { }
|
|
|
|
|
2021-09-27 14:42:36 +00:00
|
|
|
static const char* kClassName() { return "rocksdb.Noop"; }
|
|
|
|
const char* Name() const override { return kClassName(); }
|
2013-08-23 06:10:02 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Slice Transform(const Slice& src) const override { return src; }
|
2013-08-23 06:10:02 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InDomain(const Slice& /*src*/) const override { return true; }
|
2013-08-23 06:10:02 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InRange(const Slice& /*dst*/) const override { return true; }
|
2015-01-21 19:09:56 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool SameResultWhenAppended(const Slice& /*prefix*/) const override {
|
2015-01-21 19:09:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-08-23 06:10:02 +00:00
|
|
|
};
|
|
|
|
|
2021-09-27 14:42:36 +00:00
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
const SliceTransform* NewFixedPrefixTransform(size_t prefix_len) {
|
|
|
|
return new FixedPrefixTransform(prefix_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SliceTransform* NewCappedPrefixTransform(size_t cap_len) {
|
|
|
|
return new CappedPrefixTransform(cap_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SliceTransform* NewNoopTransform() { return new NoopTransform; }
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
static int RegisterBuiltinSliceTransform(ObjectLibrary& library,
|
|
|
|
const std::string& /*arg*/) {
|
2021-12-29 15:55:17 +00:00
|
|
|
// For the builtin transforms, the format is typically
|
2022-01-27 18:04:35 +00:00
|
|
|
// [Name].[0-9]+ or [NickName]:[0-9]+
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<const SliceTransform>(
|
2021-09-27 14:42:36 +00:00
|
|
|
NoopTransform::kClassName(),
|
|
|
|
[](const std::string& /*uri*/,
|
|
|
|
std::unique_ptr<const SliceTransform>* guard,
|
|
|
|
std::string* /*errmsg*/) {
|
|
|
|
guard->reset(NewNoopTransform());
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<const SliceTransform>(
|
2021-12-29 15:55:17 +00:00
|
|
|
ObjectLibrary::PatternEntry(FixedPrefixTransform::kNickName(), false)
|
|
|
|
.AddNumber(":"),
|
2021-09-27 14:42:36 +00:00
|
|
|
[](const std::string& uri, std::unique_ptr<const SliceTransform>* guard,
|
|
|
|
std::string* /*errmsg*/) {
|
|
|
|
auto colon = uri.find(":");
|
|
|
|
auto len = ParseSizeT(uri.substr(colon + 1));
|
|
|
|
guard->reset(NewFixedPrefixTransform(len));
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<const SliceTransform>(
|
2022-01-27 18:04:35 +00:00
|
|
|
ObjectLibrary::PatternEntry(FixedPrefixTransform::kClassName(), false)
|
2021-12-29 15:55:17 +00:00
|
|
|
.AddNumber("."),
|
2021-09-27 14:42:36 +00:00
|
|
|
[](const std::string& uri, std::unique_ptr<const SliceTransform>* guard,
|
|
|
|
std::string* /*errmsg*/) {
|
2022-01-27 18:04:35 +00:00
|
|
|
auto len = ParseSizeT(
|
|
|
|
uri.substr(strlen(FixedPrefixTransform::kClassName()) + 1));
|
|
|
|
guard->reset(NewFixedPrefixTransform(len));
|
2021-09-27 14:42:36 +00:00
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<const SliceTransform>(
|
2021-12-29 15:55:17 +00:00
|
|
|
ObjectLibrary::PatternEntry(CappedPrefixTransform::kNickName(), false)
|
|
|
|
.AddNumber(":"),
|
2021-09-27 14:42:36 +00:00
|
|
|
[](const std::string& uri, std::unique_ptr<const SliceTransform>* guard,
|
|
|
|
std::string* /*errmsg*/) {
|
|
|
|
auto colon = uri.find(":");
|
|
|
|
auto len = ParseSizeT(uri.substr(colon + 1));
|
|
|
|
guard->reset(NewCappedPrefixTransform(len));
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<const SliceTransform>(
|
2022-01-27 18:04:35 +00:00
|
|
|
ObjectLibrary::PatternEntry(CappedPrefixTransform::kClassName(), false)
|
2021-12-29 15:55:17 +00:00
|
|
|
.AddNumber("."),
|
2021-09-27 14:42:36 +00:00
|
|
|
[](const std::string& uri, std::unique_ptr<const SliceTransform>* guard,
|
|
|
|
std::string* /*errmsg*/) {
|
2022-01-27 18:04:35 +00:00
|
|
|
auto len = ParseSizeT(
|
|
|
|
uri.substr(strlen(CappedPrefixTransform::kClassName()) + 1));
|
|
|
|
guard->reset(NewCappedPrefixTransform(len));
|
2021-09-27 14:42:36 +00:00
|
|
|
return guard->get();
|
|
|
|
});
|
2021-12-29 15:55:17 +00:00
|
|
|
size_t num_types;
|
|
|
|
return static_cast<int>(library.GetFactoryCount(&num_types));
|
2021-09-27 14:42:36 +00:00
|
|
|
}
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
|
|
|
Status SliceTransform::CreateFromString(
|
|
|
|
const ConfigOptions& config_options, const std::string& value,
|
|
|
|
std::shared_ptr<const SliceTransform>* result) {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
static std::once_flag once;
|
|
|
|
std::call_once(once, [&]() {
|
|
|
|
RegisterBuiltinSliceTransform(*(ObjectLibrary::Default().get()), "");
|
|
|
|
});
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
std::string id;
|
|
|
|
std::unordered_map<std::string, std::string> opt_map;
|
|
|
|
Status status = Customizable::GetOptionsMap(config_options, result->get(),
|
|
|
|
value, &id, &opt_map);
|
|
|
|
if (!status.ok()) { // GetOptionsMap failed
|
|
|
|
return status;
|
2021-10-19 17:42:04 +00:00
|
|
|
} else if (id.empty() && opt_map.empty()) {
|
|
|
|
result->reset();
|
|
|
|
} else {
|
2021-09-27 14:42:36 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2021-10-19 17:42:04 +00:00
|
|
|
status = config_options.registry->NewSharedObject(id, result);
|
2021-09-27 14:42:36 +00:00
|
|
|
#else
|
2021-10-19 17:42:04 +00:00
|
|
|
auto Matches = [](const std::string& input, size_t size,
|
|
|
|
const char* pattern, char sep) {
|
|
|
|
auto plen = strlen(pattern);
|
|
|
|
return (size > plen + 2 && input[plen] == sep &&
|
|
|
|
StartsWith(input, pattern));
|
|
|
|
};
|
|
|
|
|
|
|
|
auto size = id.size();
|
|
|
|
if (id == NoopTransform::kClassName()) {
|
|
|
|
result->reset(NewNoopTransform());
|
|
|
|
} else if (Matches(id, size, FixedPrefixTransform::kNickName(), ':')) {
|
|
|
|
auto fixed = strlen(FixedPrefixTransform::kNickName());
|
|
|
|
auto len = ParseSizeT(id.substr(fixed + 1));
|
|
|
|
result->reset(NewFixedPrefixTransform(len));
|
|
|
|
} else if (Matches(id, size, CappedPrefixTransform::kNickName(), ':')) {
|
|
|
|
auto capped = strlen(CappedPrefixTransform::kNickName());
|
|
|
|
auto len = ParseSizeT(id.substr(capped + 1));
|
|
|
|
result->reset(NewCappedPrefixTransform(len));
|
|
|
|
} else if (Matches(id, size, CappedPrefixTransform::kClassName(), '.')) {
|
|
|
|
auto capped = strlen(CappedPrefixTransform::kClassName());
|
|
|
|
auto len = ParseSizeT(id.substr(capped + 1));
|
|
|
|
result->reset(NewCappedPrefixTransform(len));
|
|
|
|
} else if (Matches(id, size, FixedPrefixTransform::kClassName(), '.')) {
|
|
|
|
auto fixed = strlen(FixedPrefixTransform::kClassName());
|
|
|
|
auto len = ParseSizeT(id.substr(fixed + 1));
|
|
|
|
result->reset(NewFixedPrefixTransform(len));
|
|
|
|
} else {
|
|
|
|
status = Status::NotSupported("Cannot load object in LITE mode ", id);
|
|
|
|
}
|
2021-09-27 14:42:36 +00:00
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
if (config_options.ignore_unsupported_options && status.IsNotSupported()) {
|
|
|
|
return Status::OK();
|
2021-10-19 17:42:04 +00:00
|
|
|
} else if (status.ok()) {
|
|
|
|
SliceTransform* transform = const_cast<SliceTransform*>(result->get());
|
|
|
|
status =
|
|
|
|
Customizable::ConfigureNewObject(config_options, transform, opt_map);
|
2021-09-27 14:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
2022-01-21 19:36:36 +00:00
|
|
|
}
|
2021-09-27 14:42:36 +00:00
|
|
|
|
|
|
|
std::string SliceTransform::AsString() const {
|
2022-01-28 00:57:03 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2022-01-27 18:04:35 +00:00
|
|
|
if (HasRegisteredOptions()) {
|
|
|
|
ConfigOptions opts;
|
|
|
|
opts.delimiter = ";";
|
|
|
|
return ToString(opts);
|
|
|
|
}
|
2022-01-28 00:57:03 +00:00
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
return GetId();
|
2013-08-13 21:04:56 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 04:25:12 +00:00
|
|
|
// 2 small internal utility functions, for efficient hex conversions
|
|
|
|
// and no need for snprintf, toupper etc...
|
2022-05-06 20:03:58 +00:00
|
|
|
// Originally from wdt/util/EncryptionUtils.cpp - for
|
|
|
|
// std::to_string(true)/DecodeHex:
|
2016-03-30 04:25:12 +00:00
|
|
|
char toHex(unsigned char v) {
|
|
|
|
if (v <= 9) {
|
|
|
|
return '0' + v;
|
|
|
|
}
|
|
|
|
return 'A' + v - 10;
|
|
|
|
}
|
|
|
|
// most of the code is for validation/error check
|
|
|
|
int fromHex(char c) {
|
|
|
|
// toupper:
|
|
|
|
if (c >= 'a' && c <= 'f') {
|
|
|
|
c -= ('a' - 'A'); // aka 0x20
|
|
|
|
}
|
|
|
|
// validation
|
|
|
|
if (c < '0' || (c > '9' && (c < 'A' || c > 'F'))) {
|
|
|
|
return -1; // invalid not 0-9A-F hex char
|
|
|
|
}
|
|
|
|
if (c <= '9') {
|
|
|
|
return c - '0';
|
|
|
|
}
|
|
|
|
return c - 'A' + 10;
|
|
|
|
}
|
2015-07-07 23:58:20 +00:00
|
|
|
|
2016-06-09 22:30:19 +00:00
|
|
|
Slice::Slice(const SliceParts& parts, std::string* buf) {
|
|
|
|
size_t length = 0;
|
|
|
|
for (int i = 0; i < parts.num_parts; ++i) {
|
|
|
|
length += parts.parts[i].size();
|
|
|
|
}
|
|
|
|
buf->reserve(length);
|
|
|
|
|
|
|
|
for (int i = 0; i < parts.num_parts; ++i) {
|
|
|
|
buf->append(parts.parts[i].data(), parts.parts[i].size());
|
|
|
|
}
|
|
|
|
data_ = buf->data();
|
|
|
|
size_ = buf->size();
|
|
|
|
}
|
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
// Return a string that contains the copy of the referenced data.
|
|
|
|
std::string Slice::ToString(bool hex) const {
|
2015-07-13 19:11:05 +00:00
|
|
|
std::string result; // RVO/NRVO/move
|
2015-07-07 23:58:20 +00:00
|
|
|
if (hex) {
|
2016-03-30 04:25:12 +00:00
|
|
|
result.reserve(2 * size_);
|
|
|
|
for (size_t i = 0; i < size_; ++i) {
|
|
|
|
unsigned char c = data_[i];
|
|
|
|
result.push_back(toHex(c >> 4));
|
|
|
|
result.push_back(toHex(c & 0xf));
|
2015-07-07 23:58:20 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
result.assign(data_, size_);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 23:09:09 +00:00
|
|
|
// Originally from rocksdb/utilities/ldb_cmd.h
|
2016-03-30 04:25:12 +00:00
|
|
|
bool Slice::DecodeHex(std::string* result) const {
|
|
|
|
std::string::size_type len = size_;
|
|
|
|
if (len % 2) {
|
|
|
|
// Hex string must be even number of hex digits to get complete bytes back
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!result) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
result->clear();
|
|
|
|
result->reserve(len / 2);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < len;) {
|
|
|
|
int h1 = fromHex(data_[i++]);
|
|
|
|
if (h1 < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int h2 = fromHex(data_[i++]);
|
|
|
|
if (h2 < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 17:48:47 +00:00
|
|
|
result->push_back(static_cast<char>((h1 << 4) | h2));
|
2016-03-30 04:25:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-07 22:24:41 +00:00
|
|
|
PinnableSlice::PinnableSlice(PinnableSlice&& other) {
|
|
|
|
*this = std::move(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
PinnableSlice& PinnableSlice::operator=(PinnableSlice&& other) {
|
|
|
|
if (this != &other) {
|
|
|
|
Cleanable::Reset();
|
|
|
|
Cleanable::operator=(std::move(other));
|
|
|
|
size_ = other.size_;
|
|
|
|
pinned_ = other.pinned_;
|
|
|
|
if (pinned_) {
|
|
|
|
data_ = other.data_;
|
|
|
|
// When it's pinned, buf should no longer be of use.
|
|
|
|
} else {
|
|
|
|
if (other.buf_ == &other.self_space_) {
|
|
|
|
self_space_ = std::move(other.self_space_);
|
|
|
|
buf_ = &self_space_;
|
|
|
|
data_ = buf_->data();
|
|
|
|
} else {
|
|
|
|
buf_ = other.buf_;
|
|
|
|
data_ = other.data_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
other.self_space_.clear();
|
|
|
|
other.buf_ = &other.self_space_;
|
|
|
|
other.pinned_ = false;
|
|
|
|
other.PinSelf();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|