dosubot[bot] commented on issue #2639:
URL:
https://github.com/apache/incubator-hugegraph/issues/2639#issuecomment-2287759825
<!-- Answer -->
To fix the logic design issue in the `lockGraph` method of the
`PartitionCache` class, you need to change the condition in the `while` loop.
The `compareAndSet` method returns `true` if it successfully sets the value,
meaning the lock was acquired, so the loop should exit. The correct condition
should be `!lock.compareAndSet(false, true)`.
Here is the corrected `lockGraph` method:
```java
public void lockGraph(String graphName) {
var lock = getOrCreateGraphLock(graphName);
while (!lock.compareAndSet(false, true)) {
Thread.onSpinWait();
}
}
```
This change ensures that the loop will continue spinning only if the
`compareAndSet` method fails to acquire the lock
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionCache.java)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
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]