Deprecate WriteBatch.remove() and use the new style delete() (#9256)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9256

Reviewed By: mrambacher

Differential Revision: D32971447

Pulled By: jay-zhuang

fbshipit-source-id: 6954d7287229a8c776092bd82af3a8a8cd92b35e
main
Jermy Li 3 years ago committed by Facebook GitHub Bot
parent 653c392e47
commit c39a808cb6
  1. 4
      java/rocksjni/write_batch.cc
  2. 4
      java/rocksjni/write_batch_with_index.cc
  3. 56
      java/src/main/java/org/rocksdb/AbstractWriteBatch.java
  4. 2
      java/src/main/java/org/rocksdb/WriteBatch.java
  5. 88
      java/src/main/java/org/rocksdb/WriteBatchInterface.java
  6. 2
      java/src/main/java/org/rocksdb/WriteBatchWithIndex.java
  7. 2
      java/src/test/java/org/rocksdb/WriteBatchTest.java

@ -363,10 +363,10 @@ void Java_org_rocksdb_WriteBatch_singleDelete__J_3BIJ(JNIEnv* env, jobject jobj,
/*
* Class: org_rocksdb_WriteBatch
* Method: removeDirect
* Method: deleteDirect
* Signature: (JLjava/nio/ByteBuffer;IIJ)V
*/
void Java_org_rocksdb_WriteBatch_removeDirect(JNIEnv* env, jobject /*jobj*/,
void Java_org_rocksdb_WriteBatch_deleteDirect(JNIEnv* env, jobject /*jobj*/,
jlong jwb_handle, jobject jkey,
jint jkey_offset, jint jkey_len,
jlong jcf_handle) {

@ -301,10 +301,10 @@ void Java_org_rocksdb_WriteBatchWithIndex_singleDelete__J_3BIJ(
/*
* Class: org_rocksdb_WriteBatchWithIndex
* Method: removeDirect
* Method: deleteDirect
* Signature: (JLjava/nio/ByteBuffer;IIJ)V
*/
void Java_org_rocksdb_WriteBatchWithIndex_removeDirect(
void Java_org_rocksdb_WriteBatchWithIndex_deleteDirect(
JNIEnv* env, jobject /*jobj*/, jlong jwb_handle, jobject jkey,
jint jkey_offset, jint jkey_len, jlong jcf_handle) {
auto* wb = reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatch*>(jwb_handle);

@ -56,7 +56,21 @@ public abstract class AbstractWriteBatch extends RocksObject
delete(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
}
public void put(ByteBuffer key, ByteBuffer value) throws RocksDBException {
@Override
@Deprecated
public void remove(final ByteBuffer key) throws RocksDBException {
this.delete(key);
}
@Override
@Deprecated
public void remove(ColumnFamilyHandle columnFamilyHandle, final ByteBuffer key)
throws RocksDBException {
this.delete(columnFamilyHandle, key);
}
@Override
public void put(final ByteBuffer key, final ByteBuffer value) throws RocksDBException {
assert key.isDirect() && value.isDirect();
putDirect(nativeHandle_, key, key.position(), key.remaining(), value, value.position(),
value.remaining(), 0);
@ -65,8 +79,8 @@ public abstract class AbstractWriteBatch extends RocksObject
}
@Override
public void put(ColumnFamilyHandle columnFamilyHandle, ByteBuffer key, ByteBuffer value)
throws RocksDBException {
public void put(ColumnFamilyHandle columnFamilyHandle, final ByteBuffer key,
final ByteBuffer value) throws RocksDBException {
assert key.isDirect() && value.isDirect();
putDirect(nativeHandle_, key, key.position(), key.remaining(), value, value.position(),
value.remaining(), columnFamilyHandle.nativeHandle_);
@ -85,6 +99,19 @@ public abstract class AbstractWriteBatch extends RocksObject
delete(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
}
@Override
public void delete(final ByteBuffer key) throws RocksDBException {
deleteDirect(nativeHandle_, key, key.position(), key.remaining(), 0);
key.position(key.limit());
}
@Override
public void delete(ColumnFamilyHandle columnFamilyHandle, final ByteBuffer key)
throws RocksDBException {
deleteDirect(
nativeHandle_, key, key.position(), key.remaining(), columnFamilyHandle.nativeHandle_);
key.position(key.limit());
}
@Override
public void singleDelete(byte[] key) throws RocksDBException {
@ -110,19 +137,6 @@ public abstract class AbstractWriteBatch extends RocksObject
columnFamilyHandle.nativeHandle_);
}
public void remove(ByteBuffer key) throws RocksDBException {
removeDirect(nativeHandle_, key, key.position(), key.remaining(), 0);
key.position(key.limit());
}
@Override
public void remove(ColumnFamilyHandle columnFamilyHandle, ByteBuffer key)
throws RocksDBException {
removeDirect(
nativeHandle_, key, key.position(), key.remaining(), columnFamilyHandle.nativeHandle_);
key.position(key.limit());
}
@Override
public void putLogData(byte[] blob) throws RocksDBException {
putLogData(nativeHandle_, blob, blob.length);
@ -184,13 +198,13 @@ public abstract class AbstractWriteBatch extends RocksObject
abstract void delete(final long handle, final byte[] key,
final int keyLen, final long cfHandle) throws RocksDBException;
abstract void singleDelete(final long handle, final byte[] key,
final int keyLen) throws RocksDBException;
abstract void singleDelete(final long handle, final byte[] key, final int keyLen)
throws RocksDBException;
abstract void singleDelete(final long handle, final byte[] key,
final int keyLen, final long cfHandle) throws RocksDBException;
abstract void singleDelete(final long handle, final byte[] key, final int keyLen,
final long cfHandle) throws RocksDBException;
abstract void removeDirect(final long handle, final ByteBuffer key, final int keyOffset,
abstract void deleteDirect(final long handle, final ByteBuffer key, final int keyOffset,
final int keyLength, final long cfHandle) throws RocksDBException;
abstract void deleteRange(final long handle, final byte[] beginKey, final int beginKeyLen,

@ -243,7 +243,7 @@ public class WriteBatch extends AbstractWriteBatch {
@Override final native void singleDelete(final long handle, final byte[] key,
final int keyLen, final long cfHandle) throws RocksDBException;
@Override
final native void removeDirect(final long handle, final ByteBuffer key, final int keyOffset,
final native void deleteDirect(final long handle, final ByteBuffer key, final int keyOffset,
final int keyLength, final long cfHandle) throws RocksDBException;
@Override
final native void deleteRange(final long handle, final byte[] beginKey, final int beginKeyLen,

@ -39,8 +39,8 @@ public interface WriteBatchInterface {
* @param value the value associated with the specified key.
* @throws RocksDBException thrown if error happens in underlying native library.
*/
void put(ColumnFamilyHandle columnFamilyHandle,
byte[] key, byte[] value) throws RocksDBException;
void put(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)
throws RocksDBException;
/**
* <p>Store the mapping "key-&gt;value" within given column
@ -52,7 +52,7 @@ public interface WriteBatchInterface {
* Supports direct buffer only.
* @throws RocksDBException
*/
void put(ByteBuffer key, ByteBuffer value) throws RocksDBException;
void put(final ByteBuffer key, final ByteBuffer value) throws RocksDBException;
/**
* <p>Store the mapping "key-&gt;value" within given column
@ -66,7 +66,7 @@ public interface WriteBatchInterface {
* Supports direct buffer only.
* @throws RocksDBException
*/
void put(ColumnFamilyHandle columnFamilyHandle, ByteBuffer key, ByteBuffer value)
void put(ColumnFamilyHandle columnFamilyHandle, final ByteBuffer key, final ByteBuffer value)
throws RocksDBException;
/**
@ -90,8 +90,8 @@ public interface WriteBatchInterface {
* the specified key.
* @throws RocksDBException thrown if error happens in underlying native library.
*/
void merge(ColumnFamilyHandle columnFamilyHandle,
byte[] key, byte[] value) throws RocksDBException;
void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)
throws RocksDBException;
/**
* <p>If the database contains a mapping for "key", erase it. Else do nothing.</p>
@ -114,7 +114,31 @@ public interface WriteBatchInterface {
* @throws RocksDBException thrown if error happens in underlying native library.
*/
@Deprecated
void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key)
void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException;
/**
* <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param key Key to delete within database. It is using position and limit.
* Supports direct buffer only.
*
* @deprecated Use {@link #delete(ByteBuffer)}
* @throws RocksDBException thrown if error happens in underlying native library.
*/
@Deprecated void remove(final ByteBuffer key) throws RocksDBException;
/**
* <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
* @param key Key to delete within database. It is using position and limit.
* Supports direct buffer only.
*
* @deprecated Use {@link #delete(ColumnFamilyHandle, ByteBuffer)}
* @throws RocksDBException thrown if error happens in underlying native library.
*/
@Deprecated
void remove(ColumnFamilyHandle columnFamilyHandle, final ByteBuffer key)
throws RocksDBException;
/**
@ -132,7 +156,28 @@ public interface WriteBatchInterface {
* @param key Key to delete within database
* @throws RocksDBException thrown if error happens in underlying native library.
*/
void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key)
void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException;
/**
* <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param key Key to delete within database. It is using position and limit.
* Supports direct buffer only.
*
* @throws RocksDBException thrown if error happens in underlying native library.
*/
void delete(final ByteBuffer key) throws RocksDBException;
/**
* <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
* @param key Key to delete within database. It is using position and limit.
* Supports direct buffer only.
*
* @throws RocksDBException thrown if error happens in underlying native library.
*/
void delete(ColumnFamilyHandle columnFamilyHandle, final ByteBuffer key)
throws RocksDBException;
/**
@ -182,27 +227,8 @@ public interface WriteBatchInterface {
* native library.
*/
@Experimental("Performance optimization for a very specific workload")
void singleDelete(final ColumnFamilyHandle columnFamilyHandle,
final byte[] key) throws RocksDBException;
/**
* <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param key Key to delete within database. It is using position and limit.
* Supports direct buffer only.
* @throws RocksDBException
*/
void remove(ByteBuffer key) throws RocksDBException;
/**
* <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
* @param key Key to delete within database. It is using position and limit.
* Supports direct buffer only.
* @throws RocksDBException
*/
void remove(ColumnFamilyHandle columnFamilyHandle, ByteBuffer key) throws RocksDBException;
void singleDelete(final ColumnFamilyHandle columnFamilyHandle, final byte[] key)
throws RocksDBException;
/**
* Removes the database entries in the range ["beginKey", "endKey"), i.e.,
@ -237,8 +263,8 @@ public interface WriteBatchInterface {
* Last key to delete within database (excluded)
* @throws RocksDBException thrown if error happens in underlying native library.
*/
void deleteRange(ColumnFamilyHandle columnFamilyHandle, byte[] beginKey,
byte[] endKey) throws RocksDBException;
void deleteRange(ColumnFamilyHandle columnFamilyHandle, byte[] beginKey, byte[] endKey)
throws RocksDBException;
/**
* Append a blob of arbitrary size to the records in this batch. The blob will

@ -318,7 +318,7 @@ public class WriteBatchWithIndex extends AbstractWriteBatch {
@Override final native void singleDelete(final long handle, final byte[] key,
final int keyLen, final long cfHandle) throws RocksDBException;
@Override
final native void removeDirect(final long handle, final ByteBuffer key, final int keyOffset,
final native void deleteDirect(final long handle, final ByteBuffer key, final int keyOffset,
final int keyLength, final long cfHandle) throws RocksDBException;
// DO NOT USE - `WriteBatchWithIndex::deleteRange` is not yet supported
@Override

@ -100,7 +100,7 @@ public class WriteBatchTest {
key.clear();
key.put("box".getBytes("US-ASCII")).flip();
batch.remove(key);
batch.delete(key);
assertThat(key.position()).isEqualTo(3);
assertThat(key.limit()).isEqualTo(3);

Loading…
Cancel
Save