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

Aggregate operations into a single work request #2

Open
spekulant opened this issue Aug 17, 2022 · 0 comments
Open

Aggregate operations into a single work request #2

spekulant opened this issue Aug 17, 2022 · 0 comments

Comments

@spekulant
Copy link
Member

At the moment, we run 3 queues

save   chan ItemRequest
fetch  chan Request
delete chan Request
func (s *KVStore) loop() {
	for {
		select {
		case setRequest := <-s.save:
			// set process
		case getRequest := <-s.fetch:
			// get process
		case delRequest := <-s.delete:
			// del process
                }
        }
}

This leads to a situation where save has bigger priority than fetch and might behave unexpectedly in corner case scenarios.

In order to further strengthen thread safety, it would be good to run a select loop on a single channel like a work unit.

func (s *KVStore) loop() {
	for {
		select {
		case request := <-s.operations:
			// unified process
                }
        }
}

Shape of the Request in operations chan Request is yet to be decided as mistakes here might lead to type safety issues. Obviously we dont want to trade thread safety for type safety.

Issue open for thoughts

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

No branches or pull requests

1 participant