public PartitionsLeaderMatrix( final int partitionsCount, final int clusterSize, final int replicationFactor) { ensureValidValues(partitionsCount, clusterSize, replicationFactor); this.rowCount = partitionsCount; this.columnCount = clusterSize; matrix = new int[rowCount][columnCount]; this.replicationFactor = replicationFactor; init(); printMatrix(); }
private void ensureValidValues( final int partitionsCount, final int clusterSize, final int replicationFactor) { ensureLargerThen(partitionsCount, 1, "Partitions count must not be smaller then one."); ensureSmallerThen( partitionsCount, Protocol.MAXIMUM_PARTITIONS, "Partitions count must be smaller then maximum partition space of " + Protocol.MAXIMUM_PARTITIONS + "."); ensureLargerThen(clusterSize, 1, "Cluster size must not be smaller then one."); ensureLargerThen(replicationFactor, 1, "Replication factor must not be smaller then one."); ensureLargerThen( clusterSize, replicationFactor, "Cluster size must not be smaller then replication factor."); }
@Override public void onStateChange(final Raft raft, final RaftState raftState) { switch (raftState) { case LEADER: removeFollowerPartitionService(raft); installLeaderPartition(raft); break; case FOLLOWER: installFollowerPartition(raft); break; case CANDIDATE: default: removeFollowerPartitionService(raft); break; } }
public BootstrapPartitions(final BrokerCfg brokerCfg) { this.brokerCfg = brokerCfg; final ClusterCfg cluster = brokerCfg.getCluster(); partitionsLeaderMatrix = new PartitionsLeaderMatrix( cluster.getPartitionsCount(), cluster.getClusterSize(), cluster.getReplicationFactor()); final int nodeId = cluster.getNodeId(); followingPartitions = partitionsLeaderMatrix.getFollowingPartitions(nodeId); leadingPartitions = partitionsLeaderMatrix.getLeadingPartitions(nodeId); }
@Test public void shouldThrowExceptionOnSmallerClusterSizeThenReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then replication factor."); // when new PartitionsLeaderMatrix(1, 1, 2); } }
public Builder(Partition partition, ServiceName<Partition> serviceName) { this.logStream = partition.getLogStream(); this.additionalDependencies.add(serviceName); }
@Override public void onMemberJoined(final Raft raft, final Collection<Integer> currentNodeIds) { if (raft.getState() == RaftState.LEADER) { installLeaderPartition(raft); } }
@Test public void shouldThrowExceptionOnNegativeClusterSize() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then one."); // when new PartitionsLeaderMatrix(1, -1, 1); }
public PartitionsLeaderMatrix( final int partitionsCount, final int clusterSize, final int replicationFactor) { ensureValidValues(partitionsCount, clusterSize, replicationFactor); this.rowCount = partitionsCount; this.columnCount = clusterSize; matrix = new int[rowCount][columnCount]; this.replicationFactor = replicationFactor; init(); printMatrix(); }
@Override public void onStateChange(final Raft raft, final RaftState raftState) { switch (raftState) { case LEADER: removeFollowerPartitionService(raft); installLeaderPartition(raft); break; case FOLLOWER: installFollowerPartition(raft); break; case CANDIDATE: default: removeFollowerPartitionService(raft); break; } }
private void ensureValidValues( final int partitionsCount, final int clusterSize, final int replicationFactor) { ensureLargerThen(partitionsCount, 1, "Partitions count must not be smaller then one."); ensureSmallerThen( partitionsCount, Protocol.MAXIMUM_PARTITIONS, "Partitions count must be smaller then maximum partition space of " + Protocol.MAXIMUM_PARTITIONS + "."); ensureLargerThen(clusterSize, 1, "Cluster size must not be smaller then one."); ensureLargerThen(replicationFactor, 1, "Replication factor must not be smaller then one."); ensureLargerThen( clusterSize, replicationFactor, "Cluster size must not be smaller then replication factor."); }
public Builder(Partition partition, ServiceName<Partition> serviceName) { this.logStream = partition.getLogStream(); this.additionalDependencies.add(serviceName); }
@Override public void onMemberJoined(final Raft raft, final Collection<Integer> currentNodeIds) { if (raft.getState() == RaftState.LEADER) { installLeaderPartition(raft); } }
@Test public void shouldThrowExceptionOnZeroReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Replication factor must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 1, -1); }
private boolean writeCreatingDeployment( final Partition partition, final long key, final UnpackedObject event) { final RecordType recordType = RecordType.COMMAND; final ValueType valueType = ValueType.DEPLOYMENT; final Intent intent = DeploymentIntent.CREATE; logStreamWriter.wrap(partition.getLogStream()); recordMetadata.reset().recordType(recordType).valueType(valueType).intent(intent); final long position = logStreamWriter.key(key).metadataWriter(recordMetadata).valueWriter(event).tryWrite(); return position > 0; } }
@Test public void shouldThrowExceptionOnNegativeReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Replication factor must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 1, -1); }
@Test public void shouldThrowExceptionOnZeroPartitionsCount() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Partitions count must not be smaller then one."); // when new PartitionsLeaderMatrix(0, 1, 1); }
@Test public void shouldThrowExceptionToLargePartitionsCount() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Partitions count must be smaller then maximum partition space of " + Protocol.MAXIMUM_PARTITIONS + "."); // when new PartitionsLeaderMatrix((int) Protocol.MAXIMUM_PARTITIONS, 1, 1); }
@Test public void shouldThrowExceptionOnNegativePartitionsCount() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Partitions count must not be smaller then one."); // when new PartitionsLeaderMatrix(-1, 1, 1); }
@Test public void shouldThrowExceptionOnZeroClusterSize() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 0, 1); }