Even if the key is the same in the same database, if the Column Families are different, it will be possible to register / reference / delete. The official documentation said, "Provides a way to logically partition the database." You can think of it as a concept similar to namespaces. The features are as follows (the official is Google Translate, so please refer to the official document correctly).
Atomic operations on different Column Families This means that Write ({cf1, key1, value1}, {cf2, key2, value2}) can be done atomically. cf1 and cf2 are the specifications of Column Families.
Consistent view across Column Families in the database It is not well understood
Ability to configure different Column Families individually It is not well understood
You can add and drop new Column Families. Both operations are fairly fast As described
Official documentation https://github.com/facebook/rocksdb/wiki/Column-Families
I honestly don't know. However, it may be useful someday if you know that there is such a function. .. ..
public class SampleCulmunFamily {
public void execute() throws Exception {
//DB creation
try (final RocksDB db = RocksDB.open("sample")) {
//Creating a column family (multiple ColumnFamilyDescriptor first
//When creating multiple columnfamily, create List of ColumnFamilyDescriptor and db.You can pass it to open
try (final ColumnFamilyHandle columnFamilyHandle = db.createColumnFamily(
new ColumnFamilyDescriptor("new_cf".getBytes(),
new ColumnFamilyOptions()))) {
}
}
//Creating a DB and two Culmun Family
final List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
//Even if you don't specify CulmunFamily, a CulmunFamily called default is created behind the scenes.
//Therefore, this time, default and new_You will create two Culmun Family called cf.
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions()));
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(
"new_cf".getBytes(), new ColumnFamilyOptions()));
final List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
try (final DBOptions options = new DBOptions();
final RocksDB db = RocksDB.open("sample",
columnFamilyDescriptors, columnFamilyHandles)) {
//Get Culumn Family identifier
ColumnFamilyHandle defaultColumnFamily = columnFamilyHandles.get(0);
ColumnFamilyHandle newColumnFamily = columnFamilyHandles.get(1);
try {
//Register with the same key. Use the identifier to sort the registration destination.
db.put(defaultColumnFamily, new WriteOptions(),
"key".getBytes(), "default_value".getBytes());
db.put(newColumnFamily, new WriteOptions(),
"key".getBytes(), "new_cf_value".getBytes());
//reference
System.out.println(new String(db.get(defaultColumnFamily, "key".getBytes())));
System.out.println(new String(db.get(newColumnFamily, "key".getBytes())));
//Delete
db.delete(defaultColumnFamily, "key".getBytes());
db.delete(newColumnFamily, "key".getBytes());
//Delete column family
db.dropColumnFamily(newColumnFamily);
} finally {
for (final ColumnFamilyHandle handle : columnFamilyHandles) {
handle.close();
}
}
}
}
}
Recommended Posts