Class LogTruncationException

All Implemented Interfaces:
Serializable

@Public public class LogTruncationException extends OffsetOutOfRangeException
In the event of an unclean leader election, the log will be truncated, previously committed data will be lost, and new data will be written over these offsets. When this happens, the consumer will detect the truncation and raise this exception (if no automatic reset policy has been defined) with the first offset known to diverge from what the consumer previously read.
See Also:
  • Constructor Details

    • LogTruncationException

      public LogTruncationException(Map<TopicPartition, Long> fetchOffsets, Map<TopicPartition, OffsetAndMetadata> divergentOffsets)
      Constructs a new LogTruncationException with the fetch offsets and divergent offsets.
      Parameters:
      fetchOffsets - The fetch offsets that were out of range
      divergentOffsets - The offsets where the consumer's log diverged from the broker's log
    • LogTruncationException

      public LogTruncationException(String message, Map<TopicPartition, Long> fetchOffsets, Map<TopicPartition, OffsetAndMetadata> divergentOffsets)
      Constructs a new LogTruncationException with a custom message.
      Parameters:
      message - The detail message
      fetchOffsets - The fetch offsets that were out of range
      divergentOffsets - The offsets where the consumer's log diverged from the broker's log
  • Method Details

    • divergentOffsets

      public Map<TopicPartition, OffsetAndMetadata> divergentOffsets()
      Get the divergent offsets for the partitions which were truncated. For each partition, this is the first offset which is known to diverge from what the consumer read. Note that there is no guarantee that this offset will be known. It is necessary to use OffsetOutOfRangeException.partitions() to see the set of partitions that were truncated and then check for the presence of a divergent offset in this map.