지구정복

[HDFS] Erasure Coding 본문

데이터 엔지니어링 정복/HDFS

[HDFS] Erasure Coding

eeaarrtthh 2023. 5. 12. 23:53
728x90
반응형
SMALL

출처 

https://hadoop.apache.org/docs/r3.3.5/index.html

https://www.cnblogs.com/basenet855x/p/7889994.html


 

 

목적

기본 복제계수 값은 3이고 이럴 경우 데이터가 HDFS에 저장되면 200%의 공간과 리소스(네트워크 등)를 차지한다.

이때 잘 사용하지 않는 warm 또는 cold데이터의 경우 공간 낭비가 심하다.

따라서 이를 해결하기 위해 Eraser Coding을 HDFS 3버전부터 도입했다.

 

EC를 사용하면 fault-tolerance는 유지하면서 HDFS공간은 더욱 효율적으로 사용할 수 있다.

EC를 사용하면 디스크 오버헤드는 50%로 줄어든다.

 

이때 EC가 적용된 파일들의 경우 복제계수의 값은 사용하지 않는다.

EC가 적용된 파일들의 복제계수는 무조건 1이고 hdfs 명령어인 '-setrep' 명령어는 적용되지 않는다.

 

 

배경

EC의 특징 중 하나는 RAID이다.

RAID는 EC를 가능하게 하는데 파일을 논리적으로 잘게 나눈 뒤 각각 다른 디스크들에 저장하는 방식으로 RAID의 striping을 사용한다.

이렇게 잘게 나눠져서 다른 디스크에 저장되는 단위를 striping cell이라고 한다.

이때 이 striping cell에는 parity정보가 계산되어서 저장된다.

이러한 과정은 encoding이라고 한다.

 

만약 데이터에 문제가 생겨서 특정 cell이 이상해졌다면 다른 cell의 parity값을 계산해서 복구할 수 있다.

이를 통해 과거 복제기반의 HDFS의 데이터 지속성을 유지하면서도 스토리지 공간을 더욱 효율적으로 사용할 수 있게 해준다.

 

예를 들어 과거 복제기반의 HDFS에서 블록이 6개인 복제파일의 경우

6 x 3 = 18개의 블록이 HDFS에 저장되는 반면

 

EC가 적용된 HDFS에서는 블록이 6개인 파일은 추가적으로 parity값을 저장할 3개의 cell만 더 있으면 돼서

총 9개의 cell 즉, 9개의 블록만 HDFS에 저장되면 된다.

만약 7, 8, 9의 3개의 데이터가 있고 50, 122의 parity 데이터가 있을 경우에

이때 7, 8, 9 데이터가 만약 손실되었다면 아래처럼 복구가 가능하다.

 

 

아키텍쳐

 

  • NameNode Extensions -
    EC적용된 striped HDFS 파일들은 논리적인 블록 그룹으로 구성되어 있다.
    이 블록 그룹안에 HDFS 파일 블록들이 존재한다. 
    이때 네임노드가 블록들의 메타데이터를 메모리에서 관리하는데, 네임노드의 메모리 사용을 줄이기 위해 새로운 블록 네이밍 프로토콜이 도입돼서 블록을 관리하는게 아니라 블록 그룹 자체를 관리하게 되었다.

 

  • DataNode Extensions -
    데이터 노드의 경우 추가적인 ErasureCodingWorker(ECWorker)가 백그라운드에서 실행되는데 이 역할은 EC된 블록이 고장날 때 기능을 발휘한다.
    만약 블록이 고장나면 이는 네임노드가 알아차리고 아무 데이터노드를 정해서 복구 작업을 명령한다.
    이 작업은 복제된 블록을 재복제하는 과정과 비슷하다.
    1. 어떤 데이터 노드의 어떤 블록인지 확인하고 이를 복구하기 위해 어떤 블록을 읽어야 하는지 확인. 이때 최소한으로 블록을 읽는다.
    2. parity정보로 디코딩 작업을 통해 데이터를 복구한다.
    3. 생성된 데이터를 특정 데이터노드에 전송되어 저장된다.

 

  • Erasure coding policies 
    EC를 구현하는 정책은 여러가지가 있다.
    EC 정책은 어떻게 encoding 혹은 decoding할지를 정하는 것이다.

    1. EC 스키마 : 데이터 수와 패리티 수를 정의(예: 6+3) 하고 코덱 알고리즘도 정한다.
    2. 스트라이핑 셀의 크기

    정책 이름은 다음과 같이 만들어 진다.
    'codec' - 'num data blocks' - 'num parity blocks' - 'cell size'
    기본적으로 5가지 정책이 설정되어 있다. 기본값은 RS-6-3-1024k이다.
    RS-3-2-1024k, RS-6-3-1024k, RS-10-4-1024k, RS-LEGACY-6-3-1024k, XOR-2-1-1024k

    만약 EC를 디렉터리에 적용하면 그 안에 새로 생성되는 파일들도 자동으로 EC가 적용된다.
    이때 파일이 만들어지고 EC가 적용되면 EC정책을 더 이상 변경할 수 없다.
    또한 EC가 적용된 파일이 다른 정책을 가지고 있는 디렉토리로 이동될 경우에도 기존 EC 정책이 유지된다.

    따라서 새로운 EC를 파일에 적용시키려면 파일을 새로 만들어야 한다.
    distcp와 같은 명령어로 파일을 복사해주면 된다.

    사용자가 EC정책을 만드려면 Hadoop conf디렉터리에 있는 user_ec_policies.xml.template 파일을 참고해서 만들면 된다. 

    또한 기존 replication 정책도 디렉터리에만 적용할 수 있다. 
    이럴 경우 해당 디렉터리의 상위 디렉터리가 EC가 적용되어 있더라도 replication 정책도 따르게 된다.
    즉, 이런 디렉터리는 EC도 적용되고 replication (3x) 정책도 적용된다. 
    단 파일은 적용되지 않고 디렉터리만 적용된다.

 

Deployment

클러스터와 하드웨어 설정

EC는 클러스터 데이터노드와 클라이언트의 CPU와 네트워크를 인코딩/디코딩 하는데 사용한다.
또 EC가 적용되려면 EC정책에 필요한 최소한의 데이터노드 개수가 필요하다.
최소 (6+3) = 9 개 데이터노드가 필요하다.

또한 EC가 적용된 파일의 cell들은 rack fault-tolerance를 위해 랙 전체에 분산되어 저장된다.

그리고 랙 개수도 중요한데 다음 공식 이상의 랙 개수가 필요하다.

(data blocks + parity blocks) / parity blocks 

( 6 + 3 ) / 3 = 3(반올림) 개 랙이 최소한으로 필요하다.

 

만약 패리티 셀 개수보다 랙 수가 적게되면 rack falut-tolerance는 포기하면 되고 그냥 사용하면 된다.

 

Configuration keys 중요 설정값

기본적으로 EC 정책들은 dfs.namenode.ec.system.default.policy에 정의된 정책을 제외하고는 모두 꺼져있다.

HDFS 관리자는 다음 명령으로 EC를 적용할 수 있다.

hdfs ec [-enablePolicy -policy <policyName>]

만약 클러스터에 9개의 랙이 있는데 RS-10-4-1024k 정책을 여기에 맞지 않다.

왜냐하면 (10 + 4) = 14이기 때문에 최소한 14개의 데이터노드가 필요하기 때문이다.

이럴 경우 RS-6-3-1024k 정책이나 RS-3-2-1024k 정책을 사용하는 것이 적절하다.

 

HDFS에 특정 EC 정책을 기본값으로 설정하고 싶으면 아래 설정에 적어주면 된다.

dfs.namenode.ec.system.default.policy

만약 위 EC 명령어에서 '-setPolicy' 옵션을 빼서 실행할 경우 이 설정값에 적용된 정책이 자동으로 설정된다.

이 설정의 기본값은 “RS-6-3-1024k”이다.

 

또한 데이터가 고장났을 경우 데이터노드들은 EC를 통해 복원해야되는데 이때 사용되는 설정값들도 있다.

  1. dfs.datanode.ec.reconstruction.stripedread.timeout.millis - Stiped 읽기 제한. 기본값은 5000ms
  2. dfs.datanode.ec.reconstruction.stripedread.buffer.size - 읽기 버퍼 사이즈. Default value is 64KB.
  3. dfs.datanode.ec.reconstruction.threads - 데이터노드가 복원하는데 사용할 스레드 개수. Default value is 8 threads.
  4. dfs.datanode.ec.reconstruction.xmits.weight - replication 복구 방법과 EC 방법 중에서 EC방법으로 사용할 가중치. 

 

명령어 설명

   hdfs ec [generic options]
     [-setPolicy -path <path> [-policy <policyName>] [-replicate]]
     [-getPolicy -path <path>]
     [-unsetPolicy -path <path>]
     [-listPolicies]
     [-addPolicies -policyFile <file>]
     [-listCodecs]
     [-enablePolicy -policy <policyName>]
     [-disablePolicy -policy <policyName>]
     [-removePolicy -policy <policyName>]
     [-verifyClusterSetup -policy <policyName>...<policyName>]
     [-help [cmd ...]]

Below are the details about each command.

  • [-setPolicy -path <path> [-policy <policyName>] [-replicate]]path: An directory in HDFS. This is a mandatory parameter. Setting a policy only affects newly created files, and does not affect existing files.-replicate apply the default REPLICATION scheme on the directory, force the directory to adopt 3x replication scheme.
  • -replicate and -policy <policyName> are optional arguments. They cannot be specified at the same time.
  • policyName: The erasure coding policy to be used for files under this directory. This parameter can be omitted if a ‘dfs.namenode.ec.system.default.policy’ configuration is set. The EC policy of the path will be set with the default value in configuration.
  • Sets an erasure coding policy on a directory at the specified path.
  • [-getPolicy -path <path>]
  • Get details of the erasure coding policy of a file or directory at the specified path.
  • [-unsetPolicy -path <path>]
  • Unset an erasure coding policy set by a previous call to setPolicy on a directory. If the directory inherits the erasure coding policy from an ancestor directory, unsetPolicy is a no-op. Unsetting the policy on a directory which doesn’t have an explicit policy set will not return an error.
  • [-listPolicies]
  • Lists all (enabled, disabled and removed) erasure coding policies registered in HDFS. Only the enabled policies are suitable for use with the setPolicy command.
  • [-addPolicies -policyFile <file>]
  • Add a list of user defined erasure coding policies. Please refer etc/hadoop/user_ec_policies.xml.template for the example policy file. The maximum cell size is defined in property ‘dfs.namenode.ec.policies.max.cellsize’ with the default value 4MB. Currently HDFS allows the user to add 64 policies in total, and the added policy ID is in range of 64 to 127. Adding policy will fail if there are already 64 policies added.
  • [-listCodecs]
  • Get the list of supported erasure coding codecs and coders in system. A coder is an implementation of a codec. A codec can have different implementations, thus different coders. The coders for a codec are listed in a fall back order.
  • [-removePolicy -policy <policyName>]
  • Remove an user defined erasure coding policy.
  • [-enablePolicy -policy <policyName>]
  • Enable an erasure coding policy.
  • [-disablePolicy -policy <policyName>]
  • Disable an erasure coding policy.
  • [-verifyClusterSetup -policy <policyName>...<policyName>]
  • Verify if the cluster setup can support all enabled erasure coding policies. If optional parameter -policy is specified, verify if the cluster setup can support the given policy or policies.

Limitations 제한사항

특정 HDFS 커맨드는 EC파일에 적용되지 않는다.

(hflush, hsync, concat, setReplication, truncate, append)

  • append() and truncate() on an erasure coded file will throw IOException.
  • concat() will throw IOException if files are mixed with different erasure coding policies or with replicated files.
  • setReplication() is no-op on erasure coded files.
  • hflush() and hsync() on DFSStripedOutputStream are no-op. Thus calling hflush() or hsync() on an erasure coded file can not guarantee data being persistent.

 

728x90
반응형
LIST
Comments