You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/06/23 23:45:13 UTC

[GitHub] [geode] dschneider-pivotal opened a new pull request #5289: removed main thread from GeodeRedisServer

dschneider-pivotal opened a new pull request #5289:
URL: https://github.com/apache/geode/pull/5289


   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] dschneider-pivotal commented on a change in pull request #5289: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445208186



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/PassiveExpirationManager.java
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.geode.logging.internal.executors.LoggingExecutors.newSingleThreadScheduledExecutor;
+
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.EntryDestroyedException;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.redis.internal.data.ByteArrayWrapper;
+import org.apache.geode.redis.internal.data.RedisData;
+import org.apache.geode.redis.internal.executor.key.RedisKeyCommands;
+import org.apache.geode.redis.internal.executor.key.RedisKeyCommandsFunctionExecutor;
+
+public class PassiveExpirationManager {
+  private static final Logger logger = LogService.getLogger();
+
+  private final Region<ByteArrayWrapper, RedisData> dataRegion;
+  private final ScheduledExecutorService expirationExecutor;
+
+
+  public PassiveExpirationManager(Region<ByteArrayWrapper, RedisData> dataRegion) {
+    this.dataRegion = dataRegion;
+    expirationExecutor = newSingleThreadScheduledExecutor("GemFireRedis-PassiveExpiration-");
+  }
+
+  public void start() {
+    int INTERVAL = 1;
+    expirationExecutor.scheduleAtFixedRate(() -> doDataExpiration(dataRegion), INTERVAL, INTERVAL,

Review comment:
       good idea; it is done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] lgtm-com[bot] commented on pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
lgtm-com[bot] commented on pull request #5289:
URL: https://github.com/apache/geode/pull/5289#issuecomment-649265042


   This pull request **introduces 1 alert** and **fixes 1** when merging b1827f612ae61b908f7f4f4098c691fafd96f6f9 into 5732a1c1ef9c8ccb979770a963d5c4b1b7324f1a - [view on LGTM.com](https://lgtm.com/projects/g/apache/geode/rev/pr-5e63332d9040bfffe2b4547c1c047fa30a9e5a4d)
   
   **new alerts:**
   
   * 1 for Potential input resource leak
   
   **fixed alerts:**
   
   * 1 for Potential input resource leak


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] lgtm-com[bot] commented on pull request #5289: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
lgtm-com[bot] commented on pull request #5289:
URL: https://github.com/apache/geode/pull/5289#issuecomment-649069446


   This pull request **introduces 1 alert** and **fixes 1** when merging 3eb2b0e65fbcea9d49f518bf2b5bd56609c3e68f into 210dc4fe9b1657d8d7cb5c197c6b0153389be3ea - [view on LGTM.com](https://lgtm.com/projects/g/apache/geode/rev/pr-15a27647819551ab0690adf350cdde845ebf270c)
   
   **new alerts:**
   
   * 1 for Potential input resource leak
   
   **fixed alerts:**
   
   * 1 for Potential input resource leak


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445776826



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
##########
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal.netty;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.concurrent.ThreadFactory;
+import java.util.function.Supplier;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.PooledByteBufAllocator;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.ServerChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.timeout.WriteTimeoutHandler;
+import io.netty.util.concurrent.Future;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.admin.SSLConfig;
+import org.apache.geode.internal.inet.LocalHostUtil;
+import org.apache.geode.internal.net.SSLConfigurationFactory;
+import org.apache.geode.internal.security.SecurableCommunicationChannel;
+import org.apache.geode.logging.internal.executors.LoggingThreadFactory;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.redis.internal.RegionProvider;
+import org.apache.geode.redis.internal.pubsub.PubSub;
+
+public class NettyRedisServer {
+
+  /**
+   * System property name that can be used to set the number of threads to be used by the
+   * GeodeRedisServer
+   */
+  private static final String NUM_THREADS_SYS_PROP_NAME = "gemfireredis.numthreads";
+
+  private static final int RANDOM_PORT_INDICATOR = 0;
+
+  private static final Logger logger = LogService.getLogger();
+  /**
+   * Connection timeout in milliseconds
+   */
+  private static final int connectTimeoutMillis = 1000;
+
+  /**
+   * The number of threads that will work on handling requests
+   */
+  private final int numWorkerThreads;
+
+  /**
+   * The number of threads that will work socket selectors
+   */
+  private final int numSelectorThreads;
+
+  /**
+   * whether to use old single thread per connection model for worker group
+   */
+  private final boolean singleThreadPerConnection;
+
+  private final Supplier<DistributionConfig> configSupplier;
+  private final RegionProvider regionProvider;
+  private final PubSub pubsub;
+  private final Supplier<Boolean> allowUnsupportedSupplier;
+  private final Runnable shutdownInvoker;
+
+
+  private Channel serverChannel;
+  private EventLoopGroup bossGroup;
+  private EventLoopGroup workerGroup;
+  private EventLoopGroup subscriberGroup;
+
+  private final InetAddress bindAddress;
+  private int serverPort;
+
+  public NettyRedisServer(Supplier<DistributionConfig> configSupplier,
+      RegionProvider regionProvider, PubSub pubsub, Supplier<Boolean> allowUnsupportedSupplier,
+      Runnable shutdownInvoker, int port, String requestedAddress) {
+    this.configSupplier = configSupplier;
+    this.regionProvider = regionProvider;
+    this.pubsub = pubsub;
+    this.allowUnsupportedSupplier = allowUnsupportedSupplier;
+    this.shutdownInvoker = shutdownInvoker;
+    if (port < RANDOM_PORT_INDICATOR) {
+      throw new IllegalArgumentException("Redis port cannot be less than 0");
+    }
+    serverPort = port;
+    this.bindAddress = getBindAddress(requestedAddress);
+    numWorkerThreads = setNumWorkerThreads();
+    singleThreadPerConnection = numWorkerThreads == 0;
+    numSelectorThreads = 1;
+  }
+
+
+  public void start() {
+    Class<? extends ServerChannel> socketClass = initializeEventLoopGroups();
+    ServerBootstrap serverBootstrap = new ServerBootstrap();
+
+    serverBootstrap.group(bossGroup, workerGroup).channel(socketClass)
+        .childHandler(createChannelInitializer())
+        .option(ChannelOption.SO_REUSEADDR, true)
+        .option(ChannelOption.SO_RCVBUF, getBufferSize())
+        .childOption(ChannelOption.SO_KEEPALIVE, true)
+        .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis)
+        .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+
+    serverChannel = createBoundChannel(serverBootstrap);
+  }
+
+  public void stop() {
+    ChannelFuture closeFuture = null;
+    if (serverChannel != null) {
+      closeFuture = serverChannel.closeFuture();
+    }
+    workerGroup.shutdownGracefully();
+    Future<?> bossFuture = bossGroup.shutdownGracefully();
+    if (serverChannel != null) {
+      serverChannel.close();
+    }
+    bossFuture.syncUninterruptibly();
+    if (closeFuture != null) {
+      closeFuture.syncUninterruptibly();
+    }
+  }
+
+  public int getPort() {
+    return serverPort;
+  }
+
+  private ChannelInitializer<SocketChannel> createChannelInitializer() {
+    String redisPassword = configSupplier.get().getRedisPassword();
+    final byte[] redisPasswordBytes = Coder.stringToBytes(redisPassword);
+
+    return new ChannelInitializer<SocketChannel>() {
+      @Override
+      public void initChannel(SocketChannel socketChannel) {
+        if (logger.isDebugEnabled()) {
+          logger.debug(
+              "GeodeRedisServer-Connection established with " + socketChannel.remoteAddress());
+        }
+        ChannelPipeline pipeline = socketChannel.pipeline();
+        addSSLIfEnabled(socketChannel, pipeline);
+        pipeline.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
+        pipeline.addLast(new WriteTimeoutHandler(10));
+        pipeline.addLast(ExecutionHandlerContext.class.getSimpleName(),
+            new ExecutionHandlerContext(socketChannel, regionProvider, pubsub, subscriberGroup,
+                allowUnsupportedSupplier, shutdownInvoker, redisPasswordBytes));
+      }
+    };
+  }
+
+  private void addSSLIfEnabled(SocketChannel ch, ChannelPipeline p) {
+
+    SSLConfig sslConfigForComponent =
+        SSLConfigurationFactory.getSSLConfigForComponent(configSupplier.get(),
+            SecurableCommunicationChannel.SERVER);
+
+    if (!sslConfigForComponent.isEnabled()) {
+      return;
+    }
+
+    SslContext sslContext;
+    try {
+      KeyStore ks = KeyStore.getInstance("JKS");
+      ks.load(new FileInputStream(sslConfigForComponent.getKeystore()),
+          sslConfigForComponent.getKeystorePassword().toCharArray()/**/);
+
+      // Set up key manager factory to use our key store
+      KeyManagerFactory kmf =
+          KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+      kmf.init(ks, sslConfigForComponent.getKeystorePassword().toCharArray());
+
+      SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(kmf);
+      sslContext = sslContextBuilder.build();
+
+    } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | IOException
+        | CertificateException e) {
+      throw new RuntimeException(e);
+    }
+    p.addLast(sslContext.newHandler(ch.alloc()));
+  }
+
+  private Class<? extends ServerChannel> initializeEventLoopGroups() {
+    ThreadFactory selectorThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-SelectorThread-", false);
+
+    ThreadFactory workerThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-WorkerThread-", true);
+
+    if (singleThreadPerConnection) {

Review comment:
       Sounds good.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] lgtm-com[bot] commented on pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
lgtm-com[bot] commented on pull request #5289:
URL: https://github.com/apache/geode/pull/5289#issuecomment-649120737


   This pull request **introduces 1 alert** and **fixes 1** when merging 54ed604c30def8db08bc18f9eeea656624e2ea7d into 5732a1c1ef9c8ccb979770a963d5c4b1b7324f1a - [view on LGTM.com](https://lgtm.com/projects/g/apache/geode/rev/pr-f4517dd7fc24dba1d7e99f817333b0bb61493a59)
   
   **new alerts:**
   
   * 1 for Potential input resource leak
   
   **fixed alerts:**
   
   * 1 for Potential input resource leak


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #5289: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445196891



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/PassiveExpirationManager.java
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.geode.logging.internal.executors.LoggingExecutors.newSingleThreadScheduledExecutor;
+
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.EntryDestroyedException;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.redis.internal.data.ByteArrayWrapper;
+import org.apache.geode.redis.internal.data.RedisData;
+import org.apache.geode.redis.internal.executor.key.RedisKeyCommands;
+import org.apache.geode.redis.internal.executor.key.RedisKeyCommandsFunctionExecutor;
+
+public class PassiveExpirationManager {
+  private static final Logger logger = LogService.getLogger();
+
+  private final Region<ByteArrayWrapper, RedisData> dataRegion;
+  private final ScheduledExecutorService expirationExecutor;
+
+
+  public PassiveExpirationManager(Region<ByteArrayWrapper, RedisData> dataRegion) {
+    this.dataRegion = dataRegion;
+    expirationExecutor = newSingleThreadScheduledExecutor("GemFireRedis-PassiveExpiration-");
+  }
+
+  public void start() {
+    int INTERVAL = 1;
+    expirationExecutor.scheduleAtFixedRate(() -> doDataExpiration(dataRegion), INTERVAL, INTERVAL,

Review comment:
       I think this would be potentially better with `scheduleWithFixedDelay` so that there's a guaranteed pause between runs. I'm concerned that a large data set would result in `doDataExpiration` taking longer than 1 second and putting pressure on the system by constantly running back-to-back.

##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
##########
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal.netty;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.concurrent.ThreadFactory;
+import java.util.function.Supplier;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.PooledByteBufAllocator;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.ServerChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.timeout.WriteTimeoutHandler;
+import io.netty.util.concurrent.Future;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.admin.SSLConfig;
+import org.apache.geode.internal.inet.LocalHostUtil;
+import org.apache.geode.internal.net.SSLConfigurationFactory;
+import org.apache.geode.internal.security.SecurableCommunicationChannel;
+import org.apache.geode.logging.internal.executors.LoggingThreadFactory;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.redis.internal.RegionProvider;
+import org.apache.geode.redis.internal.pubsub.PubSub;
+
+public class NettyRedisServer {
+
+  /**
+   * System property name that can be used to set the number of threads to be used by the
+   * GeodeRedisServer
+   */
+  private static final String NUM_THREADS_SYS_PROP_NAME = "gemfireredis.numthreads";
+
+  private static final int RANDOM_PORT_INDICATOR = 0;
+
+  private static final Logger logger = LogService.getLogger();
+  /**
+   * Connection timeout in milliseconds
+   */
+  private static final int connectTimeoutMillis = 1000;
+
+  /**
+   * The number of threads that will work on handling requests
+   */
+  private final int numWorkerThreads;
+
+  /**
+   * The number of threads that will work socket selectors
+   */
+  private final int numSelectorThreads;
+
+  /**
+   * whether to use old single thread per connection model for worker group
+   */
+  private final boolean singleThreadPerConnection;
+
+  private final Supplier<DistributionConfig> configSupplier;
+  private final RegionProvider regionProvider;
+  private final PubSub pubsub;
+  private final Supplier<Boolean> allowUnsupportedSupplier;
+  private final Runnable shutdownInvoker;
+
+
+  private Channel serverChannel;
+  private EventLoopGroup bossGroup;
+  private EventLoopGroup workerGroup;
+  private EventLoopGroup subscriberGroup;
+
+  private final InetAddress bindAddress;
+  private int serverPort;
+
+  public NettyRedisServer(Supplier<DistributionConfig> configSupplier,
+      RegionProvider regionProvider, PubSub pubsub, Supplier<Boolean> allowUnsupportedSupplier,
+      Runnable shutdownInvoker, int port, String requestedAddress) {
+    this.configSupplier = configSupplier;
+    this.regionProvider = regionProvider;
+    this.pubsub = pubsub;
+    this.allowUnsupportedSupplier = allowUnsupportedSupplier;
+    this.shutdownInvoker = shutdownInvoker;
+    if (port < RANDOM_PORT_INDICATOR) {
+      throw new IllegalArgumentException("Redis port cannot be less than 0");
+    }
+    serverPort = port;
+    this.bindAddress = getBindAddress(requestedAddress);
+    numWorkerThreads = setNumWorkerThreads();
+    singleThreadPerConnection = numWorkerThreads == 0;
+    numSelectorThreads = 1;
+  }
+
+
+  public void start() {
+    Class<? extends ServerChannel> socketClass = initializeEventLoopGroups();
+    ServerBootstrap serverBootstrap = new ServerBootstrap();
+
+    serverBootstrap.group(bossGroup, workerGroup).channel(socketClass)
+        .childHandler(createChannelInitializer())
+        .option(ChannelOption.SO_REUSEADDR, true)
+        .option(ChannelOption.SO_RCVBUF, getBufferSize())
+        .childOption(ChannelOption.SO_KEEPALIVE, true)
+        .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis)
+        .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+
+    serverChannel = createBoundChannel(serverBootstrap);
+  }
+
+  public void stop() {
+    ChannelFuture closeFuture = null;
+    if (serverChannel != null) {
+      closeFuture = serverChannel.closeFuture();
+    }
+    workerGroup.shutdownGracefully();
+    Future<?> bossFuture = bossGroup.shutdownGracefully();
+    if (serverChannel != null) {
+      serverChannel.close();
+    }
+    bossFuture.syncUninterruptibly();
+    if (closeFuture != null) {
+      closeFuture.syncUninterruptibly();
+    }
+  }
+
+  public int getPort() {
+    return serverPort;
+  }
+
+  private ChannelInitializer<SocketChannel> createChannelInitializer() {
+    String redisPassword = configSupplier.get().getRedisPassword();
+    final byte[] redisPasswordBytes = Coder.stringToBytes(redisPassword);
+
+    return new ChannelInitializer<SocketChannel>() {
+      @Override
+      public void initChannel(SocketChannel socketChannel) {
+        if (logger.isDebugEnabled()) {
+          logger.debug(
+              "GeodeRedisServer-Connection established with " + socketChannel.remoteAddress());
+        }
+        ChannelPipeline pipeline = socketChannel.pipeline();
+        addSSLIfEnabled(socketChannel, pipeline);
+        pipeline.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
+        pipeline.addLast(new WriteTimeoutHandler(10));
+        pipeline.addLast(ExecutionHandlerContext.class.getSimpleName(),
+            new ExecutionHandlerContext(socketChannel, regionProvider, pubsub, subscriberGroup,
+                allowUnsupportedSupplier, shutdownInvoker, redisPasswordBytes));
+      }
+    };
+  }
+
+  private void addSSLIfEnabled(SocketChannel ch, ChannelPipeline p) {
+
+    SSLConfig sslConfigForComponent =
+        SSLConfigurationFactory.getSSLConfigForComponent(configSupplier.get(),
+            SecurableCommunicationChannel.SERVER);
+
+    if (!sslConfigForComponent.isEnabled()) {
+      return;
+    }
+
+    SslContext sslContext;
+    try {
+      KeyStore ks = KeyStore.getInstance("JKS");
+      ks.load(new FileInputStream(sslConfigForComponent.getKeystore()),
+          sslConfigForComponent.getKeystorePassword().toCharArray()/**/);
+
+      // Set up key manager factory to use our key store
+      KeyManagerFactory kmf =
+          KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+      kmf.init(ks, sslConfigForComponent.getKeystorePassword().toCharArray());
+
+      SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(kmf);
+      sslContext = sslContextBuilder.build();
+
+    } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | IOException
+        | CertificateException e) {
+      throw new RuntimeException(e);
+    }
+    p.addLast(sslContext.newHandler(ch.alloc()));
+  }
+
+  private Class<? extends ServerChannel> initializeEventLoopGroups() {
+    ThreadFactory selectorThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-SelectorThread-", false);
+
+    ThreadFactory workerThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-WorkerThread-", true);
+
+    if (singleThreadPerConnection) {

Review comment:
       What do you think about removing this altogether? We do no testing with this mode and I wouldn't expect anyone to actually use it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] dschneider-pivotal commented on a change in pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445655890



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
##########
@@ -77,7 +78,7 @@ private void startRedisServer(InternalCache cache) {
           String.format("Starting GeodeRedisServer on bind address %s on port %s",

Review comment:
       We currently have two log messages. One says "starting" and shows the requested configuration. The other says "started" and show the actual host and port. It seems like both are worth having. Does that resolve this conversation?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445582180



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
##########
@@ -77,7 +78,7 @@ private void startRedisServer(InternalCache cache) {
           String.format("Starting GeodeRedisServer on bind address %s on port %s",

Review comment:
       Since you're working on this, could you move the log message after the start so that we log the actual port used in the event that it is started on an ephemeral port. (Otherwise it just says `Starting... on port 0`).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] dschneider-pivotal merged pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal merged pull request #5289:
URL: https://github.com/apache/geode/pull/5289


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] dschneider-pivotal commented on a change in pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445776709



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
##########
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal.netty;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.concurrent.ThreadFactory;
+import java.util.function.Supplier;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.PooledByteBufAllocator;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.ServerChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.timeout.WriteTimeoutHandler;
+import io.netty.util.concurrent.Future;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.admin.SSLConfig;
+import org.apache.geode.internal.inet.LocalHostUtil;
+import org.apache.geode.internal.net.SSLConfigurationFactory;
+import org.apache.geode.internal.security.SecurableCommunicationChannel;
+import org.apache.geode.logging.internal.executors.LoggingThreadFactory;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.redis.internal.RegionProvider;
+import org.apache.geode.redis.internal.pubsub.PubSub;
+
+public class NettyRedisServer {
+
+  /**
+   * System property name that can be used to set the number of threads to be used by the
+   * GeodeRedisServer
+   */
+  private static final String NUM_THREADS_SYS_PROP_NAME = "gemfireredis.numthreads";
+
+  private static final int RANDOM_PORT_INDICATOR = 0;
+
+  private static final Logger logger = LogService.getLogger();
+  /**
+   * Connection timeout in milliseconds
+   */
+  private static final int connectTimeoutMillis = 1000;
+
+  /**
+   * The number of threads that will work on handling requests
+   */
+  private final int numWorkerThreads;
+
+  /**
+   * The number of threads that will work socket selectors
+   */
+  private final int numSelectorThreads;
+
+  /**
+   * whether to use old single thread per connection model for worker group
+   */
+  private final boolean singleThreadPerConnection;
+
+  private final Supplier<DistributionConfig> configSupplier;
+  private final RegionProvider regionProvider;
+  private final PubSub pubsub;
+  private final Supplier<Boolean> allowUnsupportedSupplier;
+  private final Runnable shutdownInvoker;
+
+
+  private Channel serverChannel;
+  private EventLoopGroup bossGroup;
+  private EventLoopGroup workerGroup;
+  private EventLoopGroup subscriberGroup;
+
+  private final InetAddress bindAddress;
+  private int serverPort;
+
+  public NettyRedisServer(Supplier<DistributionConfig> configSupplier,
+      RegionProvider regionProvider, PubSub pubsub, Supplier<Boolean> allowUnsupportedSupplier,
+      Runnable shutdownInvoker, int port, String requestedAddress) {
+    this.configSupplier = configSupplier;
+    this.regionProvider = regionProvider;
+    this.pubsub = pubsub;
+    this.allowUnsupportedSupplier = allowUnsupportedSupplier;
+    this.shutdownInvoker = shutdownInvoker;
+    if (port < RANDOM_PORT_INDICATOR) {
+      throw new IllegalArgumentException("Redis port cannot be less than 0");
+    }
+    serverPort = port;
+    this.bindAddress = getBindAddress(requestedAddress);
+    numWorkerThreads = setNumWorkerThreads();
+    singleThreadPerConnection = numWorkerThreads == 0;
+    numSelectorThreads = 1;
+  }
+
+
+  public void start() {
+    Class<? extends ServerChannel> socketClass = initializeEventLoopGroups();
+    ServerBootstrap serverBootstrap = new ServerBootstrap();
+
+    serverBootstrap.group(bossGroup, workerGroup).channel(socketClass)
+        .childHandler(createChannelInitializer())
+        .option(ChannelOption.SO_REUSEADDR, true)
+        .option(ChannelOption.SO_RCVBUF, getBufferSize())
+        .childOption(ChannelOption.SO_KEEPALIVE, true)
+        .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis)
+        .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+
+    serverChannel = createBoundChannel(serverBootstrap);
+  }
+
+  public void stop() {
+    ChannelFuture closeFuture = null;
+    if (serverChannel != null) {
+      closeFuture = serverChannel.closeFuture();
+    }
+    workerGroup.shutdownGracefully();
+    Future<?> bossFuture = bossGroup.shutdownGracefully();
+    if (serverChannel != null) {
+      serverChannel.close();
+    }
+    bossFuture.syncUninterruptibly();
+    if (closeFuture != null) {
+      closeFuture.syncUninterruptibly();
+    }
+  }
+
+  public int getPort() {
+    return serverPort;
+  }
+
+  private ChannelInitializer<SocketChannel> createChannelInitializer() {
+    String redisPassword = configSupplier.get().getRedisPassword();
+    final byte[] redisPasswordBytes = Coder.stringToBytes(redisPassword);
+
+    return new ChannelInitializer<SocketChannel>() {
+      @Override
+      public void initChannel(SocketChannel socketChannel) {
+        if (logger.isDebugEnabled()) {
+          logger.debug(
+              "GeodeRedisServer-Connection established with " + socketChannel.remoteAddress());
+        }
+        ChannelPipeline pipeline = socketChannel.pipeline();
+        addSSLIfEnabled(socketChannel, pipeline);
+        pipeline.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
+        pipeline.addLast(new WriteTimeoutHandler(10));
+        pipeline.addLast(ExecutionHandlerContext.class.getSimpleName(),
+            new ExecutionHandlerContext(socketChannel, regionProvider, pubsub, subscriberGroup,
+                allowUnsupportedSupplier, shutdownInvoker, redisPasswordBytes));
+      }
+    };
+  }
+
+  private void addSSLIfEnabled(SocketChannel ch, ChannelPipeline p) {
+
+    SSLConfig sslConfigForComponent =
+        SSLConfigurationFactory.getSSLConfigForComponent(configSupplier.get(),
+            SecurableCommunicationChannel.SERVER);
+
+    if (!sslConfigForComponent.isEnabled()) {
+      return;
+    }
+
+    SslContext sslContext;
+    try {
+      KeyStore ks = KeyStore.getInstance("JKS");
+      ks.load(new FileInputStream(sslConfigForComponent.getKeystore()),
+          sslConfigForComponent.getKeystorePassword().toCharArray()/**/);
+
+      // Set up key manager factory to use our key store
+      KeyManagerFactory kmf =
+          KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+      kmf.init(ks, sslConfigForComponent.getKeystorePassword().toCharArray());
+
+      SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(kmf);
+      sslContext = sslContextBuilder.build();
+
+    } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | IOException
+        | CertificateException e) {
+      throw new RuntimeException(e);
+    }
+    p.addLast(sslContext.newHandler(ch.alloc()));
+  }
+
+  private Class<? extends ServerChannel> initializeEventLoopGroups() {
+    ThreadFactory selectorThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-SelectorThread-", false);
+
+    ThreadFactory workerThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-WorkerThread-", true);
+
+    if (singleThreadPerConnection) {

Review comment:
       I added this to the numThreads sys prop story




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] dschneider-pivotal commented on a change in pull request #5289: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on a change in pull request #5289:
URL: https://github.com/apache/geode/pull/5289#discussion_r445206636



##########
File path: geode-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
##########
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal.netty;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.concurrent.ThreadFactory;
+import java.util.function.Supplier;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.PooledByteBufAllocator;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.ServerChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.timeout.WriteTimeoutHandler;
+import io.netty.util.concurrent.Future;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.admin.SSLConfig;
+import org.apache.geode.internal.inet.LocalHostUtil;
+import org.apache.geode.internal.net.SSLConfigurationFactory;
+import org.apache.geode.internal.security.SecurableCommunicationChannel;
+import org.apache.geode.logging.internal.executors.LoggingThreadFactory;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.management.ManagementException;
+import org.apache.geode.redis.internal.RegionProvider;
+import org.apache.geode.redis.internal.pubsub.PubSub;
+
+public class NettyRedisServer {
+
+  /**
+   * System property name that can be used to set the number of threads to be used by the
+   * GeodeRedisServer
+   */
+  private static final String NUM_THREADS_SYS_PROP_NAME = "gemfireredis.numthreads";
+
+  private static final int RANDOM_PORT_INDICATOR = 0;
+
+  private static final Logger logger = LogService.getLogger();
+  /**
+   * Connection timeout in milliseconds
+   */
+  private static final int connectTimeoutMillis = 1000;
+
+  /**
+   * The number of threads that will work on handling requests
+   */
+  private final int numWorkerThreads;
+
+  /**
+   * The number of threads that will work socket selectors
+   */
+  private final int numSelectorThreads;
+
+  /**
+   * whether to use old single thread per connection model for worker group
+   */
+  private final boolean singleThreadPerConnection;
+
+  private final Supplier<DistributionConfig> configSupplier;
+  private final RegionProvider regionProvider;
+  private final PubSub pubsub;
+  private final Supplier<Boolean> allowUnsupportedSupplier;
+  private final Runnable shutdownInvoker;
+
+
+  private Channel serverChannel;
+  private EventLoopGroup bossGroup;
+  private EventLoopGroup workerGroup;
+  private EventLoopGroup subscriberGroup;
+
+  private final InetAddress bindAddress;
+  private int serverPort;
+
+  public NettyRedisServer(Supplier<DistributionConfig> configSupplier,
+      RegionProvider regionProvider, PubSub pubsub, Supplier<Boolean> allowUnsupportedSupplier,
+      Runnable shutdownInvoker, int port, String requestedAddress) {
+    this.configSupplier = configSupplier;
+    this.regionProvider = regionProvider;
+    this.pubsub = pubsub;
+    this.allowUnsupportedSupplier = allowUnsupportedSupplier;
+    this.shutdownInvoker = shutdownInvoker;
+    if (port < RANDOM_PORT_INDICATOR) {
+      throw new IllegalArgumentException("Redis port cannot be less than 0");
+    }
+    serverPort = port;
+    this.bindAddress = getBindAddress(requestedAddress);
+    numWorkerThreads = setNumWorkerThreads();
+    singleThreadPerConnection = numWorkerThreads == 0;
+    numSelectorThreads = 1;
+  }
+
+
+  public void start() {
+    Class<? extends ServerChannel> socketClass = initializeEventLoopGroups();
+    ServerBootstrap serverBootstrap = new ServerBootstrap();
+
+    serverBootstrap.group(bossGroup, workerGroup).channel(socketClass)
+        .childHandler(createChannelInitializer())
+        .option(ChannelOption.SO_REUSEADDR, true)
+        .option(ChannelOption.SO_RCVBUF, getBufferSize())
+        .childOption(ChannelOption.SO_KEEPALIVE, true)
+        .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis)
+        .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+
+    serverChannel = createBoundChannel(serverBootstrap);
+  }
+
+  public void stop() {
+    ChannelFuture closeFuture = null;
+    if (serverChannel != null) {
+      closeFuture = serverChannel.closeFuture();
+    }
+    workerGroup.shutdownGracefully();
+    Future<?> bossFuture = bossGroup.shutdownGracefully();
+    if (serverChannel != null) {
+      serverChannel.close();
+    }
+    bossFuture.syncUninterruptibly();
+    if (closeFuture != null) {
+      closeFuture.syncUninterruptibly();
+    }
+  }
+
+  public int getPort() {
+    return serverPort;
+  }
+
+  private ChannelInitializer<SocketChannel> createChannelInitializer() {
+    String redisPassword = configSupplier.get().getRedisPassword();
+    final byte[] redisPasswordBytes = Coder.stringToBytes(redisPassword);
+
+    return new ChannelInitializer<SocketChannel>() {
+      @Override
+      public void initChannel(SocketChannel socketChannel) {
+        if (logger.isDebugEnabled()) {
+          logger.debug(
+              "GeodeRedisServer-Connection established with " + socketChannel.remoteAddress());
+        }
+        ChannelPipeline pipeline = socketChannel.pipeline();
+        addSSLIfEnabled(socketChannel, pipeline);
+        pipeline.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
+        pipeline.addLast(new WriteTimeoutHandler(10));
+        pipeline.addLast(ExecutionHandlerContext.class.getSimpleName(),
+            new ExecutionHandlerContext(socketChannel, regionProvider, pubsub, subscriberGroup,
+                allowUnsupportedSupplier, shutdownInvoker, redisPasswordBytes));
+      }
+    };
+  }
+
+  private void addSSLIfEnabled(SocketChannel ch, ChannelPipeline p) {
+
+    SSLConfig sslConfigForComponent =
+        SSLConfigurationFactory.getSSLConfigForComponent(configSupplier.get(),
+            SecurableCommunicationChannel.SERVER);
+
+    if (!sslConfigForComponent.isEnabled()) {
+      return;
+    }
+
+    SslContext sslContext;
+    try {
+      KeyStore ks = KeyStore.getInstance("JKS");
+      ks.load(new FileInputStream(sslConfigForComponent.getKeystore()),
+          sslConfigForComponent.getKeystorePassword().toCharArray()/**/);
+
+      // Set up key manager factory to use our key store
+      KeyManagerFactory kmf =
+          KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+      kmf.init(ks, sslConfigForComponent.getKeystorePassword().toCharArray());
+
+      SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(kmf);
+      sslContext = sslContextBuilder.build();
+
+    } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | IOException
+        | CertificateException e) {
+      throw new RuntimeException(e);
+    }
+    p.addLast(sslContext.newHandler(ch.alloc()));
+  }
+
+  private Class<? extends ServerChannel> initializeEventLoopGroups() {
+    ThreadFactory selectorThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-SelectorThread-", false);
+
+    ThreadFactory workerThreadFactory =
+        new LoggingThreadFactory("GeodeRedisServer-WorkerThread-", true);
+
+    if (singleThreadPerConnection) {

Review comment:
       I like that idea. It uses deprecated apis so I'd really want us to test with it before allowing customers to use it.
   But I think that should be on its own PR. We have one about numThreads sys prop; seems like we could do it on that one.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] lgtm-com[bot] commented on pull request #5289: GEODE-8295: refactor GeodeRedisServer

Posted by GitBox <gi...@apache.org>.
lgtm-com[bot] commented on pull request #5289:
URL: https://github.com/apache/geode/pull/5289#issuecomment-649672240


   This pull request **introduces 1 alert** and **fixes 1** when merging d4caf7bc9551cfbf3847d51e0ea7599b0873030d into 5e2baea7516b5e900f2699afddb63c59a20a1ab3 - [view on LGTM.com](https://lgtm.com/projects/g/apache/geode/rev/pr-d1933f829613474b00ff788caf6b658dcc41a30d)
   
   **new alerts:**
   
   * 1 for Potential input resource leak
   
   **fixed alerts:**
   
   * 1 for Potential input resource leak


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org