Merge KAFKA-1382

Merging
https://issues.apache.org/jira/secure/attachment/12646741/KAFKA-1382.patch