-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
KeyError Creating SimpleProducer #113
Comments
Not sure why, but when it's a new topic kafka doesn't return the partition info to the first metadata request. As a workaround, you can do what |
Latest master (after merging #111 pull request) changes behavior so the Producer init no longer takes a topic. But this error could still show up on first message send to a new topic. Can you test? |
My testing suggests that when topic auto-creation is enabled on the kafka server (auto.create.topics.enable=True), it will create the topic but return a LeaderNotAvailable error while it does the initial setup asynchronously. this means that the message produce has to wait until the topic is fully setup w/ a broker leader. kafka-python should probably check for this error and optionally retry (w/ resyncing leader metadata?) |
Any updates on this? |
As of 8811298 this still breaks with KeyError:
|
merged #109 -- please retry w/ master trunk |
Still seeing this issue on master. Any updates? |
I can confirm the issue happening, and I've looked into it enough to know why. Right now I am working on beefing up the test suite. On a scale of 1-10, how much of a blocker is this for you? -Mark
|
I'm working around it for the moment by creating the topics manually. Lets go with 4 - Annoying.
|
I'm getting exactly this error constantly, not just on the first try. Not sure why yet. Traceback (most recent call last): |
Do you have a topic without ISR or without a leader? Can you print -Mark On Tue, May 20, 2014 at 4:22 AM, Korijn van Golen
|
I feel silly. It was a configuration issue. The kafka-server-start.sh and zookeeper-server-start.sh scripts that come with the packaged install from the ubuntu repo's were not exactly suitable for use with supervisord. After correcting setup all problems were solved. I can post the scripts if you're interested. |
Nonetheless, there's an assumption in the code that we'll always get topic metadata back from the server. We need to handle this more gracefully. https://github.com/mumrah/kafka-python/blob/master/kafka/producer.py#L219 |
Here's an idea: make it possible to work with kafka-python without metadata through a configuration option (or something similar). In the case of missing metadata, raise an exception that indicates that metadata can't be retrieved, and mention in the exception message that you can configure kafka-python not to use metadata. That would have pointed me in the proper direction immediately (figuring out why metadata can't be retrieved), instead of aimlessly searching for a workaround to some issue with kafka-python. Just a though :) Thanks for the help guys. |
Metadata is necessary to know which broker the producer must connect to for a particular topic-partition. kafka-python doesn't currently expose a super low level producer that requires users to manage leadership discovery / topic metadata. But even if it did, you'd still be forced to deal with metadata. It's a pretty core part of the kafka design. Nonetheless, this is clearly a bug in how kafka-python handles partition cycles when a topic does not exist (or at least the broker has no metadata available). |
I guess you're right about that. |
This is an issue I've been experiencing running Master branch. Basically, the first time I access an uncreated topic, I get a KeyError, whereas the second time, I can access it just fine.
import kafka
client = kafka.client.KafkaClient(address, port)
producer = kafka.producer.SimpleProducer(client, "test") # Fails first time called, succeeds thereafter
Traceback (most recent call last):
File "/home/vagrant/.pycharm_helpers/pydev/pydevd.py", line 1532, in
debugger.run(setup['file'], None, None)
File "/home/vagrant/.pycharm_helpers/pydev/pydevd.py", line 1143, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/projects/scratch/init.py", line 27, in
main()
File "/home/vagrant/.virtualenvs/app/local/lib/python2.7/site-packages/kafka/producer.py", line 191, in init
self.next_partition = cycle(client.topic_partitions[topic])
KeyError: 'test'
The text was updated successfully, but these errors were encountered: