public ProposalRequestProcessor(LeaderZooKeeperServer zks, RequestProcessor nextProcessor) { this.zks = zks; this.nextProcessor = nextProcessor; AckRequestProcessor ackProcessor = new AckRequestProcessor(zks.getLeader()); syncProcessor = new SyncRequestProcessor(zks, ackProcessor); }
public ProposalRequestProcessor(LeaderZooKeeperServer zks, RequestProcessor nextProcessor) { this.zks = zks; this.nextProcessor = nextProcessor; AckRequestProcessor ackProcessor = new AckRequestProcessor(zks.getLeader()); syncProcessor = new SyncRequestProcessor(zks, ackProcessor); }
@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { ServerStats serverStats = zkServer.serverStats(); serverStats.reset(); if (serverStats.getServerState().equals("leader")) { ((LeaderZooKeeperServer)zkServer).getLeader().getProposalStats().reset(); } pw.println("Server stats reset."); } } }
pw.println(zkServer.getZKDatabase().getNodeCount()); if (serverStats.getServerState().equals("leader")) { Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader(); BufferStats proposalStats = leader.getProposalStats(); pw.printf("Proposal sizes last/min/max: %s%n", proposalStats.toString());
@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { ServerStats serverStats = zkServer.serverStats(); serverStats.reset(); if (serverStats.getServerState().equals("leader")) { ((LeaderZooKeeperServer)zkServer).getLeader().getProposalStats().reset(); } pw.println("Server stats reset."); } } }
@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { ServerStats serverStats = zkServer.serverStats(); serverStats.reset(); if (serverStats.getServerState().equals("leader")) { ((LeaderZooKeeperServer)zkServer).getLeader().getProposalStats().reset(); } pw.println("Server stats reset."); } } }
public MockProposalRequestProcessor(LeaderZooKeeperServer zks, RequestProcessor nextProcessor) { super(zks, nextProcessor); /** * The only purpose here is to inject the mocked * SyncRequestProcessor */ AckRequestProcessor ackProcessor = new AckRequestProcessor(zks.getLeader()); syncProcessor = new MockSyncRequestProcessor(zks, ackProcessor); } }
public void processRequest(Request request) throws RequestProcessorException { // LOG.warn("Ack>>> cxid = " + request.cxid + " type = " + // request.type + " id = " + request.sessionId); // request.addRQRec(">prop"); /* In the following IF-THEN-ELSE block, we process syncs on the leader. * If the sync is coming from a follower, then the follower * handler adds it to syncHandler. Otherwise, if it is a client of * the leader that issued the sync command, then syncHandler won't * contain the handler. In this case, we add it to syncHandler, and * call processRequest on the next processor. */ if (request instanceof LearnerSyncRequest){ zks.getLeader().processSync((LearnerSyncRequest)request); } else { nextProcessor.processRequest(request); if (request.getHdr() != null) { // We need to sync and get consensus on any transactions try { zks.getLeader().propose(request); } catch (XidRolloverException e) { throw new RequestProcessorException(e.getMessage(), e); } syncProcessor.processRequest(request); } } }
pw.println(zkServer.getZKDatabase().getNodeCount()); if (serverStats.getServerState().equals("leader")) { Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader(); ProposalStats proposalStats = leader.getProposalStats(); pw.printf("Proposal sizes last/min/max: %s%n", proposalStats.toString());
@Before public void setUp() { outputWriter = new StringWriter(); ServerCnxn serverCnxnMock = mock(ServerCnxn.class); LeaderZooKeeperServer zks = mock(LeaderZooKeeperServer.class); when(zks.isRunning()).thenReturn(true); providerMock = mock(ServerStats.Provider.class); when(zks.serverStats()).thenReturn(new ServerStats(providerMock)); ZKDatabase zkDatabaseMock = mock(ZKDatabase.class); when(zks.getZKDatabase()).thenReturn(zkDatabaseMock); Leader leaderMock = mock(Leader.class); when(leaderMock.getProposalStats()).thenReturn(new BufferStats()); when(zks.getLeader()).thenReturn(leaderMock); ServerCnxnFactory serverCnxnFactory = mock(ServerCnxnFactory.class); ServerCnxn serverCnxn = mock(ServerCnxn.class); List<ServerCnxn> connections = new ArrayList<>(); connections.add(serverCnxn); when(serverCnxnFactory.getConnections()).thenReturn(connections); statCommand = new StatCommand(new PrintWriter(outputWriter), serverCnxnMock, FourLetterCommands.statCmd); statCommand.setZkServer(zks); statCommand.setFactory(serverCnxnFactory); }
pw.println(zkServer.getZKDatabase().getNodeCount()); if (serverStats.getServerState().equals("leader")) { Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader(); ProposalStats proposalStats = leader.getProposalStats(); pw.printf("Proposal sizes last/min/max: %s%n", proposalStats.toString());
public void processRequest(Request request) throws RequestProcessorException { // LOG.warn("Ack>>> cxid = " + request.cxid + " type = " + // request.type + " id = " + request.sessionId); // request.addRQRec(">prop"); /* In the following IF-THEN-ELSE block, we process syncs on the leader. * If the sync is coming from a follower, then the follower * handler adds it to syncHandler. Otherwise, if it is a client of * the leader that issued the sync command, then syncHandler won't * contain the handler. In this case, we add it to syncHandler, and * call processRequest on the next processor. */ if(request instanceof LearnerSyncRequest){ zks.getLeader().processSync((LearnerSyncRequest)request); } else { nextProcessor.processRequest(request); if (request.hdr != null) { // We need to sync and get consensus on any transactions try { zks.getLeader().propose(request); } catch (XidRolloverException e) { throw new RequestProcessorException(e.getMessage(), e); } syncProcessor.processRequest(request); } } }
@Test public void testStatResetWithLeader() { // Arrange LeaderZooKeeperServer leaderZks = mock(LeaderZooKeeperServer.class); when(leaderZks.isRunning()).thenReturn(true); when(leaderZks.serverStats()).thenReturn(serverStats); Leader leader = mock(Leader.class); when(leaderZks.getLeader()).thenReturn(leader); statResetCommand.setZkServer(leaderZks); when(serverStats.getServerState()).thenReturn("leader"); BufferStats bufferStats = mock(BufferStats.class); when(leader.getProposalStats()).thenReturn(bufferStats); // Act statResetCommand.commandRun(); // Assert String output = outputWriter.toString(); assertEquals("Server stats reset.\n", output); verify(serverStats, times(1)).reset(); verify(bufferStats, times(1)).reset(); } }
@Override protected void setupRequestProcessors() { RequestProcessor finalProcessor = new FinalRequestProcessor(this); RequestProcessor toBeAppliedProcessor = new Leader.ToBeAppliedRequestProcessor(finalProcessor, getLeader()); commitProcessor = new CommitProcessor(toBeAppliedProcessor, Long.toString(getServerId()), false, getZooKeeperServerListener()); commitProcessor.start(); ProposalRequestProcessor proposalProcessor = new ProposalRequestProcessor(this, commitProcessor); proposalProcessor.initialize(); prepRequestProcessor = new PrepRequestProcessor(this, proposalProcessor); prepRequestProcessor.start(); firstProcessor = new LeaderRequestProcessor(this, prepRequestProcessor); setupContainerManager(); }
@Override protected void setupRequestProcessors() { RequestProcessor finalProcessor = new FinalRequestProcessor(this); RequestProcessor toBeAppliedProcessor = new Leader.ToBeAppliedRequestProcessor( finalProcessor, getLeader().toBeApplied); commitProcessor = new CommitProcessor(toBeAppliedProcessor, Long.toString(getServerId()), false, getZooKeeperServerListener()); commitProcessor.start(); ProposalRequestProcessor proposalProcessor = new ProposalRequestProcessor(this, commitProcessor); proposalProcessor.initialize(); firstProcessor = new PrepRequestProcessor(this, proposalProcessor); ((PrepRequestProcessor)firstProcessor).start(); }
@Override public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) { CommandResponse response = initializeResponse(); LOG.info("running stat"); response.put("version", Version.getFullVersion()); response.put("read_only", zkServer instanceof ReadOnlyZooKeeperServer); response.put("server_stats", zkServer.serverStats()); response.put("client_response", zkServer.serverStats().getClientResponseStats()); if (zkServer instanceof LeaderZooKeeperServer) { Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader(); response.put("proposal_stats", leader.getProposalStats()); } response.put("node_count", zkServer.getZKDatabase().getNodeCount()); return response; } }
Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader();
Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader();
Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader();
Leader leader = ((LeaderZooKeeperServer) zkServer).getLeader();