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

[Backport 0.5-nexus] Support alter from manual to auto without specifying scheduler mode #932

Merged
merged 1 commit into from
Nov 20, 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 @@ -523,6 +523,10 @@ class FlintSpark(val spark: SparkSession) extends FlintSparkTransactionSupport w
private def isSchedulerModeChanged(
originalOptions: FlintSparkIndexOptions,
updatedOptions: FlintSparkIndexOptions): Boolean = {
// Altering from manual to auto should not be interpreted as a scheduling mode change.
if (!originalOptions.options.contains(SCHEDULER_MODE.toString)) {
return false
}
updatedOptions.isExternalSchedulerEnabled() != originalOptions.isExternalSchedulerEnabled()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,44 @@ class FlintSparkUpdateIndexITSuite extends FlintSparkSuite {
flint.queryIndex(testIndex).collect().toSet should have size 2
}

test("update full refresh index to auto refresh should start job with external scheduler") {
setFlintSparkConf(FlintSparkConf.EXTERNAL_SCHEDULER_ENABLED, "true")

withTempDir { checkpointDir =>
// Create full refresh Flint index
flint
.skippingIndex()
.onTable(testTable)
.addPartitions("year", "month")
.options(FlintSparkIndexOptions(Map("auto_refresh" -> "false")), testIndex)
.create()

spark.streams.active.find(_.name == testIndex) shouldBe empty
flint.queryIndex(testIndex).collect().toSet should have size 0
val indexInitial = flint.describeIndex(testIndex).get
indexInitial.options.isExternalSchedulerEnabled() shouldBe false

val updatedIndex = flint
.skippingIndex()
.copyWithUpdate(
indexInitial,
FlintSparkIndexOptions(
Map(
"auto_refresh" -> "true",
"checkpoint_location" -> checkpointDir.getAbsolutePath)))

val jobId = flint.updateIndex(updatedIndex)
jobId shouldBe empty
val indexFinal = flint.describeIndex(testIndex).get
indexFinal.options.isExternalSchedulerEnabled() shouldBe true
indexFinal.options.autoRefresh() shouldBe true
indexFinal.options.refreshInterval() shouldBe Some(
FlintOptions.DEFAULT_EXTERNAL_SCHEDULER_INTERVAL)

verifySchedulerIndex(testIndex, 5, "MINUTES")
}
}

test("update incremental refresh index to auto refresh should start job") {
withTempDir { checkpointDir =>
// Create incremental refresh Flint index and wait for complete
Expand Down Expand Up @@ -673,6 +711,51 @@ class FlintSparkUpdateIndexITSuite extends FlintSparkSuite {
}
}

test(
"update incremental refresh index to auto refresh should start job with external scheduler") {
setFlintSparkConf(FlintSparkConf.EXTERNAL_SCHEDULER_ENABLED, "true")

withTempDir { checkpointDir =>
// Create incremental refresh Flint index
flint
.skippingIndex()
.onTable(testTable)
.addPartitions("year", "month")
.options(
FlintSparkIndexOptions(
Map(
"incremental_refresh" -> "true",
"checkpoint_location" -> checkpointDir.getAbsolutePath)),
testIndex)
.create()

spark.streams.active.find(_.name == testIndex) shouldBe empty
flint.queryIndex(testIndex).collect().toSet should have size 0
val indexInitial = flint.describeIndex(testIndex).get
indexInitial.options.isExternalSchedulerEnabled() shouldBe false

val updatedIndex = flint
.skippingIndex()
.copyWithUpdate(
indexInitial,
FlintSparkIndexOptions(
Map(
"auto_refresh" -> "true",
"incremental_refresh" -> "false",
"checkpoint_location" -> checkpointDir.getAbsolutePath)))

val jobId = flint.updateIndex(updatedIndex)
jobId shouldBe empty
val indexFinal = flint.describeIndex(testIndex).get
indexFinal.options.isExternalSchedulerEnabled() shouldBe true
indexFinal.options.autoRefresh() shouldBe true
indexFinal.options.refreshInterval() shouldBe Some(
FlintOptions.DEFAULT_EXTERNAL_SCHEDULER_INTERVAL)

verifySchedulerIndex(testIndex, 5, "MINUTES")
}
}

test("update auto refresh index to full refresh should stop job") {
// Create auto refresh Flint index and wait for complete
flint
Expand Down
Loading