Properly synchronised sqlite3 handler across threads

This commit is contained in:
Amos Ng 2020-06-16 08:04:22 +08:00
parent 5b78da589e
commit 0afa1d2eaa
No known key found for this signature in database
GPG Key ID: 89086414F634D123
2 changed files with 16 additions and 9 deletions

View File

@ -30,8 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [2020-06-14] Removed old cache subdirectory migration system by [@carbotaniuman].
### Fixed
- [2020-06-15] Fixed tokenized data-saver parser not working by [@lflare].
- [2020-06-14] Switched cache metadata over to a MySql instance [@carbotaniuman].
- [2020-06-15] Fixed tokenized data-saver parser not working by [@lflare].
- [2020-06-15] Properly synchronised sqlite3 handler across threads by [@lflare].
## [1.0.0-RC16] - 2020-06-14
### Added

View File

@ -77,8 +77,10 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
val imageId = printHexString(rc4Bytes)
val snapshot = cache.getUnsafe(imageId.toCacheId())
val imageDatum = transaction(database) {
ImageDatum.findById(imageId)
val imageDatum = synchronized(database) {
transaction(database) {
ImageDatum.findById(imageId)
}
}
if (snapshot != null && imageDatum != null) {
@ -96,8 +98,10 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
if (LOGGER.isWarnEnabled) {
LOGGER.warn("Deleting DB entry for $sanitizedUri without corresponding file")
}
transaction(database) {
imageDatum.delete()
synchronized(database) {
transaction(database) {
imageDatum.delete()
}
}
}
@ -174,10 +178,12 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
LOGGER.trace("Request for $sanitizedUri is being cached and served")
}
transaction(database) {
ImageDatum.new(imageId) {
this.contentType = contentType
this.lastModified = lastModified
synchronized(database) {
transaction(database) {
ImageDatum.new(imageId) {
this.contentType = contentType
this.lastModified = lastModified
}
}
}