/** * Removes the graph corresponding to the supplied graphName * from the {@link JanusGraphManager} graph reference tracker and * returns the corresponding Graph, or null if it doesn't exist. * * @param graphName Graph * @return JanusGraph */ public static JanusGraph close(String graphName) throws Exception { final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance(); Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG); final Graph graph = jgm.removeGraph(graphName); if (null != graph) graph.close(); return (JanusGraph) graph; }
/** * Removes {@link Graph} from {@link JanusGraphManager} graph reference tracker, if exists * there. * * @param graph Graph */ public static void close(Graph graph) throws Exception { final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance(); if (jgm != null) { jgm.removeGraph(((StandardJanusGraph) graph).getGraphName()); } graph.close(); }
@Override public void clear(Graph g, final Configuration configuration) throws Exception { if (null != g) { while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph(); JanusGraph graph = (JanusGraph) g; if (graph.isOpen()) { if (g.tx().isOpen()) g.tx().rollback(); try { g.close(); } catch (IOException | IllegalStateException e) { logger.warn("Titan graph may not have closed cleanly", e); } } } WriteConfiguration config = new CommonsConfiguration(configuration); BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE); if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) { JanusGraphBaseTest.clearGraph(config); } }
@Override public void clear(Graph g, final Configuration configuration) throws Exception { if (null != g) { while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph(); TitanGraph graph = (TitanGraph) g; if (graph.isOpen()) { if (g.tx().isOpen()) g.tx().rollback(); g.close(); } } WriteConfiguration config = new CommonsConfiguration(configuration); BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE); if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) { TitanGraphBaseTest.clearGraph(config); } }
@Override public void clear(final Graph graph, final Configuration configuration) throws Exception { if (graph != null) graph.close(); }
/** * {@inheritDoc} */ public final Graph removeGraph(final String graphName) throws Exception { Graph graph = graphs.remove(graphName); graph.close(); return graph; }
logger.debug("Closing Graph instance [{}]", gName); try { serverGremlinExecutor.getGraphManager().getGraph(gName).close(); } catch (Exception ex) { logger.warn(String.format("Exception while closing Graph instance [%s]", gName), ex);
@Override public void workerIterationStart(final Memory memory) { if (null == graph) { graph = GraphFactory.open(configuration.subset(WRITE_GRAPH_CFG_KEY)); LOGGER.info("Opened Graph instance: {}", graph); try { listener = new BulkLoadingListener(); g = graph.traversal().withStrategies(EventStrategy.build().addListener(listener).create()); } catch (Exception e) { try { graph.close(); } catch (Exception e2) { LOGGER.warn("Failed to close Graph instance", e2); } throw e; } } else { LOGGER.warn("Leaked Graph instance: {}", graph); } }
graph.close(); LOGGER.info("Closed Graph instance: {}", graph); graph = null;
@Override public void clear(final Graph graph, final Configuration configuration) throws Exception { if (graph != null) graph.close(); }
/** * {@inheritDoc} */ public final Graph removeGraph(final String graphName) throws Exception { Graph graph = graphs.remove(graphName); graph.close(); return graph; }
@Override protected void doDestroy() { try { g.close(); } catch (Exception e) { LOGGER.warn("An error occurred whilst closing the database", e); } }
@Test @LoadGraphWith(MODERN) public void shouldUseOneTimeBulkLoader() throws Exception { for (int iteration = 1; iteration <= 2; iteration++) { final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build() .bulkLoader(OneTimeBulkLoader.class) .writeGraph(getWriteGraphConfiguration()).create(graph); final BulkLoader loader = getBulkLoader(blvp); assertTrue(loader instanceof OneTimeBulkLoader); graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get(); final Graph result = getWriteGraph(); assertEquals(6 * iteration, IteratorUtils.count(result.vertices())); assertEquals(6 * iteration, IteratorUtils.count(result.edges())); result.close(); } }
@Test @LoadGraphWith(MODERN) public void shouldUseOneTimeBulkLoaderWithUserSuppliedIds() throws Exception { final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build() .bulkLoader(OneTimeBulkLoader.class) .userSuppliedIds(true) .writeGraph(getWriteGraphConfiguration()).create(graph); final BulkLoader loader = getBulkLoader(blvp); assertTrue(loader instanceof OneTimeBulkLoader); graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get(); final Graph result = getWriteGraph(); assertEquals(6, IteratorUtils.count(result.vertices())); assertEquals(6, IteratorUtils.count(result.edges())); result.close(); }
@Override public void finalize() throws Throwable { LOGGER.debug("calling close"); tGraph.close(); LOGGER.debug("close called"); super.finalize(); LOGGER.debug("after finalize"); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE) public void shouldPersistDataOnClose() throws Exception { final Vertex v = graph.addVertex(); final Vertex u = graph.addVertex(); if (graph.features().vertex().properties().supportsStringValues()) { v.property(VertexProperty.Cardinality.single, "name", "marko"); u.property(VertexProperty.Cardinality.single, "name", "pavel"); } final Edge e = v.addEdge(graphProvider.convertLabel("collaborator"), u); if (graph.features().edge().properties().supportsStringValues()) e.property("location", "internet"); tryCommit(graph, getAssertVertexEdgeCounts(2, 1)); graph.close(); final Graph reopenedGraph = graphProvider.standardTestGraph(this.getClass(), name.getMethodName(), null); assertVertexEdgeCounts(reopenedGraph, 2, 1); if (graph.features().vertex().properties().supportsStringValues()) { reopenedGraph.vertices().forEachRemaining(vertex -> { assertTrue(vertex.property("name").value().equals("marko") || vertex.property("name").value().equals("pavel")); }); } reopenedGraph.edges().forEachRemaining(edge -> { assertEquals(graphProvider.convertLabel("collaborator"), edge.label()); if (graph.features().edge().properties().supportsStringValues()) assertEquals("internet", edge.property("location").value()); }); graphProvider.clear(reopenedGraph, graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), null)); }
private void doClose() { try { g.close(); } catch (Exception e) { getMonitor().warn("Error closing graph " + g.configuration(), e); } finally { g = null; } } }
private void doClose() { try { g.close(); } catch (Exception e) { getMonitor().warn("Error closing graph " + g.configuration(), e); } finally { g = null; } } }
@Override public void closeDatabase() throws Exception { LOGGER.entering(getClass().getName(), "closeDatabase"); try { g.tx().commit(); while (g.tx().isOpen()) { g.tx().commit(); } } finally { g.close(); } }
/** * Closes the root session this graph stems from. This will automatically rollback any pending transactions. */ public void closeSession() { try { txCache().closeTx(ErrorMessage.SESSION_CLOSED.getMessage(keyspace())); getTinkerPopGraph().close(); } catch (Exception e) { throw GraknTxOperationException.closingFailed(this, e); } }