本文整理汇总了Java中org.rocksdb.RocksDB.open方法的典型用法代码示例。如果您正苦于以下问题:Java RocksDB.open方法的具体用法?Java RocksDB.open怎么用?Java RocksDB.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rocksdb.RocksDB
的用法示例。
在下文中一共展示了RocksDB.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public static void main(String[] args) {
RocksDB.loadLibrary();
Options rockopts = new Options().setCreateIfMissing(false);
RocksDB db = null;
try {
db = RocksDB.open(rockopts, args[0]);
RocksIterator iter = db.newIterator();
iter.seekToFirst();
while (iter.isValid()) {
String key = new String(iter.key(), StandardCharsets.UTF_8);
String val = new String(iter.value(), StandardCharsets.UTF_8);
System.out.println(key + " -> " + val);
iter.next();
}
db.close();
} catch (RocksDBException rdbe) {
rdbe.printStackTrace(System.err);
}
}
示例2: main
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public static void main(String[] args) {
RocksDB.loadLibrary();
Options rockopts = new Options().setCreateIfMissing(false);
RocksDB db = null;
try {
db = RocksDB.open(rockopts, args[0]);
String query = args[1];
byte[] val = db.get(query.getBytes(StandardCharsets.UTF_8));
if (val != null) {
System.out.println(new String(val, StandardCharsets.UTF_8));
}
db.close();
} catch (RocksDBException rdbe) {
rdbe.printStackTrace(System.err);
}
}
示例3: initializeRocksDb
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@SuppressWarnings("WeakerAccess") @VisibleForTesting
RocksDB initializeRocksDb() {
try {
final String absolutePath = rocksDir.getAbsolutePath();
logger.info("op=initialise_rocks, path={}", absolutePath);
return RocksDB.open(options, absolutePath);
} catch (RocksDBException e) {
logger.warn(
"op=create_rocks, result=create_rocks_failed, msg='could not create a rocks db client storage actions will be skipped'");
logger.error(e.getMessage());
}
return null;
}
示例4: openDB
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
private RocksDB openDB(File dir, Options options, int ttl) throws IOException {
try {
if (ttl == TTL_NOT_USED) {
Files.createDirectories(dir.getParentFile().toPath());
return RocksDB.open(options, dir.getAbsolutePath());
} else {
throw new UnsupportedOperationException("Change log is not supported for store " + this.name + " since it is TTL based.");
// TODO: support TTL with change log?
// return TtlDB.open(options, dir.toString(), ttl, false);
}
} catch (RocksDBException e) {
throw new ProcessorStateException("Error opening store " + this.name + " at location " + dir.toString(), e);
}
}
示例5: initialize
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
static void initialize() throws Exception {
RocksDB.loadLibrary();
options = new Options().setCreateIfMissing(true);
try {
ensureDirectories();
transientStateDB = RocksDB.open(options, transientPath.toString());
failedStateDB = RocksDB.open(options, failedPath.toString());
} catch (RocksDBException | IOException e) {
e.printStackTrace();
throw new Exception(e);
}
}
示例6: init
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@Override
public void init() throws StorageException {
try {
collections = new ArrayList<>();
descriptors = new ArrayList<>();
final File f = new File(dataPath);
boolean newDB = !f.exists();
if (newDB) {
f.mkdirs();
logger.info("Created database folder : " + dataPath);
descriptors.add(new ColumnFamilyDescriptor(
RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions()));
} else {
final List<byte[]> columns = RocksDB.listColumnFamilies(options, dataPath);
if (columns != null) {
for(byte[] column: columns) {
descriptors.add(new ColumnFamilyDescriptor(
column, new ColumnFamilyOptions()));
}
}
}
dbOptions = new DBOptions()
.setCreateIfMissing(true);
db = RocksDB.open(dbOptions, dataPath, descriptors, collections);
} catch (RocksDBException e) {
throw new StorageException("Error initialising Storage", e);
}
}
示例7: setLabelDb
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public void setLabelDb(String filename) throws RocksDBException {
if (label_db != null)
label_db.close();
else
RocksDB.loadLibrary();
Options rockopts = new Options().setCreateIfMissing(false);
label_db = RocksDB.open(rockopts, filename);
}
示例8: main
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public static void main(String[] args) {
RocksDB.loadLibrary();
Options rockopts = new Options().setCreateIfMissing(true);
RocksDB db = null;
int count = 0;
try {
BufferedReader in = new BufferedReader(new FileReader(args[0]));
db = RocksDB.open(rockopts, args[1]);
String line;
while ((line = in.readLine()) != null) {
String[] fields = line.split("\\t+");
if (fields[2].endsWith("@en")) {
byte[] key = fields[0].substring(1, fields[0].length() - 1).getBytes(StandardCharsets.UTF_8);
byte[] value = fields[2].substring(1, fields[2].length() - 4).getBytes(StandardCharsets.UTF_8);
db.put(key, value);
}
count++;
if ((count % 100000) == 0)
System.out.print(".");
}
db.close();
System.out.println();
} catch (RocksDBException rdbe) {
rdbe.printStackTrace(System.err);
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}
示例9: open
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public void open() throws RocksDBException {
if (db != null) throw new IllegalStateException("Database already open");
storagePath.toFile().mkdirs();
defaultColumnFamily = addColumnFamily("default", Serdes.stringSerdes()); // must exist
options = new DBOptions();
options.setCreateIfMissing(true);
options.setCreateMissingColumnFamilies(true);
//options.setBytesPerSync(1024 * 1024);
List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
List<ColumnFamilyHandle> handles = new ArrayList<>();
List<ColumnFamily<?, ?>> families = new ArrayList<>();
try {
for (Map.Entry<String, ColumnFamily<?, ?>> entry : columnFamilies.entrySet()) {
descriptors.add(new ColumnFamilyDescriptor(entry.getKey().getBytes("UTF-8")));
families.add(entry.getValue());
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
db = RocksDB.open(options, storagePath.toString(), descriptors, handles);
if (families.size() != handles.size()) {
throw new IllegalStateException("Unexpected number of column family handles");
}
for (int i = 0; i < families.size(); i++) {
families.get(i).setDBHandle(db, handles.get(i));
}
log.info("Opened database {} at path {}", name, storagePath);
}
示例10: openDatabase
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
private RocksDB openDatabase() {
try {
return RocksDB.open(this.databaseOptions, this.dbDir);
} catch (RocksDBException ex) {
throw convert(ex, "initialize RocksDB instance");
}
}
示例11: createSuffixDataStore
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@Override
public SuffixDataStore createSuffixDataStore(int id) {
RocksDB.loadLibrary();
try (Options options = new Options().setCreateIfMissing(true).prepareForBulkLoad()) {
Files.createDirectories(dbPath);
RocksDB rocksDB = RocksDB.open(options, dbPath.resolve(getSuffixesName(id)).toString());
rocksDBS.add(rocksDB);
return new RocksDbSuffixDataStore(rocksDB);
} catch (RocksDBException | IOException e) {
throw new RuntimeException(e);
}
}
示例12: createKnownWordsDataStore
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@Override
public KnownWordsDataStore createKnownWordsDataStore(int id) {
RocksDB.loadLibrary();
try (Options options = new Options().setCreateIfMissing(true).prepareForBulkLoad()) {
Files.createDirectories(dbPath);
RocksDB rocksDB = RocksDB.open(options, dbPath.resolve(getWordsName(id)).toString());
rocksDBS.add(rocksDB);
RocksDB candidatesDB = RocksDB.open(options, dbPath.resolve(getCandidatesName(id)).toString());
rocksDBS.add(candidatesDB);
return new RocksDbKnownWordsDataStore(rocksDB, candidatesDB);
} catch (RocksDBException | IOException e) {
throw new RuntimeException(e);
}
}
示例13: openDB
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
private RocksDB openDB(
String path,
List<ColumnFamilyDescriptor> stateColumnFamilyDescriptors,
List<ColumnFamilyHandle> stateColumnFamilyHandles) throws IOException {
List<ColumnFamilyDescriptor> columnFamilyDescriptors =
new ArrayList<>(1 + stateColumnFamilyDescriptors.size());
columnFamilyDescriptors.addAll(stateColumnFamilyDescriptors);
// we add the required descriptor for the default CF in last position.
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(DEFAULT_COLUMN_FAMILY_NAME_BYTES, columnOptions));
RocksDB dbRef;
try {
dbRef = RocksDB.open(
Preconditions.checkNotNull(dbOptions),
Preconditions.checkNotNull(path),
columnFamilyDescriptors,
stateColumnFamilyHandles);
} catch (RocksDBException e) {
throw new IOException("Error while opening RocksDB instance.", e);
}
// requested + default CF
Preconditions.checkState(1 + stateColumnFamilyDescriptors.size() == stateColumnFamilyHandles.size(),
"Not all requested column family handles have been created");
return dbRef;
}
示例14: createRocksDb
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
@BeforeClass
static public void createRocksDb() throws IOException, RocksDBException {
if (Files.exists(dirPath)) {
removeRecursiveDirectory(dirPath);
}
Files.createDirectories(dirPath);
Options options = new Options().setCreateIfMissing(true);
db = RocksDB.open(options, dirPath.toString());
db.put("testString".getBytes(), "this is string".getBytes());
db.put(ByteBuffer.allocate(4).putInt(123).array(), ByteBuffer.allocate(4).putInt(456).array());
}
示例15: RocksDBHashtable
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public RocksDBHashtable(String path, Class<T> contentClass) {
this.contentClass = contentClass;
this.options = new Options();
this.options.setCreateIfMissing(true);
try {
this.db = RocksDB.open(options, path);
} catch (RocksDBException e) {
throw new RuntimeException("Failed to open database at "+path, e);
}
}