mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-21 22:33:17 +08:00
java-bindings: Add function to disable/enable/resize DirectBuffer
This commit is contained in:
parent
5cefb27fe2
commit
738cd82a85
@ -33,6 +33,8 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
class DirectBufferPool {
|
class DirectBufferPool {
|
||||||
static final DirectBufferPool __instance = new DirectBufferPool();
|
static final DirectBufferPool __instance = new DirectBufferPool();
|
||||||
|
|
||||||
|
// When tuning this, make sure that the size of the buffer,
|
||||||
|
// is always greater than the maximum size KV allowed by FDB.
|
||||||
static private final int DEFAULT_NUM_BUFFERS = 128;
|
static private final int DEFAULT_NUM_BUFFERS = 128;
|
||||||
static private final int DEFAULT_BUFFER_SIZE = 1024 * 512;
|
static private final int DEFAULT_BUFFER_SIZE = 1024 * 512;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ class FDBTransaction extends NativeObjectWrapper implements Transaction, OptionC
|
|||||||
private final TransactionOptions options;
|
private final TransactionOptions options;
|
||||||
|
|
||||||
private boolean transactionOwner;
|
private boolean transactionOwner;
|
||||||
|
private boolean enableDirectBufferQueries = false;
|
||||||
|
|
||||||
public final ReadTransaction snapshot;
|
public final ReadTransaction snapshot;
|
||||||
|
|
||||||
@ -283,6 +284,17 @@ class FDBTransaction extends NativeObjectWrapper implements Transaction, OptionC
|
|||||||
return this.getEstimatedRangeSizeBytes(range.begin, range.end);
|
return this.getEstimatedRangeSizeBytes(range.begin, range.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
// Feature Options
|
||||||
|
///////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use DirectByteBuffers to fetch getRange() results.
|
||||||
|
*/
|
||||||
|
public void setDirectBufferQueryEnabled(boolean v) {
|
||||||
|
enableDirectBufferQueries = v;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// getRange -> KeySelectors
|
// getRange -> KeySelectors
|
||||||
///////////////////
|
///////////////////
|
||||||
@ -373,7 +385,7 @@ class FDBTransaction extends NativeObjectWrapper implements Transaction, OptionC
|
|||||||
return new FutureResults(Transaction_getRange(
|
return new FutureResults(Transaction_getRange(
|
||||||
getPtr(), begin.getKey(), begin.orEqual(), begin.getOffset(),
|
getPtr(), begin.getKey(), begin.orEqual(), begin.getOffset(),
|
||||||
end.getKey(), end.orEqual(), end.getOffset(), rowLimit, targetBytes,
|
end.getKey(), end.orEqual(), end.getOffset(), rowLimit, targetBytes,
|
||||||
streamingMode, iteration, isSnapshot, reverse), executor);
|
streamingMode, iteration, isSnapshot, reverse), enableDirectBufferQueries, executor);
|
||||||
} finally {
|
} finally {
|
||||||
pointerReadLock.unlock();
|
pointerReadLock.unlock();
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,10 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
class FutureResults extends NativeFuture<RangeResultInfo> {
|
class FutureResults extends NativeFuture<RangeResultInfo> {
|
||||||
FutureResults(long cPtr, Executor executor) {
|
FutureResults(long cPtr, boolean enableDirectBufferQueries, Executor executor) {
|
||||||
super(cPtr);
|
super(cPtr);
|
||||||
registerMarshalCallback(executor);
|
registerMarshalCallback(executor);
|
||||||
|
this.enableDirectBufferQueries = enableDirectBufferQueries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +47,9 @@ class FutureResults extends NativeFuture<RangeResultInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RangeResult getResults() {
|
public RangeResult getResults() {
|
||||||
DirectBufferIterator directIterator = new DirectBufferIterator();
|
DirectBufferIterator directIterator = enableDirectBufferQueries
|
||||||
|
? new DirectBufferIterator()
|
||||||
|
: null;
|
||||||
try {
|
try {
|
||||||
pointerReadLock.lock();
|
pointerReadLock.lock();
|
||||||
if (directIterator.getBuffer() != null) {
|
if (directIterator.getBuffer() != null) {
|
||||||
@ -61,6 +64,8 @@ class FutureResults extends NativeFuture<RangeResultInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean enableDirectBufferQueries = false;
|
||||||
|
|
||||||
private native RangeResult FutureResults_get(long cPtr) throws FDBException;
|
private native RangeResult FutureResults_get(long cPtr) throws FDBException;
|
||||||
private native void FutureResults_getDirect(long cPtr, ByteBuffer buffer, int capacity)
|
private native void FutureResults_getDirect(long cPtr, ByteBuffer buffer, int capacity)
|
||||||
throws FDBException;
|
throws FDBException;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user