Skip to content
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

KAFKA-3959: enforce offsets.topic.replication.factor upon __consumer_offsets auto topic creation (KIP-115) #2177

Closed
wants to merge 1 commit into from

Conversation

onurkaraman
Copy link
Contributor

Kafka brokers have a config called "offsets.topic.replication.factor" that specify the replication factor for the "__consumer_offsets" topic. The problem is that this config isn't being enforced. If an attempt to create the internal topic is made when there are fewer brokers than "offsets.topic.replication.factor", the topic ends up getting created anyway with the current number of live brokers. The current behavior is pretty surprising when you have clients or tooling running as the cluster is getting setup. Even if your cluster ends up being huge, you'll find out much later that __consumer_offsets was setup with no replication.

The cluster not meeting the "offsets.topic.replication.factor" requirement on the internal topic is another way of saying the cluster isn't fully setup yet.

The right behavior should be for "offsets.topic.replication.factor" to be enforced. Topic creation of the internal topic should fail with GROUP_COORDINATOR_NOT_AVAILABLE until the "offsets.topic.replication.factor" requirement is met. This closely resembles the behavior of regular topic creation when the requested replication factor exceeds the current size of the cluster, as the request fails with error INVALID_REPLICATION_FACTOR.

@hachikuji
Copy link

@onurkaraman LGTM for the change itself. I'm guessing this might have some repercussions for system tests though. Maybe we should add the override to tests/kafkatest/services/kafka/templates/kafka.properties as well? Actually since we have broker failure tests for the consumer, we may need to determine a suitable replication factor based on the number of brokers in the test.

@onurkaraman
Copy link
Contributor Author

@hachikuji yeah agreed. I realized after submitting the PR that I hadn't even run the tests. I had only done a manual test. Config values in the integration/system tests may need to change. I can look into it.

@onurkaraman
Copy link
Contributor Author

Force pushed a change that should fix the unit/integration tests. Still need to look into system tests.

@ijuma
Copy link
Contributor

ijuma commented Nov 30, 2016

I think this is a good change. A couple of comments:

  1. We should add a note to upgrade.html
  2. Does this need a KIP since it's a potential breaking change?

@onurkaraman
Copy link
Contributor Author

Added a note to upgrade.html and updated the config documentation in KafkaConfig.

@onurkaraman
Copy link
Contributor Author

onurkaraman commented Nov 30, 2016

Something to consider is that internal topic creation can happen in five paths:

  1. By a broker upon GroupCoordinatorRequest.
  2. By a broker from MetadataRequest querying the internal topic even if "auto.create.topics.enable" is false.
  3. By a user when using AdminUtils.
  4. By a user when running kafka-topics (which calls AdminUtils).
  5. By a broker through AdminManager (which calls AdminUtils) handling CreateTopicsRequest.

Consequences of this PR:

  1. is covered correctly by this PR.
  2. now accidentally may have the MetadataResponse return GROUP_COORDINATOR_NOT_AVAILABLE for when a MetadataRequest queries the internal topic. Internal topic creation from MetadataRequest in the past used to always succeed since the replication factor was adjusted.
  3. AdminUtils.createTopic behavior remains unchanged (though the current behavior is arguably wrong). AdminUtils does a similar cluster size vs. replication factor comparison but throws an InvalidReplicationFactorException if the manually specified replication factor isn't met. If the replication factor is met, it creates the topic, ignoring the broker's offsets.topic.replication.factor config.
  4. Same as 3.
  5. Same as 3. CreateTopicsResponse including an internal topic will return INVALID_REPLICATION_FACTOR if the manually specified replication factor isn't met.

So scenario 1 has been fixed, 2 has an unexpected change, and 3-5 remain unchanged but potentially do the wrong thing.

@onurkaraman
Copy link
Contributor Author

onurkaraman commented Dec 1, 2016

6th way: By a user directly writing to the topic znode in zookeeper.
Consequences of this PR: Unrelated, as the zk write will not receive any error from kafka.

@onurkaraman
Copy link
Contributor Author

That being said, I don't think we need to worry about users manually creating the __consumer_offsets topic for now, so really we just need to worry about path 1 and maybe 2.

@ewencp
Copy link
Contributor

ewencp commented Jan 2, 2017

Only worrying about 1 & 2 for internal topics seems reasonable to me.

@asfbot
Copy link

asfbot commented Jan 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/423/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Jan 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/424/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Jan 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/422/
Test FAILed (JDK 7 and Scala 2.10).

@hachikuji
Copy link

Yeah, focusing on 1 & 2 makes sense. @ijuma Feels a bit weird to require a KIP to enforce an existing configuration correctly 😉 . That said, I'm not too sure about the impact, so might be safer to do a KIP anyway. Seems this only affects new clusters, so I imagine the main impact would be broken tests. Perhaps some broken deployment recipes also?

@ijuma
Copy link
Contributor

ijuma commented Jan 25, 2017

@hachikuji, sorry for the delay. I agree that this should have been the correct behaviour for the configuration. However, the previous behaviour was specified and it was not an accident either (Jun and Neha discussed it in the original JIRA). Given that and the potential impact on new deployments, a KIP seems inevitable. It should be a simple one and it will hopefully pass as easily as the unclean leader election one. :)

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1189/
Test FAILed (JDK 7 and Scala 2.10).

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1189/
Test PASSed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1191/
Test PASSed (JDK 8 and Scala 2.11).

@onurkaraman
Copy link
Contributor Author

onurkaraman commented Jan 25, 2017

For 1, I think we all agree that it should be solved with GROUP_COORDINATOR_NOT_AVAILABLE.

For 2, I think we want to preserve existing MetadataRequest topic creation behavior by returning INVALID_REPLICATION_FACTOR, but I don't know if we actually agreed on that. If this is what we want, then I need to revise the code.

@onurkaraman
Copy link
Contributor Author

I updated the PR assuming the behavior mentioned in my previous comment.

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1196/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1194/
Test PASSed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1194/
Test PASSed (JDK 7 and Scala 2.10).

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1198/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1196/
Test PASSed (JDK 8 and Scala 2.12).

@onurkaraman
Copy link
Contributor Author

@hachikuji @ijuma @ewencp so what is the plan? Can we just check it into 0.10.2.0?

I need to know the release in order to tweak the upgrade.html correctly.

@asfbot
Copy link

asfbot commented Jan 25, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1196/
Test FAILed (JDK 7 and Scala 2.10).

@onurkaraman
Copy link
Contributor Author

Updated the upgrade.html so the comment is under the 0.10.2.0 notable changes.

@asfbot
Copy link

asfbot commented Jan 26, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1211/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Jan 26, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1212/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Jan 26, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1211/
Test PASSed (JDK 7 and Scala 2.10).

…offsets auto topic creation (KIP-115)

Kafka brokers have a config called "offsets.topic.replication.factor" that specify the replication factor for the __consumer_offsets topic. The problem is that this config isn't being enforced upon auto topic creation. If an attempt to auto create the internal topic is made when there are fewer brokers than "offsets.topic.replication.factor", the topic ends up getting created anyway with the current number of live brokers. The current behavior is pretty surprising when you have clients or tooling running as the cluster is getting setup. Even if your cluster ends up being huge, you'll find out much later that __consumer_offsets was setup with no replication.

The cluster not meeting the "offsets.topic.replication.factor" requirement on the internal topic is another way of saying the cluster isn't fully setup yet. The right behavior should be for "offsets.topic.replication.factor" to be enforced.

Internal topic creation can happen in five paths:
1. By a broker upon GroupCoordinatorRequest.
2. By a broker from MetadataRequest querying the internal topic even if "auto.create.topics.enable" is false.
3. By a user when using AdminUtils.
4. By a user when running kafka-topics (which calls AdminUtils).
5. By a broker through AdminManager (which calls AdminUtils) handling CreateTopicsRequest.
6. By a user directly writing to the topic znode in zookeeper.

Consequences of this patch:
1. will now fail topic creation of the internal topic with GROUP_COORDINATOR_NOT_AVAILABLE until the "offsets.topic.replication.factor" requirement is met.
2. will now fail topic creation of the internal topic and retain existing behavior of failing topic creation with INVALID_REPLICATION_FACTOR until the "offsets.topic.replication.factor" requirement is met.
3. will retain existing behavior. AdminUtils compares cluster size vs. replication factor comparison and throws an InvalidReplicationFactorException if the manually specified replication factor isn't met. If the replication factor is met, it creates the topic, ignoring the broker's offsets.topic.replication.factor config.
4. Same as 3.
5. Same as 3. CreateTopicsResponse including an internal topic will return INVALID_REPLICATION_FACTOR if the manually specified replication factor isn't met.
6. is unrelated, as the zk write will not receive any error from kafka.
@asfbot
Copy link

asfbot commented Jan 30, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1341/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Jan 30, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1337/
Test PASSed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Jan 30, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1337/
Test FAILed (JDK 7 and Scala 2.10).

@onurkaraman onurkaraman changed the title KAFKA-3959: enforce offsets.topic.replication.factor KAFKA-3959: enforce offsets.topic.replication.factor upon __consumer_offsets auto topic creation (KIP-115) Jan 30, 2017
@ewencp
Copy link
Contributor

ewencp commented Feb 1, 2017

Was about to check this in, but I didn't see any notes about validating the system tests still work. Kicked off https://jenkins.confluent.io/job/system-test-kafka-branch-builder-2/187/ to make sure they are still in good shape with just the minor template tweak.

@onurkaraman
Copy link
Contributor Author

@ewencp looks like https://jenkins.confluent.io/job/system-test-kafka-branch-builder-2/187/ failed.

I kicked off a new build with the same params as build 187 and it passed: https://jenkins.confluent.io/job/system-test-kafka-branch-builder-2/188/

@ewencp
Copy link
Contributor

ewencp commented Feb 2, 2017

Thanks @onurkaraman. LGTM, committing to trunk for inclusion in 0.10.3.0.

@asfgit asfgit closed this in 063d534 Feb 2, 2017
@onurkaraman
Copy link
Contributor Author

onurkaraman commented Feb 2, 2017

@ewencp Thanks for the check-in. I just noticed that the checked in code has the upgrade notes under "Notable changes in 0.10.2.0" while I think we agreed to put it in 0.10.3.0.

@ewencp
Copy link
Contributor

ewencp commented Feb 2, 2017

@onurkaraman Good catch, somehow missed this despite re-reviewing the changes. Filed #2484 and reopened the JIRA to adjust the docs.

soenkeliebau pushed a commit to soenkeliebau/kafka that referenced this pull request Feb 7, 2017
…offsets auto topic creation (KIP-115)

Kafka brokers have a config called "offsets.topic.replication.factor" that specify the replication factor for the "__consumer_offsets" topic. The problem is that this config isn't being enforced. If an attempt to create the internal topic is made when there are fewer brokers than "offsets.topic.replication.factor", the topic ends up getting created anyway with the current number of live brokers. The current behavior is pretty surprising when you have clients or tooling running as the cluster is getting setup. Even if your cluster ends up being huge, you'll find out much later that __consumer_offsets was setup with no replication.

The cluster not meeting the "offsets.topic.replication.factor" requirement on the internal topic is another way of saying the cluster isn't fully setup yet.

The right behavior should be for "offsets.topic.replication.factor" to be enforced. Topic creation of the internal topic should fail with GROUP_COORDINATOR_NOT_AVAILABLE until the "offsets.topic.replication.factor" requirement is met. This closely resembles the behavior of regular topic creation when the requested replication factor exceeds the current size of the cluster, as the request fails with error INVALID_REPLICATION_FACTOR.

Author: Onur Karaman <okaraman@linkedin.com>

Reviewers: Jason Gustafson <jason@confluent.io>, Ismael Juma <ismael@juma.me.uk>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes apache#2177 from onurkaraman/KAFKA-3959
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants