title: Kafka Log Compaction always shows two last records of same key
body: <p>Found these two questions : <a href="https://stackoverflow.com/questions/54550457/kafka-log-compaction-returns-two-records-with-the-same-key">here</a> and <a href="https://stackoverflow.com/questions/57751695/kafka-log-compaction-behavior">here</a>, but I still don't quite understand.
  I still got (unexpected?) behaviour.</p>
  
  <p>I try to log-compact kafka topic using this configuration</p>
  
  <p><code>kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --replication-factor 1 --topic test1 --config "cleanup.policy=compact" --config "delete.retention.ms=1000"  --config "segment.ms=1000" --config "min.cleanable.dirty.ratio=0.01" --config "min.compaction.lag.ms=500"</code></p>
  
  <p>Then I send these messages, each has at least 1 second interval</p>
  
  <pre><code>A: 3
  A: 4
  A: 5
  B: 10
  B: 20
  B: 30
  B: 40
  A: 6
  </code></pre>
  
  <p>What I expect is after few seconds (1000 as configured?), when I run <code>kafka-console-consumer.sh --bootstrap-server localhost:9092 --property print.key=true --topic test1 --from-beginning</code>, I should get</p>
  
  <pre><code>A: 6
  B: 40
  </code></pre>
  
  <p>Instead, I got :</p>
  
  <pre><code>A: 5
  B: 40
  A: 6
  </code></pre>
  
  <p>If I publish another message <code>B:50</code> and runs the consumer, I got :</p>
  
  <pre><code>B: 40
  A: 6
  B: 50
  </code></pre>
  
  <p>instead of expected </p>
  
  <pre><code>A: 6
  B: 50
  </code></pre>
  
  <ol>
  <li>Actually, how to configure log compaction?</li>
  <li>From <a href="https://kafka.apache.org/documentation.html#compaction" rel="nofollow noreferrer">Kafka documentation</a> : <em>Log compaction ensures that Kafka will always retain at least the last known value for each message key within the log of data for a single topic partition</em><br>
  Is this means I can only use log compaction on topic with single partition?</li>
  </ol>