Skip to content

[Bug] PD PartitionCache lockGraph method opposite to the expected behavior. #2639

Closed

Description

@haohao0103

Bug Type (问题类型)

logic (逻辑设计问题)

Before submit

  • 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.5.0 (Apache Release Version)
  • Backend: HStore

Expected & Actual behavior (期望与实际表现)

PartitionCache->lockGraph()

while (lock.compareAndSet(false, true)) {
            Thread.onSpinWait();
        }

the while condition (lock. compareAndSet (false, true)) will enter the loop when compactAndSet succeeds, which is opposite to the expected behavior.

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

Activity

  1. dosubot commented on Aug 14, 2024

    @dosubot

    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:

    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 [1].

    To continue talking to Dosu, mention @dosu.

  2. added a commit that references this issue on Aug 14, 2024
    6148c6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions