// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
+// 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).
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
namespace test {
+extern const uint32_t kDefaultFormatVersion;
+extern const uint32_t kLatestFormatVersion;
+
// Store in *dst a random string of length "len" and return a Slice that
// references the generated data.
extern Slice RandomString(Random* rnd, int len, std::string* dst);
}
};
+#ifndef NDEBUG
// An internal comparator that just forward comparing results from the
// user comparator in it. Can be used to test entities that have no dependency
// on internal key structure but consumes InternalKeyComparator, like
virtual int Compare(const Slice& a, const Slice& b) const override {
return user_comparator()->Compare(a, b);
}
- virtual void FindShortestSeparator(std::string* start,
- const Slice& limit) const override {
- user_comparator()->FindShortestSeparator(start, limit);
- }
- virtual void FindShortSuccessor(std::string* key) const override {
- user_comparator()->FindShortSuccessor(key);
- }
};
+#endif
// A test comparator which compare two strings in this way:
// (1) first compare prefix of 8 bytes in alphabet order,
return -(suffix_a.compare(suffix_b));
}
}
- virtual void FindShortestSeparator(std::string* start,
- const Slice& limit) const override {}
+ virtual void FindShortestSeparator(std::string* /*start*/,
+ const Slice& /*limit*/) const override {}
- virtual void FindShortSuccessor(std::string* key) const override {}
+ virtual void FindShortSuccessor(std::string* /*key*/) const override {}
};
// Returns a user key comparator that can be used for comparing two uint64_t
virtual Status status() const override { return Status::OK(); }
+ virtual bool IsKeyPinned() const override { return true; }
+ virtual bool IsValuePinned() const override { return true; }
+
private:
std::vector<std::string> keys_;
std::vector<std::string> values_;
size_t current_;
};
-extern WritableFileWriter* GetWritableFileWriter(WritableFile* wf);
+extern WritableFileWriter* GetWritableFileWriter(WritableFile* wf,
+ const std::string& fname);
extern RandomAccessFileReader* GetRandomAccessFileReader(RandomAccessFile* raf);
-extern SequentialFileReader* GetSequentialFileReader(SequentialFile* se);
+extern SequentialFileReader* GetSequentialFileReader(SequentialFile* se,
+ const std::string& fname);
class StringSink: public WritableFile {
public:
public:
explicit RandomRWStringSink(StringSink* ss) : ss_(ss) {}
- Status Write(uint64_t offset, const Slice& data) {
+ Status Write(uint64_t offset, const Slice& data) override {
if (offset + data.size() > ss_->contents_.size()) {
- ss_->contents_.resize(offset + data.size(), '\0');
+ ss_->contents_.resize(static_cast<size_t>(offset) + data.size(), '\0');
}
char* pos = const_cast<char*>(ss_->contents_.data() + offset);
return Status::OK();
}
- Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const {
+ Status Read(uint64_t offset, size_t n, Slice* result,
+ char* /*scratch*/) const override {
*result = Slice(nullptr, 0);
if (offset < ss_->contents_.size()) {
size_t str_res_sz =
return Status::OK();
}
- Status Flush() { return Status::OK(); }
+ Status Flush() override { return Status::OK(); }
- Status Sync() { return Status::OK(); }
+ Status Sync() override { return Status::OK(); }
- Status Close() { return Status::OK(); }
+ Status Close() override { return Status::OK(); }
const std::string& contents() const { return ss_->contents(); }
class NullLogger : public Logger {
public:
using Logger::Logv;
- virtual void Logv(const char* format, va_list ap) override {}
+ virtual void Logv(const char* /*format*/, va_list /*ap*/) override {}
virtual size_t GetLogFileSize() const override { return 0; }
};
std::string last_merge_operand_key() { return last_merge_operand_key_; }
- bool Filter(int level, const rocksdb::Slice& key, const rocksdb::Slice& value,
- std::string* new_value, bool* value_changed) const override {
+ bool Filter(int /*level*/, const rocksdb::Slice& /*key*/,
+ const rocksdb::Slice& value, std::string* /*new_value*/,
+ bool* /*value_changed*/) const override {
if (value.size() == sizeof(uint64_t)) {
return num_ == DecodeFixed64(value.data());
}
return true;
}
- bool FilterMergeOperand(int level, const rocksdb::Slice& key,
+ bool FilterMergeOperand(int /*level*/, const rocksdb::Slice& key,
const rocksdb::Slice& value) const override {
last_merge_operand_key_ = key.ToString();
if (value.size() == sizeof(uint64_t)) {
"Attemp to read when it already reached eof.");
}
// TODO(yhchiang): Currently doesn't handle the overflow case.
- offset_ += n;
+ offset_ += static_cast<size_t>(n);
return Status::OK();
}
explicit StringSink(std::string* contents)
: WritableFile(), contents_(contents) {}
virtual Status Truncate(uint64_t size) override {
- contents_->resize(size);
+ contents_->resize(static_cast<size_t>(size));
return Status::OK();
}
virtual Status Close() override { return Status::OK(); }
// The following text is boilerplate that forwards all methods to target()
Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r,
- const EnvOptions& options) override {
+ const EnvOptions& /*options*/) override {
auto iter = files_.find(f);
if (iter == files_.end()) {
return Status::NotFound("The specified file does not exist", f);
r->reset(new SeqStringSource(iter->second));
return Status::OK();
}
- Status NewRandomAccessFile(const std::string& f,
- unique_ptr<RandomAccessFile>* r,
- const EnvOptions& options) override {
+ Status NewRandomAccessFile(const std::string& /*f*/,
+ unique_ptr<RandomAccessFile>* /*r*/,
+ const EnvOptions& /*options*/) override {
return Status::NotSupported();
}
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r,
- const EnvOptions& options) override {
+ const EnvOptions& /*options*/) override {
auto iter = files_.find(f);
if (iter != files_.end()) {
return Status::IOError("The specified file already exists", f);
r->reset(new StringSink(&files_[f]));
return Status::OK();
}
- virtual Status NewDirectory(const std::string& name,
- unique_ptr<Directory>* result) override {
+ virtual Status NewDirectory(const std::string& /*name*/,
+ unique_ptr<Directory>* /*result*/) override {
return Status::NotSupported();
}
Status FileExists(const std::string& f) override {
}
return Status::OK();
}
- Status GetChildren(const std::string& dir,
- std::vector<std::string>* r) override {
+ Status GetChildren(const std::string& /*dir*/,
+ std::vector<std::string>* /*r*/) override {
return Status::NotSupported();
}
Status DeleteFile(const std::string& f) override {
files_.erase(f);
return Status::OK();
}
- Status CreateDir(const std::string& d) override {
+ Status CreateDir(const std::string& /*d*/) override {
return Status::NotSupported();
}
- Status CreateDirIfMissing(const std::string& d) override {
+ Status CreateDirIfMissing(const std::string& /*d*/) override {
return Status::NotSupported();
}
- Status DeleteDir(const std::string& d) override {
+ Status DeleteDir(const std::string& /*d*/) override {
return Status::NotSupported();
}
Status GetFileSize(const std::string& f, uint64_t* s) override {
return Status::OK();
}
- Status GetFileModificationTime(const std::string& fname,
- uint64_t* file_mtime) override {
+ Status GetFileModificationTime(const std::string& /*fname*/,
+ uint64_t* /*file_mtime*/) override {
return Status::NotSupported();
}
- Status RenameFile(const std::string& s, const std::string& t) override {
+ Status RenameFile(const std::string& /*s*/,
+ const std::string& /*t*/) override {
return Status::NotSupported();
}
- Status LinkFile(const std::string& s, const std::string& t) override {
+ Status LinkFile(const std::string& /*s*/, const std::string& /*t*/) override {
return Status::NotSupported();
}
- Status LockFile(const std::string& f, FileLock** l) override {
+ Status LockFile(const std::string& /*f*/, FileLock** /*l*/) override {
return Status::NotSupported();
}
- Status UnlockFile(FileLock* l) override { return Status::NotSupported(); }
+ Status UnlockFile(FileLock* /*l*/) override { return Status::NotSupported(); }
protected:
std::unordered_map<std::string, std::string> files_;
void SetName(const std::string& name) { name_ = name; }
- virtual bool FullMergeV2(const MergeOperationInput& merge_in,
- MergeOperationOutput* merge_out) const override {
+ virtual bool FullMergeV2(const MergeOperationInput& /*merge_in*/,
+ MergeOperationOutput* /*merge_out*/) const override {
return false;
}
- virtual bool PartialMergeMulti(const Slice& key,
- const std::deque<Slice>& operand_list,
- std::string* new_value,
- Logger* logger) const override {
+ virtual bool PartialMergeMulti(const Slice& /*key*/,
+ const std::deque<Slice>& /*operand_list*/,
+ std::string* /*new_value*/,
+ Logger* /*logger*/) const override {
return false;
}
virtual const char* Name() const override { return name_.c_str(); }
void SetName(const std::string& name) { name_ = name; }
- bool Filter(int level, const Slice& key, const Slice& existing_value,
- std::string* new_value, bool* value_changed) const override {
+ bool Filter(int /*level*/, const Slice& /*key*/,
+ const Slice& /*existing_value*/, std::string* /*new_value*/,
+ bool* /*value_changed*/) const override {
return false;
}
void SetName(const std::string& name) { name_ = name; }
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
- const CompactionFilter::Context& context) override {
+ const CompactionFilter::Context& /*context*/) override {
return std::unique_ptr<CompactionFilter>();
}