07. In-Sync Replicas
Last updated
Last updated
Leader ์ฅ์ ์ Leader๋ฅผ ์ ์ถํ๋๋ฐ ์ฌ์ฉ
In-Sync Replicas(ISR)๋ High Water Mark๋ผ๊ณ ํ๋ ์ง์ ๊น์ง ๋์ผํ Replicas (Leader์ Follower ๋ชจ๋)์ ๋ชฉ๋ก
Leader์ ์ฅ์ ๊ฐ ๋ฐ์ํ๋ฉด, ISR ์ค์์ ์ Leader๋ฅผ ์ ์ถ
๋ฉ์์ง ์ ์ ๋์ด ๊ฐ์๊ธฐ ๋์ด๋ ๊ฒฝ์ฐ
replica.lag.max.messages ๋ก ISR ํ๋จ์ ๋ํ๋ ์ ์๋ ๋ฌธ์ ์
๋ฉ์์ง ์ ์ ๋์ด ๊ฐ์๊ธฐ ๋์ด๋ ๊ฒฝ์ฐ(์, ์ด๋น 10 msg/sec), ์ง์ฐ์ผ๋ก ํ๋จํ๊ณ OSR(Outof-Sync Replica)๋ก ์ํ๋ฅผ ๋ณ๊ฒฝ์ํด
๋ฉ์์ง๊ฐ ํญ์ ์ผ์ ํ ๋น์จ(์ด๋น ์ ์ ๋๋ ๋ฉ์์ง, 3 msg/sec ์ดํ )๋ก Kafka๋ก ๋ค์ด์ฌ ๋, replica.lag.max.messages=5๋ก ํ๋ฉด 5 ๊ฐ ์ด์์ผ๋ก ์ง์ฐ๋๋ ๊ฒฝ์ฐ๊ฐ ์์ผ๋ฏ๋ก ISR๋ค์ด ์ ์์ ์ผ๋ก ๋์
์ค์ Follower๋ ์ ์์ ์ผ๋ก ๋์ํ๊ณ ๋จ์ง ์ ๊น ์ง์ฐ๋ง ๋ฐ์ํ์ ๋ฟ์ธ๋ฐ, replica.lag.max.messages ์ต์ ์ ์ด์ฉํ๋ฉด OSR๋ก ํ๋จํ๊ฒ ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ (์ด์์ค์ ๋ถํ์ํ error ๋ฐ์ ๋ฐ ๊ทธ๋ก ์ธํ ๋ถํ์ํ retry ์ ๋ฐ)
confluent ์๋ฃจ์ ์์๋ ์ ๊ณต๋์ง ์๋๋ค.
replica.lag.time.max.ms์ผ๋ก ํ๋จํด์ผ ํจ
Follower๊ฐ Leader๋ก Fetch ์์ฒญ์ ๋ณด๋ด๋ Interval์ ์ฒดํฌ
์) replica.lag.time.max.ms = 10000 ์ด๋ผ๋ฉด Follower๊ฐ Leader๋ก Fetch ์์ฒญ์ 10000 ms ๋ด์๋ง ์์ฒญํ๋ฉด ์ ์์ผ๋ก ํ๋จ
Confluent ์์๋ replica.lag.time.max.ms ์ต์ ๋ง ์ ๊ณต(๋ณต์ก์ฑ ์ ๊ฑฐ)
Zookeeper์ ISR ์ ๋ฐ์ดํธ, Controller๊ฐ Zookeeper๋ก๋ถํฐ ์์
Follower๊ฐ ๋๋ฌด ๋๋ฆฌ๋ฉด Leader๋ ISR์์ Follower๋ฅผ ์ ๊ฑฐํ๊ณ ZooKeeper์ ISR์ ์ ์ง
Controller๋ Partition Metadata์ ๋ํ ๋ณ๊ฒฝ ์ฌํญ์ ๋ํด์ Zookeeper๋ก๋ถํฐ ์์
Kafka Cluster ๋ด์ Broker์ค ํ๋๊ฐ Controller๊ฐ ๋จ
Controller๋ ZooKeeper๋ฅผ ํตํด Broker Liveness๋ฅผ ๋ชจ๋ํฐ๋ง
Controller๋ Leader์ Replica ์ ๋ณด๋ฅผ Cluster๋ด์ ๋ค๋ฅธ Broker๋ค์๊ฒ ์ ๋ฌ
Controller๋ ZooKeeper์ Replicas ์ ๋ณด์ ๋ณต์ฌ๋ณธ์ ์ ์งํ ๋ค์ ๋ ๋น ๋ฅธ ์ก์ธ์ค๋ฅผ ์ํด ํด๋ฌ์คํฐ์ ๋ชจ๋ Broker๋ค์๊ฒ ๋์ผํ ์ ๋ณด๋ฅผ ์บ์ํจ
Controller๊ฐ Leader ์ฅ์ ์ Leader Election์ ์ํ
Controller๊ฐ ์ฅ์ ๊ฐ ๋๋ฉด ๋ค๋ฅธ Active Broker๋ค ์ค์์ ์ฌ์ ์ถ๋จ
Last Committed Offset(Current Offset) : Consumer๊ฐ ์ต์ข Commitํ Offset
Current Position : Consumer๊ฐ ์ฝ์ด๊ฐ ์์น(์ฒ๋ฆฌ ์ค, Commit ์ )
High Water Mark(Committed) : ISR(Leader-Follower)๊ฐ์ ๋ณต์ ๋ Offset
Log End Offset : Producer๊ฐ ๋ฉ์์ง๋ฅผ ๋ณด๋ด์ ์ ์ฅ๋, ๋ก๊ทธ์ ๋งจ ๋ Offset
ISR ๋ชฉ๋ก์ ๋ชจ๋ Replicas๊ฐ ๋ฉ์์ง๋ฅผ ๋ฐ์ผ๋ฉด โCommittedโ
Consumer๋ Committed ๋ฉ์์ง๋ง ์ฝ์ ์ ์์
Leader๋ ๋ฉ์์ง๋ฅผ Commitํ ์๊ธฐ๋ฅผ ๊ฒฐ์
Committed ๋ฉ์์ง๋ ๋ชจ๋ Follower์์ ๋์ผํ Offset์ ๊ฐ๋๋ก ๋ณด์ฅ
์ฆ, ์ด๋ค Replica๊ฐ Leader์ธ์ง์ ๊ด๊ณ์์ด (์ฅ์ ๋ฐ์์ด๋ผ๋) ๋ชจ๋ Consumer๋ ํด๋น Offset์์ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ณผ ์ ์์
Broker๊ฐ ๋ค์ ์์ํ ๋ Committed ๋ฉ์์ง ๋ชฉ๋ก์ ์ ์งํ๋๋ก ํ๊ธฐ ์ํด, Broker์ ๋ชจ๋ Partition์ ๋ํ ๋ง์ง๋ง Committed Offset์ replicationoffset-checkpoint๋ผ๋ ํ์ผ์ ๊ธฐ๋ก๋จ
High Water Mark, Leader Epoch
High Water Mark
๊ฐ์ฅ ์ต๊ทผ์ Committed ๋ฉ์์ง์ Offset ์ถ์
replication-offset-checkpoint ํ์ผ์ ์ฒดํฌํฌ์ธํธ๋ฅผ ๊ธฐ๋ก
Leader Epoch
์ Leader๊ฐ ์ ์ถ๋ ์์ ์ Offset์ผ๋ก ํ์
Broker ๋ณต๊ตฌ ์ค์ ๋ฉ์์ง๋ฅผ ์ฒดํฌํฌ์ธํธ๋ก ์๋ฅธ ๋ค์ ํ์ฌ Leader๋ฅผ ๋ฐ๋ฅด๊ธฐ ์ํด ์ฌ์ฉ๋จ
Controller๊ฐ ์ Leader๋ฅผ ์ ํํ๋ฉด Leader Epoch๋ฅผ ์ ๋ฐ์ดํธํ๊ณ ํด๋น ์ ๋ณด๋ฅผ ISR ๋ชฉ๋ก์ ๋ชจ๋ ๊ตฌ์ฑ์์๊ฒ ๋ณด๋
leader-epoch-checkpoint ํ์ผ์ ์ฒดํฌํฌ์ธํธ๋ฅผ ๊ธฐ๋ก
Follower์์ Leader๋ก Fetch๋ง ์ํ
Offset 5 ๊น์ง ๋ณต์ ๊ฐ ์๋ฃ๋์ด ์๋ ์ํฉ์์, Producer๊ฐ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๋ฉด Leader๊ฐ offset 6 ์ ์ ๋ฉ์์ง๋ฅผ ์ถ๊ฐ
๊ฐ Follower๋ค์ Fetcher Thread๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก fetch๋ฅผ ์ํํ๊ณ , ๊ฐ์ ธ์จ ๋ฉ์์ง๋ฅผ offset 6 ์ ๋ฉ์์ง๋ฅผ Write
Follower๋ค์ Fetcher Thread๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก ๋ค์ fetch๋ฅผ ์ํํ๊ณ null ์ ๋ฐ์ Leader๋ High Water Mark ์ด๋
๊ฐ Follower๋ค์ Fetcher Thread๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก ๋ค์ fetch๋ฅผ ์ํํ๊ณ High Water Mark๋ฅผ ๋ฐ์