Skip to content

Commit 9bd23c7

Browse files
committed
Correct class/structure declaration order.
1. Correct the class/struct declaration order to be IAW the Google C++ style guide[1]. 2. For non-copyable classes, switched from non-implemented private methods to explicitly deleted[2] methods. 3. Minor const and member initialization fixes. [1] https://google.github.io/styleguide/cppguide.html#Declaration_Order [2] http://eel.is/c++draft/dcl.fct.def.delete PiperOrigin-RevId: 246521844
1 parent c784d63 commit 9bd23c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+412
-403
lines changed

db/autocompact_test.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ namespace leveldb {
1212

1313
class AutoCompactTest {
1414
public:
15-
std::string dbname_;
16-
Cache* tiny_cache_;
17-
Options options_;
18-
DB* db_;
19-
2015
AutoCompactTest() {
2116
dbname_ = test::TmpDir() + "/autocompact_test";
2217
tiny_cache_ = NewLRUCache(100);
@@ -47,6 +42,12 @@ class AutoCompactTest {
4742
}
4843

4944
void DoReads(int n);
45+
46+
private:
47+
std::string dbname_;
48+
Cache* tiny_cache_;
49+
Options options_;
50+
DB* db_;
5051
};
5152

5253
static const int kValueSize = 200 * 1024;

db/c.cc

+17-15
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ struct leveldb_filelock_t {
8484
};
8585

8686
struct leveldb_comparator_t : public Comparator {
87-
void* state_;
88-
void (*destructor_)(void*);
89-
int (*compare_)(void*, const char* a, size_t alen, const char* b,
90-
size_t blen);
91-
const char* (*name_)(void*);
92-
9387
virtual ~leveldb_comparator_t() { (*destructor_)(state_); }
9488

9589
virtual int Compare(const Slice& a, const Slice& b) const {
@@ -101,18 +95,15 @@ struct leveldb_comparator_t : public Comparator {
10195
// No-ops since the C binding does not support key shortening methods.
10296
virtual void FindShortestSeparator(std::string*, const Slice&) const {}
10397
virtual void FindShortSuccessor(std::string* key) const {}
104-
};
10598

106-
struct leveldb_filterpolicy_t : public FilterPolicy {
10799
void* state_;
108100
void (*destructor_)(void*);
101+
int (*compare_)(void*, const char* a, size_t alen, const char* b,
102+
size_t blen);
109103
const char* (*name_)(void*);
110-
char* (*create_)(void*, const char* const* key_array,
111-
const size_t* key_length_array, int num_keys,
112-
size_t* filter_length);
113-
unsigned char (*key_match_)(void*, const char* key, size_t length,
114-
const char* filter, size_t filter_length);
104+
};
115105

106+
struct leveldb_filterpolicy_t : public FilterPolicy {
116107
virtual ~leveldb_filterpolicy_t() { (*destructor_)(state_); }
117108

118109
virtual const char* Name() const { return (*name_)(state_); }
@@ -134,6 +125,15 @@ struct leveldb_filterpolicy_t : public FilterPolicy {
134125
return (*key_match_)(state_, key.data(), key.size(), filter.data(),
135126
filter.size());
136127
}
128+
129+
void* state_;
130+
void (*destructor_)(void*);
131+
const char* (*name_)(void*);
132+
char* (*create_)(void*, const char* const* key_array,
133+
const size_t* key_length_array, int num_keys,
134+
size_t* filter_length);
135+
unsigned char (*key_match_)(void*, const char* key, size_t length,
136+
const char* filter, size_t filter_length);
137137
};
138138

139139
struct leveldb_env_t {
@@ -470,7 +470,8 @@ leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(int bits_per_key) {
470470
// they delegate to a NewBloomFilterPolicy() instead of user
471471
// supplied C functions.
472472
struct Wrapper : public leveldb_filterpolicy_t {
473-
const FilterPolicy* rep_;
473+
static void DoNothing(void*) {}
474+
474475
~Wrapper() { delete rep_; }
475476
const char* Name() const { return rep_->Name(); }
476477
void CreateFilter(const Slice* keys, int n, std::string* dst) const {
@@ -479,7 +480,8 @@ leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(int bits_per_key) {
479480
bool KeyMayMatch(const Slice& key, const Slice& filter) const {
480481
return rep_->KeyMayMatch(key, filter);
481482
}
482-
static void DoNothing(void*) {}
483+
484+
const FilterPolicy* rep_;
483485
};
484486
Wrapper* wrapper = new Wrapper;
485487
wrapper->rep_ = NewBloomFilterPolicy(bits_per_key);

db/corruption_test.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,14 @@ static const int kValueSize = 1000;
2222

2323
class CorruptionTest {
2424
public:
25-
test::ErrorEnv env_;
26-
std::string dbname_;
27-
Cache* tiny_cache_;
28-
Options options_;
29-
DB* db_;
30-
31-
CorruptionTest() {
32-
tiny_cache_ = NewLRUCache(100);
25+
CorruptionTest()
26+
: db_(nullptr),
27+
dbname_("/memenv/corruption_test"),
28+
tiny_cache_(NewLRUCache(100)) {
3329
options_.env = &env_;
3430
options_.block_cache = tiny_cache_;
35-
dbname_ = "/memenv/corruption_test";
3631
DestroyDB(dbname_, options_);
3732

38-
db_ = nullptr;
3933
options_.create_if_missing = true;
4034
Reopen();
4135
options_.create_if_missing = false;
@@ -185,6 +179,14 @@ class CorruptionTest {
185179
Random r(k);
186180
return test::RandomString(&r, kValueSize, storage);
187181
}
182+
183+
test::ErrorEnv env_;
184+
Options options_;
185+
DB* db_;
186+
187+
private:
188+
std::string dbname_;
189+
Cache* tiny_cache_;
188190
};
189191

190192
TEST(CorruptionTest, Recovery) {

db/db_impl.cc

+19-18
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,23 @@ const int kNumNonTableCacheFiles = 10;
4242

4343
// Information kept for every waiting writer
4444
struct DBImpl::Writer {
45+
explicit Writer(port::Mutex* mu)
46+
: batch(nullptr), sync(false), done(false), cv(mu) {}
47+
4548
Status status;
4649
WriteBatch* batch;
4750
bool sync;
4851
bool done;
4952
port::CondVar cv;
50-
51-
explicit Writer(port::Mutex* mu)
52-
: batch(nullptr), sync(false), done(false), cv(mu) {}
5353
};
5454

5555
struct DBImpl::CompactionState {
56-
Compaction* const compaction;
57-
58-
// Sequence numbers < smallest_snapshot are not significant since we
59-
// will never have to service a snapshot below smallest_snapshot.
60-
// Therefore if we have seen a sequence number S <= smallest_snapshot,
61-
// we can drop all entries for the same key with sequence numbers < S.
62-
SequenceNumber smallest_snapshot;
63-
6456
// Files produced by compaction
6557
struct Output {
6658
uint64_t number;
6759
uint64_t file_size;
6860
InternalKey smallest, largest;
6961
};
70-
std::vector<Output> outputs;
71-
72-
// State kept for output being generated
73-
WritableFile* outfile;
74-
TableBuilder* builder;
75-
76-
uint64_t total_bytes;
7762

7863
Output* current_output() { return &outputs[outputs.size() - 1]; }
7964

@@ -83,6 +68,22 @@ struct DBImpl::CompactionState {
8368
outfile(nullptr),
8469
builder(nullptr),
8570
total_bytes(0) {}
71+
72+
Compaction* const compaction;
73+
74+
// Sequence numbers < smallest_snapshot are not significant since we
75+
// will never have to service a snapshot below smallest_snapshot.
76+
// Therefore if we have seen a sequence number S <= smallest_snapshot,
77+
// we can drop all entries for the same key with sequence numbers < S.
78+
SequenceNumber smallest_snapshot;
79+
80+
std::vector<Output> outputs;
81+
82+
// State kept for output being generated
83+
WritableFile* outfile;
84+
TableBuilder* builder;
85+
86+
uint64_t total_bytes;
8687
};
8788

8889
// Fix user-supplied options to be reasonable

db/db_impl.h

+33-31
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class VersionSet;
2929
class DBImpl : public DB {
3030
public:
3131
DBImpl(const Options& options, const std::string& dbname);
32+
33+
DBImpl(const DBImpl&) = delete;
34+
DBImpl& operator=(const DBImpl&) = delete;
35+
3236
virtual ~DBImpl();
3337

3438
// Implementations of the DB interface
@@ -71,6 +75,31 @@ class DBImpl : public DB {
7175
struct CompactionState;
7276
struct Writer;
7377

78+
// Information for a manual compaction
79+
struct ManualCompaction {
80+
int level;
81+
bool done;
82+
const InternalKey* begin; // null means beginning of key range
83+
const InternalKey* end; // null means end of key range
84+
InternalKey tmp_storage; // Used to keep track of compaction progress
85+
};
86+
87+
// Per level compaction stats. stats_[level] stores the stats for
88+
// compactions that produced data for the specified "level".
89+
struct CompactionStats {
90+
CompactionStats() : micros(0), bytes_read(0), bytes_written(0) {}
91+
92+
void Add(const CompactionStats& c) {
93+
this->micros += c.micros;
94+
this->bytes_read += c.bytes_read;
95+
this->bytes_written += c.bytes_written;
96+
}
97+
98+
int64_t micros;
99+
int64_t bytes_read;
100+
int64_t bytes_written;
101+
};
102+
74103
Iterator* NewInternalIterator(const ReadOptions&,
75104
SequenceNumber* latest_snapshot,
76105
uint32_t* seed);
@@ -121,6 +150,10 @@ class DBImpl : public DB {
121150
Status InstallCompactionResults(CompactionState* compact)
122151
EXCLUSIVE_LOCKS_REQUIRED(mutex_);
123152

153+
const Comparator* user_comparator() const {
154+
return internal_comparator_.user_comparator();
155+
}
156+
124157
// Constant after construction
125158
Env* const env_;
126159
const InternalKeyComparator internal_comparator_;
@@ -161,45 +194,14 @@ class DBImpl : public DB {
161194
// Has a background compaction been scheduled or is running?
162195
bool background_compaction_scheduled_ GUARDED_BY(mutex_);
163196

164-
// Information for a manual compaction
165-
struct ManualCompaction {
166-
int level;
167-
bool done;
168-
const InternalKey* begin; // null means beginning of key range
169-
const InternalKey* end; // null means end of key range
170-
InternalKey tmp_storage; // Used to keep track of compaction progress
171-
};
172197
ManualCompaction* manual_compaction_ GUARDED_BY(mutex_);
173198

174199
VersionSet* const versions_;
175200

176201
// Have we encountered a background error in paranoid mode?
177202
Status bg_error_ GUARDED_BY(mutex_);
178203

179-
// Per level compaction stats. stats_[level] stores the stats for
180-
// compactions that produced data for the specified "level".
181-
struct CompactionStats {
182-
int64_t micros;
183-
int64_t bytes_read;
184-
int64_t bytes_written;
185-
186-
CompactionStats() : micros(0), bytes_read(0), bytes_written(0) {}
187-
188-
void Add(const CompactionStats& c) {
189-
this->micros += c.micros;
190-
this->bytes_read += c.bytes_read;
191-
this->bytes_written += c.bytes_written;
192-
}
193-
};
194204
CompactionStats stats_[config::kNumLevels] GUARDED_BY(mutex_);
195-
196-
// No copying allowed
197-
DBImpl(const DBImpl&);
198-
void operator=(const DBImpl&);
199-
200-
const Comparator* user_comparator() const {
201-
return internal_comparator_.user_comparator();
202-
}
203205
};
204206

205207
// Sanitize db options. The caller should delete result.info_log if

db/db_iter.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class DBIter : public Iterator {
5555
valid_(false),
5656
rnd_(seed),
5757
bytes_until_read_sampling_(RandomCompactionPeriod()) {}
58+
59+
DBIter(const DBIter&) = delete;
60+
DBIter& operator=(const DBIter&) = delete;
61+
5862
virtual ~DBIter() { delete iter_; }
5963
virtual bool Valid() const { return valid_; }
6064
virtual Slice key() const {
@@ -106,19 +110,13 @@ class DBIter : public Iterator {
106110
const Comparator* const user_comparator_;
107111
Iterator* const iter_;
108112
SequenceNumber const sequence_;
109-
110113
Status status_;
111114
std::string saved_key_; // == current key when direction_==kReverse
112115
std::string saved_value_; // == current raw value when direction_==kReverse
113116
Direction direction_;
114117
bool valid_;
115-
116118
Random rnd_;
117119
size_t bytes_until_read_sampling_;
118-
119-
// No copying allowed
120-
DBIter(const DBIter&);
121-
void operator=(const DBIter&);
122120
};
123121

124122
inline bool DBIter::ParseKey(ParsedInternalKey* ikey) {

db/db_test.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ static std::string RandomKey(Random* rnd) {
4040

4141
namespace {
4242
class AtomicCounter {
43-
private:
44-
port::Mutex mu_;
45-
int count_ GUARDED_BY(mu_);
46-
4743
public:
4844
AtomicCounter() : count_(0) {}
4945
void Increment() { IncrementBy(1); }
@@ -59,6 +55,10 @@ class AtomicCounter {
5955
MutexLock l(&mu_);
6056
count_ = 0;
6157
}
58+
59+
private:
60+
port::Mutex mu_;
61+
int count_ GUARDED_BY(mu_);
6262
};
6363

6464
void DelayMilliseconds(int millis) {
@@ -227,21 +227,14 @@ class SpecialEnv : public EnvWrapper {
227227
};
228228

229229
class DBTest {
230-
private:
231-
const FilterPolicy* filter_policy_;
232-
233-
// Sequence of option configurations to try
234-
enum OptionConfig { kDefault, kReuse, kFilter, kUncompressed, kEnd };
235-
int option_config_;
236-
237230
public:
238231
std::string dbname_;
239232
SpecialEnv* env_;
240233
DB* db_;
241234

242235
Options last_options_;
243236

244-
DBTest() : option_config_(kDefault), env_(new SpecialEnv(Env::Default())) {
237+
DBTest() : env_(new SpecialEnv(Env::Default())), option_config_(kDefault) {
245238
filter_policy_ = NewBloomFilterPolicy(10);
246239
dbname_ = test::TmpDir() + "/db_test";
247240
DestroyDB(dbname_, Options());
@@ -533,6 +526,13 @@ class DBTest {
533526
}
534527
return files_renamed;
535528
}
529+
530+
private:
531+
// Sequence of option configurations to try
532+
enum OptionConfig { kDefault, kReuse, kFilter, kUncompressed, kEnd };
533+
534+
const FilterPolicy* filter_policy_;
535+
int option_config_;
536536
};
537537

538538
TEST(DBTest, Empty) {

0 commit comments

Comments
 (0)