use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class IndexRepairJob method workerIterationEnd.
@Override
public void workerIterationEnd(final ScanMetrics metrics) {
try {
if (index instanceof JanusGraphIndex) {
BackendTransaction mutator = writeTx.getTxHandle();
IndexType indexType = managementSystem.getSchemaVertex(index).asIndexType();
if (indexType.isMixedIndex() && documentsPerStore.size() > 0) {
mutator.getIndexTransaction(indexType.getBackingIndexName()).restore(documentsPerStore);
documentsPerStore = new HashMap<>();
}
}
} catch (BackendException e) {
throw new JanusGraphException(e.getMessage(), e);
} finally {
super.workerIterationEnd(metrics);
}
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class JanusGraphAbstractAuthenticator method setup.
@Override
public void setup(final Map<String, Object> config) {
logger.info("Initializing authentication with the {}", this.getClass().getName());
Preconditions.checkArgument(config != null, "Could not configure a %s - provide a 'config' in the 'authentication' settings", this.getClass().getName());
Preconditions.checkState(config.containsKey(CONFIG_CREDENTIALS_DB), "Credential configuration missing the %s key that points to a graph config file or graph name", CONFIG_CREDENTIALS_DB);
Preconditions.checkState(config.containsKey(CONFIG_DEFAULT_USER), "Credential configuration missing the %s key for the default user", CONFIG_DEFAULT_USER);
Preconditions.checkState(config.containsKey(CONFIG_DEFAULT_PASSWORD), "Credential configuration missing the %s key for the default password", CONFIG_DEFAULT_PASSWORD);
final JanusGraph graph = openGraph(config.get(CONFIG_CREDENTIALS_DB).toString());
credentials = createCredentials(graph);
graph.tx().rollback();
ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
if (!mgmt.containsGraphIndex(USERNAME_INDEX_NAME)) {
final PropertyKey username = mgmt.makePropertyKey(PROPERTY_USERNAME).dataType(String.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex(USERNAME_INDEX_NAME, Vertex.class).addKey(username).unique().buildCompositeIndex();
mgmt.commit();
mgmt = (ManagementSystem) graph.openManagement();
final JanusGraphIndex index = mgmt.getGraphIndex(USERNAME_INDEX_NAME);
if (!index.getIndexStatus(username).equals(SchemaStatus.ENABLED)) {
try {
mgmt = (ManagementSystem) graph.openManagement();
mgmt.updateIndex(mgmt.getGraphIndex(USERNAME_INDEX_NAME), SchemaAction.REINDEX);
ManagementSystem.awaitGraphIndexStatus(graph, USERNAME_INDEX_NAME).status(SchemaStatus.ENABLED).call();
mgmt.commit();
} catch (InterruptedException rude) {
mgmt.rollback();
throw new RuntimeException("Timed out waiting for byUsername index to be created on credential graph", rude);
}
}
}
final String defaultUser = config.get(CONFIG_DEFAULT_USER).toString();
if (!userExists(defaultUser)) {
createUser(defaultUser, config.get(CONFIG_DEFAULT_PASSWORD).toString());
}
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class ManagementSystem method setConsistency.
/**
* Sets the consistency level for those schema elements that support it (types and internal indexes)
* <p>
* Note, that it is possible to have a race condition here if two threads simultaneously try to change the
* consistency level. However, this is resolved when the consistency level is being read by taking the
* first one and deleting all existing attached consistency levels upon modification.
*
* @param element
* @param consistency
*/
@Override
public void setConsistency(JanusGraphSchemaElement element, ConsistencyModifier consistency) {
if (element instanceof RelationType) {
RelationTypeVertex rv = (RelationTypeVertex) element;
Preconditions.checkArgument(consistency != ConsistencyModifier.FORK || !rv.multiplicity().isConstrained(), "Cannot apply FORK consistency mode to constraint relation type: %s", rv.name());
} else if (element instanceof JanusGraphIndex) {
IndexType index = ((JanusGraphIndexWrapper) element).getBaseIndex();
if (index.isMixedIndex())
throw new IllegalArgumentException("Cannot change consistency on mixed index: " + element);
} else
throw new IllegalArgumentException("Cannot change consistency of schema element: " + element);
setTypeModifier(element, ModifierType.CONSISTENCY, consistency);
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class ManagementSystem method updateIndex.
@Override
public ScanJobFuture updateIndex(Index index, SchemaAction updateAction, int numOfThreads) {
Preconditions.checkArgument(index != null, "Need to provide an index");
Preconditions.checkArgument(updateAction != null, "Need to provide update action");
JanusGraphSchemaVertex schemaVertex = getSchemaVertex(index);
Set<JanusGraphSchemaVertex> dependentTypes;
Set<PropertyKeyVertex> keySubset = Collections.emptySet();
if (index instanceof RelationTypeIndex) {
dependentTypes = Collections.singleton((JanusGraphSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
} else if (index instanceof JanusGraphIndex) {
IndexType indexType = schemaVertex.asIndexType();
dependentTypes = new HashSet<>();
if (indexType.isCompositeIndex()) {
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
for (PropertyKey key : ((JanusGraphIndex) index).getFieldKeys()) {
dependentTypes.add((PropertyKeyVertex) key);
}
} else {
keySubset = new HashSet<>();
MixedIndexType mixedIndexType = (MixedIndexType) indexType;
Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
for (ParameterIndexField field : mixedIndexType.getFieldKeys()) {
if (applicableStatus.contains(field.getStatus()))
keySubset.add((PropertyKeyVertex) field.getFieldKey());
}
if (keySubset.isEmpty())
return null;
dependentTypes.addAll(keySubset);
}
} else
throw new UnsupportedOperationException("Updates not supported for index: " + index);
IndexIdentifier indexId = new IndexIdentifier(index);
StandardScanner.Builder builder;
ScanJobFuture future;
switch(updateAction) {
case REGISTER_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
future = new EmptyScanJobFuture();
break;
case REINDEX:
builder = graph.getBackend().buildEdgeScanJob();
builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
builder.setJobId(indexId);
builder.setNumProcessingThreads(numOfThreads);
builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
try {
future = builder.execute();
} catch (BackendException e) {
throw new JanusGraphException(e);
}
break;
case ENABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
future = new EmptyScanJobFuture();
break;
case DISABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
future = new EmptyScanJobFuture();
break;
case REMOVE_INDEX:
if (index instanceof RelationTypeIndex) {
builder = graph.getBackend().buildEdgeScanJob();
} else {
JanusGraphIndex graphIndex = (JanusGraphIndex) index;
if (graphIndex.isMixedIndex())
throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
builder = graph.getBackend().buildGraphIndexScanJob();
}
builder.setFinishJob(indexId.getIndexJobFinisher());
builder.setJobId(indexId);
builder.setNumProcessingThreads(numOfThreads);
builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
try {
future = builder.execute();
} catch (BackendException e) {
throw new JanusGraphException(e);
}
break;
default:
throw new UnsupportedOperationException("Update action not supported: " + updateAction);
}
return future;
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class ManagementSystem method printIndexes.
private String printIndexes(boolean calledDirectly) {
StringBuilder sb = new StringBuilder();
String pattern = "%-30s | %-11s | %-9s | %-14s | %-10s %10s |%n";
String relationPattern = "%-30s | %-11s | %-9s | %-14s | %-8s | %10s |%n";
Iterable<JanusGraphIndex> vertexIndexes = getGraphIndexes(Vertex.class);
Iterable<JanusGraphIndex> edgeIndexes = getGraphIndexes(Edge.class);
Iterable<RelationType> relationTypes = getRelationTypes(RelationType.class);
LinkedList<RelationTypeIndex> relationIndexes = new LinkedList<>();
for (RelationType rt : relationTypes) {
Iterable<RelationTypeIndex> rti = getRelationIndexes(rt);
rti.forEach(relationIndexes::add);
}
if (calledDirectly) {
sb.append(FIRSTDASH);
} else {
sb.append(DASHBREAK);
}
sb.append(String.format(pattern, "Graph Index (Vertex)", "Type", "Unique", "Backing", "Key:", "Status"));
sb.append(DASHBREAK);
sb.append(iterateIndexes(pattern, vertexIndexes));
sb.append(DASHBREAK);
sb.append(String.format(pattern, "Graph Index (Edge)", "Type", "Unique", "Backing", "Key:", "Status"));
sb.append(DASHBREAK);
sb.append(iterateIndexes(pattern, edgeIndexes));
sb.append(DASHBREAK);
sb.append(String.format(relationPattern, "Relation Index (VCI)", "Type", "Direction", "Sort Key", "Order", "Status"));
sb.append(DASHBREAK);
for (RelationTypeIndex ri : relationIndexes) {
sb.append(String.format(relationPattern, ri.name(), ri.getType(), ri.getDirection(), ri.getSortKey()[0], ri.getSortOrder(), ri.getIndexStatus().name()));
}
if (!relationIndexes.isEmpty()) {
sb.append(DASHBREAK);
}
return sb.toString();
}
Aggregations