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

Decouple nio constructs from the tcp transport #27484

Merged
merged 9 commits into from
Nov 22, 2017

Conversation

Tim-Brooks
Copy link
Contributor

This is related to #27260. Currently, basic nio constructs (nio
channels, the channel factories, selector event handlers, etc) implement
logic that is specific to the tcp transport. For example, NioChannel
implements the TcpChannel interface. These nio constructs at some point
will also need to support other protocols (ex: http).

This commit separates the TcpTransport logic from the nio building
blocks.

@Tim-Brooks
Copy link
Contributor Author

This will also go on the 6.x branch. But there is not yet a tag for 6.2.

@Tim-Brooks Tim-Brooks changed the title Decouple Nio constructs from the tcp transport Decouple nio constructs from the tcp transport Nov 21, 2017
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.

lefts some minors LGTM mostly

@@ -79,8 +71,8 @@ void acceptChannel(NioServerSocketChannel nioServerChannel) throws IOException {
ChannelFactory channelFactory = nioServerChannel.getChannelFactory();
SocketSelector selector = selectorSupplier.get();
NioSocketChannel nioSocketChannel = channelFactory.acceptNioChannel(nioServerChannel, selector);
openChannels.acceptedChannelOpened(nioSocketChannel);
acceptedChannelCallback.accept(nioSocketChannel);
// openChannels.acceptedChannelOpened(nioSocketChannel);
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover?

private void acceptChannel(NioSocketChannel channel) {
TcpNioSocketChannel tcpChannel = (TcpNioSocketChannel) channel;
openChannels.acceptedChannelOpened(tcpChannel);
tcpChannel.addCloseListener(new RemoveClosedChannelListener(channel));
Copy link
Contributor

Choose a reason for hiding this comment

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

rather use ActionListener.wrap(v -> openChannels.channelClosed(channel), e -> openChannels.channelClosed(channel)) then we don't need to define this extra class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. And better than that, I can used the Runnable version ActionListener.wrap(() -> openChannels.channelClosed(channel))

@@ -34,76 +32,86 @@
import java.nio.channels.SocketChannel;
import java.util.function.Consumer;

public class ChannelFactory {
public abstract class ChannelFactory<SS extends NioServerSocketChannel, S extends NioSocketChannel> {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use different generics s/SS/ServerSocket/ s/S/Socket please?

*/
public abstract SS createServerChannel(AcceptingSelector selector, ServerSocketChannel channel) throws IOException;

private S createChannel0(SocketSelector selector, SocketChannel rawChannel) 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.

we usually call it internalCreateChannel instead of using a number

@@ -43,4 +45,6 @@
SelectionKey getSelectionKey();

NetworkChannel getRawChannel();

void addCloseListener(ActionListener<Void> listener);
Copy link
Contributor

Choose a reason for hiding this comment

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

javadocs please :)

@@ -39,6 +39,7 @@
private final SocketSelector socketSelector;
private WriteContext writeContext;
private ReadContext readContext;
private BiConsumer<NioSocketChannel, Exception> exceptionHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we ensure that this is only set once?

import java.nio.channels.SocketChannel;
import java.util.function.Consumer;

public class TcpChannelFactory extends ChannelFactory<TcpNioServerSocketChannel, TcpNioSocketChannel> {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be pkg private? and can we have javadocs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It cannot be package private as it is instantiated in a NioTransport which is in a different package. I think at some point I will rework the packages and it can eventually be package private. But that is a different PR.

this.serverContextSetter = serverContextSetter;
}

public TcpNioSocketChannel createChannel(SocketSelector selector, SocketChannel channel) 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.

@Override?

import java.io.IOException;
import java.nio.channels.ServerSocketChannel;

public class TcpNioServerSocketChannel extends NioServerSocketChannel implements TcpChannel {
Copy link
Contributor

Choose a reason for hiding this comment

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

javadocs?


@Override
public void setSoLinger(int value) throws IOException {
if (isOpen()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be protected to be not concurrently closed?

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'm not sure there is a clear way to do that. If it is closed, it just throws an IOException. And we handle / log that. Additionally, this only occurs at transport shutdown (as setting SO_LINGER is mainly to avoid running out of ports during the build).

@Tim-Brooks Tim-Brooks merged commit ef34555 into elastic:master Nov 22, 2017
Tim-Brooks added a commit that referenced this pull request Nov 22, 2017
This is related to #27260. Currently, basic nio constructs (nio
channels, the channel factories, selector event handlers, etc) implement
logic that is specific to the tcp transport. For example, NioChannel
implements the TcpChannel interface. These nio constructs at some point
will also need to support other protocols (ex: http).

This commit separates the TcpTransport logic from the nio building
blocks.
martijnvg added a commit that referenced this pull request Nov 24, 2017
* es/master: (38 commits)
  Backport wait_for_initialiazing_shards to cluster health API
  Carry over version map size to prevent excessive resizing (#27516)
  Fix scroll query with a sort that is a prefix of the index sort (#27498)
  Delete shard store files before restoring a snapshot (#27476)
  Replace `delimited_payload_filter` by `delimited_payload` (#26625)
  CURRENT should not be a -SNAPSHOT version if build.snapshot is false (#27512)
  Fix merging of _meta field (#27352)
  Remove unused method (#27508)
  unmuted test, this has been fixed by #27397
  Consolidate version numbering semantics (#27397)
  Add wait_for_no_initializing_shards to cluster health API (#27489)
  [TEST] use routing partition size based on the max routing shards of the second split
  Adjust CombinedDeletionPolicy for multiple commits (#27456)
  Update composite-aggregation.asciidoc
  Deprecate `levenstein` in favor of `levenshtein` (#27409)
  Automatically prepare indices for splitting (#27451)
  Validate `op_type` for `_create` (#27483)
  Minor ShapeBuilder cleanup
  muted test
  Decouple nio constructs from the tcp transport (#27484)
  ...
martijnvg added a commit that referenced this pull request Nov 24, 2017
* es/6.x: (30 commits)
  Add wait_for_no_initializing_shards to cluster health API (#27489)
  Carry over version map size to prevent excessive resizing (#27516)
  Fix scroll query with a sort that is a prefix of the index sort (#27498)
  Delete shard store files before restoring a snapshot (#27476)
  CURRENT should not be a -SNAPSHOT version if build.snapshot is false (#27512)
  Fix merging of _meta field (#27352)
  test: do not run percolator query builder bwc test against 5.x versions
  Remove unused method (#27508)
  Consolidate version numbering semantics (#27397)
  Adjust CombinedDeletionPolicy for multiple commits (#27456)
  Minor ShapeBuilder cleanup
  [GEO] Deprecate ShapeBuilders and decouple geojson parse logic
  Improve docs for split API in 6.1/6.x (#27504)
  test: use correct pre 6.0.0-alpha1 format
  Update composite-aggregation.asciidoc
  Deprecate `levenstein` in favor of `levenshtein` (#27409)
  Decouple nio constructs from the tcp transport (#27484)
  Bump version from 6.1 to 6.2
  Fix whitespace in Security.java
  Tighten which classes can exit
  ...
@Tim-Brooks Tim-Brooks deleted the fix_types2 branch November 14, 2018 14:51
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
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