bitflicker64 commented on code in PR #3368:
URL: https://github.com/apache/hugegraph/pull/3368#discussion_r4302704419


##########
hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/meta/IdMetaStore.java:
##########
@@ -145,7 +187,7 @@ public long getCId(String key, String name, long max) 
throws PDException {
             byte[] value = getOne(cidDelayKey);
             if (value != null) {
                 // Remove from delayed deletion queue
-                remove(cidDelayKey);
+                getStore().remove(cidDelayKey, term);
                 return ((long[]) deserialize(value))[0];
             } else {
                 return getCId(key, max);

Review Comment:
   Minor: With no delayed slot for `name`, this calls the public `getCId(key, 
max)`, which runs its own `inLeaderTerm`: a second ReadIndex wait and a new 
term, while this thread still holds `synchronized (this)`. Every allocation by 
name waits on two barriers, and when leadership changes repeatedly the inner 
loop's 3 attempts run inside each of the outer loop's 3, so up to 9 attempts. 
The outer term's ReadIndex already covers the counter and slot reads, because 
this leader applies its own writes before `put` returns and no other leader can 
write in the same term. Could this call the private overload with the outer 
term instead?
   
   ```java
   return allocateCId(key, max, term);
   ```
   
   It takes the same per-key lock the nested call took, and its writes are then 
checked against the same term as the delayed-slot read and the cleanup above.



-- 
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