Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Comments

Use first shard as PoolProxy spec#6

Open
KumatomatomaKu wants to merge 1 commit intotiepadrinofrom
proxy-pool-use-first-shard-as-spec
Open

Use first shard as PoolProxy spec#6
KumatomatomaKu wants to merge 1 commit intotiepadrinofrom
proxy-pool-use-first-shard-as-spec

Conversation

@KumatomatomaKu
Copy link

@KumatomatomaKu KumatomatomaKu commented Aug 20, 2019

master_shard is usually identical across clusters. Therefore, it doesn't make sense to use master_shard's spec as the cluster's one. On the other hand, shards usually are not.

see https://github.com/monsterstrike/activerecord-turntable/blob/tiepadrino/lib/active_record/turntable/base.rb#L66

@KumatomatomaKu
Copy link
Author

日本語で問題を説明し直しますと、ActiveRecordのconnection_handlerではconnection_poolのspec(specification)でそれを一意管理している。管理する構造体としては spec => connection_pool のhashでやっていて、同じspecなら同じdb connectionであろうと、そう持ってますし、ActiveRecordの文脈ではそれは成立する(と思う)。

ところで、turntableではっていうと、connection_proxyをActiveRecordからみる一個のconnection_poolとして仕立てて、その中でいい感じに複数のconnection(masterとseqとshards)を使い分けしてますが、じゃぁそいつのspecはなんだという問題があります。今までは、masterのspecをproxy全体のspecとしましたが、masterは実装上default dbのconnection_poolになりがちで、つまりどのclusterのconnection_proxyでも同じである、となればhandlerではそれらspecも同じだから同じものと一個しかリファレンス持ちませんが、それは間違いで、実はseqもshardsも違うけどmasterだけ同じのclusterを混同することに。それが複数のclusterが同じ枠を取り合いで、handlerが一個のproxyしか管理してないことに。

ではActiveRecordのインターフェイスに満たしつつも全てのconnection_proxyをいい感じに管理できるようにするためには、違うclusterなら違うspecである必要がある。からのこのPR

Copy link

@genkami genkami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コード読んでやっと説明の意味わかりましたw

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants