<commit_before>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the “License”). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.worker.netty;

import alluxio.Configuration;
import alluxio.Constants;
import alluxio.network.protocol.RPCBlockReadRequest;
import alluxio.network.protocol.RPCBlockWriteRequest;
import alluxio.network.protocol.RPCErrorResponse;
import alluxio.network.protocol.RPCFileReadRequest;
import alluxio.network.protocol.RPCFileWriteRequest;
import alluxio.network.protocol.RPCMessage;
import alluxio.network.protocol.RPCRequest;
import alluxio.network.protocol.RPCResponse;
import alluxio.worker.AlluxioWorker;

import com.google.common.base.Preconditions;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

import javax.annotation.concurrent.NotThreadSafe;

/**
 * This class processes {@link RPCRequest} messages and delegates them to the appropriate
 * handlers to return {@link RPCResponse} messages.
 */
@ChannelHandler.Sharable
@NotThreadSafe
public final class DataServerHandler extends SimpleChannelInboundHandler<RPCMessage> {
  private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE);

  /** Handler for any block store requests. */
  private final BlockDataServerHandler mBlockHandler;
  /** Handler for any file system requests. */
  private final UnderFileSystemDataServerHandler mUnderFileSystemHandler;

  /**
   * Creates a new instance of {@link DataServerHandler}.
   *
   * @param worker the Alluxio worker handle
   * @param configuration Alluxio configuration
   */
  public DataServerHandler(final AlluxioWorker worker, Configuration configuration) {
    Preconditions.checkNotNull(worker);
    Preconditions.checkNotNull(configuration);
    mBlockHandler = new BlockDataServerHandler(worker.getBlockWorker(), configuration);
    mUnderFileSystemHandler =
        new UnderFileSystemDataServerHandler(worker.getFileSystemWorker(), configuration);
  }

  @Override
  public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg)
      throws IOException {
    switch (msg.getType()) {
      case RPC_BLOCK_READ_REQUEST:
        assert msg instanceof RPCBlockReadRequest;
        mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
        break;
      case RPC_BLOCK_WRITE_REQUEST:
        assert msg instanceof RPCBlockWriteRequest;
        mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
        break;
      case RPC_FILE_READ_REQUEST:
        assert msg instanceof RPCFileReadRequest;
        mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
        break;
      case RPC_FILE_WRITE_REQUEST:
        assert msg instanceof RPCFileWriteRequest;
        mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
        break;
      default:
        RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
        ctx.writeAndFlush(resp);
        throw new IllegalArgumentException(
            "No handler implementation for rpc msg type: " + msg.getType());
    }
  }

  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOG.warn("Exception thrown while processing request", cause);
    ctx.close();
  }
}<commit_msg>Handle error response in data server handler.<commit_after>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the “License”). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.worker.netty;

import alluxio.Configuration;
import alluxio.Constants;
import alluxio.network.protocol.RPCBlockReadRequest;
import alluxio.network.protocol.RPCBlockWriteRequest;
import alluxio.network.protocol.RPCErrorResponse;
import alluxio.network.protocol.RPCFileReadRequest;
import alluxio.network.protocol.RPCFileWriteRequest;
import alluxio.network.protocol.RPCMessage;
import alluxio.network.protocol.RPCRequest;
import alluxio.network.protocol.RPCResponse;
import alluxio.worker.AlluxioWorker;

import com.google.common.base.Preconditions;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

import javax.annotation.concurrent.NotThreadSafe;

/**
 * This class processes {@link RPCRequest} messages and delegates them to the appropriate
 * handlers to return {@link RPCResponse} messages.
 */
@ChannelHandler.Sharable
@NotThreadSafe
public final class DataServerHandler extends SimpleChannelInboundHandler<RPCMessage> {
  private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE);

  /** Handler for any block store requests. */
  private final BlockDataServerHandler mBlockHandler;
  /** Handler for any file system requests. */
  private final UnderFileSystemDataServerHandler mUnderFileSystemHandler;

  /**
   * Creates a new instance of {@link DataServerHandler}.
   *
   * @param worker the Alluxio worker handle
   * @param configuration Alluxio configuration
   */
  public DataServerHandler(final AlluxioWorker worker, Configuration configuration) {
    Preconditions.checkNotNull(worker);
    Preconditions.checkNotNull(configuration);
    mBlockHandler = new BlockDataServerHandler(worker.getBlockWorker(), configuration);
    mUnderFileSystemHandler =
        new UnderFileSystemDataServerHandler(worker.getFileSystemWorker(), configuration);
  }

  @Override
  public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg)
      throws IOException {
    switch (msg.getType()) {
      case RPC_BLOCK_READ_REQUEST:
        assert msg instanceof RPCBlockReadRequest;
        mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
        break;
      case RPC_BLOCK_WRITE_REQUEST:
        assert msg instanceof RPCBlockWriteRequest;
        mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
        break;
      case RPC_FILE_READ_REQUEST:
        assert msg instanceof RPCFileReadRequest;
        mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
        break;
      case RPC_FILE_WRITE_REQUEST:
        assert msg instanceof RPCFileWriteRequest;
        mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
        break;
      case RPC_ERROR_RESPONSE:
        assert msg instanceof RPCErrorResponse;
        LOG.error("Received an error response from the client: " + msg.toString());
        break;
      default:
        RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
        ctx.writeAndFlush(resp);
        throw new IllegalArgumentException(
            "No handler implementation for rpc msg type: " + msg.getType());
    }
  }

  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOG.warn("Exception thrown while processing request", cause);
    ctx.close();
  }
}
{'fraction_non_alphanumeric': 0.07316767068273092, 'fraction_numerical': 0.0017570281124497991, 'mean_word_length': 4.5455810716771055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5218287', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2088, 'n_words': 591}