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;
}
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);
}
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);
}
}
}
}
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);
}
}
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);
}
}
Aggregations