drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudheeshkatkam <...@git.apache.org>
Subject [GitHub] drill pull request #773: DRILL-4335: Apache Drill should support network enc...
Date Tue, 02 May 2017 15:06:13 GMT
Github user sudheeshkatkam commented on a diff in the pull request:

    https://github.com/apache/drill/pull/773#discussion_r114334608
  
    --- Diff: exec/rpc/src/main/java/org/apache/drill/exec/rpc/ChunkCreationHandler.java ---
    @@ -0,0 +1,101 @@
    +/*
    + * 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.drill.exec.rpc;
    +
    +
    +import io.netty.buffer.ByteBuf;
    +import io.netty.buffer.CompositeByteBuf;
    +import io.netty.channel.ChannelHandlerContext;
    +import io.netty.handler.codec.MessageToMessageEncoder;
    +
    +import java.util.List;
    +
    +import static com.google.common.base.Preconditions.checkArgument;
    +import static java.lang.Math.min;
    +
    +/**
    + * Handler that converts an input ByteBuf into chunk size ByteBuf's and add it to the
    + * CompositeByteBuf as individual components. If encryption is enabled, this is always
    + * added in the channel pipeline.
    + */
    +class ChunkCreationHandler extends MessageToMessageEncoder<ByteBuf> {
    +  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(
    +      ChunkCreationHandler.class.getCanonicalName());
    +
    +  private final int chunkSize;
    +
    +  ChunkCreationHandler(int chunkSize) {
    +    checkArgument(chunkSize > 0);
    +    this.chunkSize = chunkSize;
    +  }
    +
    +  @Override
    +  public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    +    super.handlerAdded(ctx);
    +    logger.trace("Added " + RpcConstants.CHUNK_CREATION_HANDLER + " handler!");
    +  }
    +
    +  @Override
    +  public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
    +    super.handlerRemoved(ctx);
    +    logger.trace("Removed " + RpcConstants.CHUNK_CREATION_HANDLER + " handler");
    +  }
    +
    +  @Override
    +  protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
throws Exception {
    +
    +    if (RpcConstants.EXTRA_DEBUGGING) {
    +      logger.debug("ChunkCreationHandler called with msg {} of size {} with chunkSize
{}",
    +          msg, msg.readableBytes(), chunkSize);
    +    }
    +
    +    if (!ctx.channel().isOpen()) {
    +      logger.debug("Channel closed, skipping encode inside {}.", RpcConstants.CHUNK_CREATION_HANDLER);
    +      msg.release();
    +      return;
    +    }
    +
    +    ByteBuf chunkBuf;
    +
    +    // Calculate the number of chunks based on configured chunk size and input msg size
    +    int numChunks = (int) Math.ceil((double) msg.readableBytes() / chunkSize);
    +
    +    // Initialize a composite buffer to hold numChunks chunk.
    +    final CompositeByteBuf cbb = ctx.alloc().compositeBuffer(numChunks);
    --- End diff --
    
    `ctx.alloc().compositeDirectBuffer(...)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message