private void updateClocks(final long nowNs) { if (clockUpdateDeadlineNs - nowNs < 0) { clockUpdateDeadlineNs = nowNs + CLOCK_UPDATE_DURATION_NS; cachedNanoClock.update(nowNs); cachedEpochClock.update(epochClock.time()); } }
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; }
@Test public void shouldCloseInactiveSession() { final CachedEpochClock clock = new CachedEpochClock(); final long startMs = 7L; clock.update(startMs); ctx.epochClock(clock); final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx); final long correlationId = 1L; agent.state(ConsensusModule.State.ACTIVE); agent.role(Cluster.Role.LEADER); agent.appendedPositionCounter(mock(ReadableCounter.class)); agent.onSessionConnect(correlationId, 2, RESPONSE_CHANNEL_ONE, new byte[0]); agent.doWork(); verify(mockLogPublisher).appendSessionOpen(any(ClusterSession.class), anyLong(), eq(startMs)); final long timeMs = startMs + TimeUnit.NANOSECONDS.toMillis(ConsensusModule.Configuration.sessionTimeoutNs()); clock.update(timeMs); agent.doWork(); final long timeoutMs = timeMs + 1L; clock.update(timeoutMs); agent.doWork(); verify(mockTimedOutClientCounter).incrementOrdered(); verify(mockLogPublisher).appendSessionClose(any(ClusterSession.class), anyLong(), eq(timeoutMs)); verify(mockEgressPublisher).sendEvent( any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.ERROR), eq(SESSION_TIMEOUT_MSG)); }
@Test public void shouldCloseTerminatedSession() { final CachedEpochClock clock = new CachedEpochClock(); final long startMs = 7L; clock.update(startMs); ctx.epochClock(clock); final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx); final long correlationId = 1L; agent.state(ConsensusModule.State.ACTIVE); agent.role(Cluster.Role.LEADER); agent.appendedPositionCounter(mock(ReadableCounter.class)); agent.onSessionConnect(correlationId, 2, RESPONSE_CHANNEL_ONE, new byte[0]); agent.doWork(); final ArgumentCaptor<ClusterSession> sessionCaptor = ArgumentCaptor.forClass(ClusterSession.class); verify(mockLogPublisher).appendSessionOpen(sessionCaptor.capture(), anyLong(), eq(startMs)); final long timeMs = startMs + 1; clock.update(timeMs); agent.doWork(); agent.onServiceCloseSession(sessionCaptor.getValue().id()); verify(mockLogPublisher).appendSessionClose(any(ClusterSession.class), anyLong(), eq(timeMs)); verify(mockEgressPublisher).sendEvent( any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.ERROR), eq(SESSION_TERMINATED_MSG)); }
@Test public void shouldUpdateEpochClock() { final long timestamp = 333L; final CachedEpochClock clock = new CachedEpochClock(); assertThat(clock.time(), is(0L)); clock.update(timestamp); assertThat(clock.time(), is(timestamp)); } }
@Test public void shouldLimitActiveSessions() { final CachedEpochClock clock = new CachedEpochClock(); ctx.maxConcurrentSessions(1); ctx.epochClock(clock); final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx); final long correlationIdOne = 1L; agent.state(ConsensusModule.State.ACTIVE); agent.role(Cluster.Role.LEADER); agent.appendedPositionCounter(mock(ReadableCounter.class)); agent.onSessionConnect(correlationIdOne, 2, RESPONSE_CHANNEL_ONE, new byte[0]); clock.update(1); agent.doWork(); verify(mockLogPublisher).appendSessionOpen(any(ClusterSession.class), anyLong(), anyLong()); final long correlationIdTwo = 2L; agent.onSessionConnect(correlationIdTwo, 3, RESPONSE_CHANNEL_TWO, new byte[0]); clock.update(2); agent.doWork(); verify(mockEgressPublisher).sendEvent( any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.ERROR), eq(SESSION_LIMIT_MSG)); }
clock.update(t2); election.onRequestVote(leadershipTermId, logPosition, candidateTermId, candidateId); verify(memberStatusPublisher).placeVote(
clock.update(t1); election.doWork(t1); assertThat(election.state(), is(Election.State.CANVASS)); clock.update(t2); election.doWork(t2); assertThat(election.state(), is(Election.State.NOMINATE)); clock.update(t3); election.doWork(t3); election.doWork(t3); clock.update(t3); election.doWork(t3); assertThat(election.state(), is(Election.State.LEADER_REPLAY)); clock.update(t5); election.doWork(t5); election.doWork(t5); clock.update(t6); final int logSessionId = -7; election.logSessionId(logSessionId); clock.update(t7); election.onAppendedPosition(candidateTermId, logPosition, clusterMembers[1].id()); election.onAppendedPosition(candidateTermId, logPosition, clusterMembers[2].id());
ArchiveConductor(final Archive.Context ctx) { super("archive-conductor", ctx.countedErrorHandler()); this.ctx = ctx; aeron = ctx.aeron(); aeronAgentInvoker = aeron.conductorAgentInvoker(); driverAgentInvoker = ctx.mediaDriverAgentInvoker(); epochClock = ctx.epochClock(); archiveDir = ctx.archiveDir(); archiveDirChannel = ctx.archiveDirChannel(); maxConcurrentRecordings = ctx.maxConcurrentRecordings(); maxConcurrentReplays = ctx.maxConcurrentReplays(); connectTimeoutMs = TimeUnit.NANOSECONDS.toMillis(ctx.connectTimeoutNs()); final ChannelUri controlChannelUri = ChannelUri.parse(ctx.controlChannel()); controlChannelUri.put(CommonContext.SPARSE_PARAM_NAME, Boolean.toString(ctx.controlTermBufferSparse())); controlSubscription = aeron.addSubscription(controlChannelUri.toString(), ctx.controlStreamId(), this, null); localControlSubscription = aeron.addSubscription( ctx.localControlChannel(), ctx.localControlStreamId(), this, null); recordingEventsProxy = new RecordingEventsProxy( aeron.addExclusivePublication(ctx.recordingEventsChannel(), ctx.recordingEventsStreamId())); cachedEpochClock.update(epochClock.time()); catalog = ctx.catalog(); markFile = ctx.archiveMarkFile(); }
cachedEpochClock.update(epochClock.time()); timeOfLastTimerCheckNs = nowNs; timeOfLastToDriverPositionChangeNs = nowNs;
private void updateClocks(final long nowNs) { if (clockUpdateDeadlineNs - nowNs < 0) { clockUpdateDeadlineNs = nowNs + CLOCK_UPDATE_DURATION_NS; cachedNanoClock.update(nowNs); cachedEpochClock.update(epochClock.time()); } }
private void updateClocks(final long nowNs) { if (clockUpdateDeadlineNs - nowNs < 0) { clockUpdateDeadlineNs = nowNs + CLOCK_UPDATE_DURATION_NS; cachedNanoClock.update(nowNs); cachedEpochClock.update(epochClock.time()); } }
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; }
ArchiveConductor(final Archive.Context ctx) { super("archive-conductor", ctx.countedErrorHandler()); this.ctx = ctx; aeron = ctx.aeron(); aeronAgentInvoker = aeron.conductorAgentInvoker(); driverAgentInvoker = ctx.mediaDriverAgentInvoker(); epochClock = ctx.epochClock(); archiveDir = ctx.archiveDir(); archiveDirChannel = ctx.archiveDirChannel(); maxConcurrentRecordings = ctx.maxConcurrentRecordings(); maxConcurrentReplays = ctx.maxConcurrentReplays(); connectTimeoutMs = TimeUnit.NANOSECONDS.toMillis(ctx.connectTimeoutNs()); final ChannelUri controlChannelUri = ChannelUri.parse(ctx.controlChannel()); controlChannelUri.put(CommonContext.SPARSE_PARAM_NAME, Boolean.toString(ctx.controlTermBufferSparse())); controlSubscription = aeron.addSubscription(controlChannelUri.toString(), ctx.controlStreamId(), this, null); localControlSubscription = aeron.addSubscription( ctx.localControlChannel(), ctx.localControlStreamId(), this, null); recordingEventsProxy = new RecordingEventsProxy( aeron.addExclusivePublication(ctx.recordingEventsChannel(), ctx.recordingEventsStreamId())); cachedEpochClock.update(epochClock.time()); catalog = ctx.catalog(); markFile = ctx.archiveMarkFile(); }
cachedEpochClock.update(epochClock.time()); timeOfLastTimerCheckNs = nowNs; timeOfLastToDriverPositionChangeNs = nowNs;
cachedEpochClock.update(epochClock.time()); timeOfLastTimerCheckNs = nowNs; timeOfLastToDriverPositionChangeNs = nowNs;