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

Add NioGroup for use in different transports #27737

Merged
merged 14 commits into from
Dec 15, 2017

Conversation

Tim-Brooks
Copy link
Contributor

This commit is related to #27260. It adds a base NioGroup for use in
different transports. This class creates and starts the underlying
selectors. Different protocols or transports are established by passing
the ChannelFactory to the bindServerChannel or openChannel
methods. This allows a TcpChannelFactory to be passed which will
create and register channels that support the elasticsearch tcp binary
protocol or a channel factory that will create http channels (or other).

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

I left some comments

private void shutdownSelector(ESSelector selector) {
try {
selector.close();
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it might make sense to deduplicate this exception otherwise we might spam logs?

}

startSelectors(socketSelectors, socketSelectorThreadFactory);

Copy link
Contributor

Choose a reason for hiding this comment

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

extra newlines

private final ThreadFactory socketSelectorThreadFactory;
private final ArrayList<SocketSelector> socketSelectors;
private final Function<Logger, SocketEventHandler> socketEventHandlerFunction;
private RoundRobinSupplier<SocketSelector> socketSelectorSupplier;
Copy link
Contributor

Choose a reason for hiding this comment

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

can be final?

private final ThreadFactory acceptorThreadFactory;
private final ArrayList<AcceptingSelector> acceptors;
private final BiFunction<Logger, Supplier<SocketSelector>, AcceptorEventHandler> acceptorEventHandlerFunction;
private RoundRobinSupplier<AcceptingSelector> acceptorSupplier;
Copy link
Contributor

Choose a reason for hiding this comment

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

can be final?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think they can be final in the current design. Creating a Selector can throw an exception which is why I do it in start().

I guess the options are:

  1. I could make them volatile
  2. I could throw IOException from the ctor. Although with handling exceptions and closing in the ctor.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am leaning towards 2. it's much cleaner

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

Copy link
Contributor

Choose a reason for hiding this comment

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

can you summarize what this does?

socketSelectors.clear();
}

private static <S extends ESSelector> void startSelectors(Iterable<S> selectors, ThreadFactory threadFactory) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we fail to start do we close the started ones

@Tim-Brooks
Copy link
Contributor Author

@s1monw - based on your comment about making the suppliers final, I decided to put in some work relating to ensuring that the state of the NioGroup is consistent between start and close. With those changes, this is ready for another review.

@Tim-Brooks Tim-Brooks requested a review from s1monw December 13, 2017 16:20
socketSelectors = new ArrayList<>(this.socketSelectorCount);
}

public synchronized void start() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we can prevent this kind of state handling we should. My experience with stuff like this is consistently negative so lets try to move it to the ctor and make it clear once the group is created it's ready to use. I still think we should have an ensureOpen() method that checks a boolean if we are still open.

@Tim-Brooks Tim-Brooks requested a review from s1monw December 14, 2017 17:34
Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

LGTM

ensureRunning();
if (acceptorCount == 0) {
ensureOpen();
if (acceptors.size() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe us isEmpty()?

@Tim-Brooks Tim-Brooks merged commit 916e7db into elastic:master Dec 15, 2017
Tim-Brooks added a commit that referenced this pull request Dec 15, 2017
This commit is related to #27260. It adds a base NioGroup for use in
different transports. This class creates and starts the underlying
selectors. Different protocols or transports are established by passing
the ChannelFactory to the bindServerChannel or openChannel
methods. This allows a TcpChannelFactory to be passed which will
create and register channels that support the elasticsearch tcp binary
protocol or a channel factory that will create http channels (or other).
martijnvg added a commit that referenced this pull request Dec 18, 2017
* es/6.x: (170 commits)
  Allow TrimFilter to be used in custom normalizers (#27758)
  recovery from snapshot should fill gaps (#27850)
  Remove unused class PreBuiltTokenFilters (#27839)
  Reject scroll query if size is 0 (#22552) (#27842)
  Mutes ‘Rollover no condition matched’ YAML test
  Make randomNonNegativeLong() draw from a uniform distribution (#27856)
  Adapt rest test after backport. Relates #27833
  Handle case where the hole vertex is south of the containing polygon(s) (#27685)
  Move range field mapper back to core
  Fix publication of elasticsearch-cli to Maven
  Do not use system properties when building the HttpAsyncClient (#27829)
  Optimize version map for append-only indexing (#27752)
  Add NioGroup for use in different transports (#27737)
  adapt field collapsing skip test version. relates #27833
  Add version support for inner hits in field collapsing (#27822) (#27833)
  Clarify that number of threads is set by packages
  Register HTTP read timeout setting
  Fixes Checkstyle
  Remove `operationThreaded` from Java API (#27836)
  Fixes failing BytesSizeValues tests
  ...
@Tim-Brooks Tim-Brooks deleted the nio_machine_updated branch December 10, 2018 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants