Slide 1

Slide 1 text

Fukuoka.go#15 with Kagoshima Gophers Tomohisa Oda / Mar 2, 2020 What isCockroachDB

Slide 2

Slide 2 text

Fukuoka.go#15 with Kagoshima Gophers @linyows blog: tomohisaoda.com affiliation: GMO pepabo, inc.

Slide 3

Slide 3 text

Fukuoka.go#15 with Kagoshima Gophers Private Projects ΞϓϦέʔγϣϯࣗ਎͕ϦϙδτϦ͔Β࠷৽ͷίʔυΛݕ ஌ͯࣗ͠ಈͰσϓϩΠͱσϦόϦʔΛߦ͏πʔϧ MJOVYͷVTFS໊લղܾΛ(JU)VCͷ5FBNϝϯόʔ΍Ϧϙδτ ϦͷΞΫηεݖݶऀ͔Βߦ͏πʔϧ

Slide 4

Slide 4 text

Fukuoka.go#15 with Kagoshima Gophers ͓࿳ͼ"CockroachDBίʔυϦʔσΟϯά"͸ "CockroachDBͬͯԿ" ʹͳΓ·ͨ͠ɻ

Slide 5

Slide 5 text

Fukuoka.go#15 with Kagoshima Gophers CockroachDBͱ͸

Slide 6

Slide 6 text

Fukuoka.go#15 with Kagoshima Gophers ๏ ஍ཧత෼ࢄ42-σʔλϕʔε ๏ 3%#ͱ/P42-ͷਐԽܥͰ͋Δ/FX42- ๏ ࣗಈ'BJMPWFSͱࣗಈ3FQBJS ๏ .VMUJ"DUJWFͳՄ༻ੑ ๏ 1PTUHSF42-ޓ׵ͰطଘͷυϥΠό͕࢖༻Ͱ͖Δ CockroachDB

Slide 7

Slide 7 text

Fukuoka.go#15 with Kagoshima Gophers

Slide 8

Slide 8 text

Fukuoka.go#15 with Kagoshima Gophers Design ਫฏͷεέʔϥϏϦςΟ ๏ ࿦ཧతʹ͸ແݶʹ૿΍ͤΔ ๏ ΫΤϦ෼ࢄͰ୯ҰΫΤϦΛશମత εϧʔϓοτ޲্ ߴ͍ੜଘੑ ๏ Ϛγϯ෼ࢄɺϥοΫ෼ࢄɺ஍ཧత ෼ࢄ ๏ ࣗݾम෮ɺࣗݾෛՙόϥϯγϯά ڧ͍Ұ؏ੑ ๏ ߹ҙϕʔεͷϨϓϦέʔγϣϯ ๏ "$*%ηϚϯςΟΫεΛຬͨ͢෼ ࢄτϥϯβΫγϣϯ

Slide 9

Slide 9 text

Fukuoka.go#15 with Kagoshima Gophers ๏ 42-*OUFSGBDF͕ͩத਎͸෼ࢄ,74UPSF -FWFM%#ͷϑΥʔΫ3PDLT%# ๏ ςʔϒϧΛ3BOHFͱ͍͏.#Ҏ಺ͷαΠζʹͨ͠୯ҐͰ෼ׂ ๏ 3BOHF͕ϨϓϦέʔγϣϯͷ୯ҐͰ/PEFؒͰ4IBSEJOH͢Δ ๏ ϨϓϦέʔγϣϯ͸3BGUΞϧΰϦζϜͰߦ͍ɺ5SJQMJDBUFEʢ̏ॏʣߦ͑Δ ๏ ϨϓϦΧͷ૯਺/'ͱ͢Δͱ࠷େ'ݸͷো֐ʹ଱͑Δ Architecture

Slide 10

Slide 10 text

Fukuoka.go#15 with Kagoshima Gophers SQL Transactional Distribution Replication Storage Client Foo : ID = [1, 51] Foo : ID = [51, 103] … Table Foo Index FooIdx Table Bar … Node1 Node2 Node3 Node4 64M Ranges Range Index 64M

Slide 11

Slide 11 text

Fukuoka.go#15 with Kagoshima Gophers CockroachDB͕΍ͬͯ͘ΕΔ͜ͱ

Slide 12

Slide 12 text

Fukuoka.go#15 with Kagoshima Gophers ReplicasͷϦόϥϯγϯάۉҰԽ $MVTUFSʹ/PEFΛ৽͘͠௥Ճ͢Δ $PDLSPBDI%#͸3BOHFΛ഑ஔ͢Δ $PDLSPBDI%#͸$MVTUFSΛۉ౳ʹ͢Δ

Slide 13

Slide 13 text

Fukuoka.go#15 with Kagoshima Gophers ReplicasͷϦόϥϯγϯάम෮ ো֐͕ൃੜ͠/PEFΛফࣦ͢Δ $PDLSPBDI%#͸3FQMJDBͷܽམΛೝࣝͯ͠ "DUJWF/PEF্ʹϨϓϦΧΛஔ͖׵͑Δ ো֐͕Ұ࣌తͰ/PEF͕෮ؼͨ͠Β -FBTIPMEFSͱݺ͹ΕΔ3BGU-FBEFS͕ ϨϓϦΧΛΩϟονΞοϓ͢Δ

Slide 14

Slide 14 text

Fukuoka.go#15 with Kagoshima Gophers ๏ 51$$ϕϯνϚʔΫʹ͓͍ͯ"NB[PO"VSPSB ͱൺֱ͢Δͱഒͷεϧʔϓοτ͕͋Δ ๏ ͜ͷεϧʔϓοτ͸51$$ϥϯΩϯάͰ൪ ໨ʹେ͖͍ ๏ ,7 SFBE XSJUF Ͱ/PEF਺ͷ૿Ճʹ ΑͬͯτϥϯβΫγϣϯͷॲཧೳྗ͕ઢܗʹ ޲্͍ͯ͘͜͠ͱ͕Θ͔͍ͬͯΔ ๏ $PDLSPBDI%#ʹ͸ཧ࿦্ͷεέʔϦϯά੍ ݶ͸ͳ͍ͱͷ͜ͱ Performance

Slide 15

Slide 15 text

Fukuoka.go#15 with Kagoshima Gophers CockroachDBͷ࣮૷

Slide 16

Slide 16 text

Fukuoka.go#15 with Kagoshima Gophers ๏ (P Ҏ্͸ඇਪ঑ ๏ $DPNQJMFS͕ඞཁ 3PDLT%#΍$SZQUPɺ,FSCFSPTɺ4OBQQZͳͲʹґଘ ๏ (Pͷσ ΟϨΫτϦߏ੒͸ࢸͬͯී௨QLHʹ࣮૷͕͋Δ ๏ ֎෦QLH͸ఔͳͷͰن໛తʹґଘ͕গͳ͍Α͏ʹݟ͑Δ https://github.com/cockroachdb/cockroach ࣮૷ʹ͍ͭͯ $ tree pkg | grep .go | grep -v test.go | wc -l 2405 // ͜ͷϑΝΠϧ਺ͰίʔυϦʔσΟϯά͢Δؾ͕ͳ͘ͳͬͨ $ grep 'name =' Gopkg.toml | grep -v golang | grep -v cockroach | wc -l 20

Slide 17

Slide 17 text

Fukuoka.go#15 with Kagoshima Gophers CockroachDBΛ͞ΘͬͯΈΔ

Slide 18

Slide 18 text

Fukuoka.go#15 with Kagoshima Gophers ๏ IFMNͰ$PDLSPBDI%#ΫϥελΛ࡞੒ 4UBUFGVM4FUͷͭͷ1PE͕ىಈ helm install my-release --values my-values.yaml stable/cockroachdb kubectl get csr ๏ $PDLSPBDI%#ϊʔυͷূ໌ॻʹॺ໊͢ΔͨΊͷ$43Λঝೝ kubectl certificate approve default.node.my-release-cockroachdb-0 kubectl certificate approve default.client.root kubectl get pv ๏ #VJMUJO$MJFOUͷ४උ kubectl create -f client-secure.yaml kubectl exec -it cockroachdb-client-secure -- ./cockroach sql --certs-dir=/cockroach-certs —host=my-release-cockroachdb-public https://www.cockroachlabs.com/docs/stable/orchestrate-a-local-cluster-with-kubernetes.html KubernetesΛ࢖ͬͯDemo: ४උ

Slide 19

Slide 19 text

Fukuoka.go#15 with Kagoshima Gophers ๏ 42-ͷ࣮ߦ CREATE DATABASE bank; CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL); INSERT INTO bank.accounts VALUES (1, 1000.50); SELECT * FROM bank.accounts; CREATE USER roach WITH PASSWORD 'Q7gc8rEdS'; INSERT INTO system.role_members (role, member, "isAdmin") VALUES ('admin', 'roach', true); ๏ ίϯιʔϧϩάΠϯ kubectl port-forward my-release-cockroachdb-0 8080 ๏ /PEF'BJMPWFSɺ/PEFͷ௥Ճɺ࡟আ kubectl delete pod my-release-cockroachdb-2 helm upgrade my-release stable/cockroachdb --set statefulset.replicas=4 —reuse-values kubectl certificate approve default.node.my-release-cockroachdb-3 kubectl exec -it cockroachdb-client-secure -- ./cockroach node status --certs-dir=/cockroach-certs —host=my-release-cockroachdb-public kubectl exec -it cockroachdb-client-secure -- ./cockroach node decommission 2 --certs-dir=/cockroach-certs —host=my-release-cockroachdb-public helm upgrade my-release stable/cockroachdb --set statefulset.replicas=3 --reuse-values https://www.cockroachlabs.com/docs/stable/orchestrate-a-local-cluster-with-kubernetes.html KubernetesΛ࢖ͬͯDemo: ૢ࡞

Slide 20

Slide 20 text

Fukuoka.go#15 with Kagoshima Gophers add node to cluster delete a pod

Slide 21

Slide 21 text

Fukuoka.go#15 with Kagoshima Gophers ๏ IUUQTHJUIVCDPNDPDLSPBDIECDPDLSPBDICMPCNBTUFSEPDTEFTJHONE ๏ IUUQTXXXDPDLSPBDIMBCTDPNEPDTTUBCMFBSDIJUFDUVSFPWFSWJFXIUNM ๏ IUUQTXXXDPDLSPBDIMBCTDPNEPDTTUBCMFDPDLSPBDIECJODPNQBSJTPOIUNM ๏ IUUQTXXXDPDLSPBDIMBCTDPNEPDTTUBCMFNVMUJBDUJWFBWBJMBCJMJUZIUNM ๏ IUUQTXXXDPDLSPBDIMBCTDPNCMPHMJNJUTPGUIFDBQUIFPSFN ๏ IUUQTXXXJOGPRDPNQSFTFOUBUJPOTDPDLSPBDIECEJTUSJCVUFETRM ๏ IUUQTXXXDPDLSPBDIMBCTDPNCMPHUQDDL ๏ IUUQTXXXDPDLSPBDIMBCTDPNEPDTTUBCMFPSDIFTUSBUFBMPDBMDMVTUFSXJUILVCFSOFUFTIUNM References

Slide 22

Slide 22 text

Fukuoka.go#15 with Kagoshima Gophers Thank youaʕ⊙౪⚆ʔ