coderzc commented on code in PR #286:
URL: 
https://github.com/apache/incubator-hugegraph-computer/pull/286#discussion_r1418808134


##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/worker/WorkerService.java:
##########
@@ -91,57 +89,68 @@ public WorkerService() {
     /**
      * Init worker service, create the managers used by worker service.
      */
-    public void init(Config config) {
-        E.checkArgument(!this.inited, "The %s has been initialized", this);
-
-        this.serviceThread = Thread.currentThread();
-        this.registerShutdownHook();
-
-        this.config = config;
-
-        this.workerInfo = new ContainerInfo();
-        LOG.info("{} Start to initialize worker", this);
-
-        this.bsp4Worker = new Bsp4Worker(this.config, this.workerInfo);
+    public synchronized void init(Config config) {
+        try {
+            LOG.info("{} Prepare to init WorkerService", this);
+            // TODO: what will happen if init() called by multiple threads?
+            E.checkArgument(!this.inited, "The %s has been initialized", this);
 
-        /*
-         * Keep the waitMasterInitDone() called before initManagers(),
-         * in order to ensure master init() before worker managers init()
-         */
-        this.masterInfo = this.bsp4Worker.waitMasterInitDone();
+            this.serviceThread = Thread.currentThread();
+            this.registerShutdownHook();
+            this.config = config;
+            this.workerInfo = new ContainerInfo();
 
-        InetSocketAddress address = this.initManagers(this.masterInfo);
-        this.workerInfo.updateAddress(address);
+            LOG.info("{} Start to initialize worker", this);
+            this.bsp4Worker = new Bsp4Worker(this.config, this.workerInfo);
+            /*
+             * Keep the waitMasterInitDone() called before initManagers(),
+             * in order to ensure master init() before worker managers init()
+             */
+            ContainerInfo masterInfo = this.bsp4Worker.waitMasterInitDone();
+            InetSocketAddress address = this.initManagers(masterInfo);
+            this.workerInfo.updateAddress(address);
+            this.loadComputation();
+
+            LOG.info("{} register WorkerService", this);
+            this.bsp4Worker.workerInitDone();
+            this.connectToWorkers();
+
+            this.computeManager = new ComputeManager(this.workerInfo.id(), 
this.context,
+                                                     this.managers);
+
+            this.managers.initedAll(this.config);
+            LOG.info("{} WorkerService initialized", this);
+            this.inited = true;
+        } catch (Exception e) {
+            LOG.error("Error while initializing WorkerService", e);
+            // TODO: shall we call close() here?
+            this.close();

Review Comment:
   There should be no need to call close, we registered the shutdown hook.



##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/worker/WorkerService.java:
##########
@@ -152,29 +161,45 @@ private void registerShutdownHook() {
     }
 
     /**
-     * Stop the worker service. Stop the managers created in
-     * {@link #init(Config)}.
+     * Stop the worker service. Stop the managers created in {@link 
#init(Config)}.
      */
     @Override
     public synchronized void close() {
-        this.checkInited();
+        // TODO: why checkInited() here, if init throws exception, how to 
close the resource?
+        //this.checkInited();

Review Comment:
   Make sense, also remove `this.checkInited()` on MasterService.close();



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to