-
Notifications
You must be signed in to change notification settings - Fork 11
docs(inkless): document the interceptors introduced for CREATE_TOPIC #680
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # CREATE_TOPICS Config Interceptors | ||
|
|
||
| This document describes the interceptor framework that the controller applies to `CREATE_TOPICS` requests. Interceptors give the controller a generic hook to **mutate the topic configs** of a topic being created (for example, force `diskless.enable=true` or `remote.storage.enable=true`) and to run **additional validations** (for example, reject a request that explicitly opts out of a forced config). | ||
|
|
||
| ## Motivation | ||
|
|
||
| Operators often want cluster-wide policies over how topics are stored — "all matching topics must be diskless", "all classic topics must be tiered" — without requiring every client to set the right configs. Rather than scattering that logic through `ReplicationControlManager`, the interceptor framework lets each policy live in its own small, testable class, and chains them with clear priority ordering. | ||
|
|
||
| ## Concepts | ||
|
|
||
| ### The interceptor interface | ||
|
|
||
| `CreateTopicConfigInterceptor` has multiple `intercept` methods and they can all be invoked during a single topic creation (see [Where it runs](#where-it-runs)), so an interceptor must be careful to apply the same decision through all variants to keep the persisted records and the response view consistent. | ||
|
|
||
| The two responsibilities of an interceptor are: | ||
|
|
||
| - **Mutation** — add or change entries in the target map (e.g. set `diskless.enable=true`). | ||
| - **Validation** — throw an `ApiException` (such as `InvalidRequestException`) to reject the request. | ||
|
|
||
| ### The chain: first-match-wins | ||
|
|
||
| `CreateTopicConfigInterceptors` holds an ordered list of interceptors and applies them with **first-match-wins** semantics: it walks the chain and stops at the first interceptor whose `intercept` returns `true`. Subsequent interceptors are skipped. This lets multiple policies coexist as long as their matching rules don't overlap; when they might, the chain order decides the winner. | ||
|
|
||
| The chain is built once in `ReplicationControlManager`'s constructor via `CreateTopicConfigInterceptors.create(...)`, from controller configs. | ||
|
|
||
| ## Where it runs | ||
|
|
||
| Interceptors run inside `ReplicationControlManager.createTopics`, per topic, in two places: | ||
|
|
||
| - When computing the config records to persist, the **records variant** is applied to the `keyToOps` map. Any `ApiException` thrown here is recorded as that topic's error and the topic is skipped. | ||
| - Inside `createTopic`, the **view variant** is re-applied to a fresh `creationConfigs` map. This ensures forced configs participate in topic-policy validation and are reflected in the effective-config view returned to the client. | ||
|
|
||
| ## Built-in interceptors | ||
|
|
||
| - [DisklessForceCreateTopicInterceptor](../../metadata/src/main/java/org/apache/kafka/controller/DisklessForceCreateTopicInterceptor.java) - Forces `diskless.enable=true` for some topics based on `diskless.force.include.topic.regexes`. | ||
| - [ClassicTopicRemoteStorageForceCreateTopicInterceptor](../../metadata/src/main/java/org/apache/kafka/controller/ClassicTopicRemoteStorageForceCreateTopicInterceptor.java) - Forces `remote.storage.enable=true` on classic topics. | ||
| - [DisklessDisabledFallbackCreateTopicInterceptor](../../metadata/src/main/java/org/apache/kafka/controller/DisklessDisabledFallbackCreateTopicInterceptor.java) - Allow `diskless.enable=false` to be passed even when diskless storage is disabled. | ||
|
|
||
| ## Adding a new interceptor | ||
|
|
||
| 1. Implement `CreateTopicConfigInterceptor`, providing all `intercept` overloads. | ||
| 2. Add any new controller configs to `ServerConfigs` and surface them through `KafkaConfig`. | ||
| 3. Insert the interceptor into `CreateTopicConfigInterceptors.create(...)` at the appropriate position in the chain (remember first-match-wins). | ||
| 4. Throw an `ApiException` from `intercept` for validation failures; the controller converts it into a per-topic error. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.