Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cp-2790] Fix gc max wait time #2792

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.pingcap.tikv.exception.TiInternalException
import com.pingcap.tikv.meta.TiTimestamp
import com.pingcap.tikv.util.{BackOffer, ConcreteBackOffer}
import com.google.common.util.concurrent.ThreadFactoryBuilder
import org.apache.spark.sql.SparkSession
import org.slf4j.LoggerFactory

import java.util.concurrent.{Executors, ScheduledExecutorService, TimeUnit}
Expand All @@ -31,7 +32,8 @@ case class ServiceSafePoint(
serviceId: String,
ttl: Long,
GCMaxWaitTime: Long,
tiSession: TiSession) {
tiSession: TiSession,
sparkSession: SparkSession) {

private final val logger = LoggerFactory.getLogger(getClass.getName)
private var minStartTs = Long.MaxValue
Expand All @@ -40,6 +42,14 @@ case class ServiceSafePoint(
service.scheduleAtFixedRate(
() => {
if (minStartTs != Long.MaxValue) {
val now = tiSession.getTimestamp
if (now.getPhysical - TiTimestamp.extractPhysical(minStartTs) >= GCMaxWaitTime * 1000) {
val msg =
s"Can not pause GC more than spark.tispark.gc_max_wait_time=$GCMaxWaitTime s. start_ts: ${minStartTs}, now: ${now.getVersion}. You can adjust spark.tispark.gc_max_wait_time to increase the gc max wait time."
logger.error(msg)
sparkSession.stop()
throw new TiInternalException(msg)
}
val safePoint = tiSession.getPDClient.updateServiceGCSafePoint(
serviceId,
ttl,
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/org/apache/spark/sql/TiContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class TiContext(val sparkSession: SparkSession) extends Serializable with Loggin
"tispark_" + UUID.randomUUID,
TiConfigConst.DEFAULT_GC_SAFE_POINT_TTL,
GCMaxWaitTime,
tiSession)
tiSession,
sparkSession)

sparkSession.sparkContext.addSparkListener(new SparkListener() {
override def onApplicationEnd(applicationEnd: SparkListenerApplicationEnd): Unit = {
Expand Down
Loading