use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.
the class PersistitKeyValueStore method getSlice.
/**
* Runs all getSlice queries
*
* The keyStart & keyEnd are not guaranteed to exist
* if keyStart is after keyEnd, an empty list is returned
*
* @param keyStart
* @param keyEnd
* @param selector
* @param limit
* @param txh
* @return
* @throws StorageException
*/
private RecordIterator<KeyValueEntry> getSlice(final StaticBuffer keyStart, final StaticBuffer keyEnd, final KeySelector selector, final Integer limit, StoreTransaction txh) throws StorageException {
PersistitTransaction tx = (PersistitTransaction) txh;
final List<KeyValueEntry> results = new ArrayList<KeyValueEntry>();
synchronized (tx) {
tx.assign();
Exchange exchange = tx.getExchange(name);
try {
byte[] start = getArray(keyStart);
byte[] end = getArray(keyEnd);
// bail out if the start key comes after the end
if (compare(start, end) > 0) {
return KVUtil.EMPTY_ITERATOR;
}
KeyFilter.Term[] terms = { KeyFilter.rangeTerm(start, end, true, false, null) };
KeyFilter keyFilter = new KeyFilter(terms);
int i = 0;
while (exchange.next(keyFilter)) {
StaticBuffer k = getKey(exchange);
// check the key against the selector, and that is has a corresponding value
if (exchange.getValue().isDefined() && (selector == null || selector.include(k))) {
StaticBuffer v = getValue(exchange);
KeyValueEntry kv = new KeyValueEntry(k, v);
results.add(kv);
i++;
if (limit != null && limit >= 0 && i >= limit)
break;
if (selector != null && selector.reachedLimit())
break;
}
}
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
} finally {
tx.releaseExchange(exchange);
}
}
// on heap for at least 2 collections.
return new RecordIterator<KeyValueEntry>() {
private final Iterator<KeyValueEntry> entries = results.iterator();
@Override
public boolean hasNext() {
return entries.hasNext();
}
@Override
public KeyValueEntry next() {
return entries.next();
}
@Override
public void close() {
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.
the class ElasticSearchIndex method clearStorage.
@Override
public void clearStorage() throws StorageException {
try {
try {
client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();
// We wait for one second to let ES delete the river
Thread.sleep(1000);
} catch (IndexMissingException e) {
// Index does not exist... Fine
}
} catch (Exception e) {
throw new PermanentStorageException("Could not delete index " + indexName, e);
} finally {
close();
}
}
use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.
the class PersistitKeyValueStore method delete.
@Override
public void delete(final StaticBuffer key, StoreTransaction txh) throws StorageException {
final PersistitTransaction tx = (PersistitTransaction) txh;
synchronized (tx) {
tx.assign();
final Exchange exchange = tx.getExchange(name);
try {
toKey(exchange, key);
exchange.remove();
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
} finally {
tx.releaseExchange(exchange);
}
}
}
use of com.thinkaurelius.titan.diskstorage.PermanentStorageException in project titan by thinkaurelius.
the class PersistitTransaction method getExchange.
public Exchange getExchange(String treeName, Boolean create) throws StorageException {
synchronized (this) {
Exchange exchange;
try {
assign();
exchange = db.getExchange(VOLUME_NAME, treeName, create);
return exchange;
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
}
}
}
use of com.thinkaurelius.titan.diskstorage.PermanentStorageException 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