Skip to content

Commit

Permalink
fix assert error while db.getDefaultColumnFamily().getDescriptor() (f…
Browse files Browse the repository at this point in the history
…acebook#6006)

Summary:
Threw assert error at assert(isOwningHandle()) in ColumnFamilyHandle.getDescriptor(),
because default CF don't own a handle, due to [RocksDB.getDefaultColumnFamily()](https://github.com/facebook/rocksdb/blob/3a408eeae95614150ac930fc7f244524ed8c6f1c/java/src/main/java/org/rocksdb/RocksDB.java#L3702) called cfHandle.disOwnNativeHandle().
Pull Request resolved: facebook#6006

Differential Revision: D19031448

fbshipit-source-id: 2420c45e835bda0e552e919b1b63708472b91538
  • Loading branch information
javeme authored and facebook-github-bot committed Feb 27, 2020
1 parent 741decf commit 72ee067
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion java/src/main/java/org/rocksdb/ColumnFamilyHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ColumnFamilyHandle extends RocksObject {
* @throws RocksDBException if an error occurs whilst retrieving the name.
*/
public byte[] getName() throws RocksDBException {
assert(isOwningHandle() || isDefaultColumnFamily());
return getName(nativeHandle_);
}

Expand All @@ -41,6 +42,7 @@ public byte[] getName() throws RocksDBException {
* @return the ID of the Column Family.
*/
public int getID() {
assert(isOwningHandle() || isDefaultColumnFamily());
return getID(nativeHandle_);
}

Expand All @@ -59,7 +61,7 @@ public int getID() {
* descriptor.
*/
public ColumnFamilyDescriptor getDescriptor() throws RocksDBException {
assert(isOwningHandle());
assert(isOwningHandle() || isDefaultColumnFamily());
return getDescriptor(nativeHandle_);
}

Expand Down Expand Up @@ -91,6 +93,10 @@ public int hashCode() {
}
}

protected boolean isDefaultColumnFamily() {
return nativeHandle_ == rocksDB_.getDefaultColumnFamily().nativeHandle_;
}

/**
* <p>Deletes underlying C++ iterator pointer.</p>
*
Expand Down
1 change: 1 addition & 0 deletions java/src/test/java/org/rocksdb/ColumnFamilyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void defaultColumnFamily() throws RocksDBException {

assertThat(cfh.getName()).isEqualTo("default".getBytes(UTF_8));
assertThat(cfh.getID()).isEqualTo(0);
assertThat(cfh.getDescriptor().getName()).isEqualTo("default".getBytes(UTF_8));

final byte[] key = "key".getBytes();
final byte[] value = "value".getBytes();
Expand Down

0 comments on commit 72ee067

Please sign in to comment.