本文整理汇总了Java中org.rocksdb.RocksDB.openReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Java RocksDB.openReadOnly方法的具体用法?Java RocksDB.openReadOnly怎么用?Java RocksDB.openReadOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rocksdb.RocksDB
的用法示例。
在下文中一共展示了RocksDB.openReadOnly方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openSuffixDataStore
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@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);
}
}
示例2: openKnownWordDataStore
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@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);
}
}
示例3: RocksDbKeyValueReader
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
/**
* 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
ArrayList<TaskName> taskNameList = new ArrayList<TaskName>();
taskNameList.add(new TaskName("read-rocks-db"));
SamzaContainerContext samzaContainerContext =
new SamzaContainerContext("0", config, taskNameList, new MetricsRegistryMap());
Options options = RocksDbOptionsHelper.options(config, samzaContainerContext);
// 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);
}
}
示例4: RocksDBNormalizerModel
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
RocksDBNormalizerModel(Path dbPath) {
RocksDB.loadLibrary();
try {
db = RocksDB.openReadOnly(dbPath.toString());
} catch (RocksDBException e) {
throw new RuntimeException(e);
}
}
示例5: RocksDbIdentifiers
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public RocksDbIdentifiers(Path identifiersPath) {
RocksDB.loadLibrary();
try {
indices = RocksDB.openReadOnly(identifiersPath.toString());
} catch (RocksDBException e) {
// says "if error happens in underlying native library", can't possible hope to handle that.
throw new RuntimeException(e);
}
}
示例6: RocksDbStrings
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
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);
}
}
示例7: init
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public RocksDbWrapper init() throws RocksDBException {
if (!directory.isDirectory() || !directory.exists()) {
throw new IllegalArgumentException(directory + " does not exist, or not a directory!");
}
prepareColumnFamilyDescriptors();
if (dbOptions == null) {
dbOptions = RocksDbUtils.buildDbOptions();
myOwnDbOptions = true;
} else {
myOwnDbOptions = false;
}
String path = directory.getAbsolutePath();
List<ColumnFamilyDescriptor> cfdList = new ArrayList<>(columnFamilies);
List<ColumnFamilyHandle> cfhList = new ArrayList<>();
if (readOnly) {
if (readOptions == null) {
readOptions = RocksDbUtils.buildReadOptions(true);
myOwnReadOptions = true;
} else {
myOwnReadOptions = false;
}
rocksDb = RocksDB.openReadOnly(dbOptions, path, cfdList, cfhList);
} else {
if (writeOptions == null) {
/*
* As of RocksDB v3.10.1, no data lost if process crashes even
* if sync==false. Data lost only when server/OS crashes. So
* it's relatively safe to set sync=false for fast write.
*/
writeOptions = RocksDbUtils.buildWriteOptions(false, false);
myOwnWriteOptions = true;
} else {
myOwnWriteOptions = false;
}
if (readOptions == null) {
readOptions = RocksDbUtils.buildReadOptions(true);
myOwnReadOptions = true;
} else {
myOwnReadOptions = false;
}
rocksDb = RocksDB.open(dbOptions, path, cfdList, cfhList);
}
for (int i = 0, n = cfdList.size(); i < n; i++) {
byte[] cfName = cfdList.get(i).columnFamilyName();
ColumnFamilyHandle cfh = cfhList.get(i);
columnFamilyHandles.put(new String(cfName, RocksDbUtils.UTF8), cfh);
}
return this;
}
示例8: init
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public RocksDbWrapper init() throws IOException, RocksDbException {
if (!directory.exists() && !readOnly) {
FileUtils.forceMkdir(directory);
}
if (!directory.isDirectory() || !directory.exists()) {
throw new IllegalArgumentException(directory + " does not exist, or not a directory!");
}
prepareColumnFamilyDescriptors();
if (dbOptions == null) {
dbOptions = RocksDbUtils.buildDbOptions();
myOwnDbOptions = true;
} else {
myOwnDbOptions = false;
}
String path = directory.getAbsolutePath();
List<ColumnFamilyDescriptor> cfdList = new ArrayList<>(columnFamilies);
List<ColumnFamilyHandle> cfhList = new ArrayList<>();
try {
if (readOnly) {
if (readOptions == null) {
readOptions = RocksDbUtils.buildReadOptions(true);
myOwnReadOptions = true;
} else {
myOwnReadOptions = false;
}
rocksDb = RocksDB.openReadOnly(dbOptions, path, cfdList, cfhList);
} else {
if (writeOptions == null) {
writeOptions = RocksDbUtils.buildWriteOptions();
myOwnWriteOptions = true;
} else {
myOwnWriteOptions = false;
}
if (readOptions == null) {
readOptions = RocksDbUtils.buildReadOptions(true);
myOwnReadOptions = true;
} else {
myOwnReadOptions = false;
}
rocksDb = RocksDB.open(dbOptions, path, cfdList, cfhList);
}
} catch (Exception e) {
throw e instanceof RocksDbException ? (RocksDbException) e : new RocksDbException(e);
}
for (int i = 0, n = cfdList.size(); i < n; i++) {
byte[] cfName = cfdList.get(i).columnFamilyName();
ColumnFamilyHandle cfh = cfhList.get(i);
columnFamilyHandles.put(new String(cfName, RocksDbUtils.UTF8), cfh);
}
return this;
}