org.janusgraph.graphdb.database.StandardJanusGraph Java Examples
The following examples show how to use
org.janusgraph.graphdb.database.StandardJanusGraph.
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 restoreSelective(String guid) throws Exception { Set<String> referencedGUIDs = new HashSet<>(getEntityAndReferenceGuids(guid)); displayCrlf("processing referencedGuids => "+ referencedGUIDs); StandardJanusGraph janusGraph = (StandardJanusGraph) graph; IndexSerializer indexSerializer = janusGraph.getIndexSerializer(); for (String indexName : getIndexes()){ displayCrlf("Restoring: " + indexName); long startTime = System.currentTimeMillis(); reindexVertex(indexName, indexSerializer, referencedGUIDs); display(": Time taken: " + (System.currentTimeMillis() - startTime) + " ms"); displayCrlf(": Done!"); } }
Example #2
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 6 votes |
public AtlasJanusGraph(JanusGraph graphInstance) { //determine multi-properties once at startup JanusGraphManagement mgmt = null; try { mgmt = graphInstance.openManagement(); Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class); for (PropertyKey key : keys) { if (key.cardinality() != Cardinality.SINGLE) { multiProperties.add(key.name()); } } } finally { if (mgmt != null) { mgmt.rollback(); } } janusGraph = (StandardJanusGraph) graphInstance; }
Example #3
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
@Test public void processTripleWithTraversals() throws BackendException { tripleIngestBase((StandardJanusGraph graph, List<Triple> lines) -> { final GraphTraversalSource g = graph.traversal(); lines.parallelStream().forEach(triple -> { final Vertex left = getVertexIfDoesntExist(g, triple.getLeftPropertyName(), triple.getLeftPropertyValue()); final Vertex right = getVertexIfDoesntExist(g, triple.getRightPropertyName(), triple.getRightPropertyValue()); //your original method was creating vertices in the processRelationship method. //this caused the uniqueness constraint violation (one of a few issues in your //original code) because you have a unique index on the rightPropertyName g.V() .is(left) .outE(triple.getRelationship().name()) .filter(inV().is(right)) .tryNext() .orElseGet(() -> left.addEdge(triple.getRelationship().name(), right)); }); final Stopwatch watch = Stopwatch.createStarted(); g.tx().commit(); log.info("Committed in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms"); watch.stop(); }); }
Example #4
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
private void demonstrateLockExpiry(final StandardJanusGraph graph, final boolean useNativeLocking, final long waitMillis) throws TemporaryLockingException, InterruptedException { //BEGIN code from first code listing graph.addVertex(T.label, DATABASE_METADATA_LABEL).property(VERSION_PROPERTY, VERSION_ONE); if(useNativeLocking) { System.out.println("regular tx one " + getTxFromGraph(graph).toString() + " " + System.currentTimeMillis()); } graph.tx().commit(); final GraphTraversalSource g = graph.traversal(); g.V().hasLabel(DATABASE_METADATA_LABEL).has(VERSION_PROPERTY, VERSION_ONE).property(VERSION_PROPERTY, VERSION_TWO).next(); if(useNativeLocking) { System.out.println("regular tx two " + getTxFromGraph(graph).toString() + " " + System.currentTimeMillis()); } g.tx().commit(); Thread.sleep(waitMillis); //wait for the lock to expire g.V().hasLabel(DATABASE_METADATA_LABEL).has(VERSION_PROPERTY, VERSION_TWO).property(VERSION_PROPERTY, VERSION_THREE).next(); if(useNativeLocking) { System.out.println("regular tx three " + getTxFromGraph(graph).toString() + " " + System.currentTimeMillis()); } g.tx().commit(); //END code from first code listing }
Example #5
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
private void tripleIngestBase(final BiConsumer<StandardJanusGraph, List<Triple>> writer) throws BackendException { final Stopwatch watch = Stopwatch.createStarted(); final StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open(TestGraphUtil.instance.createTestGraphConfig(BackendDataModel.MULTI)); log.info("Created graph in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms"); watch.reset(); watch.start(); createHotelSchema(graph); log.info("Created schema in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms"); watch.reset(); watch.start(); final URL url = ScenarioTests.class.getClassLoader().getResource("META-INF/HotelTriples.txt"); Preconditions.checkNotNull(url); final List<Triple> lines; try (CSVReader reader = new CSVReader(new InputStreamReader(url.openStream()))) { lines = reader.readAll().stream() .map(Triple::new) .collect(Collectors.toList()); } catch (IOException e) { throw new IllegalStateException("Error processing triple file", e); } log.info("Read file into Triple objects in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms"); watch.reset(); watch.start(); writer.accept(graph, lines); log.info("Added objects in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms"); TestGraphUtil.instance.cleanUpTables(); }
Example #6
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
@Test public void processTripleWithMaps() throws BackendException { final ConcurrentMap<String, Vertex> brandTypeMap = new ConcurrentHashMap<>(); final ConcurrentMap<String, Vertex> companyMap = new ConcurrentHashMap<>(); final ConcurrentMap<String, Vertex> hotelBrandMap = new ConcurrentHashMap<>(); tripleIngestBase((StandardJanusGraph graph, List<Triple> triples) -> { final JanusGraphTransaction threadedGraph = graph.newTransaction(); triples.parallelStream().forEach(triple -> { final Vertex outV = hotelBrandMap.computeIfAbsent(triple.getLeftPropertyValue(), value -> threadedGraph.addVertex(triple.getLeftPropertyName(), value)); //your original method was creating vertices in the processRelationship method. //this caused the uniqueness constraint violation (one of a few issues in your //original code) because you have a unique index on the rightPropertyName switch (triple.getRelationship()) { case hotelBrandType: outV.addEdge("hotelBrandType",brandTypeMap.computeIfAbsent(triple.getRightPropertyValue(), value -> threadedGraph.addVertex(triple.getRightPropertyName(), value))); break; case instanceOf: outV.addEdge("instanceOf", companyMap.computeIfAbsent(triple.getRightPropertyValue(), value -> threadedGraph.addVertex(triple.getRightPropertyName(), value))); break; default: throw new IllegalArgumentException("unexpected relationship type"); } }); final Stopwatch watch = Stopwatch.createStarted(); threadedGraph.commit(); log.info("Committed in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms"); watch.stop(); }); }
Example #7
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
private void createSchemaAndDemoLockExpiry(final boolean useNativeLocking, final boolean useEdgestoreLocking, final boolean useGraphindexLocking, final long waitMillis) throws BackendException { try { final StandardJanusGraph graph = (StandardJanusGraph) createGraphWithSchema(useNativeLocking, useEdgestoreLocking, useGraphindexLocking, waitMillis); demonstrateLockExpiry(graph, useNativeLocking, waitMillis); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { TestGraphUtil.instance.cleanUpTables(); } }
Example #8
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 4 votes |
private static DynamoDbStoreTransaction getTxFromGraph(final StandardJanusGraph graph) { return DynamoDbStoreTransaction.getTx(((CacheTransaction) ((StandardJanusGraphTx) graph.getCurrentThreadTx()).getTxHandle().getStoreTransaction()).getWrappedTransaction()); }
Example #9
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 4 votes |
private JanusGraph initializeJanusGraph(boolean createMode, boolean enableListeners) { LOG.fine("Initializing graph."); Path lucene = graphDir.resolve("graphsearch"); Path berkeley = graphDir.resolve("titangraph"); // TODO: Externalize this. conf = new BaseConfiguration(); // Sets a unique id in order to fix WINDUP-697. This causes Titan to not attempt to generate and ID, // as the Titan id generation code fails on machines with broken network configurations. conf.setProperty("graph.unique-instance-id", "windup_" + System.nanoTime() + "_" + RandomStringUtils.randomAlphabetic(6)); conf.setProperty("storage.directory", berkeley.toAbsolutePath().toString()); conf.setProperty("storage.backend", "berkeleyje"); // Sets the berkeley cache to a relatively small value to reduce the memory footprint. // This is actually more important than performance on some of the smaller machines out there, and // the performance decrease seems to be minimal. conf.setProperty("storage.berkeleydb.cache-percentage", 1); // Set READ UNCOMMITTED to improve performance conf.setProperty("storage.berkeleydb.lock-mode", LockMode.READ_UNCOMMITTED); conf.setProperty("storage.berkeleydb.isolation-level", BerkeleyJEStoreManager.IsolationLevel.READ_UNCOMMITTED); // Increase storage write buffer since we basically do a large bulk load during the first phases. // See http://s3.thinkaurelius.com/docs/titan/current/bulk-loading.html conf.setProperty("storage.buffer-size", "4096"); // Turn off transactions to improve performance conf.setProperty("storage.transactions", false); conf.setProperty("ids.block-size", 25000); // conf.setProperty("ids.flush", true); // conf.setProperty("", false); // // turn on a db-cache that persists across txn boundaries, but make it relatively small conf.setProperty("cache.db-cache", true); conf.setProperty("cache.db-cache-clean-wait", 0); conf.setProperty("cache.db-cache-size", .09); conf.setProperty("cache.db-cache-time", 0); conf.setProperty("index.search.backend", "lucene"); conf.setProperty("index.search.directory", lucene.toAbsolutePath().toString()); writeToPropertiesFile(conf, graphDir.resolve("TitanConfiguration.properties").toFile()); JanusGraph janusGraph = JanusGraphFactory.open(conf); /* * We only need to setup the eventing system when initializing a graph, not when loading it later for * reporting. */ if (enableListeners) { TraversalStrategies graphStrategies = TraversalStrategies.GlobalCache .getStrategies(StandardJanusGraph.class) .clone(); // Remove any old listeners if (graphStrategies.getStrategy(EventStrategy.class) != null) graphStrategies.removeStrategies(EventStrategy.class); graphStrategies.addStrategies(EventStrategy.build().addListener(mutationListener).create()); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, graphStrategies); mutationListener.setGraph(this); } return janusGraph; }