use of de.invesdwin.context.integration.retry.RetryLaterRuntimeException in project invesdwin-context-persistence by subes.
the class ATimeSeriesUpdater method update.
public final boolean update() throws IncompleteUpdateFoundException {
try {
if (!table.getTableLock(key).writeLock().tryLock(1, TimeUnit.MINUTES)) {
throw new RetryLaterRuntimeException("Write lock could not be acquired for table [" + table.getName() + "] and key [" + key + "]. Please ensure all iterators are closed!");
}
} catch (final InterruptedException e1) {
throw new RuntimeException(e1);
}
try {
if (updateLockFile.exists()) {
throw new IncompleteUpdateFoundException("Incomplete update found for table [" + table.getName() + "], need to clean everything up to restore all from scratch.");
}
try {
FileUtils.touch(updateLockFile);
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Instant updateStart = new Instant();
onUpdateStart();
doUpdate();
onUpdateFinished(updateStart);
Assertions.assertThat(updateLockFile.delete()).isTrue();
return true;
} finally {
table.getTableLock(key).writeLock().unlock();
}
}
use of de.invesdwin.context.integration.retry.RetryLaterRuntimeException in project invesdwin-context-persistence by subes.
the class ADelegateTable method initializeTableLocked.
private void initializeTableLocked() {
if (tableFinalizer.table == null) {
if (getTableCreationTime() == null) {
if (getPersistenceMode().isDisk()) {
try {
Files.touch(timestampFile);
} catch (final IOException e) {
throw Err.process(e);
}
}
tableCreationTime = new FDate();
}
try {
tableFinalizer.table = db.getTable(name);
if (tableFinalizer.table == null) {
throw new IllegalStateException("table should not be null");
}
tableFinalizer.register(this);
RangeTableCloseManager.register(this);
} catch (final Throwable e) {
if (Strings.containsIgnoreCase(e.getMessage(), "LOCK")) {
// at de.invesdwin.context.persistence.leveldb.ADelegateRangeTable.getTableWithReadLock(ADelegateRangeTable.java:144)
throw new RetryLaterRuntimeException(e);
} else {
Err.process(new RuntimeException("Table data for [" + getDirectory() + "/" + getName() + "] is inconsistent. Resetting data and trying again.", e));
innerDeleteTable();
tableFinalizer.table = db.getRangeTable(name);
if (tableFinalizer.table == null) {
throw new IllegalStateException("table should not be null");
}
tableFinalizer.register(this);
}
}
}
}
use of de.invesdwin.context.integration.retry.RetryLaterRuntimeException in project invesdwin-context-persistence by subes.
the class ADelegateRangeTable method initializeTableLocked.
private void initializeTableLocked() {
if (tableFinalizer.table == null) {
if (getTableCreationTime() == null) {
if (getPersistenceMode().isDisk()) {
try {
Files.touch(timestampFile);
} catch (final IOException e) {
throw Err.process(e);
}
}
tableCreationTime = new FDate();
}
try {
tableFinalizer.table = db.getRangeTable(name);
if (tableFinalizer.table == null) {
throw new IllegalStateException("table should not be null");
}
tableFinalizer.register(this);
RangeTableCloseManager.register(this);
} catch (final Throwable e) {
if (Strings.containsIgnoreCase(e.getMessage(), "LOCK")) {
// at de.invesdwin.context.persistence.leveldb.ADelegateRangeTable.getTableWithReadLock(ADelegateRangeTable.java:144)
throw new RetryLaterRuntimeException(e);
} else {
Err.process(new RuntimeException("Table data for [" + getDirectory() + "/" + getName() + "] is inconsistent. Resetting data and trying again.", e));
innerDeleteTable();
tableFinalizer.table = db.getRangeTable(name);
if (tableFinalizer.table == null) {
throw new IllegalStateException("table should not be null");
}
tableFinalizer.register(this);
}
}
}
}
use of de.invesdwin.context.integration.retry.RetryLaterRuntimeException in project invesdwin-context-persistence by subes.
the class ATimeSeriesUpdater method update.
@Override
public final boolean update() throws IncompleteUpdateFoundException {
final ILock writeLock = table.getTableLock(key).writeLock();
try {
if (!writeLock.tryLock(1, TimeUnit.MINUTES)) {
throw Locks.getLockTrace().handleLockException(writeLock.getName(), new RetryLaterRuntimeException("Write lock could not be acquired for table [" + table.getName() + "] and key [" + key + "]. Please ensure all iterators are closed!"));
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
final File updateLockSyncFile = new File(updateLockFile.getAbsolutePath() + ".sync");
try (FileChannelLock updateLockSyncFileLock = new FileChannelLock(updateLockSyncFile)) {
if (updateLockSyncFile.exists() || !updateLockSyncFileLock.tryLock() || updateLockFile.exists()) {
throw new IncompleteUpdateFoundException("Incomplete update found for table [" + table.getName() + "] and key [" + key + "], need to clean everything up to restore all from scratch.");
}
try {
try {
Files.touch(updateLockFile);
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Instant updateStart = new Instant();
onUpdateStart();
doUpdate();
onUpdateFinished(updateStart);
Assertions.assertThat(updateLockFile.delete()).isTrue();
return true;
} catch (final Throwable t) {
final IncompleteUpdateFoundException incompleteException = Throwables.getCauseByType(t, IncompleteUpdateFoundException.class);
if (incompleteException != null) {
throw incompleteException;
} else {
throw new IncompleteUpdateFoundException("Something unexpected went wrong", t);
}
}
} finally {
writeLock.unlock();
}
}
use of de.invesdwin.context.integration.retry.RetryLaterRuntimeException in project invesdwin-context-persistence by subes.
the class ASegmentedTimeSeriesStorageCache method initSegmentRetry.
private void initSegmentRetry(final SegmentedKey<K> segmentedKey, final Function<SegmentedKey<K>, ICloseableIterable<? extends V>> source) {
final ARetryCallable<Throwable> retryTask = new ARetryCallable<Throwable>(new RetryOriginator(ASegmentedTimeSeriesDB.class, "initSegment", segmentedKey)) {
@Override
protected Throwable callRetry() throws Exception {
try {
if (closed) {
return new RetryLaterRuntimeException(ASegmentedTimeSeriesStorageCache.class.getSimpleName() + "for [" + hashKey + "] is already closed.");
} else {
initSegment(segmentedKey, source);
}
return null;
} catch (final Throwable t) {
if (closed) {
return t;
} else {
throw t;
}
}
}
@Override
protected BackOffPolicy getBackOffPolicyOverride() {
// randomize backoff to prevent race conditions between multiple processes
return BackOffPolicies.randomFixedBackOff(Duration.ONE_SECOND);
}
};
final Throwable t = retryTask.call();
if (t != null) {
throw Throwables.propagate(t);
}
}
Aggregations