gpt4 book ai didi

apache-spark - 查询开始时使用结构化流从 Kafka 主题的开头读取

转载 作者:行者123 更新时间:2023-12-05 02:06:14 25 4
gpt4 key购买 nike

<分区>

我使用结构化流从 kafka 主题读取,使用 spark 2.4scala 2.12

我正在使用检查点来使我的查询容错。

然而,每次我开始查询时,它都会跳转到当前偏移量,而不会在连接到主题之前读取现有数据。

我是否缺少 kafka 流的配置?

阅读:

 val df = spark.readStream
.format("kafka")
.option("kafka.bootstrap.servers", "localhost:9092")
.option("subscribe", "test")
.option("maxOffsetsPerTrigger","1")
.option("startingOffset","earliest")
.option("auto.offset.reset","earliest")
.load()
val msg = df.select($"value" cast "string", $"topic", $"partition", $"offset")

写:

val query= msg.writeStream
.foreachBatch(
(dfbatch: Dataset[Row], batchid: Long) =>
{
println(s"IM AT BATCH ID: $batchid")
dfbatch.show()
dfbatch.write.csv(s"s3a://abucket/$param")
}
)
.option("checkpointLocation","s3a://checkpoint/")
.trigger(Trigger.ProcessingTime("10 seconds"))
.format("console")
.start()

query.awaitTermination()

编辑:

这是我清空检查点目录后的日志:

0/07/11 18:15:16 INFO CheckpointFileManager: Writing atomically to s3a://checkpoint/metadata using temp file s3a://checkpoint/.metadata.304a751a-68b7-4b8d-858c-3aa5df272db4.tmp
20/07/11 18:15:17 INFO CheckpointFileManager: Renamed temp file s3a://checkpoint/.metadata.304a751a-68b7-4b8d-858c-3aa5df272db4.tmp to s3a://checkpoint/metadata
20/07/11 18:15:17 INFO MicroBatchExecution: Starting [id = e83c6066-9611-4e9b-97d5-d02421b2d1d6, runId = e77896e3-ce76-488b-8345-7a29cc0d7d0b]. Use s3a://checkpoint/ to store the query checkpoint.
20/07/11 18:15:17 INFO MicroBatchExecution: Using MicroBatchReader [KafkaV2[Subscribe[test]]] from DataSourceV2 named 'kafka' [org.apache.spark.sql.kafka010.KafkaSourceProvider@2375c472]
20/07/11 18:15:17 INFO MicroBatchExecution: Starting new streaming query.
20/07/11 18:15:17 INFO MicroBatchExecution: Stream started from {}
20/07/11 18:15:18 INFO ConsumerConfig: ConsumerConfig values:
auto.commit.interval.ms = 5000
auto.offset.reset = earliest
bootstrap.servers = [localhost:9092]
check.crcs = true
client.id =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.ByteArrayDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 1
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
session.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = https
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class org.apache.kafka.common.serialization.ByteArrayDeserializer

20/07/11 18:15:18 INFO AppInfoParser: Kafka version : 2.0.0
20/07/11 18:15:18 INFO AppInfoParser: Kafka commitId : 3402a8361b734732
20/07/11 18:15:18 INFO Metadata: Cluster ID: X8K8aVFyRi6OcUDs1zXOhQ
20/07/11 18:15:18 INFO AbstractCoordinator: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Discovered group coordinator Myuser-PC:9092 (id: 2147483647 rack: null)
20/07/11 18:15:18 INFO ConsumerCoordinator: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Revoking previously assigned partitions []
20/07/11 18:15:18 INFO AbstractCoordinator: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] (Re-)joining group
20/07/11 18:15:18 INFO AbstractCoordinator: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Successfully joined group with generation 1
20/07/11 18:15:18 INFO ConsumerCoordinator: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Setting newly assigned partitions [test-0]
20/07/11 18:15:18 INFO Fetcher: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Resetting offset for partition test-0 to offset 0.
20/07/11 18:15:18 INFO Fetcher: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Resetting offset for partition test-0 to offset 18.
20/07/11 18:15:18 INFO deprecation: io.bytes.per.checksum is deprecated. Instead, use dfs.bytes-per-checksum
20/07/11 18:15:18 INFO CheckpointFileManager: Writing atomically to s3a://checkpoint/sources/0/0 using temp file s3a://checkpoint/sources/0/.0.e900c0dd-dbb5-4ca7-ada2-e3a84e892c5f.tmp
20/07/11 18:15:19 INFO CheckpointFileManager: Renamed temp file s3a://checkpoint/sources/0/.0.e900c0dd-dbb5-4ca7-ada2-e3a84e892c5f.tmp to s3a://checkpoint/sources/0/0
20/07/11 18:15:19 INFO KafkaMicroBatchReader: Initial offsets: {"test":{"0":18}}
20/07/11 18:15:19 INFO Fetcher: [Consumer clientId=consumer-1, groupId=spark-kafka-source-1fa35d7f-b356-4806-9ee7-658ef48c837d--2088528104-driver-0] Resetting offset for partition test-0 to offset 18.
20/07/11 18:15:19 INFO CheckpointFileManager: Writing atomically to s3a://checkpoint/offsets/0 using temp file s3a://checkpoint/offsets/.0.a7a4e7f3-7e4a-433f-8532-23d6179c3b98.tmp
20/07/11 18:15:19 INFO CheckpointFileManager: Renamed temp file s3a://checkpoint/offsets/.0.a7a4e7f3-7e4a-433f-8532-23d6179c3b98.tmp to s3a://checkpoint/offsets/0
20/07/11 18:15:19 INFO MicroBatchExecution: Committed offsets for batch 0. Metadata OffsetSeqMetadata(0,1594480519101,Map(spark.sql.streaming.stateStore.providerClass -> org.apache.spark.sql.execution.streaming.state.HDFSBackedStateStoreProvider, spark.sql.streaming.flatMapGroupsWithState.stateFormatVersion -> 2, spark.sql.streaming.multipleWatermarkPolicy -> min, spark.sql.streaming.aggregation.stateFormatVersion -> 2, spark.sql.shuffle.partitions -> 200))
20/07/11 18:15:20 INFO KafkaMicroBatchReader: Partitions added: Map()
20/07/11 18:15:20 INFO CodeGenerator: Code generated in 171.85213 ms
20/07/11 18:15:20 INFO CodeGenerator: Code generated in 23.189288 ms

我进入检查点目录并修改了数据,它从头开始处理!必须有一个配置做同样的事情..

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