Ejemplo n.º 1
0
  private void writeFile(Operation operation) throws Exception {
    Logger.logDebug("Start operation to send writeFile request to datanode", getClass());
    // on a write request, the parameter is a FileWriteOperationParameter
    FileWriteOperationParameter fileWriteParm =
        (FileWriteOperationParameter) operation.getParamProto();

    // find all datanodes that will be receiving that file
    List<DatanodeInfo> datanodes = Datanodes.findDatanodesForFileWrite(fileWriteParm.getDfsFile());
    Logger.logDebug(
        "Operation will send write request to " + datanodes.size() + " datanodes: ", getClass());
    // add the chosen datanodes to the operation parameter
    for (DatanodeInfo datanodeInfo : datanodes) {
      fileWriteParm.addDatanode(datanodeInfo);
      Logger.logDebug(">>> " + datanodeInfo, getClass());
    }

    // remove valid datanodes from the dfsFile
    FileStructure.getInstance()
        .removeValidDatanodes(fileWriteParm.getFilePath(), fileWriteParm.getDfsFile().getName());

    // send the request to the first datanode
    FileOperationReqProtocol fileOperationRequest =
        new FileOperationReqProtocolImpl(fileWriteParm.findNextDatanode(), operation);
    fileOperationRequest.requestFileOperation();
  }
Ejemplo n.º 2
0
  private void readFile(Operation operation) throws Exception {
    Logger.logDebug("Start operation to send readFile request to datanode", getClass());
    // on a read request, the parameter is a FileReadOperationParameter
    FileReadOperationParameter fileReadParm =
        (FileReadOperationParameter) operation.getParamProto();

    // find the datanode that will be sending that file
    List<DatanodeInfo> datanodes = Datanodes.findDatanodesForFileWrite(fileReadParm.getDfsFile());
    Logger.logDebug("Operation will send read request to one of the valid datanodes: ", getClass());
    // add the chosen datanodes to the operation parameter
    for (DatanodeInfo datanodeInfo : datanodes) {
      fileReadParm.addDatanode(datanodeInfo);
      Logger.logDebug(">>> " + datanodeInfo, getClass());
    }

    // TODO receive file from multiple datanodes, someday

    // send the request to the first datanode
    FileOperationReqProtocol fileOperationRequest =
        new FileOperationReqProtocolImpl(fileReadParm.findNextDatanode(), operation);
    fileOperationRequest.requestFileOperation();
  }