Search in sources :

Example 31 with TemporaryStorageException

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

the class OrderedKeyValueStoreAdapter method convert.

private List<Entry> convert(RecordIterator<KeyValueEntry> entries) throws StorageException {
    List<Entry> newentries = new ArrayList<Entry>(entries.hasNext() ? 20 : 0);
    while (entries.hasNext()) {
        KeyValueEntry entry = entries.next();
        newentries.add(getEntry(entry));
    }
    try {
        entries.close();
    } catch (IOException e) {
        /*
             * IOException could be permanent or temporary. Choosing temporary
             * allows useful retries of transient failures but also allows
             * futile retries of permanent failures.
             */
        throw new TemporaryStorageException(e);
    }
    return newentries;
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) IOException(java.io.IOException)

Example 32 with TemporaryStorageException

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

the class HBaseStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws StorageException {
    // TODO: use same timestamp functionality as Cassandra
    // final Timestamp timestamp = super.getTimestamp(txh);
    // Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = convertToCommands(mutations, timestamp.additionTime, timestamp.deletionTime);
    final long delTS = System.currentTimeMillis();
    final long putTS = delTS + 1;
    Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = convertToCommands(mutations, putTS, delTS);
    // actual batch operation
    List<Row> batch = new ArrayList<Row>(commandsPerKey.size());
    // convert sorted commands into representation required for 'batch' operation
    for (Pair<Put, Delete> commands : commandsPerKey.values()) {
        if (commands.getFirst() != null)
            batch.add(commands.getFirst());
        if (commands.getSecond() != null)
            batch.add(commands.getSecond());
    }
    try {
        HTableInterface table = null;
        try {
            table = connectionPool.getTable(tableName);
            table.batch(batch);
            table.flushCommits();
        } finally {
            IOUtils.closeQuietly(table);
        }
    } catch (IOException e) {
        throw new TemporaryStorageException(e);
    } catch (InterruptedException e) {
        throw new TemporaryStorageException(e);
    }
    waitUntil(putTS);
}
Also used : IOException(java.io.IOException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Pair(org.apache.hadoop.hbase.util.Pair)

Example 33 with TemporaryStorageException

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

the class HBaseStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String tableName, String columnFamily) throws StorageException {
    HBaseAdmin adm = getAdminInterface();
    HTableDescriptor desc = ensureTableExists(tableName);
    Preconditions.checkNotNull(desc);
    HColumnDescriptor cf = desc.getFamily(columnFamily.getBytes());
    // Create our column family, if necessary
    if (cf == null) {
        try {
            adm.disableTable(tableName);
            desc.addFamily(new HColumnDescriptor(columnFamily).setCompressionType(Compression.Algorithm.GZ));
            adm.modifyTable(tableName.getBytes(), desc);
            try {
                logger.debug("Added HBase ColumnFamily {}, waiting for 1 sec. to propogate.", columnFamily);
                Thread.sleep(1000L);
            } catch (InterruptedException ie) {
                throw new TemporaryStorageException(ie);
            }
            adm.enableTable(tableName);
        } catch (TableNotFoundException ee) {
            logger.error("TableNotFoundException", ee);
            throw new PermanentStorageException(ee);
        } catch (org.apache.hadoop.hbase.TableExistsException ee) {
            logger.debug("Swallowing exception {}", ee);
        } catch (IOException ee) {
            throw new TemporaryStorageException(ee);
        }
    } else {
        // check if compression was enabled, if not - enable it
        if (cf.getCompressionType() == null || cf.getCompressionType() == Compression.Algorithm.NONE) {
            try {
                adm.disableTable(tableName);
                adm.modifyColumn(tableName, cf.setCompressionType(Compression.Algorithm.GZ));
                adm.enableTable(tableName);
            } catch (IOException e) {
                throw new TemporaryStorageException(e);
            }
        }
    }
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 34 with TemporaryStorageException

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

the class HBaseStoreManager method clearStorage.

/**
 * Deletes the specified table with all its columns.
 * ATTENTION: Invoking this method will delete the table if it exists and therefore causes data loss.
 */
@Override
public void clearStorage() throws StorageException {
    HBaseAdmin adm = getAdminInterface();
    try {
        // first of all, check if table exists, if not - we are done
        if (!adm.tableExists(tableName)) {
            logger.debug("clearStorage() called before table {} was created, skipping.", tableName);
            return;
        }
    } catch (IOException e) {
        throw new TemporaryStorageException(e);
    }
    HTable table = null;
    try {
        table = new HTable(hconf, tableName);
        Scan scan = new Scan();
        scan.setBatch(100);
        scan.setCacheBlocks(false);
        scan.setCaching(2000);
        ResultScanner scanner = null;
        try {
            scanner = table.getScanner(scan);
            for (Result res : scanner) {
                table.delete(new Delete(res.getRow()));
            }
        } finally {
            IOUtils.closeQuietly(scanner);
        }
    } catch (IOException e) {
        throw new TemporaryStorageException(e);
    } finally {
        IOUtils.closeQuietly(table);
    }
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) IOException(java.io.IOException)

Example 35 with TemporaryStorageException

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

the class LuceneIndex method query.

@Override
public Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, TransactionHandle tx) throws StorageException {
    Query q;
    try {
        q = new QueryParser(LUCENE_VERSION, "_all", analyzer).parse(query.getQuery());
    } catch (ParseException e) {
        throw new PermanentStorageException("Could not parse raw query: " + query.getQuery(), e);
    }
    try {
        IndexSearcher searcher = ((Transaction) tx).getSearcher(query.getStore());
        // Index does not yet exist
        if (searcher == null)
            return ImmutableList.of();
        long time = System.currentTimeMillis();
        TopDocs docs = searcher.search(q, query.hasLimit() ? query.getLimit() : Integer.MAX_VALUE - 1);
        log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
        List<RawQuery.Result<String>> result = new ArrayList<RawQuery.Result<String>>(docs.scoreDocs.length);
        for (int i = 0; i < docs.scoreDocs.length; i++) {
            result.add(new RawQuery.Result<String>(searcher.doc(docs.scoreDocs[i].doc).getField(DOCID).stringValue(), docs.scoreDocs[i].score));
        }
        return result;
    } catch (IOException e) {
        throw new TemporaryStorageException("Could not execute Lucene query", e);
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) IOException(java.io.IOException) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Aggregations

TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)37 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)11 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)10 IOException (java.io.IOException)10 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)9 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)6 Test (org.junit.Test)6 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)5 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)5 NotFoundException (org.apache.cassandra.thrift.NotFoundException)5 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)5 TException (org.apache.thrift.TException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)4 ByteBuffer (java.nio.ByteBuffer)4 Cassandra (org.apache.cassandra.thrift.Cassandra)4 CfDef (org.apache.cassandra.thrift.CfDef)4 KsDef (org.apache.cassandra.thrift.KsDef)4 TitanException (com.thinkaurelius.titan.core.TitanException)3 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)3