

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS Glue를 사용하여 Apache Cassandra 워크로드를 Amazon Keyspaces으로 마이그레이션
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue"></a>

*Nikolai Kolesnikov, Karthiga Priya Chandran, Samir Patel, Amazon Web Services*

## 요약
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-summary"></a>

이 패턴은 AWS Glue에서 CQLReplicator를 사용하여 기존 Apache Cassandra 워크로드를 Amazon Keyspaces(Apache Cassandra용)로 마이그레이션하는 방법을 보여줍니다. AWS Glue에서 CQLReplicator를 사용하여 워크로드를 마이그레이션하는 데 따른 복제 지연을 몇 분으로 줄일 수 있습니다. 또한, Amazon Simple Storage Service(Amazon S3) 버킷을 사용하여 [Apache Parquet](https://parquet.apache.org/) 파일, 구성 파일, 스크립트 등 마이그레이션에 필요한 데이터를 저장하는 방법도 알아봅니다. 이 패턴은 Cassandra 워크로드가 가상 사설 클라우드(VPC)의 Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스에서 호스팅된다고 가정합니다.

## 사전 조건 및 제한 사항
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-prereqs"></a>

**사전 조건 **
+ 소스 테이블이 있는 Cassandra 클러스터
+ 워크로드 복제를 위한 Amazon Keyspace의 대상 테이블
+ 점진적 데이터 변경이 포함된 중간 Parquet 파일을 저장할 S3 버킷
+ 작업 구성 파일 및 스크립트를 저장할 S3 버킷

**제한 사항 **
+ AWS Glue의 CQLReplicator는 Cassandra 워크로드에 대해 데이터 프로세싱 장치(DPU)를 프로비저닝하는 데 시간이 걸립니다. Cassandra 클러스터와 Amazon Keyspaces의 대상 키스페이스 및 테이블 사이의 복제 지연은 단 몇 분 동안만 지속될 가능성이 높습니다.

## 아키텍처
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-architecture"></a>

**소스 기술 스택  **
+ Apache Cassandra
+ DataStax 서버
+ ScyllaDB

**대상 기술 스택  **
+ Amazon Keyspaces

**마이그레이션 아키텍처**

아래의 다이어그램은 Cassandra 클러스터가 EC2 인스턴스에 호스팅되고 세 개의 가용 영역에 분산되어 있는 예제 아키텍처를 보여줍니다. Cassandra 노드는 개인 서브넷에서 호스팅됩니다.

![\[AWS Glue가 노드 VPC에 연결되는 사용자 지정 서비스 역할, Amazon Keyspaces 및 Amazon S3.\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/images/pattern-img/e08048da-8996-4f2c-b8ed-da49fe9e693b/images/76256ab3-a1e6-4c9e-9c40-dc78f51edf0f.png)


이 다이어그램은 다음 워크플로를 보여줍니다.

1. 사용자 지정 서비스 역할은 Amazon Keyspaces 및 S3 버킷에 대한 액세스를 제공합니다.

1. AWS Glue 작업은 S3 버킷의 작업 구성과 스크립트를 읽습니다.

1. AWS Glue 작업은 포트 9042를 통해 연결되어 Cassandra 클러스터에서 데이터를 읽습니다.

1. AWS Glue 작업은 포트 9142를 통해 연결하여 Amazon Keyspaces에 데이터를 씁니다.

## 도구
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-tools"></a>

**AWS 서비스 및 도구**
+ [AWS Command Line Interface(AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)는 명령줄 쉘에서 명령을 사용하여 AWS 서비스와 상호 작용할 수 있는 오픈 소스 도구입니다.
+ [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html)은 AWS Command Line Interface(AWS CLI) 및 사전 설치된 다양한 개발 도구를 사용하여 AWS 서비스를 관리하는 데 사용할 수 있는 브라우저 기반 쉘입니다.
+ [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html)는 데이터 스토어와 데이터 스트림 간에 데이터를 안정적으로 분류, 정리, 보강, 이동할 수 있는 완전 관리형 ETL 서비스입니다.
+ [Amazon Keyspaces(Apache Cassandra용)](https://docs.aws.amazon.com/keyspaces/latest/devguide/what-is-keyspaces.html)는 AWS 클라우드에서 Cassandra 워크로드를 마이그레이션, 실행, 확장할 수 있도록 지원하는 관리형 데이터베이스 서비스입니다.

**코드**

이 패턴의 코드는 GitHub [CQLReplicator](https://github.com/aws-samples/cql-replicator/tree/main/glue) 리포지토리에서 확인할 수 있습니다.

## 모범 사례
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-best-practices"></a>
+ 마이그레이션에 필요한 AWS Glue 리소스를 확인하려면 소스 Cassandra 테이블의 행 수를 추정합니다. 예를 들어 84GB 디스크가 있는 0.25 DPU당 250K 행(vCPUs, 메모리 4GB).
+ CQLReplicator를 실행하기 전에 Amazon Keyspaces 테이블을 사전 워밍합니다. 예를 들어 8개의 CQLReplicator 타일(AWS Glue 작업)은 초당 최대 22K WCUs를 쓸 수 있으므로 대상은 초당 최대 25\$130K WCUs까지 사전 워밍되어야 합니다.
+ AWS Glue 구성 요소 간에 통신하려면 보안 그룹의 모든 TCP 포트에 자기 참조 인바운드 규칙을 사용합니다.
+ 증분 트래픽 전략을 사용하여 시간이 지남에 따라 마이그레이션 워크로드를 분산합니다.

## 에픽
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-epics"></a>

### CQLReplicator 배포
<a name="deploy-cqlreplicator"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 대상 키스페이스와 테이블을 생성합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue.html) | 앱 소유자, AWS 관리자, DBA, 앱 개발자 | 
| Cassandra에 연결하도록 Cassandra 드라이버를 구성합니다. | 다음 구성 스크립트를 사용합니다.<pre>Datastax-java-driver {<br />  basic.request.consistency = "LOCAL_QUORUM"<br />  basic.contact-points = ["127.0.0.1:9042"]<br />   advanced.reconnect-on-init = true<br />   basic.load-balancing-policy {<br />        local-datacenter = "datacenter1"<br />}<br />advanced.auth-provider = {<br />       class = PlainTextAuthProvider<br />       username = "user-at-sample"<br />       password = "S@MPLE=PASSWORD="<br />}<br />}</pre>위 스크립트는 Spark Cassandra Connector를 사용합니다. 자세한 내용은 [Cassandra](https://docs.datastax.com/en/developer/java-driver/4.17/manual/core/configuration/reference/)에 대한 참조 구성을 참조하세요. | DBA | 
| Amazon Keyspaces에 연결하도록 Cassandra 드라이버를 구성합니다. | 다음과 같은 구성 스트립트를 사용합니다.<pre>datastax-java-driver {<br />basic {<br />  load-balancing-policy {<br />    local-datacenter = us-west-2<br />        }<br />  contact-points = [<br />            "cassandra.us-west-2.amazonaws.com:9142"<br />        ]<br />  request {<br />  page-size = 2500<br />  timeout = 360 seconds<br />  consistency = LOCAL_QUORUM<br />        }<br />    }<br />advanced {<br /> control-connection {<br />  timeout = 360 seconds<br />        }<br /> session-leak.threshold = 6<br /> connection {<br /> connect-timeout = 360 seconds<br /> init-query-timeout = 360 seconds<br /> warn-on-init-error = false<br />        }<br /> auth-provider = {<br />  class = software.aws.mcs.auth.SigV4AuthProvider<br />  aws-region = us-west-2<br /> }<br /><br /> ssl-engine-factory {<br />  class = DefaultSslEngineFactory<br />        }<br />    }<br />}</pre>위 스크립트는 Spark Cassandra Connector를 사용합니다. 자세한 내용은 [Cassandra](https://docs.datastax.com/en/developer/java-driver/4.17/manual/core/configuration/reference/)에 대한 참조 구성을 참조하세요. | DBA | 
| AWS Glue 작업에 대한 IAM 역할을 생성합니다. | AWS Glue를 신뢰할 수 있는 엔터티로 사용하여 `glue-cassandra-migration`라는 새 AWS 서비스 역할을 생성합니다.는 S3 버킷 및 Amazon Keyspaces에 대한 읽기 및 쓰기 액세스 권한을 제공해야 `glue-cassandra-migration` 합니다. S3 버킷에는 .jar 파일, Amazon Keyspaces 및 Cassandra에 대한 구성 파일, 중간 Parquet 파일이 포함되어 있습니다. 예를 들어 , `AWSGlueServiceRole` `AmazonS3FullAccess`및 `AmazonKeyspacesFullAccess` 관리형 정책이 포함되어 있습니다. | DevOps | 
| AWS CloudShell에서 CQLReplicator를 다운로드합니다. | 다음 명령을 실행하여 프로젝트를 홈 폴더에 다운로드합니다.<pre>git clone https://github.com/aws-samples/cql-replicator.git<br />cd cql-replicator/glue<br /># Only for AWS CloudShell, the bc package includes bc and dc. Bc is an arbitrary precision numeric processing arithmetic language<br />sudo yum install bc -y</pre> |  | 
| 참조 구성 파일을 수정합니다. | 프로젝트 폴더의 `../glue/conf` 디렉터리에 `CassandraConnector.conf` 및 `KeyspacesConnector.conf`를 복사합니다. | DevOps | 
| 마이그레이션 프로세스를 시작합니다. | 다음 명령은 CQLReplicator 환경을 초기화합니다. 초기화에는 .jar 아티팩트를 복사하고 AWS Glue 커넥터, S3 버킷, AWS Glue 작업, `migration` 키스페이스 및 `ledger` 테이블을 생성하는 작업이 포함됩니다.<pre>cd cql-replicator/glue/bin<br />./cqlreplicator --state init --sg '"sg-1","sg-2"' \ <br />                --subnet "subnet-XXXXXXXXXXXX" \ <br />                --az us-west-2a --region us-west-2 \ <br />                --glue-iam-role glue-cassandra-migration \ <br />                --landing-zone s3://cql-replicator-1234567890-us-west-2<br /></pre>이 스크립트에는 다음 파라미터가 포함되어 있습니다.[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue.html) | DevOps | 
| 배포를 검증합니다. | 이전 명령을 실행한 후 AWS 계정에는 다음이 포함되어야 합니다.[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue.html) | DevOps | 

### CQLReplicator 실행
<a name="run-cqlreplicator"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 마이그레이션 프로세스를 시작합니다. | AWS Glue에서 CQLReplicator를 작동하려면 `--state run` 명령을 사용한 다음 일련의 파라미터를 사용해야 합니다. 이러한 파라미터의 정확한 구성은 주로 고유한 마이그레이션 요구 사항에 따라 결정됩니다. 예를 들어 TTL(Time to Live) 값 및 업데이트를 복제하도록 선택하거나 1MB를 초과하는 객체를 Amazon S3로 오프로드하는 경우 이러한 설정이 달라질 수 있습니다.Cassandra 클러스터에서 Amazon Keyspaces로 워크로드를 복제하려면 다음 명령을 실행합니다.<pre>./cqlreplicator --state run --tiles 8  \<br />                --landing-zone s3://cql-replicator-1234567890-us-west-2 \ <br />                --region us-west-2 \                              <br />                --src-keyspace source_keyspace \ <br />                --src-table source_table \  <br />                --trg-keyspace taget_keyspace \<br />                --writetime-column column_name \<br />                --trg-table target_table --inc-traffic</pre>소스 키스페이스와 테이블은 Cassandra 클러스터`source_keyspace.source_table`에 있습니다. 대상 키스페이스과 테이블은 Amazon Keyspaces의 `target_keyspace.target_table`에 있습니다. 파라미터는 증분 트래픽이 많은 요청으로 Cassandra 클러스터 및 Amazon Keyspaces에 과부하를 가하는 것을 방지하는 `--inc-traffic` 데 도움이 됩니다.업데이트를 복제하려면 명령줄`--writetime-column regular_column_name`에를 추가합니다. 일반 열은 쓰기 타임스탬프의 소스로 사용됩니다. | DevOps | 

### 마이그레이션 프로세스 모니터링
<a name="monitor-the-migration-process"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 이전 마이그레이션 단계에서 마이그레이션된 Cassandra 행을 검증합니다. | 채우기 단계에서 복제된 행 수를 얻으려면 다음 명령을 실행합니다.<pre>./cqlreplicator --state stats \<br />                --landing-zone s3://cql-replicator-1234567890-us-west-2 \  <br />                --src-keyspace source_keyspace --src-table source_table --region us-west-2</pre> | DevOps | 

### 마이그레이션 프로세스 중지
<a name="stop-the-migration-process"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| `cqlreplicator` 명령 또는 AWS Glue 콘솔을 사용합니다. | 마이그레이션 프로세스를 정상적으로 중지하려면 다음 명령을 실행합니다.<pre>./cqlreplicator --state request-stop --tiles 8 \                         <br />                --landing-zone s3://cql-replicator-1234567890-us-west-2 \     <br />                --region us-west-2 \                     <br />                --src-keyspace source_keyspace --src-table source_table</pre>마이그레이션 프로세스를 즉시 중지하려면 AWS Glue 콘솔을 사용합니다. | DevOps | 

### 정리
<a name="clean-up"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 배포된 리소스를 삭제합니다. | 다음 명령은 AWS Glue 작업, 커넥터, S3 버킷 및 Keyspaces 테이블을 삭제합니다. `ledger` <pre>./cqlreplicator --state cleanup --landing-zone s3://cql-replicator-1234567890-us-west-2</pre> | DevOps | 

## 문제 해결
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-troubleshooting"></a>


| 문제 | Solution | 
| --- | --- | 
| AWS Glue 작업이 실패하여 메모리 부족(OOM) 오류를 반환했습니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue.html) | 

## 관련 리소스
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-resources"></a>
+ [AWS Glue를 사용하는 CQLReplicator README.MD](https://github.com/aws-samples/cql-replicator/blob/main/glue/README.MD)
+ [AWS Glue 설명서](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html)
+ [Amazon Keyspaces 설명서](https://docs.aws.amazon.com/keyspaces/latest/devguide/what-is-keyspaces.html)
+ [Apache Cassandra](https://cassandra.apache.org/_/index.html)

## 추가 정보
<a name="migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue-additional"></a>

**마이그레이션 고려 사항**

AWS Glue를 사용하여 Cassandra 워크로드를 Amazon Keyspace로 마이그레이션하는 동시에 마이그레이션 프로세스 중에 Cassandra 소스 데이터베이스가 완전히 기능하도록 유지할 수 있습니다. 복제가 완료되면 Cassandra 클러스터와 Amazon Keyspaces 간의 복제 지연 시간(몇 분 미만)을 최소화하면서 애플리케이션을 Amazon Keyspaces로 전환하도록 선택할 수 있습니다. 데이터 일관성을 유지하기 위해 유사한 파이프라인을 사용하여 Amazon Keyspaces에서 데이터를 Cassandra 클러스터로 다시 복제할 수도 있습니다.

**쓰기 단위 계산**

한 시간 동안 행 크기가 1KiB인 500,000,000을 쓰는 경우를 예로 들어 보겠습니다. 필요한 Amazon Keyspaces 쓰기 단위(WCU)의 총 수는 다음 계산을 기반으로 합니다.

`(number of rows/60 mins 60s) 1 WCU per row = (500,000,000/(60*60s) * 1 WCU) = 69,444 WCUs required`

초당 69,444WCU는 1시간 요금이지만, 오버헤드에 대비하여 약간의 여유를 추가할 수 있습니다.  예를 들어, `69,444 * 1.10 = 76,388 WCUs`는 오버헤드가 10% 입니다.

**CQL을 사용하여 키스페이스 생성**

CQL을 사용하여 키스페이스를 생성하려면 다음 명령을 실행합니다.

```
CREATE KEYSPACE target_keyspace WITH replication = {'class': 'SingleRegionStrategy'}
CREATE TABLE target_keyspace.target_table ( userid uuid, level text, gameid int, description text, nickname text, zip text, email text, updatetime text, PRIMARY KEY (userid, level, gameid) ) WITH default_time_to_live = 0 AND CUSTOM_PROPERTIES = {'capacity_mode':{ 'throughput_mode':'PROVISIONED', 'write_capacity_units':76388, 'read_capacity_units':3612 }} AND CLUSTERING ORDER BY (level ASC, gameid ASC)
```