Skip to content

Commit

Permalink
Adapt rocksdb 6.4.6 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Nov 1, 2019
1 parent bcad80e commit 9107617
Show file tree
Hide file tree
Showing 53 changed files with 786 additions and 320 deletions.
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[submodule "libs/rocksdb"]
path = libs/rocksdb
url = https://github.com/facebook/rocksdb.git
branch = 6.3.fb
[submodule "libs/lz4"]
path = libs/lz4
url = https://github.com/lz4/lz4.git
Expand Down
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM centos:7

# install toolchain(s) and go
ENV GOLANG_PACKAGE go1.13.4.linux-amd64.tar.gz

RUN yum -y update && \
yum -y install gcc gcc-c++ git pkg-config make which unzip && \
curl https://dl.google.com/go/${GOLANG_PACKAGE} -o ${GOLANG_PACKAGE} && \
tar -C /usr/local -xzf ${GOLANG_PACKAGE} && rm ${GOLANG_PACKAGE} && \
yum clean all && rm -rf /var/cache/yum

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $PATH:$GOROOT/bin:$GOPATH/bin

RUN mkdir -p "$GOPATH/src/github.com/linxGnu/grocksdb" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

# install cmake
RUN yum install -y wget && \
cd /tmp && \
wget https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5.tar.gz && \
tar xzf cmake-3.15.5.tar.gz && cd cmake-3.15.5 && \
./bootstrap --parallel=16 && make -j16 && make install && \
cd /tmp && rm -rf * && \
yum remove -y wget && yum clean all && rm -rf /var/cache/yum

# building
ADD . "$GOPATH/src/github.com/linxGnu/grocksdb"
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ STRIPFLAGS = -S -x
ZLIB_COMMIT = cacf7f1d4e3d44d871b605da3b647f07d718623f
SNAPPY_COMMIT = e9e11b84e629c3e06fbaa4f0a86de02ceb9d6992
LZ4_COMMIT = e8baeca51ef2003d6c9ec21c32f1563fef1065b9
ZSTD_COMMIT = ed65210c9b6635e21e67e60138f86d04a071681f
ZSTD_COMMIT = a3d655d2255481333e09ecca9855f1b37f757c52
BZ2_COMMIT = 6a8690fc8d26c815e798c588f796eabe9d684cf0
ROCKSDB_COMMIT = d47cdbc1888440a75ecf43646fd1ddab8ebae9be
ROCKSDB_COMMIT = e3169e3ea8762d2f34880742106858a23c8dc8b7

ROCKSDB_EXTRA_CXXFLAGS :=
ifeq ($(GOOS), darwin)
Expand Down Expand Up @@ -58,7 +58,7 @@ snappy:
lz4:
git submodule update --remote --init --recursive -- libs/lz4
cd libs/lz4 && git checkout $(LZ4_COMMIT)
cd libs/lz4 && $(MAKE) clean && $(MAKE) $(MAKE_FLAGS) CFLAGS='-fPIC -O2 ${EXTRA_CFLAGS}' lz4 lz4-release
cd libs/lz4 && $(MAKE) clean && $(MAKE) $(MAKE_FLAGS) CFLAGS='-fPIC -O2 ${EXTRA_CFLAGS}' lz4-release
cp libs/lz4/lib/liblz4.a $(DEST_LIB)/
cp libs/lz4/lib/*.h $(DEST_INCLUDE)/

Expand Down
9 changes: 2 additions & 7 deletions dist/darwin_amd64/include/rocksdb/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct LRUCacheOptions {
//
// See also
// BlockBasedTableOptions::cache_index_and_filter_blocks_with_high_priority.
double high_pri_pool_ratio = 0.0;
double high_pri_pool_ratio = 0.5;

// If non-nullptr will use this allocator instead of system allocator when
// allocating memory for cache blocks. Call this method before you start using
Expand Down Expand Up @@ -99,7 +99,7 @@ struct LRUCacheOptions {
// will be at least 512KB and number of shard bits will not exceed 6.
extern std::shared_ptr<Cache> NewLRUCache(
size_t capacity, int num_shard_bits = -1,
bool strict_capacity_limit = false, double high_pri_pool_ratio = 0.0,
bool strict_capacity_limit = false, double high_pri_pool_ratio = 0.5,
std::shared_ptr<MemoryAllocator> memory_allocator = nullptr,
bool use_adaptive_mutex = kDefaultToAdaptiveMutex);

Expand Down Expand Up @@ -250,11 +250,6 @@ class Cache {

virtual std::string GetPrintableOptions() const { return ""; }

// Mark the last inserted object as being a raw data block. This will be used
// in tests. The default implementation does nothing.
virtual void TEST_mark_as_data_block(const Slice& /*key*/,
size_t /*charge*/) {}

MemoryAllocator* memory_allocator() const { return memory_allocator_.get(); }

private:
Expand Down
1 change: 1 addition & 0 deletions dist/darwin_amd64/include/rocksdb/comparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Comparator {

virtual ~Comparator() {}

static const char* Type() { return "Comparator"; }
// Three-way comparison. Returns value:
// < 0 iff "a" < "b",
// == 0 iff "a" == "b",
Expand Down
45 changes: 38 additions & 7 deletions dist/darwin_amd64/include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ class DB {
// stats should be included, or file stats approximation or both
enum SizeApproximationFlags : uint8_t {
NONE = 0,
INCLUDE_MEMTABLES = 1,
INCLUDE_MEMTABLES = 1 << 0,
INCLUDE_FILES = 1 << 1
};

Expand All @@ -818,14 +818,24 @@ class DB {
// Note that the returned sizes measure file system space usage, so
// if the user data compresses by a factor of ten, the returned
// sizes will be one-tenth the size of the corresponding user data size.
//
// If include_flags defines whether the returned size should include
// the recently written data in the mem-tables (if
// the mem-table type supports it), data serialized to disk, or both.
// include_flags should be of type DB::SizeApproximationFlags
virtual Status GetApproximateSizes(const SizeApproximationOptions& options,
ColumnFamilyHandle* column_family,
const Range* range, int n,
uint64_t* sizes) = 0;

// Simpler versions of the GetApproximateSizes() method above.
// The include_flags argumenbt must of type DB::SizeApproximationFlags
// and can not be NONE.
virtual void GetApproximateSizes(ColumnFamilyHandle* column_family,
const Range* range, int n, uint64_t* sizes,
uint8_t include_flags = INCLUDE_FILES) = 0;
uint8_t include_flags = INCLUDE_FILES) {
SizeApproximationOptions options;
options.include_memtabtles =
(include_flags & SizeApproximationFlags::INCLUDE_MEMTABLES) != 0;
options.include_files =
(include_flags & SizeApproximationFlags::INCLUDE_FILES) != 0;
GetApproximateSizes(options, column_family, range, n, sizes);
}
virtual void GetApproximateSizes(const Range* range, int n, uint64_t* sizes,
uint8_t include_flags = INCLUDE_FILES) {
GetApproximateSizes(DefaultColumnFamily(), range, n, sizes, include_flags);
Expand Down Expand Up @@ -1174,6 +1184,27 @@ class DB {
virtual Status IngestExternalFiles(
const std::vector<IngestExternalFileArg>& args) = 0;

// CreateColumnFamilyWithImport() will create a new column family with
// column_family_name and import external SST files specified in metadata into
// this column family.
// (1) External SST files can be created using SstFileWriter.
// (2) External SST files can be exported from a particular column family in
// an existing DB.
// Option in import_options specifies whether the external files are copied or
// moved (default is copy). When option specifies copy, managing files at
// external_file_path is caller's responsibility. When option specifies a
// move, the call ensures that the specified files at external_file_path are
// deleted on successful return and files are not modified on any error
// return.
// On error return, column family handle returned will be nullptr.
// ColumnFamily will be present on successful return and will not be present
// on error return. ColumnFamily may be present on any crash during this call.
virtual Status CreateColumnFamilyWithImport(
const ColumnFamilyOptions& options, const std::string& column_family_name,
const ImportColumnFamilyOptions& import_options,
const ExportImportFilesMetaData& metadata,
ColumnFamilyHandle** handle) = 0;

virtual Status VerifyChecksum() = 0;

// AddFile() is deprecated, please use IngestExternalFile()
Expand Down
21 changes: 17 additions & 4 deletions dist/darwin_amd64/include/rocksdb/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ struct EnvOptions {
bool fallocate_with_keep_size = true;

// See DBOptions doc
size_t compaction_readahead_size;
size_t compaction_readahead_size = 0;

// See DBOptions doc
size_t random_access_max_buffer_size;
size_t random_access_max_buffer_size = 0;

// See DBOptions doc
size_t writable_file_max_buffer_size = 1024 * 1024;
Expand All @@ -144,6 +144,11 @@ class Env {

virtual ~Env();

static const char* Type() { return "Environment"; }

// Loads the environment specified by the input value into the result
static Status LoadEnv(const std::string& value, Env** result);

// Return a default environment suitable for the current operating
// system. Sophisticated users may wish to provide their own Env
// implementation instead of relying on this default environment.
Expand Down Expand Up @@ -395,9 +400,11 @@ class Env {
// same directory.
virtual Status GetTestDirectory(std::string* path) = 0;

// Create and return a log file for storing informational messages.
// Create and returns a default logger (an instance of EnvLogger) for storing
// informational messages. Derived classes can overide to provide custom
// logger.
virtual Status NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) = 0;
std::shared_ptr<Logger>* result);

// Returns the number of micro-seconds since some fixed point in time.
// It is often used as system time such as in GenericRateLimiter
Expand Down Expand Up @@ -1563,4 +1570,10 @@ Status NewHdfsEnv(Env** hdfs_env, const std::string& fsname);
// This is a factory method for TimedEnv defined in utilities/env_timed.cc.
Env* NewTimedEnv(Env* base_env);

// Returns an instance of logger that can be used for storing informational
// messages.
// This is a factory method for EnvLogger declared in logging/env_logging.h
Status NewEnvLogger(const std::string& fname, Env* env,
std::shared_ptr<Logger>* result);

} // namespace rocksdb
1 change: 1 addition & 0 deletions dist/darwin_amd64/include/rocksdb/merge_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Logger;
class MergeOperator {
public:
virtual ~MergeOperator() {}
static const char* Type() { return "MergeOperator"; }

// Gives the client a way to express the read -> modify -> write semantics
// key: (IN) The key that's associated with this merge operation.
Expand Down
7 changes: 7 additions & 0 deletions dist/darwin_amd64/include/rocksdb/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,11 @@ struct LiveFileMetaData : SstFileMetaData {
int level; // Level at which this file resides.
LiveFileMetaData() : column_family_name(), level(0) {}
};

// Metadata returned as output from ExportColumnFamily() and used as input to
// CreateColumnFamiliesWithImport().
struct ExportImportFilesMetaData {
std::string db_comparator_name; // Used to safety check at import.
std::vector<LiveFileMetaData> files; // Vector of file metadata.
};
} // namespace rocksdb
27 changes: 27 additions & 0 deletions dist/darwin_amd64/include/rocksdb/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ struct ColumnFamilyOptions : public AdvancedColumnFamilyOptions {
// this option helps reducing the cpu usage of long-running compactions. The
// feature is disabled when max_subcompactions is greater than one.
//
// NOTE: This feautre is currently incompatible with RangeDeletes.
//
// Default: 0
//
// Dynamically changeable through SetOptions() API
Expand Down Expand Up @@ -760,6 +762,8 @@ struct DBOptions {
// for this mode if using block-based table.
//
// Default: false
// This flag has no affect on the behavior of compaction and plan to delete
// in the future.
bool new_table_reader_for_compaction_inputs = false;

// If non-zero, we perform bigger reads when doing compaction. If you're
Expand Down Expand Up @@ -1085,6 +1089,13 @@ struct DBOptions {
// If set to true, takes precedence over
// ReadOptions::background_purge_on_iterator_cleanup.
bool avoid_unnecessary_blocking_io = false;

// The number of bytes to prefetch when reading the log. This is mostly useful
// for reading a remotely located log, as it can save the number of
// round-trips. If 0, then the prefetching is disabled.
//
// Default: 0
size_t log_readahead_size = 0;
};

// Options to control the behavior of a database (passed to DB::Open)
Expand Down Expand Up @@ -1489,4 +1500,20 @@ struct TraceOptions {
uint64_t filter = kTraceFilterNone;
};

// ImportColumnFamilyOptions is used by ImportColumnFamily()
struct ImportColumnFamilyOptions {
// Can be set to true to move the files instead of copying them.
bool move_files = false;
};

// Options used with DB::GetApproximateSizes()
struct SizeApproximationOptions {
// Defines whether the returned size should include the recently written
// data in the mem-tables. If set to false, include_files must be true.
bool include_memtabtles = false;
// Defines whether the returned size should include data serialized to disk.
// If set to false, include_memtabtles must be true.
bool include_files = true;
};

} // namespace rocksdb
2 changes: 1 addition & 1 deletion dist/darwin_amd64/include/rocksdb/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ enum StatsLevel : uint8_t {
class Statistics {
public:
virtual ~Statistics() {}

static const char* Type() { return "Statistics"; }
virtual uint64_t getTickerCount(uint32_t tickerType) const = 0;
virtual void histogramData(uint32_t type,
HistogramData* const data) const = 0;
Expand Down
26 changes: 22 additions & 4 deletions dist/darwin_amd64/include/rocksdb/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct BlockBasedTableOptions {
// blocks with high priority. If set to true, depending on implementation of
// block cache, index and filter blocks may be less likely to be evicted
// than data blocks.
bool cache_index_and_filter_blocks_with_high_priority = false;
bool cache_index_and_filter_blocks_with_high_priority = true;

// if cache_index_and_filter_blocks is true and the below is true, then
// filter and index blocks are stored in the cache, but a reference is
Expand All @@ -93,14 +93,32 @@ struct BlockBasedTableOptions {
enum IndexType : char {
// A space efficient index block that is optimized for
// binary-search-based index.
kBinarySearch,
kBinarySearch = 0x00,

// The hash index, if enabled, will do the hash lookup when
// `Options.prefix_extractor` is provided.
kHashSearch,
kHashSearch = 0x01,

// A two-level index implementation. Both levels are binary search indexes.
kTwoLevelIndexSearch,
kTwoLevelIndexSearch = 0x02,

// Like kBinarySearch, but index also contains first key of each block.
// This allows iterators to defer reading the block until it's actually
// needed. May significantly reduce read amplification of short range scans.
// Without it, iterator seek usually reads one block from each level-0 file
// and from each level, which may be expensive.
// Works best in combination with:
// - IndexShorteningMode::kNoShortening,
// - custom FlushBlockPolicy to cut blocks at some meaningful boundaries,
// e.g. when prefix changes.
// Makes the index significantly bigger (2x or more), especially when keys
// are long.
//
// IO errors are not handled correctly in this mode right now: if an error
// happens when lazily reading a block in value(), value() returns empty
// slice, and you need to call Valid()/status() afterwards.
// TODO(kolmike): Fix it.
kBinarySearchWithFirstKey = 0x03,
};

IndexType index_type = kBinarySearch;
Expand Down
14 changes: 14 additions & 0 deletions dist/darwin_amd64/include/rocksdb/utilities/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
#ifndef ROCKSDB_LITE

#include <string>
#include <vector>
#include "rocksdb/status.h"

namespace rocksdb {

class DB;
class ColumnFamilyHandle;
struct LiveFileMetaData;
struct ExportImportFilesMetaData;

class Checkpoint {
public:
Expand All @@ -36,6 +40,16 @@ class Checkpoint {
virtual Status CreateCheckpoint(const std::string& checkpoint_dir,
uint64_t log_size_for_flush = 0);

// Exports all live SST files of a specified Column Family onto export_dir,
// returning SST files information in metadata.
// - SST files will be created as hard links when the directory specified
// is in the same partition as the db directory, copied otherwise.
// - export_dir should not already exist and will be created by this API.
// - Always triggers a flush.
virtual Status ExportColumnFamily(ColumnFamilyHandle* handle,
const std::string& export_dir,
ExportImportFilesMetaData** metadata);

virtual ~Checkpoint() {}
};

Expand Down
4 changes: 4 additions & 0 deletions dist/darwin_amd64/include/rocksdb/utilities/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Status GetAllKeyVersions(DB* db, Slice begin_key, Slice end_key,
size_t max_num_ikeys,
std::vector<KeyVersion>* key_versions);

Status GetAllKeyVersions(DB* db, ColumnFamilyHandle* cfh, Slice begin_key,
Slice end_key, size_t max_num_ikeys,
std::vector<KeyVersion>* key_versions);

} // namespace rocksdb

#endif // ROCKSDB_LITE
Loading

0 comments on commit 9107617

Please sign in to comment.