NoSQL의 종류
NoSQL의 종류
Key-Value Store Column-Oriented Store Document-Orient Store
NoSQL의 종류
Key-Value Store Column-Oriented Store Document-Orient Store
MongoDB
MongoDB 의 특징
MongoDB의 주요 특징
Document-Oriented Full Index Support Querying
MongoDB의 주요 특징
Document-Oriented Full Index Support Querying Easy To Use
Replication
Replication
Master/Slave
장애시 Master가 자동으로 선출되지 않는다.
Replica Set
Automated FailOver Data Redundancy Read Scaling(Low Consistency) Maintenance Disaster Recovery
Replica Set
OpLog Write Operation 마다 증가. (insert/update/delete/index/etc) Size 가 고정되어 있다.(Collection) FailOver, Replication 의 핵심
OpTime class OpTime { unsigned i; unsigned secs; }
Idempotent
INC A + 1 이런 형태가 아니라
SET A = 2 이런 형태
HeartBeat
Primary
- 자신을 포함한 절반 이상의 노드가 응답하지 않으면 Secondary 가 된다
HeartBeat
Secondary
- Primary가 응답이 없으면, Voting을 요청한다.
Primary
• Master • Only 1 server in a time
Secondary
• Can be thought of as a slave in the cluster; varies over time
RECOVERING
• getting back in sync before entering Secondary mode.
Standard
• Primary 가 될 수 있는 노드
Passive
• Replica Set 에는 참여하지만 Primary가 될 수 없는 노드
• Priority가 0인 노드들
Arbiter
• Replica Set에는 참여하지 않고 투표만을 위한 노드, 데이터는 전달 받지 않는다.
Replication Steps
Call Write Operation
Apply Database
Write OpLog
Tailing Primary OpLog
Write OpLog
Apply Database
Primary Secondary
General View
Strong Consistency Primary
Secondary
Secondary
Driver
Write
Read
Eventual Consistency Primary
Secondary
Secondary
Driver
Write
Read
Read
FailOver
Automated Leader Election
Primary
Primary
Secondary
Driver
Write
Read
Read
Recovery
Secondary
Primary
Secondary
Driver
Write
Read
Read
Recovery
If OpLog Size can save 20H
Primary
Primary
Secondary
Driver
Write
Read
Read
Die 1 Hour
Start Replication
Secondary
Primary
Secondary
Driver
Write
Read
Read
Replication
If Downtime is 21 Hour
Primary
Primary
Secondary
Driver
Write
Read
Read
Die 21 Hour
Start Replication
Stale
Primary
Secondary
Driver
Write
Read
Need Full Resync
Voting
Triggering an Election
• 하나의 노드에서 Primary 가 연결이 안될때.(단 해당노드는 Arbiter가 아니어야 함. Heartbeat(timeout:20))
• 해당 노드의 priority 가 다른 노드보다 크거나 같을 경우.
Picking Primary 1. get maxLocalOpOrdinal from each server. 2. if a majority of servers are not up (from this
server's POV), remain in Secondary mode and stop.
3. if the last op time seems very old, stop and await human intervention.
4. else, using a consensus protocol, pick the server with the highest maxLocalOpOrdinal as the Primary.
Consensus Vote
과반 수 이상의 득표가 있어야 선출
startReplication
repl.cpp
startRepSets
repl/rs.cpp
_go
repl/rs.cpp
startThreads
repl/rs.cpp
msgCheckNewState
repl/manager.cpp
Source Flows
TIPS
1. 64bit OS를 사용하라.
MongoDB는 메모리를 많이 사용해야 한다.(MemoryMapped File) 32bit 에서는 2.5GB 짜리 DB파일만 생성 가능
2. 많은 메모리를 사용하라.
Working Set이 메모리에 모두 들어가 있어야 빠른 속도를 보장한다.
3. ReplSet, Journaling
안전성을 위해서 Replica Set과 Journaling을 기본으로 사용한다.
4. 최신 버전을 사용하자.
1.8.x 보다는 2.0.x 버전을… 같은 버전에서도 최신 버전을… Global Write Lock이 2.0.x에서 좀 더 개선됨.
4. Scale Up > Shard
샤딩 보다는 Scale UP을 먼저 하자. 메모리 증가, HDD -> SDD 샤드키를 잘 만드는 것보다 이게 더 쉽다.
Thank You!
그 외의 이야기들…
Recommended