Skip to content

Commit

Permalink
Deprecate WriteBatch.remove() and use the new style delete() (#9256)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #9256

Reviewed By: mrambacher

Differential Revision: D32971447

Pulled By: jay-zhuang

fbshipit-source-id: 6954d7287229a8c776092bd82af3a8a8cd92b35e
  • Loading branch information
javeme authored and facebook-github-bot committed Dec 10, 2021
1 parent 653c392 commit c39a808
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 59 deletions.
4 changes: 2 additions & 2 deletions java/rocksjni/write_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions java/rocksjni/write_batch_with_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
56 changes: 35 additions & 21 deletions java/src/main/java/org/rocksdb/AbstractWriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,21 @@ public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key)
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);
Expand All @@ -65,8 +79,8 @@ public void put(ByteBuffer key, ByteBuffer value) throws RocksDBException {
}

@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_);
Expand All @@ -85,6 +99,19 @@ public void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key)
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 {
Expand All @@ -110,19 +137,6 @@ public void deleteRange(ColumnFamilyHandle columnFamilyHandle,
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);
Expand Down Expand Up @@ -184,13 +198,13 @@ abstract void delete(final long handle, final byte[] key,
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,
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/org/rocksdb/WriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ final native void putDirect(final long handle, final ByteBuffer key, final int k
@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,
Expand Down
88 changes: 57 additions & 31 deletions java/src/main/java/org/rocksdb/WriteBatchInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +52,7 @@ void put(ColumnFamilyHandle columnFamilyHandle,
* 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
Expand All @@ -66,7 +66,7 @@ void put(ColumnFamilyHandle columnFamilyHandle,
* 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;

/**
Expand All @@ -90,8 +90,8 @@ void put(ColumnFamilyHandle columnFamilyHandle, ByteBuffer key, ByteBuffer value
* 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>
Expand All @@ -114,7 +114,31 @@ void merge(ColumnFamilyHandle columnFamilyHandle,
* @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;

/**
Expand All @@ -132,7 +156,28 @@ void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key)
* @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;

/**
Expand Down Expand Up @@ -182,27 +227,8 @@ void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key)
* 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.,
Expand Down Expand Up @@ -237,8 +263,8 @@ void singleDelete(final ColumnFamilyHandle columnFamilyHandle,
* 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
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/org/rocksdb/WriteBatchWithIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ final native void putDirect(final long handle, final ByteBuffer key, final int k
@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
Expand Down
2 changes: 1 addition & 1 deletion java/src/test/java/org/rocksdb/WriteBatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void multipleBatchOperationsDirect()

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

Expand Down

0 comments on commit c39a808

Please sign in to comment.