KAFKA-5291: AdminClient should not trigger auto creation of topics#3098
KAFKA-5291: AdminClient should not trigger auto creation of topics#3098ijuma wants to merge 5 commits intoapache:trunkfrom
Conversation
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
e960814 to
8194071
Compare
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
f29e855 to
a50f24e
Compare
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Review by @junrao. |
|
@ijuma Took a quick glance and it seems reasonable. I guess if you connect to a pre-0.11 broker, then we'll downgrade to the old behavior with auto-creation allowed? |
|
@hachikuji, yes, that's right. I mentioned that in the KIP thread, but forgot to update the description. Did it now. |
There was a problem hiding this comment.
Is there a race condition here where we might not get Errors.LEADER_NOT_AVAILABLE, if the brokers are quicker than usual?
There was a problem hiding this comment.
I don't think so. The call that initiates auto creation always returns LEADER_NOT_AVAILABLE.
|
@ijuma: great idea for an improvement. As I mentioned on the mailing list thread, I think it would be more reasonable to use MetadataRequest(topics=ALL) when doing a protocol downgrade. This would avoid having such surprisingly different behavior when talking to 0.10.x. It does mean that the scalability of old versions is lower, but that's why we have upgrades, right? |
a50f24e to
d358ddc
Compare
There was a problem hiding this comment.
This was just a hack to demonstrate the issue, but without this change the fallback times out.
There was a problem hiding this comment.
Removed this hack as it seems to be fixed by the @cmccabe's timeout fixes PR that I just merged.
d358ddc to
f3427b9
Compare
|
@cmccabe, can you please take a look? |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
There was a problem hiding this comment.
Shouldn't this default to true here? I think all the places that use allTopics() are expecting this to be true (except the new use in adminclient)
There was a problem hiding this comment.
The behaviour of ALL_TOPICS is that auto creation never happens. So, I had set it to false to make that obvious. All the code handles this properly. The one downside is that if you serialize a version that doesn't have this field and then deserialize, the deserialized version will have the boolean as true. This may be confusing, so I will change it to true like you suggested.
f3427b9 to
bf65707
Compare
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
bf65707 to
f1df03b
Compare
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
- Added a boolean allow_auto_topic_creation to MetadataRequest. I didn’t bump the version a second time since we did it once for this release already, but this needs to be verified. - Set it to false in the new AdminClient and StreamsKafkaClient (which exists for the purpose of creating topics manually); set it to true everywhere else for now. Other clients will eventually rely on client-side auto topic creation, but that’s not there yet.
04560e7 to
be6cb0d
Compare
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
d1d5ef9 to
ef816cc
Compare
| val response1 = sendMetadataRequest(new MetadataRequest(Seq(topic1, topic2).asJava, true, ApiKeys.METADATA.latestVersion)) | ||
| checkAutoCreatedTopic(topic1, topic2, response1) | ||
|
|
||
| // V2 doesn't support a configurable allowAutoTopicCreation, so the fact that we set it to `false` has no effect |
| val response2 = sendMetadataRequest(new MetadataRequest(Seq(topic2, topic3).asJava, false, 2)) | ||
| checkAutoCreatedTopic(topic2, topic3, response2) | ||
|
|
||
| // V3 and higher support a configurable allowAutoTopicCreation |
There was a problem hiding this comment.
Yes, the test fails (as expected) without that change.
|
@junrao, updated the PR. I'll merge it after the tests pass if you're OK with that. |
|
Refer to this link for build results (access rights to CI server needed): |
|
|
||
| @Override | ||
| boolean handleUnsupportedVersionException(UnsupportedVersionException exception) { | ||
| if (supportsDisablingTopicCreation) { |
There was a problem hiding this comment.
This works for now since we only support disabling auto topic creation in the latest version. However, if we bump up the version of metadata request again in the future, this check may be too restrictive. If this requires more changes, perhaps we can at least add a comment for now.
There was a problem hiding this comment.
I think that would still work in that case. We only ever need to fall back once: if the highest version of metadata request supported by the broker is v3 or lower. The first attempt will fail and the subsequent one will work.
To make it more concrete, say we introduce metadata request v5. If the broker supports v4 or v5, then it will just work. If the broker only supports v3, it's the same as now: we fail on the first attempt and then we fallback to not using the flag. Does that make sense?
There was a problem hiding this comment.
Thanks for the explanation. That works then.
|
@ijuma : Yes, LGTM. Just left another minor comment. You can merge the PR once it's addressed. |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
- Added a boolean `allow_auto_topic_creation` to MetadataRequest and bumped the protocol version to V4. - When connecting to brokers older than 0.11.0.0, the `allow_auto_topic_creation` field won't be considered, so we send a metadata request for all topics to keep the behavior consistent. - Set `allow_auto_topic_creation` to false in the new AdminClient and StreamsKafkaClient (which exists for the purpose of creating topics manually); set it to true everywhere else for now. Other clients will eventually rely on client-side auto topic creation, but that’s not there yet. - Add `allowAutoTopicCreation` field to `Metadata`, which is used by `DefaultMetadataUpdater`. This is not strictly needed for the new `AdminClient`, but it avoids surprises if it ever adds a topic to `Metadata` via `setTopics` or `addTopic`. Author: Ismael Juma <ismael@juma.me.uk> Reviewers: Jun Rao <junrao@gmail.com> Closes #3098 from ijuma/kafka-5291-admin-client-no-auto-topic-creation (cherry picked from commit 7311dcb) Signed-off-by: Ismael Juma <ismael@juma.me.uk>
Added a boolean
allow_auto_topic_creationto MetadataRequest andbumped the protocol version to V4.
When connecting to brokers older than 0.11.0.0, the
allow_auto_topic_creationfield won't be considered, so we send a metadata request for all topics
to keep the behavior consistent.
Set
allow_auto_topic_creationto false in the new AdminClient andStreamsKafkaClient (which exists for the purpose of creating topics
manually); set it to true everywhere else for now. Other clients will eventually
rely on client-side auto topic creation, but that’s not there yet.
Add
allowAutoTopicCreationfield toMetadata, which is used byDefaultMetadataUpdater. This is not strictly needed for the newAdminClient, but it avoids surprises if it ever adds a topic toMetadatavia
setTopicsoraddTopic.