티스토리 뷰

spring data redis 를 사용하여 운영 중 장애를 맞고 알게된, 미리 알았으면 좋았을 것들에 대해 기록

Topology 설정의 중요성

Elasticache 를 cluster mode 로 replica node 를 생성하고 multi az 설정을 하여 사용 하고 있었다. 이렇게 설정해 놓으면 안전하겠지 생각했지만 빠진게 있었다. 바로 topology 설정이다.
얼마 전 장애가 났다. Master node 에 문제가 생겼고, fail over 처리를 하여 replica 중 하나가 master 로 선출 되어 교체 되었고, 새로운 replica 노드가 생성되었다.
이 모든게 수분 내에 이루어졌고 문제가 해결 됐다고 생각했지만 우리 서버는 그 후로도 몇분간 장애를 내뱉었다.
topology 설정을 안했기 때문이다. 이미 master node(중 하나) 는 없어졌는데 처음에 connection 을 맺을 때 들고온 cluster 구성 정보를 가지고 write 요청을 계속 하니 앱 단에선 장애가 해결되지 않고 잇었다.

단일 connection 공유

lettuce connector 를 사용 할 때 LettuceConnectionFactory 로 생성한 모든 LettuceConnection 은 non-blocking 이나 non-transactional 한 오퍼레이션에 대해 동일한 thread-safe 한 native connection 을 사용한다.
문서 참조

 There are also a few Lettuce-specific connection parameters that can be tweaked. 
 By default, all `LettuceConnection` instances created by the `LettuceConnectionFactory` 
 share the same thread-safe native connection for all non-blocking and non-transactional operations. 
 To use a dedicated connection each time, set `shareNativeConnection` to `false`. 
 `LettuceConnectionFactory` can also be configured to use a `LettucePool` for pooling blocking 
 and transactional connections or all connections if `shareNativeConnection` is set to `false`.

LettuceConnectionFactory 로 여러 connection 을 생성하여 사용하고 있었고, 분명히 가이드 따라서 topology 설정을 했는데 제대로 동작하지 않아 엄한 곳을 의심하며 삽질을 많이 했는데,,, 이런 이유가 있었다.

읽는건 replica 에서?

LettuceClientConfiguration 를 사용 하여 read/write 전략을 세팅 할 수 있다.
처음엔 단순히 read 는 replica 에서 해야 하는거 아니야? 라는 생각을 가지고 있었지만 무조건 어떤 전략이 좋다 이런건 없고 redis mode(cluster / standalone 등등), 서비스에서 실행되는 read / write 비율, 실패를 얼마나 감내할 수 있는지에 따라 상황에 맞는 전략을 선택하는게 중요하다고 생각이 바뀌었다.

Connection 은 Lazy 하게

앱이 처음 부팅 될 때 connection 을 맺고 시작하는줄 알았다. 그냥... 당연히 그럴 줄 알았지.
그런데 앱이 부팅 되고 처음 redis에 접근이(?) 이루어질 때 connection 이 맺어진다. 그래서 앱 부팅 되고 첫 질의는 시간이 오래걸린다. 커넥션을 맺어야해서.

'Redis' 카테고리의 다른 글

Redis Transactions  (0) 2022.09.28
Redis Pub/Sub  (0) 2022.08.02
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday