javeme commented on code in PR #286:
URL:
https://github.com/apache/incubator-hugegraph-computer/pull/286#discussion_r1421435730
##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/master/MasterService.java:
##########
@@ -141,24 +140,36 @@ private void registerShutdownHook() {
}
/**
- * Stop the the master service. Stop the managers created in
- * {@link #init(Config)}.
+ * Stop the master service. Stop the managers created in {@link
#init(Config)}.
*/
@Override
public synchronized void close() {
- this.checkInited();
+ // TODO: check the logic of close carefully later
+ //this.checkInited();
if (this.closed) {
LOG.info("{} MasterService had closed before", this);
return;
}
- this.masterComputation.close(new DefaultMasterContext());
+ try {
+ if (this.masterComputation != null) {
+ this.masterComputation.close(new DefaultMasterContext());
+ }
+ } catch (Exception e) {
+ LOG.error("Error occurred while closing masterComputation", e);
Review Comment:
masterComputation => master service
##########
checkstyle.xml:
##########
@@ -35,7 +35,7 @@
<module name="TreeWalker">
<!--检查行长度-->
<module name="LineLength">
- <property name="max" value="100"/>
+ <property name="max" value="105"/>
Review Comment:
prefer don't break the rule
##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/worker/WorkerService.java:
##########
@@ -152,29 +160,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();
if (this.closed) {
LOG.info("{} WorkerService had closed before", this);
return;
}
- this.computeManager.close();
+ try {
+ this.computeManager.close();
+ } catch (Exception e) {
+ LOG.error("Error when closing computeManager", e);
Review Comment:
computeManager => ComputeManager
##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/worker/WorkerService.java:
##########
@@ -152,29 +160,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();
if (this.closed) {
LOG.info("{} WorkerService had closed before", this);
return;
}
- this.computeManager.close();
+ try {
+ this.computeManager.close();
Review Comment:
`return if computeManager is null` since checkInited is removed
##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/worker/WorkerService.java:
##########
@@ -91,57 +89,67 @@ 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) {
Review Comment:
don't need to try-catch and just log here
--
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]