Redis Cluster concept

์žญ์žญ์ดยท2021๋…„ 6์›” 29์ผ
2

redis

๋ชฉ๋ก ๋ณด๊ธฐ
2/6
post-thumbnail

Redis Cluster concept

๐ŸŽ ๋ชฉ์ฐจ

๊ฐœ์š”

Cluster๋ž€ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๊ณ ๊ฐ€์šฉ์„ฑ(HA)๋ฅผ ์ œ๊ณตํ•ด ์ค€๋‹ค.
Redis cluster๋Š” HA๋ฟ๋งŒ ์•„๋‹ˆ๋ผ Sharding(์—ฌ๋Ÿฌ ์„œ๋ฒ„์— ๋ฐ์ดํ„ฐ๊ฐ€ ๋ถ„์‚ฐ์ €์žฅ)์„ ๋™์‹œ ์ œ๊ณตํ•œ๋‹ค.
๋…ธ๋“œ๋Š” Master์™€ Slave๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋‹ค.
Slave๋…ธ๋“œ๋Š” Master๋…ธ๋“œ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณต์ œํ•˜์—ฌ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.
Master๋…ธ๋“œ์—์„œ ์žฅ์•  ๋ฐœ์ƒ ์‹œ Slave๋…ธ๋“œ๊ฐ€ Master๋กœ ์Šน๊ฒฉ๋˜๋ฉฐ ๋ฌด์ค‘๋‹จ์„œ๋น„์Šค๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

1. ํฌํŠธ

๋ชจ๋“  Redis cluster node๋Š” ๋‘ ๊ฐœ์˜ TCP ํฌํŠธ๊ฐ€ ์—ด๋ ค ์žˆ์–ด์•ผ ํ•œ๋‹ค.
1. Client port

  • Client - Cluster ๊ฐ„ ํ†ต์‹ ์— ์‚ฌ์šฉ
  1. Cluster bus port
    • ์žฅ์•  ๊ฐ์ง€, ๊ตฌ์„ฑ ์—…๋ฐ์ดํŠธ, ์žฅ์•  ์กฐ์น˜ ๊ถŒํ•œ ๋ถ€์—ฌ ๋“ฑ์— ์‚ฌ์šฉ
    • ๋…ธ๋“œ ๊ฐ„ ๋ฐ์ดํ„ฐ ๊ตํ™˜์„ ์œ„ํ•ด ์ด์ง„ ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•œ๋‹ค.

2. Sharding

Redis cluster์—๋Š” 16384๊ฐœ์˜ Hash slot์ด ์žˆ์œผ๋ฉฐ Redis cluster์˜ ๋ชจ๋“  ๋…ธ๋“œ๋Š” ์ด๋ฅผ ๋‚˜๋ˆ„์–ด ๊ฐ–๋Š”๋‹ค.
๋”ฐ๋ผ์„œ ๋…ธ๋“œ๋ฅผ ์ถ”๊ฐ€ ๋ฐ ์ œ๊ฑฐํ•  ๋•Œ Hash slot์ด ์žฌ ๊ตฌ์„ฑ๋œ๋‹ค.
๋…ธ๋“œ์—์„œ ๋‹ค๋ฅธ ๋…ธ๋“œ๋กœ Hash slot์„ ์ด๋™ํ•  ๋•Œ ์ž‘์—…์„ ์ค‘์ง€ ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.
๋•Œ๋ฌธ์— ๋…ธ๋“œ ์ถ”๊ฐ€ ๋ฐ ์ œ๊ฑฐ๋กœ ๋…ธ๋“œ๊ฐ€ ๋ณด์œ ํ•˜๋Š” Hash slot์˜ ๋น„์œจ์„ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐ ๋‹ค์šด ํƒ€์ž„์ด ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค.

3. Master Slave mode

Redis cluster๋Š” sharding์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์‚ฐ ์ €์žฅํ•œ๋‹ค.
๋•Œ๋ฌธ์— cluster ์ค‘ ํ•˜๋‚˜์—์„œ ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ•ด๋‹น cluster์˜ hashslot์€ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•œ๋‹ค.
์ด๋ฅผ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด master node๋Š” ์ž์‹ ์„ ๋ณต์ œํ•œ slave๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
Master ๋…ธ๋“œ์—์„œ ์žฅ์•  ๋ฐœ์ƒ ์‹œ slave๋…ธ๋“œ๋Š” master๋กœ ์Šน๊ฒฉํ•œ๋‹ค.
Master์™€ slave ๋…ธ๋“œ๊ฐ€ ๊ฐ™์€ ์„œ๋ฒ„์— ์กด์žฌํ•˜๊ณ , ํ•ด๋‹น ์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ๋™์‹œ ์‹คํŒจํ•˜๋ฉด redis cluster๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค.

4. Redis cluster์™€ async

Redis cluster๋Š” ๋น„๋™๊ธฐ ๋ณต์ œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
1. Client๊ฐ€ Master B์—๊ฒŒ write.
2. Master B๊ฐ€ Client์—๊ฒŒ OK ์†ก์‹ .
3. Master B๋Š” write set์„ Slave(B1, B2, B3)๋“ค์—๊ฒŒ ์ „ํŒŒ.

Client์—๊ฒŒ 3๋ฒˆ์˜ ๊ณผ์ •์„ ๊ธฐ๋‹ค๋ฆฌ๋Š” ๊ฒƒ์€ ์—„์ฒญ๋‚œ ์ง€์—ฐ ํŒจ๋„ํ‹ฐ์ด๋‹ค.
๋”ฐ๋ผ์„œ redis cluster๋Š” ๋น„๋™๊ธฐ ๋ณต์ œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

ํ•˜์ง€๋งŒ 3์˜ ๊ณผ์ •์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด??
1. B1, B2๋Š” Master B๋กœ ๋ถ€ํ„ฐ write set์„ ์ „๋‹ฌ๋ฐ›์•˜๋‹ค.
2. B3์€ ์ „๋‹ฌ๋ฐ›์ง€ ๋ชปํ•œ ์ฑ„๋กœ ๋„คํŠธ์›Œํฌ์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
3. B3์ด Master๋กœ ์Šน๊ฒฉํ•œ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค๋กœ write์˜ ์†์‹ค์ด ๋ฐœ์ƒํ•œ๋‹ค.

5. Redis cluster์˜ ์ผ๊ด€์„ฑ ๋ณด์žฅ

์œ„์™€ ๊ฐ™์€ ์žฅ์• ์‹œ๋‚˜๋ฆฌ์˜ค์— ๋Œ€ํ•œ ์†”๋ฃจ์…˜์œผ๋กœ Redis๋Š” WAIT์„ ์‚ฌ์šฉํ•œ๋‹ค.
async ๋ณต์ œ๋ฅผ ์‚ฌ์šฉํ•˜๋˜ ๋•Œ์— ๋”ฐ๋ผ์„œ sync write๋ฅผ ์ง€์›ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
ํ•˜์ง€๋งŒ, ์ด๋Š” ์™„๋ฒฝํ•œ ์ผ๊ด€์„ฑ์„ ๋ณด์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋‹ค์Œ ์žฅ์•  ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ๋ณด์ž.

  1. Master A, B, C์™€ Slave A1, B1, C1 ์กด์žฌ
  2. ๋„คํŠธ์›Œํฌ ํŒŒํ‹ฐ์…˜ ๋ฐœ์ƒ!!
  3. A, C, A1, B1, C1์€ ํŒŒํ‹ฐ์…˜ ํ•œ์ชฝ์—, B์™€ Client๊ฐ€ ๋‹ค๋ฅธ ์ชฝ์— ์กด์žฌ.
  4. Client๋Š” ์žฅ์•  ์ƒํ™ฉ์„ ๋ชจ๋ฅด๊ณ  ๊ณ„์† B์—๊ฒŒ write.
  5. ํŒŒํ‹ฐ์…˜์˜ ์–‘ ์ชฝ์ด ๋‹ค๋ฆ„(write ์œ ์‹ค)

์ด๋ฅผ ์œ„ํ•ด redis cluster๋Š” Node time out์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด write๋ฅผ ๋ถˆํ—ˆํ•œ๋‹ค...

6. Redis cluster config

  • cluster-enabled<yes/no>
    • default: no
    • Redis ์ธ์Šคํ„ด์Šค์—์„œ cluster ํ™œ์„ฑํ™” ์—ฌ๋ถ€
  • cluster-config-file<filename>
    • cluster์˜ ์ƒํƒœ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ
  • cluster-node-timeout<milliseconds>
    • cluster๊ฐ€ ๋‹ค์šด๋˜์—ˆ๋Š”์ง€ ํŒ๋‹จํ•˜๋Š” ์‹œ๊ฐ„.
  • cluster-slave-validity-factor<factor>
    • master์™€ slave ๊ฐ„ ์ฒดํฌ๊ฐ€ ์˜ค๋žซ๋™์•ˆ ๋‹จ์ ˆ๋˜๋ฉด ํ•ด๋‹น slave๋Š” ์Šน๊ฒฉ ๋Œ€์ƒ์—์„œ ์ œ์™ธํ•œ๋‹ค.
    • ์ด๋•Œ, ์Šน๊ฒฉ ๋Œ€์ƒ์—์„œ ์ œ์™ธํ•˜๋Š” ํŒ๋‹จ ๊ธฐ์ค€์˜ ์‹œ๊ฐ„์„ ์„ค์ •
  • cluster-migration-barrier<count>
    • default: 1
    • master์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด์•ผ ํ•˜๋Š” ์ตœ์†Œ slave ์ˆ˜
  • cluster-require-full-coverage<yes/no>
    • cluster์˜ ์ผ๋ถ€๊ฐ€ ๋‹ค์šด๋  ๋•Œ ์šด์˜ํ•  ๋ฐฉ๋ฒ• ์„ค์ •
    • yes: slave๊ฐ€ ์—†๋Š” master๊ฐ€ ๋‹ค์šด๋˜๋ฉด cluster ์ „์ฒด ์ค‘์ง€
    • no: slave์—†๋Š” master๊ฐ€ ๋‹ค์šด๋˜์–ด๋„ cluster ์œ ์ง€. ๋‹จ, ํ•ด๋‹น master slot์—์„œ error ๋ฐœ์ƒ
    • ๋ฐ์ดํ„ฐ ์ •ํ•ฉ์„ฑ์ด ์ค‘์š”ํ•˜๋‹ค๋ฉด yes์„ ํƒ
  • cluster-allow-reads-when-down<yes/no>
    • no: ์‹คํŒจ ์ƒํƒœ ์‹œ ๋ชจ๋“  ํŠธ๋ž˜ํ”ฝ ์ค‘์ง€.
    • yes: ์‹คํŒจ ์ƒํƒœ ๋™์•ˆ์—๋„ ๋…ธ๋“œ์—์„œ read ๊ฐ€๋Šฅ.

0๊ฐœ์˜ ๋Œ“๊ธ€