accumulo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] milleruntime commented on a change in pull request #560: Provide new Crypto interface & impl
Date Mon, 06 Aug 2018 21:04:58 GMT
milleruntime commented on a change in pull request #560: Provide new Crypto interface &
impl
URL: https://github.com/apache/accumulo/pull/560#discussion_r208028977
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/security/crypto/CryptoServiceFactory.java
 ##########
 @@ -16,30 +16,30 @@
  */
 package org.apache.accumulo.core.security.crypto;
 
+import java.util.concurrent.atomic.AtomicReference;
+
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.spi.crypto.CryptoService;
 import org.apache.accumulo.core.spi.crypto.CryptoService.CryptoException;
 import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
 
 public class CryptoServiceFactory {
-  private static CryptoService singleton = null;
+  private static AtomicReference<CryptoService> singleton = new AtomicReference<>();
 
   /**
    * Load the singleton class configured in {@link Property#INSTANCE_CRYPTO_SERVICE}
    */
   public static CryptoService getConfigured(AccumuloConfiguration conf) {
+    CryptoService cyptoService = singleton.get();
     String configuredClass = conf.get(Property.INSTANCE_CRYPTO_SERVICE.getKey());
-    if (singleton == null) {
-      singleton = loadCryptoService(configuredClass);
-      singleton.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
-    } else {
-      if (!singleton.getClass().getName().equals(configuredClass)) {
-        singleton = loadCryptoService(configuredClass);
-        singleton.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
-      }
+    if (cyptoService == null || !cyptoService.getClass().getName().equals(configuredClass))
{
+      CryptoService newCryptoService = loadCryptoService(configuredClass);
+      newCryptoService.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
+      singleton.compareAndSet(cyptoService, newCryptoService);
+      return singleton.get();
 
 Review comment:
   This still doesn't prevent concurrency issues though does it?  There is still the possibility
of a race condition where CryptoService.init() gets called twice.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message