mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
Merge pull request #2498 from corda/aslemmer-fix-cache-duplicate-detection-on-evict
CORDA-1003: Fix duplicate detection on cache evict
This commit is contained in:
commit
a9109e0855
@ -57,6 +57,7 @@ abstract class AppendOnlyPersistentMapBase<K, V, E, out EK>(
|
|||||||
// Depending on 'store' method, this may insert without checking key duplication or it may avoid inserting a duplicated key.
|
// Depending on 'store' method, this may insert without checking key duplication or it may avoid inserting a duplicated key.
|
||||||
val existingInDb = store(key, value)
|
val existingInDb = store(key, value)
|
||||||
if (existingInDb != null) { // Always reuse an existing value from the storage of a duplicated key.
|
if (existingInDb != null) { // Always reuse an existing value from the storage of a duplicated key.
|
||||||
|
isUnique = false
|
||||||
Optional.of(existingInDb)
|
Optional.of(existingInDb)
|
||||||
} else {
|
} else {
|
||||||
Optional.of(value)
|
Optional.of(value)
|
||||||
|
@ -172,9 +172,22 @@ class DBTransactionStorageTests {
|
|||||||
assertEquals(expected, actual)
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newTransactionStorage() {
|
@Test
|
||||||
|
fun `duplicates are detected when transaction is evicted from cache`() {
|
||||||
|
newTransactionStorage(cacheSizeBytesOverride = 0)
|
||||||
|
val transaction = newTransaction()
|
||||||
database.transaction {
|
database.transaction {
|
||||||
transactionStorage = DBTransactionStorage(NodeConfiguration.defaultTransactionCacheSize)
|
val firstInserted = transactionStorage.addTransaction(transaction)
|
||||||
|
val secondInserted = transactionStorage.addTransaction(transaction)
|
||||||
|
require(firstInserted) { "We inserted a fresh transaction" }
|
||||||
|
require(!secondInserted) { "Second time should be redundant" }
|
||||||
|
println("$firstInserted $secondInserted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun newTransactionStorage(cacheSizeBytesOverride: Long? = null) {
|
||||||
|
database.transaction {
|
||||||
|
transactionStorage = DBTransactionStorage(cacheSizeBytesOverride ?: NodeConfiguration.defaultTransactionCacheSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user