use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class BerkeleyJEKeyValueStore method get.
@Override
public StaticBuffer get(StaticBuffer key, StoreTransaction txh) throws BackendException {
Transaction tx = getTransaction(txh);
try {
DatabaseEntry databaseKey = key.as(ENTRY_FACTORY);
DatabaseEntry data = new DatabaseEntry();
log.trace("db={}, op=get, tx={}", name, txh);
OperationStatus status = db.get(tx, databaseKey, data, getLockMode(txh));
if (status == OperationStatus.SUCCESS) {
return getBuffer(data);
} else {
return null;
}
} catch (DatabaseException e) {
throw new PermanentBackendException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class BerkeleyJETx method commit.
@Override
public synchronized void commit() throws BackendException {
super.commit();
if (tx == null)
return;
if (log.isTraceEnabled())
log.trace("{} committed", this.toString(), new TransactionClose(this.toString()));
try {
closeOpenIterators();
tx.commit();
tx = null;
} catch (DatabaseException e) {
throw new PermanentBackendException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class AstyanaxKeyColumnValueStore method getKeys.
@Override
public KeyIterator getKeys(KeyRangeQuery query, StoreTransaction txh) throws BackendException {
// this query could only be done when byte-ordering partitioner is used
// because Cassandra operates on tokens internally which means that even contiguous
// range of keys (e.g. time slice) with random partitioner could produce disjoint set of tokens
// returning ambiguous results to the user.
Partitioner partitioner = storeManager.getPartitioner();
if (partitioner != Partitioner.BYTEORDER)
throw new PermanentBackendException("getKeys(KeyRangeQuery could only be used with byte-ordering partitioner.");
ByteBuffer start = query.getKeyStart().asByteBuffer(), end = query.getKeyEnd().asByteBuffer();
RowSliceQuery rowSlice = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate()).getKeyRange(start, end, null, null, Integer.MAX_VALUE);
// Astyanax is bad at builder pattern :(
rowSlice.withColumnRange(query.getSliceStart().asByteBuffer(), query.getSliceEnd().asByteBuffer(), false, query.getLimit());
// Omit final the query's key end from the result, if present in result
final Rows<ByteBuffer, ByteBuffer> r;
try {
r = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) rowSlice.execute()).getResult();
} catch (ConnectionException e) {
throw new TemporaryBackendException(e);
}
Iterator<Row<ByteBuffer, ByteBuffer>> i = Iterators.filter(r.iterator(), new KeySkipPredicate(query.getKeyEnd().asByteBuffer()));
return new RowIterator(i, query);
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class AstyanaxStoreManager method getCompressionOptions.
@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
try {
Keyspace k = keyspaceContext.getClient();
KeyspaceDefinition keyspaceDefinition = k.describeKeyspace();
if (null == keyspaceDefinition) {
throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
}
ColumnFamilyDefinition columnFamilyDefinition = keyspaceDefinition.getColumnFamily(cf);
if (null == columnFamilyDefinition) {
throw new PermanentBackendException("Column family " + cf + " is undefined");
}
return columnFamilyDefinition.getCompressionOptions();
} catch (ConnectionException e) {
throw new PermanentBackendException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class CQLStoreManager method initializeCluster.
Cluster initializeCluster() throws PermanentBackendException {
final Configuration configuration = getStorageConfig();
final List<InetSocketAddress> contactPoints;
try {
contactPoints = Array.of(this.hostnames).map(hostName -> hostName.split(":")).map(array -> Tuple.of(array[0], array.length == 2 ? Integer.parseInt(array[1]) : this.port)).map(tuple -> new InetSocketAddress(tuple._1, tuple._2)).toJavaList();
} catch (SecurityException | ArrayIndexOutOfBoundsException | NumberFormatException e) {
throw new PermanentBackendException("Error initialising cluster contact points", e);
}
final Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints).withClusterName(configuration.get(CLUSTER_NAME));
if (configuration.get(PROTOCOL_VERSION) != 0) {
builder.withProtocolVersion(ProtocolVersion.fromInt(configuration.get(PROTOCOL_VERSION)));
}
if (configuration.has(AUTH_USERNAME) && configuration.has(AUTH_PASSWORD)) {
builder.withCredentials(configuration.get(AUTH_USERNAME), configuration.get(AUTH_PASSWORD));
}
if (configuration.has(LOCAL_DATACENTER)) {
builder.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(configuration.get(LOCAL_DATACENTER)).build()));
}
if (configuration.get(SSL_ENABLED)) {
try {
final TrustManager[] trustManagers;
try (final FileInputStream keyStoreStream = new FileInputStream(configuration.get(SSL_TRUSTSTORE_LOCATION))) {
final KeyStore keystore = KeyStore.getInstance("jks");
keystore.load(keyStoreStream, configuration.get(SSL_TRUSTSTORE_PASSWORD).toCharArray());
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
trustManagers = trustManagerFactory.getTrustManagers();
}
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
final JdkSSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(sslContext).build();
builder.withSSL(sslOptions);
} catch (NoSuchAlgorithmException | CertificateException | IOException | KeyStoreException | KeyManagementException e) {
throw new PermanentBackendException("Error initialising SSL connection properties", e);
}
}
// Build the PoolingOptions based on the configurations
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, configuration.get(LOCAL_MAX_REQUESTS_PER_CONNECTION)).setMaxRequestsPerConnection(HostDistance.REMOTE, configuration.get(REMOTE_MAX_REQUESTS_PER_CONNECTION));
poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, configuration.get(LOCAL_CORE_CONNECTIONS_PER_HOST), configuration.get(LOCAL_MAX_CONNECTIONS_PER_HOST)).setConnectionsPerHost(HostDistance.REMOTE, configuration.get(REMOTE_CORE_CONNECTIONS_PER_HOST), configuration.get(REMOTE_MAX_CONNECTIONS_PER_HOST));
return builder.withPoolingOptions(poolingOptions).build();
}
Aggregations