本文整理汇总了Java中org.rocksdb.DBOptions.setCreateMissingColumnFamilies方法的典型用法代码示例。如果您正苦于以下问题:Java DBOptions.setCreateMissingColumnFamilies方法的具体用法?Java DBOptions.setCreateMissingColumnFamilies怎么用?Java DBOptions.setCreateMissingColumnFamilies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rocksdb.DBOptions
的用法示例。
在下文中一共展示了DBOptions.setCreateMissingColumnFamilies方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.rocksdb.DBOptions; //导入方法依赖的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);
}
示例2: main
import org.rocksdb.DBOptions; //导入方法依赖的package包/类
public static void main(String[] args) {
Map conf = JStormHelper.LoadConf(args[0]);
putNum = JStormUtils.parseInt(conf.get("put.number"), 100);
isFlush = JStormUtils.parseBoolean(conf.get("is.flush"), true);
isCheckpoint = JStormUtils.parseBoolean(conf.get("is.checkpoint"), true);
sleepTime = JStormUtils.parseInt(conf.get("sleep.time"), 5000);
compactionInterval = JStormUtils.parseInt(conf.get("compaction.interval"), 30000);
flushInterval = JStormUtils.parseInt(conf.get("flush.interval"), 3000);
isCompaction = JStormUtils.parseBoolean(conf.get("is.compaction"), true);
fileSizeBase = JStormUtils.parseLong(conf.get("file.size.base"), 10 * SizeUnit.KB);
levelNum = JStormUtils.parseInt(conf.get("db.level.num"), 1);
compactionTriggerNum = JStormUtils.parseInt(conf.get("db.compaction.trigger.num"), 4);
LOG.info("Conf={}", conf);
RocksDB db;
File file = new File(cpPath);
file.mkdirs();
List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
try {
Options options = new Options();
options.setCreateMissingColumnFamilies(true);
options.setCreateIfMissing(true);
options.setTargetFileSizeBase(fileSizeBase);
options.setMaxBackgroundFlushes(2);
options.setMaxBackgroundCompactions(2);
options.setCompactionStyle(CompactionStyle.LEVEL);
options.setNumLevels(levelNum);
options.setLevelZeroFileNumCompactionTrigger(compactionTriggerNum);
DBOptions dbOptions = new DBOptions();
dbOptions.setCreateMissingColumnFamilies(true);
dbOptions.setCreateIfMissing(true);
dbOptions.setMaxBackgroundFlushes(2);
dbOptions.setMaxBackgroundCompactions(2);
ColumnFamilyOptions familyOptions = new ColumnFamilyOptions();
familyOptions.setTargetFileSizeBase(fileSizeBase);
familyOptions.setCompactionStyle(CompactionStyle.LEVEL);
familyOptions.setNumLevels(levelNum);
familyOptions.setLevelZeroFileNumCompactionTrigger(compactionTriggerNum);
List<byte[]> families = RocksDB.listColumnFamilies(options, dbPath);
List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
if (families != null) {
for (byte[] bytes : families) {
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(bytes, familyOptions));
LOG.info("Load colum family of {}", new String(bytes));
}
}
if (columnFamilyDescriptors.size() > 0) {
db = RocksDB.open(dbOptions, dbPath, columnFamilyDescriptors, columnFamilyHandles);
} else {
db = RocksDB.open(options, dbPath);
}
} catch (RocksDBException e) {
LOG.error("Failed to open db", e);
return;
}
rocksDbTest(db, columnFamilyHandles);
db.close();
}