Merge pull request #7276 from corda/cc/merge/os-4.9/os-4.10/28-Nov-2022

ENT-8817 - Fwd-merge OS 4.9 to OS 4.10
This commit is contained in:
Rick Parker 2022-11-29 08:47:00 +00:00 committed by GitHub
commit c3083af4c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -73,7 +73,7 @@ class InfrequentlyMutatedCache<K : Any, V : Any>(name: String, cacheFactory: Nam
backingCache.invalidateAll() backingCache.invalidateAll()
} }
private fun invalidate(key: K, value: Wrapper.Invalidated<V>): Wrapper.Invalidated<V> { private fun invalidate(key: K, value: Wrapper.Invalidated<V>): Wrapper.Invalidated<V>? {
val tx = contextTransactionOrNull val tx = contextTransactionOrNull
value.invalidators.incrementAndGet() value.invalidators.incrementAndGet()
currentlyInvalid[key] = value currentlyInvalid[key] = value
@ -81,7 +81,10 @@ class InfrequentlyMutatedCache<K : Any, V : Any>(name: String, cacheFactory: Nam
// When we close, we can't start using caching again until all simultaneously open transactions are closed. // When we close, we can't start using caching again until all simultaneously open transactions are closed.
tx.onClose { tx.database.onAllOpenTransactionsClosed { decrementInvalidators(key, value) } } tx.onClose { tx.database.onAllOpenTransactionsClosed { decrementInvalidators(key, value) } }
} else { } else {
decrementInvalidators(key, value) if (value.invalidators.decrementAndGet() == 0) {
currentlyInvalid.remove(key)
return null
}
} }
return value return value
} }

View File

@ -25,6 +25,11 @@ class InfrequentlyMutatedCacheTest {
database.close() database.close()
} }
@Test(timeout = 300_000)
fun `invalidate outside transaction should not hang`() {
cache.invalidate("Fred")
}
@Test(timeout=300_000) @Test(timeout=300_000)
fun `get from empty cache returns result of loader`() { fun `get from empty cache returns result of loader`() {
database.transaction { database.transaction {