Skip to content

Add initial member count to stream creator #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/rabbitmq/stream/StreamCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public interface StreamCreator {
*/
StreamCreator filterSize(int size);

/**
* Set the number of initial members the stream should have.
*
* @param initialMemberCount initial number of nodes
* @return this creator instance
* @see <a href="https://www.rabbitmq.com/docs/streams#replication-factor">Initial Replication
* Factor</a>
*/
StreamCreator initialMemberCount(int initialMemberCount);

/**
* Configure the super stream to create.
*
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/rabbitmq/stream/impl/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,14 @@ public StreamParametersBuilder filterSize(int size) {
return this;
}

public StreamParametersBuilder initialMemberCount(int initialMemberCount) {
if (initialMemberCount <= 0) {
throw new IllegalArgumentException("The initial member count must be greater than 0");
}
this.parameters.put("initial-cluster-size", String.valueOf(initialMemberCount));
return this;
}

public StreamParametersBuilder put(String key, String value) {
parameters.put(key, value);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public StreamCreator filterSize(int size) {
return this;
}

@Override
public StreamCreator initialMemberCount(int initialMemberCount) {
streamParametersBuilder.initialMemberCount(initialMemberCount);
return this;
}

@Override
public SuperStreamConfiguration superStream() {
if (this.superStreamConfiguration == null) {
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/rabbitmq/stream/impl/StreamEnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,17 @@ void enforceEntityPerConnectionLimits() {
executor.shutdownNow();
}
}

@Test
void brokerShouldAcceptInitialMemberCountArgument(TestInfo info) {
String s = streamName(info);
Environment env = environmentBuilder.build();
try {
env.streamCreator().name(s).initialMemberCount(1).create();
assertThat(env.streamExists(s)).isTrue();
} finally {
env.deleteStream(s);
env.close();
}
}
}