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

make cachekv store thread-safe again #14376

Closed
Tracked by #14377
yihuang opened this issue Dec 21, 2022 · 0 comments · Fixed by #14378
Closed
Tracked by #14377

make cachekv store thread-safe again #14376

yihuang opened this issue Dec 21, 2022 · 0 comments · Fixed by #14378
Assignees

Comments

@yihuang
Copy link
Collaborator

yihuang commented Dec 21, 2022

In #13881 we identified and fixed a deadlock issue by removing a lock on btree which makes cachekv iterations not thread-safe anymore.
It'd be good if we can support the concurrent use cases again with simple solutions and don't add much overhead for non-concurrent use cases.
Previously there are two issues regarding thread-safty:

  • iterator need to hold the read lock of sorted cache, which blocks creation of new iterators which may need to insert new dirty items into the sorted cache.
  • iterator reference store.deleted directly without holding locks.

The first issue can be solved with copy-on-write feature of tidwall/btree, each iterator just make a isolated snapshot of the sorted cache, don't block the operations on the main one.
For the second issue, I don't understand the purpose of deleted field, we should check the nil value for deleted keys. But I think this change will be a behavior change and breaking.

yihuang added a commit to yihuang/cosmos-sdk that referenced this issue Dec 21, 2022
Closes: cosmos#14376

Solution:
- copy isolated sortedCache when starting iterating
- cleanup deletion logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant