[CF] Fix lint errors in CF code

Summary: Big CF diff uncovered some lint errors. This diff fixes some of them. Not much to see here

Test Plan: make check

Reviewers: dhruba, haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D16347
main
Igor Canadi 10 years ago
parent 8b7ab9951c
commit 9bce2b2a84
  1. 57
      db/column_family_test.cc
  2. 2
      db/db_impl.cc
  3. 1
      db/db_impl.h
  4. 1
      db/memtable_list.h
  5. 6
      db/version_set.cc

@ -7,6 +7,10 @@
// Use of this source code is governed by a BSD-style license that can be // 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. // found in the LICENSE file. See the AUTHORS file for names of contributors.
#include <algorithm>
#include <vector>
#include <string>
#include "db/db_impl.h" #include "db/db_impl.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
#include "rocksdb/db.h" #include "rocksdb/db.h"
@ -14,14 +18,8 @@
#include "util/testutil.h" #include "util/testutil.h"
#include "utilities/merge_operators.h" #include "utilities/merge_operators.h"
#include <algorithm>
#include <vector>
#include <string>
namespace rocksdb { namespace rocksdb {
using namespace std;
namespace { namespace {
std::string RandomString(Random* rnd, int len) { std::string RandomString(Random* rnd, int len) {
std::string r; std::string r;
@ -52,8 +50,8 @@ class ColumnFamilyTest {
return Open({"default"}); return Open({"default"});
} }
Status Open(vector<string> cf) { Status Open(std::vector<std::string> cf) {
vector<ColumnFamilyDescriptor> column_families; std::vector<ColumnFamilyDescriptor> column_families;
for (auto x : cf) { for (auto x : cf) {
column_families.push_back( column_families.push_back(
ColumnFamilyDescriptor(x, column_family_options_)); ColumnFamilyDescriptor(x, column_family_options_));
@ -73,7 +71,7 @@ class ColumnFamilyTest {
ASSERT_OK(DestroyDB(dbname_, Options(db_options_, column_family_options_))); ASSERT_OK(DestroyDB(dbname_, Options(db_options_, column_family_options_)));
} }
void CreateColumnFamilies(const vector<string>& cfs) { void CreateColumnFamilies(const std::vector<std::string>& cfs) {
int cfi = handles_.size(); int cfi = handles_.size();
handles_.resize(cfi + cfs.size()); handles_.resize(cfi + cfs.size());
for (auto cf : cfs) { for (auto cf : cfs) {
@ -82,7 +80,7 @@ class ColumnFamilyTest {
} }
} }
void DropColumnFamilies(const vector<int>& cfs) { void DropColumnFamilies(const std::vector<int>& cfs) {
for (auto cf : cfs) { for (auto cf : cfs) {
ASSERT_OK(db_->DropColumnFamily(handles_[cf])); ASSERT_OK(db_->DropColumnFamily(handles_[cf]));
delete handles_[cf]; delete handles_[cf];
@ -102,20 +100,20 @@ class ColumnFamilyTest {
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[cf])); ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[cf]));
} }
Status Put(int cf, const string& key, const string& value) { Status Put(int cf, const std::string& key, const std::string& value) {
return db_->Put(WriteOptions(), handles_[cf], Slice(key), Slice(value)); return db_->Put(WriteOptions(), handles_[cf], Slice(key), Slice(value));
} }
Status Merge(int cf, const string& key, const string& value) { Status Merge(int cf, const std::string& key, const std::string& value) {
return db_->Merge(WriteOptions(), handles_[cf], Slice(key), Slice(value)); return db_->Merge(WriteOptions(), handles_[cf], Slice(key), Slice(value));
} }
Status Flush(int cf) { Status Flush(int cf) {
return db_->Flush(FlushOptions(), handles_[cf]); return db_->Flush(FlushOptions(), handles_[cf]);
} }
string Get(int cf, const string& key) { std::string Get(int cf, const std::string& key) {
ReadOptions options; ReadOptions options;
options.verify_checksums = true; options.verify_checksums = true;
string result; std::string result;
Status s = db_->Get(options, handles_[cf], Slice(key), &result); Status s = db_->Get(options, handles_[cf], Slice(key), &result);
if (s.IsNotFound()) { if (s.IsNotFound()) {
result = "NOT_FOUND"; result = "NOT_FOUND";
@ -130,7 +128,7 @@ class ColumnFamilyTest {
} }
int NumTableFilesAtLevel(int cf, int level) { int NumTableFilesAtLevel(int cf, int level) {
string property; std::string property;
ASSERT_TRUE(db_->GetProperty( ASSERT_TRUE(db_->GetProperty(
handles_[cf], "rocksdb.num-files-at-level" + NumberToString(level), handles_[cf], "rocksdb.num-files-at-level" + NumberToString(level),
&property)); &property));
@ -138,8 +136,8 @@ class ColumnFamilyTest {
} }
// Return spread of files per level // Return spread of files per level
string FilesPerLevel(int cf) { std::string FilesPerLevel(int cf) {
string result; std::string result;
int last_non_zero_offset = 0; int last_non_zero_offset = 0;
for (int level = 0; level < column_family_options_.num_levels; level++) { for (int level = 0; level < column_family_options_.num_levels; level++) {
int f = NumTableFilesAtLevel(cf, level); int f = NumTableFilesAtLevel(cf, level);
@ -162,8 +160,8 @@ class ColumnFamilyTest {
// Do n memtable flushes, each of which produces an sstable // Do n memtable flushes, each of which produces an sstable
// covering the range [small,large]. // covering the range [small,large].
void MakeTables(int cf, int n, const string& small, void MakeTables(int cf, int n, const std::string& small,
const string& large) { const std::string& large) {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
ASSERT_OK(Put(cf, small, "begin")); ASSERT_OK(Put(cf, small, "begin"));
ASSERT_OK(Put(cf, large, "end")); ASSERT_OK(Put(cf, large, "end"));
@ -183,7 +181,7 @@ class ColumnFamilyTest {
return ret; return ret;
} }
void CopyFile(const string& source, const string& destination, void CopyFile(const std::string& source, const std::string& destination,
uint64_t size = 0) { uint64_t size = 0) {
const EnvOptions soptions; const EnvOptions soptions;
unique_ptr<SequentialFile> srcfile; unique_ptr<SequentialFile> srcfile;
@ -199,7 +197,7 @@ class ColumnFamilyTest {
char buffer[4096]; char buffer[4096];
Slice slice; Slice slice;
while (size > 0) { while (size > 0) {
uint64_t one = min(uint64_t(sizeof(buffer)), size); uint64_t one = std::min(uint64_t(sizeof(buffer)), size);
ASSERT_OK(srcfile->Read(one, &slice, buffer)); ASSERT_OK(srcfile->Read(one, &slice, buffer));
ASSERT_OK(destfile->Append(slice)); ASSERT_OK(destfile->Append(slice));
size -= slice.size(); size -= slice.size();
@ -207,10 +205,10 @@ class ColumnFamilyTest {
ASSERT_OK(destfile->Close()); ASSERT_OK(destfile->Close());
} }
vector<ColumnFamilyHandle*> handles_; std::vector<ColumnFamilyHandle*> handles_;
ColumnFamilyOptions column_family_options_; ColumnFamilyOptions column_family_options_;
DBOptions db_options_; DBOptions db_options_;
string dbname_; std::string dbname_;
DB* db_ = nullptr; DB* db_ = nullptr;
Env* env_; Env* env_;
Random rnd_; Random rnd_;
@ -226,10 +224,11 @@ TEST(ColumnFamilyTest, AddDrop) {
ASSERT_OK(Open({"default", "one", "three", "four"})); ASSERT_OK(Open({"default", "one", "three", "four"}));
Close(); Close();
vector<string> families; std::vector<std::string> families;
ASSERT_OK(DB::ListColumnFamilies(db_options_, dbname_, &families)); ASSERT_OK(DB::ListColumnFamilies(db_options_, dbname_, &families));
sort(families.begin(), families.end()); sort(families.begin(), families.end());
ASSERT_TRUE(families == vector<string>({"default", "four", "one", "three"})); ASSERT_TRUE(families ==
std::vector<std::string>({"default", "four", "one", "three"}));
} }
TEST(ColumnFamilyTest, DropTest) { TEST(ColumnFamilyTest, DropTest) {
@ -299,12 +298,12 @@ TEST(ColumnFamilyTest, ReadWrite) {
} }
TEST(ColumnFamilyTest, IgnoreRecoveredLog) { TEST(ColumnFamilyTest, IgnoreRecoveredLog) {
string backup_logs = dbname_ + "/backup_logs"; std::string backup_logs = dbname_ + "/backup_logs";
// delete old files in backup_logs directory // delete old files in backup_logs directory
ASSERT_OK(env_->CreateDirIfMissing(dbname_)); ASSERT_OK(env_->CreateDirIfMissing(dbname_));
ASSERT_OK(env_->CreateDirIfMissing(backup_logs)); ASSERT_OK(env_->CreateDirIfMissing(backup_logs));
vector<string> old_files; std::vector<std::string> old_files;
env_->GetChildren(backup_logs, &old_files); env_->GetChildren(backup_logs, &old_files);
for (auto& file : old_files) { for (auto& file : old_files) {
if (file != "." && file != "..") { if (file != "." && file != "..") {
@ -320,7 +319,7 @@ TEST(ColumnFamilyTest, IgnoreRecoveredLog) {
CreateColumnFamilies({"cf1", "cf2"}); CreateColumnFamilies({"cf1", "cf2"});
// fill up the DB // fill up the DB
string one, two, three; std::string one, two, three;
PutFixed64(&one, 1); PutFixed64(&one, 1);
PutFixed64(&two, 2); PutFixed64(&two, 2);
PutFixed64(&three, 3); PutFixed64(&three, 3);
@ -335,7 +334,7 @@ TEST(ColumnFamilyTest, IgnoreRecoveredLog) {
ASSERT_OK(Merge(1, "franjo", one)); ASSERT_OK(Merge(1, "franjo", one));
// copy the logs to backup // copy the logs to backup
vector<string> logs; std::vector<std::string> logs;
env_->GetChildren(db_options_.wal_dir, &logs); env_->GetChildren(db_options_.wal_dir, &logs);
for (auto& log : logs) { for (auto& log : logs) {
if (log != ".." && log != ".") { if (log != ".." && log != ".") {

@ -3159,7 +3159,7 @@ Status DBImpl::NewIterators(
const ReadOptions& options, const ReadOptions& options,
const std::vector<ColumnFamilyHandle*>& column_family, const std::vector<ColumnFamilyHandle*>& column_family,
std::vector<Iterator*>* iterators) { std::vector<Iterator*>* iterators) {
// TODO // TODO(icanadi)
return Status::NotSupported("Not yet!"); return Status::NotSupported("Not yet!");
} }

@ -13,6 +13,7 @@
#include <set> #include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <string>
#include "db/dbformat.h" #include "db/dbformat.h"
#include "db/log_writer.h" #include "db/log_writer.h"

@ -15,7 +15,6 @@
#include "rocksdb/iterator.h" #include "rocksdb/iterator.h"
#include "db/dbformat.h" #include "db/dbformat.h"
#include "db/memtable.h"
#include "db/skiplist.h" #include "db/skiplist.h"
#include "db/memtable.h" #include "db/memtable.h"
#include "rocksdb/db.h" #include "rocksdb/db.h"

@ -1962,7 +1962,6 @@ Status VersionSet::Recover(
Status VersionSet::ListColumnFamilies(std::vector<std::string>* column_families, Status VersionSet::ListColumnFamilies(std::vector<std::string>* column_families,
const std::string& dbname, Env* env) { const std::string& dbname, Env* env) {
// these are just for performance reasons, not correcntes, // these are just for performance reasons, not correcntes,
// so we're fine using the defaults // so we're fine using the defaults
EnvOptions soptions; EnvOptions soptions;
@ -2034,7 +2033,8 @@ Status VersionSet::ReduceNumberOfLevels(const std::string& dbname,
Status status; Status status;
std::vector<ColumnFamilyDescriptor> dummy; std::vector<ColumnFamilyDescriptor> dummy;
ColumnFamilyDescriptor dummy_descriptor(default_column_family_name, ColumnFamilyOptions(*options)); ColumnFamilyDescriptor dummy_descriptor(default_column_family_name,
ColumnFamilyOptions(*options));
dummy.push_back(dummy_descriptor); dummy.push_back(dummy_descriptor);
status = versions.Recover(dummy); status = versions.Recover(dummy);
if (!status.ok()) { if (!status.ok()) {
@ -2114,7 +2114,7 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname,
uint64_t log_number = 0; uint64_t log_number = 0;
uint64_t prev_log_number = 0; uint64_t prev_log_number = 0;
int count = 0; int count = 0;
// TODO works only for default column family currently // TODO(icanadi) works only for default column family currently
ColumnFamilyData* default_cfd = column_family_set_->GetDefault(); ColumnFamilyData* default_cfd = column_family_set_->GetDefault();
VersionSet::Builder builder(default_cfd, default_cfd->current()); VersionSet::Builder builder(default_cfd, default_cfd->current());

Loading…
Cancel
Save