Skip to content

Commit 3699fda

Browse files
committed
Merge branch 'master' into jni
2 parents e351184 + d1d19f5 commit 3699fda

File tree

10 files changed

+83
-42
lines changed

10 files changed

+83
-42
lines changed

HISTORY.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
* Added Env::GetThreadPoolQueueLen(), which returns the waiting queue length of thread pools
1616
* Added a command "checkconsistency" in ldb tool, which checks
1717
if file system state matches DB state (file existence and file sizes)
18-
* CompactionFilter::Context is now CompactionFilterContext. It is shared by CompactionFilter and CompactionFilterV2
1918

2019
### New Features
2120
* If we find one truncated record at the end of the MANIFEST or WAL files,
2221
we will ignore it. We assume that writers of these records were interrupted
2322
and that we can safely ignore it.
24-
* Now compaction filter has a V2 interface. It buffers the kv-pairs sharing the same key prefix, process them in batches, and return the batched results back to DB.
23+
* Now compaction filter has a V2 interface. It buffers the kv-pairs sharing the same key prefix, process them in batches, and return the batched results back to DB. The new interface uses a new structure CompactionFilterContext for the same purpose as CompactionFilter::Context in V1.
2524
* Geo-spatial support for locations and radial-search.
2625

2726
## 2.7.0 (01/28/2014)

db/c_test.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ int main(int argc, char** argv) {
439439
rocksdb_close(db);
440440
rocksdb_destroy_db(options, dbname, &err);
441441

442-
rocksdb_options_set_filter_policy(options, rocksdb_filterpolicy_create_bloom(10));
442+
rocksdb_filterpolicy_t* policy = rocksdb_filterpolicy_create_bloom(10);
443+
rocksdb_options_set_filter_policy(options, policy);
443444
rocksdb_options_set_prefix_extractor(options, rocksdb_slicetransform_create_fixed_prefix(3));
444445
rocksdb_options_set_hash_skip_list_rep(options, 50000, 4, 4);
445446

@@ -477,6 +478,7 @@ int main(int argc, char** argv) {
477478
rocksdb_iter_get_error(iter, &err);
478479
CheckNoError(err);
479480
rocksdb_iter_destroy(iter);
481+
rocksdb_filterpolicy_destroy(policy);
480482
}
481483

482484
StartPhase("cleanup");

db/db_impl.cc

+12-4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ struct DBImpl::CompactionState {
117117
total_bytes(0) {
118118
}
119119

120+
// Create a client visible context of this compaction
121+
CompactionFilter::Context GetFilterContextV1() {
122+
CompactionFilter::Context context;
123+
context.is_full_compaction = compaction->IsFullCompaction();
124+
context.is_manual_compaction = compaction->IsManualCompaction();
125+
return context;
126+
}
127+
120128
// Create a client visible context of this compaction
121129
CompactionFilterContext GetFilterContext() {
122130
CompactionFilterContext context;
@@ -2545,7 +2553,7 @@ Status DBImpl::ProcessKeyValueCompaction(
25452553
auto compaction_filter = options_.compaction_filter;
25462554
std::unique_ptr<CompactionFilter> compaction_filter_from_factory = nullptr;
25472555
if (!compaction_filter) {
2548-
auto context = compact->GetFilterContext();
2556+
auto context = compact->GetFilterContextV1();
25492557
compaction_filter_from_factory =
25502558
options_.compaction_filter_factory->CreateCompactionFilter(context);
25512559
compaction_filter = compaction_filter_from_factory.get();
@@ -4026,6 +4034,9 @@ Status DBImpl::MakeRoomForWrite(bool force,
40264034
new_mem = new MemTable(internal_comparator_, options_);
40274035
new_superversion = new SuperVersion();
40284036
}
4037+
Log(options_.info_log,
4038+
"New memtable created with log file: #%lu\n",
4039+
(unsigned long)new_log_number);
40294040
}
40304041
mutex_.Lock();
40314042
if (!s.ok()) {
@@ -4043,9 +4054,6 @@ Status DBImpl::MakeRoomForWrite(bool force,
40434054
}
40444055
mem_ = new_mem;
40454056
mem_->Ref();
4046-
Log(options_.info_log,
4047-
"New memtable created with log file: #%lu\n",
4048-
(unsigned long)logfile_number_);
40494057
mem_->SetLogNumber(logfile_number_);
40504058
force = false; // Do not force another compaction if have room
40514059
MaybeScheduleFlushOrCompaction();

db/db_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ class KeepFilterFactory : public CompactionFilterFactory {
24832483
: check_context_(check_context) {}
24842484

24852485
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
2486-
const CompactionFilterContext& context) override {
2486+
const CompactionFilter::Context& context) override {
24872487
if (check_context_) {
24882488
ASSERT_EQ(expect_full_compaction_.load(), context.is_full_compaction);
24892489
ASSERT_EQ(expect_manual_compaction_.load(), context.is_manual_compaction);
@@ -2500,7 +2500,7 @@ class KeepFilterFactory : public CompactionFilterFactory {
25002500
class DeleteFilterFactory : public CompactionFilterFactory {
25012501
public:
25022502
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
2503-
const CompactionFilterContext& context) override {
2503+
const CompactionFilter::Context& context) override {
25042504
if (context.is_manual_compaction) {
25052505
return std::unique_ptr<CompactionFilter>(new DeleteFilter());
25062506
} else {
@@ -2516,7 +2516,7 @@ class ChangeFilterFactory : public CompactionFilterFactory {
25162516
explicit ChangeFilterFactory() {}
25172517

25182518
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
2519-
const CompactionFilterContext& context) override {
2519+
const CompactionFilter::Context& context) override {
25202520
return std::unique_ptr<CompactionFilter>(new ChangeFilter());
25212521
}
25222522

db/table_cache.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace rocksdb {
2525
class Env;
2626
struct FileMetaData;
2727

28+
// TODO(sdong): try to come up with a better API to pass the file information
29+
// other than simply passing FileMetaData.
2830
class TableCache {
2931
public:
3032
TableCache(const std::string& dbname, const Options* options,

db/version_set.cc

+33-12
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ bool SomeFileOverlapsRange(
140140
return !BeforeFile(ucmp, largest_user_key, files[index]);
141141
}
142142

143+
namespace {
144+
// Used for LevelFileNumIterator to pass "block handle" value,
145+
// which actually means file information in this iterator.
146+
// It contains subset of fields of FileMetaData, that is sufficient
147+
// for table cache to use.
148+
struct EncodedFileMetaData {
149+
uint64_t number; // file number
150+
uint64_t file_size; // file size
151+
Cache::Handle* table_reader_handle; // cached table reader's handler
152+
};
153+
} // namespace
154+
143155
// An internal iterator. For a given version/level pair, yields
144156
// information about the files in the level. For a given entry, key()
145157
// is the largest key that occurs in the file, and value() is an
@@ -181,22 +193,27 @@ class Version::LevelFileNumIterator : public Iterator {
181193
}
182194
Slice value() const {
183195
assert(Valid());
184-
return Slice(reinterpret_cast<const char*>((*flist_)[index_]),
185-
sizeof(FileMetaData));
196+
auto* file_meta = (*flist_)[index_];
197+
current_value_.number = file_meta->number;
198+
current_value_.file_size = file_meta->file_size;
199+
current_value_.table_reader_handle = file_meta->table_reader_handle;
200+
return Slice(reinterpret_cast<const char*>(&current_value_),
201+
sizeof(EncodedFileMetaData));
186202
}
187203
virtual Status status() const { return Status::OK(); }
188204
private:
189205
const InternalKeyComparator icmp_;
190206
const std::vector<FileMetaData*>* const flist_;
191207
uint32_t index_;
208+
mutable EncodedFileMetaData current_value_;
192209
};
193210

194211
static Iterator* GetFileIterator(void* arg, const ReadOptions& options,
195212
const EnvOptions& soptions,
196213
const InternalKeyComparator& icomparator,
197214
const Slice& file_value, bool for_compaction) {
198215
TableCache* cache = reinterpret_cast<TableCache*>(arg);
199-
if (file_value.size() != sizeof(FileMetaData)) {
216+
if (file_value.size() != sizeof(EncodedFileMetaData)) {
200217
return NewErrorIterator(
201218
Status::Corruption("FileReader invoked with unexpected value"));
202219
} else {
@@ -208,11 +225,13 @@ static Iterator* GetFileIterator(void* arg, const ReadOptions& options,
208225
options_copy.prefix = nullptr;
209226
}
210227

211-
const FileMetaData* meta_file =
212-
reinterpret_cast<const FileMetaData*>(file_value.data());
228+
const EncodedFileMetaData* encoded_meta =
229+
reinterpret_cast<const EncodedFileMetaData*>(file_value.data());
230+
FileMetaData meta(encoded_meta->number, encoded_meta->file_size);
231+
meta.table_reader_handle = encoded_meta->table_reader_handle;
213232
return cache->NewIterator(
214-
options.prefix ? options_copy : options, soptions, icomparator,
215-
*meta_file, nullptr /* don't need reference to table*/, for_compaction);
233+
options.prefix ? options_copy : options, soptions, icomparator, meta,
234+
nullptr /* don't need reference to table*/, for_compaction);
216235
}
217236
}
218237

@@ -231,11 +250,13 @@ bool Version::PrefixMayMatch(const ReadOptions& options,
231250
// key() will always be the biggest value for this SST?
232251
may_match = true;
233252
} else {
234-
const FileMetaData* meta_file =
235-
reinterpret_cast<const FileMetaData*>(level_iter->value().data());
236-
237-
may_match = vset_->table_cache_->PrefixMayMatch(
238-
options, vset_->icmp_, *meta_file, internal_prefix, nullptr);
253+
const EncodedFileMetaData* encoded_meta =
254+
reinterpret_cast<const EncodedFileMetaData*>(
255+
level_iter->value().data());
256+
FileMetaData meta(encoded_meta->number, encoded_meta->file_size);
257+
meta.table_reader_handle = encoded_meta->table_reader_handle;
258+
may_match = vset_->table_cache_->PrefixMayMatch(options, vset_->icmp_, meta,
259+
internal_prefix, nullptr);
239260
}
240261
return may_match;
241262
}

include/rocksdb/compaction_filter.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ struct CompactionFilterContext {
3131

3232
class CompactionFilter {
3333
public:
34+
// Context information of a compaction run
35+
struct Context {
36+
// Does this compaction run include all data files
37+
bool is_full_compaction;
38+
// Is this compaction requested by the client (true),
39+
// or is it occurring as an automatic compaction process
40+
bool is_manual_compaction;
41+
};
42+
3443
virtual ~CompactionFilter() {}
3544

3645
// The compaction process invokes this
@@ -105,7 +114,7 @@ class CompactionFilterFactory {
105114
virtual ~CompactionFilterFactory() { }
106115

107116
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
108-
const CompactionFilterContext& context) = 0;
117+
const CompactionFilter::Context& context) = 0;
109118

110119
// Returns a name that identifies this compaction filter factory.
111120
virtual const char* Name() const = 0;
@@ -115,8 +124,8 @@ class CompactionFilterFactory {
115124
// return any filter
116125
class DefaultCompactionFilterFactory : public CompactionFilterFactory {
117126
public:
118-
virtual std::unique_ptr<CompactionFilter>
119-
CreateCompactionFilter(const CompactionFilterContext& context) override {
127+
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
128+
const CompactionFilter::Context& context) override {
120129
return std::unique_ptr<CompactionFilter>(nullptr);
121130
}
122131

util/crc32c.cc

+14-13
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,8 @@ static bool isSSE42() {
334334
#endif
335335
}
336336

337-
typedef void (*Function)(uint64_t*, uint8_t const**);
338-
339-
static inline Function Choose_CRC32() {
340-
return isSSE42() ? Fast_CRC32 : Slow_CRC32;
341-
}
342-
343-
static Function func = Choose_CRC32();
344-
345-
static inline void CRC32(uint64_t* l, uint8_t const **p) {
346-
func(l, p);
347-
}
348-
349-
uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
337+
template<void (*CRC32)(uint64_t*, uint8_t const**)>
338+
uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) {
350339
const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);
351340
const uint8_t *e = p + size;
352341
uint64_t l = crc ^ 0xffffffffu;
@@ -388,5 +377,17 @@ uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
388377
return l ^ 0xffffffffu;
389378
}
390379

380+
typedef uint32_t (*Function)(uint32_t, const char*, size_t);
381+
382+
static inline Function Choose_Extend() {
383+
return isSSE42() ? ExtendImpl<Fast_CRC32> : ExtendImpl<Slow_CRC32>;
384+
}
385+
386+
Function ChosenExtend = Choose_Extend();
387+
388+
uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
389+
return ChosenExtend(crc, buf, size);
390+
}
391+
391392
} // namespace crc32c
392393
} // namespace rocksdb

utilities/ttl/db_ttl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class TtlCompactionFilterFactory : public CompactionFilterFactory {
192192
user_comp_filter_factory_(comp_filter_factory) { }
193193

194194
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
195-
const CompactionFilterContext& context) {
195+
const CompactionFilter::Context& context) {
196196
return std::unique_ptr<TtlCompactionFilter>(
197197
new TtlCompactionFilter(
198198
ttl_,

utilities/ttl/ttl_test.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,8 @@ class TtlTest {
283283
kNewValue_(kNewValue) {
284284
}
285285

286-
virtual std::unique_ptr<CompactionFilter>
287-
CreateCompactionFilter(
288-
const CompactionFilterContext& context) override {
286+
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
287+
const CompactionFilter::Context& context) override {
289288
return std::unique_ptr<CompactionFilter>(
290289
new TestFilter(kSampleSize_, kNewValue_));
291290
}

0 commit comments

Comments
 (0)