Clean kafka topic

set retention.ms to a small value, then wait a minute
kafka-configs --zookeeper localhost:2181 --entity-type topics --alter --add-config retention.ms=1000 --entity-name MyTopic

check if the value set successfully:
kafka-configs --zookeeper localhost:2181 --entity-type topics --describe --entity-name MyTopic

check if log files has been deleted:
ls /tmp/kafka-logs/MyTopic-0/

restore the default retention.ms value:
kafka-configs --zookeeper localhost:2181 --entity-type topics --alter --delete-config retention.ms --entity-name MyTopic