Skip to content

Commit

Permalink
adapt RocksDB v9.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Apr 9, 2024
1 parent 36c5311 commit 6d48db0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
25 changes: 14 additions & 11 deletions c.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ extern ROCKSDB_LIBRARY_API const rocksdb_snapshot_t* rocksdb_create_snapshot(
extern ROCKSDB_LIBRARY_API void rocksdb_release_snapshot(
rocksdb_t* db, const rocksdb_snapshot_t* snapshot);

extern ROCKSDB_LIBRARY_API uint64_t
rocksdb_snapshot_get_sequence_number(const rocksdb_snapshot_t* snapshot);

/* Returns NULL if property name is unknown.
Else returns a pointer to a malloc()-ed null-terminated value. */
extern ROCKSDB_LIBRARY_API char* rocksdb_property_value(rocksdb_t* db,
Expand Down Expand Up @@ -691,8 +694,8 @@ extern ROCKSDB_LIBRARY_API void rocksdb_flush_wal(rocksdb_t* db,
extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions(rocksdb_t* db,
char** errptr);

extern ROCKSDB_LIBRARY_API void rocksdb_enable_file_deletions(
rocksdb_t* db, unsigned char force, char** errptr);
extern ROCKSDB_LIBRARY_API void rocksdb_enable_file_deletions(rocksdb_t* db,
char** errptr);

/* Management operations */

Expand Down Expand Up @@ -1152,10 +1155,16 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_env(rocksdb_options_t*,
rocksdb_env_t*);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_info_log(rocksdb_options_t*,
rocksdb_logger_t*);
extern ROCKSDB_LIBRARY_API rocksdb_logger_t* rocksdb_options_get_info_log(
rocksdb_options_t* opt);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_info_log_level(
rocksdb_options_t*, int);
extern ROCKSDB_LIBRARY_API int rocksdb_options_get_info_log_level(
rocksdb_options_t*);
extern ROCKSDB_LIBRARY_API rocksdb_logger_t*
rocksdb_logger_create_stderr_logger(int log_level, const char* prefix);
extern ROCKSDB_LIBRARY_API void rocksdb_logger_destroy(
rocksdb_logger_t* logger);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_write_buffer_size(
rocksdb_options_t*, size_t);
extern ROCKSDB_LIBRARY_API size_t
Expand Down Expand Up @@ -1499,10 +1508,6 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_advise_random_on_open(
rocksdb_options_t*, unsigned char);
extern ROCKSDB_LIBRARY_API unsigned char
rocksdb_options_get_advise_random_on_open(rocksdb_options_t*);
extern ROCKSDB_LIBRARY_API void
rocksdb_options_set_access_hint_on_compaction_start(rocksdb_options_t*, int);
extern ROCKSDB_LIBRARY_API int
rocksdb_options_get_access_hint_on_compaction_start(rocksdb_options_t*);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_use_adaptive_mutex(
rocksdb_options_t*, unsigned char);
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_options_get_use_adaptive_mutex(
Expand Down Expand Up @@ -1678,12 +1683,10 @@ extern ROCKSDB_LIBRARY_API int rocksdb_options_get_wal_compression(
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);
extern ROCKSDB_LIBRARY_API rocksdb_ratelimiter_t*
rocksdb_ratelimiter_create_auto_tuned(int64_t rate_bytes_per_sec,
int64_t refill_period_us,
int32_t fairness);
rocksdb_ratelimiter_create_with_mode(int64_t rate_bytes_per_sec,
int64_t refill_period_us, int32_t fairness,
int mode, bool auto_tuned);
extern ROCKSDB_LIBRARY_API void rocksdb_ratelimiter_destroy(
rocksdb_ratelimiter_t*);

Expand Down
2 changes: 1 addition & 1 deletion db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func newTestDB(t *testing.T, applyOpts func(opts *Options)) *DB {

opts := NewDefaultOptions()
// test the ratelimiter
rateLimiter := NewRateLimiter(1024, 100*1000, 10)
rateLimiter := NewRateLimiter(1024, 100*1000, 10, RateLimiterModeReadsOnly)
opts.SetRateLimiter(rateLimiter)
opts.SetCreateIfMissing(true)
opts.SetCompression(ZSTDCompression)
Expand Down
15 changes: 0 additions & 15 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,21 +1451,6 @@ func (opts *Options) GetDbWriteBufferSize() uint64 {
return uint64(C.rocksdb_options_get_db_write_buffer_size(opts.c))
}

// SetAccessHintOnCompactionStart specifies the file access pattern
// once a compaction is started.
//
// It will be applied to all input files of a compaction.
// Default: NormalCompactionAccessPattern
func (opts *Options) SetAccessHintOnCompactionStart(value CompactionAccessPattern) {
C.rocksdb_options_set_access_hint_on_compaction_start(opts.c, C.int(value))
}

// GetAccessHintOnCompactionStart returns the file access pattern
// once a compaction is started.
func (opts *Options) GetAccessHintOnCompactionStart() CompactionAccessPattern {
return CompactionAccessPattern(C.rocksdb_options_get_access_hint_on_compaction_start(opts.c))
}

// SetUseAdaptiveMutex enable/disable adaptive mutex, which spins
// in the user space before resorting to kernel.
//
Expand Down
35 changes: 24 additions & 11 deletions ratelimiter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package grocksdb

const (
RateLimiterModeReadsOnly = iota
RateLimiterModeWritesOnly
RateLimiterModeAllIo
)

// #include <stdlib.h>
// #include "rocksdb/c.h"
import "C"
Expand Down Expand Up @@ -31,25 +37,32 @@ type RateLimiter struct {
// continuously. This fairness parameter grants low-pri requests permission by
// 1/fairness chance even though high-pri requests exist to avoid starvation.
// You should be good by leaving it at default 10.
func NewRateLimiter(rateBytesPerSec, refillPeriodMicros int64, fairness int32) *RateLimiter {
cR := C.rocksdb_ratelimiter_create(
//
// @mode: Mode indicates which types of operations count against the limit.
//
// @auto_tuned: Enables dynamic adjustment of rate limit within the range
// `[rate_bytes_per_sec / 20, rate_bytes_per_sec]`, according to
// the recent demand for background I/O.
func NewGenericRateLimiter(
rateBytesPerSec, refillPeriodMicros int64, fairness int32,
int mode, bool autoTuned,
) *RateLimiter {
cR := C.rocksdb_ratelimiter_create_with_mode(
C.int64_t(rateBytesPerSec),
C.int64_t(refillPeriodMicros),
C.int32_t(fairness),
C.int(mode),
C.bool(autoTuned),
)
return newNativeRateLimiter(cR)
}

// NewAutoTunedRateLimiter similar to NewRateLimiter, enables dynamic adjustment of rate
// limit within the range `[rate_bytes_per_sec / 20, rate_bytes_per_sec]`, according to
// the recent demand for background I/O.
func NewRateLimiter(rateBytesPerSec, refillPeriodMicros int64, fairness int32) *RateLimiter {
return NewGenericRateLimiter(rateBytesPerSec, refillPeriodMicros, fairness, RateLimiterModeWritesOnly, false)
}

func NewAutoTunedRateLimiter(rateBytesPerSec, refillPeriodMicros int64, fairness int32) *RateLimiter {
cR := C.rocksdb_ratelimiter_create_auto_tuned(
C.int64_t(rateBytesPerSec),
C.int64_t(refillPeriodMicros),
C.int32_t(fairness),
)
return newNativeRateLimiter(cR)
return NewGenericRateLimiter(rateBytesPerSec, refillPeriodMicros, fairness, RateLimiterModeWritesOnly, true)
}

// NewNativeRateLimiter creates a native RateLimiter object.
Expand Down
5 changes: 5 additions & 0 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ func (snapshot *Snapshot) Destroy() {
C.rocksdb_free(unsafe.Pointer(snapshot.c))
snapshot.c = nil
}

// GetSequenceNumber returns the sequence number of the snapshot
func (snapshot *Snapshot) GetSequenceNumber() uint64 {
return C.rocksdb_snapshot_get_sequence_number(snapshot.c)
}

0 comments on commit 6d48db0

Please sign in to comment.