nsivabalan commented on code in PR #20679:
URL: https://github.com/apache/hudi/pull/20679#discussion_r4624727669
##########
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:
These are requested times in BLOCK mode, but `getBatch` converts both ends
to completion times (write version ≥ 8 by default), and `IncrementalRelationV1`
then filters on requested time. Capped, the intermediate ends have
non-monotonic completion times, which produces the duplicates described in the
review body. Suggest mirroring
`HoodieIncrSource#fetchNextBatchBasedOnRequestedTime`: stay in requested time
end to end on V1.
##########
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:
Every `getWriteTimeline` action counts toward the cap, and only the active
timeline is consulted. Two consequences:
- with `skip_compact=true`, compactions use up the cap but return no rows;
- after an archived start, the first capped batch covers the whole archived
gap.
`IncrementalQueryAnalyzer.limit(...)` applies the limit after the skip
filters. Can we align with that?
--
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]