Skip to content

Deliver RemoteSplit exactly once#13978

Merged
arhimondr merged 5 commits intotrinodb:masterfrom
arhimondr:remote-split-deliver-once
Sep 9, 2022
Merged

Deliver RemoteSplit exactly once#13978
arhimondr merged 5 commits intotrinodb:masterfrom
arhimondr:remote-split-deliver-once

Conversation

@arhimondr
Copy link
Copy Markdown
Contributor

Description

Currently a single RemoteSplit is delivered multiple times (once per ExchangeOperator instance). The deduplication is done at the DirectExchangeClient level. While it is easy to de-duplicate based on the URI, it is not as straightforward when it comes to spooling exhange. Currently there is a guarantee of an excacly one RemoteSplit per exchange when SpoolingExchange is used, however this is about to be changed (see #13968), thus this change is required.

Is this change a fix, improvement, new feature, refactoring, or other?

Refactor

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

Core engine

How would you describe this change to a non-technical end user or system administrator?

N/A

Related issues, pull requests, and links

#13968

Documentation

(X) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

(X) No release notes entries required.
( ) Release notes entries required with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Sep 2, 2022
@arhimondr
Copy link
Copy Markdown
Contributor Author

Still WIP

@arhimondr arhimondr force-pushed the remote-split-deliver-once branch from a136377 to 3043dd9 Compare September 6, 2022 15:15
@arhimondr arhimondr changed the title [WIP] Deliver RemoteSplit exactly once Deliver RemoteSplit exactly once Sep 6, 2022
@arhimondr
Copy link
Copy Markdown
Contributor Author

Ready for review

@arhimondr arhimondr force-pushed the remote-split-deliver-once branch from 3043dd9 to 1bda8ee Compare September 6, 2022 21:31
@arhimondr arhimondr requested a review from dain September 6, 2022 22:08
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.

verify(this.noMoreSplits.compareAndSet(false, noMoreSplits), "noMoreSplits already set");?

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 believe the noMoreSplits signal may be potentially sent more then once by coordinator. Not sure if we need to be restrictive here as it doesn't impact correctness.

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.

Yeah - actually what I had in mind (which verify which I suggested does not do) was to check if we are not switching from this.noMoreSplits==true to this.noMoreSplits==false.

Maybe just verify(!this.noMoreSplits || noMoreSplits, "cannot unset noMoreSplits")

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.

Yeah, that makes sense. Let me add a check.

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.

remove reference from the queue?

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.

This is a CopyOnWriteArrayList. The iterator doesn't support remove. Removing it from the original list is possible, but it will make it harder to reason about (what is already quite difficult to be honest). The WeakReference objects are relatively lightweight, not sure if the saved memory is worth the extra complexity.

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.

else remove reference from the queue?

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.

ditto

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.

I think this is not accurate or I am not reading it correctly.
It is possible to have QueryOutputInfo with noMoreInputs==true and still non-empty inputsQueue, right?
As I read the comment it feels that it says it should not happen.

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.

Good catch. Basically what I was trying to say that once noMoreInputs the queue inside should't contain any new splits in any subsequent calls. Let me try to rephrase.

Copy link
Copy Markdown
Member

@losipiuk losipiuk Sep 7, 2022

Choose a reason for hiding this comment

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

maybe add:

// inputsQueue is shared between `QueryOutputInfo` instances. 
// It is guaranteed that no new entries will be added to `inputsQueue` after `QueryOutputInfo` with `noMoreInputs==true` is created.

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.

Updated QueryOutputInfo java doc

@arhimondr arhimondr force-pushed the remote-split-deliver-once branch from 265f6ae to faaa851 Compare September 7, 2022 17:40
@arhimondr
Copy link
Copy Markdown
Contributor Author

Updated

@arhimondr arhimondr force-pushed the remote-split-deliver-once branch from faaa851 to f378567 Compare September 7, 2022 18:55
Copy link
Copy Markdown
Member

@linzebing linzebing left a comment

Choose a reason for hiding this comment

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

I don't have enough domain knowledge to verify the correctness of this PR so I hope we have people familiar with these files to take a look as well.

@arhimondr arhimondr force-pushed the remote-split-deliver-once branch from f378567 to 648711d Compare September 8, 2022 16:45
@arhimondr
Copy link
Copy Markdown
Contributor Author

@losipiuk Updated

Call ExchangeDataSource#noMoreInputs only after all ExchangeOperator's
have been created and have received noMoreSplits from the engine
To further allow releasing query inputs as they are being consumed
In addition to that make sure the inputs are not retained in memory
longer than necessary. While it is unlikely that the number of inputs
will be large with pipelined execution it may no longer be true with
fault tolerant execution.
@arhimondr arhimondr force-pushed the remote-split-deliver-once branch from 648711d to e64026e Compare September 9, 2022 15:05
@arhimondr arhimondr merged commit 622f843 into trinodb:master Sep 9, 2022
@arhimondr arhimondr deleted the remote-split-deliver-once branch September 9, 2022 18:58
@github-actions github-actions bot added this to the 396 milestone Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants