Search in sources :

Example 31 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class CassandraEmbeddedKeyColumnValueStore method getInternal.

static ByteBuffer getInternal(String keyspace, String columnFamily, ByteBuffer key, ByteBuffer column, org.apache.cassandra.db.ConsistencyLevel cl) throws StorageException {
    QueryPath slicePath = new QueryPath(columnFamily);
    SliceByNamesReadCommand namesCmd = new SliceByNamesReadCommand(keyspace, key.duplicate(), slicePath, Arrays.asList(column.duplicate()));
    List<Row> rows = read(namesCmd, cl);
    if (null == rows || 0 == rows.size())
        return null;
    if (1 < rows.size())
        throw new PermanentStorageException("Received " + rows.size() + " rows from a single-key-column cassandra read");
    assert 1 == rows.size();
    Row r = rows.get(0);
    if (null == r) {
        log.warn("Null Row object retrieved from Cassandra StorageProxy");
        return null;
    }
    ColumnFamily cf = r.cf;
    if (null == cf)
        return null;
    if (cf.isMarkedForDelete())
        return null;
    IColumn c = cf.getColumn(column.duplicate());
    if (null == c)
        return null;
    // These came up during testing
    if (c.isMarkedForDelete())
        return null;
    return org.apache.cassandra.utils.ByteBufferUtil.clone(c.value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException)

Example 32 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class CassandraEmbeddedKeyColumnValueStore method getKeySlice.

private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize) throws StorageException {
    IPartitioner<?> partitioner = StorageService.getPartitioner();
    SliceRange columnSlice = new SliceRange();
    if (sliceQuery == null) {
        columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
    } else {
        columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
    }
    /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
    SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
    RowPosition startPosition = start.minKeyBound(partitioner);
    RowPosition endPosition = end.minKeyBound(partitioner);
    List<Row> rows;
    try {
        IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, Schema.instance.getComparator(keyspace, columnFamily));
        rows = StorageProxy.getRangeSlice(new RangeSliceCommand(keyspace, new ColumnParent(columnFamily), filter, new Bounds<RowPosition>(startPosition, endPosition), null, pageSize), ConsistencyLevel.QUORUM);
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    }
    return rows;
}
Also used : IDiskAtomFilter(org.apache.cassandra.db.filter.IDiskAtomFilter) SliceRange(org.apache.cassandra.thrift.SliceRange) ColumnParent(org.apache.cassandra.thrift.ColumnParent) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) IsBootstrappingException(org.apache.cassandra.exceptions.IsBootstrappingException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) UnavailableException(org.apache.cassandra.exceptions.UnavailableException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) IOException(java.io.IOException)

Example 33 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class CassandraThriftKeyColumnValueStore method getNamesSlice.

public Map<ByteBuffer, List<Entry>> getNamesSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws StorageException {
    Preconditions.checkArgument(query.getLimit() >= 0);
    if (0 == query.getLimit())
        return Collections.emptyMap();
    ColumnParent parent = new ColumnParent(columnFamily);
    /*
         * Cassandra cannot handle columnStart = columnEnd.
		 * Cassandra's Thrift getSlice() throws InvalidRequestException
		 * if columnStart = columnEnd.
		 */
    if (ByteBufferUtil.compare(query.getSliceStart(), query.getSliceEnd()) >= 0) {
        // Check for invalid arguments where columnEnd < columnStart
        if (ByteBufferUtil.isSmallerThan(query.getSliceEnd(), query.getSliceStart())) {
            throw new PermanentStorageException("columnStart=" + query.getSliceStart() + " is greater than columnEnd=" + query.getSliceEnd() + ". " + "columnStart must be less than or equal to columnEnd");
        }
        if (0 != query.getSliceStart().length() && 0 != query.getSliceEnd().length()) {
            logger.debug("Return empty list due to columnEnd==columnStart and neither empty");
            return Collections.emptyMap();
        }
    }
    // true: columnStart < columnEnd
    ConsistencyLevel consistency = getTx(txh).getReadConsistencyLevel().getThriftConsistency();
    SlicePredicate predicate = new SlicePredicate();
    SliceRange range = new SliceRange();
    range.setCount(query.getLimit());
    range.setStart(query.getSliceStart().asByteBuffer());
    range.setFinish(query.getSliceEnd().asByteBuffer());
    predicate.setSlice_range(range);
    CTConnection conn = null;
    try {
        conn = pool.borrowObject(keyspace);
        Cassandra.Client client = conn.getClient();
        List<ByteBuffer> requestKeys = new ArrayList<ByteBuffer>(keys.size());
        {
            for (StaticBuffer key : keys) {
                requestKeys.add(key.asByteBuffer());
            }
        }
        Map<ByteBuffer, List<ColumnOrSuperColumn>> rows = client.multiget_slice(requestKeys, parent, predicate, consistency);
        /*
			 * The final size of the "result" List may be at most rows.size().
			 * However, "result" could also be up to two elements smaller than
			 * rows.size(), depending on startInclusive and endInclusive
			 */
        Map<ByteBuffer, List<Entry>> results = new HashMap<ByteBuffer, List<Entry>>();
        ByteBuffer sliceEndBB = query.getSliceEnd().asByteBuffer();
        for (ByteBuffer key : rows.keySet()) {
            results.put(key, excludeLastColumn(rows.get(key), sliceEndBB));
        }
        return results;
    } catch (Exception e) {
        throw convertException(e);
    } finally {
        pool.returnObjectUnsafe(keyspace, conn);
    }
}
Also used : HashMap(java.util.HashMap) ColumnParent(org.apache.cassandra.thrift.ColumnParent) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) ArrayList(java.util.ArrayList) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) ByteBuffer(java.nio.ByteBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TimedOutException(org.apache.cassandra.thrift.TimedOutException) NoSuchElementException(java.util.NoSuchElementException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) ConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel) CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) ByteBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.ByteBufferEntry) SliceRange(org.apache.cassandra.thrift.SliceRange) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) List(java.util.List) ArrayList(java.util.ArrayList)

Example 34 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class CassandraThriftStoreManager method createColumnFamily.

private void createColumnFamily(Cassandra.Client client, String ksName, String cfName, String comparator) throws StorageException {
    CfDef createColumnFamily = new CfDef();
    createColumnFamily.setName(cfName);
    createColumnFamily.setKeyspace(ksName);
    createColumnFamily.setComparator_type(comparator);
    ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<String, String>();
    if (compressionEnabled) {
        compressionOptions.put("sstable_compression", compressionClass).put("chunk_length_kb", Integer.toString(compressionChunkSizeKB));
    }
    createColumnFamily.setCompression_options(compressionOptions.build());
    // Hard-coded caching settings
    if (cfName.startsWith(Backend.EDGESTORE_NAME)) {
        createColumnFamily.setCaching("keys_only");
    } else if (cfName.startsWith(Backend.VERTEXINDEX_STORE_NAME)) {
        createColumnFamily.setCaching("rows_only");
    }
    log.debug("Adding column family {} to keyspace {}...", cfName, ksName);
    try {
        client.system_add_column_family(createColumnFamily);
    } catch (SchemaDisagreementException e) {
        throw new TemporaryStorageException("Error in setting up column family", e);
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    }
    log.debug("Added column family {} to keyspace {}.", cfName, ksName);
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException) CfDef(org.apache.cassandra.thrift.CfDef) ImmutableMap(com.google.common.collect.ImmutableMap) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

Example 35 with PermanentStorageException

use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.

the class CTConnectionFactory method waitForClusterSize.

public static void waitForClusterSize(Cassandra.Client thriftClient, int minSize) throws InterruptedException, StorageException {
    log.debug("Checking Cassandra cluster size" + " (want at least {} nodes)...", minSize);
    Map<String, List<String>> versions = null;
    final long STARTUP_WAIT_MAX = 10000L;
    final long STARTUP_WAIT_INCREMENT = 100L;
    long start = System.currentTimeMillis();
    long lastTry = 0;
    long limit = start + STARTUP_WAIT_MAX;
    long minSleep = STARTUP_WAIT_INCREMENT;
    Integer curSize = null;
    while (limit - System.currentTimeMillis() >= 0) {
        // Block for a little while if we're looping too fast
        long sinceLast = System.currentTimeMillis() - lastTry;
        long willSleep = minSleep - sinceLast;
        if (0 < willSleep) {
            // log.debug("Cassandra cluster size={} " +
            // "(want {}); rechecking in {} ms",
            // new Object[]{ curSize, minSize, willSleep });
            Thread.sleep(willSleep);
        }
        // Issue thrift query
        try {
            lastTry = System.currentTimeMillis();
            versions = thriftClient.describe_schema_versions();
            if (1 != versions.size())
                continue;
            String version = Iterators.getOnlyElement(versions.keySet().iterator());
            curSize = versions.get(version).size();
            if (curSize >= minSize) {
                log.debug("Cassandra cluster verified at size {} (schema version {}) in about {} ms", new Object[] { curSize, version, System.currentTimeMillis() - start });
                return;
            }
        } catch (Exception e) {
            throw new PermanentStorageException("Failed to fetch Cassandra Thrift schema versions: " + ((e instanceof InvalidRequestException) ? ((InvalidRequestException) e).getWhy() : e.getMessage()));
        }
    }
    throw new PermanentStorageException("Could not verify Cassandra cluster size");
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TTransportException(org.apache.thrift.transport.TTransportException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException)

Aggregations

PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)43 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)14 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)12 PersistitException (com.persistit.exception.PersistitException)9 IOException (java.io.IOException)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)6 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)5 ByteBuffer (java.nio.ByteBuffer)5 StaticByteBuffer (com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer)4 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)4 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)3 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)3 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)2 Exchange (com.persistit.Exchange)2 DatabaseException (com.sleepycat.je.DatabaseException)2 TitanException (com.thinkaurelius.titan.core.TitanException)2 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)2 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)2 KeyValueEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)2 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)2