use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class RocksDBStore method open.
@Override
public synchronized void open(HugeConfig config) {
LOG.debug("Store open: {}", this.store);
E.checkNotNull(config, "config");
String graphStore = config.get(CoreOptions.STORE_GRAPH);
this.isGraphStore = this.store.equals(graphStore);
this.dataPath = config.get(RocksDBOptions.DATA_PATH);
if (this.sessions != null && !this.sessions.closed()) {
LOG.debug("Store {} has been opened before", this.store);
this.useSessions();
return;
}
List<Future<?>> futures = new ArrayList<>();
ExecutorService openPool = ExecutorUtil.newFixedThreadPool(OPEN_POOL_THREADS, DB_OPEN);
// Open base disk
futures.add(openPool.submit(() -> {
this.sessions = this.open(config, this.tableNames());
}));
// Open tables with optimized disk
Map<String, String> disks = config.getMap(RocksDBOptions.DATA_DISKS);
Set<String> openedDisks = new HashSet<>();
if (!disks.isEmpty()) {
this.parseTableDiskMapping(disks, this.dataPath);
for (Entry<HugeType, String> e : this.tableDiskMapping.entrySet()) {
String disk = e.getValue();
if (openedDisks.contains(disk)) {
continue;
}
openedDisks.add(disk);
List<String> tables = this.tableNames(e.getKey());
futures.add(openPool.submit(() -> {
this.open(config, disk, disk, tables);
}));
}
}
this.waitOpenFinish(futures, openPool);
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class RocksDBStore method parseTableDiskMapping.
private final void parseTableDiskMapping(Map<String, String> disks, String dataPath) {
this.tableDiskMapping.clear();
for (Map.Entry<String, String> disk : disks.entrySet()) {
// The format of `disk` like: `graph/vertex: /path/to/disk1`
String name = disk.getKey();
String path = disk.getValue();
E.checkArgument(!dataPath.equals(path), "Invalid disk path" + "(can't be the same as data_path): '%s'", path);
E.checkArgument(!name.isEmpty() && !path.isEmpty(), "Invalid disk format: '%s', expect `NAME:PATH`", disk);
String[] pair = name.split("/", 2);
E.checkArgument(pair.length == 2, "Invalid disk key format: '%s', " + "expect `STORE/TABLE`", name);
String store = pair[0].trim();
HugeType table = HugeType.valueOf(pair[1].trim().toUpperCase());
if (this.store.equals(store)) {
path = this.wrapPath(path);
this.tableDiskMapping.put(table, path);
}
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class RocksDBStore method query.
@Override
public Iterator<BackendEntry> query(Query query) {
Lock readLock = this.storeLock.readLock();
readLock.lock();
try {
this.checkOpened();
HugeType tableType = RocksDBTable.tableType(query);
RocksDBTable table;
RocksDBSessions.Session session;
if (query.olap()) {
table = this.table(this.olapTableName(tableType));
session = this.session(HugeType.OLAP);
} else {
table = this.table(tableType);
session = this.session(tableType);
}
Iterator<BackendEntry> entries = table.query(session, query);
// Merge olap results as needed
Set<Id> olapPks = query.olapPks();
if (this.isGraphStore && !olapPks.isEmpty()) {
List<Iterator<BackendEntry>> iterators = new ArrayList<>();
for (Id pk : olapPks) {
Query q = query.copy();
table = this.table(this.olapTableName(pk));
iterators.add(table.query(this.session(HugeType.OLAP), q));
}
entries = new MergeIterator<>(entries, iterators, BackendEntry::mergeable);
}
return entries;
} finally {
readLock.unlock();
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class RocksDBTable method newEntryIterator.
protected static final BackendEntryIterator newEntryIterator(BackendColumnIterator cols, Query query) {
return new BinaryEntryIterator<>(cols, query, (entry, col) -> {
if (entry == null || !entry.belongToMe(col)) {
HugeType type = query.resultType();
// NOTE: only support BinaryBackendEntry currently
entry = new BinaryBackendEntry(type, col.name);
} else {
assert !Bytes.equals(entry.id().asBytes(), col.name);
}
entry.columns(col);
return entry;
});
}
Aggregations