Skip to content

Commit

Permalink
Adapt RocksDB 8.6.7 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Dec 12, 2023
1 parent 23acbb6 commit 33f5fd7
Show file tree
Hide file tree
Showing 5 changed files with 744 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cd $BUILD_PATH && wget https://github.com/facebook/zstd/archive/v${zstd_version}

# Note: if you don't have a good reason, please do not set -DPORTABLE=ON
# This one is set here on purpose of compatibility with github action runtime processor
rocksdb_version="8.5.3"
rocksdb_version="8.6.7"
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 -DWITH_LIBURING=OFF \
Expand Down
49 changes: 48 additions & 1 deletion c.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ typedef struct rocksdb_wal_iterator_t rocksdb_wal_iterator_t;
typedef struct rocksdb_wal_readoptions_t rocksdb_wal_readoptions_t;
typedef struct rocksdb_memory_consumers_t rocksdb_memory_consumers_t;
typedef struct rocksdb_memory_usage_t rocksdb_memory_usage_t;
typedef struct rocksdb_statistics_histogram_data_t
rocksdb_statistics_histogram_data_t;

/* DB operations */

Expand Down Expand Up @@ -1252,6 +1254,22 @@ rocksdb_options_set_max_bytes_for_level_multiplier_additional(
rocksdb_options_t*, int* level_values, size_t num_levels);
extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_statistics(
rocksdb_options_t*);

enum {
rocksdb_statistics_level_disable_all = 0,
rocksdb_statistics_level_except_tickers =
rocksdb_statistics_level_disable_all,
rocksdb_statistics_level_except_histogram_or_timers = 1,
rocksdb_statistics_level_except_timers = 2,
rocksdb_statistics_level_except_detailed_timers = 3,
rocksdb_statistics_level_except_time_for_mutex = 4,
rocksdb_statistics_level_all = 5,
};

extern ROCKSDB_LIBRARY_API void rocksdb_options_set_statistics_level(
rocksdb_options_t*, int level);
extern ROCKSDB_LIBRARY_API int rocksdb_options_get_statistics_level(
rocksdb_options_t*);
extern ROCKSDB_LIBRARY_API void
rocksdb_options_set_skip_stats_update_on_db_open(rocksdb_options_t* opt,
unsigned char val);
Expand Down Expand Up @@ -1328,6 +1346,11 @@ extern ROCKSDB_LIBRARY_API int rocksdb_options_get_prepopulate_blob_cache(
/* returns a pointer to a malloc()-ed, null terminated string */
extern ROCKSDB_LIBRARY_API char* rocksdb_options_statistics_get_string(
rocksdb_options_t* opt);
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_options_statistics_get_ticker_count(
rocksdb_options_t* opt, uint32_t ticker_type);
extern ROCKSDB_LIBRARY_API void rocksdb_options_statistics_get_histogram_data(
rocksdb_options_t* opt, uint32_t histogram_type,
rocksdb_statistics_histogram_data_t* const data);

extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_write_buffer_number(
rocksdb_options_t*, int);
Expand Down Expand Up @@ -2257,7 +2280,8 @@ extern ROCKSDB_LIBRARY_API rocksdb_fifo_compaction_options_t*
rocksdb_fifo_compaction_options_create(void);
extern ROCKSDB_LIBRARY_API void
rocksdb_fifo_compaction_options_set_allow_compaction(
rocksdb_fifo_compaction_options_t* fifo_opts, unsigned char allow_compaction);
rocksdb_fifo_compaction_options_t* fifo_opts,
unsigned char allow_compaction);
extern ROCKSDB_LIBRARY_API unsigned char
rocksdb_fifo_compaction_options_get_allow_compaction(
rocksdb_fifo_compaction_options_t* fifo_opts);
Expand Down Expand Up @@ -2880,6 +2904,29 @@ extern ROCKSDB_LIBRARY_API void rocksdb_disable_manual_compaction(

extern ROCKSDB_LIBRARY_API void rocksdb_enable_manual_compaction(rocksdb_t* db);

extern ROCKSDB_LIBRARY_API rocksdb_statistics_histogram_data_t*
rocksdb_statistics_histogram_data_create(void);
extern ROCKSDB_LIBRARY_API void rocksdb_statistics_histogram_data_destroy(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_median(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_p95(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_p99(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_average(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_std_dev(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_max(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_statistics_histogram_data_get_count(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_statistics_histogram_data_get_sum(
rocksdb_statistics_histogram_data_t* data);
extern ROCKSDB_LIBRARY_API double rocksdb_statistics_histogram_data_get_min(
rocksdb_statistics_histogram_data_t* data);

#ifdef __cplusplus
} /* end extern "C" */
#endif
33 changes: 33 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,29 @@ func (opts *Options) GetStatisticsString() (stats string) {
return
}

func (opts *Options) GetTickerCount(tickerType TickerType) uint64 {
return uint64(C.rocksdb_options_statistics_get_ticker_count(opts.c, C.uint32_t(tickerType)))
}

func (opts *Options) GetHistogramData(histogramType HistogramType) (histogram HistogramData) {
hData := C.rocksdb_statistics_histogram_data_create()
C.rocksdb_options_statistics_get_histogram_data(opts.c, C.uint32_t(histogramType), hData)

histogram.Median = float64(C.rocksdb_statistics_histogram_data_get_median(hData))
histogram.P95 = float64(C.rocksdb_statistics_histogram_data_get_p95(hData))
histogram.P99 = float64(C.rocksdb_statistics_histogram_data_get_p99(hData))
histogram.Average = float64(C.rocksdb_statistics_histogram_data_get_average(hData))
histogram.StdDev = float64(C.rocksdb_statistics_histogram_data_get_std_dev(hData))
histogram.Max = float64(C.rocksdb_statistics_histogram_data_get_max(hData))
histogram.Min = float64(C.rocksdb_statistics_histogram_data_get_min(hData))
histogram.Count = uint64(C.rocksdb_statistics_histogram_data_get_count(hData))
histogram.Sum = uint64(C.rocksdb_statistics_histogram_data_get_sum(hData))

C.rocksdb_statistics_histogram_data_destroy(hData)

return
}

// SetRateLimiter sets the rate limiter of the options.
// Use to control write rate of flush and compaction. Flush has higher
// priority than compaction. Rate limiting is disabled if nullptr.
Expand Down Expand Up @@ -1744,6 +1767,16 @@ func (opts *Options) EnableStatistics() {
C.rocksdb_options_enable_statistics(opts.c)
}

// SetStatisticsLevel set statistics level.
func (opts *Options) SetStatisticsLevel(level StatisticsLevel) {
C.rocksdb_options_set_statistics_level(opts.c, C.int(level))
}

// GetStatisticsLevel get statistics level.
func (opts *Options) GetStatisticsLevel() StatisticsLevel {
return StatisticsLevel(C.rocksdb_options_get_statistics_level(opts.c))
}

// PrepareForBulkLoad prepare the DB for bulk loading.
//
// All data will be in level 0 without any automatic compaction.
Expand Down
8 changes: 8 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ func TestOptions(t *testing.T) {
opts.AvoidUnnecessaryBlockingIO(true)
require.True(t, opts.GetAvoidUnnecessaryBlockingIOFlag())

require.Equal(t, StatisticsLevelExceptDetailedTimers, opts.GetStatisticsLevel())
opts.SetStatisticsLevel(StatisticsLevelExceptHistogramOrTimers)
require.Equal(t, StatisticsLevelExceptHistogramOrTimers, opts.GetStatisticsLevel())

require.EqualValues(t, 0, opts.GetTickerCount(TickerType_BACKUP_WRITE_BYTES))
hData := opts.GetHistogramData(HistogramType_BLOB_DB_MULTIGET_MICROS)
require.EqualValues(t, 0, hData.P99)

// cloning
cl := opts.Clone()
require.EqualValues(t, 5, cl.GetTableCacheNumshardbits())
Expand Down
Loading

0 comments on commit 33f5fd7

Please sign in to comment.