Skip to content

Commit

Permalink
Improve the design and native object management of Stats in RocksJava
Browse files Browse the repository at this point in the history
Summary: Closes facebook#2551

Differential Revision: D5399288

Pulled By: sagar0

fbshipit-source-id: dd3df2ed6cc5ae612db0998ea746cc29fccf568e
  • Loading branch information
adamretter authored and facebook-github-bot committed Jul 12, 2017
1 parent 269d383 commit 000bf0a
Show file tree
Hide file tree
Showing 21 changed files with 1,900 additions and 384 deletions.
1 change: 1 addition & 0 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(JNI_NATIVE_SOURCES
rocksjni/snapshot.cc
rocksjni/sst_file_writerjni.cc
rocksjni/statistics.cc
rocksjni/statisticsjni.cc
rocksjni/table.cc
rocksjni/transaction_log.cc
rocksjni/ttl.cc
Expand Down
15 changes: 8 additions & 7 deletions java/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NATIVE_JAVA_CLASSES = org.rocksdb.AbstractCompactionFilter\
org.rocksdb.AbstractComparator\
org.rocksdb.AbstractComparator\
org.rocksdb.AbstractSlice\
org.rocksdb.BackupEngine\
org.rocksdb.BackupableDBOptions\
Expand Down Expand Up @@ -69,9 +69,9 @@ ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.
endif

JAVA_TESTS = org.rocksdb.BackupableDBOptionsTest\
org.rocksdb.BackupEngineTest\
org.rocksdb.BackupEngineTest\
org.rocksdb.BlockBasedTableConfigTest\
org.rocksdb.util.BytewiseComparatorTest\
org.rocksdb.util.BytewiseComparatorTest\
org.rocksdb.CheckPointTest\
org.rocksdb.ClockCacheTest\
org.rocksdb.ColumnFamilyOptionsTest\
Expand All @@ -94,13 +94,13 @@ JAVA_TESTS = org.rocksdb.BackupableDBOptionsTest\
org.rocksdb.FlushTest\
org.rocksdb.InfoLogLevelTest\
org.rocksdb.KeyMayExistTest\
org.rocksdb.LoggerTest\
org.rocksdb.LoggerTest\
org.rocksdb.LRUCacheTest\
org.rocksdb.MemTableTest\
org.rocksdb.MergeTest\
org.rocksdb.MixedOptionsTest\
org.rocksdb.MutableColumnFamilyOptionsTest\
org.rocksdb.NativeLibraryLoaderTest\
org.rocksdb.MutableColumnFamilyOptionsTest\
org.rocksdb.NativeLibraryLoaderTest\
org.rocksdb.OptionsTest\
org.rocksdb.PlainTableConfigTest\
org.rocksdb.RateLimiterTest\
Expand All @@ -117,11 +117,12 @@ JAVA_TESTS = org.rocksdb.BackupableDBOptionsTest\
org.rocksdb.SstFileWriterTest\
org.rocksdb.TransactionLogIteratorTest\
org.rocksdb.TtlDBTest\
org.rocksdb.StatisticsTest\
org.rocksdb.StatisticsCollectorTest\
org.rocksdb.WALRecoveryModeTest\
org.rocksdb.WriteBatchHandlerTest\
org.rocksdb.WriteBatchTest\
org.rocksdb.WriteBatchThreadedTest\
org.rocksdb.WriteBatchThreadedTest\
org.rocksdb.WriteOptionsTest\
org.rocksdb.WriteBatchWithIndexTest

Expand Down
66 changes: 43 additions & 23 deletions java/rocksjni/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "rocksjni/comparatorjnicallback.h"
#include "rocksjni/portal.h"
#include "rocksjni/statisticsjni.h"

#include "rocksdb/db.h"
#include "rocksdb/options.h"
Expand Down Expand Up @@ -224,24 +225,34 @@ void Java_org_rocksdb_Options_setMaxWriteBufferNumber(

/*
* Class: org_rocksdb_Options
* Method: createStatistics
* Signature: (J)V
* Method: setStatistics
* Signature: (JJ)V
*/
void Java_org_rocksdb_Options_createStatistics(
JNIEnv* env, jobject jobj, jlong jOptHandle) {
reinterpret_cast<rocksdb::Options*>(jOptHandle)->statistics =
rocksdb::CreateDBStatistics();
void Java_org_rocksdb_Options_setStatistics(
JNIEnv* env, jobject jobj, jlong jhandle, jlong jstatistics_handle) {
auto* opt = reinterpret_cast<rocksdb::Options*>(jhandle);
auto* pSptr =
reinterpret_cast<std::shared_ptr<rocksdb::StatisticsJni>*>(
jstatistics_handle);
opt->statistics = *pSptr;
}

/*
* Class: org_rocksdb_Options
* Method: statisticsPtr
* Method: statistics
* Signature: (J)J
*/
jlong Java_org_rocksdb_Options_statisticsPtr(
JNIEnv* env, jobject jobj, jlong jOptHandle) {
auto* st = reinterpret_cast<rocksdb::Options*>(jOptHandle)->statistics.get();
return reinterpret_cast<jlong>(st);
jlong Java_org_rocksdb_Options_statistics(
JNIEnv* env, jobject jobj, jlong jhandle) {
auto* opt = reinterpret_cast<rocksdb::Options*>(jhandle);
std::shared_ptr<rocksdb::Statistics> sptr = opt->statistics;
if (sptr == nullptr) {
return 0;
} else {
std::shared_ptr<rocksdb::Statistics>* pSptr =
new std::shared_ptr<rocksdb::Statistics>(sptr);
return reinterpret_cast<jlong>(pSptr);
}
}

/*
Expand Down Expand Up @@ -4376,25 +4387,34 @@ jint Java_org_rocksdb_DBOptions_maxFileOpeningThreads(

/*
* Class: org_rocksdb_DBOptions
* Method: createStatistics
* Signature: (J)V
* Method: setStatistics
* Signature: (JJ)V
*/
void Java_org_rocksdb_DBOptions_createStatistics(
JNIEnv* env, jobject jobj, jlong jOptHandle) {
reinterpret_cast<rocksdb::DBOptions*>(jOptHandle)->statistics =
rocksdb::CreateDBStatistics();
void Java_org_rocksdb_DBOptions_setStatistics(
JNIEnv* env, jobject jobj, jlong jhandle, jlong jstatistics_handle) {
auto* opt = reinterpret_cast<rocksdb::DBOptions*>(jhandle);
auto* pSptr =
reinterpret_cast<std::shared_ptr<rocksdb::StatisticsJni>*>(
jstatistics_handle);
opt->statistics = *pSptr;
}

/*
* Class: org_rocksdb_DBOptions
* Method: statisticsPtr
* Method: statistics
* Signature: (J)J
*/
jlong Java_org_rocksdb_DBOptions_statisticsPtr(
JNIEnv* env, jobject jobj, jlong jOptHandle) {
auto* st = reinterpret_cast<rocksdb::DBOptions*>(jOptHandle)->
statistics.get();
return reinterpret_cast<jlong>(st);
jlong Java_org_rocksdb_DBOptions_statistics(
JNIEnv* env, jobject jobj, jlong jhandle) {
auto* opt = reinterpret_cast<rocksdb::DBOptions*>(jhandle);
std::shared_ptr<rocksdb::Statistics> sptr = opt->statistics;
if (sptr == nullptr) {
return 0;
} else {
std::shared_ptr<rocksdb::Statistics>* pSptr =
new std::shared_ptr<rocksdb::Statistics>(sptr);
return reinterpret_cast<jlong>(pSptr);
}
}

/*
Expand Down
Loading

0 comments on commit 000bf0a

Please sign in to comment.