๐Ÿ˜OID <-> ๐Ÿš€table_id

14554 ๋‹จ์–ด yugabytedbdatabasesqldistributed
YugabyteDB ์›น ์ฝ˜์†” ๋˜๋Š” ์ผ๋ถ€ yb-admin ์ถœ๋ ฅ์„ ๋ณด๋ฉด table_id ๋˜๋Š” uuid ๋กœ ์‹๋ณ„๋˜๋Š” YSQL ํ…Œ์ด๋ธ”์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์˜ˆ์ž…๋‹ˆ๋‹ค.


์ด ํ…Œ์ด๋ธ” ID๋Š” YSQL ํ…Œ์ด๋ธ” ๋˜๋Š” ์ธ๋ฑ์Šค ์ด๋ฆ„์ด "ํ…Œ์ด๋ธ” ์ด๋ฆ„"์œผ๋กœ ํ‘œ์‹œ๋˜๊ณ  YSQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ "ํ‚ค์ŠคํŽ˜์ด์Šค"๋กœ ํ‘œ์‹œ๋˜๋”๋ผ๋„ ํ…Œ์ด๋ธ”, ์ธ๋ฑ์Šค ๋˜๋Š” ํŒŒํ‹ฐ์…˜์„ ์‹๋ณ„ํ•˜๊ธฐ์— ์ถฉ๋ถ„ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. DocDB์˜ ์ €์žฅ์†Œ๋Š” ๋ชจ๋“  API์— ๊ณตํ†ต์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. YSQL ์Šคํ‚ค๋งˆ ๋˜๋Š” ๊ด€๊ณ„ ์œ ํ˜•์„ ๋ชจ๋ฆ…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  YCQL ํ…Œ์ด๋ธ”๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ…Œ์ด๋ธ” OID



์œ„์˜ ์Šคํฌ๋ฆฐ์ƒท์—์„œ "Table OID"๊ฐ€ ํ‘œ์‹œ๋˜๊ธฐ ๋•Œ๋ฌธ์— YSQL ํ…Œ์ด๋ธ”์„ ์‰ฝ๊ฒŒ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์˜ˆ์—์„œ ํ…Œ์ด๋ธ” 00004001000030008000000000004002์€ OID๊ฐ€ categories์ธ yb_demo_northwind ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ 16386 ํ…Œ์ด๋ธ”์ž„์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

yugabyte=# \c yb_demo_northwind

psql (13.5, server 11.2-YB-2.13.1.0-b0)
You are now connected to database "yb_demo_northwind" as user "yugabyte".

select
 current_database(), schema, relname, relkind, am, owner, tablespace
from (                     -- pg_class -> table or index
select relkind, relname, relnamespace, reltype, relowner, relam, reltablespace from pg_class
where oid=16386
) as c natural left join ( -- pg_namespace -> schema
select oid relnamespace, nspname as schema from pg_namespace
) as n natural left join ( -- pg_authid -> owner
select oid relowner, rolname as owner from pg_authid
) as o natural left join ( -- pg_am -> access method
select oid relam, amname am from pg_am
) as a natural left join ( -- spcname pg_tablespace -> tablespace
select oid reltablespace, spcname as tablespace from pg_tablespace
) as t;

 current_database  | schema |  relname   | relkind | am |  owner   | tablespace
-------------------+--------+------------+---------+----+----------+------------
 yb_demo_northwind | public | categories | r       |    | yugabyte |



UUID



๊ทธ๋Ÿฌ๋‚˜ YSQL ํ…Œ์ด๋ธ”์—์„œ table_id๋ฅผ ์ฐพ์•„์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํ‚ค์ŠคํŽ˜์ด์Šค(YSQL์˜ ๊ฒฝ์šฐ PostgreSQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค)์™€ ํ…Œ์ด๋ธ”(YSQL์˜ ๊ฒฝ์šฐ ๊ด€๊ณ„์˜ PostgreSQL OID ํฌํ•จ)์—์„œ ๋นŒ๋“œ๋œ UUID์ž…๋‹ˆ๋‹ค.

์œ„์˜ ๋‚ด table_id: 00004001000030008000000000004002๋ฅผ ๋ถ„ํ•ดํ•˜์—ฌ ๋นŒ๋“œ ๋ฐฉ๋ฒ•์„ ์ดํ•ดํ•ด ๋ด…์‹œ๋‹ค.

00004001-0000-3000-8000-000000004002 
    ^^^^                                -> PostgreSQL Database OID
              ^                         -> UUID Version 3 = name based MD5
                   ^                    -> UUID Variant = DCE 1.1, ISO/IEC
                                ^^^^    -> PostgreSQL Relation OID



code์€ Postgres oids๋ฅผ ํฌํ•จํ•˜๊ธฐ ์œ„ํ•ด ์ด์ „ ์ด๋ฆ„ โ€‹โ€‹๊ธฐ๋ฐ˜ UUID v3์˜ ์šฉ๋„ ๋ณ€๊ฒฝ์ด๋ผ๊ณ  ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

OID



๋‹ค์Œ์€ ํ˜„์žฌ search_path๋กœ ์ฐพ์€ ํ˜„์žฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋‚ด table_id ํ…Œ์ด๋ธ”์— ๋Œ€ํ•ด PostgreSQL์—์„œ categories๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

yb_demo_northwind=#

select format('0000%s00003000800000000000%s'
 ,lpad(to_hex(oid::int), 4, '0')
 ,lpad(to_hex('categories'::regclass::oid::int),4,'0')
 ) table_id from pg_database where datname=current_database()

             table_id
----------------------------------
 00004001000030008000000000004002
(1 row)


์˜ˆ๋ฅผ ๋“ค์–ด ํƒœ๋ธ”๋ฆฟ ์ •์˜๋ฅผ http://yb-tmaster-0:7000/table?id=00004001000030008000000000004002๋กœ ์ง์ ‘ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ์ด๊ฒƒ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ด ์—”๋“œํฌ์ธํŠธ๋Š” keyspace_name ๋Œ€์‹  table_id ๋ฐ id๊ฐ€ ์žˆ๋Š” ํƒœ๋ธ”๋ฆฟ๋„ ์ฐพ์„ ์ˆ˜ ์žˆ์ง€๋งŒ ์Šคํ‚ค๋งˆ๊ฐ€ ์—†๋Š” YCQL์—์„œ๋งŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

yb ๊ด€๋ฆฌ์ž



ํ…Œ์ด๋ธ” ID๋ฅผ ์•„๋Š” ๊ฒƒ์€ UUID์— yb-admin ์ ‘๋‘์–ด๋ฅผ ๋ถ™์ด๋Š” tableid. ๋ช…๋ น์—๋„ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ /home/opc/yugabyte-2.13.1.0/bin/yb-admin list_tablets  tableid.00004001000030008000000000004002

Tablet-UUID                             Range                                                           Leader-IP               Leader-UUID
e4216871ffd644c3b616d37668400212        partition_key_start: "" partition_key_end: "UU"                 10.0.0.61:9100          1e6aa7f085d146e8b29207483592116a
85f1061e6f10410888cbbf6418d7047c        partition_key_start: "UU" partition_key_end: "\252\252"         10.0.0.63:9100          9eec605aede445e98ad61bf833dbf6cc
2884fe988f304591b2905e5272a571f9        partition_key_start: "\252\252" partition_key_end: ""           10.0.0.62:9100          4729e36c42934175817c580b52ea6a18

list_tablets๋Š” ํ‚ค์ŠคํŽ˜์ด์Šค์— ysql. ์ ‘๋‘์‚ฌ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ YSQL ํ…Œ์ด๋ธ” ์ด๋ฆ„์œผ๋กœ ์ž‘์—…ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

]$ /home/opc/yugabyte-2.13.1.0/bin/yb-admin list_tablets  ysql.yb_demo_northwind categories

Tablet-UUID                             Range                                                           Leader-IP               Leader-UUID
e4216871ffd644c3b616d37668400212        partition_key_start: "" partition_key_end: "UU"                 10.0.0.61:9100          1e6aa7f085d146e8b29207483592116a
85f1061e6f10410888cbbf6418d7047c        partition_key_start: "UU" partition_key_end: "\252\252"         10.0.0.63:9100          9eec605aede445e98ad61bf833dbf6cc
2884fe988f304591b2905e5272a571f9        partition_key_start: "\252\252" partition_key_end: ""           10.0.0.62:9100          4729e36c42934175817c580b52ea6a18


๊ทธ๋Ÿฌ๋‚˜ ์ด๊ฒƒ์€ ์ด ์ด๋ฆ„์„ ๊ฐ€์ง„ ํ…Œ์ด๋ธ”์ด ํ•˜๋‚˜๋งŒ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์Šคํ‚ค๋งˆ์—์„œ ๋‹ค๋ฅธ ์Šคํ‚ค๋งˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ:

yb_demo_northwind=# create schema franck;
CREATE SCHEMA
yb_demo_northwind=# create table franck.categories (a int);
CREATE TABLE
yb_demo_northwind=#


๋™์ผํ•œyb-admin ๋ช…๋ น์ด ์ด์ œ ์ด๋ฆ„์œผ๋กœ DocDB ํ…Œ์ด๋ธ”์„ ์‹๋ณ„ํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.

$ /home/opc/yugabyte-2.13.1.0/bin/yb-admin -init_master_addrs=10.0.0.61:7100 list_tablets  ysql.yb_demo_northwind categories

Error running list_tablets: Invalid argument (yb/tools/yb-admin_client.cc:406): Namespace 'ysql.yb_demo_northwind' has multiple tables named 'categories', specify table id instead


์š”์ปจ๋Œ€



ํ‚ค์ŠคํŽ˜์ด์Šค์™€ ํ…Œ์ด๋ธ” ์ด๋ฆ„์˜ ์กฐํ•ฉ์€ YCQL์— ๋Œ€ํ•ด์„œ๋งŒ ํ…Œ์ด๋ธ”์„ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. YSQL์„ ์‚ฌ์šฉํ•˜๋ฉด PostgreSQL ์Šคํ‚ค๋งˆ์ธ ํ…Œ์ด๋ธ” ๋‚ด์— ์—ฌ๋Ÿฌ ๋„ค์ž„์ŠคํŽ˜์ด์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. DocDB์—์„œ YSQL ๊ด€๊ณ„๋ฅผ ์‹๋ณ„ํ•˜๋ ค๋ฉด PostgreSQL ๊ฐ์ฒด ์‹๋ณ„์ž(OID)์—์„œ ๊ตฌ์„ฑ๋œ UUID์ธ ํ…Œ์ด๋ธ” ID๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์œ„์˜ ์ฟผ๋ฆฌ๋ฅผ ์ด ์šฉ๋„๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฃผ๋ง์— 14์‚ด์งœ๋ฆฌ ์•„์ด์™€ ์ˆ˜ํ•™์„ ์ข€ ํ–ˆ๊ณ , YSQL ํ…Œ์ด๋ธ”์„ DocDB ํ…Œ์ด๋ธ”์— ์ด๋ฆ„์œผ๋กœ ๋งคํ•‘ํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ non-injective ์ด๋ผ๋Š” ๊ฒƒ์„ ์ด์ œ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹จ์‚ฌ ํ•จ์ˆ˜๋ฅผ ์–ป์œผ๋ ค๋ฉด UUID๋กœ ๋งคํ•‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. YCQL์— ๋Œ€ํ•œ ํ…Œ์ด๋ธ”๋„ ๋ณด์œ ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— DocDB์˜ ๋ชจ๋“  UUID๋ฅผ ๊ณ ๋ คํ•œ๋‹ค๋ฉด ์—ฌ์ „ํžˆ non-surjective์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ UUID ๋ฒ„์ „ 3์—์„œ๋Š” bijection ์ด๋ฏ€๋กœ URL ๋ฐ yb-admin ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. YCQL ๋˜๋Š” ์‹œ์Šคํ…œ ํ…Œ์ด๋ธ”๊ณผ ๊ฐ™์€ ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์€ UUID ๋ฒ„์ „ 4์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํ…Œ์ด๋ธ” ID์˜ 16์ง„์ˆ˜ ํ‘œํ˜„์—์„œ 13๋ฒˆ์งธ ์ˆซ์ž์™€ ์‰ฝ๊ฒŒ ๊ตฌ๋ณ„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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