---
title: Solr/ZooKeeper 前編
tags:  #lifull #solr #zookeeper  
author: [株式会社LIFULL](https://www.docswell.com/user/LIFULL)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/V4JQPDGN7P.jpg?width=480
description: ユーザー目線で見たSolrとZooKeeperについて説明しました
published: June 02, 22
canonical: https://www.docswell.com/s/LIFULL/Z2EJ4K-2022-06-02-160256
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/V4JQPDGN7P.jpg)

Solr/ZooKeeper
前編
株式会社LIFULL
社内技術勉強会
秀野 亮


# Page. 2

![Page Image](https://bcdn.docswell.com/page/DK74YZ53J1.jpg)

ユーザー目線で見る
内部の動きまではまだ理解できてない
Solr/ZooKeeperのユーザー目線でみる


# Page. 3

![Page Image](https://bcdn.docswell.com/page/PLJ16RWZ7G.jpg)

ZooKeeper
分散システムのための調整システム
• 同期、共有、グルーピング、等を行えるようになる
GoogleのChubbyにインスパイアされたらしい
• 小規模なファイル管理、ファイルのロック機構
データ構造はファイルシステムと同じような感じ
•
/
•
•
/zookeeper
• /conﬁg
/solr_root
• /collections
• /bukken
• /live_nodes
• xx.xx.xx.xx:8983_solr
• xx.xx.xx.xx:8983_solr


# Page. 4

![Page Image](https://bcdn.docswell.com/page/8GJWW166J2.jpg)

ZooKeeper
アクセス手段
•
API (Java)
•
•
•
Web API (AdminServer)
•
•
•
SolrJはZooKeeperからノードの状態を把握しつつリクエストしてる
SolrJはJava製のSolrクライアント
8080ポートでアクセス
統計情報
zkCli.sh
•
•
ZooKeeper付属クライアント
REPL環境を提供


# Page. 5

![Page Image](https://bcdn.docswell.com/page/W4EZ5PYRJ3.jpg)

ZooKeeper / AdminServer
http://localhost:8080/commands
configuration
connection_stat_reset
connections
dirs
dump
environment
get_trace_mask
hash
initial_configuration
is_read_only
last_snapshot
leader
monitor
observer_connection_stat_reset
observers
ruok
server_stats
set_trace_mask
stat_reset
stats
system_properties
voting_view
watch_summary
watches
watches_by_path
zabstate


# Page. 6

![Page Image](https://bcdn.docswell.com/page/KY769MD17V.jpg)

ZooKeeper / AdminServer
http://localhost:8080/commands/connections


# Page. 7

![Page Image](https://bcdn.docswell.com/page/5G75NZ3LJ4.jpg)

ZooKeeper / zkCli.sh
addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
addauth scheme auth
close
conﬁg [-c] [-w] [-s]
connect host:port
create [-s] [-e] [-c] [-t ttl] path [data] [acl]
delete [-v version] path
deleteall path [-b batch size]
delquota [-n|-b] path
get [-s] [-w] path
getAcl [-s] path
getAllChildrenNumber path
getEphemerals path
history
listquota path
ls [-s] [-w] [-R] path
printwatches on|off
quit
reconﬁg [-s] [-v version] [[-ﬁle path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
redo cmdno
removewatches path [-c|-d|-a] [-l]
set [-s] [-v version] path data
setAcl [-s] [-v version] [-R] path acl
setquota -n|-b val path
stat [-w] path
sync path
version


# Page. 8

![Page Image](https://bcdn.docswell.com/page/V9J25RZ3JR.jpg)

ZooKeeper / zkCli.sh
$ ./zkCli.sh
[zk: localhost:2181(CONNECTED) 9] ls /collections/bukken
[counter, leader_elect, leaders, state.json, terms]
[zk: localhost:2181(CONNECTED) 10] get /collections/bukken/state.json
{&quot;bukken&quot;:{
&quot;pullReplicas&quot;:&quot;0&quot;,
&quot;replicationFactor&quot;:&quot;0&quot;,
&quot;router&quot;:{
&quot;ﬁeld&quot;:&quot;bykey&quot;,
&quot;name&quot;:&quot;compositeId&quot;},
&quot;maxShardsPerNode&quot;:&quot;1&quot;,
&quot;autoAddReplicas&quot;:&quot;false&quot;,
&quot;nrtReplicas&quot;:&quot;0&quot;,
&quot;tlogReplicas&quot;:&quot;1&quot;,
&quot;shards&quot;:{&quot;shard1&quot;:{
&quot;range&quot;:&quot;80000000-7fffffff&quot;,
&quot;state&quot;:&quot;active&quot;,
&quot;replicas&quot;:{
&quot;core_node2&quot;:{
&quot;core&quot;:&quot;bukken_shard1_replica_t1&quot;,
&quot;node_name&quot;:&quot;172.20.16.59:8983_solr&quot;,
&quot;base_url&quot;:&quot;http://172.20.16.59:8983/solr&quot;,
&quot;state&quot;:&quot;active&quot;,
&quot;type&quot;:&quot;TLOG&quot;,
&quot;force_set_state&quot;:&quot;false&quot;,
&quot;leader&quot;:&quot;true&quot;},
:


# Page. 9

![Page Image](https://bcdn.docswell.com/page/5DEYKDR87M.jpg)

ZooKeeper / Dynamic Reconﬁguration
再起動なしで設定を動的に反映できるAPI
zoo.cfg → zoo.cfg.dynamicに動的な部分を書き出す
•
•
ノードの追加/削除を動的に行える
追加ノードはあらかじめリーダーに接続している必要がある
zkCli.sh reconﬁg で設定反映できる
https://nobutaka-saito.hatenadiary.jp/entry/2018/04/08/152002


# Page. 10

![Page Image](https://bcdn.docswell.com/page/2VJNR6D9E8.jpg)

ZooKeeper / Dynamic Reconﬁguration
Solrはまだ対応していない
•
最初に指定したZooKeeperノードたちじゃないとダメ
[#SOLR-14389] Support dynamic reconﬁguration of Zookeeper ensemble - ASF JIRA


# Page. 11

![Page Image](https://bcdn.docswell.com/page/GYE9MLG3J3.jpg)

Solr
● コレクション
○
コア？
● シャーディング
○
○
シャード
シャードリーダー
● レプリカ
○
○
レプリカ
レプリカタイプ


# Page. 12

![Page Image](https://bcdn.docswell.com/page/5GE8LXVLJD.jpg)

Solr / Collections
Solrではかつてコアと呼ばれていた
•
コレクションというものはなかった
SolrCloudではコレクションと呼ぶ
•
あちこちに core という名称があって混乱しがち
わかりにくいもの
•
•
コア
•
SolrCloudでのコアがよく分からない
•
bukken_shard1_replica_p883 ←これコア？
ディレクトリ名
•
•
•
レプリカのディレクトリ名がbukken_shard1_replica_p883 ???
ノード名(Solr)
•
core_node111 ???
•
いつからいた？
•
ノード名じゃなくてコア名（レプリカ名）らしい
ノード名(ZooKeeper)
•
固定？
•
xx.xx.xx.xx:8983_solr ???


# Page. 13

![Page Image](https://bcdn.docswell.com/page/MLELL85QER.jpg)

Solr / Sharding
一般的な用語
•
•
•
負荷分散のためデータを水平分割する手法
RDBMSだと同じテーブルを持っていてレコードはノードごとに違う
Solrのシャーディングもほぼ同じ
Solrのシャーディング
•
•
•
コレクション単位でドキュメントを水平分割
各シャードでは担当のドキュメント範囲をbykeyのハッシュなどで決めてる（多分）
シャードは論理的な概念で分割設定だけ持っている感じ
シャードリーダー
•
•
物理的なサーバー（TLOGとか）のどれかがシャードのリーダーになる
シャードリーダーにドキュメントを登録する


# Page. 14

![Page Image](https://bcdn.docswell.com/page/54JMM6RKJW.jpg)

Solr / Sharding
SolrのAdminから確認するとこんな感じ
•
rangeに各シャードの担当範囲が書いてある


# Page. 15

![Page Image](https://bcdn.docswell.com/page/ZPJRVPR6E9.jpg)

Solr / Replica
レプリカとはシャードの物理的なコピー
•
•
シャードの設定にしたがって実際に作られたインデックスなどのデータ
シャードリーダーの手元にあるデータもオリジナルっぽいけどレプリカと呼ばれる


# Page. 16

![Page Image](https://bcdn.docswell.com/page/NPEXZ3RDJX.jpg)

Solr / Replica
論理的な図
shard1
shard2
shard3
replica
1-1
replica
2-1
replica
3-1
replica
1-2
replica
2-2
replica
3-2
replica
1-3
replica
2-3
replica
3-3


# Page. 17

![Page Image](https://bcdn.docswell.com/page/63EK8YRDJD.jpg)

Solr / Replica
物理的な図
shard1
shard2
shard3
TLOG1
replica
1-1
TLOG2
replica
2-1
TLOG3
PULL1
replica
1-2
PULL2
replica
2-2
PULL3
replica
2-3
replica
3-3
replica
3-1
replica
3-2
replica
1-3


# Page. 18

![Page Image](https://bcdn.docswell.com/page/4L73298PE5.jpg)

Solr / Replica
レプリカタイプは3種類
•
•
•
NRTレプリカ
TLOGレプリカ
PULLレプリカ
レプリカタイプの組合せ方で推奨されているもの（他の構成は非推奨）
•
NRTのみ
•
•
TLOGのみ
•
•
小規模、遅延なし（NRT）、復旧が遅い
シャードが多い環境、遅延あり（NRTではない）
TLOG+PULL
•
シャードが多い環境、遅延あり、検索性能を重視


