Search in sources :

Example 31 with HugeType

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);
}
Also used : ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) HugeType(com.baidu.hugegraph.type.HugeType) HashSet(java.util.HashSet)

Example 32 with HugeType

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);
        }
    }
}
Also used : Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HugeType(com.baidu.hugegraph.type.HugeType)

Example 33 with HugeType

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();
    }
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) ArrayList(java.util.ArrayList) HugeType(com.baidu.hugegraph.type.HugeType) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) MergeIterator(com.baidu.hugegraph.backend.serializer.MergeIterator) Iterator(java.util.Iterator) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Id(com.baidu.hugegraph.backend.id.Id)

Example 34 with HugeType

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;
    });
}
Also used : BinaryEntryIterator(com.baidu.hugegraph.backend.serializer.BinaryEntryIterator) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) HugeType(com.baidu.hugegraph.type.HugeType)

Aggregations

HugeType (com.baidu.hugegraph.type.HugeType)34 Id (com.baidu.hugegraph.backend.id.Id)16 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 Query (com.baidu.hugegraph.backend.query.Query)4 ExistedException (com.baidu.hugegraph.exception.ExistedException)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 ArrayList (java.util.ArrayList)4 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)3 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)3 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)3 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 Lock (java.util.concurrent.locks.Lock)3 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BinaryEntryIterator (com.baidu.hugegraph.backend.serializer.BinaryEntryIterator)2