Skip to content

Commit

Permalink
NO-ISSUE Adapt rocksdb 6.22.1 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Jul 13, 2021
1 parent 9154c4a commit 5baba6b
Show file tree
Hide file tree
Showing 44 changed files with 1,978 additions and 807 deletions.
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

INSTALL_PREFIX=$1

export CFLAGS='-fPIC -O3 -pipe'
export CXXFLAGS='-fPIC -O3 -pipe'
export CFLAGS='-fPIC -O2 -pipe'
export CXXFLAGS='-fPIC -O2 -pipe'

BUILD_PATH=/tmp/build
mkdir -p $BUILD_PATH
Expand Down Expand Up @@ -33,7 +33,7 @@ cd $BUILD_PATH && wget https://github.com/facebook/zstd/archive/v${zstd_version}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DZSTD_ZLIB_SUPPORT=ON -DZSTD_LZMA_SUPPORT=OFF -DCMAKE_BUILD_TYPE=Release .. && make -j$(nproc) install && \
cd $BUILD_PATH && rm -rf * && ldconfig

rocksdb_version="6.20.3"
rocksdb_version="6.22.1"
cd $BUILD_PATH && wget https://github.com/facebook/rocksdb/archive/v${rocksdb_version}.tar.gz && tar xzf v${rocksdb_version}.tar.gz && cd rocksdb-${rocksdb_version}/ && \
mkdir -p build_place && cd build_place && cmake -DCMAKE_BUILD_TYPE=Release $CMAKE_REQUIRED_PARAMS -DCMAKE_PREFIX_PATH=$INSTALL_PREFIX -DWITH_TESTS=OFF -DWITH_GFLAGS=OFF \
-DWITH_BENCHMARK_TOOLS=OFF -DWITH_TOOLS=OFF -DWITH_MD_LIBRARY=OFF -DWITH_RUNTIME_DEBUG=OFF -DROCKSDB_BUILD_SHARED=OFF -DWITH_SNAPPY=ON -DWITH_LZ4=ON -DWITH_ZLIB=ON \
Expand Down
2 changes: 1 addition & 1 deletion builtin_static_linux_amd64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build builtin_static !static
// +build builtin_static

package grocksdb

Expand Down
31 changes: 31 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ func NewLRUCache(capacity uint64) *Cache {
return NewNativeCache(C.rocksdb_cache_create_lru(C.size_t(capacity)))
}

// NewLRUCacheWithOptions creates a new LRU Cache from options.
func NewLRUCacheWithOptions(opt *LRUCacheOptions) *Cache {
return NewNativeCache(C.rocksdb_cache_create_lru_opts(opt.c))
}

// NewNativeCache creates a Cache object.
func NewNativeCache(c *C.rocksdb_cache_t) *Cache {
return &Cache{c}
Expand Down Expand Up @@ -52,3 +57,29 @@ func (c *Cache) Destroy() {
C.rocksdb_cache_destroy(c.c)
c.c = nil
}

// LRUCacheOptions are options for LRU Cache.
type LRUCacheOptions struct {
c *C.rocksdb_lru_cache_options_t
}

// NewLRUCacheOptions creates lru cache options.
func NewLRUCacheOptions() *LRUCacheOptions {
return &LRUCacheOptions{c: C.rocksdb_lru_cache_options_create()}
}

// Destroy lru cache options.
func (l *LRUCacheOptions) Destroy() {
C.rocksdb_lru_cache_options_destroy(l.c)
l.c = nil
}

// SetCapacity sets capacity for this lru cache.
func (l *LRUCacheOptions) SetCapacity(s uint) {
C.rocksdb_lru_cache_options_set_capacity(l.c, C.ulong(s))
}

// SetMemoryAllocator for this lru cache.
func (l *LRUCacheOptions) SetMemoryAllocator(m *MemoryAllocator) {
C.rocksdb_lru_cache_options_set_memory_allocator(l.c, m.c)
}
15 changes: 15 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@ func TestCache(t *testing.T) {

cache.DisownData()
}

func TestCacheWithOpts(t *testing.T) {
opts := NewLRUCacheOptions()
opts.SetCapacity(19)
defer opts.Destroy()

cache := NewLRUCacheWithOptions(opts)
defer cache.Destroy()

require.EqualValues(t, 19, cache.GetCapacity())
cache.SetCapacity(128)
require.EqualValues(t, 128, cache.GetCapacity())

cache.DisownData()
}
15 changes: 13 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ func (db *DB) CompactRangeCFOpt(cf *ColumnFamilyHandle, r Range, opt *CompactRan
C.rocksdb_compact_range_cf_opt(db.c, cf.c, opt.c, cStart, C.size_t(len(r.Start)), cLimit, C.size_t(len(r.Limit)))
}

// Flush triggers a manuel flush for the database.
// Flush triggers a manual flush for the database.
func (db *DB) Flush(opts *FlushOptions) (err error) {
var cErr *C.char

Expand All @@ -1160,7 +1160,7 @@ func (db *DB) Flush(opts *FlushOptions) (err error) {
return
}

// FlushCF triggers a manuel flush for the database on specific column family.
// FlushCF triggers a manual flush for the database on specific column family.
func (db *DB) FlushCF(cf *ColumnFamilyHandle, opts *FlushOptions) (err error) {
var cErr *C.char

Expand All @@ -1170,6 +1170,17 @@ func (db *DB) FlushCF(cf *ColumnFamilyHandle, opts *FlushOptions) (err error) {
return
}

// FlushWAL flushes the WAL memory buffer to the file. If sync is true, it calls SyncWAL
// afterwards.
func (db *DB) FlushWAL(sync bool) (err error) {
var cErr *C.char

C.rocksdb_flush_wal(db.c, boolToChar(sync), &cErr)
err = fromCError(cErr)

return
}

// DisableFileDeletions disables file deletions and should be used when backup the database.
func (db *DB) DisableFileDeletions() (err error) {
var cErr *C.char
Expand Down
21 changes: 20 additions & 1 deletion dist/linux_amd64/include/rocksdb/advanced_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ struct CompressionOptions {
max_dict_buffer_bytes(_max_dict_buffer_bytes) {}
};

// Temperature of a file. Used to pass to FileSystem for a different
// placement and/or coding.
// Reserve some numbers in the middle, in case we need to insert new tier
// there.
enum class Temperature : uint8_t {
kUnknown = 0,
kHot = 0x04,
kWarm = 0x08,
kCold = 0x0C,
};

enum UpdateStatus { // Return status For inplace update callback
UPDATE_FAILED = 0, // Nothing to update
UPDATED_INPLACE = 1, // Value updated inplace
Expand Down Expand Up @@ -380,7 +391,8 @@ struct AdvancedColumnFamilyOptions {

// size of one block in arena memory allocation.
// If <= 0, a proper value is automatically calculated (usually 1/8 of
// writer_buffer_size, rounded up to a multiple of 4KB).
// writer_buffer_size, rounded up to a multiple of 4KB, or 1MB which ever is
// smaller).
//
// There are two additional restriction of the specified size:
// (1) size should be in the range of [4096, 2 << 30] and
Expand Down Expand Up @@ -758,6 +770,13 @@ struct AdvancedColumnFamilyOptions {
// data is left uncompressed (unless compression is also requested).
uint64_t sample_for_compression = 0;

// EXPERIMENTAL
// The feature is still in development and is incomplete.
// If this option is set, when creating bottommost files, pass this
// temperature to FileSystem used. Should be no-op for default FileSystem
// and users need to plug in their own FileSystem to take advantage of it.
Temperature bottommost_temperature = Temperature::kUnknown;

// When set, large values (blobs) are written to separate blob files, and
// only pointers to them are stored in SST files. This can reduce write
// amplification for large-value use cases at the cost of introducing a level
Expand Down
46 changes: 45 additions & 1 deletion dist/linux_amd64/include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ typedef struct rocksdb_backup_engine_t rocksdb_backup_engine_t;
typedef struct rocksdb_backup_engine_info_t rocksdb_backup_engine_info_t;
typedef struct rocksdb_backupable_db_options_t rocksdb_backupable_db_options_t;
typedef struct rocksdb_restore_options_t rocksdb_restore_options_t;
typedef struct rocksdb_cache_t rocksdb_cache_t;
typedef struct rocksdb_memory_allocator_t rocksdb_memory_allocator_t;
typedef struct rocksdb_lru_cache_options_t rocksdb_lru_cache_options_t;
typedef struct rocksdb_cache_t rocksdb_cache_t;
typedef struct rocksdb_compactionfilter_t rocksdb_compactionfilter_t;
typedef struct rocksdb_compactionfiltercontext_t
rocksdb_compactionfiltercontext_t;
Expand Down Expand Up @@ -537,6 +539,10 @@ extern ROCKSDB_LIBRARY_API void rocksdb_flush_cf(
rocksdb_t* db, const rocksdb_flushoptions_t* options,
rocksdb_column_family_handle_t* column_family, char** errptr);

extern ROCKSDB_LIBRARY_API void rocksdb_flush_wal(rocksdb_t* db,
unsigned char sync,
char** errptr);

extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions(rocksdb_t* db,
char** errptr);

Expand Down Expand Up @@ -998,9 +1004,21 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compression_options(
extern ROCKSDB_LIBRARY_API void
rocksdb_options_set_compression_options_zstd_max_train_bytes(rocksdb_options_t*,
int);
extern ROCKSDB_LIBRARY_API int
rocksdb_options_get_compression_options_zstd_max_train_bytes(
rocksdb_options_t* opt);
extern ROCKSDB_LIBRARY_API void
rocksdb_options_set_compression_options_parallel_threads(rocksdb_options_t*,
int);
extern ROCKSDB_LIBRARY_API int
rocksdb_options_get_compression_options_parallel_threads(
rocksdb_options_t* opt);
extern ROCKSDB_LIBRARY_API void
rocksdb_options_set_compression_options_max_dict_buffer_bytes(
rocksdb_options_t*, uint64_t);
extern ROCKSDB_LIBRARY_API uint64_t
rocksdb_options_get_compression_options_max_dict_buffer_bytes(
rocksdb_options_t* opt);
extern ROCKSDB_LIBRARY_API void
rocksdb_options_set_bottommost_compression_options(rocksdb_options_t*, int, int,
int, int, unsigned char);
Expand Down Expand Up @@ -1412,6 +1430,14 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_row_cache(
rocksdb_options_t* opt, rocksdb_cache_t* cache
);

extern ROCKSDB_LIBRARY_API void
rocksdb_options_add_compact_on_deletion_collector_factory(
rocksdb_options_t*, size_t window_size, size_t num_dels_trigger);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_manual_wal_flush(
rocksdb_options_t* opt, unsigned char);
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_options_get_manual_wal_flush(
rocksdb_options_t* opt);

/* RateLimiter */
extern ROCKSDB_LIBRARY_API rocksdb_ratelimiter_t* rocksdb_ratelimiter_create(
int64_t rate_bytes_per_sec, int64_t refill_period_us, int32_t fairness);
Expand Down Expand Up @@ -1738,10 +1764,28 @@ extern ROCKSDB_LIBRARY_API void rocksdb_flushoptions_set_wait(
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_flushoptions_get_wait(
rocksdb_flushoptions_t*);

/* Memory allocator */

extern ROCKSDB_LIBRARY_API rocksdb_memory_allocator_t*
rocksdb_jemalloc_nodump_allocator_create(char** errptr);
extern ROCKSDB_LIBRARY_API void rocksdb_memory_allocator_destroy(
rocksdb_memory_allocator_t*);

/* Cache */

extern ROCKSDB_LIBRARY_API rocksdb_lru_cache_options_t*
rocksdb_lru_cache_options_create(void);
extern ROCKSDB_LIBRARY_API void rocksdb_lru_cache_options_destroy(
rocksdb_lru_cache_options_t*);
extern ROCKSDB_LIBRARY_API void rocksdb_lru_cache_options_set_capacity(
rocksdb_lru_cache_options_t*, size_t);
extern ROCKSDB_LIBRARY_API void rocksdb_lru_cache_options_set_memory_allocator(
rocksdb_lru_cache_options_t*, rocksdb_memory_allocator_t*);

extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru(
size_t capacity);
extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru_opts(
rocksdb_lru_cache_options_t*);
extern ROCKSDB_LIBRARY_API void rocksdb_cache_destroy(rocksdb_cache_t* cache);
extern ROCKSDB_LIBRARY_API void rocksdb_cache_disown_data(
rocksdb_cache_t* cache);
Expand Down
Loading

0 comments on commit 5baba6b

Please sign in to comment.