티스토리 뷰

반응형

MySQL 인스턴스를 받아서 Airflow 를 연동해보는 아래와 같은 오류가 발생했다. 참고로 이 오류는 MySQL 가 group-replication 으로 세팅되어있을때 나타나는 현상이다.

 

구글링을 해보면 이 오류의 일반적인 케이스는 PKEY 를 지정안한 Table 을 사용할때 나타난 문제였지만, 나는 이 문제가 아니라 "FOREIGN KEY ... REFERENCES .. ON DELETE CASCADE" 제약조건이 Airflow 에서 자동생성되는 테이블에 존재했기 때문에 나타난 문제였다. 그 원인과 해결방법을 알아보도록 하자.

sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (3098, 'The table does not comply with the requirements by an external plugin.')
[SQL: UPDATE task_instance SET state=%s, updated_at=%s, trigger_id=%s, next_method=%s, next_kwargs=%s WHERE task_instance.state = %s AND task_instance.trigger_timeout < %s]
[parameters: (<TaskInstanceState.SCHEDULED: 'scheduled'>, datetime.datetime(2023, 4, 28, 2, 53, 58, 572390), None, '__fail__', '{"__var": {"error": "Trigger/execution timeout"}, "__type": "dict"}', <TaskInstanceState.DEFERRED: 'deferred'>, datetime.datetime(2023, 4, 28, 2, 53, 58, 566636, tzinfo=Timezone('UTC')))]
(Background on this error at: https://sqlalche.me/e/14/e3q8)

원인

MySQL 에서 Group Replication 으로 세팅되어있다면, 필요조건과 제약조건를 모두 만족해야한다.

구글링해서 나오는 pkey 문제는 필요조건이고, 내가 겪은 문제는 제약조건에 문제가 되기 때문이었다.

로그를 뒤져보면 airflow 에서 insert/delete 쿼리가 실패하는 문제가 되는 쿼리중 하나의 생성쿼리를 확인해보니, 아래와 같이 "FOREIGN KEY ... REFERENCES .. ON DELETE CASCADE" 와 같은 제약조건이 존재했다. 실제로 해당 제약조건을 제거한 임시테이블을 만들어서 테스트해보면 문제가 없었다.

CREATE TABLE `dag_warning` (
  `dag_id` varchar(250) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `warning_type` varchar(50) COLLATE utf8mb4_general_ci NOT NULL,
  `message` text COLLATE utf8mb4_general_ci NOT NULL,
  `timestamp` timestamp(6) NOT NULL,
  PRIMARY KEY (`dag_id`,`warning_type`),
  CONSTRAINT `dcw_dag_id_fkey` FOREIGN KEY (`dag_id`) REFERENCES `dag` (`dag_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci

해결방법

가장 쉬운건 replication 방식을 변경하는것일것이고, 관련된 세팅을 변경하는것이다.

Group Replication 이 적용된 MySQL 에서 "FOREIGN KEY ... REFERENCES .. ON DELETE CASCADE" 조건이 있는 테이블을 사용하지 못하는 이유는 아래와 같은 이유 때문이다.

Foreign Keys with Cascading Constraints. Multi-primary mode groups (members all configured with group_replication_single_primary_mode=OFF) do not support tables with multi-level foreign key dependencies, specifically tables that have defined CASCADING foreign key constraints. This is because foreign key constraints that result in cascading operations executed by a multi-primary mode group can result in undetected conflicts and lead to inconsistent data across the members of the group. Therefore we recommend setting group_replication_enforce_update_everywhere_checks=ON on server instances used in multi-primary mode groups to avoid undetected conflicts.

In single-primary mode this is not a problem as it does not allow concurrent writes to multiple members of the group and thus there is no risk of undetected conflicts.

즉, 이 말은 설명에 있는 기본 설정값을 쓰지 않고 관련된 속성을 인위적으로 해제 혹은 활성화 하면 해결이 된다는말이다.

나는 해당 문제를 담당자에게 고쳐달라고 요청후 사용이 가능했다.

 

만약, Replication 종류에 따른 이해를 하면 이해하는데 도움이 될텐데, 이건 아래 링크에 설명이 잘 되어있으니 읽어보도록 하자.

https://hoing.io/archives/5006

 

MySQL - InnoDB Cluster(클러스터) - (5) - 그룹 복제 모드 별 상세 내용 - 트랜잭션 일관성 보장

안녕하세요 이번 포스팅에서는 그룹 복제 모드 중에서 Multi Primary 와 Single Primary 각각에 대해서 조금 더 자세하게 내용을 확인 해보도록 하겠으며, 그룹 복제에서의 트랜잭션 일관성 보장 관련

hoing.io

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함