danny0405 commented on code in PR #20679:
URL: https://github.com/apache/hudi/pull/20679#discussion_r4639454911
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/streaming/HoodieStreamSourceV1.scala:
##########
@@ -97,6 +99,18 @@ class HoodieStreamSourceV1(sqlContext: SQLContext,
}
}
+ override protected def admissionParameters: Map[String, String] = parameters
+
+ override protected def admissionInitialOffset: HoodieSourceOffset =
initialOffsets
+
+ override protected def completedWriteOffsets: Seq[String] = {
+ metaClient.reloadActiveTimeline()
+ val timeline = handleHollowCommitIfNeeded(
+ metaClient.getActiveTimeline.getWriteTimeline.filterCompletedInstants(),
metaClient, hollowCommitHandlingMode)
+ timeline.getInstants.asScala.map(instant =>
+ if (hollowCommitHandlingMode == USE_TRANSITION_TIME)
instant.getCompletionTime else instant.requestedTime()).toSeq
Review Comment:
Follow-up in `26b7428ff4a6`: the cap-one v6 MOR regression now runs both
`skip_compact` values in `BLOCK` and `USE_TRANSITION_TIME`. It verifies that
compaction was requested before the last delta commit and completed after it,
and checks the order and uniqueness of rows. In `BLOCK`, it also checks that
compaction becomes a batch boundary when `skip_compact=false`. The upgrade note
in #20751 covers the possible one-time replay from older `BLOCK` checkpoints.
The existing requested-time record span in `MergeOnReadIncrementalRelationV1`
is a separate follow-up. All four cases passed on JDK 17 and Spark 3.5.
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/streaming/HoodieSourceAdmissionControl.scala:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hudi.streaming
+
+import org.apache.hudi.DataSourceReadOptions.STREAMING_MAX_COMMITS_PER_TRIGGER
+
+import org.apache.spark.sql.connector.read.streaming.{Offset =>
ConnectorOffset, ReadLimit, SupportsTriggerAvailableNow}
+import org.apache.spark.sql.execution.streaming.Source
+
+/** Commit boundaries are indivisible: this limits commits, not rows or bytes.
*/
+private[streaming] trait HoodieSourceAdmissionControl extends Source with
SupportsTriggerAvailableNow {
+ protected def admissionParameters: Map[String, String]
+ protected def admissionInitialOffset: HoodieSourceOffset
+ protected def completedWriteOffsets: Seq[String]
+
+ private lazy val configuredLimit: ReadLimit =
admissionParameters.get(STREAMING_MAX_COMMITS_PER_TRIGGER.key) match {
+ case Some(value) =>
+ val count = try {
+ value.toInt
+ } catch {
+ case _: NumberFormatException => throw new IllegalArgumentException(
+ s"${STREAMING_MAX_COMMITS_PER_TRIGGER.key} must be a positive
integer: $value")
+ }
+ require(count > 0, s"${STREAMING_MAX_COMMITS_PER_TRIGGER.key} must be
positive: $value")
+ HoodieSourceCommitLimit(count)
+ case None => ReadLimit.allAvailable()
+ }
+
+ // Some(None) means AvailableNow started on an empty timeline. Do not admit
later arrivals.
+ private var availableNowEnd: Option[Option[HoodieSourceOffset]] = None
+
+ override def getDefaultReadLimit: ReadLimit = configuredLimit
+
+ override def prepareForTriggerAvailableNow(): Unit = {
+ // Capture 'latest' initial offsets before pinning the end, rather than at
the first getBatch.
+ admissionInitialOffset
+ availableNowEnd = Some(getOffset.map(HoodieSourceOffset(_)))
+ }
+
+ override def latestOffset(startOffset: ConnectorOffset, limit: ReadLimit):
ConnectorOffset = {
+ val start = Option(startOffset).map(offset =>
HoodieSourceOffset.fromJson(offset.json()))
+ .getOrElse(admissionInitialOffset)
+ val end = availableNowEnd.getOrElse(getOffset.map(HoodieSourceOffset(_)))
+ end.map { latest =>
+ limit match {
+ case HoodieSourceCommitLimit(count) =>
+ val candidates = completedWriteOffsets.sorted.filter(time =>
Review Comment:
Follow-up in `26b7428ff4a6`: idle triggers skip candidate lookup.
Requested-time checkpoints read the archive from the checkpoint only if it
predates the active write timeline. For completion-time offsets, the archive is
indexed by requested time, so the lookup uses the incremental reader's one-day
lookback. That bounded range can still overlap the archive when an older
request completed late. Legacy entries with no completion time are skipped in
completion-time mode. An instant present in both snapshots counts once, and
separate writes sharing a completion timestamp still count separately.
The streaming test package is now in the package check and the Azure and
GitHub Spark test filters. The package check, admission tests, MOR clustering
and capped V2 MOR CDC passed on JDK 17 and Spark 3.5. Spark 4.2 and Azure
results for this revision are pending.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]