Skip to content

Commit 4213953

Browse files
docs(admin-api-topics): document topic truncate operation (#1121)
Add a "Truncate topic" section in admin-api-topics.md with the standard pulsar-admin / REST API / Java tab layout, matching the style of the surrounding Unload/Delete sections. The feature itself has been available for years via `pulsar-admin topics truncate` (CmdTopics.TruncateCmd), the Topics#truncate(String) Java admin API, and `DELETE /{tenant}/{namespace}/{topic}/truncate` on the broker (PersistentTopics#truncateTopic). It just wasn't documented on pulsar.apache.org/docs/*/admin-api-topics/. Fixes apache/pulsar#24086
1 parent fdf9023 commit 4213953

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

docs/admin-api-topics.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,38 @@ admin.topics().unload(topic);
257257
</Tabs>
258258
````
259259

260+
### Truncate topic
261+
262+
You can truncate a topic in the following ways. The truncate operation moves all cursors to the end of the topic and deletes all inactive ledgers, freeing the storage used by messages that have already been consumed.
263+
264+
````mdx-code-block
265+
<Tabs groupId="api-choice"
266+
defaultValue="pulsar-admin"
267+
values={[{"label":"pulsar-admin","value":"pulsar-admin"},{"label":"REST API","value":"REST API"},{"label":"Java","value":"Java"}]}>
268+
<TabItem value="pulsar-admin">
269+
270+
```shell
271+
pulsar-admin topics truncate persistent://test-tenant/ns1/tp1
272+
```
273+
274+
</TabItem>
275+
<TabItem value="REST API">
276+
277+
[](swagger:/admin/v2/PersistentTopics_truncateTopic)
278+
279+
</TabItem>
280+
<TabItem value="Java">
281+
282+
```java
283+
String topic = "persistent://my-tenant/my-namespace/my-topic";
284+
admin.topics().truncate(topic);
285+
```
286+
287+
</TabItem>
288+
289+
</Tabs>
290+
````
291+
260292
### Get stats
261293

262294
For the detailed statistics of a topic, see [Pulsar statistics](administration-stats.md#topic-stats).

0 commit comments

Comments
 (0)