Skip to content

Commit

Permalink
Add JAVA and C Interface for EnableSpeedbFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
mrambacher authored and udi-speedb committed Dec 25, 2023
1 parent 5e356db commit b129e16
Show file tree
Hide file tree
Showing 14 changed files with 650 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Enhancements
* Added a kUseBaseAddress flag and GetBaseOffset flag to OptionTypeInfo. If this flag is set and a function is used for processing options, the function is passed the base address of the struct rather than the specific field (#397)
* Enabled speedb features in C and Java (#722)

### Bug Fixes
* Stall deadlock consists small cfs (#637).
Expand Down
70 changes: 70 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ using ROCKSDB_NAMESPACE::RateLimiter;
using ROCKSDB_NAMESPACE::ReadOptions;
using ROCKSDB_NAMESPACE::RestoreOptions;
using ROCKSDB_NAMESPACE::SequentialFile;
using ROCKSDB_NAMESPACE::SharedOptions;
using ROCKSDB_NAMESPACE::Slice;
using ROCKSDB_NAMESPACE::SliceParts;
using ROCKSDB_NAMESPACE::SliceTransform;
Expand Down Expand Up @@ -189,6 +190,9 @@ struct rocksdb_writeoptions_t {
struct rocksdb_options_t {
Options rep;
};
struct rocksdb_shared_options_t {
SharedOptions rep;
};
struct rocksdb_compactoptions_t {
CompactRangeOptions rep;
Slice full_history_ts_low;
Expand Down Expand Up @@ -2828,6 +2832,27 @@ void rocksdb_options_optimize_universal_style_compaction(
opt->rep.OptimizeUniversalStyleCompaction(memtable_memory_budget);
}

void rocksdb_options_enable_speedb_features(rocksdb_options_t* opt,
rocksdb_shared_options_t* shared) {
opt->rep.EnableSpeedbFeatures(shared->rep);
}

void rocksdb_options_enable_speedb_features_db(
rocksdb_options_t* db_options, rocksdb_shared_options_t* shared) {
DBOptions& db_options_part = db_options->rep;
db_options_part.EnableSpeedbFeaturesDB(shared->rep);
}

void rocksdb_options_enable_speedb_features_cf(
rocksdb_options_t* column_family_options,
rocksdb_shared_options_t* shared) {
ColumnFamilyOptions& cf_options_part = column_family_options->rep;
cf_options_part.EnableSpeedbFeaturesCF(shared->rep);
}

void rocksdb_options_enable_speedb_features_db(
rocksdb_options_t* opt, rocksdb_shared_options_t* shared);

void rocksdb_options_set_allow_ingest_behind(rocksdb_options_t* opt,
unsigned char v) {
opt->rep.allow_ingest_behind = v;
Expand Down Expand Up @@ -3975,6 +4000,51 @@ int rocksdb_options_get_wal_compression(rocksdb_options_t* opt) {
return opt->rep.wal_compression;
}

rocksdb_shared_options_t* rocksdb_shared_options_create(
size_t total_ram_size_bytes, size_t total_threads) {
return new rocksdb_shared_options_t{
SharedOptions(total_ram_size_bytes, total_threads)};
}
rocksdb_shared_options_t* rocksdb_shared_options_create_from(
size_t total_ram_size_bytes, size_t total_threads,
size_t delayed_write_rate, size_t bucket_size, int use_merge) {
return new rocksdb_shared_options_t{
SharedOptions(total_ram_size_bytes, total_threads, delayed_write_rate,
bucket_size, use_merge)};
}

void rocksdb_shared_options_destroy(rocksdb_shared_options_t* opt) {
delete opt;
}

size_t rocksdb_shared_options_get_max_write_buffer_manager_size(
rocksdb_shared_options_t* opt) {
return opt->rep.GetMaxWriteBufferManagerSize();
}

size_t rocksdb_shared_options_get_total_threads(rocksdb_shared_options_t* opt) {
return opt->rep.GetTotalThreads();
}

size_t rocksdb_shared_options_get_total_ram_size_bytes(
rocksdb_shared_options_t* opt) {
return opt->rep.GetTotalRamSizeBytes();
}

size_t rocksdb_shared_options_get_delayed_write_rate(
rocksdb_shared_options_t* opt) {
return opt->rep.GetDelayedWriteRate();
}

size_t rocksdb_shared_options_get_bucket_size(rocksdb_shared_options_t* opt) {
return opt->rep.GetBucketSize();
}

unsigned char rocksdb_shared_options_is_merge_memtable_supported(
rocksdb_shared_options_t* opt) {
return opt->rep.IsMergeMemtableSupported();
}

rocksdb_ratelimiter_t* rocksdb_ratelimiter_create(int64_t rate_bytes_per_sec,
int64_t refill_period_us,
int32_t fairness) {
Expand Down
53 changes: 53 additions & 0 deletions db/c_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,59 @@ int main(int argc, char** argv) {
rocksdb_options_destroy(o);
}

StartPhase("shared_options");
{
size_t total_ram_size = 100 * 1024 * 1024 * 1024ul;
size_t total_threads = 8;
size_t delayed_write_rate = 256 * 1024 * 1024ul;
size_t bucket_size = 50000;
rocksdb_shared_options_t* so;
so = rocksdb_shared_options_create(total_ram_size, total_threads);
CheckCondition(total_threads ==
rocksdb_shared_options_get_total_threads(so));
CheckCondition(total_ram_size ==
rocksdb_shared_options_get_total_ram_size_bytes(so));
rocksdb_shared_options_destroy(so);

so = rocksdb_shared_options_create_from(total_ram_size, total_threads,
delayed_write_rate, bucket_size, 1);
CheckCondition(total_threads ==
rocksdb_shared_options_get_total_threads(so));
CheckCondition(total_ram_size ==
rocksdb_shared_options_get_total_ram_size_bytes(so));
CheckCondition(delayed_write_rate ==
rocksdb_shared_options_get_delayed_write_rate(so));
CheckCondition(bucket_size == rocksdb_shared_options_get_bucket_size(so));
CheckCondition(
total_ram_size / 4 ==
rocksdb_shared_options_get_max_write_buffer_manager_size(so));
CheckCondition(1 == rocksdb_shared_options_is_merge_memtable_supported(so));
rocksdb_options_t* opts1 = rocksdb_options_create();
rocksdb_options_enable_speedb_features(opts1, so);

CheckCondition((int)total_threads ==
rocksdb_options_get_max_background_jobs(opts1));
CheckCondition(1 << 20 == rocksdb_options_get_bytes_per_sync(opts1));
CheckCondition(4 == rocksdb_options_get_max_write_buffer_number(opts1));

rocksdb_options_t* opts2 = rocksdb_options_create();
size_t orig_total_threads = rocksdb_options_get_max_background_jobs(opts2);
CheckCondition(total_threads != orig_total_threads);
rocksdb_options_enable_speedb_features_db(opts2, so);
CheckCondition((int)total_threads ==
rocksdb_options_get_max_background_jobs(opts2));

rocksdb_options_t* opts3 = rocksdb_options_create();
rocksdb_options_enable_speedb_features_cf(opts3, so);
CheckCondition((int)orig_total_threads ==
rocksdb_options_get_max_background_jobs(opts3));

rocksdb_options_destroy(opts3);
rocksdb_options_destroy(opts2);
rocksdb_options_destroy(opts1);
rocksdb_shared_options_destroy(so);
}

StartPhase("read_options");
{
rocksdb_readoptions_t* ro;
Expand Down
33 changes: 33 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef struct rocksdb_iterator_t rocksdb_iterator_t;
typedef struct rocksdb_logger_t rocksdb_logger_t;
typedef struct rocksdb_mergeoperator_t rocksdb_mergeoperator_t;
typedef struct rocksdb_options_t rocksdb_options_t;
typedef struct rocksdb_shared_options_t rocksdb_shared_options_t;
typedef struct rocksdb_compactoptions_t rocksdb_compactoptions_t;
typedef struct rocksdb_block_based_table_options_t
rocksdb_block_based_table_options_t;
Expand Down Expand Up @@ -1113,6 +1114,12 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_optimize_for_point_lookup(
rocksdb_options_t* opt, uint64_t block_cache_size_mb);
extern ROCKSDB_LIBRARY_API void rocksdb_options_optimize_level_style_compaction(
rocksdb_options_t* opt, uint64_t memtable_memory_budget);
extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_speedb_features(
rocksdb_options_t* opt, rocksdb_shared_options_t* shared);
extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_speedb_features_db(
rocksdb_options_t* opt, rocksdb_shared_options_t* shared);
extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_speedb_features_cf(
rocksdb_options_t* opt, rocksdb_shared_options_t* shared);
extern ROCKSDB_LIBRARY_API void
rocksdb_options_optimize_universal_style_compaction(
rocksdb_options_t* opt, uint64_t memtable_memory_budget);
Expand Down Expand Up @@ -1683,6 +1690,32 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_wal_compression(
extern ROCKSDB_LIBRARY_API int rocksdb_options_get_wal_compression(
rocksdb_options_t* opt);

/* SharedOptions */
extern ROCKSDB_LIBRARY_API rocksdb_shared_options_t*
rocksdb_shared_options_create(size_t total_ram_size_bytes,
size_t total_threads);
extern ROCKSDB_LIBRARY_API rocksdb_shared_options_t*
rocksdb_shared_options_create_from(size_t total_ram_size_bytes,
size_t total_threads,
size_t delayed_write_rate,
size_t bucket_size, int use_merge);
extern ROCKSDB_LIBRARY_API void rocksdb_shared_options_destroy(
rocksdb_shared_options_t* options);
extern ROCKSDB_LIBRARY_API size_t
rocksdb_shared_options_get_max_write_buffer_manager_size(
rocksdb_shared_options_t* opt);
extern ROCKSDB_LIBRARY_API size_t
rocksdb_shared_options_get_total_threads(rocksdb_shared_options_t* opt);
extern ROCKSDB_LIBRARY_API size_t
rocksdb_shared_options_get_total_ram_size_bytes(rocksdb_shared_options_t* opt);
extern ROCKSDB_LIBRARY_API size_t
rocksdb_shared_options_get_delayed_write_rate(rocksdb_shared_options_t* opt);
extern ROCKSDB_LIBRARY_API size_t
rocksdb_shared_options_get_bucket_size(rocksdb_shared_options_t* options);
extern ROCKSDB_LIBRARY_API unsigned char
rocksdb_shared_options_is_merge_memtable_supported(
rocksdb_shared_options_t* options);

/* 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
16 changes: 16 additions & 0 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2023 Speedb Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.4)

if(${CMAKE_VERSION} VERSION_LESS "3.11.4")
Expand Down Expand Up @@ -280,6 +294,7 @@ set(JAVA_MAIN_CLASSES
src/main/java/org/rocksdb/util/ReverseBytewiseComparator.java
src/main/java/org/rocksdb/util/SizeUnit.java
src/main/java/org/rocksdb/UInt64AddOperator.java
src/main/java/org/rocksdb/SharedOptions.java
)

set(JAVA_TEST_CLASSES
Expand Down Expand Up @@ -523,6 +538,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.11.4")
org.rocksdb.WriteBatchTestInternalHelper
org.rocksdb.WriteBufferManager
org.rocksdb.test.TestableEventListener
org.rocksdb.SharedOptions
)

create_javah(
Expand Down
18 changes: 17 additions & 1 deletion java/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2023 Speedb Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PROJECT_NAME?=speedb

NATIVE_JAVA_CLASSES = \
Expand Down Expand Up @@ -92,7 +106,8 @@ NATIVE_JAVA_CLASSES = \
org.rocksdb.WriteOptions\
org.rocksdb.WriteBatchWithIndex\
org.rocksdb.WriteBufferManager\
org.rocksdb.WBWIRocksIterator
org.rocksdb.WBWIRocksIterator\
org.rocksdb.SharedOptions

NATIVE_JAVA_TEST_CLASSES = \
org.rocksdb.RocksDBExceptionTest\
Expand Down Expand Up @@ -174,6 +189,7 @@ JAVA_TESTS = \
org.rocksdb.RocksMemEnvTest\
org.rocksdb.util.SizeUnitTest\
org.rocksdb.SecondaryDBTest\
org.rocksdb.SharedOptionsTest\
org.rocksdb.SliceTest\
org.rocksdb.SnapshotTest\
org.rocksdb.SstFileManagerTest\
Expand Down
Loading

0 comments on commit b129e16

Please sign in to comment.