Search in sources :

Example 6 with TemporaryBackendException

use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String name) throws BackendException {
    Cluster cl = clusterContext.getClient();
    try {
        KeyspaceDefinition ksDef = cl.describeKeyspace(keySpaceName);
        boolean found = false;
        if (null != ksDef) {
            for (ColumnFamilyDefinition cfDef : ksDef.getColumnFamilyList()) {
                found |= cfDef.getName().equals(name);
            }
        }
        if (!found) {
            ColumnFamilyDefinition cfDef = cl.makeColumnFamilyDefinition().setName(name).setKeyspace(keySpaceName).setComparatorType("org.apache.cassandra.db.marshal.BytesType");
            final ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<>();
            if (storageConfig.has(COMPACTION_STRATEGY)) {
                cfDef.setCompactionStrategy(storageConfig.get(COMPACTION_STRATEGY));
            }
            if (!compactionOptions.isEmpty()) {
                cfDef.setCompactionStrategyOptions(compactionOptions);
            }
            if (compressionEnabled) {
                compressionOptions.put("sstable_compression", compressionClass).put("chunk_length_kb", Integer.toString(compressionChunkSizeKB));
            }
            cl.addColumnFamily(cfDef.setCompressionOptions(compressionOptions.build()));
        }
    } catch (ConnectionException e) {
        throw new TemporaryBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) Cluster(com.netflix.astyanax.Cluster) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 7 with TemporaryBackendException

use of org.janusgraph.diskstorage.TemporaryBackendException 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);
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) RowSliceQuery(com.netflix.astyanax.query.RowSliceQuery) Row(com.netflix.astyanax.model.Row) ByteBuffer(java.nio.ByteBuffer) Partitioner(org.janusgraph.diskstorage.cassandra.AbstractCassandraStoreManager.Partitioner) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) Rows(com.netflix.astyanax.model.Rows)

Example 8 with TemporaryBackendException

use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method ensureKeyspaceExists.

private void ensureKeyspaceExists(Cluster cl) throws BackendException {
    KeyspaceDefinition ksDef;
    try {
        ksDef = cl.describeKeyspace(keySpaceName);
        if (null != ksDef && ksDef.getName().equals(keySpaceName)) {
            log.debug("Found keyspace {}", keySpaceName);
            return;
        }
    } catch (ConnectionException e) {
        log.debug("Failed to describe keyspace {}", keySpaceName);
    }
    log.debug("Creating keyspace {}...", keySpaceName);
    try {
        ksDef = cl.makeKeyspaceDefinition().setName(keySpaceName).setStrategyClass(storageConfig.get(REPLICATION_STRATEGY)).setStrategyOptions(strategyOptions);
        cl.addKeyspace(ksDef);
        log.debug("Created keyspace {}", keySpaceName);
    } catch (ConnectionException e) {
        log.debug("Failed to create keyspace {}", keySpaceName);
        throw new TemporaryBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 9 with TemporaryBackendException

use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.

the class HBaseStoreManager method ensureTableExists.

private HTableDescriptor ensureTableExists(String tableName, String initialCFName, int ttlInSeconds) throws BackendException {
    AdminMask adm = null;
    HTableDescriptor desc;
    try {
        // Create our table, if necessary
        adm = getAdminInterface();
        /*
             * Some HBase versions / implementations respond badly to attempts to create a
             * table without at least one CF. See #661. Creating a CF along with
             * the table avoids HBase carping.
             */
        if (adm.tableExists(tableName)) {
            desc = adm.getTableDescriptor(tableName);
            // Check and warn if long and short cf names are interchangeably used for the same table.
            if (shortCfNames && initialCFName.equals(shortCfNameMap.get(SYSTEM_PROPERTIES_STORE_NAME))) {
                String longCFName = shortCfNameMap.inverse().get(initialCFName);
                if (desc.getFamily(Bytes.toBytes(longCFName)) != null) {
                    logger.warn("Configuration {}=true, but the table \"{}\" already has column family with long name \"{}\".", SHORT_CF_NAMES.getName(), tableName, longCFName);
                    logger.warn("Check {} configuration.", SHORT_CF_NAMES.getName());
                }
            } else if (!shortCfNames && initialCFName.equals(SYSTEM_PROPERTIES_STORE_NAME)) {
                String shortCFName = shortCfNameMap.get(initialCFName);
                if (desc.getFamily(Bytes.toBytes(shortCFName)) != null) {
                    logger.warn("Configuration {}=false, but the table \"{}\" already has column family with short name \"{}\".", SHORT_CF_NAMES.getName(), tableName, shortCFName);
                    logger.warn("Check {} configuration.", SHORT_CF_NAMES.getName());
                }
            }
        } else {
            desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
        }
    } catch (IOException e) {
        throw new TemporaryBackendException(e);
    } finally {
        IOUtils.closeQuietly(adm);
    }
    return desc;
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 10 with TemporaryBackendException

use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.

the class HBaseStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
    final MaskedTimestamp commitTime = new MaskedTimestamp(txh);
    // In case of an addition and deletion with identical timestamps, the
    // deletion tombstone wins.
    // http://hbase.apache.org/book/versions.html#d244e4250
    final Map<StaticBuffer, Pair<List<Put>, Delete>> commandsPerKey = convertToCommands(mutations, commitTime.getAdditionTime(times), commitTime.getDeletionTime(times));
    // actual batch operation
    final List<Row> batch = new ArrayList<>(commandsPerKey.size());
    // convert sorted commands into representation required for 'batch' operation
    for (Pair<List<Put>, Delete> commands : commandsPerKey.values()) {
        if (commands.getFirst() != null && !commands.getFirst().isEmpty())
            batch.addAll(commands.getFirst());
        if (commands.getSecond() != null)
            batch.add(commands.getSecond());
    }
    try {
        TableMask table = null;
        try {
            table = cnx.getTable(tableName);
            table.batch(batch, new Object[batch.size()]);
        } finally {
            IOUtils.closeQuietly(table);
        }
    } catch (IOException | InterruptedException e) {
        throw new TemporaryBackendException(e);
    }
    sleepAfterWrite(txh, commitTime);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Row(org.apache.hadoop.hbase.client.Row) Pair(org.apache.hadoop.hbase.util.Pair)

Aggregations

TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)11 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)5 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)5 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)3 List (java.util.List)3 BackendException (org.janusgraph.diskstorage.BackendException)3 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)2 Rows (com.netflix.astyanax.model.Rows)2 RowSliceQuery (com.netflix.astyanax.query.RowSliceQuery)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 Cluster (com.netflix.astyanax.Cluster)1 MutationBatch (com.netflix.astyanax.MutationBatch)1 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)1