DBAtlas · 데이터베이스 운영 아틀라스

replica set 롤링 인덱스 빌드 (멤버별)

MongoDB유지보수

명령어

// 1) Shut down a SECONDARY; comment out replication.replSetName and start it standalone on another port:
//    mongod --config /etc/mongod.conf --port 27217 --setParameter disableLogicalSessionCacheRefresh=true
// 2) Build the index on the standalone member:
db.getSiblingDB("shop").musteri.createIndex({ email: 1 }, { name: "idx_email" })
// 3) Restart with the normal configuration; wait until it is SECONDARY and lag has closed:
rs.printSecondaryReplicationInfo()
// 4) When all secondaries are done, step down the primary and apply steps 1-3 to the old primary:
rs.stepDown(120, 30)

하는 일

멤버를 일시적으로 set 밖에서 standalone으로 실행하여 각 멤버에 따로 인덱스를 빌드한다. primary는 빌드 부하를 전혀 지지 않는다.

사용 시점

매우 큰 컬렉션에서 기본 분산 빌드가 primary와 복제 지연에 주는 영향을 받아들일 수 없을 때.

주의

각 멤버의 유지보수 시간은 oplog window보다 짧아야 한다. 그렇지 않으면 멤버가 돌아올 때 too stale 상태가 된다. 롤링 방식으로 unique 인덱스를 빌드할 때는 빌드 전체 동안 컬렉션 쓰기를 중지한다. 그렇지 않으면 일부 멤버에 위반 문서가 생길 수 있다. 애플리케이션이 접속하지 않도록 standalone 멤버는 다른 포트로 시작한다.

DBAtlas에서 열기 →

관련 항목