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

remove &mut for regular operations (get) #15

Closed
joepio opened this issue Sep 18, 2020 · 2 comments
Closed

remove &mut for regular operations (get) #15

joepio opened this issue Sep 18, 2020 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@joepio
Copy link
Member

joepio commented Sep 18, 2020

When getting a resource from a store, the store might not have it locally, and will therefore try to fetch it by sending a request to its subject URL. When this happens, we want to store the newly fetched data to our store for caching. Because of this, any get command can also mutate the store. This is kind of not cool, because &mut references are exclusive. I'm kind of new to rust, but I believe this will prevent that multiple threads can do anything with this same store. This could cause latency spikes that will affect performance.

atomic_lib uses Sled, an embedded Rust key-value database, and it works entirely without mutable references. There must be something to learn here... Interesting video by the creator of sled touching this subject here.

@joepio joepio added the help wanted Extra attention is needed label Sep 22, 2020
@joepio joepio changed the title Locks while getting data remove &mut for getting data Sep 22, 2020
@joepio joepio changed the title remove &mut for getting data remove &mut for regular operations (get) Sep 22, 2020
@joepio
Copy link
Member Author

joepio commented Sep 24, 2020

Perhaps related - I want Resource instances to have some connection to a store, but how? I don't want my resource to have an exclusive reference. I'm assuming the answer has something to do with Arc and RwLock.

joepio added a commit that referenced this issue Sep 24, 2020
@joepio
Copy link
Member Author

joepio commented Sep 24, 2020

I think I've got this, but I'm still not sure whether this approach is the right one. Now, getting a resource requires a .lock()

@joepio joepio closed this as completed Sep 24, 2020
joepio added a commit that referenced this issue Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant