You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2023/08/04 20:33:34 UTC

Change in asterixdb[neo]: [NO ISSUE][MISC] Minor refactoring of controller bootstrap

From Michael Blow <mb...@apache.org>:

Michael Blow has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17694 )


Change subject: [NO ISSUE][MISC] Minor refactoring of controller bootstrap
......................................................................

[NO ISSUE][MISC] Minor refactoring of controller bootstrap

Change-Id: I511fbbee5a3f49695451011e7b13afeb12e593a8
---
M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
3 files changed, 39 insertions(+), 16 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/94/17694/1

diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
index 3e2feb9..b815b68 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.Collection;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -444,6 +445,17 @@
         MetadataNode.INSTANCE.initialize(this, ncExtensionManager.getMetadataTupleTranslatorProvider(),
                 ncExtensionManager.getMetadataExtensions(), partitionId);
 
+        // This is a special case, we just give the metadataNode directly.
+        // This way we can delay the registration of the metadataNode until
+        // it is completely initialized.
+        MetadataManager.initialize(getAsterixStateProxies(), MetadataNode.INSTANCE);
+        MetadataBootstrap.startUniverse(getServiceContext(), newUniverse);
+        MetadataBootstrap.startDDLRecovery();
+        ncExtensionManager.initializeMetadata(getServiceContext());
+        LOGGER.info("Metadata node bound");
+    }
+
+    protected Collection<IAsterixStateProxy> getAsterixStateProxies() {
         //noinspection unchecked
         ConcurrentHashMap<CcId, IAsterixStateProxy> proxyMap =
                 (ConcurrentHashMap<CcId, IAsterixStateProxy>) getServiceContext().getDistributedState();
@@ -451,14 +463,7 @@
             throw new IllegalStateException("Metadata node cannot access distributed state");
         }
 
-        // This is a special case, we just give the metadataNode directly.
-        // This way we can delay the registration of the metadataNode until
-        // it is completely initialized.
-        MetadataManager.initialize(proxyMap.values(), MetadataNode.INSTANCE);
-        MetadataBootstrap.startUniverse(getServiceContext(), newUniverse);
-        MetadataBootstrap.startDDLRecovery();
-        ncExtensionManager.initializeMetadata(getServiceContext());
-        LOGGER.info("Metadata node bound");
+        return proxyMap.values();
     }
 
     @Override
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
index 2a66cfd..084334f 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
@@ -27,6 +27,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.Charset;
+import java.rmi.RemoteException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -120,7 +121,7 @@
 public class CCApplication extends BaseCCApplication {
 
     private static final Logger LOGGER = LogManager.getLogger();
-    private static IAsterixStateProxy proxy;
+    private IAsterixStateProxy proxy;
     protected CCExtensionManager ccExtensionManager;
     protected IStorageComponentProvider componentProvider;
     protected WebManager webManager;
@@ -166,8 +167,7 @@
         }
         MetadataProperties metadataProperties = appCtx.getMetadataProperties();
 
-        setAsterixStateProxy(AsterixStateProxy.registerRemoteObject(controllerService.getNetworkSecurityManager(),
-                metadataProperties.getMetadataCallbackPort()));
+        proxy = getAsterixStateProxy(controllerService, metadataProperties);
         ccServiceCtx.setDistributedState(proxy);
         MetadataManager.initialize(proxy, metadataProperties, appCtx);
         ccServiceCtx.addJobLifecycleListener(appCtx.getActiveNotificationHandler());
@@ -184,6 +184,12 @@
         jobCapacityController = new JobCapacityController(controllerService.getResourceManager());
     }
 
+    protected IAsterixStateProxy getAsterixStateProxy(ClusterControllerService controllerService,
+            MetadataProperties metadataProperties) throws RemoteException {
+        return AsterixStateProxy.registerRemoteObject(controllerService.getNetworkSecurityManager(),
+                metadataProperties.getMetadataCallbackPort());
+    }
+
     private Map<String, String> parseCredentialMap(String credPath) {
         File credentialFile = new File(credPath);
         Map<String, String> storedCredentials = new HashMap<>();
@@ -362,10 +368,6 @@
         ApplicationConfigurator.registerConfigOptions(configManager);
     }
 
-    public static synchronized void setAsterixStateProxy(IAsterixStateProxy proxy) {
-        CCApplication.proxy = proxy;
-    }
-
     @Override
     public ICcApplicationContext getApplicationContext() {
         return appCtx;
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
index f60349f..a223e0d 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
@@ -88,6 +88,7 @@
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.api.application.INCServiceContext;
 import org.apache.hyracks.api.application.IServiceContext;
 import org.apache.hyracks.api.client.NodeStatus;
 import org.apache.hyracks.api.config.IConfigManager;
@@ -154,7 +155,7 @@
         MetadataBuiltinFunctions.init();
 
         ncExtensionManager = new NCExtensionManager(new ArrayList<>(getExtensions()));
-        runtimeContext = new NCAppRuntimeContext(ncServiceCtx, ncExtensionManager, getPropertiesFactory());
+        runtimeContext = createNCApplicationContext(ncServiceCtx, ncExtensionManager, getPropertiesFactory());
         MetadataProperties metadataProperties = runtimeContext.getMetadataProperties();
         if (!metadataProperties.getNodeNames().contains(this.ncServiceCtx.getNodeId())) {
             if (LOGGER.isInfoEnabled()) {
@@ -186,6 +187,12 @@
         performLocalCleanUp();
     }
 
+    protected INcApplicationContext createNCApplicationContext(INCServiceContext ncServiceCtx,
+            NCExtensionManager ncExtensionManager, IPropertiesFactory propertiesFactory)
+            throws IOException, AsterixException {
+        return new NCAppRuntimeContext(ncServiceCtx, ncExtensionManager, propertiesFactory);
+    }
+
     protected IRecoveryManagerFactory getRecoveryManagerFactory() {
         return RecoveryManager::new;
     }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17694
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I511fbbee5a3f49695451011e7b13afeb12e593a8
Gerrit-Change-Number: 17694
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Blow <mb...@apache.org>
Gerrit-MessageType: newchange