Skip to content
Open
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
3 changes: 3 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ allowAutoSubscriptionCreation=true
# The number of partitioned topics that is allowed to be automatically created if allowAutoTopicCreationType is partitioned.
defaultNumPartitions=1

# Default number of partitions for the system topics
systemTopicDefaultNumPartitions=1

# Enable the deletion of inactive topics. This parameter need to cooperate with the allowAutoTopicCreation parameter.
# If brokerDeleteInactiveTopicsEnabled is set to true, we should ensure that allowAutoTopicCreation is also set to true.
brokerDeleteInactiveTopicsEnabled=true
Expand Down
3 changes: 3 additions & 0 deletions conf/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,9 @@ allowAutoSubscriptionCreation=true
# The number of partitioned topics that is allowed to be automatically created if allowAutoTopicCreationType is partitioned.
defaultNumPartitions=1

# Default number of partitions for the system topics
systemTopicDefaultNumPartitions=1

### --- Transaction config variables --- ###
# Enable transaction coordinator in broker
transactionCoordinatorEnabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,12 @@ The max allowed delay for delayed delivery (in milliseconds). If the broker rece
+ " if allowAutoTopicCreationType is partitioned."
)
private int defaultNumPartitions = 1;
@FieldContext(
category = CATEGORY_STORAGE_ML,
dynamic = true,
doc = "Default number of partitions for the system topics."
)
private int systemTopicDefaultNumPartitions = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to support existing way where the default number of partitions is determined by defaultNumPartitions, for example setting this value to -1.
For backwards compatibility the default value should be -1 when this change is introduced. We could make the default 1 in master branch for the feature release of Pulsar.

@FieldContext(
category = CATEGORY_STORAGE_ML,
doc = "The class of the managed ledger storage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3729,9 +3729,11 @@ public boolean isDefaultTopicTypePartitioned(final TopicName topicName, final Op
public int getDefaultNumPartitions(final TopicName topicName, final Optional<Policies> policies) {
AutoTopicCreationOverride autoTopicCreationOverride = getAutoTopicCreationOverride(topicName, policies);
if (autoTopicCreationOverride != null) {
return autoTopicCreationOverride.getDefaultNumPartitions();
return isSystemTopic(topicName) ? autoTopicCreationOverride.getSystemTopicDefaultNumPartitions()
: autoTopicCreationOverride.getDefaultNumPartitions();
} else {
return pulsar.getConfiguration().getDefaultNumPartitions();
return isSystemTopic(topicName) ? pulsar.getConfiguration().getSystemTopicDefaultNumPartitions()
: pulsar.getConfiguration().getDefaultNumPartitions();
Comment on lines +3735 to +3736
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should check that systemTopicDefaultNumPartitions > 0.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected void setup() throws Exception {
conf.setAllowAutoTopicCreation(false);
conf.setAllowAutoTopicCreationType(TopicType.PARTITIONED);
conf.setDefaultNumPartitions(PARTITIONS);
conf.setSystemTopicDefaultNumPartitions(PARTITIONS);
conf.setManagedLedgerMaxEntriesPerLedger(1);
conf.setBrokerDeleteInactiveTopicsEnabled(false);
conf.setTransactionCoordinatorEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ public interface AutoTopicCreationOverride {

Integer getDefaultNumPartitions();

Integer getSystemTopicDefaultNumPartitions();

interface Builder {
Builder allowAutoTopicCreation(boolean allowTopicCreation);

Builder topicType(String topicType);

Builder defaultNumPartitions(Integer defaultNumPartition);

Builder systemTopicDefaultNumPartitions(Integer systemTopicDefaultNumPartitions);

AutoTopicCreationOverride build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public final class AutoTopicCreationOverrideImpl implements AutoTopicCreationOve
private boolean allowAutoTopicCreation;
private String topicType;
private Integer defaultNumPartitions;
private Integer systemTopicDefaultNumPartitions;

public static ValidateResult validateOverride(AutoTopicCreationOverride override) {
if (override == null) {
Expand All @@ -51,6 +52,14 @@ public static ValidateResult validateOverride(AutoTopicCreationOverride override
if (override.getDefaultNumPartitions() <= 0) {
return ValidateResult.fail("[defaultNumPartitions] cannot be less than 1 for partition type.");
}
if (override.getSystemTopicDefaultNumPartitions() == null) {
return ValidateResult.fail(
"[systemTopicDefaultNumPartitions] cannot be null when the type is partitioned.");
}
if (override.getSystemTopicDefaultNumPartitions() <= 0) {
return ValidateResult.fail(
"[systemTopicDefaultNumPartitions] cannot be less than 1 for partition type.");
}
Comment on lines +55 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't be backwards compatible for existing deployments of Pulsar. Please handle backwards compatibility in some way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible way would be to use defaultNumPartitions in the case that systemTopicDefaultNumPartitions is null or <= 0

} else if (TopicType.NON_PARTITIONED.toString().equals(override.getTopicType())) {
if (override.getDefaultNumPartitions() != null) {
return ValidateResult.fail("[defaultNumPartitions] is not allowed to be"
Expand All @@ -69,6 +78,7 @@ public static class AutoTopicCreationOverrideImplBuilder implements AutoTopicCre
private boolean allowAutoTopicCreation;
private String topicType;
private Integer defaultNumPartitions;
private Integer systemTopicDefaultNumPartitions;

public AutoTopicCreationOverrideImplBuilder allowAutoTopicCreation(boolean allowAutoTopicCreation) {
this.allowAutoTopicCreation = allowAutoTopicCreation;
Expand All @@ -85,8 +95,15 @@ public AutoTopicCreationOverrideImplBuilder defaultNumPartitions(Integer default
return this;
}

public AutoTopicCreationOverrideImplBuilder systemTopicDefaultNumPartitions(
Integer systemTopicDefaultNumPartitions) {
this.systemTopicDefaultNumPartitions = systemTopicDefaultNumPartitions;
return this;
}

public AutoTopicCreationOverrideImpl build() {
return new AutoTopicCreationOverrideImpl(allowAutoTopicCreation, topicType, defaultNumPartitions);
return new AutoTopicCreationOverrideImpl(allowAutoTopicCreation, topicType, defaultNumPartitions,
systemTopicDefaultNumPartitions);
}
}
}