Search in sources :

Example 51 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class ServerInfoManager method save.

private Id save(HugeServerInfo serverInfo) {
    return this.call(() -> {
        // Construct vertex from server info
        HugeServerInfo.Schema schema = HugeServerInfo.schema(this.graph);
        if (!schema.existVertexLabel(HugeServerInfo.P.SERVER)) {
            throw new HugeException("Schema is missing for %s '%s'", HugeServerInfo.P.SERVER, serverInfo);
        }
        HugeVertex vertex = this.tx().constructVertex(false, serverInfo.asArray());
        // Add or update server info in backend store
        vertex = this.tx().addVertex(vertex);
        return vertex.id();
    });
}
Also used : HugeException(com.baidu.hugegraph.HugeException) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 52 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class ServerInfoManager method save.

private int save(Collection<HugeServerInfo> serverInfos) {
    return this.call(() -> {
        if (serverInfos.isEmpty()) {
            return serverInfos.size();
        }
        HugeServerInfo.Schema schema = HugeServerInfo.schema(this.graph);
        if (!schema.existVertexLabel(HugeServerInfo.P.SERVER)) {
            throw new HugeException("Schema is missing for %s", HugeServerInfo.P.SERVER);
        }
        // Save server info in batch
        GraphTransaction tx = this.tx();
        int updated = 0;
        for (HugeServerInfo server : serverInfos) {
            if (!server.updated()) {
                continue;
            }
            HugeVertex vertex = tx.constructVertex(false, server.asArray());
            tx.addVertex(vertex);
            updated++;
        }
        // NOTE: actually it is auto-commit, to be improved
        tx.commitOrRollback();
        return updated;
    });
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) HugeException(com.baidu.hugegraph.HugeException) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 53 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class TaskManager method closeTaskTx.

private void closeTaskTx(HugeGraphParams graph) {
    final boolean selfIsTaskWorker = Thread.currentThread().getName().startsWith(TASK_WORKER_PREFIX);
    final int totalThreads = selfIsTaskWorker ? THREADS - 1 : THREADS;
    try {
        if (selfIsTaskWorker) {
            // Call closeTx directly if myself is task thread(ignore others)
            graph.closeTx();
        } else {
            Consumers.executeOncePerThread(this.taskExecutor, totalThreads, graph::closeTx);
        }
    } catch (Exception e) {
        throw new HugeException("Exception when closing task tx", e);
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException) HugeException(com.baidu.hugegraph.HugeException)

Example 54 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class RegisterUtil method registerPlugins.

/**
 * Scan the jars in plugins directory and load them
 */
public static void registerPlugins() {
    ServiceLoader<HugeGraphPlugin> plugins = ServiceLoader.load(HugeGraphPlugin.class);
    for (HugeGraphPlugin plugin : plugins) {
        LOG.info("Loading plugin {}({})", plugin.name(), plugin.getClass().getCanonicalName());
        String minVersion = plugin.supportsMinVersion();
        String maxVersion = plugin.supportsMaxVersion();
        if (!VersionUtil.match(CoreVersion.VERSION, minVersion, maxVersion)) {
            LOG.warn("Skip loading plugin '{}' due to the version range " + "'[{}, {})' that it's supported doesn't cover " + "current core version '{}'", plugin.name(), minVersion, maxVersion, CoreVersion.VERSION.get());
            continue;
        }
        try {
            plugin.register();
            LOG.info("Loaded plugin '{}'", plugin.name());
        } catch (Exception e) {
            throw new HugeException("Failed to load plugin '%s'", plugin.name(), e);
        }
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException) HugeGraphPlugin(com.baidu.hugegraph.plugin.HugeGraphPlugin) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) HugeException(com.baidu.hugegraph.HugeException)

Example 55 with HugeException

use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.

the class LockUtil method lockRead.

private static Lock lockRead(String group, String lock) {
    Lock readLock = LockManager.instance().get(group).readWriteLock(lock).readLock();
    LOG.debug("Trying to get the read lock '{}' of LockGroup '{}'", lock, group);
    if (!readLock.tryLock()) {
        throw new HugeException("Lock [%s:%s] is locked by other operation", group, lock);
    }
    LOG.debug("Got the read lock '{}' of LockGroup '{}'", lock, group);
    return readLock;
}
Also used : HugeException(com.baidu.hugegraph.HugeException) Lock(java.util.concurrent.locks.Lock) RowLock(com.baidu.hugegraph.concurrent.RowLock) KeyLock(com.baidu.hugegraph.concurrent.KeyLock)

Aggregations

HugeException (com.baidu.hugegraph.HugeException)59 Id (com.baidu.hugegraph.backend.id.Id)11 TimeoutException (java.util.concurrent.TimeoutException)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)4 File (java.io.File)4 Map (java.util.Map)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 ConfigException (com.baidu.hugegraph.config.ConfigException)3 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)3 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)3 StringReader (java.io.StringReader)3 PeerId (com.alipay.sofa.jraft.entity.PeerId)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)2 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)2