use of de.invesdwin.context.persistence.timeseriesdb.IncompleteUpdateFoundException in project invesdwin-context-persistence by subes.
the class ALazyDataUpdater method doUpdate.
protected final FDate doUpdate(final FDate estimatedTo) throws IncompleteUpdateFoundException {
try {
final ALoggingTimeSeriesUpdater<K, V> updater = new ALoggingTimeSeriesUpdater<K, V>(key, getTable(), log) {
@Override
protected FDate extractEndTime(final V element) {
return ALazyDataUpdater.this.extractEndTime(element);
}
@Override
protected ICloseableIterable<? extends V> getSource(final FDate updateFrom) {
final ICloseableIterable<? extends V> downloadElements = ALazyDataUpdater.this.downloadElements(getKey(), updateFrom);
return downloadElements;
}
@Override
protected String keyToString(final K key) {
return ALazyDataUpdater.this.keyToString(key);
}
@Override
protected String getElementsName() {
return ALazyDataUpdater.this.getElementsName();
}
@Override
public Percent getProgress() {
if (estimatedTo == null) {
return null;
}
final FDate from = getMinTime();
if (from == null) {
return null;
}
final FDate curTime = getMaxTime();
if (curTime == null) {
return null;
}
return new Percent(new Duration(from, curTime), new Duration(from, estimatedTo)).orLower(Percent.ONE_HUNDRED_PERCENT);
}
};
final Callable<FDate> task = new Callable<FDate>() {
@Override
public FDate call() throws Exception {
updater.update();
return updater.getMaxTime();
}
};
final String taskName = "Loading " + getElementsName() + " for " + keyToString(getKey());
final Callable<Percent> progress = newProgressCallable(estimatedTo, updater);
return TaskInfoCallable.of(taskName, task, progress).call();
} catch (final IncompleteUpdateFoundException e) {
throw e;
} catch (final Throwable e) {
throw Throwables.propagate(e);
}
}
use of de.invesdwin.context.persistence.timeseriesdb.IncompleteUpdateFoundException 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.persistence.timeseriesdb.IncompleteUpdateFoundException in project invesdwin-context-persistence by subes.
the class PersistentLiveSegment method putNextLiveValues.
public void putNextLiveValues(final ICloseableIterable<V> memoryValues) {
final ADelegateRangeTable<String, TimeRange, SegmentStatus> segmentStatusTable = historicalSegmentTable.getStorage().getSegmentStatusTable();
final SegmentStatus existingStatus = segmentStatusTable.get(hashKey, segmentedKey.getSegment());
if (existingStatus == null) {
segmentStatusTable.put(hashKey, segmentedKey.getSegment(), SegmentStatus.INITIALIZING);
} else if (existingStatus != SegmentStatus.INITIALIZING) {
throw UnknownArgumentException.newInstance(SegmentStatus.class, existingStatus);
}
final ATimeSeriesUpdater<SegmentedKey<K>, V> updater = new ATimeSeriesUpdater<SegmentedKey<K>, V>(segmentedKey, table) {
@Override
protected ICloseableIterable<? extends V> getSource(final FDate updateFrom) {
return memoryValues;
}
@Override
protected void onUpdateFinished(final Instant updateStart) {
}
@Override
protected void onUpdateStart() {
}
@Override
protected FDate extractEndTime(final V element) {
return historicalSegmentTable.extractEndTime(element);
}
@Override
protected void onFlush(final int flushIndex, final ATimeSeriesUpdater<SegmentedKey<K>, V>.UpdateProgress updateProgress) {
}
@Override
protected boolean shouldRedoLastFile() {
return false;
}
@Override
public Percent getProgress() {
return null;
}
};
try {
Assertions.checkTrue(updater.update());
} catch (final IncompleteUpdateFoundException e) {
throw new RuntimeException(e);
}
empty = false;
}
Aggregations