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

Ensure that the reconcile queue tracks processing items #314

Merged
2 commits merged into from
May 24, 2023

Conversation

ghost
Copy link

@ghost ghost commented May 18, 2023

Description

This commit adds some new state and functions to the orchestration queue so that it keeps track of Dequeued items until that item is marked as Done by the person who Dequeued it.

This information is used to prevent items from being re-queued while the system is processing an item because the poller feeding the queue may pick up an item which is in the process of being updated.

This also makes it safe to have multiple reconciler threads being fed from a single queue because we have a guarentee that the same item isn't in the queue twice and therefore we can't end up with mutiple reconcilers trying to process the same item.

Type of Change

[ ] Bug Fix
[ ] New Feature
[ ] Breaking Change
[X] Refactor
[ ] Documentation
[ ] Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@ghost ghost self-requested a review as a code owner May 18, 2023 14:31
@FrimIdan
Copy link
Member

FrimIdan commented May 22, 2023

This information is used to prevent items from being re-queued while the system is processing an item because the poller feeding the queue may pick up an item which is in the process of being updated.

@sambetts-cisco Not sure I understand, why that an item that was de-queued will be re-queued?
Also, why we are not removing it from the inqueue once done is called? why we need both inqueue and processing?

@ghost
Copy link
Author

ghost commented May 23, 2023

@sambetts-cisco Not sure I understand, why that an item that was de-queued will be re-queued? Also, why we are not removing it from the inqueue once done is called? why we need both inqueue and processing?

The poller searching for items in specific states continues to run while the reconciler processes an item, which can result in the poller re-adding the item which is being processed to the end of the queue, because the queue doesn't know about this item any longer.

By keeping track of the items which are being processed we can avoid readding these items and avoid an extra reconcile when we have a single reconciler, if we enable parallel reconcilers for some objects then its required to avoid two reconcilers trying to reconcile the same item.

I original implemented this re-using the inqueue map, but that broke the behaviour I wanted for the "Has" function which is meant to check if something is in the queue, so I needed to maintain the list of processing items separately which is why I added the processing map.

@ghost ghost force-pushed the queue_item_acknowledge branch from a3aee54 to 3815727 Compare May 23, 2023 07:13
@FrimIdan
Copy link
Member

I original implemented this re-using the inqueue map, but that broke the behaviour I wanted for the "Has" function which is meant to check if something is in the queue, so I needed to maintain the list of processing items separately which is why I added the processing map.

Has returns true if items is currently in the queue

So the Has is for checking if the item is in the queue or in processing or both? From the code I see that it both in the queue and in processing so not sure, again, why we can't keep it in the queue until it was done processing.

@ghost
Copy link
Author

ghost commented May 23, 2023

So the Has is for checking if the item is in the queue or in processing or both? From the code I see that it both in the queue and in processing

Has is for checking if an item is in the queue itself, dequeued items would return false even though they continue to be processed.

Dequeue removes the item from "inqueue" https://github.com/openclarity/vmclarity/pull/314/files#diff-c8aea9db7e7fbce1cfcb5e8ca00dabd75079958e9fa3409f2bbc9e5093f70e1cL86 so an item is only ever in "inqueue" if its in the queue slice.

@FrimIdan
Copy link
Member

Has is for checking if an item is in the queue itself, dequeued items would return false even though they continue to be processed.

	_, inQueue := q.inqueue[item]
	_, isProcessing := q.processing[item]
	return inQueue || isProcessing

Maybe i'm missing something but if the item continue to be processed the Has will return true.

@ghost
Copy link
Author

ghost commented May 23, 2023

Maybe i'm missing something but if the item continue to be processed the Has will return true.

face plam I must have changed that at some point during development and now I don't remember why...

@ghost
Copy link
Author

ghost commented May 23, 2023

face plam I must have changed that at some point during development and now I don't remember why...

@FrimIdan I remembered why I track processing items separately! Its to prevent the inqueue map and q.queue's state getting out of sync.
If you use the same map to track the queue and the processing items, then its possible to call Done(item) removing it from inqueue even though its not been dequeued yet. So then Has(..) will return false even though the item is still in the queue slice. If Done operates only on a separate slice then it can't affect the Dequeue/Enqueue behaviour.

I'll add a comment.

This commit adds some new state and functions to the orchestration queue
so that it keeps track of Dequeued items until that item is marked as
Done by the person who Dequeued it.

This information is used to prevent items from being re-queued while the
system is processing an item because the poller feeding the queue may
pick up an item which is in the process of being updated.

This also makes it safe to have multiple reconciler threads being fed
from a single queue because we have a guarentee that the same item isn't
in the queue twice and therefore we can't end up with mutiple
reconcilers trying to process the same item.
@ghost ghost force-pushed the queue_item_acknowledge branch from 3815727 to 465be88 Compare May 23, 2023 15:13
FrimIdan
FrimIdan previously approved these changes May 24, 2023
This ensures that if there is an error during Dequeue that we don't try
to Done() the item that is returned as a result because it should not be
a real item in the queue and therefore could cause weird behaviour.
@ghost ghost added this pull request to the merge queue May 24, 2023
Merged via the queue into main with commit 3e45aa3 May 24, 2023
5 checks passed
@ghost ghost deleted the queue_item_acknowledge branch May 24, 2023 15:25
This pull request was closed.
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 this pull request may close these issues.

None yet

3 participants