Java Code Examples for org.rocksdb.RocksDB#openReadOnly()
The following examples show how to use
org.rocksdb.RocksDB#openReadOnly() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KnowledgeBase.java From fasten with Apache License 2.0 | 6 votes |
@SuppressWarnings("resource") public static KnowledgeBase getInstance(final String kbDir, final String kbMetadataPathname, final boolean readOnly) throws RocksDBException, ClassNotFoundException, IOException { final boolean metadataExists = new File(kbMetadataPathname).exists(); final boolean kbDirExists = new File(kbDir).exists(); if (metadataExists != kbDirExists) throw new IllegalArgumentException("Either both or none of the knowledge-base directory and metadata must exist"); RocksDB.loadLibrary(); final ColumnFamilyOptions cfOptions = new ColumnFamilyOptions().setCompressionType(CompressionType.LZ4_COMPRESSION); final DBOptions dbOptions = new DBOptions().setCreateIfMissing(true).setCreateMissingColumnFamilies(true); final List<ColumnFamilyDescriptor> cfDescriptors = Arrays.asList(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOptions), new ColumnFamilyDescriptor(GID2URI, cfOptions), new ColumnFamilyDescriptor(URI2GID, cfOptions)); final List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>(); final RocksDB db = readOnly ? RocksDB.openReadOnly(dbOptions, kbDir, cfDescriptors, columnFamilyHandles) : RocksDB.open(dbOptions, kbDir, cfDescriptors, columnFamilyHandles); final KnowledgeBase kb; if (metadataExists) { kb = (KnowledgeBase) BinIO.loadObject(kbMetadataPathname); kb.readOnly = readOnly; kb.callGraphDB = db; kb.defaultHandle = columnFamilyHandles.get(0); kb.gid2uriFamilyHandle = columnFamilyHandles.get(1); kb.uri2gidFamilyHandle = columnFamilyHandles.get(2); } else kb = new KnowledgeBase(db, columnFamilyHandles.get(0), columnFamilyHandles.get(1), columnFamilyHandles.get(2), kbMetadataPathname, readOnly); return kb; }
Example 2
Source File: RocksDbDataStoreFactory.java From biomedicus with Apache License 2.0 | 6 votes |
@Override public SuffixDataStore openSuffixDataStore(int id) { RocksDB.loadLibrary(); try { LOGGER.info("Opening TnT suffix model: {}", id); RocksDB rocksDB = RocksDB.openReadOnly(dbPath.resolve(getSuffixesName(id)).toString()); RocksDbSuffixDataStore rocksDbSuffixDataStore = new RocksDbSuffixDataStore(rocksDB); if (inMemory) { LOGGER.info("Loading TnT suffix model into memory: {}", id); InMemorySuffixDataStore inMemorySuffixDataStore = rocksDbSuffixDataStore.inMemory(); LOGGER.info("Done loading TnT suffix model into memory: {}", id); rocksDB.close(); return inMemorySuffixDataStore; } rocksDBS.add(rocksDB); return rocksDbSuffixDataStore; } catch (RocksDBException e) { throw new RuntimeException(e); } }
Example 3
Source File: RocksDbDataStoreFactory.java From biomedicus with Apache License 2.0 | 6 votes |
@Override public KnownWordsDataStore openKnownWordDataStore(int id) { RocksDB.loadLibrary(); try { LOGGER.info("Opening TnT model known word model: {}", id); RocksDB rocksDB = RocksDB.openReadOnly(dbPath.resolve(getWordsName(id)).toString()); RocksDB candidatesDB = RocksDB.openReadOnly(dbPath.resolve(getCandidatesName(id)).toString()); RocksDbKnownWordsDataStore rocksDbKnownWordsDataStore = new RocksDbKnownWordsDataStore( rocksDB, candidatesDB); if (inMemory) { LOGGER.info("Loading TnT known word model into memory: {}", id); InMemoryKnownWordDataStore inMemoryKnownWordDataStore = rocksDbKnownWordsDataStore .inMemory(); LOGGER.info("Done loading TnT known word model into memory: {}", id); rocksDB.close(); candidatesDB.close(); return inMemoryKnownWordDataStore; } rocksDBS.add(rocksDB); rocksDBS.add(candidatesDB); return rocksDbKnownWordsDataStore; } catch (RocksDBException e) { throw new RuntimeException(e); } }
Example 4
Source File: RocksDbKeyValueReader.java From samza with Apache License 2.0 | 6 votes |
/** * 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 StorageConfig storageConfig = new StorageConfig(config); SerializerConfig serializerConfig = new SerializerConfig(config); keySerde = getSerdeFromName(storageConfig.getStorageKeySerde(storeName).orElse(null), serializerConfig); valueSerde = getSerdeFromName(storageConfig.getStorageMsgSerde(storeName).orElse(null), 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); } }
Example 5
Source File: AbstractRocksDBTable.java From geowave with Apache License 2.0 | 6 votes |
@SuppressFBWarnings( justification = "double check for null is intentional to avoid synchronized blocks when not needed.") protected RocksDB getReadDb() { if (!exists) { return null; } // avoid synchronization if unnecessary by checking for null outside // synchronized block if (readDb == null) { synchronized (this) { // check again within synchronized block if (readDb == null) { try { readerDirty = false; readDb = RocksDB.openReadOnly(readOptions, subDirectory); } catch (final RocksDBException e) { LOGGER.warn("Unable to open for reading", e); } } } } return readDb; }
Example 6
Source File: RocksDBLookupTable.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public RocksDBLookupTable(TableDesc tableDesc, String[] keyColumns, String dbPath) { this.options = new Options(); this.rowEncoder = new RocksDBLookupRowEncoder(tableDesc, keyColumns); try { this.rocksDB = RocksDB.openReadOnly(options, dbPath); } catch (RocksDBException e) { throw new IllegalStateException("cannot open rocks db in path:" + dbPath, e); } }
Example 7
Source File: RocksDBNormalizerModel.java From biomedicus with Apache License 2.0 | 5 votes |
RocksDBNormalizerModel(Path dbPath) { RocksDB.loadLibrary(); try (Options options = new Options().setInfoLogLevel(InfoLogLevel.ERROR_LEVEL)) { db = RocksDB.openReadOnly(options, dbPath.toString()); } catch (RocksDBException e) { throw new RuntimeException(e); } }
Example 8
Source File: RocksDbIdentifiers.java From biomedicus with Apache License 2.0 | 5 votes |
public RocksDbIdentifiers(Path identifiersPath) { RocksDB.loadLibrary(); try (Options options = new Options().setInfoLogLevel(InfoLogLevel.ERROR_LEVEL)) { indices = RocksDB.openReadOnly(options, identifiersPath.toString()); } catch (RocksDBException e) { throw new RuntimeException(e); } }
Example 9
Source File: RocksDbStrings.java From biomedicus with Apache License 2.0 | 5 votes |
public RocksDbStrings(Path termsPath) { RocksDB.loadLibrary(); try { terms = RocksDB.openReadOnly(termsPath.toString()); } catch (RocksDBException e) { // says "if error happens in underlying native library", can't possible hope to handle that. throw new RuntimeException(e); } }
Example 10
Source File: RocksDBLookupTable.java From kylin with Apache License 2.0 | 5 votes |
public RocksDBLookupTable(TableDesc tableDesc, String[] keyColumns, String dbPath) { this.options = new Options(); this.rowEncoder = new RocksDBLookupRowEncoder(tableDesc, keyColumns); try { this.rocksDB = RocksDB.openReadOnly(options, dbPath); } catch (RocksDBException e) { throw new IllegalStateException("cannot open rocks db in path:" + dbPath, e); } }