zyxxoo commented on code in PR #2151:
URL:
https://github.com/apache/incubator-hugegraph/pull/2151#discussion_r1130680354
##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java:
##########
@@ -19,26 +19,20 @@
public class GlobalMasterInfo {
- private boolean isMaster;
- private String url;
-
+ private volatile Info info;
private volatile boolean featureSupport;
public GlobalMasterInfo() {
this.featureSupport = false;
+ this.info = new Info(false, "");
}
- public synchronized void set(boolean isMaster, String url) {
- this.isMaster = isMaster;
- this.url = url;
- }
-
- public synchronized boolean isMaster() {
- return this.isMaster;
+ public void info(boolean isMaster, String url) {
+ this.info = new Info(isMaster, url);
Review Comment:
the case don't happend, because method parameter be bound;
when call 1 step, the isMaster and url parameter never be modify by external
logic, because the boolean is copy the origin data, and string is final;
this is a interesting question:
```
boolean isMaster = global.isMaster(); // 1
String url = global.url(); //2
this.info = new Info(isMaster, url); // 3
```
if the code run in more than one thread, the timing might look like this:
thread1: run 1 step; thread2: modify global.master; thread2: modify
global.url; thread1: run 2; this case will have some concurrency problem;
but in our case, only one thread modify global, so here is no problem
--
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]