hyoseok0 / share

문제 해결 사례 공유
0 stars 0 forks source link

[mongoDB] write 이후 read 시, write 하기 전 데이터가 조회되는 현상 해결 #1

Open hyoseok0 opened 2 years ago

hyoseok0 commented 2 years ago

개괄

문제 상황

예시

  1. 주문내역 저장
  2. 저장한 주문내역의 사용자와 상품에 대한 전체 주문 건수, 최근주문내역을 계산 ** 이때 직전에 저장한 주문내역이 조회되지 않는 경우가 있음

원인

구분
write concern w:1, j:true
read concern majority
read preference primary

해결

구분
write concern w:majority, j: true
read concern majority
read preference primary

해결 상세


상세

원인

write 이후 read 시, write 한 데이터를 조회하려면 mongoDB connect 설정이 아래와 같아야 함

구분
write concern w:majority, j:true
read concern majority
구분
write concern w:majority, j: true
read concern majority
read preference primary

현재 shopping-server 설정은 아래와 같고, write concern 조건이 맞지 않습니다.

구분
write concern w:1, j:true
read concern majority
read preference secondaryPreferred 가 기본. primary 는 필요 시 설정

참고) 상태값 설명

원인 상세

해결

write 이후 read 시, write 한 데이터를 조회하려면 mongoDB connect 설정이 아래와 같이 설정

구분
write concern w:majority, j:true
read concern majority
구분
write concern w:majority, j: true
read concern majority
read preference primary

해결 상세


참고자료

hyoseok0 commented 2 years ago

DB 설정 변경 후, write 이후 read 시, 직전에 write 한 데이터가 조회되는 걸 어떻게 검증할까?

mongodb_3