Skip to content

Commit e4da023

Browse files
committed
Save
1 parent c94d254 commit e4da023

File tree

8 files changed

+47
-24
lines changed

8 files changed

+47
-24
lines changed

docs/configuration/settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co
382382

383383
| Key | Default | Meaning | Type | Since |
384384
|-------------------------------------------------|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|--------|
385+
| kyuubi.metadata.cleaner.batch.size | 2147483647 | The batch size for cleaning expired metadata. This is used to avoid holding the delete lock for a long time when there are too many expired metadata to be cleaned. | int | 1.11.0 |
385386
| kyuubi.metadata.cleaner.enabled | true | Whether to clean the metadata periodically. If it is enabled, Kyuubi will clean the metadata that is in the terminate state with max age limitation. | boolean | 1.6.0 |
386387
| kyuubi.metadata.cleaner.interval | PT30M | The interval to check and clean expired metadata. | duration | 1.6.0 |
387388
| kyuubi.metadata.max.age | PT72H | The maximum age of metadata, the metadata exceeding the age will be cleaned. | duration | 1.6.0 |

kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,25 +2077,24 @@ object KyuubiConf {
20772077
.timeConf
20782078
.createWithDefault(Duration.ofMinutes(30).toMillis)
20792079

2080-
val METADATA_CLEANER_BATCH_INTERVAL: ConfigEntry[Long] =
2081-
buildConf("kyuubi.metadata.cleaner.batch.interval")
2082-
.serverOnly
2083-
.internal
2084-
.doc("The interval to check and clean expired metadata in batch mode. " +
2085-
"This is used to avoid the metadata cleaner thread being blocked for a long time " +
2086-
"when there are too many expired metadata to be cleaned.")
2087-
.version("1.11.0")
2088-
.timeConf
2089-
.createWithDefault(Duration.ofMillis(100).toMillis)
2090-
20912080
val METADATA_CLEANER_BATCH_SIZE: ConfigEntry[Int] =
20922081
buildConf("kyuubi.metadata.cleaner.batch.size")
20932082
.serverOnly
2094-
.doc("The batch size for cleaning expired metadata.")
2083+
.doc("The batch size for cleaning expired metadata. " +
2084+
"This is used to avoid holding the delete lock for a long time " +
2085+
"when there are too many expired metadata to be cleaned.")
20952086
.version("1.11.0")
20962087
.intConf
20972088
.createWithDefault(Int.MaxValue)
20982089

2090+
val METADATA_CLEANER_BATCH_INTERVAL: ConfigEntry[Long] =
2091+
buildConf("kyuubi.metadata.cleaner.batch.interval")
2092+
.serverOnly
2093+
.internal
2094+
.doc("The interval to wait before next batch of cleaning expired metadata.")
2095+
.timeConf
2096+
.createWithDefault(Duration.ofMillis(100).toMillis)
2097+
20992098
val METADATA_RECOVERY_THREADS: ConfigEntry[Int] =
21002099
buildConf("kyuubi.metadata.recovery.threads")
21012100
.serverOnly

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/MetadataManager.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package org.apache.kyuubi.server.metadata
1919

20-
import com.google.common.annotations.VisibleForTesting
21-
2220
import java.util.concurrent.{ConcurrentHashMap, ThreadPoolExecutor, TimeUnit}
2321
import java.util.concurrent.atomic.AtomicInteger
22+
2423
import scala.collection.JavaConverters._
24+
25+
import com.google.common.annotations.VisibleForTesting
26+
2527
import org.apache.kyuubi.{KyuubiException, Logging}
2628
import org.apache.kyuubi.client.api.v1.dto.Batch
2729
import org.apache.kyuubi.config.KyuubiConf

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/MetadataStore.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ trait MetadataStore extends Closeable {
106106
*/
107107
def cleanupMetadataByAge(maxAge: Long, limit: Int): Int
108108

109+
def cleanupMetadataByAge(maxAge: Long): Int = {
110+
cleanupMetadataByAge(maxAge, Int.MaxValue)
111+
}
112+
109113
/**
110114
* Cleanup kubernetes engine info by identifier.
111115
*/
@@ -117,4 +121,8 @@ trait MetadataStore extends Closeable {
117121
* @param limit the maximum number of kubernetes engine info to be cleaned up.
118122
*/
119123
def cleanupKubernetesEngineInfoByAge(maxAge: Long, limit: Int): Int
124+
125+
def cleanupKubernetesEngineInfoByAge(maxAge: Long): Int = {
126+
cleanupKubernetesEngineInfoByAge(maxAge, Int.MaxValue)
127+
}
120128
}

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStore.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,10 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
414414
override def cleanupMetadataByAge(maxAge: Long, limit: Int): Int = {
415415
val minEndTime = System.currentTimeMillis() - maxAge
416416
val query =
417-
s"DELETE FROM $METADATA_TABLE WHERE state IN ($terminalStates) AND end_time < ? liMIT ?"
417+
s"DELETE FROM $METADATA_TABLE WHERE state IN ($terminalStates) AND end_time < ?" +
418+
s" ${dialect.deleteFromLimitClause(limit)}"
418419
JdbcUtils.withConnection { connection =>
419-
withUpdateCount(connection, query, minEndTime, limit) { count =>
420+
withUpdateCount(connection, query, minEndTime) { count =>
420421
info(s"Cleaned up $count records older than $maxAge ms from $METADATA_TABLE limit:$limit.")
421422
count
422423
}
@@ -467,9 +468,10 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
467468

468469
override def cleanupKubernetesEngineInfoByAge(maxAge: Long, limit: Int): Int = {
469470
val minUpdateTime = System.currentTimeMillis() - maxAge
470-
val query = s"DELETE FROM $KUBERNETES_ENGINE_INFO_TABLE WHERE update_time < ? LIMIT ?"
471+
val query = s"DELETE FROM $KUBERNETES_ENGINE_INFO_TABLE WHERE update_time < ?" +
472+
s" ${dialect.deleteFromLimitClause(limit)}"
471473
JdbcUtils.withConnection { connection =>
472-
withUpdateCount(connection, query, minUpdateTime, limit) { count =>
474+
withUpdateCount(connection, query, minUpdateTime) { count =>
473475
info(s"Cleaned up $count records older than $maxAge ms from $KUBERNETES_ENGINE_INFO_TABLE" +
474476
s" limit $limit.")
475477
count

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/jdbc/JdbcDatabaseDialect.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.kyuubi.server.metadata.jdbc
1919

2020
trait JdbcDatabaseDialect {
2121
def limitClause(limit: Int, offset: Int): String
22+
def deleteFromLimitClause(limit: Int): String
2223
def insertOrReplace(
2324
table: String,
2425
cols: Seq[String],
@@ -31,6 +32,10 @@ class GenericDatabaseDialect extends JdbcDatabaseDialect {
3132
s"LIMIT $limit OFFSET $offset"
3233
}
3334

35+
override def deleteFromLimitClause(limit: Int): String = {
36+
"" // Generic dialect does not support LIMIT in DELETE statements
37+
}
38+
3439
override def insertOrReplace(
3540
table: String,
3641
cols: Seq[String],
@@ -71,6 +76,10 @@ class MySQLDatabaseDialect extends GenericDatabaseDialect {
7176
|${cols.filterNot(_ == keyCol).map(c => s"$c = new.$c").mkString(",")}
7277
|""".stripMargin
7378
}
79+
80+
override def deleteFromLimitClause(limit: Int): String = {
81+
s"LIMIT $limit"
82+
}
7483
}
7584
class PostgreSQLDatabaseDialect extends GenericDatabaseDialect {
7685
override def insertOrReplace(

kyuubi-server/src/test/scala/org/apache/kyuubi/server/metadata/MetadataManagerSuite.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,12 @@ class MetadataManagerSuite extends KyuubiFunSuite {
214214
metadataManager.getBatches(MetadataFilter(), 0, Int.MaxValue).foreach { batch =>
215215
// close the batch if not ended
216216
if (batch.getEndTime == 0) {
217-
metadataManager.updateMetadata(Metadata(
218-
identifier = batch.getId,
219-
state = OperationState.CLOSED.toString,
220-
endTime = System.currentTimeMillis()), false)
217+
metadataManager.updateMetadata(
218+
Metadata(
219+
identifier = batch.getId,
220+
state = OperationState.CLOSED.toString,
221+
endTime = System.currentTimeMillis()),
222+
false)
221223
}
222224
}
223225

kyuubi-server/src/test/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStoreSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class JDBCMetadataStoreSuite extends KyuubiFunSuite {
4545
batch =>
4646
jdbcMetadataStore.cleanupMetadataByIdentifier(batch.identifier)
4747
}
48-
jdbcMetadataStore.cleanupKubernetesEngineInfoByAge(0, Int.MaxValue)
48+
jdbcMetadataStore.cleanupKubernetesEngineInfoByAge(0)
4949
jdbcMetadataStore.close()
5050
}
5151

@@ -242,7 +242,7 @@ class JDBCMetadataStoreSuite extends KyuubiFunSuite {
242242
Int.MaxValue).isEmpty)
243243

244244
eventually(Timeout(3.seconds)) {
245-
jdbcMetadataStore.cleanupMetadataByAge(1000, Int.MaxValue)
245+
jdbcMetadataStore.cleanupMetadataByAge(1000)
246246
assert(jdbcMetadataStore.getMetadata(batchId) == null)
247247
}
248248
}

0 commit comments

Comments
 (0)