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 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; }
@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(); } }
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); } }
TableMetadata getTableMetadata(final String name) throws BackendException { final KeyspaceMetadata keyspaceMetadata = Option.of(this.cluster.getMetadata().getKeyspace(this.keyspace)) .getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown keyspace '%s'", this.keyspace))); return Option.of(keyspaceMetadata.getTable(name)) .getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown table '%s'", name))); }
public DynamoDBStoreManager(final Configuration backendConfig) throws BackendException { super(backendConfig, getPort(backendConfig)); try { client = new Client(backendConfig); } catch (IllegalArgumentException e) { throw new PermanentBackendException("Bad configuration used: " + backendConfig.toString(), e); } prefix = client.getPrefix(); factory = new TableNameDynamoDbStoreFactory(); features = initializeFeatures(backendConfig); prefixAndMutateMany = String.format("%s_mutateMany", prefix); prefixAndMutateManyUpdateOrDeleteItemCalls = String.format("%s_mutateManyUpdateOrDeleteItemCalls", prefix); prefixAndMutateManyKeys = String.format("%s_mutateManyKeys", prefix); prefixAndMutateManyStores = String.format("%s_mutateManyStores", prefix); lockExpiryTime = backendConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE); }
@Override public boolean exists() throws BackendException { if (mode!= Mode.CLOUD) throw new UnsupportedOperationException("Operation only supported for SolrCloud"); final CloudSolrClient server = (CloudSolrClient) solrClient; try { final ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.forciblyRefreshAllClusterStateSlow(); final ClusterState clusterState = zkStateReader.getClusterState(); final Map<String, DocCollection> collections = clusterState.getCollectionsMap(); return collections != null && !collections.isEmpty(); } catch (KeeperException | InterruptedException e) { throw new PermanentBackendException("Unable to check if index exists", e); } }
Map<String, String> getCompressionOptions(final String name) throws BackendException { final KeyspaceMetadata keyspaceMetadata = Option.of(this.cluster.getMetadata().getKeyspace(this.keyspace)) .getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown keyspace '%s'", this.keyspace))); return Option.of(keyspaceMetadata.getTable(name)) .map(tableMetadata -> tableMetadata.getOptions().getCompression()) .getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown table '%s'", name))); }
private ElasticSearchResponse runCommonQuery(RawQuery query, BaseTransaction tx, int size, boolean useScroll) throws BackendException{ final ElasticSearchRequest sr = new ElasticSearchRequest(); sr.setQuery(compat.queryString(query.getQuery())); sr.setFrom(0); sr.setSize(size); try { return client.search(getIndexStoreName(query.getStore()), useMultitypeIndex ? query.getStore() : null, compat.createRequestBody(sr, query.getParameters()), useScroll); } catch (final IOException | UncheckedIOException e) { throw new PermanentBackendException(e); } }