๐Ÿš€ YugabyteDB ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•œ ์ง€๋ฆฌ์  ๋ถ„ํฌ

12365 ๋‹จ์–ด sqlyugabytedbpostgresdistributed
์ด ์‹œ๋ฆฌ์ฆˆ์˜ ์ฒซ ๋ฒˆ์งธ ๊ฒŒ์‹œ๋ฌผ์—์„œ๋Š” 5๊ฐœ์˜ ๋…ธ๋“œ๊ฐ€ ์žˆ๋Š” RF=3 ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๋งŒ๋“ค๊ณ  ํƒœ๋ธ”๋ฆฟ์— ๋Œ€ํ•œ RF=5 ๋ฐฐ์น˜๋ฅผ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ๋™์ผํ•œ ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•˜์ง€๋งŒ ๋ณด๋‹ค ๋ฏธ์„ธํ•œ ์ˆ˜์ค€์˜ ์ œ์–ด๋ฅผ ์œ„ํ•ด ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋กœ ๋ฐฐ์น˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ์ธ๋ฑ์Šค, ํ…Œ์ด๋ธ” ๋ฐ ํŒŒํ‹ฐ์…˜์„ ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค์— ์ƒ์„ฑํ•˜์—ฌ ๋ฐฐ์น˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

YugabyteDB ํด๋Ÿฌ์Šคํ„ฐ ์„ค์ •



5๊ฐœ์˜ ๋…ธ๋“œ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

docker network create -d bridge yb

docker run -d --network yb --name yb-eu-1 -p5001:5433 -p7001:7000 -p9001:9000 \
yugabytedb/yugabyte:2.15.0.0-b11 \
yugabyted start --daemon=false --listen yb-eu-1 \
 --master_flags="placement_zone=1,placement_region=eu,placement_cloud=cloud" \
--tserver_flags="placement_zone=1,placement_region=eu,placement_cloud=cloud"

docker run -d --network yb --name yb-eu-2 -p5002:5433 -p7002:7000 -p9002:9000 \
yugabytedb/yugabyte:2.15.0.0-b11 \
yugabyted start --daemon=false --listen yb-eu-2 --join yb-eu-1 \
 --master_flags="placement_zone=2,placement_region=eu,placement_cloud=cloud" \
--tserver_flags="placement_zone=2,placement_region=eu,placement_cloud=cloud"

docker run -d --network yb --name yb-us-1 -p5003:5433 -p7003:7000 -p9003:9000 \
yugabytedb/yugabyte:2.15.0.0-b11 \
yugabyted start --daemon=false --listen yb-us-1 --join yb-eu-1 \
 --master_flags="placement_zone=1,placement_region=us,placement_cloud=cloud" \
--tserver_flags="placement_zone=1,placement_region=us,placement_cloud=cloud"

docker run -d --network yb --name yb-ap-1 -p5004:5433 -p7004:7000 -p9004:9000 \
yugabytedb/yugabyte:2.15.0.0-b11 \
yugabyted start --daemon=false --listen yb-ap-1 --join yb-eu-1 \
 --master_flags="placement_zone=1,placement_region=ap,placement_cloud=cloud" \
--tserver_flags="placement_zone=1,placement_region=ap,placement_cloud=cloud"

docker run -d --network yb --name yb-au-1 -p5005:5433 -p7005:7000 -p9005:9000 \
yugabytedb/yugabyte:2.15.0.0-b11 \
yugabyted start --daemon=false --listen yb-au-1 --join yb-eu-1 \
 --master_flags="placement_zone=1,placement_region=au,placement_cloud=cloud" \
--tserver_flags="placement_zone=1,placement_region=au,placement_cloud=cloud"


yugabyted๊ฐ€ cloud1.datacenter1.rack1๋ฅผ ์ •์˜ํ•˜์ง€๋งŒ ๋‹ค๋ฅธ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ RF=3์„ ์œ ์ง€ํ•˜๋ฉด์„œ ๊ธฐ๋ณธ ๋ฐฐ์น˜๋ฅผ ์ •์˜ํ•˜์ง€๋งŒ ๋‘˜ ๋‹คeu์— ํ•˜๋‚˜ ์ด์ƒ์˜ ํƒœ๋ธ”๋ฆฟ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

docker exec -i yb-eu-1 yb-admin -master_addresses yb-eu-1:7100,yb-eu-2:7100,yb-us-1:7100 \
modify_placement_info \
cloud.eu.1:1,cloud.eu.2:1,cloud.us.1:0,cloud.ap.1:0,cloud.au.1:0 \
3

docker exec -i yb-eu-1 yb-admin -master_addresses yb-eu-1:7100,yb-eu-2:7100,yb-us-1:7100 \
set_preferred_zones cloud.eu.1 cloud.eu.2



ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค



์ด ์‹œ๋ฆฌ์ฆˆ์˜ ์ฒซ ๋ฒˆ์งธ ๊ฒŒ์‹œ๋ฌผ์—์„œ๋Š” yb-admin modify_placement_info cloud.eu.1:1,cloud.eu.2:1,cloud.us.1:1,cloud.ap.1:1,cloud.au.1:1 \
5
๋กœ ๋ณต์ œ๋ณธ ๋ฐ ๋ฐฐ์น˜ ๋ธ”๋ก ์ˆ˜๋ฅผ ์ •์˜ํ•˜๊ณ  yb-admin set_preferred_zones cloud.eu.1 cloud.eu.2๋กœ ๋ฆฌ๋” ์„ ํ˜ธ๋„๋ฅผ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํด๋Ÿฌ์Šคํ„ฐ ์ˆ˜์ค€์ด์—ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ๊ธฐ๋ณธ๊ฐ’(๋ฆฌ๋”๊ฐ€ ๋ชจ๋“  ํด๋Ÿฌ์Šคํ„ฐ์— ๋ถ„์‚ฐ๋œ RF=3)์„ ๊ทธ๋Œ€๋กœ ๋‘์ง€๋งŒ ๋™์ผํ•œ ๋ฐฐ์น˜๋กœ eu_preferred๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

psql -p 5001 -c '
create tablespace eu_preferred with (
  replica_placement=$placement$
{
    "num_replicas": 5,
    "placement_blocks": [{
            "cloud": "cloud",
            "region": "eu",
            "zone": "1",
            "min_num_replicas": 1,
            "leader_preference": 1
        },
        {
            "cloud": "cloud",
            "region": "eu",
            "zone": "2",
            "min_num_replicas": 1,
            "leader_preference": 1
        },
        {
            "cloud": "cloud",
            "region": "us",
            "zone": "1",
            "min_num_replicas": 1
        },
        {
            "cloud": "cloud",
            "region": "ap",
            "zone": "1",
            "min_num_replicas": 1
        },
        {
            "cloud": "cloud",
            "region": "au",
            "zone": "1",
            "min_num_replicas": 1
        }
    ]
}$placement$)
'


๋ฆฌ๋” ๋ฐ ์ถ”์ข…์ž ๋ฐฐ์น˜



์ด์ „ ๊ฒŒ์‹œ๋ฌผ๊ณผ ๋™์ผํ•˜๊ฒŒ ์‹คํ–‰ํ•˜์ง€๋งŒ ์ƒˆ ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค์— ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

psql -p 5005 -e <<SQL
drop table if exists demo;
create table demo tablespace eu_preferred 
 as select generate_series(1,1000) n;
update demo set n=n+1;
\watch 0.01
SQL



๋ฆฌ๋”๋Š” eu์— ์žˆ์œผ๋ฉฐ ์—ฌ๊ธฐ์—์„œ ์ฝ๊ธฐ ๋ฐ ์“ฐ๊ธฐ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.


๋ชจ๋“  ์ง€์—ญ์— ํŒ”๋กœ์›Œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.


์ด ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค์˜ ํ…Œ์ด๋ธ”์€ ์ด ์‹œ๋ฆฌ์ฆˆ์™€ ๋™์ผํ•œ ๋ถ„ํฌ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ๋ถ„ํฌ



ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋Š” ํŠน์ • ํ…Œ์ด๋ธ”์— ๋Œ€ํ•œ ์ œ์–ด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ์€ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์—๊ฒŒ๋Š” ๊ธฐ๋ณธ๊ฐ’์ž…๋‹ˆ๋‹ค. ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋ฅผ ์–ธ๊ธ‰ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฐฐํฌ๋Š” ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ธฐ๋ณธ ํƒœ๋ธ”๋ฆฟ ๋ฐฐ์น˜๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

psql -p 5005 -e <<SQL
drop table if exists simple ;
create table simple 
 as select generate_series(1,1000) n;
update simple set n=n+1;
\watch 0.01
SQL



์ด๊ฒƒ์€ eu์— ๋‘ ๊ฐœ์˜ ํƒœ๋ธ”๋ฆฟ์ด ์žˆ๋Š” ๋‚ด ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ธฐ๋ณธ๊ฐ’์„ ์‚ฌ์šฉํ•˜๊ณ  ๊ฑฐ๊ธฐ์— ์„ ํ˜ธํ•˜๋Š” ๋ฆฌ๋”๊ฐ€ ์žˆ๊ณ  ๋‹ค๋ฅธ ์ง€์—ญ์— ํŒ”๋กœ์›Œ๊ฐ€ ํ•œ ๋ช… ์žˆ์Šต๋‹ˆ๋‹ค.



์—…๋ฐ์ดํŠธ๋Š” ๋ฆฌ๋”์—๊ฒŒ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.


์ด์ œ au์— ์—ฐ๊ฒฐํ•˜๊ณ  ํŒ”๋กœ์–ด ์ฝ๊ธฐ๋ฅผ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.

psql -p 5005 -e <<SQL
set yb_read_from_followers=on;
set default_transaction_read_only = on;
explain analyze select * from simple;
\watch 0.01
SQL


๊ธฐ๋ณธ ํด๋Ÿฌ์Šคํ„ฐ ๋ฐฐํฌ(RF=3์ธ 5๊ฐœ ๋…ธ๋“œ)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด ๊ฐ„๋‹จํ•œ ํ…Œ์ด๋ธ”๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ชจ๋“  ๋…ธ๋“œ์— ๋ชจ๋“  ๋ฐ์ดํ„ฐ์˜ ๋ณต์‚ฌ๋ณธ์ด ์—†์œผ๋ฉฐ ์ฝ๊ธฐ๊ฐ€ ๋ชจ๋“  ๋…ธ๋“œ์— ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค.


์ด๊ฒƒ์€ ํŒ”๋กœ์–ด ์ฝ๊ธฐ์˜ ๋˜ ๋‹ค๋ฅธ ์žฅ์ ์ž…๋‹ˆ๋‹ค. ๋ฆฌ๋”๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋„ ์ฝ๊ธฐ๊ฐ€ ๋ถ„์‚ฐ๋ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ๋ฐฐ์น˜ ๋ฐ ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค ๋•๋ถ„์— ๋‘ ๊ฒฝ์šฐ ๋ชจ๋‘ ํƒœ๋ธ”๋ฆฟ ๋ฆฌ๋”๋ฅผ ํŠน๋ณ„ํžˆ ๊ณ ๋ คํ•˜์—ฌ ๋ชจ๋“  ์ง€์—ญ์—์„œ ๋ณต์ œํ•  ํ…Œ์ด๋ธ”๊ณผ ๋ฐฐํฌํ•  ํ…Œ์ด๋ธ”์„ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ…Œ์ด๋ธ”์ด๋ž€ ์ธ๋ฑ์Šค์™€ ํŒŒํ‹ฐ์…˜๋„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ๋ฆฌ๋”๋ฅผ ๋ฐฐ์น˜ํ•  ์ฃผ์š” ์ง€์—ญ์œผ๋กœ eu๋ฅผ ๊ณ ๋ คํ–ˆ์ง€๋งŒ ์„ ์–ธ์  ํŒŒํ‹ฐ์…”๋‹์„ ์‚ฌ์šฉํ•˜๋ฉด ์‚ฌ์šฉ์ž ๊ตญ๊ฐ€์™€ ๊ฐ™์€ ํ…Œ์ด๋ธ” ์—ด์˜ ๋น„์ฆˆ๋‹ˆ์Šค ๊ฐ’์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์งˆ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ