From 1a816b0f14ec83eac904983c4aec2ee1fd95f031 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 25 Aug 2024 17:20:15 +0100 Subject: [PATCH] Fixed list write deadlock for mysql --- .../data/handlers/impl/MySQLPersistentDataHandler.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/handlers/impl/MySQLPersistentDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/handlers/impl/MySQLPersistentDataHandler.kt index f61dd4ab..9a742523 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/handlers/impl/MySQLPersistentDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/handlers/impl/MySQLPersistentDataHandler.kt @@ -16,6 +16,7 @@ import org.jetbrains.exposed.sql.Column import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.greaterEq import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.deleteWhere @@ -191,11 +192,15 @@ class MySQLPersistentDataHandler( override fun writeAsync(uuid: UUID, key: PersistentDataKey>, value: List) { withRetries { transaction(database) { - table.deleteWhere { (table.uuid eq uuid) and (table.key eq key.key.toString()) } + // Remove existing values greater than the new list size + table.deleteWhere { + (table.uuid eq uuid) and + (table.key eq key.key.toString()) and + (table.index greaterEq value.size) + } - // Can't get batch inserts to work, would like to fix + // Replace existing values in bounds value.forEachIndexed { index, t -> - // Using replace instead of insert to avoid any deadlock issues table.replace { it[table.uuid] = uuid it[table.key] = key.key.toString()