[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
This commit is contained in:
fyrz 2015-01-30 21:05:45 +01:00
parent ea189b320c
commit cb5c3159f0
5 changed files with 44 additions and 2 deletions

View File

@ -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\

View File

@ -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);
}

View File

@ -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);

View File

@ -6,18 +6,18 @@
// This file implements the "bridge" between Java and C++ and enables
// calling c++ rocksdb::DB methods from Java side.
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include <memory>
#include <string>
#include <vector>
#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

26
java/rocksjni/snapshot.cc Normal file
View File

@ -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 <jni.h>
#include <stdio.h>
#include <stdlib.h>
#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<rocksdb::Snapshot*>(
jsnapshot_handle);
return snapshot->GetSequenceNumber();
}