当前位置: 首页>>代码示例>>Java>>正文


Java RocksDB.open方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:22,代码来源:DumpLabelDb.java

示例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);
    }
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:18,代码来源:QueryLabelDb.java

示例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;
}
 
开发者ID:dehora,项目名称:outland,代码行数:14,代码来源:FeatureStoreRocksDb.java

示例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);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:15,代码来源:RocksDBStore.java

示例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);
    }
}
 
开发者ID:apsaltis,项目名称:StreamingData-Book-Examples,代码行数:14,代码来源:HybridMessageLogger.java

示例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);
    }
}
 
开发者ID:sciodb,项目名称:sciodb,代码行数:35,代码来源:RocksDBEngine.java

示例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);
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:9,代码来源:FreebaseSearcher.java

示例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);
    }
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:32,代码来源:BuildLabelDb.java

示例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);
}
 
开发者ID:trvedata,项目名称:trvedb,代码行数:32,代码来源:KeyValueStore.java

示例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");
    }
}
 
开发者ID:pravega,项目名称:pravega,代码行数:8,代码来源:RocksDBCache.java

示例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);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:14,代码来源:RocksDbDataStoreFactory.java

示例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);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:16,代码来源:RocksDbDataStoreFactory.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:32,代码来源:RocksDBKeyedStateBackend.java

示例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());
}
 
开发者ID:apache,项目名称:samza,代码行数:12,代码来源:TestRocksDbKeyValueReader.java

示例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);
    }
}
 
开发者ID:ViDA-NYU,项目名称:ache,代码行数:11,代码来源:RocksDBHashtable.java


注:本文中的org.rocksdb.RocksDB.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。