代码之家  ›  专栏  ›  技术社区  ›  Soheil Pourbafrani

卡夫卡在生成消息时生成大量额外数据

  •  0
  • Soheil Pourbafrani  · 技术社区  · 7 年前

    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
    

    开始时,没有关于代理的主题,它们将自动创建。当我启动producer时,Kafka集群出现了一个奇怪的行为:

    1-它创建所有主题,但当生成数据的速率为每秒10KB时 不到一分钟 每个代理的日志目录 从零数据到9.0 GB数据 ! 所有代理都关闭了(因为缺少log dir容量)

    2-刚开始生成数据时,我尝试使用控制台使用者使用数据,而这只是错误

    WARN Error while fetching metadata with correlation id 2 : {Topic1=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
    

    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.
    

    在多次重复上述日志之后,我们得到:

    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)
    

    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)
    

    然后关机!

    使用同一个新版本的kafki.4和另一个新版本的kafki.4建立了一个新的版本。

    更新1:


    更新2:

    00000000000000000000.index (10MB)  00000000000000000000.log(0MB)  00000000000000000000.timeindex(10MB)  leader-epoch-checkpoint(4KB)
    

    Kafka为服务器日志文件:

    [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 -> producer, message.format.version -> 2.1-IV2, file.delete.delay.ms -> 60000, max.message.bytes -> 1000012, min.compaction.lag.ms -> 0, message.timestamp.type -> CreateTime, message.downconversion.enable -> true, min.insync.replicas -> 1, segment.jitter.ms -> 0, preallocate -> false, min.cleanable.dirty.ratio -> 0.5, index.interval.bytes -> 4096, unclean.leader.election.enable -> false, retention.bytes -> -1, delete.retention.ms -> 86400000, cleanup.policy -> [delete], flush.ms -> 9223372036854775807, segment.ms -> 604800000, segment.bytes -> 1073741824, retention.ms -> 604800000, message.timestamp.difference.max.ms -> 9223372036854775807, segment.index.bytes -> 10485760, flush.messages -> 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)
    

    服务器日志中没有错误。我甚至可以消费数据,如果我产生数据的主题。由于日志目录的总空间是10GB,在我的场景中,25个主题需要12025MB,大于总目录空间,Kafka会出错并关闭!

    为了测试,我使用同一个Zookeeper集群设置了另一个Kafka代理(即broker2),并创建了一个新的主题,其中24个分区只占用了100K的所有空分区!

    • OS CentOS 7和XFS作为系统文件

    如果Broker2(新主题占用100KB数据):

    0 回复  |  直到 7 年前
        1
  •  3
  •   Soheil Pourbafrani    7 年前
    • 为什么Kafka为每个分区预分配21MB?

    segment.index.bytes 默认值为10485760字节或10MB。这是因为每个分区目录中的索引分配了10MB:

    00000000000000000000.index (10MB)  
    00000000000000000000.log(0MB)  
    00000000000000000000.timeindex(10MB)  
    leader-epoch-checkpoint(4KB)
    

    We preallocate this index file and shrink it only after log rolls.
    

    推荐文章