@Override public void lock(Duration timeout) { boolean success = false; try { success = super.tryLock(timeout.toNanos(), TimeUnit.NANOSECONDS); } catch (InterruptedException e) { log.warn("Interrupted waiting for lock: {}",e); } if (!success) throw new JanusGraphException("Possible dead lock detected. Waited for transaction lock without success"); }
@Override public String toString() { return super.toString() + " [" + element.toString() + "]"; }
@Test public void testOrForceIndexComposite() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); final PropertyKey ageProperty = management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("ageridx", Vertex.class).addKey(ageProperty).buildCompositeIndex(); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); g.V().has("age", P.gte(4).or(P.lt(2))).hasNext(); fail("should fail"); } catch (final JanusGraphException e){ assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled")); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } } }
/** * Executes a method which has the potential to throw a {@link TemporaryLockingException} or a {@link PermanentLockingException}. * If the exception is thrown it is wrapped in a {@link GraknBackendException} so that the transaction can be retried. * * @param method The locking method to execute */ private <X> X executeLockingMethod(Supplier<X> method){ try { return method.get(); } catch (JanusGraphException e){ if(e.isCausedBy(TemporaryLockingException.class) || e.isCausedBy(PermanentLockingException.class)){ throw TemporaryWriteException.temporaryLock(e); } else { throw GraknBackendException.unknown(e); } } }
@Test public void testOrForceIndexPartialIndex() throws Exception { JanusGraph customGraph = null; try { customGraph = this.getForceIndexGraph(); final JanusGraphManagement management = customGraph.openManagement(); final PropertyKey stringProperty = management.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); management.makePropertyKey("age").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); management.buildIndex("oridx", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); management.commit(); customGraph.tx().commit(); final GraphTraversalSource g = customGraph.traversal(); g.addV().property("name", "Hiro").property("age", 2).next(); g.addV().property("name", "Totoro").property("age", 1).next(); customGraph.tx().commit(); g.V().or(__.has("name", "Totoro"),__.has("age", 2)).hasNext(); fail("should fail"); } catch (final JanusGraphException e){ assertTrue(e.getMessage().contains("Could not find a suitable index to answer graph query and graph scans are disabled")); } finally { if (customGraph != null) { JanusGraphFactory.close(customGraph); } } }
public static <V> V execute(Callable<V> exe, Duration totalWaitTime) throws JanusGraphException { try { return executeDirect(exe,totalWaitTime); } catch (BackendException e) { throw new JanusGraphException("Could not execute operation due to backend exception",e); } }
public static JanusGraph getGraphInstance() { if (graphInstance == null) { synchronized (AtlasJanusGraphDatabase.class) { if (graphInstance == null) { Configuration config; try { config = getConfiguration(); } catch (AtlasException e) { throw new RuntimeException(e); } try { graphInstance = JanusGraphFactory.open(config); } catch (JanusGraphException e) { LOG.warn("JanusGraphException: {}", e.getMessage()); if (e.getMessage().startsWith(OLDER_STORAGE_EXCEPTION)) { LOG.info("Newer client is being used with older janus storage version. Setting allow-upgrade=true and reattempting connection"); config.addProperty("graph.allow-upgrade", true); graphInstance = JanusGraphFactory.open(config); } } atlasGraphInstance = new AtlasJanusGraph(); validateIndexBackend(config); } } } return graphInstance; }
public void closeLogManager(String logManagerName) { if (logManagers.containsKey(logManagerName)) { try { logManagers.remove(logManagerName).close(); } catch (final BackendException e) { throw new JanusGraphException("Could not close log manager " + logManagerName,e); } } }
public Log getSystemMgmtLog() { try { return managementLogManager.openLog(SYSTEM_MGMT_LOG_NAME); } catch (BackendException e) { throw new JanusGraphException("Could not re-open management log", e); } }
@Override public void add(StaticBuffer key, Entry cell) { try { kcvs.mutateEntries(key, Lists.newArrayList(cell), KCVSCache.NO_DELETIONS,tx); } catch (BackendException e) { throw new JanusGraphException("Unexpected storage exception in log persistence against cache",e); } } }
public KCVSLog getSystemTxLog() { try { return txLogManager.openLog(SYSTEM_TX_LOG_NAME); } catch (BackendException e) { throw new JanusGraphException("Could not re-open transaction log", e); } }
@Override public synchronized void shutdown() throws JanusGraphException { if (!isOpen) return; isOpen = false; try { for (Log log : processorLogs.values()) { log.close(); } processorLogs.clear(); } catch (BackendException e) { throw new JanusGraphException(e); } }
@Override public synchronized void close() { closed=true; try { waitForIDBlockGetter(); } catch (InterruptedException e) { throw new JanusGraphException("Interrupted while waiting for id renewer thread to finish", e); } for (Future<?> closeBlocker : closeBlockers) { try { closeBlocker.get(); } catch (InterruptedException e) { throw new JanusGraphException("Interrupted while waiting for runaway ID renewer task " + closeBlocker, e); } catch (ExecutionException e) { log.debug("Runaway ID renewer task completed with exception", e); } } exec.shutdownNow(); }
@Override public synchronized boolean removeLogProcessor(String logIdentifier) { checkOpen(); if (processorLogs.containsKey(logIdentifier)) { try { processorLogs.get(logIdentifier).close(); } catch (BackendException e) { throw new JanusGraphException("Could not close transaction log: "+ logIdentifier,e); } processorLogs.remove(logIdentifier); return true; } else return false; }
private void closeLogs() { try { for (final LogManager lm : logManagers.values()) lm.close(); logManagers.clear(); if (logStoreManager!=null) { logStoreManager.close(); logStoreManager=null; } } catch (final BackendException e) { throw new JanusGraphException(e); } }
@Override public IDBlock call() { Stopwatch running = Stopwatch.createStarted(); try { if (stopRequested) { log.debug("Aborting ID block retrieval on partition({})-namespace({}) after " + "graceful shutdown was requested, exec time {}, exec+q time {}", partition, idNamespace, running.stop(), alive.stop()); throw new JanusGraphException("ID block retrieval aborted by caller"); } IDBlock idBlock = idAuthority.getIDBlock(partition, idNamespace, renewTimeout); log.debug("Retrieved ID block from authority on partition({})-namespace({}), " + "exec time {}, exec+q time {}", partition, idNamespace, running.stop(), alive.stop()); Preconditions.checkArgument(idBlock!=null && idBlock.numIds()>0); return idBlock; } catch (BackendException e) { throw new JanusGraphException("Could not acquire new ID block from storage", e); } catch (IDPoolExhaustedException e) { return ID_POOL_EXHAUSTION; } } }
String msg = String.format("ID block allocation on partition(%d)-namespace(%d) failed with an exception in %s", partition, idNamespace, sw.stop()); throw new JanusGraphException(msg, e); } catch (TimeoutException e) { String msg = String.format("ID block allocation on partition(%d)-namespace(%d) timed out in %s", throw new JanusGraphException(msg, e); } catch (CancellationException e) { String msg = String.format("ID block allocation on partition(%d)-namespace(%d) was cancelled after %s", partition, idNamespace, sw.stop()); throw new JanusGraphException(msg, e); } finally { idBlockFuture = null;
@Override public synchronized Future<Message> add(StaticBuffer content) { final TestMessage msg = new TestMessage(content); final FutureMessage<TestMessage> fmsg = new FutureMessage<>(msg); if (failAdds) { System.out.println("Failed message add"); throw new JanusGraphException("Log unavailable"); } if (readers.isEmpty()) { messageBacklog.add(fmsg); } else { process(fmsg); } return fmsg; }
public SubqueryIterator(JointIndexQuery.Subquery subQuery, IndexSerializer indexSerializer, BackendTransaction tx, Cache<JointIndexQuery.Subquery, List<Object>> indexCache, int limit, Function<Object, ? extends JanusGraphElement> function, List<Object> otherResults) { this.subQuery = subQuery; this.indexCache = indexCache; final List<Object> cacheResponse = indexCache.getIfPresent(subQuery); final Stream<?> stream; if (cacheResponse != null) { stream = cacheResponse.stream(); } else { try { currentIds = new ArrayList<>(); profiler = QueryProfiler.startProfile(subQuery.getProfiler(), subQuery); isTimerRunning = true; stream = indexSerializer.query(subQuery, tx).peek(r -> currentIds.add(r)); } catch (final Exception e) { throw new JanusGraphException("Could not call index", e.getCause()); } } elementIterator = stream.filter(e -> otherResults == null || otherResults.contains(e)).limit(limit).map(function).map(r -> (JanusGraphElement) r).iterator(); }
subResult = call.call(subLimit); } catch (final Exception e) { throw new JanusGraphException("Could not process individual retrieval call ", e);