RocksDB changes to support unity build:

* Remove extra definition of TotalFileSize
* Remove extra definition of ClipToRange
* Move EncodedFileMetaData out from anonymous namespace
* Move version_set Saver to its own namespace
* Move some symbols into a named namespace
* Move symbols out of anonymous namespace (prevents warning)
* Make BloomHash inline
This commit is contained in:
Vinnie Falco
2014-06-04 17:11:33 -07:00
parent 90a6aca48e
commit 78b8a7d908
13 changed files with 44 additions and 77 deletions

View File

@@ -49,15 +49,6 @@ ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() {
uint32_t ColumnFamilyHandleImpl::GetID() const { return cfd()->GetID(); } uint32_t ColumnFamilyHandleImpl::GetID() const { return cfd()->GetID(); }
namespace {
// Fix user-supplied options to be reasonable
template <class T, class V>
static void ClipToRange(T* ptr, V minvalue, V maxvalue) {
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
}
} // anonymous namespace
ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp, ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
const InternalFilterPolicy* ipolicy, const InternalFilterPolicy* ipolicy,
const ColumnFamilyOptions& src) { const ColumnFamilyOptions& src) {

View File

@@ -18,7 +18,7 @@
namespace rocksdb { namespace rocksdb {
static uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) { uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0; uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) { for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->fd.GetFileSize(); sum += files[i]->fd.GetFileSize();
@@ -26,6 +26,14 @@ static uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
return sum; return sum;
} }
uint64_t TotalCompensatedFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->compensated_file_size;
}
return sum;
}
Compaction::Compaction(Version* input_version, int level, int out_level, Compaction::Compaction(Version* input_version, int level, int out_level,
uint64_t target_file_size, uint64_t target_file_size,
uint64_t max_grandparent_overlap_bytes, uint64_t max_grandparent_overlap_bytes,

View File

@@ -10,8 +10,12 @@
#pragma once #pragma once
#include "db/version_set.h" #include "db/version_set.h"
#include <vector>
namespace rocksdb { namespace rocksdb {
struct FileMetaData;
class Version; class Version;
class ColumnFamilyData; class ColumnFamilyData;
@@ -164,4 +168,8 @@ class Compaction {
void ResetNextCompactionIndex(); void ResetNextCompactionIndex();
}; };
// Utility functions
extern uint64_t TotalFileSize(const std::vector<FileMetaData*>& files);
extern uint64_t TotalCompensatedFileSize(const std::vector<FileMetaData*>& files);
} // namespace rocksdb } // namespace rocksdb

View File

@@ -12,6 +12,7 @@
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#include <inttypes.h> #include <inttypes.h>
#include <limits> #include <limits>
#include "db/compaction.h"
#include "db/filename.h" #include "db/filename.h"
#include "util/log_buffer.h" #include "util/log_buffer.h"
#include "util/statistics.h" #include "util/statistics.h"
@@ -45,14 +46,6 @@ CompressionType GetCompressionType(const Options& options, int level,
} }
} }
uint64_t TotalCompensatedFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->compensated_file_size;
}
return sum;
}
// Multiple two operands. If they overflow, return op1. // Multiple two operands. If they overflow, return op1.
uint64_t MultiplyCheckOverflow(uint64_t op1, int op2) { uint64_t MultiplyCheckOverflow(uint64_t op1, int op2) {
if (op1 == 0) { if (op1 == 0) {

View File

@@ -256,15 +256,6 @@ struct DBImpl::CompactionState {
} }
}; };
namespace {
// Fix user-supplied options to be reasonable
template <class T, class V>
static void ClipToRange(T* ptr, V minvalue, V maxvalue) {
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
}
} // anonymous namespace
Options SanitizeOptions(const std::string& dbname, Options SanitizeOptions(const std::string& dbname,
const InternalKeyComparator* icmp, const InternalKeyComparator* icmp,
const InternalFilterPolicy* ipolicy, const InternalFilterPolicy* ipolicy,

View File

@@ -644,4 +644,11 @@ extern Options SanitizeOptions(const std::string& db,
const Options& src); const Options& src);
extern DBOptions SanitizeOptions(const std::string& db, const DBOptions& src); extern DBOptions SanitizeOptions(const std::string& db, const DBOptions& src);
// Fix user-supplied options to be reasonable
template <class T, class V>
inline void ClipToRange(T* ptr, V minvalue, V maxvalue) {
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
}
} // namespace rocksdb } // namespace rocksdb

View File

@@ -19,6 +19,7 @@
#include <vector> #include <vector>
#include <stdio.h> #include <stdio.h>
#include "db/compaction.h"
#include "db/filename.h" #include "db/filename.h"
#include "db/log_reader.h" #include "db/log_reader.h"
#include "db/log_writer.h" #include "db/log_writer.h"
@@ -40,23 +41,6 @@
namespace rocksdb { namespace rocksdb {
static uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->fd.GetFileSize();
}
return sum;
}
static uint64_t TotalCompensatedFileSize(
const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->compensated_file_size;
}
return sum;
}
Version::~Version() { Version::~Version() {
assert(refs_ == 0); assert(refs_ == 0);
@@ -373,7 +357,6 @@ void Version::AddIterators(const ReadOptions& read_options,
} }
// Callback from TableCache::Get() // Callback from TableCache::Get()
namespace {
enum SaverState { enum SaverState {
kNotFound, kNotFound,
kFound, kFound,
@@ -381,6 +364,7 @@ enum SaverState {
kCorrupt, kCorrupt,
kMerge // saver contains the current merge result (the operands) kMerge // saver contains the current merge result (the operands)
}; };
namespace version_set {
struct Saver { struct Saver {
SaverState state; SaverState state;
const Comparator* ucmp; const Comparator* ucmp;
@@ -393,7 +377,7 @@ struct Saver {
Logger* logger; Logger* logger;
Statistics* statistics; Statistics* statistics;
}; };
} } // namespace version_set
// Called from TableCache::Get and Table::Get when file/block in which // Called from TableCache::Get and Table::Get when file/block in which
// key may exist are not there in TableCache/BlockCache respectively. In this // key may exist are not there in TableCache/BlockCache respectively. In this
@@ -401,7 +385,7 @@ struct Saver {
// IO to be certain.Set the status=kFound and value_found=false to let the // IO to be certain.Set the status=kFound and value_found=false to let the
// caller know that key may exist but is not there in memory // caller know that key may exist but is not there in memory
static void MarkKeyMayExist(void* arg) { static void MarkKeyMayExist(void* arg) {
Saver* s = reinterpret_cast<Saver*>(arg); version_set::Saver* s = reinterpret_cast<version_set::Saver*>(arg);
s->state = kFound; s->state = kFound;
if (s->value_found != nullptr) { if (s->value_found != nullptr) {
*(s->value_found) = false; *(s->value_found) = false;
@@ -410,7 +394,7 @@ static void MarkKeyMayExist(void* arg) {
static bool SaveValue(void* arg, const ParsedInternalKey& parsed_key, static bool SaveValue(void* arg, const ParsedInternalKey& parsed_key,
const Slice& v) { const Slice& v) {
Saver* s = reinterpret_cast<Saver*>(arg); version_set::Saver* s = reinterpret_cast<version_set::Saver*>(arg);
MergeContext* merge_contex = s->merge_context; MergeContext* merge_contex = s->merge_context;
std::string merge_result; // temporary area for merge results later std::string merge_result; // temporary area for merge results later
@@ -538,7 +522,7 @@ void Version::Get(const ReadOptions& options,
Slice user_key = k.user_key(); Slice user_key = k.user_key();
assert(status->ok() || status->IsMergeInProgress()); assert(status->ok() || status->IsMergeInProgress());
Saver saver; version_set::Saver saver;
saver.state = status->ok()? kNotFound : kMerge; saver.state = status->ok()? kNotFound : kMerge;
saver.ucmp = user_comparator_; saver.ucmp = user_comparator_;
saver.user_key = user_key; saver.user_key = user_key;

View File

@@ -45,7 +45,6 @@ namespace rocksdb {
extern const std::string kHashIndexPrefixesBlock; extern const std::string kHashIndexPrefixesBlock;
extern const std::string kHashIndexPrefixesMetadataBlock; extern const std::string kHashIndexPrefixesMetadataBlock;
namespace {
typedef BlockBasedTableOptions::IndexType IndexType; typedef BlockBasedTableOptions::IndexType IndexType;
@@ -335,8 +334,6 @@ Slice CompressBlock(const Slice& raw,
return raw; return raw;
} }
} // anonymous namespace
// kBlockBasedTableMagicNumber was picked by running // kBlockBasedTableMagicNumber was picked by running
// echo rocksdb.table.block_based | sha1sum // echo rocksdb.table.block_based | sha1sum
// and taking the leading 64 bits. // and taking the leading 64 bits.

View File

@@ -16,18 +16,10 @@
namespace rocksdb { namespace rocksdb {
namespace {
inline uint32_t Hash(const Slice& s) {
return rocksdb::Hash(s.data(), s.size(), 0);
}
inline uint32_t PrefixToBucket(const Slice& prefix, uint32_t num_buckets) { inline uint32_t PrefixToBucket(const Slice& prefix, uint32_t num_buckets) {
return Hash(prefix) % num_buckets; return Hash(prefix.data(), prefix.size(), 0) % num_buckets;
} }
// The prefix block index is simply a bucket array, with each entry pointing to // The prefix block index is simply a bucket array, with each entry pointing to
// the blocks that span the prefixes hashed to this bucket. // the blocks that span the prefixes hashed to this bucket.
// //
@@ -74,8 +66,6 @@ struct PrefixRecord {
PrefixRecord* next; PrefixRecord* next;
}; };
} // anonymous namespace
class BlockPrefixIndex::Builder { class BlockPrefixIndex::Builder {
public: public:
explicit Builder(const SliceTransform* internal_prefix_extractor) explicit Builder(const SliceTransform* internal_prefix_extractor)

View File

@@ -23,7 +23,7 @@
#include "util/autovector.h" #include "util/autovector.h"
namespace rocksdb { namespace rocksdb {
namespace { namespace merger {
typedef std::priority_queue< typedef std::priority_queue<
IteratorWrapper*, IteratorWrapper*,
std::vector<IteratorWrapper*>, std::vector<IteratorWrapper*>,
@@ -43,7 +43,7 @@ MaxIterHeap NewMaxIterHeap(const Comparator* comparator) {
MinIterHeap NewMinIterHeap(const Comparator* comparator) { MinIterHeap NewMinIterHeap(const Comparator* comparator) {
return MinIterHeap(MinIteratorComparator(comparator)); return MinIterHeap(MinIteratorComparator(comparator));
} }
} // namespace } // namespace merger
const size_t kNumIterReserve = 4; const size_t kNumIterReserve = 4;
@@ -56,8 +56,8 @@ class MergingIterator : public Iterator {
current_(nullptr), current_(nullptr),
use_heap_(true), use_heap_(true),
direction_(kForward), direction_(kForward),
maxHeap_(NewMaxIterHeap(comparator_)), maxHeap_(merger::NewMaxIterHeap(comparator_)),
minHeap_(NewMinIterHeap(comparator_)) { minHeap_(merger::NewMinIterHeap(comparator_)) {
children_.resize(n); children_.resize(n);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
children_[i].Set(children[i]); children_[i].Set(children[i]);
@@ -274,8 +274,8 @@ class MergingIterator : public Iterator {
kReverse kReverse
}; };
Direction direction_; Direction direction_;
MaxIterHeap maxHeap_; merger::MaxIterHeap maxHeap_;
MinIterHeap minHeap_; merger::MinIterHeap minHeap_;
}; };
void MergingIterator::FindSmallest() { void MergingIterator::FindSmallest() {
@@ -302,8 +302,8 @@ void MergingIterator::FindLargest() {
void MergingIterator::ClearHeaps() { void MergingIterator::ClearHeaps() {
use_heap_ = true; use_heap_ = true;
maxHeap_ = NewMaxIterHeap(comparator_); maxHeap_ = merger::NewMaxIterHeap(comparator_);
minHeap_ = NewMinIterHeap(comparator_); minHeap_ = merger::NewMinIterHeap(comparator_);
} }
Iterator* NewMergingIterator(const Comparator* cmp, Iterator** list, int n, Iterator* NewMergingIterator(const Comparator* cmp, Iterator** list, int n,

View File

@@ -15,9 +15,6 @@
namespace rocksdb { namespace rocksdb {
namespace { namespace {
static uint32_t BloomHash(const Slice& key) {
return Hash(key.data(), key.size(), 0xbc9f1d34);
}
class BloomFilterPolicy : public FilterPolicy { class BloomFilterPolicy : public FilterPolicy {
private: private:

View File

@@ -14,9 +14,6 @@
namespace rocksdb { namespace rocksdb {
namespace { namespace {
static uint32_t BloomHash(const Slice& key) {
return Hash(key.data(), key.size(), 0xbc9f1d34);
}
uint32_t GetTotalBitsForLocality(uint32_t total_bits) { uint32_t GetTotalBitsForLocality(uint32_t total_bits) {
uint32_t num_blocks = uint32_t num_blocks =

View File

@@ -17,4 +17,8 @@ namespace rocksdb {
extern uint32_t Hash(const char* data, size_t n, uint32_t seed); extern uint32_t Hash(const char* data, size_t n, uint32_t seed);
inline uint32_t BloomHash(const Slice& key) {
return Hash(key.data(), key.size(), 0xbc9f1d34);
}
} }