Skip to content

SeekableStreamSupervisor: Don't enqueue duplicate notices. - #13334

Merged
gianm merged 4 commits into
apache:masterfrom
gianm:sss-noticesqueue
Nov 11, 2022
Merged

gianm merged 4 commits into
apache:masterfrom
gianm:sss-noticesqueue

Conversation

@gianm

@gianm gianm commented Nov 9, 2022 •

Copy link
Copy Markdown
Contributor

Similar goal to #12018, but more aggressive. Don't enqueue a notice at all if it is equal to one currently in the queue. (The prior patch #12018 only considered the head of the queue, not the entire queue.)

Similar goal to apache#12018, but more aggressive. Don't enqueue a notice at
all if it is equal to one currently in the queue.

@kfaraz kfaraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions, otherwise looks good.

public boolean equals(Object obj)
{
// All RunNotices are the same. They are de-duplicated on insertion into the NoticesQueue "notices".
return obj != null && obj.getClass().equals(RunNotice.class);

@kfaraz kfaraz Nov 9, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Since the RunNotice has no state, I wonder if we shouldn't just have a singleton like so:
static final RunNotice RUN_NOTICE = new RunNotice() and just use that wherever needed addNotice(RUN_NOTICE).

It would also help clean up the time-based condition in handle, in that the lastRunTime can now be a field in RunNotice rather than in the Supervisor. Maybe this condition is not even needed now since we are already doing aggressive deduplication in the queue itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a singleton makes sense, I can add that tomorrow when fixing the build issues.

However then lastRunTime couldn't be a field in RunNotice, since if RunNotice is a singleton, it's a singleton across all supervisors for all datasources. I'll look into whether it's still needed at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nevermind, it can't be static singleton since it accesses state of the outer class. I'll just leave it the way it is. I'm not sure if we still need the lastRunTime, so I'll leave that too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course, we still need to call the actual runInternal 😅


public T poll(final long timeoutMillis) throws InterruptedException
{
synchronized (this) {

@kfaraz kfaraz Nov 9, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Is this preferred over marking the method itself synchronized? Synchronizing the method would have the added benefit of letting callers know that it is a safe method.

@gianm gianm Nov 10, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think either one is fine. I tend to prefer synchronized (this) in code that I write, but not for any important reason.

@kfaraz

kfaraz commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

Build failing because LGTM doesn't like LinkedList 😛

public class NoticesQueue<T>
{
@GuardedBy("this")
private final LinkedList<T> queue = new LinkedList<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want a high-performance queue, we could also consider using LinkedHashSet to combine both queue and set. remove would use the iterator to remove first element. limiting size can be handled by us if needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try this out.

@gianm

gianm commented Nov 10, 2022

Copy link
Copy Markdown
Contributor Author

Build failing because LGTM doesn't like LinkedList 😛

Doh. I'll look into this tomorrow.

…ord/supervisor/NoticesQueueTest.java

Co-authored-by: Kashif Faraz <kashif.faraz@gmail.com>

@rohangarg rohangarg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gianm
gianm merged commit e78f648 into apache:master Nov 11, 2022
@gianm
gianm deleted the sss-noticesqueue branch November 11, 2022 09:54
@gianm gianm added this to the 25.0 milestone Nov 21, 2022
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
)

* SeekableStreamSupervisor: Don't enqueue duplicate notices.

Similar goal to apache#12018, but more aggressive. Don't enqueue a notice at
all if it is equal to one currently in the queue.

* Adjustments from review.

* Update indexing-service/src/test/java/org/apache/druid/indexing/overlord/supervisor/NoticesQueueTest.java

Co-authored-by: Kashif Faraz <kashif.faraz@gmail.com>

Co-authored-by: Kashif Faraz <kashif.faraz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants