diff --git a/build.sh b/build.sh index 87009a7..b191f0e 100755 --- a/build.sh +++ b/build.sh @@ -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.10.2" +rocksdb_version="8.11.3" 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 \ diff --git a/c.h b/c.h index 8a26585..54c770a 100644 --- a/c.h +++ b/c.h @@ -1261,6 +1261,9 @@ 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*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_ttl(rocksdb_options_t*, + uint64_t); +extern ROCKSDB_LIBRARY_API uint64_t rocksdb_options_get_ttl(rocksdb_options_t*); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_periodic_compaction_seconds( rocksdb_options_t*, uint64_t); extern ROCKSDB_LIBRARY_API uint64_t diff --git a/options.go b/options.go index 8fc0a1e..442c907 100644 --- a/options.go +++ b/options.go @@ -1791,6 +1791,50 @@ func (opts *Options) EnableStatistics() { C.rocksdb_options_enable_statistics(opts.c) } +// SetTTL sets TTL. This option has different meanings for different compaction styles: +// +// Leveled: Non-bottom-level files with all keys older than TTL will go +// +// through the compaction process. This usually happens in a cascading +// way so that those entries will be compacted to bottommost level/file. +// The feature is used to remove stale entries that have been deleted or +// updated from the file system. +// +// FIFO: Files with all keys older than TTL will be deleted. TTL is only +// +// supported if option max_open_files is set to -1. +// +// Universal: users should only set the option `periodic_compaction_seconds` +// +// below instead. For backward compatibility, this option has the same +// meaning as `periodic_compaction_seconds`. See more in comments for +// `periodic_compaction_seconds` on the interaction between these two +// options. +// +// This option only supports block based table format for any compaction +// style. +// +// unit: seconds. Ex: 1 day = 1 * 24 * 60 * 60 +// 0 means disabling. +// UINT64_MAX - 1 (0xfffffffffffffffe) is special flag to allow RocksDB to +// pick default. +// +// Default: 30 days if using block based table. 0 (disable) otherwise. +// +// Dynamically changeable through SetOptions() API +// Note that dynamically changing this option only works for leveled and FIFO +// compaction. For universal compaction, dynamically changing this option has +// no effect, users should dynamically change `periodic_compaction_seconds` +// instead. +func (opts *Options) SetTTL(seconds uint64) { + C.rocksdb_options_set_ttl(opts.c, C.uint64_t(seconds)) +} + +// GetTTL gets TTL option. +func (opts *Options) GetTTL() uint64 { + return uint64(C.rocksdb_options_get_ttl(opts.c)) +} + // SetPeriodicCompactionSeconds sets periodic_compaction_seconds option. // // This option has different meanings for different compaction styles: diff --git a/options_test.go b/options_test.go index 35a4fac..5a23d0c 100644 --- a/options_test.go +++ b/options_test.go @@ -395,6 +395,10 @@ func TestOptions(t *testing.T) { opts.SetPeriodicCompactionSeconds(123) require.EqualValues(t, 123, opts.GetPeriodicCompactionSeconds()) + require.EqualValues(t, uint64(0xfffffffffffffffe), opts.GetTTL()) + opts.SetTTL(123) + require.EqualValues(t, uint64(123), opts.GetTTL()) + opts.SetWriteBufferManager(wbm) // cloning