gpt4 book ai didi

hadoop - Confluent HDFS 连接器正在丢失消息

转载 作者:可可西里 更新时间:2023-11-01 15:27:52 27 4
gpt4 key购买 nike

社区,您能帮我理解为什么 ~3% 的消息没有在 HDFS 中结束吗?我用 JAVA 编写了一个简单的生成器来生成 1000 万条消息。

public static final String TEST_SCHEMA = "{"
+ "\"type\":\"record\","
+ "\"name\":\"myrecord\","
+ "\"fields\":["
+ " { \"name\":\"str1\", \"type\":\"string\" },"
+ " { \"name\":\"str2\", \"type\":\"string\" },"
+ " { \"name\":\"int1\", \"type\":\"int\" }"
+ "]}";

public KafkaProducerWrapper(String topic) throws UnknownHostException {
// store topic name
this.topic = topic;

// initialize kafka producer
Properties config = new Properties();
config.put("client.id", InetAddress.getLocalHost().getHostName());
config.put("bootstrap.servers", "myserver-1:9092");
config.put("key.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
config.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
config.put("schema.registry.url", "http://myserver-1:8089");
config.put("acks", "all");

producer = new KafkaProducer(config);

// parse schema
Schema.Parser parser = new Schema.Parser();
schema = parser.parse(TEST_SCHEMA);
}

public void send() {
// generate key
int key = (int) (Math.random() * 20);

// generate record
GenericData.Record r = new GenericData.Record(schema);
r.put("str1", "text" + key);
r.put("str2", "text2" + key);
r.put("int1", key);

final ProducerRecord<String, GenericRecord> record = new ProducerRecord<>(topic, "K" + key, (GenericRecord) r);
producer.send(record, new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) {
if (e != null) {
logger.error("Send failed for record {}", record, e);
messageErrorCounter++;
return;
}
logger.debug("Send succeeded for record {}", record);
messageCounter++;
}
});
}

public String getStats() { return "Messages sent: " + messageCounter + "/" + messageErrorCounter; }

public long getMessageCounter() {
return messageCounter + messageErrorCounter;
}

public void close() {
producer.close();
}

public static void main(String[] args) throws InterruptedException, UnknownHostException {
// initialize kafka producer
KafkaProducerWrapper kafkaProducerWrapper = new KafkaProducerWrapper("my-test-topic");

long max = 10000000L;
for (long i = 0; i < max; i++) {
kafkaProducerWrapper.send();
}

logger.info("producer-demo sent all messages");
while (kafkaProducerWrapper.getMessageCounter() < max)
{
logger.info(kafkaProducerWrapper.getStats());
Thread.sleep(2000);
}

logger.info(kafkaProducerWrapper.getStats());
kafkaProducerWrapper.close();
}

我在独立模式下使用Confluent HDFS Connector将数据写入HDFS。配置如下:

name=hdfs-consumer-test
connector.class=io.confluent.connect.hdfs.HdfsSinkConnector
tasks.max=1

topics=my-test-topic

hdfs.url=hdfs://my-cluster/kafka-test
hadoop.conf.dir=/etc/hadoop/conf/
flush.size=100000
rotate.interval.ms=20000

# increase timeouts to avoid CommitFailedException
consumer.session.timeout.ms=300000
consumer.request.timeout.ms=310000

heartbeat.interval.ms= 60000
session.timeout.ms= 100000

连接器将数据写入 HDFS,但在等待 20000 毫秒后(由于 rotate.interval.ms)并未收到所有消息。

scala> spark.read.avro("/kafka-test/topics/my-test-topic/partition=*/my-test-topic*")
.count()
res0: Long = 9749015

知道这种行为的原因是什么吗?我的错误在哪里?我正在使用 Confluent 3.0.1/Kafka 10.0.0.1

最佳答案

您是否看到最后几条消息没有移动到 HDFS?如果是这样,您可能遇到了此处描述的问题 https://github.com/confluentinc/kafka-connect-hdfs/pull/100

尝试在 rotate.interval.ms 过期后向主题发送一条消息,以验证这是否是您遇到的问题。如果您需要根据时间轮换,升级以获取修复可能是个好主意。

关于hadoop - Confluent HDFS 连接器正在丢失消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40879750/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com