ivankelly commented on a change in pull request #1192: BP-29 (task 3): use 
metadata service uri for constructing registration client
URL: https://github.com/apache/bookkeeper/pull/1192#discussion_r170919448
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
 ##########
 @@ -167,17 +167,28 @@ private static void loadInitialBookieDrivers() {
      */
     public static void registerClientDriver(String metadataBackendScheme,
                                             Class<? extends 
MetadataClientDriver> driver) {
+        registerClientDriver(metadataBackendScheme, driver, false);
+    }
+
+    @VisibleForTesting
+    public static void registerClientDriver(String metadataBackendScheme,
+                                            Class<? extends 
MetadataClientDriver> driver,
+                                            boolean allowOverride) {
         if (!initialized) {
             initialize();
         }
 
         String scheme = metadataBackendScheme.toLowerCase();
         MetadataClientDriverInfo oldDriverInfo = clientDrivers.get(scheme);
-        if (null != oldDriverInfo) {
+        if (null != oldDriverInfo && !allowOverride) {
             return;
         }
         MetadataClientDriverInfo newDriverInfo = new 
MetadataClientDriverInfo(driver);
-        oldDriverInfo = clientDrivers.putIfAbsent(scheme, newDriverInfo);
+        if (allowOverride) {
 
 Review comment:
   My problem with this is that allowOverride is brought into the default flow 
of the method. It's even the first branch from the if on L183. It means 
multiple returns from the method. Logging only occurs if there is a race. The 
existence in the map is checked twice. And what should be the non-default path 
is intertwined with the default.
   None of these are huge in themselves, but they combine to make me dislike 
the current flow a lot. Another alternative, which would be a least deal with 
some of the intertwining...
   ```
   MetadataClientDriverInfo oldDriverInfo = clientDrivers.get(scheme);
   if (null != oldDriverInfo && !allowOverride) {
       return;
   }
   MetadataClientDriverInfo newDriverInfo = new 
MetadataClientDriverInfo(driver);
   oldDriverInfo = clientDrivers.putIfAbsent(scheme, newDriverInfo);
   if (null != oldDriverInfo) {
       log.debug("Metadata client driver for {} is already there.", scheme);
       if (allowOverride) {
           log.debug("Overriding client driver for {}", scheme);
           clientDrivers.put(scheme, newDriverInfo);
       }
   }
   ```
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to