From cb5c3159f0d60556b54e43a19d3fd3f54fbd9941 Mon Sep 17 00:00:00 2001 From: fyrz Date: Fri, 30 Jan 2015 21:05:45 +0100 Subject: [PATCH] [RocksJava] Snapshot - GetSequenceNumber Summary: As the C++ part exposes now SequenceNumber retrieval for Snapshots we want this obviously also in the Java API. Test Plan: make rocksdbjava make jtest mvn -f rocksjni.pom test Reviewers: yhchiang, adamretter, ankgup87 Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D32571 --- java/Makefile | 1 + java/org/rocksdb/Snapshot.java | 13 +++++++++++++ java/org/rocksdb/test/SnapshotTest.java | 2 ++ java/rocksjni/rocksjni.cc | 4 ++-- java/rocksjni/snapshot.cc | 26 +++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 java/rocksjni/snapshot.cc diff --git a/java/Makefile b/java/Makefile index 97f0b0244d..8d75ee5e5a 100644 --- a/java/Makefile +++ b/java/Makefile @@ -32,6 +32,7 @@ NATIVE_JAVA_CLASSES = org.rocksdb.AbstractComparator\ org.rocksdb.TransactionLogIterator\ org.rocksdb.TtlDB\ org.rocksdb.VectorMemTableConfig\ + org.rocksdb.Snapshot\ org.rocksdb.StringAppendOperator\ org.rocksdb.WriteBatch\ org.rocksdb.WriteBatch.Handler\ diff --git a/java/org/rocksdb/Snapshot.java b/java/org/rocksdb/Snapshot.java index 5817a8b44c..1842dddd36 100644 --- a/java/org/rocksdb/Snapshot.java +++ b/java/org/rocksdb/Snapshot.java @@ -14,6 +14,17 @@ public class Snapshot extends RocksObject { nativeHandle_ = nativeHandle; } + /** + * Return the associated sequence number; + * + * @return the associated sequence number of + * this snapshot. + */ + public long getSequenceNumber() { + assert(isInitialized()); + return getSequenceNumber(nativeHandle_); + } + /** * Dont release C++ Snapshot pointer. The pointer * to the snapshot is released by the database @@ -21,4 +32,6 @@ public class Snapshot extends RocksObject { */ @Override protected void disposeInternal() { } + + private native long getSequenceNumber(long handle); } diff --git a/java/org/rocksdb/test/SnapshotTest.java b/java/org/rocksdb/test/SnapshotTest.java index b6dd2a3604..4aeef44eff 100644 --- a/java/org/rocksdb/test/SnapshotTest.java +++ b/java/org/rocksdb/test/SnapshotTest.java @@ -35,6 +35,8 @@ public class SnapshotTest { db.put("key".getBytes(), "value".getBytes()); // Get new Snapshot of database Snapshot snapshot = db.getSnapshot(); + assertThat(snapshot.getSequenceNumber()).isGreaterThan(0); + assertThat(snapshot.getSequenceNumber()).isEqualTo(1); readOptions = new ReadOptions(); // set snapshot in ReadOptions readOptions.setSnapshot(snapshot); diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc index eaa5603ead..54e449f538 100644 --- a/java/rocksjni/rocksjni.cc +++ b/java/rocksjni/rocksjni.cc @@ -6,18 +6,18 @@ // This file implements the "bridge" between Java and C++ and enables // calling c++ rocksdb::DB methods from Java side. +#include #include #include -#include #include #include #include #include "include/org_rocksdb_RocksDB.h" -#include "rocksjni/portal.h" #include "rocksdb/db.h" #include "rocksdb/cache.h" #include "rocksdb/types.h" +#include "rocksjni/portal.h" ////////////////////////////////////////////////////////////////////////////// // rocksdb::DB::Open diff --git a/java/rocksjni/snapshot.cc b/java/rocksjni/snapshot.cc new file mode 100644 index 0000000000..cd10c97c81 --- /dev/null +++ b/java/rocksjni/snapshot.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2014, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// +// This file implements the "bridge" between Java and C++. + +#include +#include +#include + +#include "include/org_rocksdb_Snapshot.h" +#include "rocksdb/db.h" +#include "rocksjni/portal.h" + +/* + * Class: org_rocksdb_Snapshot + * Method: getSequenceNumber + * Signature: (J)J + */ +jlong Java_org_rocksdb_Snapshot_getSequenceNumber(JNIEnv* env, + jobject jobj, jlong jsnapshot_handle) { + auto* snapshot = reinterpret_cast( + jsnapshot_handle); + return snapshot->GetSequenceNumber(); +}