mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Summary: 1. Move disOwnNativeHandle() function from RocksDB to RocksObject to allow other RocksObject to use disOwnNativeHandle() when its ownership of native handle has been transferred. 2. RocksObject now has an abstract implementation of dispose(), which does the following two things. First, it checks whether both isOwningNativeHandle() and isInitialized() return true. If so, it will call the protected abstract function dispose0(), which all the subclasses of RocksObject should implement. Second, it sets nativeHandle_ = 0. This redesign ensure all subclasses of RocksObject have the same dispose behavior. 3. All subclasses of RocksObject now should implement dispose0() instead of dispose(), and dispose0() will be called only when isInitialized() returns true. Test Plan: make rocksdbjava make jtest Reviewers: dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett, haobo Reviewed By: haobo Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D18801
100 lines
3.3 KiB
Java
100 lines
3.3 KiB
Java
// 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.
|
|
|
|
package org.rocksdb;
|
|
|
|
/**
|
|
* Options that control write operations.
|
|
*
|
|
* Note that developers should call WriteOptions.dispose() to release the
|
|
* c++ side memory before a WriteOptions instance runs out of scope.
|
|
*/
|
|
public class WriteOptions extends RocksObject {
|
|
public WriteOptions() {
|
|
super();
|
|
newWriteOptions();
|
|
}
|
|
|
|
@Override protected void disposeInternal() {
|
|
assert(isInitialized());
|
|
disposeInternal(nativeHandle_);
|
|
}
|
|
|
|
/**
|
|
* If true, the write will be flushed from the operating system
|
|
* buffer cache (by calling WritableFile::Sync()) before the write
|
|
* is considered complete. If this flag is true, writes will be
|
|
* slower.
|
|
*
|
|
* If this flag is false, and the machine crashes, some recent
|
|
* writes may be lost. Note that if it is just the process that
|
|
* crashes (i.e., the machine does not reboot), no writes will be
|
|
* lost even if sync==false.
|
|
*
|
|
* In other words, a DB write with sync==false has similar
|
|
* crash semantics as the "write()" system call. A DB write
|
|
* with sync==true has similar crash semantics to a "write()"
|
|
* system call followed by "fdatasync()".
|
|
*
|
|
* Default: false
|
|
*
|
|
* @param flag a boolean flag to indicate whether a write
|
|
* should be synchronized.
|
|
* @return the instance of the current WriteOptions.
|
|
*/
|
|
public WriteOptions setSync(boolean flag) {
|
|
setSync(nativeHandle_, flag);
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* If true, the write will be flushed from the operating system
|
|
* buffer cache (by calling WritableFile::Sync()) before the write
|
|
* is considered complete. If this flag is true, writes will be
|
|
* slower.
|
|
*
|
|
* If this flag is false, and the machine crashes, some recent
|
|
* writes may be lost. Note that if it is just the process that
|
|
* crashes (i.e., the machine does not reboot), no writes will be
|
|
* lost even if sync==false.
|
|
*
|
|
* In other words, a DB write with sync==false has similar
|
|
* crash semantics as the "write()" system call. A DB write
|
|
* with sync==true has similar crash semantics to a "write()"
|
|
* system call followed by "fdatasync()".
|
|
*/
|
|
public boolean sync() {
|
|
return sync(nativeHandle_);
|
|
}
|
|
|
|
/**
|
|
* If true, writes will not first go to the write ahead log,
|
|
* and the write may got lost after a crash.
|
|
*
|
|
* @param flag a boolean flag to specify whether to disable
|
|
* write-ahead-log on writes.
|
|
* @return the instance of the current WriteOptions.
|
|
*/
|
|
public WriteOptions setDisableWAL(boolean flag) {
|
|
setDisableWAL(nativeHandle_, flag);
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* If true, writes will not first go to the write ahead log,
|
|
* and the write may got lost after a crash.
|
|
*/
|
|
public boolean disableWAL() {
|
|
return disableWAL(nativeHandle_);
|
|
}
|
|
|
|
private native void newWriteOptions();
|
|
private native void setSync(long handle, boolean flag);
|
|
private native boolean sync(long handle);
|
|
private native void setDisableWAL(long handle, boolean flag);
|
|
private native boolean disableWAL(long handle);
|
|
private native void disposeInternal(long handle);
|
|
}
|