fix assert error while db.getDefaultColumnFamily().getDescriptor() (#6006)

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

Differential Revision: D19031448

fbshipit-source-id: 2420c45e835bda0e552e919b1b63708472b91538
main
Jermy Li 5 years ago committed by Facebook Github Bot
parent 741decfe37
commit 72ee067b90
  1. 8
      java/src/main/java/org/rocksdb/ColumnFamilyHandle.java
  2. 1
      java/src/test/java/org/rocksdb/ColumnFamilyTest.java

@ -32,6 +32,7 @@ public class ColumnFamilyHandle extends RocksObject {
* @throws RocksDBException if an error occurs whilst retrieving the name. * @throws RocksDBException if an error occurs whilst retrieving the name.
*/ */
public byte[] getName() throws RocksDBException { public byte[] getName() throws RocksDBException {
assert(isOwningHandle() || isDefaultColumnFamily());
return getName(nativeHandle_); return getName(nativeHandle_);
} }
@ -41,6 +42,7 @@ public class ColumnFamilyHandle extends RocksObject {
* @return the ID of the Column Family. * @return the ID of the Column Family.
*/ */
public int getID() { public int getID() {
assert(isOwningHandle() || isDefaultColumnFamily());
return getID(nativeHandle_); return getID(nativeHandle_);
} }
@ -59,7 +61,7 @@ public class ColumnFamilyHandle extends RocksObject {
* descriptor. * descriptor.
*/ */
public ColumnFamilyDescriptor getDescriptor() throws RocksDBException { public ColumnFamilyDescriptor getDescriptor() throws RocksDBException {
assert(isOwningHandle()); assert(isOwningHandle() || isDefaultColumnFamily());
return getDescriptor(nativeHandle_); return getDescriptor(nativeHandle_);
} }
@ -91,6 +93,10 @@ public class ColumnFamilyHandle extends RocksObject {
} }
} }
protected boolean isDefaultColumnFamily() {
return nativeHandle_ == rocksDB_.getDefaultColumnFamily().nativeHandle_;
}
/** /**
* <p>Deletes underlying C++ iterator pointer.</p> * <p>Deletes underlying C++ iterator pointer.</p>
* *

@ -75,6 +75,7 @@ public class ColumnFamilyTest {
assertThat(cfh.getName()).isEqualTo("default".getBytes(UTF_8)); assertThat(cfh.getName()).isEqualTo("default".getBytes(UTF_8));
assertThat(cfh.getID()).isEqualTo(0); assertThat(cfh.getID()).isEqualTo(0);
assertThat(cfh.getDescriptor().getName()).isEqualTo("default".getBytes(UTF_8));
final byte[] key = "key".getBytes(); final byte[] key = "key".getBytes();
final byte[] value = "value".getBytes(); final byte[] value = "value".getBytes();

Loading…
Cancel
Save