danny0405 commented on code in PR #20679: URL: https://github.com/apache/hudi/pull/20679#discussion_r4625056548
########## 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: Fixed in de440b7004e. Admission now merges archived and active completed writes before selecting a boundary, and applies IncrementalQueryAnalyzer.filterInstantsAsPerUserConfigs before counting. MOR compactions are excluded when skip_compact=true. Clustering remains included because Spark incremental reads do not currently support skipping clustering; the website guidance states that explicitly. Added a cap=1 timeline regression spanning archived and active writes with an out-of-order compaction, verifying that the compaction consumes no slot and archived writes are admitted individually. The cap-one MOR ProcessingTime regressions exercise real compaction in both V1 time modes. For #20516, snapshot fallback/recovery reads remain outside the commit cap. The acceptance notes and PR description explicitly require the PR that lands second to test recovery at a capped intermediate end, including cleaned files and an unavailable snapshot; I have not claimed combined-branch coverage here. Moved the user-facing guidance to companion website PR #20751 (ready for review, MDX compilation passed). SOURCE_THROTTLING.md now contains regression/integration notes and a link to that PR. -- 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]
