zecookiez commented on code in PR #50030:
URL: https://github.com/apache/spark/pull/50030#discussion_r2014387105


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/state/StateStoreInstanceMetricSuite.scala:
##########
@@ -0,0 +1,385 @@
+/*
+ * 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.execution.streaming.state
+
+import scala.concurrent.duration.DurationInt
+import scala.jdk.CollectionConverters.MapHasAsScala
+
+import org.apache.spark.sql.execution.streaming.MemoryStream
+import org.apache.spark.sql.functions.expr
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.streaming._
+
+// RocksDBSkipMaintenanceOnCertainPartitionsProvider is a test-only provider 
that skips running
+// maintenance for partitions 0 and 1 (these are arbitrary choices). This is 
used to test
+// snapshot upload lag can be observed through StreamingQueryProgress metrics.
+class RocksDBSkipMaintenanceOnCertainPartitionsProvider extends 
RocksDBStateStoreProvider {
+  override def doMaintenance(): Unit = {
+    if (stateStoreId.partitionId == 0 || stateStoreId.partitionId == 1) {
+      return
+    }
+    super.doMaintenance()
+  }
+}
+
+// HDFSBackedSkipMaintenanceOnCertainPartitionsProvider is a test-only 
provider that skips running
+// maintenance for partitions 0 and 1 (these are arbitrary choices). This is 
used to test
+// snapshot upload lag can be observed through StreamingQueryProgress metrics.
+class HDFSBackedSkipMaintenanceOnCertainPartitionsProvider extends 
HDFSBackedStateStoreProvider {
+  override def doMaintenance(): Unit = {
+    if (stateStoreId.partitionId == 0 || stateStoreId.partitionId == 1) {
+      return
+    }
+    super.doMaintenance()
+  }
+}
+
+class StateStoreInstanceMetricSuite extends StreamTest with 
AlsoTestWithRocksDBFeatures {
+  import testImplicits._
+
+  private val SNAPSHOT_LAG_METRIC_PREFIX = "SnapshotLastUploaded.partition_"
+
+  private def snapshotLagMetricName(
+      partitionId: Long,
+      storeName: String = StateStoreId.DEFAULT_STORE_NAME): String = {
+    s"$SNAPSHOT_LAG_METRIC_PREFIX${partitionId}_$storeName"
+  }
+
+  Seq(
+    ("SPARK-51097", "RocksDBStateStoreProvider", 
classOf[RocksDBStateStoreProvider].getName),
+    ("SPARK-51252", "HDFSBackedStateStoreProvider", 
classOf[HDFSBackedStateStoreProvider].getName)

Review Comment:
   @LuciferYang @HeartSaVioR I opened up a PR for the fix at 
https://github.com/apache/spark/pull/50405. Sorry for the flaky tests, I 
should've verified this more with this 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to