Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 28 additions & 14 deletions java/src/main/java/org/rocksdb/AbstractWriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key)
delete(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
}

@Override
@Deprecated
public void remove(ByteBuffer key) throws RocksDBException {
this.delete(key);
}

@Override
@Deprecated
public void remove(ColumnFamilyHandle columnFamilyHandle, ByteBuffer key)
throws RocksDBException {
this.delete(columnFamilyHandle, key);
}

@Override
public void put(ByteBuffer key, ByteBuffer value) throws RocksDBException {
assert key.isDirect() && value.isDirect();
putDirect(nativeHandle_, key, key.position(), key.remaining(), value, value.position(),
Expand Down Expand Up @@ -85,6 +99,19 @@ public void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key)
delete(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
}

@Override
public void delete(ByteBuffer key) throws RocksDBException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mark the parameters as final please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

deleteDirect(nativeHandle_, key, key.position(), key.remaining(), 0);
key.position(key.limit());
}

@Override
public void delete(ColumnFamilyHandle columnFamilyHandle, 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 @@ -190,7 +204,7 @@ abstract void singleDelete(final long handle, final byte[] key,
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
65 changes: 46 additions & 19 deletions java/src/main/java/org/rocksdb/WriteBatchInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ void merge(ColumnFamilyHandle columnFamilyHandle,
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(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, ByteBuffer key) throws RocksDBException;

/**
* <p>If the database contains a mapping for "key", erase it. Else do nothing.</p>
*
Expand All @@ -135,6 +160,27 @@ void remove(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(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, ByteBuffer key) throws RocksDBException;

/**
* Remove the database entry for {@code key}. Requires that the key exists
* and was not overwritten. It is not an error if the key did not exist
Expand Down Expand Up @@ -185,25 +231,6 @@ void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key)
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;

/**
* Removes the database entries in the range ["beginKey", "endKey"), i.e.,
* including "beginKey" and excluding "endKey". a non-OK status on error. It
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