imbajin commented on code in PR #3157:
URL: https://github.com/apache/hugegraph/pull/3157#discussion_r4040989183


##########
hugegraph-struct/src/main/java/org/apache/hugegraph/SchemaDriver.java:
##########
@@ -98,24 +117,75 @@ public static void init(PDConfig pdConfig) {
     }
 
     public static void init(PDConfig pdConfig, int cacheSize, long expiration) 
{
-        SchemaDriver instance = INSTANCE.get();
-        if (instance != null) {
-            throw new NotAllowException(
-                    "The SchemaDriver [cacheSize=%s, expiration=%s, " +
-                    "client=%s] has already been initialized and is not " +
-                    "allowed to be initialized again", instance.caches.limit(),
-                    instance.caches.expiration(), instance.client);
+        synchronized (LIFECYCLE_LOCK) {
+            if (destroying) {
+                throw new NotAllowException("The SchemaDriver is being 
destroyed");

Review Comment:
   The destroy-window rejection is real and explicitly tested. However, 
concurrent graph creation during global driver destruction has no established 
supported contract or production destroy caller in this repository; the 
getInstance() re-read/null race also exists on the base. Keeping this as a 
lifecycle-contract discussion: adding getOrInit or waiting/retry semantics 
needs a maintainer decision and should not be folded into watch recovery 
without one.



##########
hugegraph-struct/src/main/java/org/apache/hugegraph/SchemaDriver.java:
##########
@@ -98,24 +117,75 @@ public static void init(PDConfig pdConfig) {
     }
 
     public static void init(PDConfig pdConfig, int cacheSize, long expiration) 
{
-        SchemaDriver instance = INSTANCE.get();
-        if (instance != null) {
-            throw new NotAllowException(
-                    "The SchemaDriver [cacheSize=%s, expiration=%s, " +
-                    "client=%s] has already been initialized and is not " +
-                    "allowed to be initialized again", instance.caches.limit(),
-                    instance.caches.expiration(), instance.client);
+        synchronized (LIFECYCLE_LOCK) {
+            if (destroying) {
+                throw new NotAllowException("The SchemaDriver is being 
destroyed");
+            }
+            SchemaDriver instance = INSTANCE.get();
+            if (instance != null) {
+                throw new NotAllowException(
+                        "The SchemaDriver [cacheSize=%s, expiration=%s, " +
+                        "client=%s] has already been initialized and is not " +
+                        "allowed to be initialized again", 
instance.caches.limit(),
+                        instance.caches.expiration(), instance.client);
+            }
+            INSTANCE.set(new SchemaDriver(pdConfig, cacheSize, expiration));

Review Comment:
   Construction does hold the lifecycle lock. With unreachable PD, though, the 
first synchronous registration failure aborts the constructor, so four failed 
registrations / ~20 s is not the actual path. Serialization prevents 
publication during teardown; replacing it with an initializing/cancellation 
protocol changes lifecycle semantics. With no production destroy caller in this 
repository, I am retaining this as a design discussion rather than making that 
broader change 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]

Reply via email to