From 3218fd513df9968d7b87de945bafab66683358e8 Mon Sep 17 00:00:00 2001 From: szymonsztuka Date: Tue, 26 Sep 2017 09:34:14 +0100 Subject: [PATCH] optional warning when adding duplicated key to AppendOnlyPersistenMap (#1635) * logging duplication warning is optional when adding to AppendOnlyPersistentMap * suppress warnings in PersistentIdentityService --- .../node/services/identity/PersistentIdentityService.kt | 8 ++++---- .../net/corda/node/utilities/AppendOnlyPersistentMap.kt | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt index 9b739f455c..7d3151c63b 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt @@ -102,11 +102,11 @@ class PersistentIdentityService(identities: Iterable = empt caCertStore = CertStore.getInstance("Collection", CollectionCertStoreParameters(caCertificatesWithRoot)) identities.forEach { val key = mapToKey(it) - keyToParties.addWithDuplicatesAllowed(key, it) - principalToParties.addWithDuplicatesAllowed(it.name, key) + keyToParties.addWithDuplicatesAllowed(key, it, false) + principalToParties.addWithDuplicatesAllowed(it.name, key, false) } confidentialIdentities.forEach { - principalToParties.addWithDuplicatesAllowed(it.name, mapToKey(it)) + principalToParties.addWithDuplicatesAllowed(it.name, mapToKey(it), false) } } @@ -129,7 +129,7 @@ class PersistentIdentityService(identities: Iterable = empt val key = mapToKey(identity) keyToParties.addWithDuplicatesAllowed(key, identity) // Always keep the first party we registered, as that's the well known identity - principalToParties.addWithDuplicatesAllowed(identity.name, key) + principalToParties.addWithDuplicatesAllowed(identity.name, key, false) val parentId = mapToKey(identity.certPath.certificates[1].publicKey) return keyToParties[parentId] } diff --git a/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt b/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt index e18f7d1d16..ab9f83e884 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt @@ -48,7 +48,7 @@ class AppendOnlyPersistentMap ( return result.map { x -> fromPersistentEntity(x) }.asSequence() } - private tailrec fun set(key: K, value: V, logWarning: Boolean = true, store: (K,V) -> V?): Boolean { + private tailrec fun set(key: K, value: V, logWarning: Boolean, store: (K,V) -> V?): Boolean { var insertionAttempt = false var isUnique = true val existingInCache = cache.get(key) { // Thread safe, if multiple threads may wait until the first one has loaded. @@ -95,8 +95,8 @@ class AppendOnlyPersistentMap ( * If the map previously contained a mapping for the key, the old value is not replaced. * @return true if added key was unique, otherwise false */ - fun addWithDuplicatesAllowed(key: K, value: V): Boolean = - set(key, value) { + fun addWithDuplicatesAllowed(key: K, value: V, logWarning: Boolean = true): Boolean = + set(key, value, logWarning) { k, v -> val existingEntry = DatabaseTransactionManager.current().session.find(persistentEntityClass, toPersistentEntityKey(k)) if (existingEntry == null) {