@Override public int id() { return serverAddress.hashCode(); }
@Override public int hashCode() { return serverAddress.hashCode(); }
@Override public int id() { return serverAddress.hashCode(); }
@Override public int hashCode() { return serverAddress.hashCode(); }
@Override public int hashCode() { return serverAddress.hashCode(); }
@Override public int id() { return serverAddress.hashCode(); }
/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ private CompletableFuture<Connection> createConnection(Address address) { return client.connect(address).thenApply(connection -> { connections.put(address.hashCode(), connection); connection.closeListener(c -> connections.remove(address.hashCode())); return connection; }); }
/** * Returns the connection for the given member. * * @param address The member for which to get the connection. * @return A completable future to be called once the connection is received. */ private CompletableFuture<Connection> getConnection(Address address) { Connection connection = connections.get(address.hashCode()); return connection == null ? createConnection(address) : CompletableFuture.completedFuture(connection); }
@Override public int id() { return serverAddress.hashCode(); }
/** * Creates a connection for the given member. * * @param address The member for which to create the connection. * @return A completable future to be called once the connection has been created. */ CompletableFuture<Connection> createConnection(Address address) { return client.connect(address).thenApply(connection -> { connections.put(address.hashCode(), connection); connection.closeListener(c -> connections.remove(address.hashCode())); return connection; }); }
/** * Returns the connection for the given member. * * @param address The member for which to get the connection. * @return A completable future to be called once the connection is received. */ CompletableFuture<Connection> getConnection(Address address) { ComposableFuture<Connection> future = new ComposableFuture<>(); context.executor().execute(() -> { Connection connection = connections.get(address.hashCode()); if (connection != null) { future.complete(connection); } else { createConnection(address).whenComplete(future); } }); return future; }
/** * Creates a Copycat server. */ private CopycatServer createServer(Member member) { CopycatServer.Builder builder = CopycatServer.builder(member.clientAddress(), member.serverAddress()) .withType(member.type()) .withTransport(new NettyTransport()) .withStorage(Storage.builder() .withStorageLevel(StorageLevel.DISK) .withDirectory(new File(String.format("target/performance-logs/%d", member.address().hashCode()))) .withCompactionThreads(1) .build()) .withStateMachine(PerformanceStateMachine::new); CopycatServer server = builder.build(); server.serializer().disableWhitelist(); servers.add(server); return server; }
/** * Creates a Copycat server. */ private CopycatServer createServer(Member member) { CopycatServer.Builder builder = CopycatServer.builder(member.clientAddress(), member.serverAddress()) .withType(member.type()) .withTransport(new NettyTransport()) .withStorage(Storage.builder() .withStorageLevel(StorageLevel.DISK) .withDirectory(new File(String.format("target/fuzz-logs/%d", member.address().hashCode()))) .withMaxSegmentSize(randomNumber(1024 * 1024 * 7) + (1024 * 1024)) .withMaxEntriesPerSegment(randomNumber(10000) + 1000) .withCompactionThreads(randomNumber(4) + 1) .withCompactionThreshold(Math.random() / (double) 2) .withEntryBufferSize(randomNumber(10000) + 1) .withFlushOnCommit(randomBoolean()) .withMinorCompactionInterval(Duration.ofSeconds(randomNumber(30) + 15)) .withMajorCompactionInterval(Duration.ofSeconds(randomNumber(60) + 60)) .build()) .withStateMachine(FuzzStateMachine::new); CopycatServer server = builder.build(); server.serializer().disableWhitelist(); servers.add(server); return server; }
PollRequest request = PollRequest.builder() .withTerm(context.getTerm()) .withCandidate(context.getCluster().member().address().hashCode()) .withLogIndex(lastIndex) .withLogTerm(lastTerm)
@Override public CompletableFuture<VoteResponse> vote(VoteRequest request) { context.checkThread(); logRequest(request); // If the request indicates a term that is greater than the current term then // assign that term and leader to the current context and step down as a candidate. if (updateTermAndLeader(request.term(), 0)) { CompletableFuture<VoteResponse> future = super.vote(request); context.transition(CopycatServer.State.FOLLOWER); return future; } // If the vote request is not for this candidate then reject the vote. if (request.candidate() == context.getCluster().member().address().hashCode()) { return CompletableFuture.completedFuture(logResponse(VoteResponse.builder() .withStatus(Response.Status.OK) .withTerm(context.getTerm()) .withVoted(true) .build())); } else { return CompletableFuture.completedFuture(logResponse(VoteResponse.builder() .withStatus(Response.Status.OK) .withTerm(context.getTerm()) .withVoted(false) .build())); } }