SlideShare a Scribd company logo
분산 트랙젝션
유승기, Software Engineer, MongoDB
큰 힘에는 책임이 따른다.
여러분들이 어떤 생각을
가지고 계시는 지 알고 있습니다.
하지만, 사실은…
MongoDB 는 ACID 를 준수 합니다.
(물론, 여러 샤드에서도 말이죠.)
트랜잭션을 지원함으로써 개발이 쉬워집니다.
트랜잭션 상태에 대해 개발자가 걱정할 필요가 없음
단일 명령문이 실패할 경우 Rollback/Abort 가 자동 처리
읽기와 쓰기의 특정 시점에서 일관성 유지
def insertDocuments(s):
s.client.db.col.insert_one({'abc': 1}, session=s)
s.client.db.col.insert_one({'xyz': 999}, session=s)
with client.start_session() as s:
s.with_transaction(insertDocuments);
New API MongoDB 4.2!
New in MongoDB 4.2 - Cross Shard Transactions
트랜잭션 보증
Multi- Collection
Database
Statement
Document
Shard
All or nothing execution
TXN
Application
MongoDB
Uncommitted Writes
{ Document 1 } { Document 2 }
{ Document 3 }
Committed Writes
Snapshot Isolation
100 101 102 103 104 105 106 107 108 109 110 111
Snapshot
102
Snapshot
108
Read Your Own Writes
Operation
Read
TXN
{_id: “OWNER12345”,
name: { first: “Aly”,
last: “Cabral”},
accountType: “Paid”,
pets: [ { type: “Dog”,
name: “Lady”}],
contact: { phoneNumber: 8008675309},
Address: { city: “New York”,
street: “94th”,
zipecode: 10025}}
Uncommitted Writes
street: “92nd”
Address.street = 94th
Address.street = 92nd
트랜잭션 가이드라인
기존 JSON 기반으로 한 모델링은 여전히 유효
트랜잭션은 가장 일반적으로 많이 쓰는 작업이 아니어야 함
세션을 통해 모든 명령문을 실행하여야함
트랜잭션은 항상 중단 가능하므로 재시도 로직을 구현 하여야함
불필요한 스냅샷을 열어 두면 안됨
쓰기 작업 충돌을 처리하기 위해선 반드시 같은 Doucment 에 대해 쓰기 작업을 수행하고
있어야 함
DDL 은 현재 지원되지 않음
분산 트랜잭션의 작동 방식
Majority Writes
Majority Write 는 어떤 기능 입니까?
ReplicaSet Cluster에 데이터가 견고하게 저장 되는 기능을 말합니다.
No Abiters
Participant (참가자)
특정 트랜잭션을 대신하여 작업을 실행하는 임의의 샤드
Coordinator
특정 트랜잭션에 대해 여러 샤드에 걸쳐 커밋을 조정하는
책임이 있는 단일 샤드
P
S
S
S
P
S
Query Router
Insert {_id : “abc”}Insert {_id : “xyz”}
Coordinator!
Commit transaction
모든 ReplicaSet Node 에서 커밋이 발생
트랜잭션이 없는 세상을 상상해보십시오.
“ 자체적으로 트랜잭션을 구현해서
실행할 때와 비교할 경우 MongoDB
트랜잭션을 실행할때 2배 이상 성능이
향상 되었습니다.”
분산 환경에서 성능 향상을 내기 위해서는
데이터를 한곳에 모아서
분산 환경에서 성능 향상을 내기 위해서는
하나의 샤드에 쓰기를 수행
Read Isolation
READ CONCERN = READ ISOLATION
Options: LOCAL, MAJORITY,
SNAPSHOT, LINEARIZABLE
흥미로운 점: ReadConcern Majority는
조회 결과를 가지고 오기 위해
노드간에 조정(Cooridnate) 를 할 필요가 없다.
Read
Concern:
Snapshot
P
S
S
P
S
S
P
S
S
time: 102
Majority
or
Local
time: 102 time: 110 time: 104
스냅샷 격리에는 많은 자원이 필요합니다.
모든 샤드는 시간에 대해 조정 작업이 필요함
트랜잭션이 발생하는 시간동안 동일한 스냅샷을
사용
Locking
쓰기
트랜잭션 내부
쓰기 작업은 Document 에 대핸 변경을 시도할때 잠금 획득을 시도한다.
잠금 획득을 성공 못했을 경우 해당 작업은 취소되며 롤백 된다.
트랜잭션 외부
쓰기 작업이 잠금 획득을 시도 하는데 실패하면 exponential back off 를 사용하여 다시 시도 한다.
읽기
쓰기 작업만 잠금 획득을 시도한다.
읽기 전용 트랜잭션이 수행되는 동안, 다른 트랜잭션이 Document 수정을 하게 되면 Stale
Read 가 가능해짐
Document 변경에 대한 트랜잭션이 실패하려면 동일한 Document 수정하고 있어야 한다.
4.2 에 새로 추가된 기능
16MB 이상의 트랜잭션 지원
MongoDB 4.0
{ <statement 1>,
<statement 2>,
<statement 3>,
<statement 4>}
MongoDB 4.2
{<statement 1>},
{<statement 2>},
{<statement 3>},
{<statement 4>}
그렇다고 해서 대량의 트랜잭션이
무한정 가능한 것은 아닙니다.
WiredTiger 는 스냅샷 이후에도 여전히 이력을 유지해야 합니다.
트랜잭션은 트랜잭션 수행시간 동안 동일한 스냅샷을 생성합니다.
트랜잭션은 60초 이후에 자동으로 중단 됩니다. – 변경가능
transactionLifetimeLimitSeconds
변경 가능한 샤드키 값
계층화된 스토리지: 저비용 스토리지 샤드에 오래된 Document 를 저장
글로벌-재분산 : Document 를 다른 지역으로 옮김
MongoDB 4.2 드라이버 사용
단일 샤드를 대상으로 하는 트랜잭션은 여러 샤드에 걸친 트랜잭션 보다
빠르게 수행됨
Best practice: 하나의 트랜잭션에 1,000 이하의 Document 를 수정
Arbiter 없음
청크 마이그레이션은 트랜잭션이 일어나는 동안 중지되어 트랜잭션이
끝난 이후 실행됨
Parting Wisdom
무료 ▪ 온라인 ▪ 9의 챕터로 구성
지금 등록 하십시오! -
https://university.mongodb.com/courses/M042/about
감사합니다!
분산 트랜잭션
[유승기]
https://www.research.net/r/DistributedTransactionsSeoul

More Related Content

What's hot (20)

PDF
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB
 
PDF
Postgresql database administration volume 1
Federico Campoli
 
PDF
Distributed Lock Manager
Hao Chen
 
PDF
MariaDB 10.11 key features overview for DBAs
Federico Razzoli
 
PPTX
MongoDB
nikhil2807
 
PDF
[2018] MySQL 이중화 진화기
NHN FORWARD
 
PDF
Load Data Fast!
Karwin Software Solutions LLC
 
PPTX
Getting started with postgresql
botsplash.com
 
PPTX
Postgresql
NexThoughts Technologies
 
PDF
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
DataStax Academy
 
PPT
Advanced Sql Injection ENG
Dmitry Evteev
 
PDF
Best practices for MySQL High Availability
Colin Charles
 
PDF
Sql query patterns, optimized
Karwin Software Solutions LLC
 
PDF
SQL Overview
Stewart Rogers
 
PPT
MySQL Functions
Compare Infobase Limited
 
PDF
An introduction to MongoDB
Universidade de São Paulo
 
PDF
Java Serialization Deep Dive
Martijn Dashorst
 
PPTX
Sql injection
Mehul Boghra
 
PDF
MariaDB Galera Cluster presentation
Francisco Gonçalves
 
PDF
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB
 
Postgresql database administration volume 1
Federico Campoli
 
Distributed Lock Manager
Hao Chen
 
MariaDB 10.11 key features overview for DBAs
Federico Razzoli
 
MongoDB
nikhil2807
 
[2018] MySQL 이중화 진화기
NHN FORWARD
 
Getting started with postgresql
botsplash.com
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
DataStax Academy
 
Advanced Sql Injection ENG
Dmitry Evteev
 
Best practices for MySQL High Availability
Colin Charles
 
Sql query patterns, optimized
Karwin Software Solutions LLC
 
SQL Overview
Stewart Rogers
 
MySQL Functions
Compare Infobase Limited
 
An introduction to MongoDB
Universidade de São Paulo
 
Java Serialization Deep Dive
Martijn Dashorst
 
Sql injection
Mehul Boghra
 
MariaDB Galera Cluster presentation
Francisco Gonçalves
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 

Similar to 분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB] (20)

KEY
Mongodb cluster
Kyungsuk Song
 
PDF
[124]네이버에서 사용되는 여러가지 Data Platform, 그리고 MongoDB
NAVER D2
 
PDF
The MongoDB Strikes Back / MongoDB 의 역습
Hyun-woo Park
 
PDF
MongoDB 신제품 및 신기능 소개
MongoDB
 
PDF
Mongo db 2.x to 3.x
InBum Kim
 
PDF
[스마트스터디]모바일 애플리케이션 서비스에서의 로그 수집과 분석
smartstudy_official
 
PDF
Mongodb 특징 분석
Daeyong Shin
 
PPTX
Mongo db in use(naver)
InBum Kim
 
PDF
Mongo db intro &amp; tips
InBum Kim
 
PDF
[스마트스터디]MongoDB 의 역습
smartstudy_official
 
PDF
FIFA 온라인 3의 MongoDB 사용기
Jongwon Kim
 
PPTX
Mongodb 개발 포인트
흥배 최
 
PPTX
Mongo db 최범균
beom kyun choi
 
KEY
Mongodb tip42 50
Kyungryul KIM
 
PDF
if kakao dev 2019_Ground X_Session 04
Klaytn
 
PDF
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
Amazon Web Services Korea
 
PDF
MongoDB 하루만에 끝내기
Seongkuk Park
 
PDF
Mongodb2.2와 2.4의 신 기능 소개
흥배 최
 
PPTX
mongodb와 mysql의 CRUD 연산의 성능 비교
Woo Yeong Choi
 
PDF
(GameTech2015) Live Operation by Adbrix의 Node.js와 MongoDB를 이용한 멀티테넌트 인프라 구축사례
Jeongsang Baek
 
Mongodb cluster
Kyungsuk Song
 
[124]네이버에서 사용되는 여러가지 Data Platform, 그리고 MongoDB
NAVER D2
 
The MongoDB Strikes Back / MongoDB 의 역습
Hyun-woo Park
 
MongoDB 신제품 및 신기능 소개
MongoDB
 
Mongo db 2.x to 3.x
InBum Kim
 
[스마트스터디]모바일 애플리케이션 서비스에서의 로그 수집과 분석
smartstudy_official
 
Mongodb 특징 분석
Daeyong Shin
 
Mongo db in use(naver)
InBum Kim
 
Mongo db intro &amp; tips
InBum Kim
 
[스마트스터디]MongoDB 의 역습
smartstudy_official
 
FIFA 온라인 3의 MongoDB 사용기
Jongwon Kim
 
Mongodb 개발 포인트
흥배 최
 
Mongo db 최범균
beom kyun choi
 
Mongodb tip42 50
Kyungryul KIM
 
if kakao dev 2019_Ground X_Session 04
Klaytn
 
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
Amazon Web Services Korea
 
MongoDB 하루만에 끝내기
Seongkuk Park
 
Mongodb2.2와 2.4의 신 기능 소개
흥배 최
 
mongodb와 mysql의 CRUD 연산의 성능 비교
Woo Yeong Choi
 
(GameTech2015) Live Operation by Adbrix의 Node.js와 MongoDB를 이용한 멀티테넌트 인프라 구축사례
Jeongsang Baek
 
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
Ad

분산 트랜잭션 - 큰힘에는 큰 책임이 따른다 [MongoDB]