Skip to content

Commit 1c523fc

Browse files
authored
Merge pull request #496 from Eistern/feature/add-max-active-partitions
Add max_active_partitions support to topic operations
2 parents 6d8282d + 5216bbd commit 1c523fc

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

topic/src/main/java/tech/ydb/topic/impl/TopicClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public CompletableFuture<Status> alterTopic(String path, AlterTopicSettings sett
160160
if (minActivePartitions != null) {
161161
builder.setSetMinActivePartitions(minActivePartitions);
162162
}
163+
Long maxActivePartitions = partitioningSettings.getMaxActivePartitions();
164+
if (maxActivePartitions != null) {
165+
builder.setSetMaxActivePartitions(maxActivePartitions);
166+
}
163167
Long partitionCountLimit = partitioningSettings.getPartitionCountLimit();
164168
if (partitionCountLimit != null) {
165169
builder.setSetPartitionCountLimit(partitionCountLimit);
@@ -321,6 +325,7 @@ private TopicDescription mapDescribeTopic(YdbTopic.DescribeTopicResult result) {
321325

322326
PartitioningSettings.Builder partitioningDescription = PartitioningSettings.newBuilder()
323327
.setMinActivePartitions(partitioningSettings.getMinActivePartitions())
328+
.setMaxActivePartitions(partitioningSettings.getMaxActivePartitions())
324329
.setPartitionCountLimit(partitioningSettings.getPartitionCountLimit())
325330
.setAutoPartitioningStrategy(fromProto(autoPartitioningStrategy));
326331

topic/src/main/java/tech/ydb/topic/settings/AlterPartitioningSettings.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class AlterPartitioningSettings {
99
@Nullable
1010
private final Long minActivePartitions;
1111
@Nullable
12+
private final Long maxActivePartitions;
13+
@Nullable
1214
private final Long partitionCountLimit;
1315
@Nullable
1416
private final AutoPartitioningStrategy autoPartitioningStrategy;
@@ -17,6 +19,7 @@ public class AlterPartitioningSettings {
1719

1820
private AlterPartitioningSettings(Builder builder) {
1921
this.minActivePartitions = builder.minActivePartitions;
22+
this.maxActivePartitions = builder.maxActivePartitions;
2023
this.partitionCountLimit = builder.partitionCountLimit;
2124
this.autoPartitioningStrategy = builder.autoPartitioningStrategy;
2225
this.writeStrategySettings = builder.writeStrategySettings;
@@ -31,6 +34,11 @@ public Long getMinActivePartitions() {
3134
return minActivePartitions;
3235
}
3336

37+
@Nullable
38+
public Long getMaxActivePartitions() {
39+
return maxActivePartitions;
40+
}
41+
3442
@Nullable
3543
public Long getPartitionCountLimit() {
3644
return partitionCountLimit;
@@ -51,6 +59,7 @@ public AlterAutoPartitioningWriteStrategySettings getWriteStrategySettings() {
5159
*/
5260
public static class Builder {
5361
private Long minActivePartitions = null;
62+
private Long maxActivePartitions = null;
5463
private Long partitionCountLimit = null;
5564
private AutoPartitioningStrategy autoPartitioningStrategy = null;
5665
private AlterAutoPartitioningWriteStrategySettings writeStrategySettings = null;
@@ -65,11 +74,22 @@ public Builder setMinActivePartitions(long minActivePartitions) {
6574
return this;
6675
}
6776

77+
/**
78+
* @param maxActivePartitions maximum partition count auto merge would stop working at.
79+
* Zero value means default - 1.
80+
* @return settings builder
81+
*/
82+
public Builder setMaxActivePartitions(long maxActivePartitions) {
83+
this.maxActivePartitions = maxActivePartitions;
84+
return this;
85+
}
86+
6887
/**
6988
* @param partitionCountLimit Limit for total partition count, including active (open for write) and
7089
* read-only partitions.
7190
* Zero value means default - 100.
7291
* @return settings builder
92+
* @deprecated Use {@link #setMaxActivePartitions(long)} instead
7393
*/
7494
public Builder setPartitionCountLimit(long partitionCountLimit) {
7595
this.partitionCountLimit = partitionCountLimit;

topic/src/main/java/tech/ydb/topic/settings/PartitioningSettings.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
*/
88
public class PartitioningSettings {
99
private final long minActivePartitions;
10+
private final long maxActivePartitions;
1011
private final long partitionCountLimit;
1112
private final AutoPartitioningStrategy autoPartitioningStrategy;
1213
private final AutoPartitioningWriteStrategySettings writeStrategySettings;
1314

1415
private PartitioningSettings(Builder builder) {
1516
this.minActivePartitions = builder.minActivePartitions;
17+
this.maxActivePartitions = builder.maxActivePartitions;
1618
this.partitionCountLimit = builder.partitionCountLimit;
1719
this.autoPartitioningStrategy = builder.autoPartitioningStrategy;
1820
this.writeStrategySettings = builder.writeStrategySettings;
@@ -26,10 +28,19 @@ public long getMinActivePartitions() {
2628
return minActivePartitions;
2729
}
2830

31+
/**
32+
* @return maximum partition count auto merge would stop working at.
33+
* Zero value means default - 1.
34+
*/
35+
public long getMaxActivePartitions() {
36+
return maxActivePartitions;
37+
}
38+
2939
/**
3040
* @return Limit for total partition count, including active (open for write) and
3141
* read-only partitions.
3242
* Zero value means default - 100.
43+
* @deprecated Use {@link #getMaxActivePartitions()} instead
3344
*/
3445
public long getPartitionCountLimit() {
3546
return partitionCountLimit;
@@ -58,6 +69,7 @@ public static Builder newBuilder() {
5869
*/
5970
public static class Builder {
6071
private long minActivePartitions = 0;
72+
private long maxActivePartitions = 0;
6173
private long partitionCountLimit = 0;
6274
private AutoPartitioningStrategy autoPartitioningStrategy = AutoPartitioningStrategy.DISABLED;
6375
private AutoPartitioningWriteStrategySettings writeStrategySettings = null;
@@ -72,12 +84,24 @@ public Builder setMinActivePartitions(long minActivePartitions) {
7284
return this;
7385
}
7486

87+
/**
88+
* @param maxActivePartitions maximum partition count auto merge would stop working at.
89+
* Zero value means default - 1.
90+
* @return settings builder
91+
*/
92+
public Builder setMaxActivePartitions(long maxActivePartitions) {
93+
this.maxActivePartitions = maxActivePartitions;
94+
return this;
95+
}
96+
7597
/**
7698
* @param partitionCountLimit Limit for total partition count, including active (open for write) and
7799
* read-only partitions.
78100
* Zero value means default - 100.
79101
* @return settings builder
102+
* @deprecated Use {@link #setMaxActivePartitions(long)} instead.
80103
*/
104+
@Deprecated
81105
public Builder setPartitionCountLimit(long partitionCountLimit) {
82106
this.partitionCountLimit = partitionCountLimit;
83107
return this;
@@ -120,13 +144,20 @@ public boolean equals(Object o) {
120144
}
121145
PartitioningSettings that = (PartitioningSettings) o;
122146
return minActivePartitions == that.minActivePartitions &&
147+
maxActivePartitions == that.maxActivePartitions &&
123148
partitionCountLimit == that.partitionCountLimit &&
124149
autoPartitioningStrategy == that.autoPartitioningStrategy &&
125150
Objects.equals(writeStrategySettings, that.writeStrategySettings);
126151
}
127152

128153
@Override
129154
public int hashCode() {
130-
return Objects.hash(minActivePartitions, partitionCountLimit, autoPartitioningStrategy, writeStrategySettings);
155+
return Objects.hash(
156+
minActivePartitions,
157+
maxActivePartitions,
158+
partitionCountLimit,
159+
autoPartitioningStrategy,
160+
writeStrategySettings
161+
);
131162
}
132163
}

topic/src/test/java/tech/ydb/topic/impl/YdbTopicsIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void step07_alterTopicWithAutoPartitioning() {
268268
.setDownUtilizationPercent(20)
269269
.build())
270270
.setMinActivePartitions(1)
271-
.setPartitionCountLimit(0)
271+
.setMaxActivePartitions(1)
272272
.build();
273273

274274
Assert.assertEquals(expectedPartitioningSettings, actualPartitioningSettings);

0 commit comments

Comments
 (0)