Add statistics object

main
Ankit Gupta 11 years ago
parent c87ed0942c
commit a044398260
  1. 2
      java/Makefile
  2. 16
      java/RocksDBSample.java
  3. 33
      java/org/rocksdb/Options.java
  4. 1
      java/org/rocksdb/RocksDB.java
  5. 1
      java/org/rocksdb/RocksDBException.java
  6. 2
      java/org/rocksdb/WriteBatch.java
  7. 1
      java/org/rocksdb/WriteBatchTest.java
  8. 27
      java/rocksjni/options.cc
  9. 1
      java/rocksjni/portal.h
  10. 1
      java/rocksjni/write_batch.cc

@ -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 NATIVE_INCLUDE = ./include
ROCKSDB_JAR = rocksdbjni.jar ROCKSDB_JAR = rocksdbjni.jar

@ -34,11 +34,13 @@ public class RocksDBSample {
} }
options.setCreateIfMissing(true) options.setCreateIfMissing(true)
.createStatistics()
.setWriteBufferSize(8 * SizeUnit.KB) .setWriteBufferSize(8 * SizeUnit.KB)
.setMaxWriteBufferNumber(3) .setMaxWriteBufferNumber(3)
.setDisableSeekCompaction(true) .setDisableSeekCompaction(true)
.setBlockSize(64 * SizeUnit.KB) .setBlockSize(64 * SizeUnit.KB)
.setMaxBackgroundCompactions(10); .setMaxBackgroundCompactions(10);
Statistics stats = new Statistics(options.statisticsPtr());
assert(options.createIfMissing() == true); assert(options.createIfMissing() == true);
assert(options.writeBufferSize() == 8 * SizeUnit.KB); assert(options.writeBufferSize() == 8 * SizeUnit.KB);
@ -120,13 +122,25 @@ public class RocksDBSample {
assert(new String(testValue).equals( assert(new String(testValue).equals(
new String(enoughArray, 0, len))); new String(enoughArray, 0, len)));
writeOpts.dispose(); 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) { } catch (RocksDBException e) {
System.err.println(e); System.err.println(e);
} }
if (db != null) { if (db != null) {
db.close(); db.close();
} }
// be sure to dispose c++ pointer // be sure to dispose c++ pointers
options.dispose(); options.dispose();
} }
} }

@ -200,6 +200,35 @@ public class Options {
return maxBackgroundCompactions(nativeHandle_); 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. * Set the amount of cache in bytes that will be used by RocksDB.
* If cacheSize is non-positive, then cache will not be used. * If cacheSize is non-positive, then cache will not be used.
@ -223,7 +252,7 @@ public class Options {
* in the c++ side. * in the c++ side.
*/ */
public synchronized void dispose() { public synchronized void dispose() {
if (nativeHandle_ != 0) { if (isInitialized()) {
dispose0(); dispose0();
} }
} }
@ -249,6 +278,8 @@ public class Options {
private native void setMaxBackgroundCompactions( private native void setMaxBackgroundCompactions(
long handle, int maxBackgroundCompactions); long handle, int maxBackgroundCompactions);
private native int maxBackgroundCompactions(long handle); private native int maxBackgroundCompactions(long handle);
private native void createStatistics(long optHandle);
private native long statisticsPtr(long optHandle);
long nativeHandle_; long nativeHandle_;
long cacheSize_; long cacheSize_;

@ -5,7 +5,6 @@
package org.rocksdb; package org.rocksdb;
import java.lang.*;
import java.util.*; import java.util.*;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;

@ -5,7 +5,6 @@
package org.rocksdb; package org.rocksdb;
import java.lang.*;
import java.util.*; import java.util.*;
/** /**

@ -5,7 +5,6 @@
package org.rocksdb; package org.rocksdb;
import java.lang.*;
import java.util.*; import java.util.*;
/** /**
@ -118,4 +117,3 @@ class WriteBatchInternal {
static native long sequence(WriteBatch batch); static native long sequence(WriteBatch batch);
static native void append(WriteBatch b1, WriteBatch b2); static native void append(WriteBatch b1, WriteBatch b2);
} }

@ -9,7 +9,6 @@
package org.rocksdb; package org.rocksdb;
import java.util.*; import java.util.*;
import java.lang.*;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
/** /**

@ -9,12 +9,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <jni.h> #include <jni.h>
#include <string> #include <string>
#include <memory>
#include "include/org_rocksdb_Options.h" #include "include/org_rocksdb_Options.h"
#include "include/org_rocksdb_WriteOptions.h" #include "include/org_rocksdb_WriteOptions.h"
#include "rocksjni/portal.h" #include "rocksjni/portal.h"
#include "rocksdb/db.h" #include "rocksdb/db.h"
#include "rocksdb/options.h" #include "rocksdb/options.h"
#include "rocksdb/statistics.h"
/* /*
* Class: org_rocksdb_Options * 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); rocksdb::Options* op = rocksdb::OptionsJni::getHandle(env, jobj);
delete op; 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; 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 * Class: org_rocksdb_Options
@ -235,5 +258,3 @@ jboolean Java_org_rocksdb_WriteOptions_disableWAL(
JNIEnv* env, jobject jwrite_options, jlong jhandle) { JNIEnv* env, jobject jwrite_options, jlong jhandle) {
return reinterpret_cast<rocksdb::WriteOptions*>(jhandle)->disableWAL; return reinterpret_cast<rocksdb::WriteOptions*>(jhandle)->disableWAL;
} }

@ -12,6 +12,7 @@
#include <jni.h> #include <jni.h>
#include "rocksdb/db.h" #include "rocksdb/db.h"
#include "rocksdb/statistics.h"
namespace rocksdb { namespace rocksdb {

@ -262,4 +262,3 @@ jbyteArray Java_org_rocksdb_WriteBatchTest_getContents(
return jstate; return jstate;
} }

Loading…
Cancel
Save