use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.
the class HBaseStoreManager method mutateMany.
@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
logger.debug("Enter mutateMany");
final MaskedTimestamp commitTime = new MaskedTimestamp(txh);
// In case of an addition and deletion with identical timestamps, the
// deletion tombstone wins.
// http://hbase.apache.org/book/versions.html#d244e4250
Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = convertToCommands(mutations, commitTime.getAdditionTime(times.getUnit()), commitTime.getDeletionTime(times.getUnit()));
// actual batch operation
List<Row> batch = new ArrayList<>(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 {
TableMask table = null;
try {
table = cnx.getTable(tableName);
logger.debug("mutateMany : batch mutate started size {} ", batch.size());
table.batch(batch, new Object[batch.size()]);
logger.debug("mutateMany : batch mutate finished {} ", batch.size());
} finally {
IOUtils.closeQuietly(table);
}
} catch (IOException | InterruptedException e) {
throw new TemporaryBackendException(e);
}
sleepAfterWrite(txh, commitTime);
}
use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.
the class Solr5Index method restore.
@Override
public void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
try {
for (Map.Entry<String, Map<String, List<IndexEntry>>> stores : documents.entrySet()) {
final String collectionName = stores.getKey();
List<String> deleteIds = new ArrayList<>();
List<SolrInputDocument> newDocuments = new ArrayList<>();
for (Map.Entry<String, List<IndexEntry>> entry : stores.getValue().entrySet()) {
final String docID = entry.getKey();
final List<IndexEntry> content = entry.getValue();
if (content == null || content.isEmpty()) {
if (logger.isTraceEnabled())
logger.trace("Deleting document [{}]", docID);
deleteIds.add(docID);
continue;
}
newDocuments.add(new SolrInputDocument() {
{
setField(getKeyFieldId(collectionName), docID);
for (IndexEntry addition : content) {
Object fieldValue = addition.value;
setField(addition.field, convertValue(fieldValue));
}
}
});
}
commitDeletes(collectionName, deleteIds);
commitDocumentChanges(collectionName, newDocuments);
}
} catch (Exception e) {
throw new TemporaryBackendException("Could not restore Solr index", e);
}
}
use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.
the class HBaseStoreManager method ensureTableExists.
private HTableDescriptor ensureTableExists(String tableName, String initialCFName, int ttlInSeconds) throws BackendException {
AdminMask adm = null;
HTableDescriptor desc;
try {
// Create our table, if necessary
adm = getAdminInterface();
/*
* Some HBase versions/impls respond badly to attempts to create a
* table without at least one CF. See #661. Creating a CF along with
* the table avoids HBase carping.
*/
if (adm.tableExists(tableName)) {
desc = adm.getTableDescriptor(tableName);
} else {
desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
}
} catch (IOException e) {
throw new TemporaryBackendException(e);
} finally {
IOUtils.closeQuietly(adm);
}
return desc;
}
use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project titan by thinkaurelius.
the class IDPoolTest method testAllocationTimeoutAndRecovery.
@Test
public void testAllocationTimeoutAndRecovery() throws BackendException {
IMocksControl ctrl = EasyMock.createStrictControl();
final int partition = 42;
final int idNamespace = 777;
final Duration timeout = Duration.ofSeconds(1L);
final IDAuthority mockAuthority = ctrl.createMock(IDAuthority.class);
// Sleep for two seconds, then throw a backendexception
// this whole delegate could be deleted if we abstracted StandardIDPool's internal executor and stopwatches
expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andDelegateTo(new IDAuthority() {
@Override
public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout) throws BackendException {
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
fail();
}
throw new TemporaryBackendException("slow backend");
}
@Override
public List<KeyRange> getLocalIDPartition() throws BackendException {
throw new IllegalArgumentException();
}
@Override
public void setIDBlockSizer(IDBlockSizer sizer) {
throw new IllegalArgumentException();
}
@Override
public void close() throws BackendException {
throw new IllegalArgumentException();
}
@Override
public String getUniqueID() {
throw new IllegalArgumentException();
}
@Override
public boolean supportsInterruption() {
return true;
}
});
expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andReturn(new IDBlock() {
@Override
public long numIds() {
return 2;
}
@Override
public long getId(long index) {
return 200;
}
});
expect(mockAuthority.supportsInterruption()).andStubReturn(true);
ctrl.replay();
StandardIDPool pool = new StandardIDPool(mockAuthority, partition, idNamespace, Integer.MAX_VALUE, timeout, 0.1);
try {
pool.nextID();
fail();
} catch (TitanException e) {
}
long nextID = pool.nextID();
assertEquals(200, nextID);
ctrl.verify();
}
use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project titan by thinkaurelius.
the class AstyanaxStoreManager method ensureColumnFamilyExists.
private void ensureColumnFamilyExists(String name, String comparator) throws BackendException {
Cluster cl = clusterContext.getClient();
try {
KeyspaceDefinition ksDef = cl.describeKeyspace(keySpaceName);
boolean found = false;
if (null != ksDef) {
for (ColumnFamilyDefinition cfDef : ksDef.getColumnFamilyList()) {
found |= cfDef.getName().equals(name);
}
}
if (!found) {
ColumnFamilyDefinition cfDef = cl.makeColumnFamilyDefinition().setName(name).setKeyspace(keySpaceName).setComparatorType(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));
}
cl.addColumnFamily(cfDef.setCompressionOptions(compressionOptions.build()));
}
} catch (ConnectionException e) {
throw new TemporaryBackendException(e);
}
}
Aggregations