Skip to content

Commit 13c899e

Browse files
authored
fix: skip action rows with extra_data exceeding MySQL TEXT column limit (#371)
1 parent 6e3f820 commit 13c899e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import kotlin.math.ceil
7373
const val MAX_QUERY_RETRIES = 10
7474
const val MIN_RETRY_DELAY = 1000L
7575
const val MAX_RETRY_DELAY = 300_000L
76+
private const val MAX_EXTRA_DATA_BYTES = 65_535
7677

7778
object DatabaseManager {
7879

@@ -456,7 +457,18 @@ object DatabaseManager {
456457
}
457458

458459
private fun Transaction.insertActions(actions: List<ActionType>) {
459-
Tables.Actions.batchInsert(actions, shouldReturnGeneratedValues = false) { action ->
460+
val (safe, oversized) = actions.partition {
461+
it.extraData == null || it.extraData!!.length <= MAX_EXTRA_DATA_BYTES
462+
}
463+
oversized.forEach { action ->
464+
logWarn(
465+
"Skipping action log: extra_data too large (${action.extraData!!.length} chars) " +
466+
"for action ${action.identifier} at " +
467+
"[${action.world} ${action.pos.x} ${action.pos.y} ${action.pos.z}] " +
468+
"by ${action.sourceProfile?.name ?: action.sourceName}",
469+
)
470+
}
471+
Tables.Actions.batchInsert(safe, shouldReturnGeneratedValues = false) { action ->
460472
this[Tables.Actions.actionIdentifier] = getOrCreateActionId(action.identifier)
461473
this[Tables.Actions.timestamp] = action.timestamp
462474
this[Tables.Actions.x] = action.pos.x

0 commit comments

Comments
 (0)