복붙노트

[HADOOP] Hadoop을 사용하여 데이터 노드에서 임시 파일을 쓰는 문제

HADOOP

Hadoop을 사용하여 데이터 노드에서 임시 파일을 쓰는 문제

프로그램 중에 파일을 만들고 싶습니다. 그러나이 파일을 HDFS에 작성하지 않고 맵 작업이 실행되는 데이터 노드 파일 시스템에 작성하고 싶지 않습니다.

나는 다음과 같은 접근법을 시도했다.

public void map(Object key, Text value, Context context)
        throws IOException, InterruptedException {
    // do some hadoop stuff, like counting words
    String path = "newFile.txt";
    try {
        File f = new File(path);
        f.createNewFile();
    } catch (IOException e) {
        System.out.println("Message easy to look up in the logs.");
        System.err.println("Error easy to look up in the logs.");
        e.printStackTrace();
        throw e;
    }
}

절대 경로를 사용하면 파일이 있어야하는 위치에 파일을 얻습니다. 그러나 상대 경로를 사용하면이 코드는 프로그램을 실행하는 콘솔이나 작업 로그에서 오류를 발생시키지 않습니다. 그러나 만들어야 할 파일을 찾을 수 없습니다 (지금은 로컬 클러스터에서 작업 중입니다).

파일이나 오류 메시지를 어디에서 찾을 수 있습니까? 실제로 오류 메시지가 발생하면 어떻게 데이터 노드의 로컬 파일 시스템에 파일을 작성해야합니까?

해결법

  1. ==============================

    1.newFile.txt는 상대 경로이므로 파일은 맵 태스크 프로세스의 작업 디렉토리에 상대적으로 표시됩니다. 컨테이너에 NodeManager가 사용하는 디렉토리 아래에 위치합니다. 이것은 yarn-site.xml의 구성 속성 yarn.nodemanager.local-dirs이거나 / tmp 아래에 yarn-default.xml에서 상속 된 기본값입니다.

    newFile.txt는 상대 경로이므로 파일은 맵 태스크 프로세스의 작업 디렉토리에 상대적으로 표시됩니다. 컨테이너에 NodeManager가 사용하는 디렉토리 아래에 위치합니다. 이것은 yarn-site.xml의 구성 속성 yarn.nodemanager.local-dirs이거나 / tmp 아래에 yarn-default.xml에서 상속 된 기본값입니다.

    <property>
      <description>List of directories to store localized files in. An 
        application's localized file directory will be found in:
        ${yarn.nodemanager.local-dirs}/usercache/${user}/appcache/application_${appid}.
        Individual containers' work directories, called container_${contid}, will
        be subdirectories of this.
      </description>
      <name>yarn.nodemanager.local-dirs</name>
      <value>${hadoop.tmp.dir}/nm-local-dir</value>
    </property>
    

    다음은 테스트 환경에서 이러한 디렉토리 중 하나의 구체적인 예입니다.

    /tmp/hadoop-cnauroth/nm-local-dir/usercache/cnauroth/appcache/application_1363932793646_0002/container_1363932793646_0002_01_000001
    

    이 디렉토리는 컨테이너 실행을위한 스크래치 공간이므로 지속성을 위해 의존 할 수있는 것은 아닙니다. 백그라운드 스레드는 완료된 컨테이너에 대해 이러한 파일을 주기적으로 삭제합니다. yarn-site.xml에서 구성 속성 yarn.nodemanager.delete.debug-delay-sec를 설정하여 정리를 지연시킬 수 있습니다.

    <property>
      <description>
        Number of seconds after an application finishes before the nodemanager's 
        DeletionService will delete the application's localized file directory
        and log directory.
    
        To diagnose Yarn application problems, set this property's value large
        enough (for example, to 600 = 10 minutes) to permit examination of these
        directories. After changing the property's value, you must restart the 
        nodemanager in order for it to have an effect.
    
        The roots of Yarn applications' work directories is configurable with
        the yarn.nodemanager.local-dirs property (see below), and the roots
        of the Yarn applications' log directories is configurable with the 
        yarn.nodemanager.log-dirs property (see also below).
      </description>
      <name>yarn.nodemanager.delete.debug-delay-sec</name>
      <value>0</value>
    </property>
    

    그러나이 구성은 디렉토리를보다 쉽게 ​​볼 수 있도록 문제를 해결하기위한 것입니다. 영구적 인 프로덕션 구성으로 권장되지 않습니다. 응용 프로그램 논리가 삭제 지연에 의존하는 경우 디렉토리에 액세스하려는 응용 프로그램 논리와 디렉토리를 삭제하려고하는 NodeManager간에 경쟁 조건이 발생할 수 있습니다. 오래된 컨테이너 실행으로 인해 파일이 남아 있으면 로컬 디스크 공간이 복잡해질 수 있습니다.

    로그 메시지는 맵 작업 로그의 stdout / stderr로 이동하지만 실행이 해당 로그 메시지에 닿지 않는 것 같습니다. 대신 파일을 성공적으로 생성했다고 생각하지만 쉽게 찾을 수 없거나 (디렉토리 구조에 YARN이 관리하는 응용 프로그램 ID 및 컨테이너 ID와 같은 예측할 수없는 것들이 있거나) 파일을 가져 오기 전에 정리하는 중입니다. 그것에.

    다른 디렉토리를 가리키는 절대 경로를 사용하도록 코드를 변경하면 도움이 될 것입니다. 그러나이 접근법이 실제로 실제로 효과가 있다고는 생각하지 않습니다. Hadoop이 분산되어 있으므로 수백 또는 수천 개의 클러스터에서 원하는 로컬 파일을 포함하는 노드를 찾는 데 어려움을 겪을 수 있습니다. 대신 HDFS에 기록한 다음 작업을 시작한 노드로 로컬로 필요한 파일을 가져 오는 것이 좋습니다.

  2. from https://stackoverflow.com/questions/25184680/troubles-writing-temp-file-on-datanode-with-hadoop by cc-by-sa and MIT license