use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.
the class AstyanaxStoreManager method ensureKeyspaceExists.
private void ensureKeyspaceExists(Cluster cl) throws StorageException {
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 {
Map<String, String> stratops = ImmutableMap.of("replication_factor", String.valueOf(replicationFactor));
ksDef = cl.makeKeyspaceDefinition().setName(keySpaceName).setStrategyClass("org.apache.cassandra.locator.SimpleStrategy").setStrategyOptions(stratops);
cl.addKeyspace(ksDef);
log.debug("Created keyspace {}", keySpaceName);
} catch (ConnectionException e) {
log.debug("Failed to create keyspace {}", keySpaceName);
throw new TemporaryStorageException(e);
}
}
use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.
the class LuceneIndex method mutate.
@Override
public void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever informations, TransactionHandle tx) throws StorageException {
Transaction ltx = (Transaction) tx;
writerLock.lock();
try {
for (Map.Entry<String, Map<String, IndexMutation>> stores : mutations.entrySet()) {
mutateStores(stores, informations);
}
ltx.postCommit();
} catch (IOException e) {
throw new TemporaryStorageException("Could not update Lucene index", e);
} finally {
writerLock.unlock();
}
}
use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.
the class LuceneIndex method query.
@Override
public List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, TransactionHandle tx) throws StorageException {
// Construct query
Filter q = convertQuery(query.getCondition(), informations.get(query.getStore()));
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(new MatchAllDocsQuery(), q, query.hasLimit() ? query.getLimit() : Integer.MAX_VALUE - 1, getSortOrder(query));
log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
List<String> result = new ArrayList<String>(docs.scoreDocs.length);
for (int i = 0; i < docs.scoreDocs.length; i++) {
result.add(searcher.doc(docs.scoreDocs[i].doc).getField(DOCID).stringValue());
}
return result;
} catch (IOException e) {
throw new TemporaryStorageException("Could not execute Lucene query", e);
}
}
use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.
the class HBaseStoreManager method ensureTableExists.
private HTableDescriptor ensureTableExists(String tableName) throws StorageException {
HBaseAdmin adm = getAdminInterface();
HTableDescriptor desc;
try {
// Create our table, if necessary
if (adm.tableExists(tableName)) {
desc = adm.getTableDescriptor(tableName.getBytes());
} else {
desc = new HTableDescriptor(tableName);
adm.createTable(desc);
}
} catch (IOException e) {
throw new TemporaryStorageException(e);
}
return desc;
}
use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.
the class CassandraThriftStoreManager method ensureColumnFamilyExists.
private void ensureColumnFamilyExists(String ksName, String cfName, String comparator) throws StorageException {
CTConnection conn = null;
try {
KsDef keyspaceDef = ensureKeyspaceExists(ksName);
conn = pool.borrowObject(ksName);
Cassandra.Client client = conn.getClient();
log.debug("Looking up metadata on keyspace {}...", ksName);
boolean foundColumnFamily = false;
for (CfDef cfDef : keyspaceDef.getCf_defs()) {
String curCfName = cfDef.getName();
if (curCfName.equals(cfName))
foundColumnFamily = true;
}
if (!foundColumnFamily) {
createColumnFamily(client, ksName, cfName, comparator);
} else {
log.debug("Keyspace {} and ColumnFamily {} were found.", ksName, cfName);
}
} catch (SchemaDisagreementException e) {
throw new TemporaryStorageException(e);
} catch (Exception e) {
throw new PermanentStorageException(e);
} finally {
pool.returnObjectUnsafe(ksName, conn);
}
}
Aggregations