@Override public void run() { long currentSequence; while (!isInterrupted()) { int syncCount = 0; syncCount += releaseSyncFuture(takeSyncFuture, currentHighestSyncedSequence, null); writer.sync(useHsync); TraceUtil.addTimelineAnnotation("writer synced"); currentSequence = updateHighestSyncedSequence(currentSequence); } catch (IOException e) { LOG.error("Error syncing, request close of WAL", e); syncCount += releaseSyncFuture(takeSyncFuture, currentSequence, lastException); syncCount += releaseSyncFutures(currentSequence, lastException); if (lastException != null) { wasRollRequested = true;
this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures, this.syncFuturesCount.get()); } catch (Exception e) {
this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures, this.syncFuturesCount); } catch (Exception e) {
public void run() { long currentSequence; while (!isInterrupted()) { int syncCount = 0; SyncFuture takeSyncFuture; syncCount += releaseSyncFuture(takeSyncFuture, currentHighestSyncedSequence, null); writer.sync(); Trace.addTimelineAnnotation("writer synced"); currentSequence = updateHighestSyncedSequence(currentSequence); } catch (IOException e) { LOG.error("Error syncing, request close of WAL", e); syncCount += releaseSyncFuture(takeSyncFuture, currentSequence, lastException); syncCount += releaseSyncFutures(currentSequence, lastException); if (lastException != null) requestLogRoll(); else checkLogRoll();
/** * 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; }
RingBufferEventHandler(final int syncRunnerCount, final int maxHandlersCount) { this.syncFutures = new SyncFuture[maxHandlersCount]; this.syncRunners = new SyncRunner[syncRunnerCount]; for (int i = 0; i < syncRunnerCount; i++) { this.syncRunners[i] = new SyncRunner("sync." + i, maxHandlersCount); } }
@Override public void onShutdown() { for (SyncRunner syncRunner: this.syncRunners) syncRunner.interrupt(); } }
@Override public void onStart() { for (SyncRunner syncRunner: this.syncRunners) syncRunner.start(); }
/** * 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; }
RingBufferEventHandler(final int syncRunnerCount, final int maxHandlersCount) { this.syncFutures = new SyncFuture[maxHandlersCount]; this.syncRunners = new SyncRunner[syncRunnerCount]; for (int i = 0; i < syncRunnerCount; i++) { this.syncRunners[i] = new SyncRunner("sync." + i, maxHandlersCount); } }
@Override public void onShutdown() { for (SyncRunner syncRunner : this.syncRunners) { syncRunner.interrupt(); } } }
private boolean isOutstandingSyncsFromRunners() { // Look at SyncFutures in the SyncRunners for (SyncRunner syncRunner: syncRunners) { if(syncRunner.isAlive() && !syncRunner.areSyncFuturesReleased()) { return true; } } return false; }
@Override public void onStart() { for (SyncRunner syncRunner : this.syncRunners) { syncRunner.start(); } }