@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"); }
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 KCVSLog getSystemTxLog() { try { return txLogManager.openLog(SYSTEM_TX_LOG_NAME); } catch (BackendException e) { throw new JanusGraphException("Could not re-open transaction log", e); } }
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); } } }
@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; } } }
@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; }
@Override public void close() { try { store.close(); txProvider.close(); IOUtils.closeQuietly(serializer); } catch (BackendException e) { throw new JanusGraphException("Could not close configuration store",e); } }
public StandardJanusGraphTx newTransaction(final TransactionConfiguration configuration) { if (!isOpen) ExceptionFactory.graphShutdown(); try { StandardJanusGraphTx tx = new StandardJanusGraphTx(this, configuration); tx.setBackendTransaction(openBackendTransaction(tx)); openTransactions.add(tx); return tx; } catch (BackendException e) { throw new JanusGraphException("Could not start new transaction", e); } }
private static KCVSConfiguration getConfiguration(final BackendOperation.TransactionalProvider txProvider, final KeyColumnValueStore store, final String identifier, final Configuration config) { try { KCVSConfiguration keyColumnValueStoreConfiguration = new KCVSConfiguration(txProvider,config,store,identifier); keyColumnValueStoreConfiguration.setMaxOperationWaitTime(config.get(SETUP_WAITTIME)); return keyColumnValueStoreConfiguration; } catch (BackendException e) { throw new JanusGraphException("Could not open global configuration",e); } }
private void checkBackwardCompatibilityWithTitan(ModifiableConfiguration globalWrite, BasicConfiguration localBasicConfiguration, KCVSConfiguration keyColumnValueStoreConfiguration, ModifiableConfiguration overwrite) { String version = globalWrite.get(TITAN_COMPATIBLE_VERSIONS); Preconditions.checkArgument(version!=null,"JanusGraph version nor Titan compatibility have not been initialized"); if (!JanusGraphConstants.TITAN_COMPATIBLE_VERSIONS.contains(version)) { throw new JanusGraphException(String.format(INCOMPATIBLE_VERSION_EXCEPTION, version, JanusGraphConstants.VERSION)); } // When connecting to a store created by Titan the ID store name will not be in the // global configuration as it was not something which was configurable with Titan. // So to ensure compatibility override the default to titan_ids. boolean localIdStoreIsDefault = JanusGraphConstants.JANUSGRAPH_ID_STORE_NAME.equals(localBasicConfiguration.get(IDS_STORE_NAME)); boolean usingTitanIdStore = localIdStoreIsDefault || JanusGraphConstants.TITAN_ID_STORE_NAME.equals(localBasicConfiguration.get(IDS_STORE_NAME)); boolean existingKeyStore = keyColumnValueStoreConfiguration.get(IDS_STORE_NAME.getName(), IDS_STORE_NAME.getDatatype()) != null; Preconditions.checkArgument(usingTitanIdStore,"ID store for Titan compatibility has not been initialized to: " + JanusGraphConstants.TITAN_ID_STORE_NAME); if (!existingKeyStore) { log.info("Setting {} to {} for Titan compatibility", IDS_STORE_NAME.getName(), JanusGraphConstants.TITAN_ID_STORE_NAME); overwrite.set(IDS_STORE_NAME, JanusGraphConstants.TITAN_ID_STORE_NAME); } }
public static KCVSConfiguration getStandaloneGlobalConfiguration(final KeyColumnValueStoreManager manager, final Configuration config) { try { final StoreFeatures features = manager.getFeatures(); return getGlobalConfiguration(new BackendOperation.TransactionalProvider() { @Override public StoreTransaction openTx() throws BackendException { return manager.beginTransaction(StandardBaseTransactionConfig.of(config.get(TIMESTAMP_PROVIDER),features.getKeyConsistentTxConfig())); } @Override public void close() throws BackendException { manager.close(); } },manager.openDatabase(SYSTEM_PROPERTIES_STORE_NAME),config); } catch (BackendException e) { throw new JanusGraphException("Could not open global configuration",e); } }
@Override public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh) throws BackendException { incActionBy(1, CacheMetricsAction.RETRIEVAL,txh); if (isExpired(query)) { incActionBy(1, CacheMetricsAction.MISS,txh); return store.getSlice(query, unwrapTx(txh)); } try { return cache.get(query, () -> { incActionBy(1, CacheMetricsAction.MISS,txh); return store.getSlice(query, unwrapTx(txh)); }); } catch (Exception e) { if (e instanceof JanusGraphException) throw (JanusGraphException)e; else if (e.getCause() instanceof JanusGraphException) throw (JanusGraphException)e.getCause(); else throw new JanusGraphException(e); } }
@Override public synchronized void rollback() { Preconditions.checkArgument(isOpen(), "The transaction has already been closed"); boolean success = false; if (null != config.getGroupName()) { MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "rollback").inc(); } try { txHandle.rollback(); success = true; } catch (Exception e) { throw new JanusGraphException("Could not rollback transaction due to exception", e); } finally { releaseTransaction(); if (null != config.getGroupName() && !success) { MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "rollback.exceptions").inc(); } } }
@Override public synchronized long nextID() { assert currentIndex <= currentBlock.numIds(); if (currentIndex == currentBlock.numIds()) { try { nextBlock(); } catch (InterruptedException e) { throw new JanusGraphException("Could not renew id block due to interruption", e); } } if (currentIndex == renewBlockIndex) { startIDBlockGetter(); } long returnId = currentBlock.getId(currentIndex); currentIndex++; if (returnId >= idUpperBound) throw new IDPoolExhaustedException("Reached id upper bound of " + idUpperBound); log.trace("partition({})-namespace({}) Returned id: {}", partition, idNamespace, returnId); return returnId; }