use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class GraphIndexTransaction method queryByLabel.
@Watched(prefix = "index")
private IdHolderList queryByLabel(ConditionQuery query) {
HugeType queryType = query.resultType();
IndexLabel il = IndexLabel.label(queryType);
validateIndexLabel(il);
Id label = query.condition(HugeKeys.LABEL);
assert label != null;
HugeType indexType;
SchemaLabel schemaLabel;
if (queryType.isVertex()) {
indexType = HugeType.VERTEX_LABEL_INDEX;
schemaLabel = this.graph().vertexLabel(label);
} else if (queryType.isEdge()) {
indexType = HugeType.EDGE_LABEL_INDEX;
schemaLabel = this.graph().edgeLabel(label);
} else {
throw new HugeException("Can't query %s by label", queryType);
}
if (!this.store().features().supportsQueryByLabel() && !schemaLabel.enableLabelIndex()) {
throw new NoIndexException("Don't accept query by label '%s', " + "label index is disabled", schemaLabel);
}
ConditionQuery indexQuery = new ConditionQuery(indexType, query);
indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id());
indexQuery.eq(HugeKeys.FIELD_VALUES, label);
/*
* We can avoid redundant element ids if set limit, but if there are
* label index overridden by other vertices with different label,
* query with limit like g.V().hasLabel('xx').limit(10) may lose some
* results, so can't set limit here. But in this case, the following
* query results may be still different:
* g.V().hasLabel('xx').count() // label index count
* g.V().hasLabel('xx').limit(-1).count() // actual vertices count
* It’s a similar situation for the offset, like:
* g.V().hasLabel('xx').range(26, 27)
* g.V().hasLabel('xx').range(27, 28)
* we just reset limit here, but don't reset offset due to performance
* optimization with index+offset query, see Query.skipOffsetIfNeeded().
* NOTE: if set offset the backend itself will skip the offset
*/
indexQuery.copyBasic(query);
indexQuery.limit(Query.NO_LIMIT);
IdHolder idHolder = this.doIndexQuery(il, indexQuery);
IdHolderList holders = new IdHolderList(query.paging());
holders.add(idHolder);
return holders;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class AbstractComputer method call.
@Override
public Object call(Job<Object> job, Map<String, Object> parameters) {
this.checkAndCollectParameters(parameters);
// Read configuration
try {
this.initializeConfig((ComputerJob) job);
} catch (Exception e) {
throw new HugeException("Failed to initialize computer config file", e);
}
// Set current computer job's specified parameters
Map<String, Object> configs = new HashMap<>();
configs.putAll(this.commonConfig);
configs.putAll(this.checkAndCollectParameters(parameters));
// Construct shell command for computer job
String[] command = this.constructShellCommands(configs);
LOG.info("Execute computer job: {}", String.join(SPACE, command));
// Execute current computer
try {
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true);
builder.directory(new File(executeDir()));
Process process = builder.start();
StringBuilder output = new StringBuilder();
try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
}
int exitCode = process.waitFor();
if (exitCode == 0) {
return 0;
}
throw new HugeException("The computer job exit with code %s: %s", exitCode, output);
} catch (HugeException e) {
throw e;
} catch (Throwable e) {
throw new HugeException("Failed to execute computer job", e);
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class RamTable method loadFromDB.
private void loadFromDB() throws Exception {
Query query = new Query(HugeType.VERTEX);
query.capacity(this.verticesCapacityHalf * 2L);
query.limit(Query.NO_LIMIT);
Iterator<Vertex> vertices = this.graph.vertices(query);
// switch concurrent loading here
boolean concurrent = true;
if (concurrent) {
try (LoadTraverser traverser = new LoadTraverser()) {
traverser.load(vertices);
}
return;
}
Iterator<Edge> adjEdges;
Id lastId = IdGenerator.ZERO;
while (vertices.hasNext()) {
Id vertex = (Id) vertices.next().id();
LOG.info("scan from hbase {} loadfromDB", vertex);
if (vertex.compareTo(lastId) < 0) {
throw new HugeException("The ramtable feature is not " + "supported by %s backend", this.graph.backend());
}
ensureNumberId(vertex);
lastId = vertex;
adjEdges = this.graph.adjacentEdges(vertex);
if (adjEdges.hasNext()) {
HugeEdge edge = (HugeEdge) adjEdges.next();
this.addEdge(true, edge);
}
while (adjEdges.hasNext()) {
HugeEdge edge = (HugeEdge) adjEdges.next();
this.addEdge(false, edge);
}
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class RaftSharedContext method endpoint.
public PeerId endpoint() {
PeerId endpoint = new PeerId();
String endpointStr = this.config().get(CoreOptions.RAFT_ENDPOINT);
if (!endpoint.parse(endpointStr)) {
throw new HugeException("Failed to parse endpoint %s", endpointStr);
}
return endpoint;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class IndexLabelBuilder method create.
/**
* Create index label with sync mode
*/
@Override
public IndexLabel create() {
// Create index label async
SchemaElement.TaskWithSchema createdIndexLabel = this.createWithTask();
Id task = createdIndexLabel.task();
if (task == IdGenerator.ZERO) {
/*
* Task id will be IdGenerator.ZERO if creating index label
* already exists or creating index label is for olap
*/
return createdIndexLabel.indexLabel();
}
// Wait task completed (change to sync mode)
HugeGraph graph = this.graph();
long timeout = graph.option(CoreOptions.TASK_WAIT_TIMEOUT);
try {
graph.taskScheduler().waitUntilTaskCompleted(task, timeout);
} catch (TimeoutException e) {
throw new HugeException("Failed to wait index-creating task completed", e);
}
// Return index label without task-info
return createdIndexLabel.indexLabel();
}
Aggregations