mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add statistics object
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions
|
||||
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.Statistics
|
||||
NATIVE_INCLUDE = ./include
|
||||
ROCKSDB_JAR = rocksdbjni.jar
|
||||
|
||||
|
||||
@@ -34,11 +34,13 @@ public class RocksDBSample {
|
||||
}
|
||||
|
||||
options.setCreateIfMissing(true)
|
||||
.createStatistics()
|
||||
.setWriteBufferSize(8 * SizeUnit.KB)
|
||||
.setMaxWriteBufferNumber(3)
|
||||
.setDisableSeekCompaction(true)
|
||||
.setBlockSize(64 * SizeUnit.KB)
|
||||
.setMaxBackgroundCompactions(10);
|
||||
Statistics stats = new Statistics(options.statisticsPtr());
|
||||
|
||||
assert(options.createIfMissing() == true);
|
||||
assert(options.writeBufferSize() == 8 * SizeUnit.KB);
|
||||
@@ -120,13 +122,25 @@ public class RocksDBSample {
|
||||
assert(new String(testValue).equals(
|
||||
new String(enoughArray, 0, len)));
|
||||
writeOpts.dispose();
|
||||
|
||||
try {
|
||||
for(StatisticsType statsType : StatisticsType.values()) {
|
||||
stats.getTickerCount(statsType);
|
||||
}
|
||||
System.out.println("getTickerCount() passed.");
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println("Failed in call to getTickerCount()");
|
||||
assert(false); //Should never reach here.
|
||||
}
|
||||
|
||||
} catch (RocksDBException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
// be sure to dispose c++ pointer
|
||||
// be sure to dispose c++ pointers
|
||||
options.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +200,35 @@ public class Options {
|
||||
return maxBackgroundCompactions(nativeHandle_);
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates statistics object which collects metrics about database operations.
|
||||
Statistics objects should not be shared between DB instances as
|
||||
it does not use any locks to prevent concurrent updates.
|
||||
*
|
||||
* @return the instance of the current Options.
|
||||
* @see RocksDB.open()
|
||||
*/
|
||||
public Options createStatistics() {
|
||||
assert(isInitialized());
|
||||
createStatistics(nativeHandle_);
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Pointer to statistics object. Should only be called after statistics has
|
||||
* been created by createStatistics() call.
|
||||
*
|
||||
* @see createStatistics()
|
||||
*/
|
||||
public long statisticsPtr() {
|
||||
assert(isInitialized());
|
||||
|
||||
long statsPtr = statisticsPtr(nativeHandle_);
|
||||
assert(statsPtr != 0);
|
||||
|
||||
return statsPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the amount of cache in bytes that will be used by RocksDB.
|
||||
* If cacheSize is non-positive, then cache will not be used.
|
||||
@@ -223,7 +252,7 @@ public class Options {
|
||||
* in the c++ side.
|
||||
*/
|
||||
public synchronized void dispose() {
|
||||
if (nativeHandle_ != 0) {
|
||||
if (isInitialized()) {
|
||||
dispose0();
|
||||
}
|
||||
}
|
||||
@@ -249,6 +278,8 @@ public class Options {
|
||||
private native void setMaxBackgroundCompactions(
|
||||
long handle, int maxBackgroundCompactions);
|
||||
private native int maxBackgroundCompactions(long handle);
|
||||
private native void createStatistics(long optHandle);
|
||||
private native long statisticsPtr(long optHandle);
|
||||
|
||||
long nativeHandle_;
|
||||
long cacheSize_;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -118,4 +117,3 @@ class WriteBatchInternal {
|
||||
static native long sequence(WriteBatch batch);
|
||||
static native void append(WriteBatch b1, WriteBatch b2);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.rocksdb;
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.*;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "include/org_rocksdb_Options.h"
|
||||
#include "include/org_rocksdb_WriteOptions.h"
|
||||
#include "rocksjni/portal.h"
|
||||
#include "rocksdb/db.h"
|
||||
#include "rocksdb/options.h"
|
||||
#include "rocksdb/statistics.h"
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
@@ -35,7 +37,7 @@ void Java_org_rocksdb_Options_dispose0(JNIEnv* env, jobject jobj) {
|
||||
rocksdb::Options* op = rocksdb::OptionsJni::getHandle(env, jobj);
|
||||
delete op;
|
||||
|
||||
rocksdb::OptionsJni::setHandle(env, jobj, op);
|
||||
rocksdb::OptionsJni::setHandle(env, jobj, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -91,6 +93,27 @@ void Java_org_rocksdb_Options_setMaxWriteBufferNumber(
|
||||
jmax_write_buffer_number;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: createStatistics
|
||||
* Signature: (J)V
|
||||
*/
|
||||
void Java_org_rocksdb_Options_createStatistics(
|
||||
JNIEnv* env, jobject jobj, jlong jOptHandle) {
|
||||
reinterpret_cast<rocksdb::Options*>(jOptHandle)->statistics =
|
||||
rocksdb::CreateDBStatistics();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: statisticsPtr
|
||||
* 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
@@ -235,5 +258,3 @@ jboolean Java_org_rocksdb_WriteOptions_disableWAL(
|
||||
JNIEnv* env, jobject jwrite_options, jlong jhandle) {
|
||||
return reinterpret_cast<rocksdb::WriteOptions*>(jhandle)->disableWAL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
#include "rocksdb/db.h"
|
||||
#include "rocksdb/statistics.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
|
||||
@@ -262,4 +262,3 @@ jbyteArray Java_org_rocksdb_WriteBatchTest_getContents(
|
||||
|
||||
return jstate;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user