Heimdall: Fix bug where DB being disabled might cause errors.

This commit is contained in:
Kenneth Endfinger
2022-02-21 19:30:27 -05:00
parent 1879df780b
commit 6e1afb5e5c
4 changed files with 12 additions and 2 deletions

View File

@ -29,7 +29,7 @@ import kotlin.io.path.inputStream
class FoundationHeimdallPlugin : JavaPlugin(), Listener {
private lateinit var config: HeimdallConfig
private lateinit var pool: HikariDataSource
internal lateinit var db: Database
internal var db: Database? = null
private val buffer = EventBuffer()
private val bufferFlushThread = BufferFlushThread(this, buffer)

View File

@ -31,6 +31,11 @@ class BufferFlushThread(val plugin: FoundationHeimdallPlugin, val buffer: EventB
fun flush() {
try {
val db = plugin.db
if (db == null) {
buffer.clear()
return
}
transaction(plugin.db) {
val count = buffer.flush(this)
if (count > 0) {

View File

@ -21,4 +21,8 @@ class EventBuffer {
fun push(event: HeimdallEvent) {
events.add(event)
}
fun clear() {
events = mutableListOf()
}
}

View File

@ -2,8 +2,9 @@ package cloud.kubelet.foundation.gjallarhorn.export
import cloud.kubelet.foundation.gjallarhorn.state.BlockExpanse
import cloud.kubelet.foundation.gjallarhorn.state.SparseBlockStateMap
import kotlinx.serialization.Serializable
@kotlinx.serialization.Serializable
@Serializable
class CombinedChunkFormat(
val expanse: BlockExpanse,
val map: SparseBlockStateMap