Skip to content

Commit

Permalink
Merge pull request #83 from naver/feature/add-chunk-to-find-jvm-uuid-…
Browse files Browse the repository at this point in the history
…without-agent

Add chunk to selectAllUuidsByWithoutAgent

Reviewed by: @taeyeon-Kim
  • Loading branch information
sohyun-ku authored Jul 12, 2023
2 parents e2b7935 + e0d780a commit 01a107e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ class JvmSql : SqlGeneratorSupport() {

fun selectAllUuidsByWithoutAgent(): String =
"""
SELECT uuid FROM
jvms
WHERE
customerId = :customerId
AND uuid NOT IN (
SELECT
jvmUuid
FROM
agent_state
)
SELECT uuid FROM
jvms
WHERE
customerId = :customerId
AND uuid NOT IN (
SELECT
jvmUuid
FROM
agent_state
)
LIMIT 10000
""".trimIndent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ class GarbageCollectService(
customerId,
baseDateTime.minusMillis(intervalService.batchSweepMarginMilliSecond)
)
val uuidsWithoutAgent = jvmDao.findAllUuidsByWithoutAgent(customerId)

jvmDao.deleteAllByCustomerIdAndUuids(customerId, agentStates.map { it.jvmUuid } + uuidsWithoutAgent)
jvmDao.deleteAllByCustomerIdAndUuids(customerId, agentStates.map { it.jvmUuid })
.also { logger.info { "[$customerId] $it jvm is swiped. " } }
agentStateDao.deleteAllByCustomerIdAndIds(customerId, agentStates.map { it.id })
.also { logger.info { "[$customerId] $it agent state is swiped. " } }
} while (agentStates.isNotEmpty())

do {
val uuidsWithoutAgent = jvmDao.findAllUuidsByWithoutAgent(customerId)
jvmDao.deleteAllByCustomerIdAndUuids(customerId, uuidsWithoutAgent)
.also { logger.info { "[$customerId] $it jvm without agent is swiped." } }
} while (uuidsWithoutAgent.isNotEmpty())
} catch (e: Exception) {
logger.warn(e) { "[$customerId] error occurred while sweepAgentStates, but ignored. " }
}
Expand Down

0 comments on commit 01a107e

Please sign in to comment.