@Override public void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException { if (!failAdds) index.mutate(mutations, information,tx); else throw new TemporaryBackendException("Blocked mutation"); }
@Override public void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException { if (!failAdds) index.restore(documents, information, tx); else throw new TemporaryBackendException("Blocked mutation"); }
private List<Entry> getSliceWithRetries(KeySliceQuery ksq, StoreTransaction tx) throws BackendException { for (int i = 0; i < lockRetryCount; i++) { // TODO either make this like writeLock so that it handles all Throwable types (and pull that logic out // into a shared method) or make writeLock like this in that it only handles Temporary/PermanentSE try { return store.getSlice(ksq, tx); } catch (PermanentBackendException e) { log.error("Failed to check locks", e); throw new PermanentLockingException(e); } catch (TemporaryBackendException e) { log.warn("Temporary storage failure while checking locks", e); } } throw new TemporaryBackendException("Maximum retries (" + lockRetryCount + ") exceeded while checking locks"); }
public static EntryList convert(RecordIterator<KeyValueEntry> iterator) throws BackendException { try { return StaticArrayEntryList.ofStaticBuffer(iterator, KVEntryGetter.INSTANCE); } finally { try { iterator.close(); } catch (IOException e) { throw new TemporaryBackendException(e); } } }
private EntryList convert(RecordIterator<KeyValueEntry> entries) throws BackendException { try { return StaticArrayEntryList.ofStaticBuffer(entries,kvEntryGetter); } finally { 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 TemporaryBackendException(e); } } }
throw new TemporaryBackendException("Could not successfully complete backend operation due to repeated temporary exceptions after "+totalWaitTime,lastException);
private long getCurrentID(final StaticBuffer partitionKey) throws BackendException { final List<Entry> blocks = BackendOperation.execute( (BackendOperation.Transactional<List<Entry>>) txh -> idStore.getSlice(new KeySliceQuery(partitionKey, LOWER_SLICE, UPPER_SLICE).setLimit(5), txh),this,times); if (blocks == null) throw new TemporaryBackendException("Could not read from storage"); long latest = BASE_ID; for (Entry e : blocks) { long counterVal = getBlockValue(e); if (latest < counterVal) { latest = counterVal; } } return latest; }
throw new TemporaryBackendException("Timed out waiting for next row data - storage error likely");
throw new TemporaryBackendException("Wrote claim for id block [" + nextStart + ", " + nextEnd + ") in " + (writeElapsed) + " => too slow, threshold is: " + idApplicationWaitMS); } else { if (blocks == null) throw new TemporaryBackendException("Could not read from storage"); if (blocks.isEmpty()) throw new PermanentBackendException("It seems there is a race-condition in the block application. " +
throw new TemporaryBackendException("Lock write retry count exceeded");
private BackendException storageException(Exception solrException) { return new TemporaryBackendException("Unable to complete query on Solr.", solrException); }
@Override public void close() throws BackendException { logger.trace("Shutting down connection to Solr", solrClient); try { solrClient.close(); } catch (final IOException e) { throw new TemporaryBackendException(e); } }
private BackendException convert(Exception esException) { if (esException instanceof InterruptedException) { return new TemporaryBackendException("Interrupted while waiting for response", esException); } else { return new PermanentBackendException("Unknown exception while executing index operation", esException); } }
@Override public boolean exists() throws BackendException { try (final AdminMask adm = getAdminInterface()) { return adm.tableExists(tableName); } catch (IOException e) { throw new TemporaryBackendException(e); } }
private BackendException processDynamoDbApiException(final Throwable e, final String apiName, final String tableName) { Preconditions.checkArgument(apiName != null); Preconditions.checkArgument(!apiName.isEmpty()); final String prefix; if (tableName == null) { prefix = apiName; } else { prefix = String.format("%s_%s", apiName, tableName); } final String message = String.format("%s %s", prefix, e.getMessage()); if (e instanceof ResourceNotFoundException) { return new BackendNotFoundException(String.format("%s; table not found", message), e); } else if (e instanceof ConditionalCheckFailedException) { return new PermanentLockingException(message, e); } else if (e instanceof AmazonServiceException) { if (e.getMessage() != null && (e.getMessage().contains(HASH_RANGE_KEY_SIZE_LIMIT) || e.getMessage().contains(UPDATE_ITEM_SIZE_LIMIT))) { return new PermanentBackendException(message, e); } else { return new TemporaryBackendException(message, e); } } else if (e instanceof AmazonClientException) { //all client exceptions are retriable by default return new TemporaryBackendException(message, e); } else if (e instanceof SocketException) { //sometimes this doesn't get caught by SDK return new TemporaryBackendException(message, e); } // unknown exception type return new PermanentBackendException(message, e); }
private boolean runWithBackoffOnce() throws BackendException { boolean interrupted = false; tries++; try { result = call(); } catch (TemporaryBackendException e) { //retriable if (tries > delegate.getMaxRetries()) { throw new TemporaryBackendException("Max tries exceeded.", e); } try { Thread.sleep(exponentialBackoffTime); } catch (InterruptedException ie) { interrupted = true; } finally { exponentialBackoffTime *= 2; } } return interrupted; } }
@Override public void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException { try { for (final Map.Entry<String, Map<String, List<IndexEntry>>> stores : documents.entrySet()) { final String collectionName = stores.getKey(); final List<String> deleteIds = new ArrayList<>(); final List<SolrInputDocument> newDocuments = new ArrayList<>(); for (final 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; } final SolrInputDocument doc = new SolrInputDocument(); doc.setField(getKeyFieldId(collectionName), docID); final Map<String, Object> adds = collectFieldValues(content, collectionName, information); adds.forEach(doc::setField); newDocuments.add(doc); } commitDeletes(collectionName, deleteIds); commitChanges(collectionName, newDocuments); } } catch (final Exception e) { throw new TemporaryBackendException("Could not restore Solr index", e); } }
logger.debug("Table {} already disabled", tableName); } catch (IOException e) { throw new TemporaryBackendException(e); Thread.sleep(1000L); } catch (InterruptedException ie) { throw new TemporaryBackendException(ie); logger.debug("Swallowing exception {}", ee); } catch (IOException ee) { throw new TemporaryBackendException(ee);
throw new TemporaryBackendException(e); } finally { IOUtils.closeQuietly(adm);
throw new PermanentBackendException(e); } catch (IOException e) { throw new TemporaryBackendException(e);