Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Schema Cache expandCapacity concurrent issue #2330

Closed
1 task done
qwtsc opened this issue Oct 20, 2023 · 4 comments · Fixed by #2332
Closed
1 task done

[Bug] Schema Cache expandCapacity concurrent issue #2330

qwtsc opened this issue Oct 20, 2023 · 4 comments · Fixed by #2332
Assignees
Labels
bug Something isn't working

Comments

@qwtsc
Copy link
Contributor

qwtsc commented Oct 20, 2023

Bug Type (问题类型)

other exception / error (其他异常报错)

Before submit

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

Environment (环境信息)

see the following error-log

org.apache.hugegraph.exception.ServerException: Index 32 out of bounds for length 32

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

    public void set(int key, V value) {
        if (key >= this.currentSize) {
            this.expandCapacity();
        }
        // this.array is not the one that has done expandCapacity!
        this.array[key] = value;
    }

    private synchronized void expandCapacity() {
        if (this.currentSize == this.maxSize) {
            return;
        }
        this.currentSize = Math.min(this.currentSize * 2, this.maxSize);
        Object[] newArray = new Object[this.currentSize];
        System.arraycopy(this.array, 0, newArray, 0, this.array.length);
        this.clear();
        this.array = newArray;
    }

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

No response

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

No response

@qwtsc qwtsc added the bug Something isn't working label Oct 20, 2023
@qwtsc
Copy link
Contributor Author

qwtsc commented Oct 20, 2023

some advice

  1. use volatile
  2. In expandCapacity, write this.currentSize field after write this.array, or just use this.array.length to replace this.currentSize
  3. it's ok to simply use concurrentHashMap to replace this data structure.

@imbajin
Copy link
Member

imbajin commented Oct 20, 2023

Thanks, could submit a PR including related test for it

@conghuhu free to take a look with it~

@conghuhu
Copy link
Contributor

ok, plz assign to me

@imbajin
Copy link
Member

imbajin commented Nov 12, 2023

follow-up: #2332 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants