提交 cb5c3159 编写于 作者: F fyrz

[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
上级 ea189b32
......@@ -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\
......
......@@ -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);
}
......@@ -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);
......
......@@ -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
......
// 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();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册