title: Kafka generate huge extra data when creating new topics
body: <p>I have a 3-node Zookeeper cluster version 3.4.11 and 2-node Kafka cluster version 0.11.3. We wrote a producer that send messages to the specific topic and partitions of the Kafka cluster (I did it before and the producer is tested). Here are the Brokers configs:</p>
  
  <pre><code>broker.id=1
  listeners=PLAINTEXT://node1:9092
  num.partitions=24
  delete.topic.enable=true
  default.replication.factor=2
  log.dirs=/data
  zookeeper.connect=zoo1:2181,zoo2:2181,zoo3:2181
  log.retention.hours=168
  zookeeper.session.timeout.ms=40000
  zookeeper.connection.timeout.ms=10000
  offsets.topic.replication.factor=2
  transaction.state.log.replication.factor=2
  transaction.state.log.min.isr=2
  </code></pre>
  
  <p>In the beginning, there is no topic on the brokers and they will be created automatically. When I start the producer, Kafka cluster shows a strange behavior: </p>
  
  <p>1- It creates all topics but while the rate of producing data is 10KB per second, in <strong>less than one minutes</strong> the log directory of each broker <strong>goes from zero data to 9.0 Gigabyte data</strong>! and all brokers turned off (because of lack of log-dir capacity)</p>
  
  <p>2- Just when producing data started I try to consume data using the console-consumer and it just errors</p>
  
  <pre><code>WARN Error while fetching metadata with correlation id 2 : {Topic1=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
  </code></pre>
  
  <p>3- Here is the error which repeatedly appears in brokers log:</p>
  
  <pre><code>INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset-1} for Partition: Topic6-6. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache)
  WARN Newly rolled segment file 00000000000000000000.log already exists; deleting it first (kafka.log.Log)
  WARN Newly rolled segment file 00000000000000000000.index already exists; deleting it first (kafka.log.Log)
  WARN Newly rolled segment file 00000000000000000000.timeindex already exists; deleting it first (kafka.log.Log)
  ERROR [Replica Manager on Broker 1]: Error processing append operation on partition Topic6-6 (kafka.server.ReplicaManager)
  kafka.common.KafkaException: Trying to roll a new log segment for topic partition Topic6-6 with start offset 0 while it already exists.
  </code></pre>
  
  <p>After many repeatation of the above log we have:</p>
  
  <pre><code>ERROR [ReplicaManager broker=1] Error processing append operation on partition Topic24-10 (kafka.server.ReplicaManager)
  org.apache.kafka.common.errors.InvalidOffsetException: Attempt to append an offset (402) to position 5 no larger than the last offset appended (402)
  </code></pre>
  
  <p>And at the last (when there is no space in log-dir) it errors:</p>
  
  <pre><code>FATAL [Replica Manager on Broker 1]: Error writing to highwatermark file:  (kafka.server.ReplicaManager)
  java.io.FileNotFoundException: /data/replication-offset-checkpoint.tmp (No space left on device)
  </code></pre>
  
  <p>and shutdown!</p>
  
  <p>4- I set up new single node Kafka version 0.11.3 one another machine and it works well using the same producer and using the same Zookeeper cluster.</p>
  
  <p>5- I turned one of the two Kafka brokers off and just using one broker (of the cluster) it behaves the same as when I used two node Kafka cluster.</p>
  
  <p>What is the problem?</p>
  
  <p><strong>UPDATE1:</strong> I tried Kafka version 2.1.0 but the same result!</p>
  
  <hr>
  
  <p><strong>UPDATE2:</strong> I found out that root of the problem. In producing I create 25 topics each of which has 24 partitions. Surprisingly each topic just after creating (using kafka-topic.sh command and when no data is stored) occupy 481MB space! For example in the log directory of topic "20" for each partition directory I have the following files that totally has 21MB:</p>
  
  <pre><code>00000000000000000000.index (10MB)  00000000000000000000.log(0MB)  00000000000000000000.timeindex(10MB)  leader-epoch-checkpoint(4KB)
  </code></pre>
  
  <p>and Kafka writes the following lines for each topic-partitions in the server.log file:</p>
  
  <pre><code>[2019-02-05 10:10:54,957] INFO [Log partition=topic20-14, dir=/data] Loading producer state till offset 0 with message format version 2 (kafka.log.Log)
  [2019-02-05 10:10:54,957] INFO [Log partition=topic20-14, dir=/data] Completed load of log with 1 segments, log start offset 0 and log end offset 0 in 1 ms (kafka.log.Log)
  [2019-02-05 10:10:54,958] INFO Created log for partition topic20-14 in /data with properties {compression.type -&gt; producer, message.format.version -&gt; 2.1-IV2, file.delete.delay.ms -&gt; 60000, max.message.bytes -&gt; 1000012, min.compaction.lag.ms -&gt; 0, message.timestamp.type -&gt; CreateTime, message.downconversion.enable -&gt; true, min.insync.replicas -&gt; 1, segment.jitter.ms -&gt; 0, preallocate -&gt; false, min.cleanable.dirty.ratio -&gt; 0.5, index.interval.bytes -&gt; 4096, unclean.leader.election.enable -&gt; false, retention.bytes -&gt; -1, delete.retention.ms -&gt; 86400000, cleanup.policy -&gt; [delete], flush.ms -&gt; 9223372036854775807, segment.ms -&gt; 604800000, segment.bytes -&gt; 1073741824, retention.ms -&gt; 604800000, message.timestamp.difference.max.ms -&gt; 9223372036854775807, segment.index.bytes -&gt; 10485760, flush.messages -&gt; 9223372036854775807}. (kafka.log.LogManager)
  [2019-02-05 10:10:54,958] INFO [Partition topic20-14 broker=0] No checkpointed highwatermark is found for partition topic20-14 (kafka.cluster.Partition)
  [2019-02-05 10:10:54,958] INFO Replica loaded for partition topic20-14 with initial high watermark 0 (kafka.cluster.Replica)
  [2019-02-05 10:10:54,958] INFO [Partition topic20-14 broker=0] topic20-14 starts at Leader Epoch 0 from offset 0. Previous Leader Epoch was: -1 (kafka.cluster.Partition)
  </code></pre>
  
  <p>There is no error on the server log. I even can consume data if I produce data on the topic. As the total log directory space is 10GB, Kafka needs 12025MB for 25 topics in my scenario, which is greater than total directory space and Kafka will error and shutdown!</p>
  
  <p>Just for a test I set up another Kafka broker (namely broker2) using the same Zookeeper cluster and creating a new topic with 24 partitions there just occupy 100K for all the empty partitions!</p>
  
  <p>So I'm really confused! The Broker1 and Broker2, the same version of Kafka (0.11.3) is running and just the OS and System File is different:</p>
  
  <p>In case Broker1 (occupy 481MB data for the new topic):</p>
  
  <ul>
  <li>OS CentOS 7 and XFS as System File</li>
  </ul>
  
  <p>In case Broker2 (occupy 100KB data for a new topic):</p>
  
  <ul>
  <li>OS Ubuntu 16.04 and ext4 as System File</li>
  </ul>