Last active
September 23, 2019 16:18
-
-
Save KKcorps/d4caea39cb7d6190cbf26e31dce0ea47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestRocksDB { | |
public static void main(String[] args) throws Exception { | |
RocksDB.loadLibrary(); | |
String previousIntColumnFamily = "previousInt"; | |
byte[] previousIntColumnFamilyBA = previousIntColumnFamily.getBytes(StandardCharsets.UTF_8); | |
String nextIntcolumnFamily = "nextInt"; | |
byte[] nextIntcolumnFamilyBA = nextIntcolumnFamily.getBytes(StandardCharsets.UTF_8); | |
try (final ColumnFamilyOptions cfOpts = new ColumnFamilyOptions().optimizeUniversalStyleCompaction()) { | |
// list of column family descriptors, first entry must always be default column family | |
final List<ColumnFamilyDescriptor> cfDescriptors = Arrays.asList( | |
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOpts), | |
new ColumnFamilyDescriptor(previousIntColumnFamilyBA, cfOpts), | |
new ColumnFamilyDescriptor(nextIntcolumnFamilyBA, cfOpts) | |
); | |
// a list which will hold the handles for the column families once the db is opened | |
final List<ColumnFamilyHandle> columnFamilyHandleList = new ArrayList<>(); | |
String dbPath = "/Users/abc/job_127b2b84f80b368b8edfe02b2762d10d_op"+ | |
"_StreamFlatMap_11f49afc24b1cce91c7169b1e5140284__1_1__uuid_19b333d3-3278-4e51-93c8-ac6c3608507c/db/"; | |
try (final DBOptions options = new DBOptions() | |
.setCreateIfMissing(true) | |
.setCreateMissingColumnFamilies(true); | |
final RocksDB db = RocksDB.open(options, dbPath, cfDescriptors, columnFamilyHandleList)) { | |
try { | |
for(ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList){ | |
byte[] name = columnFamilyHandle.getName(); | |
System.out.write(name); | |
} | |
}finally { | |
// NOTE frees the column family handles before freeing the db | |
for (final ColumnFamilyHandle columnFamilyHandle : | |
columnFamilyHandleList) { | |
columnFamilyHandle.close(); | |
} | |
} | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment