public static void main(String[] args) throws RocksDBException { RocksDbReadingTool tool = new RocksDbReadingTool(); OptionSet options = tool.parser().parse(args); MapConfig config = tool.loadConfig(options); String path = tool.getDbPath(); String dbName = tool.getDbName(); RocksDbKeyValueReader kvReader = new RocksDbKeyValueReader(dbName, path, config); for (Object obj : tool.getKeys()) { Object result = kvReader.get(obj); tool.outputResult(obj, result); } kvReader.stop(); } }
/** * Construct the <code>RocksDbKeyValueReader</code> with store's name, * database's path and Samza's config * * @param storeName name of the RocksDb defined in the config file * @param dbPath path to the db directory * @param config Samza's config */ public RocksDbKeyValueReader(String storeName, String dbPath, Config config) { // get the key serde and value serde from the config JavaStorageConfig storageConfig = new JavaStorageConfig(config); JavaSerializerConfig serializerConfig = new JavaSerializerConfig(config); keySerde = getSerdeFromName(storageConfig.getStorageKeySerde(storeName), serializerConfig); valueSerde = getSerdeFromName(storageConfig.getStorageMsgSerde(storeName), serializerConfig); // get db options Options options = RocksDbOptionsHelper.options(config, 1, new File(dbPath), StorageEngineFactory.StoreMode.ReadWrite); // open the db RocksDB.loadLibrary(); try { db = RocksDB.openReadOnly(options, dbPath); } catch (RocksDBException e) { throw new SamzaException("can not open the rocksDb in " + dbPath, e); } }
/** * Construct the <code>RocksDbKeyValueReader</code> with store's name, * database's path and Samza's config * * @param storeName name of the RocksDb defined in the config file * @param dbPath path to the db directory * @param config Samza's config */ public RocksDbKeyValueReader(String storeName, String dbPath, Config config) { // get the key serde and value serde from the config JavaStorageConfig storageConfig = new JavaStorageConfig(config); JavaSerializerConfig serializerConfig = new JavaSerializerConfig(config); keySerde = getSerdeFromName(storageConfig.getStorageKeySerde(storeName), serializerConfig); valueSerde = getSerdeFromName(storageConfig.getStorageMsgSerde(storeName), serializerConfig); // get db options Options options = RocksDbOptionsHelper.options(config, 1); // open the db RocksDB.loadLibrary(); try { db = RocksDB.openReadOnly(options, dbPath); } catch (RocksDBException e) { throw new SamzaException("can not open the rocksDb in " + dbPath, e); } }
public static void main(String[] args) throws RocksDBException { RocksDbReadingTool tool = new RocksDbReadingTool(); OptionSet options = tool.parser().parse(args); MapConfig config = tool.loadConfig(options); String path = tool.getDbPath(); String dbName = tool.getDbName(); RocksDbKeyValueReader kvReader = new RocksDbKeyValueReader(dbName, path, config); for (Object obj : tool.getKeys()) { Object result = kvReader.get(obj); tool.outputResult(obj, result); } kvReader.stop(); } }
/** * Construct the <code>RocksDbKeyValueReader</code> with store's name, * database's path and Samza's config * * @param storeName name of the RocksDb defined in the config file * @param dbPath path to the db directory * @param config Samza's config */ public RocksDbKeyValueReader(String storeName, String dbPath, Config config) { // get the key serde and value serde from the config JavaStorageConfig storageConfig = new JavaStorageConfig(config); JavaSerializerConfig serializerConfig = new JavaSerializerConfig(config); keySerde = getSerdeFromName(storageConfig.getStorageKeySerde(storeName), serializerConfig); valueSerde = getSerdeFromName(storageConfig.getStorageMsgSerde(storeName), serializerConfig); // get db options Options options = RocksDbOptionsHelper.options(config, 1); // open the db RocksDB.loadLibrary(); try { db = RocksDB.openReadOnly(options, dbPath); } catch (RocksDBException e) { throw new SamzaException("can not open the rocksDb in " + dbPath, e); } }
public static void main(String[] args) throws RocksDBException { RocksDbReadingTool tool = new RocksDbReadingTool(); OptionSet options = tool.parser().parse(args); MapConfig config = tool.loadConfig(options); String path = tool.getDbPath(); String dbName = tool.getDbName(); RocksDbKeyValueReader kvReader = new RocksDbKeyValueReader(dbName, path, config); for (Object obj : tool.getKeys()) { Object result = kvReader.get(obj); tool.outputResult(obj, result); } kvReader.stop(); } }
@Test public void testReadCorrectDbValue() throws RocksDBException { HashMap<String, String> map = new HashMap<String, String>(); map.put("stores." + DB_NAME + ".factory", "mockFactory"); map.put("stores." + DB_NAME + ".key.serde", "string"); map.put("stores." + DB_NAME + ".msg.serde", "string"); Config config = new MapConfig(map); RocksDbKeyValueReader reader = new RocksDbKeyValueReader(DB_NAME, dirPath.toString(), config); assertEquals("this is string", reader.get("testString")); // should throw exception if the input is in other type boolean throwClassCastException = false; try { reader.get(123); } catch (Exception e) { if (e instanceof ClassCastException) { throwClassCastException = true; } } assertTrue(throwClassCastException); reader.stop(); // test with customized serde map.put("serializers.registry.mock.class", IntegerSerdeFactory.class.getCanonicalName()); map.put("stores." + DB_NAME + ".key.serde", "mock"); map.put("stores." + DB_NAME + ".msg.serde", "mock"); config = new MapConfig(map); reader = new RocksDbKeyValueReader(DB_NAME, dirPath.toString(), config); assertEquals(456, reader.get(123)); assertNull(reader.get(789)); reader.stop(); }