ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘€ Overview

Shared Lock๊ณผ Exclusive Lock์€ S-Lock, X-Lock์ด๋ผ๊ณ ๋„ ํ•˜๋ฉฐ, (์ฝ๊ธฐ ๋ฝ, ์“ฐ๊ธฐ ๋ฝ), (๊ณต์œ  ๋ฝ, ๋ฐฐํƒ€ ๋ฝ)์ด๋ผ๊ณ  ๋ถˆ๋ฆฌ๊ธฐ๋„ ํ•œ๋‹ค.

ํ•˜์ง€๋งŒ ์ด lock์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ํ•™์Šตํ•˜๋ฉด์„œ ์—ฌ๋Ÿฌ ๋ธ”๋กœ๊ทธ๋“ค์„ ์ฐพ์•„๋ดค๋Š”๋ฐ, ์ž˜๋ชป๋œ ๋‚ด์šฉ๋“ค์ด ์ •๋ง ๋งŽ์•˜๋‹ค!

 

๊ทธ๋ž˜์„œ ๊ทธ ๋‚ด์šฉ๋“ค์„ ์‹ค์ œ ๋‚ด๊ฐ€ MySQL ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ๋น„๊ตํ•˜๋ฉด์„œ ๋ฐ”๋กœ์žก๊ณ , ํŒŒํ—ค์ณ ๋ณด๊ธฐ ์œ„ํ•ด์„œ ๊ธ€์„ ์จ์•ผ๊ฒ ๋‹ค๋Š” ๊ฒฐ์‹ฌ์„ ํ–ˆ๋‹ค.

 

๐Ÿ”Shared Lock๊ณผ Exclusive Lock

๋จผ์ € ์•ž ๊ธ€์—์„œ๋„ ์–ธ๊ธ‰ํ–ˆ์ง€๋งŒ, InnoDB ์Šคํ† ๋ฆฌ์ง€ ์—”์ง„ ๋ ˆ๋ฒจ์—์„œ์˜ Lock์„ ์„ค๋ช…ํ•˜๋ฉด์„œ Shared Lock, Exclusive Lock์˜ ๊ฐœ๋…์ด ๋‚˜์™”๋‹ค.

ํŠน์ • row์— lock์„ ๊ฑธ๋ฉด ๋ ˆ์ฝ”๋“œ๋ฝ, ์—ฌ๋Ÿฌ row์— range๋กœ lock์„ ๊ฑธ๋ฉด ๋„ฅ์Šคํฌ ํ‚ค ๋ฝ, ๊ทธ๋ฆฌ๊ณ  ๊ทธ row๋“ค ์ค‘๊ฐ„์— ๊ฑธ๋ฆฌ๋Š” ๊ฐญ ๋ฝ ์ด ์žˆ์—ˆ๋‹ค.

InnoDB ์Šคํ† ๋ฆฌ์ง€ ์—”์ง„์ด ์ œ๊ณตํ•˜๋Š” ๋ฝ์„ ์ทจ๋“ํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” 1๏ธโƒฃ UPDATE ์ฟผ๋ฆฌ, 2๏ธโƒฃ DELETE ์ฟผ๋ฆฌ, 3๏ธโƒฃ Shared Lock / Exclusive Lock ํš๋“ ์‹œ์— ๋ฐœ์ƒํ•œ๋‹ค๊ณ  ์–ธ๊ธ‰ํ–ˆ์—ˆ๋‹ค.

 

๊ทธ ์ค‘, Shared Lock๊ณผ Exclusive Lock์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž.

 

1. Shared Lock (๊ณต์œ  ๋ฝ)

Shared Lock์€ MySQL 8.0 ๋ฒ„์ „ ๋ถ€ํ„ฐ SELECT .. FOR SHARE ์„ ํ†ตํ•ด ํš๋“ํ•  ์ˆ˜ ์žˆ๋‹ค.

Shared Lock์€ ์ฝ๊ธฐ ์ž ๊ธˆ์ด๋ผ๊ณ  ๋งํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ๋ฆฌ์†Œ์Šค๋ฅผ ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋™์‹œ์— ๋ ˆ์ฝ”๋“œ๋ฅผ ์ฝ์„ ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๊ฐ€ ๋ณ€๊ฒฝ ํ•˜๋Š” ๊ฒƒ์€ ์ฐจ๋‹จํ•œ๋‹ค๊ณ  ์—ฌ๋Ÿฌ ๋ธ”๋กœ๊ทธ๋“ค์—์„œ ๋งํ•œ๋‹ค.

ํ•˜์ง€๋งŒ Exclusive Lock์—์„œ๋„ ๋™์ผํ•˜๊ฒŒ ๋ฆฌ์†Œ์Šค๋ฅผ ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋™์‹œ์— ๋ ˆ์ฝ”๋“œ๋ฅผ ์ฝ์„ ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์„ ์ฐจ๋‹จํ•œ๋‹ค.

๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, shared, exclusive lock์ด ์•„๋‹Œ update, delete ์ฟผ๋ฆฌ์—์„œ๋„ ๋™์ผํ•˜๊ฒŒ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ๋™์‹œ์— ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์€ ์ฐจ๋‹จํ•œ๋‹ค.

 

๋ฌด์Šจ๋ง์ด๋ƒ๋ฉด, ์‚ฌ์›๋ฒˆํ˜ธ๊ฐ€ 10001๋ฒˆ์ด๊ณ  ์—ฐ๋ด‰์ด 60117์ธ row์— ๋ ˆ์ฝ”๋“œ ๋ฝ, ๊ทธ ์ค‘ shared lock์„ ํ•œ ํŠธ๋žœ์žญ์…˜ ๋‚ด์—์„œ ๊ฑธ์—ˆ๋‹ค. (์˜ˆ์‹œ๋Š” ์—…๋ฌด์— ๋ฐ”๋กœ์“ฐ๋Š” SQL ํŠœ๋‹ ์ฑ…์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค)

autocommit์„ ๋„๊ณ , ํŠธ๋žœ์žญ์…˜์„ ์‹œ์ž‘ํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  shared lock์„ for share ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ํš๋“ํ–ˆ๋‹ค.

transaction 1๋ฒˆ - shared lock ํš๋“

shared lock์„ ์œ„์—์„œ ์–ป๊ณ , ๋‹ค๋ฅธ ์ฐฝ์„ ์—ด์–ด ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ํ•ด๋‹น row๋ฅผ updateํ•ด ๋ณด์•˜๋‹ค.

transaction 2๋ฒˆ - update ํ†ตํ•œ row ๋ณ€๊ฒฝ ์‹œ๋„

๊ทธ๋Ÿฌ๋‹ˆ ๋ฌดํ•œ ๋Œ€๊ธฐ ์ƒํƒœ์— ๋น ์กŒ๋‹ค. spin lockํ˜•ํƒœ๋กœ ๊ณ„์† ์‹œ๋„ํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

๊ทธ๋Ÿฌ๊ณ  transaction 1๋ฒˆ์—์„œ rollback ์‹œ์ผฐ๋”๋‹ˆ, ๋Œ€๊ธฐ์ค‘์ด๋˜ transaction 2๋ฒˆ์—์„œ update ์ฟผ๋ฆฌ๊ฐ€ ์ •์ƒ ์‹คํ–‰๋˜์—ˆ๋‹ค.

transaction 2๋ฒˆ - transaction 1๋ฒˆ์—์„œ rollback ํ›„ ์‹คํ–‰ (44์ดˆ ๊ฑธ๋ฆผ)

๊ทธ๋ฆฌ๊ณ  SHOW PROCESSLIST;๋กœ ๋‹ค๋ฅธ ์ฐฝ์„ ํ•˜๋‚˜ ๋” ์—ด์–ด ํ”„๋กœ์„ธ์Šค๊ฐ€ ์–ด๋–ค ์ƒํƒœ์ธ์ง€ ๋น„๊ต๋ฅผ ํ•ด ๋ณด์•˜๋‹ค.

๋จผ์ € Transaction 1๋ฒˆ์ด rollback์„ ํ†ตํ•ด lock ๋ฐ˜ํ™˜ ์ „ ๋ชจ์Šต์ด๋‹ค.

Transaction 3 - ํ”„๋กœ์„ธ์Šค ์ƒํƒœ ํ™•์ธ

Id๊ฐ€ 77๋ฒˆ์ธ ํ”„๋กœ์„ธ์Šค์—์„œ update ์ฟผ๋ฆฌ๋ฅผ ๊ณ„์†ํ•ด์„œ ์‹คํ–‰ํ•˜๊ณ  ์žˆ๋‹ค.

 

์•„๋ž˜๋Š” Transaction 1๋ฒˆ์ด rollback ํ›„ lock์„ ๋ฐ˜ํ™˜ ํ•˜๊ณ  ๋‚œ ๋ชจ์Šต์ด๋‹ค.

Transaction 3 - ํ”„๋กœ์„ธ์Šค ์ƒํƒœ ํ™•์ธ

Id๊ฐ€ 77๋ฒˆ์ธ ํ”„๋กœ์„ธ์Šค์—์„œ update๋ฅผ ๋งˆ์น˜๊ณ  state๊ฐ€ ๋ฐ”๋€Œ์—ˆ๋‹ค.

 

๊ทธ๋Ÿฐ๋ฐ ์ด๋ ‡๊ฒŒ lock์„ ํš๋“ํ•˜๊ณ  ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ update ์ฟผ๋ฆฌ ์‹คํ–‰ ์‹œ ๋Œ€๊ธฐํ•˜๋Š” ํ˜„์ƒ์€ shared lock, exclusive lock์ด ์•„๋‹Œ update๋‚˜ delete์—์„œ๋„ ๋™์ผํ•˜๋‹ค.

Trasaction 1๋ฒˆ - delete ์ฟผ๋ฆฌ ์‹คํ–‰
Transaction 2๋ฒˆ - delete ์ฟผ๋ฆฌ ์‹คํ–‰

์œ„ ์ฟผ๋ฆฌ๋ฅผ ๋ณด๋ฉด, ๊ฒฐ๊ตญ transaction 1๋ฒˆ์ด rollback์„ ํ•˜๊ณ  ๋‚˜์„œ์•ผ 16์ดˆ ๋งŒ์— delete ์ฟผ๋ฆฌ๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

์ด๊ฑด 

 

๋™์‹œ์— ๋ ˆ์ฝ”๋“œ๋ฅผ ์ฝ์„ ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๊ฐ€ ๋ณ€๊ฒฝ ํ•˜๋Š” ๊ฒƒ์€ ์ฐจ๋‹จํ•˜๋Š” ๊ฒƒ์ด shared lock์˜ ํŠน์ง•์ด๋ผ๊ณ  ๋‚˜์˜ค๋Š”๋ฐ, ์ด๋Š” shared lock์—์„œ์˜ ํŠน์ง•์ด๋ผ๊ธฐ ๋ณด๋‹ค๋Š” InnoDB ์Šคํ† ๋ฆฌ์ง€ ์—”์ง„ ์ƒ์—์„œ ํŠน์ • row์— ๋ ˆ์ฝ”๋“œ๋ฝ์ด ๊ฑธ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์ด๋ผ๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

๋”ฐ๋ผ์„œ ๊ฐœ์ธ์ ์œผ๋กœ shared lock์— ๋Œ€ํ•ด์„œ ํ•™์Šตํ•˜๋‹ค ํ—ท๊ฐˆ๋ฆฐ ๋ถ€๋ถ„์ด ์•„๋ž˜ ๋ถ€๋ถ„์ธ๋ฐ, ํŠน์ • row์— ๋Œ€ํ•ด์„œ shared lock์„ ์–ป์€ ํŠธ๋žœ์žญ์…˜๋‚ด์—์„œ update๋ฅผ ํ†ตํ•œ row์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•˜๋‹ค! shared lock์ด๋ผ๊ณ  ๋ฌด์กฐ๊ฑด lock์ด ๊ฑธ๋ฆฐ row์— ๋Œ€ํ•ด ์“ฐ๊ธฐ์ž‘์—…์ด ๋ถˆ๊ฐ€๋Šฅํ•œ๊ฒƒ ์•„๋‹ˆ๋ผ, ๋™์ผํ•œ ํŠธ๋žœ์žญ์…˜์ด๋ฉด ๊ฐ€๋Šฅํ•˜๋‹ค.

๋™์ผํ•œ ํŠธ๋žœ์žญ์…˜์ผ ๊ฒฝ์šฐ shared lock ํš๋“ ํ›„ ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ

๊ทธ๋Ÿฌ๋ฉด Shard Lock์˜ ์ง„์งœ ํŠน์ง•์€ ๋ญ˜๊นŒ?

 

์•„๋ž˜์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ, ํ•œ ํŠธ๋žœ์žญ์…˜์—์„œ ๊ณต์œ  ๋ฝ์„ ํš๋“ํ•˜๋ฉด, ํ•ด๋‹น ํŠธ๋žœ์žญ์…˜์ด ์ปค๋ฐ‹ / ๋กค๋ฐฑ์„ ํ†ตํ•ด ๋ฝ์„ ๋ฐ˜ํ™˜ํ•  ๋•Œ ๊นŒ์ง€ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ํš๋“ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฝ์„ ๋งํ•œ๋‹ค. ๋‹จ, ๋ฐฐํƒ€ ๋ฝ์€ ํš๋“ ๋ถˆ๊ฐ€๋Šฅ ํ•˜๋‹ค. ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ๋ฐฐํƒ€ ๋ฝ ์„ ํš๋“ํ•˜๋ ค ํ•˜๋ฉด ๋Œ€๊ธฐ ์ƒํƒœ์— ๋น ์ง„๋‹ค.

Transaction 1๋ฒˆ - ํŠธ๋žœ์žญ์…˜ ์‹œ์ž‘ ํ›„ ๊ณต์œ ๋ฝ ํš๋“
Transaction 2๋ฒˆ - ํŠธ๋žœ์žญ์…˜ ์‹œ์ž‘ ํ›„ ๊ณต์œ ๋ฝ ํš๋“ ๊ฐ€๋Šฅ but ๋ฐฐํƒ€ ๋ฝ ํš๋“ ๋ถˆ๊ฐ€

 

2) Exclusive Lock (๋ฐฐํƒ€ ๋ฝ) 

Exclusive Lock์€ ์ด๋ฏธ ๋‚˜์™”์ง€๋งŒ SELECT .. FOR UPDATE ์„ ํ†ตํ•ด ํš๋“ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ฐฐํƒ€ ๋ฝ์˜ ํŠน์ง• ๋˜ํ•œ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ์ฝ๊ธฐ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ์ด๋Š” ์ž˜๋ชป๋˜์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค.

Transaction 1๋ฒˆ - Exclusive Lock ํš๋“

์œ„ Transaction 1๋ฒˆ์—์„œ ๋ฐฐํƒ€๋ฝ์„ ํš๋“ํ•˜๋ฉด ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ์ฝ๊ธฐ๊ฐ€ ์•ˆ๋ ๊ฒƒ ๊ฐ™์ง€๋งŒ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

Transaction 2๋ฒˆ - ๋™์ผํ•œ row์— ๋Œ€ํ•ด์„œ select ๊ฐ€๋Šฅ

์œ„์™€ ๊ฐ™์€ select ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋Œ€๊ธฐ ์ƒํƒœ์— ๋น ์งˆ๊ฒƒ ๊ฐ™์•˜์ง€๋งŒ ๋ฐ”๋กœ ์กฐํšŒ๊ฐ€ ๋˜์—ˆ๋‹ค.

์™œ๊ทธ๋Ÿด๊นŒ?๐Ÿค”

 

๋ฐฐํƒ€๋ฝ์˜ ํŠน์ง•์„ ์ž˜๋ชป ์ดํ•ดํ•˜๊ณ  ์žˆ์–ด์„œ ์œ„์™€ ๊ฐ™์€ ์˜คํ•ด๋ฅผ ํ–ˆ๋Š”๋ฐ,

๋ฐฐํƒ€๋ฝ์˜ ํŠน์ง•์€ ํ•œ ํŠธ๋žœ์žญ์…˜์—์„œ ๋ฐฐํƒ€๋ฝ์„ ํš๋“ํ•˜๋ฉด ์ปค๋ฐ‹ or ๋กค๋ฐฑ์„ ํ†ตํ•ด ๋ฐฐํƒ€๋ฝ์„ ๋ฐ˜๋‚ฉํ•˜๊ธฐ ์ „ ๊นŒ์ง€ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ๋ฐฐํƒ€๋ฝ AND ๊ณต์œ ๋ฝ ์„ ์ทจ๋“ ํ•  ์ˆ˜ ์—†๋‹ค.

Transaction 1๋ฒˆ - ๋ฐฐํƒ€๋ฝ ํš๋“
Transaction 2๋ฒˆ - ๋ฐฐํƒ€๋ฝ ํš๋“ ์‹คํŒจ

๋ฐฐํƒ€๋ฝ์„ Transaction 2๋ฒˆ์—์„œ ํš๋“ ํ•˜๋ ค๊ณ  ํ•˜๋ฉด ๋Œ€๊ธฐ์ƒํƒœ์— ๋น ์ง„๋‹ค. (Transaction 1๋ฒˆ์ด ๋ฐฐํƒ€๋ฝ์„ ์ปค๋ฐ‹ / ๋กค๋ฐฑ์„ ํ†ตํ•ด ๋ฐ˜๋‚ฉํ•ด์•ผ ํš๋“ํ•œ๋‹ค)

์ด๋•Œ๋Š” Transaction 2๋ฒˆ์—์„œ ๊ณต์œ ๋ฝ์„ ํš๋“ ํ•˜๋ ค๊ณ  ํ•ด๋„ ๋Œ€๊ธฐ์ƒํƒœ์— ๋น ์ง„๋‹ค

Transaction 2๋ฒˆ - ๊ณต์œ ๋ฝ ํš๋“ ์‹คํŒจ (๋Œ€๊ธฐ์ƒํƒœ)

 

 

์ •๋ฆฌํ•˜์ž๋ฉด, ๊ณต์œ ๋ฝ์€ ํ•œ ํŠธ๋žœ์žญ์…˜์—์„œ ํš๋“ ์‹œ, ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ๋„ ํš๋“ ๊ฐ€๋Šฅํ•˜๋‹ค. ์ด๋Š” ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ๋ฐฐํƒ€๋ฝ์˜ ํš๋“์„ ๋ง‰๊ณ , ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ์˜ update, delete ์ฟผ๋ฆฌ ์‹คํ–‰์„ ๋ง‰๋Š”๋‹ค.

๋ฐฐํƒ€ ๋ฝ์€ ํ•œ ํŠธ๋žœ์žญ์…˜์—์„œ ํš๋“ ์‹œ, ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ๊ณต์œ ๋ฝ, ๋ฐฐํƒ€๋ฝ ํš๋“ ๋ชจ๋‘๋ฅผ ๋ง‰๋Š”๋‹ค. ์ด๋Š” ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ์˜ updaet, delete ์ฟผ๋ฆฌ ์‹คํ–‰์„ ๋ง‰๋Š”๋‹ค. 

 

ํ›„๊ธฐ

๋ณดํ†ต ํ›„๊ธฐ๋ฅผ ์ž˜ ์“ฐ์ง€๋Š” ์•Š๋Š”๋ฐ, ์—ฌ๋Ÿฌ ๋ธ”๋กœ๊ทธ๋ฅผ ํ†ตํ•ด ํ•™์Šต์„ ํ•˜๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•˜์ง€๋งŒ, ์ง์ ‘ ์‹ค์Šต์„ ํ†ตํ•ด ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด ๋ณด๋Š” ๊ณผ์ •๋„ ์ค‘์š”ํ•˜๊ตฌ๋‚˜..! ๋ผ๋Š” ๊ฒƒ์„ ๋Š๊ผˆ๋‹ค.

์ง์ ‘ sql ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค๋ณด๋ฉด์„œ, ๊ธฐ์กด์˜ ๋‚ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋˜ ์ƒ๊ฐ๋“ค,

- shared lock == ์ฝ๊ธฐ ๋ฝ -> ๋‹ค๋ฅธ ๊ณณ์—์„œ ์ฝ๋Š” ๊ฒƒ์€ ๊ฐ€๋Šฅํ•˜๊ณ  ์“ฐ๋Š” ๊ฒƒ๋งŒ ๋ง‰๋Š” ๊ตฌ๋‚˜

- exclusive lock == ์“ฐ๊ธฐ ๋ฝ -> ๋‹ค๋ฅธ ๊ณณ์—์„œ ์ฝ๋Š” ๊ฒƒ๋„ ์•ˆ๋˜๊ณ  ์“ฐ๋Š”๊ฒƒ๋„ ์•ˆ๋˜๊ตฌ๋‚˜

๋ผ๋Š” ์ž˜๋ชป๋œ ์ธ์‹์—์„œ ํ•ด๋ฐฉ์‹œ์ผœ ์ฃผ์—ˆ๋‹ค.

 

 

[Lock ์‹œ๋ฆฌ์ฆˆ]

๋™์‹œ์„ฑ ์ œ์–ด๋ฅผ ์œ„ํ•œ Lock (1) - DB Lock

๋™์‹œ์„ฑ ์ œ์–ด๋ฅผ ์œ„ํ•œ Lock (2) - Shard Lock, Exclusive Lock Deep Dive

 

 

Reference

Real MySQL 8.0 Chapter 5

https://velog.io/@soongjamm/Select-%EC%BF%BC%EB%A6%AC%EB%8A%94-S%EB%9D%BD%EC%9D%B4-%EC%95%84%EB%8B%88%EB%8B%A4.-X%EB%9D%BD%EA%B3%BC-S%EB%9D%BD%EC%9D%98-%EC%B0%A8%EC%9D%B4

 

Select ์ฟผ๋ฆฌ๋Š” S๋ฝ์ด ์•„๋‹ˆ๋‹ค. (X๋ฝ๊ณผ S๋ฝ์˜ ์ฐจ์ด)

์ด ๊ธ€์—์„œ ์‚ฌ์šฉํ•œ dbms๋Š” MySQL 8.x ๋ฒ„์ „์ด๊ณ  innoDB engine ๊ธฐ์ค€์ž…๋‹ˆ๋‹ค.์ €๋Š” Real MySQL์„ ํ†ตํ•ด DB๋ฅผ ๊ณต๋ถ€ํ•˜๋˜ ์ค‘ S-Lock ๊ณผ X-Lock์— ๋Œ€ํ•ด ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  SELECT - FOR UPDATE ์ฟผ๋ฆฌ๋Š” ํ•ด๋‹น ๋ ˆ์ฝ”๋“œ์˜ X-loc

velog.io

 

 

 
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday