use of com.baidu.hugegraph.backend.store.rocksdb.OpenedRocksDB.CFHandle in project incubator-hugegraph by apache.
the class RocksDBStdSessions method openRocksDB.
private static OpenedRocksDB openRocksDB(HugeConfig config, List<String> cfNames, String dataPath, String walPath) throws RocksDBException {
// Old CFs should always be opened
Set<String> mergedCFs = RocksDBStdSessions.mergeOldCFs(dataPath, cfNames);
List<String> cfs = ImmutableList.copyOf(mergedCFs);
// Init CFs options
List<ColumnFamilyDescriptor> cfds = new ArrayList<>(cfs.size());
for (String cf : cfs) {
ColumnFamilyDescriptor cfd = new ColumnFamilyDescriptor(encode(cf));
ColumnFamilyOptions options = cfd.getOptions();
RocksDBStdSessions.initOptions(config, null, null, options, options);
cfds.add(cfd);
}
// Init DB options
DBOptions options = new DBOptions();
RocksDBStdSessions.initOptions(config, options, options, null, null);
if (walPath != null) {
options.setWalDir(walPath);
}
SstFileManager sstFileManager = new SstFileManager(Env.getDefault());
options.setSstFileManager(sstFileManager);
// Open RocksDB with CFs
List<ColumnFamilyHandle> cfhs = new ArrayList<>();
RocksDB rocksdb = RocksDB.open(options, dataPath, cfds, cfhs);
E.checkState(cfhs.size() == cfs.size(), "Expect same size of cf-handles and cf-names");
// Collect CF Handles
Map<String, CFHandle> cfHandles = new ConcurrentHashMap<>();
for (int i = 0; i < cfs.size(); i++) {
cfHandles.put(cfs.get(i), new CFHandle(rocksdb, cfhs.get(i)));
}
return new OpenedRocksDB(rocksdb, cfHandles, sstFileManager);
}
use of com.baidu.hugegraph.backend.store.rocksdb.OpenedRocksDB.CFHandle in project incubator-hugegraph by apache.
the class RocksDBStdSessions method ingestExternalFile.
private void ingestExternalFile() throws RocksDBException {
String directory = this.config().get(RocksDBOptions.SST_PATH);
if (directory == null || directory.isEmpty()) {
return;
}
RocksDBIngester ingester = new RocksDBIngester(this.rocksdb());
// Ingest all *.sst files in each directory named cf name
for (String cf : this.rocksdb.cfs()) {
Path path = Paths.get(directory, cf);
if (path.toFile().isDirectory()) {
try (CFHandle cfh = this.cf(cf)) {
ingester.ingest(path, cfh.get());
}
}
}
}
use of com.baidu.hugegraph.backend.store.rocksdb.OpenedRocksDB.CFHandle in project incubator-hugegraph by apache.
the class RocksDBStdSessions method createTable.
@Override
public synchronized void createTable(String... tables) throws RocksDBException {
this.checkValid();
List<ColumnFamilyDescriptor> cfds = new ArrayList<>();
for (String table : tables) {
if (this.rocksdb.existCf(table)) {
continue;
}
ColumnFamilyDescriptor cfd = new ColumnFamilyDescriptor(encode(table));
ColumnFamilyOptions options = cfd.getOptions();
initOptions(this.config(), null, null, options, options);
cfds.add(cfd);
}
/*
* To speed up the creation of tables, like truncate() for tinkerpop
* test, we call createColumnFamilies instead of createColumnFamily.
*/
List<ColumnFamilyHandle> cfhs = this.rocksdb().createColumnFamilies(cfds);
for (ColumnFamilyHandle cfh : cfhs) {
String table = decode(cfh.getName());
this.rocksdb.addCf(table, new CFHandle(this.rocksdb(), cfh));
}
this.ingestExternalFile();
}
use of com.baidu.hugegraph.backend.store.rocksdb.OpenedRocksDB.CFHandle in project incubator-hugegraph by apache.
the class RocksDBStdSessions method dropTable.
@Override
public synchronized void dropTable(String... tables) throws RocksDBException {
this.checkValid();
/*
* May cause bug to drop CF when someone is reading or writing this CF,
* use CFHandle to wait for others and then do drop:
* https://github.com/hugegraph/hugegraph/issues/697
*/
List<ColumnFamilyHandle> cfhs = new ArrayList<>();
for (String table : tables) {
CFHandle cfh = this.rocksdb.cf(table);
if (cfh == null) {
continue;
}
cfhs.add(cfh.waitForDrop());
}
/*
* To speed up the creation of tables, like truncate() for tinkerpop
* test, we call dropColumnFamilies instead of dropColumnFamily.
*/
this.rocksdb().dropColumnFamilies(cfhs);
for (String table : tables) {
CFHandle cfh = this.rocksdb.cf(table);
if (cfh == null) {
continue;
}
cfh.destroy();
this.rocksdb.removeCf(table);
}
}
use of com.baidu.hugegraph.backend.store.rocksdb.OpenedRocksDB.CFHandle in project incubator-hugegraph by apache.
the class RocksDBStdSessions method cf.
private CFHandle cf(String cfName) {
CFHandle cfh = this.rocksdb.cf(cfName);
if (cfh == null) {
throw new BackendException("Table '%s' is not opened", cfName);
}
cfh.open();
return cfh;
}
Aggregations