Your SlideShare is downloading. ×
Transaction
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Transaction

312
views

Published on


0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
312
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Transaction
  • 2. 트랜잭션이 뭔가요?
  • 3. DB에서 상호작용의 단위
  • 4. ACID
  • 5. Atomicity Consistency Isolation Durability
  • 6. Atomicity
  • 7. 다 실행하거나 아무것도 안하거나
  • 8. 유저가 포인트로 아이템을 삽니다
  • 9. 1. 포인트를 깎는다.
  • 10. 2. 아이템을 지급한다.
  • 11. 그런데.. 아이템을 생성하다 죽으면?
  • 12. 포인트만 나갔네…?
  • 13. 포인트만 나갔네…?
  • 14. 망했어?
  • 15. 안망했어?
  • 16. Consistency
  • 17. 일관성
  • 18. DB Constraints
  • 19. PRIMARY KEY UNIQUE
  • 20. FOREIGN KEY
  • 21. ENUM
  • 22. 위반하는 트랜잭션은 OUT!
  • 23. Isolation
  • 24. 혼자 있고 싶습니다 모두 나가 주세요
  • 25. 고립성(Isolation)
  • 26. 다른 트랜잭션의 연산 작업이 끼어들지 못하도록 보장하는 것을 의미한다.
  • 27. Durability
  • 28. 한번 커밋된 내용은 시스템 문제, DB 일관성 체크 등 무슨 짓을 해도 영원히 반영
  • 29. 뭐 알아서 잘 만들었겠죠
  • 30. Q.
  • 31. 왜 대충 DB ACID 검색하면 나오는 뻔한 얘기를 하고 있나요?
  • 32. 우리중 스파이가 있는 것 같아
  • 33. Isolation
  • 34. BEGIN TRANSACTION
  • 35. BEGIN TRANSACTION BEGIN TRANSACTION
  • 36. BEGIN TRANSACTION BEGIN TRANSACTION
  • 37. 다른 트랜잭션의 연산 작업이 끼어들지 못하도록 보장하는 것을 의미한다.
  • 38. BEGIN TRANSACTION BEGIN TRANSACTION ???????? 먼저 시작한 놈이 뭘 하려는 거지?
  • 39. BEGIN TRANSACTION BEGIN TRANSACTION ???????? 먼저 시작한 놈이 뭘 하려는 거지?
  • 40. BEGIN TRANSACTION BEGIN TRANSACTION SELECT * WHERE id=1 이러면 망하는데? INSERT id=1
  • 41. BEGIN TRANSACTION BEGIN TRANSACTION ????????
  • 42. BEGIN TRANSACTION BEGIN TRANSACTION SLEEP(10000)
  • 43. 타협
  • 44. 타협 Level
  • 45. Isolation Level
  • 46. Serializable
  • 47. 내가 건드린건 보지 마
  • 48. Read-Write Lock
  • 49. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 UPDATE users SET age=21 where id=1 SELECT age FROM users WHERE id=1
  • 50. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 1 UPDATE users SET age=21 where id=1 SELECT age FROM users WHERE id=1
  • 51. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 120 UPDATE users SET age=21 where id=1 SELECT age FROM users WHERE id=1
  • 52. SELECT age FROM users WHERE id=1 T1 T2 UPDATE users SET age=21 where id=1 DB 1, 20 1 Locked! 20 SELECT age FROM users WHERE id=1
  • 53. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 1 2 20 20 Locked! UPDATE users SET age=21 where id=1 SELECT age FROM users WHERE id=1
  • 54. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 1 Locked! Release! 2 20 20 UPDATE users SET age=21 where id=1 SELECT age FROM users WHERE id=1
  • 55. SELECT age FROM users WHERE id=1 T1 T2 UPDATE users SET age=21 where id=1 DB 1, 21 1 Release! 2 3 20 20 SELECT age FROM users WHERE id=1
  • 56. 기다리기 싫어요!
  • 57. MORE 타협
  • 58. REPEATABLE READ
  • 59. 첫인상
  • 60. 첫 READ
  • 61. 첫 READ가 트랜잭션 내내 유지
  • 62. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 120 UPDATE users SET age=21 where id=1 SELECT age FROM users WHERE id=1
  • 63. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 20 120 UPDATE users SET age=21 where id=1 T1 Snapshot 1, 20 SELECT age FROM users WHERE id=1
  • 64. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 21 120 UPDATE users SET age=21 where id=1 2 T1 Snapshot 1, 20 SELECT age FROM users WHERE id=1
  • 65. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 21 120 UPDATE users SET age=21 where id=1 T1 Snapshot 1, 20 2 어 스냅샷이 20이네? 3 SELECT age FROM users WHERE id=1
  • 66. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 T1 Snapshot 1, 20 2 그럼 20 디비가 뭐라든… 20 3
  • 67. 그 시점에 커밋된걸 보고 싶어요!
  • 68. READ COMMITTED
  • 69. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1
  • 70. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1
  • 71. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 2
  • 72. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 2 어 21이네? 3
  • 73. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 2 21 3
  • 74. ACID 필요없어! 그냥 졸라 빠르게!
  • 75. READ UNCOMMITTED
  • 76. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 2 21 3
  • 77. 사실 뭔가 생략되어있어요
  • 78. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 COMMIT 2 21 3
  • 79. 커밋을 안하고 롤백하면?
  • 80. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 UPDATE users SET age=21 where id=1 ROLLBACK
  • 81. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1 ROLLBACK
  • 82. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1 ROLLBACK 2
  • 83. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1 2 ROLLBACK 어 우리 커밋 안했는데 기다려야하는거 아니에요? 몰라 대충 넣어
  • 84. SELECT age FROM users WHERE id=1 T1 T2 DB 1, 21 120 UPDATE users SET age=21 where id=1 ROLLBACK 2 SELECT age FROM users WHERE id=1 21 3
  • 85. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 21 120 UPDATE users SET age=21 where id=1 2 21 3 ROLLBACK 4
  • 86. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1 2 21 3 ROLLBACK 4 롤백롤백
  • 87. SELECT age FROM users WHERE id=1 T1 T2 SELECT age FROM users WHERE id=1 DB 1, 20 120 UPDATE users SET age=21 where id=1 2 21 3 ROLLBACK 4 롤백롤백 ????????
  • 88. Q: 이럴거면 뭐하러 트랜잭션을 쓰죠?
  • 89. A: 몰라요
  • 90. 권장하지 않아요.
  • 91. MySQL Default REPEATABLE READ
  • 92. Postgres Default READ COMMITTED
  • 93. 짜잘짜잘하게 다른데 그런건 알아서!
  • 94. 하고싶은 말
  • 95. 트랜잭션은 생각보다 만능이 아닙니다…
  • 96. Execution Order 를 보장해주지 않아요.
  • 97.

×