org.janusgraph.core.schema.JanusGraphIndex Java Examples
The following examples show how to use
org.janusgraph.core.schema.JanusGraphIndex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepairIndex.java From atlas with Apache License 2.0 | 6 votes |
private void restoreAll() throws Exception { for (String indexName : getIndexes()){ displayCrlf("Restoring: " + indexName); long startTime = System.currentTimeMillis(); ManagementSystem mgmt = (ManagementSystem) graph.openManagement(); JanusGraphIndex index = mgmt.getGraphIndex(indexName); mgmt.updateIndex(index, SchemaAction.REINDEX).get(); mgmt.commit(); ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).call(); display(": Time taken: " + (System.currentTimeMillis() - startTime) + " ms"); displayCrlf(": Done!"); } }
Example #2
Source File: RepairIndex.java From atlas with Apache License 2.0 | 6 votes |
private static void reindexVertex(String indexName, IndexSerializer indexSerializer, Set<String> entityGUIDs) throws Exception { Map<String, Map<String, List<IndexEntry>>> documentsPerStore = new java.util.HashMap<>(); ManagementSystem mgmt = (ManagementSystem) graph.openManagement(); StandardJanusGraphTx tx = mgmt.getWrappedTx(); BackendTransaction mutator = tx.getTxHandle(); JanusGraphIndex index = mgmt.getGraphIndex(indexName); MixedIndexType indexType = (MixedIndexType) mgmt.getSchemaVertex(index).asIndexType(); for (String entityGuid : entityGUIDs){ for (int attemptCount = 1; attemptCount <= MAX_TRIES_ON_FAILURE; attemptCount++) { AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(entityGuid); try { indexSerializer.reindexElement(vertex.getWrappedElement(), indexType, documentsPerStore); break; }catch (Exception e){ displayCrlf("Exception: " + e.getMessage()); displayCrlf("Pausing before retry.."); Thread.sleep(2000 * attemptCount); } } } mutator.getIndexTransaction(indexType.getBackingIndexName()).restore(documentsPerStore); }
Example #3
Source File: GraphDbObjectFactory.java From atlas with Apache License 2.0 | 5 votes |
/** * @param index The gremlin index. * @return */ public static AtlasGraphIndex createGraphIndex(JanusGraphIndex index) { if (index == null) { return null; } return new AtlasJanusGraphIndex(index); }
Example #4
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 5 votes |
String getIndexFieldName(AtlasPropertyKey propertyKey, JanusGraphIndex graphIndex, Parameter ... parameters) { PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(propertyKey); if(parameters == null) { parameters = EMPTY_PARAMETER_ARRAY; } return janusGraph.getIndexSerializer().getDefaultFieldName(janusKey, parameters, graphIndex.getBackingIndex()); }
Example #5
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 5 votes |
private Set<String> getIndexKeys(Class<? extends Element> janusGraphElementClass) { JanusGraphManagement mgmt = getGraph().openManagement(); Iterable<JanusGraphIndex> indices = mgmt.getGraphIndexes(janusGraphElementClass); Set<String> result = new HashSet<String>(); for (JanusGraphIndex index : indices) { result.add(index.name()); } mgmt.commit(); return result; }
Example #6
Source File: RecreateWeightIndex.java From janusgraph_tutorial with Apache License 2.0 | 5 votes |
private void reindexFor(String label, String propertyKey) throws BackendException, ExecutionException, InterruptedException { LOGGER.info("Reindexing index for edge {} and property {} using map reduce", label, propertyKey); MapReduceIndexManagement mr = new MapReduceIndexManagement(graph); JanusGraphIndex index = mgt.getGraphIndex(Schema.indexName(label, propertyKey)); mr.updateIndex(index, SchemaAction.REINDEX).get(); }
Example #7
Source File: GraphOMRSGraphFactory.java From egeria with Apache License 2.0 | 4 votes |
private boolean createControlIndex() { final String methodName = "createControlIndex"; // Prior to creating the control vertex - create an index to allow us to find it without a full scan JanusGraphManagement management = graph.openManagement(); String indexName = "controlIndex"; try { // Check if index exists JanusGraphIndex controlIndex = management.getGraphIndex(indexName); if (controlIndex == null) { log.info("{} index create {} for control vertex", methodName, indexName); // Property key should not already exist - but check it anyway. PropertyKey propertyKey = management.getPropertyKey(controlVertexIdPropertyName); if (propertyKey != null) { // Somehow - despite this being a new graph - the property key already exists. Stop. log.error("{} property key {} already exists", methodName, controlVertexIdPropertyName); management.rollback(); return false; } else { log.info("{} make property key {}", methodName, controlVertexIdPropertyName); propertyKey = management.makePropertyKey(controlVertexIdPropertyName).dataType(String.class).make(); } if (propertyKey == null) { // Could not create property key. Stop. log.error("{} property key {} could not be created", methodName, controlVertexIdPropertyName); management.rollback(); return false; } else { log.info("{} create index {}", methodName, indexName); JanusGraphManagement.IndexBuilder indexBuilder = management.buildIndex(indexName, Vertex.class).addKey(propertyKey).unique(); JanusGraphIndex index = indexBuilder.buildCompositeIndex(); management.setConsistency(index, ConsistencyModifier.LOCK); management.commit(); // Enable the index - set a relatively short timeout (10 s vs the default of 1 minute) log.info("{} await ENABLED for {}", methodName, indexName); ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).timeout(10, ChronoUnit.SECONDS).call(); return true; } } else { // That really should not be possible - a new graph should not have the index. Stop. log.error("{} control index already exists", methodName); management.rollback(); return false; } } catch (Exception e) { log.error("{} caught interrupted exception from awaitGraphIndexStatus ENABLED {}", methodName, e); management.rollback(); return false; } }
Example #8
Source File: AtlasJanusGraphIndex.java From atlas with Apache License 2.0 | 4 votes |
public AtlasJanusGraphIndex(JanusGraphIndex toWrap) { this.wrapped = toWrap; }
Example #9
Source File: RecreateWeightIndex.java From janusgraph_tutorial with Apache License 2.0 | 4 votes |
private void deleteIndex(String label, String propertyKey) { LOGGER.info("Deleting index for edge {} and property {}", label, propertyKey); JanusGraphIndex index = mgt.getGraphIndex(Schema.indexName(label, propertyKey)); mgt.updateIndex(index, SchemaAction.REMOVE_INDEX); }