Skip to content

Commit 717b919

Browse files
ElenaAfinablinkov
andauthored
autopartitioning-eng (#10532)
Co-authored-by: Ivan Blinkov <ivan@ydb.tech>
1 parent 21ff1db commit 717b919

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

ydb/docs/en/core/concepts/topic.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,63 @@ Messages may contain user-defined attributes in "key-value" format. They are ret
1919

2020
## Partitioning {#partitioning}
2121

22-
To enable horizontal scaling, a topic is divided into `partitions` that are units of parallelism. Each partition has a limited bandwidth. The recommended write speed is 1 MBps.
22+
To enable horizontal scaling, a topic is divided into `partitions` that are units of parallelism. Each partition has a limited throughput. The recommended write speed is 1 MBps.
2323

2424
{% note info %}
2525

2626
As for now, you can only reduce the number of partitions in a topic by deleting and recreating a topic with a smaller number of partitions.
2727

2828
{% endnote %}
2929

30+
Partitions can be:
31+
32+
- **Active.** By default, all partitions are active. Both read and write operations are allowed on an active partition.
33+
- **Inactive.** An inactive partition is read-only. A partition becomes inactive after splitting for [autopartitioning](#autopartitioning). It is automatically deleted once all messages are removed due to the expiration of the retention period.
34+
3035
### Offset {#offset}
3136

3237
All messages within a partition have a unique sequence number called an `offset` An offset monotonically increases as new messages are written.
3338

39+
## Autopartitioning {#autopartitioning}
40+
41+
Total topic throughput is determined by the number of partitions in the topic and the throughput of each partition. The number of partitions and the throughput of each partition are set at the time of topic creation. If the maximum required write speed for a topic is unknown at the creation time, autopartitioning allows the topic to be scaled automatically. If autopartitioning is enabled for a topic, the number of partitions will increase automatically as the write speed increases (see [Autopartitioning strategies](#autopartitioning_strategies)).
42+
43+
### Guarantees {#autopartitioning_guarantee}
44+
45+
1. The SDK and server provide an exactly-once guarantee in the case of writing during a partition split. This means that any message will be written either to the parent partition or to one of the child partitions but never to both simultaneously. Additionally, a message cannot be written to the same partition multiple times.
46+
2. The SDK and server maintain the reading order. Data is read from the parent partition first, followed by the child partitions.
47+
3. As a result, the exactly-once writing guarantee and the reading order guarantee are preserved for a specific [producer identifier](#producer-id).
48+
49+
### Autopartitioning strategies {#autopartitioning_strategies}
50+
51+
The following autopartitioning strategies are available for any topic:
52+
53+
#### DISABLED
54+
55+
Autopartitioning is disabled for this topic. The number of partitions remains constant, and there is no automatic scaling.
56+
57+
The initial number of partitions is set during topic creation. If the partition count is manually adjusted, new partitions are added. Both previously existing and new partitions are active.
58+
59+
#### UP
60+
61+
Upwards autopartitioning is enabled for this topic. This means that if the write speed to the topic increases, the number of partitions will automatically increase. However, if the write speed decreases, the number of partitions remains unchanged.
62+
63+
The partition count increase algorithm works as follows: if the write speed for a partition exceeds a defined threshold (as a percentage of the maximum write speed for that partition) during a specified period, the partition is split into two child partitions. The original partition becomes inactive, allowing only read operations. When the retention period expires, and all messages in the original partition are deleted, the partition itself is also deleted. The two new child partitions become active, allowing both read and write operations.
64+
65+
#### PAUSED
66+
67+
Autopartitioning is paused for this topic, meaning that the number of partitions does not increase automatically. If needed, you can re-enable autopartitioning for this topic.
68+
69+
Examples of YQL queries for switching between different autopartitioning strategies can be found [here](../yql/reference/syntax/alter-topic.md#autopartitioning).
70+
71+
### Autopartitioning constraints {#autopartitioning_constraints}
72+
73+
The following constraints apply when using autopartitioning:
74+
75+
1. Once autopartitioning is enabled for a topic, it cannot be stopped, only paused.
76+
2. When autopartitioning is enabled for a topic, it is impossible to read from or write to it using the [Kafka API](../reference/kafka-api/index.md).
77+
3. Autopartitioning can only be enabled on topics that use the reserved capacity mode.
78+
3479
## Message sources and groups {#producer-id}
3580

3681
Messages are ordered using the `producer_id` and `message_group_id`. The order of written messages is maintained within pairs: `<producer ID, message group ID>`.

ydb/docs/en/core/reference/kafka-api/constraints.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
4. Transactions are not supported.
99
5. DDL operations are not supported. Use the [{{ ydb-short-name }} SDK](../ydb-sdk/index.md) or [{{ ydb-short-name }} CLI](../ydb-cli/index.md) to perform them.
1010
6. Data schema validation not supported.
11-
7. Kafka Connect is only supported in standalone mode.
11+
7. Kafka Connect is supported only in standalone mode.
12+
8. Kafka API can't be used to read from or write to topics with enabled autopartitioning.

ydb/docs/en/core/yql/reference/yql-core/syntax/alter-topic.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,31 @@ ALTER TOPIC `my_topic` RESET (
141141
* `supported_codecs`: List of [codecs](../../../../concepts/topic#message-codec) supported by the topic. Value type: `String`.
142142

143143
{% endif %}
144+
145+
### Change autopartitioning strategies for the topic {#autopartitioning}
146+
147+
The following command sets the [autopartitioning](../../../concepts/topic.md#autopartitioning) strategy to `UP`:
148+
149+
```yql
150+
ALTER TOPIC `my_topic` SET (
151+
min_active_partitions = 1,
152+
max_active_partitions = 5,
153+
auto_partitioning_strategy = 'scale_up'
154+
);
155+
```
156+
157+
The following command pauses the topic [autopartitioning](../../../concepts/topic.md#autopartitioning):
158+
159+
```yql
160+
ALTER TOPIC `my_topic` SET (
161+
auto_partitioning_strategy = 'paused'
162+
);
163+
```
164+
165+
The following command unpauses the topic [autopartitioning](../../../concepts/topic.md#autopartitioning):
166+
167+
```yql
168+
ALTER TOPIC `my_topic` SET (
169+
auto_partitioning_strategy = 'scale_up'
170+
);
171+
```

0 commit comments

Comments
 (0)