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();
});
}
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;
});
}
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);
}
}
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);
}
}
}
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;
}
Aggregations