public static File getOrCreateDataDirectory(String location, String childLocation) throws BackendException { final File storageDir; if (null != childLocation) { storageDir = new File(location, childLocation); } else { storageDir = new File(location); } if (storageDir.exists() && storageDir.isFile()) throw new PermanentBackendException(String.format("%s exists but is a file.", location)); if (!storageDir.exists() && !storageDir.mkdirs()) throw new PermanentBackendException(String.format("Failed to create directory %s for local storage.", location)); return storageDir; }
private void sleepAndConvertInterrupts(Duration d) throws BackendException { try { times.sleepPast(times.getTime().plus(d)); } catch (InterruptedException e) { throw new PermanentBackendException(e); } }
/** * Rolls back all transactions and makes sure that this does not get cut short * by exceptions. If exceptions occur, the storage exception takes priority on re-throw. * @throws BackendException */ @Override public void rollback() throws BackendException { Throwable exception = null; for (IndexTransaction itx : indexTx.values()) { try { itx.rollback(); } catch (Throwable e) { exception = e; } } storeTx.rollback(); if (exception!=null) { //throw any encountered index transaction rollback exceptions if (exception instanceof BackendException) throw (BackendException)exception; else throw new PermanentBackendException("Unexpected exception",exception); } }
throw (BackendException)e; } else { throw new PermanentBackendException("Permanent exception while executing backend operation "+exe.toString(),e); throw new PermanentBackendException("Interrupted while waiting to retry failed backend operation", r);
protected void sleepAfterWrite(StoreTransaction txh, MaskedTimestamp mustPass) throws BackendException { assert mustPass.getDeletionTime(times) < mustPass.getAdditionTime(times); try { times.sleepPast(mustPass.getAdditionTimeInstant(times)); } catch (InterruptedException e) { throw new PermanentBackendException("Unexpected interrupt", e); } }
+ " but mismatched timestamps; no lock column contained our timestamp (" + ls.getWriteTimestamp() + ")"; throw new PermanentBackendException(msg);
if (blocks == null) throw new TemporaryBackendException("Could not read from storage"); if (blocks.isEmpty()) throw new PermanentBackendException("It seems there is a race-condition in the block application. " + "If you have multiple JanusGraph instances running on one physical machine, ensure that they have unique machine idAuthorities");
@Override public void close() throws BackendException { try { client.close(); } catch (final IOException e) { throw new PermanentBackendException(e); } }
private BackendException convert(Exception esException) { if (esException instanceof InterruptedException) { return new TemporaryBackendException("Interrupted while waiting for response", esException); } else { return new PermanentBackendException("Unknown exception while executing index operation", esException); } }
@Override public boolean exists() throws BackendException { try { return client.indexExists(indexName); } catch (final IOException e) { throw new PermanentBackendException("Could not check if index " + indexName + " exists", e); } }
private <E> Stream<E> executeQuery(Integer limit, int offset, String collection, SolrQuery solrQuery, Function<SolrDocument, E> function) throws PermanentBackendException { try { final SolrResultIterator<E> resultIterator = new SolrResultIterator<>(solrClient, limit, offset, solrQuery.getRows(), collection, solrQuery, function); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(resultIterator, Spliterator.ORDERED), false); } catch (final IOException | UncheckedIOException e) { logger.error("Query did not complete : ", e); throw new PermanentBackendException(e); } catch (final SolrServerException | UncheckedSolrException e) { logger.error("Unable to query Solr index.", e); throw new PermanentBackendException(e); } }
/** * VAVR Future.await will throw InterruptedException wrapped in a FatalException. If the Thread was in Object.wait, the interrupted * flag will be cleared as a side effect and needs to be reset. This method checks that the underlying cause of the FatalException is * InterruptedException and resets the interrupted flag. * * @param result the future to wait on * @throws PermanentBackendException if the thread was interrupted while waiting for the future result */ private void interruptibleWait(final Future<?> result) throws PermanentBackendException { try { result.await(); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new PermanentBackendException(e); } }
private static int getPort(final Configuration config) throws BackendException { final String endpoint = JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT); int port = DEFAULT_PORT; if (endpoint != null && !endpoint.equals(Constants.DYNAMODB_CLIENT_ENDPOINT.getDefaultValue())) { final URL url; try { url = new URL(endpoint); } catch (IOException e) { throw new PermanentBackendException("Unable to determine port from endpoint: " + endpoint); } port = url.getPort(); } return port; }
private static String convertToJsType(Object value, String scriptLang, Mapping mapping) throws PermanentBackendException { final String esValue; try { esValue = mapWriter.writeValueAsString(convertToEsType(value, mapping)); } catch (final IOException e) { throw new PermanentBackendException("Could not write json"); } return scriptLang.equals("groovy") ? esValue.replace("$", "\\$") : esValue; }
private Map<String, String> parseKeyFieldsForCollections(Configuration config) throws BackendException { final Map<String, String> keyFieldNames = new HashMap<>(); final String[] collectionFieldStatements = config.has(KEY_FIELD_NAMES) ? config.get(KEY_FIELD_NAMES) : new String[0]; for (final String collectionFieldStatement : collectionFieldStatements) { final String[] parts = collectionFieldStatement.trim().split("="); if (parts.length != 2) { throw new PermanentBackendException( "Unable to parse the collection name / key field name pair. It should be of the format collection=field"); } final String collectionName = parts[0]; final String keyFieldName = parts[1]; keyFieldNames.put(collectionName, keyFieldName); } return keyFieldNames; }
public static String shortenCfName(BiMap<String, String> shortCfNameMap, String longName) throws PermanentBackendException { final String s; if (shortCfNameMap.containsKey(longName)) { s = shortCfNameMap.get(longName); Preconditions.checkNotNull(s); logger.debug("Substituted default CF name \"{}\" with short form \"{}\" to reduce HBase KeyValue size", longName, s); } else { if (shortCfNameMap.containsValue(longName)) { String fmt = "Must use CF long-form name \"%s\" instead of the short-form name \"%s\" when configured with %s=true"; String msg = String.format(fmt, shortCfNameMap.inverse().get(longName), longName, SHORT_CF_NAMES.getName()); throw new PermanentBackendException(msg); } s = longName; logger.debug("Kept default CF name \"{}\" because it has no associated short form", s); } return s; }
@Override public void clearStorage() throws BackendException { try { client.deleteIndex(indexName); } catch (final Exception e) { throw new PermanentBackendException("Could not delete index " + indexName, e); } finally { close(); } }
private BackendException processDynamoDbApiException(final Throwable e, final String apiName, final String tableName) { Preconditions.checkArgument(apiName != null); Preconditions.checkArgument(!apiName.isEmpty()); final String prefix; if (tableName == null) { prefix = apiName; } else { prefix = String.format("%s_%s", apiName, tableName); } final String message = String.format("%s %s", prefix, e.getMessage()); if (e instanceof ResourceNotFoundException) { return new BackendNotFoundException(String.format("%s; table not found", message), e); } else if (e instanceof ConditionalCheckFailedException) { return new PermanentLockingException(message, e); } else if (e instanceof AmazonServiceException) { if (e.getMessage() != null && (e.getMessage().contains(HASH_RANGE_KEY_SIZE_LIMIT) || e.getMessage().contains(UPDATE_ITEM_SIZE_LIMIT))) { return new PermanentBackendException(message, e); } else { return new TemporaryBackendException(message, e); } } else if (e instanceof AmazonClientException) { //all client exceptions are retriable by default return new TemporaryBackendException(message, e); } else if (e instanceof SocketException) { //sometimes this doesn't get caught by SDK return new TemporaryBackendException(message, e); } // unknown exception type return new PermanentBackendException(message, e); }
boolean ensureTableDeleted(final String tableName) throws BackendException { boolean successFlag = false; int retryCount = 0; do { try { this.describeTable(tableName); } catch (BackendNotFoundException e) { successFlag = true; break; } interruptibleSleep(CONTROL_PLANE_RETRY_DELAY_MS); retryCount++; } while (!successFlag && retryCount < maxRetries); if (!successFlag) { throw new PermanentBackendException("Table deletion not completed after retrying " + maxRetries + " times"); } return successFlag; }
boolean initializeCompactStorage() throws PermanentBackendException { try { final ResultSet versionResultSet = this.session.execute( select().column("release_version").from("system", "local") ); final String version = versionResultSet.one().getString(0); final int major = Integer.parseInt(version.substring(0, version.indexOf("."))); // starting with Cassandra 3 COMPACT STORAGE is deprecated and has no impact return (major < 3); } catch (NumberFormatException | NoHostAvailableException | QueryExecutionException | QueryValidationException e) { throw new PermanentBackendException("Error determining Cassandra version", e); } }