private boolean hasGoneInactive() { return activityDeadlineMs != Aeron.NULL_VALUE && epochClock.time() > activityDeadlineMs; }
private void updateClocks(final long nowNs) { if (clockUpdateDeadlineNs - nowNs < 0) { clockUpdateDeadlineNs = nowNs + CLOCK_UPDATE_DURATION_NS; cachedNanoClock.update(nowNs); cachedEpochClock.update(epochClock.time()); } }
private int checkLiveness(final long nowNs) { if ((timeOfLastKeepAliveNs + keepAliveIntervalNs) - nowNs < 0) { if (epochClock.time() > (driverProxy.timeOfLastDriverKeepaliveMs() + driverTimeoutMs)) { isTerminating = true; forceCloseResources(); Thread.yield(); throw new DriverTimeoutException("MediaDriver keepalive older than (ms): " + driverTimeoutMs); } driverProxy.sendClientKeepalive(); timeOfLastKeepAliveNs = nowNs; return 1; } return 0; }
@Test public void shouldTimeoutIfConnectSentButPublicationNotConnected() { when(mockEpochClock.time()).thenReturn(0L); when(mockControlPublication.isClosed()).thenReturn(false); when(mockControlPublication.isConnected()).thenReturn(false); session.doWork(); when(mockEpochClock.time()).thenReturn(CONNECT_TIMEOUT_MS + 1L); session.doWork(); assertTrue(session.isDone()); }
boolean pollForEndOfSnapshotLoad(final Counter recoveryStateCounter) { consensusModuleAdapter.poll(); if (ServiceAck.hasReachedPosition(expectedAckPosition, serviceAckId, serviceAcks)) { ++serviceAckId; recoveryStateCounter.close(); if (ConsensusModule.State.SUSPENDED != state) { state(ConsensusModule.State.ACTIVE); } timeOfLastLogUpdateMs = cachedTimeMs = epochClock.time(); leadershipTermId = recoveryPlan.lastLeadershipTermId; return true; } return false; }
public ArchiveMarkFile(final Archive.Context ctx) { this(new File(ctx.archiveDir(), FILENAME), alignedTotalFileLength(ctx), ctx.epochClock(), 0); encode(ctx); updateActivityTimestamp(ctx.epochClock().time()); signalReady(); }
private void awaitActiveLog() { idleStrategy.reset(); while (null == activeLogEvent) { serviceAdapter.poll(); checkInterruptedStatus(); heartbeatCounter.setOrdered(epochClock.time()); idleStrategy.idle(); } }
/** * Free the counter identified by counterId. * * @param counterId the counter to freed */ public void free(final int counterId) { final int recordOffset = metaDataOffset(counterId); metaDataBuffer.putLong( recordOffset + FREE_FOR_REUSE_DEADLINE_OFFSET, epochClock.time() + freeToReuseTimeoutMs); metaDataBuffer.putIntOrdered(recordOffset, RECORD_RECLAIMED); freeList.addInt(counterId); }
@Test public void shouldReadFirstObservation() { final ErrorConsumer consumer = mock(ErrorConsumer.class); final long timestamp = 7; final RuntimeException error = new RuntimeException("Test Error"); when(clock.time()).thenReturn(timestamp); log.record(error); assertThat(ErrorLogReader.read(buffer, consumer), is(1)); verify(consumer).accept(eq(1), eq(timestamp), eq(timestamp), any(String.class)); }
@Test public void shouldTimeoutIfConnectSentButPublicationFailsToSend() { when(mockEpochClock.time()).thenReturn(0L); when(mockControlPublication.isClosed()).thenReturn(false); when(mockControlPublication.isConnected()).thenReturn(true); session.doWork(); session.sendOkResponse(1L, mockProxy); session.doWork(); when(mockEpochClock.time()).thenReturn(CONNECT_TIMEOUT_MS + 1L); session.doWork(); assertTrue(session.isDone()); } }
@Test public void shouldFailToRecordWhenInsufficientSpace() { final long timestamp = 7; final RuntimeException error = new RuntimeException("Test Error"); when(clock.time()).thenReturn(timestamp); when(buffer.capacity()).thenReturn(32); assertFalse(log.record(error)); } }
void closeRecordingSession(final RecordingSession session) { final long recordingId = session.sessionId(); catalog.recordingStopped(recordingId, session.recordingPosition().get(), epochClock.time()); recordingSessionByIdMap.remove(recordingId); closeSession(session); }
void onAppendedPosition(final long leadershipTermId, final long logPosition, final int followerMemberId) { final ClusterMember follower = clusterMemberByIdMap.get(followerMemberId); if (null != follower) { follower .logPosition(logPosition) .leadershipTermId(leadershipTermId) .timeOfLastAppendPositionMs(ctx.epochClock().time()); consensusModuleAgent.checkCatchupStop(follower); } }
private int awaitRecoveryCounter(final CountersReader counters) { idleStrategy.reset(); int counterId = RecoveryState.findCounterId(counters); while (NULL_COUNTER_ID == counterId) { checkInterruptedStatus(); idleStrategy.idle(); heartbeatCounter.setOrdered(epochClock.time()); counterId = RecoveryState.findCounterId(counters); } return counterId; }
protected int preWork() { int workCount = 0; final long nowMs = epochClock.time(); if (cachedEpochClock.time() != nowMs) { cachedEpochClock.update(nowMs); markFile.updateActivityTimestamp(nowMs); workCount += aeronAgentInvoker.invoke(); } workCount += invokeDriverConductor(); workCount += runTasks(taskQueue); return workCount; }
private void checkForSnapshot(final CountersReader counters, final int recoveryCounterId) { clusterTimeMs = RecoveryState.getTimestamp(counters, recoveryCounterId); final long leadershipTermId = RecoveryState.getLeadershipTermId(counters, recoveryCounterId); if (NULL_VALUE != leadershipTermId) { loadSnapshot(RecoveryState.getSnapshotRecordingId(counters, recoveryCounterId, serviceId)); } heartbeatCounter.setOrdered(epochClock.time()); consensusModuleProxy.ack(RecoveryState.getLogPosition(counters, recoveryCounterId), ackId++, serviceId); }
private ReadableCounter awaitCommitPositionCounter(final CountersReader counters) { idleStrategy.reset(); int counterId = CommitPos.findCounterId(counters); while (NULL_COUNTER_ID == counterId) { checkInterruptedStatus(); idleStrategy.idle(); heartbeatCounter.setOrdered(epochClock.time()); counterId = CommitPos.findCounterId(counters); } return new ReadableCounter(counters, counterId); }
public void onStart() { final CountersReader counters = aeron.countersReader(); roleCounter = awaitClusterRoleCounter(counters); heartbeatCounter = awaitHeartbeatCounter(counters); commitPosition = awaitCommitPositionCounter(counters); service.onStart(this); isServiceActive = true; final int recoveryCounterId = awaitRecoveryCounter(counters); heartbeatCounter.setOrdered(epochClock.time()); checkForSnapshot(counters, recoveryCounterId); checkForReplay(counters, recoveryCounterId); }
private void checkForReplay(final CountersReader counters, final int recoveryCounterId) { if (RecoveryState.hasReplay(counters, recoveryCounterId)) { awaitActiveLog(); try (Subscription subscription = aeron.addSubscription(activeLogEvent.channel, activeLogEvent.streamId)) { consensusModuleProxy.ack(activeLogEvent.logPosition, ackId++, serviceId); final Image image = awaitImage(activeLogEvent.sessionId, subscription); final BoundedLogAdapter adapter = new BoundedLogAdapter(image, commitPosition, this); consumeImage(image, adapter, activeLogEvent.maxLogPosition); } activeLogEvent = null; heartbeatCounter.setOrdered(epochClock.time()); } }
public void encode(final Archive.Context ctx) { headerEncoder .startTimestamp(ctx.epochClock().time()) .controlStreamId(ctx.controlStreamId()) .localControlStreamId(ctx.localControlStreamId()) .eventsStreamId(ctx.recordingEventsStreamId()) .controlChannel(ctx.controlChannel()) .localControlChannel(ctx.localControlChannel()) .eventsChannel(ctx.recordingEventsChannel()) .aeronDirectory(ctx.aeron().context().aeronDirectoryName()); }