Aurora Mysql Writer/Reader 분산처리시 에러

0

안녕하세요. 가입후 처음으로 글을 올립니다. 우선 모든분들 반갑습니다. 아직 초보라서 모르는 부분이 많으니 이해바라며 잘 부탁드립니다. 저는 현재 Mysql 8.0.23 호환 Aurora 를 사용중입니다. DB 서버부하 분산시키기 위해 Spring Data JPA에서 주로 사용하는 '@Transactional(readOnly=true/false)' 를 적용하였습니다. 테스트 과정에서 대부분은 'readOnly' 설정에 따라 해당 엔드포인트로 접속되고 쿼리실행도 잘 되는 것을 workbench 와 cloudwatch 로그로 확인했습니다. 그런데, @Service 의 함수내에서 하나의 테이블에서 select 해온 결과를 가져온 후(@Transactional(readOnly=true) 사용), 동일한 테이블의 특정 컬럼값을 Update (@Transactional(readOnly=false) 사용)하려고 하면 'Read-only' 에서는 update 쿼리를 실행할 수 없다는 에러가 발생하고 있습니다. 이런 경우 어떻게 해결하면 될까요? 도와주세요.

Hello, I'm posting for the first time since I signed up. First of all, nice to meet you all. I'm still a beginner, so there are many things I don't know, so please understand and take good care of me.

I am currently using a Mysql 8.0.23 compatible Aurora. We applied '@Transactional(readOnly=true/false)' which is mainly used by Spring Data JPA to distribute DB server load. During the test, most of them were confirmed by workbench and cloudwatch logs to connect to the endpoint and execute queries according to the 'readOnly' setting. However, after getting the results selected from one table within the function of @Service (use @Transactional(readOnly=true), If you try to update a specific column value in the same table (use @Transactive(readOnly=false), 'Read-only' is getting an error that the update query cannot be run. What should we do in this case? Please help me.

질문됨 9달 전454회 조회
1개 답변
1
수락된 답변

Aurora MYSQL 의 경우 Writer 노드와 Reader 노드로 구성되어 있습니다. Aurora DB 를 접속 하는 것은 Cluster Endpoint, Reader Endpoint , Customer Endpoint 를 통해서 접속할 수 있습니다.

[+] https://docs.aws.amazon.com/ko_kr/AmazonRDS/latest/AuroraUserGuide/Aurora.Overview.Endpoints.html#Aurora.Overview.Endpoints.Types

쓰기 작업(트랜잭션) 의 경우 Cluster Endpoint 로 Writer 노드에서 작업이 일어날 수 있으며 단순히 조회작업의 경우 Reader Endpoint 를 통해서 접속된 Reader 에서 이루어집니다.

@Transactional(readOnly=true) 로 정의하는 경우에는 자동으로 Reader 노드로 연결이 됩니다. 따라서 트랜잭션(UPDATE, DELETE, INSERT) 작업을 수행할 수 없습니다.

트랜잭션 작업을 하기 위해서는 다음과 같이 JDBC URL 에 두개의 Endpoint 가 정의되어 있는지 확인합니다

예) jdbc-url: jdbc:mysql:aurora://클러스터엔드포인트:포트, 리더엔드포인트:포트

그리고 다음과 같이 기술해서 사용합니다. @Transactional public void update (Long id, String Name) ...

AWS
지원 엔지니어
답변함 9달 전
  • 친절한 답변 감사합니다. 내용은 그간 제가 구글링을 통해 살펴본 것과 유사해서 이해는 하고 있습니다. 일단 제가 작업한 일부 소스를 공유드리는게 더 나을 것 같이 공유를 드립니다. 괜찮으시다면 소스보시고 다시한번 의견 부탁드립니다. *기타문의: 답변주신 내용에 대해 재문의할 경우 댓글, 답변추가중 어떤 것을 사용해야 하나요?

    Thank you for your kind answer. I understand the content because it is similar to what I have looked at through Googleing. I think it would be better to share some of the sources that I worked on. If you don't mind, please look at the sauce and give me your opinion again. *Other inquiries: If I ask you again about your answer, which one should I use, comment or reply? [ source ] https://bit.ly/3rOIoh6

  • 우연히도 원인을 찾게 되어 문제를 해결하였습니다. 찾기는 어려웠지만 상위에서 readOnly=true 가 선언되어 이후 readOnly=false가 동작하지 않았었습니다.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인