private void checkIfSyncFailed(SyncFuture syncFuture) throws FailedSyncBeforeLogCloseException { if (syncFuture.isThrowable()) { throw new FailedSyncBeforeLogCloseException(syncFuture.getThrowable()); } }
@Override public synchronized String toString() { return "done=" + isDone() + ", txid=" + this.txid; }
synchronized boolean isThrowable() { return isDone() && getThrowable() != null; }
private int finishSyncLowerThanTxid(long txid, boolean addSyncTrace) { int finished = 0; for (Iterator<SyncFuture> iter = syncFutures.iterator(); iter.hasNext();) { SyncFuture sync = iter.next(); if (sync.getTxid() <= txid) { sync.done(txid, null); iter.remove(); finished++; if (addSyncTrace) { addTimeAnnotation(sync, "writer synced"); } } else { break; } } return finished; }
/** * Release the passed <code>syncFuture</code> * @return Returns 1. */ private int releaseSyncFuture(final SyncFuture syncFuture, final long currentSequence, final Throwable t) { if (!syncFuture.done(currentSequence, t)) { throw new IllegalStateException(); } // This function releases one sync future only. return 1; }
private SyncFuture getSyncFuture(final long sequence, Span span) { SyncFuture syncFuture = this.syncFuturesByHandler.get(Thread.currentThread()); if (syncFuture == null) { syncFuture = new SyncFuture(); this.syncFuturesByHandler.put(Thread.currentThread(), syncFuture); } return syncFuture.reset(sequence, span); }
protected final SyncFuture getSyncFuture(long sequence) { return cachedSyncFutures.get().reset(sequence); }
@Override protected SyncFuture initialValue() { return new SyncFuture(); } };
private Span blockOnSync(final SyncFuture syncFuture) throws IOException { // Now we have published the ringbuffer, halt the current thread until we get an answer back. try { syncFuture.get(); return syncFuture.getSpan(); } catch (InterruptedException ie) { LOG.warn("Interrupted", ie); throw convertInterruptedExceptionToIOException(ie); } catch (ExecutionException e) { throw ensureIOException(e.getCause()); } }
/** * Release all SyncFutures whose sequence is <= <code>currentSequence</code>. * @param t May be non-null if we are processing SyncFutures because an exception was thrown. * @return Count of SyncFutures we let go. */ private int releaseSyncFutures(final long currentSequence, final Throwable t) { int syncCount = 0; for (SyncFuture syncFuture; (syncFuture = this.syncFutures.peek()) != null;) { if (syncFuture.getTxid() > currentSequence) { break; } releaseSyncFuture(syncFuture, currentSequence, t); if (!this.syncFutures.remove(syncFuture)) { throw new IllegalStateException(syncFuture.toString()); } syncCount++; } return syncCount; }
protected final void blockOnSync(SyncFuture syncFuture) throws IOException { // Now we have published the ringbuffer, halt the current thread until we get an answer back. try { if (syncFuture != null) { if (closed) { throw new IOException("WAL has been closed"); } else { syncFuture.get(walSyncTimeoutNs); } } } catch (TimeoutIOException tioe) { // SyncFuture reuse by thread, if TimeoutIOException happens, ringbuffer // still refer to it, so if this thread use it next time may get a wrong // result. this.cachedSyncFutures.remove(); throw tioe; } catch (InterruptedException ie) { LOG.warn("Interrupted", ie); throw convertInterruptedExceptionToIOException(ie); } catch (ExecutionException e) { throw ensureIOException(e.getCause()); } }
/** * Release all SyncFutures whose sequence is <= <code>currentSequence</code>. * @param currentSequence * @param t May be non-null if we are processing SyncFutures because an exception was thrown. * @return Count of SyncFutures we let go. */ private int releaseSyncFutures(final long currentSequence, final Throwable t) { int syncCount = 0; for (SyncFuture syncFuture; (syncFuture = this.syncFutures.peek()) != null;) { if (syncFuture.getRingBufferSequence() > currentSequence) break; releaseSyncFuture(syncFuture, currentSequence, t); if (!this.syncFutures.remove(syncFuture)) { throw new IllegalStateException(syncFuture.toString()); } syncCount++; } return syncCount; }
long syncFutureSequence = takeSyncFuture.getRingBufferSequence(); if (syncFutureSequence > currentSequence) { throw new IllegalStateException("currentSequence=" + syncFutureSequence + TraceScope scope = Trace.continueSpan(takeSyncFuture.getSpan()); long start = System.nanoTime(); Throwable lastException = null; } finally { takeSyncFuture.setSpan(scope.detach());
private void cleanupOutstandingSyncsOnException(final long sequence, final Exception e) { // There could be handler-count syncFutures outstanding. for (int i = 0; i < this.syncFuturesCount.get(); i++) { this.syncFutures[i].done(sequence, e); } this.syncFuturesCount.set(0); }
synchronized boolean isThrowable() { return isDone() && getThrowable() != null; }
/** * Call this method to clear old usage and get it ready for new deploy. Call * this method even if it is being used for the first time. * * @param sequence sequenceId from this Future's position in the RingBuffer * @return this */ synchronized SyncFuture reset(final long sequence) { return reset(sequence, null); }