48
MongoDB 한국 사용자 그룹 [email protected] MONGO DB 잡학상식

Mongo db 잡학상식

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Mongo db 잡학상식

MongoDB 한국 사용자 그룹

[email protected]

MONGO DB 잡학상식

Page 2: Mongo db 잡학상식

NoSQL의 종류

Page 3: Mongo db 잡학상식

NoSQL의 종류

Key-Value Store Column-Oriented Store Document-Orient Store

Page 4: Mongo db 잡학상식

NoSQL의 종류

Key-Value Store Column-Oriented Store Document-Orient Store

MongoDB

Page 5: Mongo db 잡학상식

MongoDB 의 특징

Page 6: Mongo db 잡학상식

MongoDB의 주요 특징

Document-Oriented Full Index Support Querying

Page 7: Mongo db 잡학상식

MongoDB의 주요 특징

Document-Oriented Full Index Support Querying Easy To Use

Page 8: Mongo db 잡학상식

Replication

Page 9: Mongo db 잡학상식

Replication

Page 10: Mongo db 잡학상식

Master/Slave

장애시 Master가 자동으로 선출되지 않는다.

Page 11: Mongo db 잡학상식

Replica Set

Automated FailOver Data Redundancy Read Scaling(Low Consistency) Maintenance Disaster Recovery

Page 12: Mongo db 잡학상식

Replica Set

Page 13: Mongo db 잡학상식

OpLog Write Operation 마다 증가. (insert/update/delete/index/etc) Size 가 고정되어 있다.(Collection) FailOver, Replication 의 핵심

Page 14: Mongo db 잡학상식

OpTime class OpTime { unsigned i; unsigned secs; }

Page 15: Mongo db 잡학상식

Idempotent

INC A + 1 이런 형태가 아니라

SET A = 2 이런 형태

Page 16: Mongo db 잡학상식

HeartBeat

Primary

- 자신을 포함한 절반 이상의 노드가 응답하지 않으면 Secondary 가 된다

Page 17: Mongo db 잡학상식

HeartBeat

Secondary

- Primary가 응답이 없으면, Voting을 요청한다.

Page 18: Mongo db 잡학상식

Primary

• Master • Only 1 server in a time

Page 19: Mongo db 잡학상식

Secondary

• Can be thought of as a slave in the cluster; varies over time

Page 20: Mongo db 잡학상식

RECOVERING

• getting back in sync before entering Secondary mode.

Page 21: Mongo db 잡학상식

Standard

• Primary 가 될 수 있는 노드

Page 22: Mongo db 잡학상식

Passive

• Replica Set 에는 참여하지만 Primary가 될 수 없는 노드

• Priority가 0인 노드들

Page 23: Mongo db 잡학상식

Arbiter

• Replica Set에는 참여하지 않고 투표만을 위한 노드, 데이터는 전달 받지 않는다.

Page 24: Mongo db 잡학상식

Replication Steps

Call Write Operation

Apply Database

Write OpLog

Tailing Primary OpLog

Write OpLog

Apply Database

Primary Secondary

Page 25: Mongo db 잡학상식

General View

Page 26: Mongo db 잡학상식

Strong Consistency Primary

Secondary

Secondary

Driver

Write

Read

Page 27: Mongo db 잡학상식

Eventual Consistency Primary

Secondary

Secondary

Driver

Write

Read

Read

Page 28: Mongo db 잡학상식

FailOver

Page 29: Mongo db 잡학상식

Automated Leader Election

Primary

Primary

Secondary

Driver

Write

Read

Read

Page 30: Mongo db 잡학상식

Recovery

Secondary

Primary

Secondary

Driver

Write

Read

Read

Page 31: Mongo db 잡학상식

Recovery

Page 32: Mongo db 잡학상식

If OpLog Size can save 20H

Primary

Primary

Secondary

Driver

Write

Read

Read

Die 1 Hour

Page 33: Mongo db 잡학상식

Start Replication

Secondary

Primary

Secondary

Driver

Write

Read

Read

Replication

Page 34: Mongo db 잡학상식

If Downtime is 21 Hour

Primary

Primary

Secondary

Driver

Write

Read

Read

Die 21 Hour

Page 35: Mongo db 잡학상식

Start Replication

Stale

Primary

Secondary

Driver

Write

Read

Need Full Resync

Page 36: Mongo db 잡학상식

Voting

Page 37: Mongo db 잡학상식

Triggering an Election

• 하나의 노드에서 Primary 가 연결이 안될때.(단 해당노드는 Arbiter가 아니어야 함. Heartbeat(timeout:20))

• 해당 노드의 priority 가 다른 노드보다 크거나 같을 경우.

Page 38: Mongo db 잡학상식

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.

Page 39: Mongo db 잡학상식

Consensus Vote

과반 수 이상의 득표가 있어야 선출

Page 40: Mongo db 잡학상식

startReplication

repl.cpp

startRepSets

repl/rs.cpp

_go

repl/rs.cpp

startThreads

repl/rs.cpp

msgCheckNewState

repl/manager.cpp

Source Flows

Page 41: Mongo db 잡학상식

TIPS

Page 42: Mongo db 잡학상식

1. 64bit OS를 사용하라.

MongoDB는 메모리를 많이 사용해야 한다.(MemoryMapped File) 32bit 에서는 2.5GB 짜리 DB파일만 생성 가능

Page 43: Mongo db 잡학상식

2. 많은 메모리를 사용하라.

Working Set이 메모리에 모두 들어가 있어야 빠른 속도를 보장한다.

Page 44: Mongo db 잡학상식

3. ReplSet, Journaling

안전성을 위해서 Replica Set과 Journaling을 기본으로 사용한다.

Page 45: Mongo db 잡학상식

4. 최신 버전을 사용하자.

1.8.x 보다는 2.0.x 버전을… 같은 버전에서도 최신 버전을… Global Write Lock이 2.0.x에서 좀 더 개선됨.

Page 46: Mongo db 잡학상식

4. Scale Up > Shard

샤딩 보다는 Scale UP을 먼저 하자. 메모리 증가, HDD -> SDD 샤드키를 잘 만드는 것보다 이게 더 쉽다.

Page 47: Mongo db 잡학상식

Thank You!

Page 48: Mongo db 잡학상식

그 외의 이야기들…