LoginSignup
1

More than 5 years have passed since last update.

PGroongaがLockして困った件

Last updated at Posted at 2019-01-28

毎度、ググっても出てこない小ネタを取り扱っております。
本記事は個人的な見解であり、筆者の所属するいかなる団体も関係ございません。

1. 課題

 表題の通り

2. 環境

  • mattermost のDBをPostgresql 9.5 の PGroonga で動かしている。
  • Mattermostの投稿メッセージの全文検索で使おうと思ったが、Mattermost側の検索クエリーを修正しないと全文検索されないということが分かり全文検索としては未使用

3. 現象

Mattermostから投稿をいくらしても、プロセスが INSERTで固まってしまう。

 4338 ?        Ss     0:00 postgres: mt matmost 127.0.0.1(39890) INSERT
 4340 ?        Ss     0:00 postgres: mt matmost 127.0.0.1(39892) INSERT
  • Mattermost のログ
{"level":"error","ts":1548651915.9732091,"caller":"web/context.go:60","msg":"We couldn't save the Post","path":"/api/v4/posts","request_id":"crop436fhb8s8runp6nnuhwipo","ip_addr":"XXX.XXX.XXX.XXX","user_id":"sqwk87qhw3f4pqhdmzeyo35aay","meth
od":"POST","err_where":"SqlPostStore.Save","http_code":500,"err_details":"id=owh1se9y138hmbkayrs5ajhpoh, pq: pgroonga: failed to add a record: <12>: grn_io_lock failed"}
  • postgresql のログ
/var/log/postgresql/postgresql-9.5-main.log
2019-01-28 14:15:14 JST [2431-1] mt@matmost ERROR:  pgroonga: failed to add a record: <13>: grn_io_lock failed
2019-01-28 14:15:14 JST [2431-2] mt@matmost STATEMENT:  insert into "posts" ("id","createat","updateat","editat","deleteat","ispinned","userid","channelid","rootid","parentid","originalid","message","type","props","hashtags","filenames","fileids","hasreactions") values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18);
  • pgroongaのログ
/var/lib/postgresql/9.5/main/pgroonga.log
2019-01-28 14:15:14.064384|w|2431: [DB Locked] time out(900000): io(base/16384/pgrn.0000107) collisions(900000/5)
2019-01-28 14:15:14.064489|e|2431: grn_io_lock failed
2019-01-28 14:15:14.067479|e|2431: /usr/lib/x86_64-linux-gnu/libgroonga.so.0(grn_io_lock+0x28e) [0x7f8fbe822f5e]
2019-01-28 14:15:14.067508|e|2431: /usr/lib/x86_64-linux-gnu/libgroonga.so.0(grn_table_add+0x77e) [0x7f8fbe6baa7e]
2019-01-28 14:15:14.067519|e|2431: /usr/lib/postgresql/9.5/lib/pgroonga.so(+0xc841) [0x7f8fbf09f841]
2019-01-28 14:15:14.067530|e|2431: /usr/lib/postgresql/9.5/lib/pgroonga.so(pgroonga_insert+0x65) [0x7f8fbf0a2855]

どうも lockされているようだ。

grn_io_lock failed / Deadlock · Issue #48 · pgroonga/pgroonga
https://github.com/pgroonga/pgroonga/issues/48
でissueは立っているが、Closeされていない。

4. 対応

groonga pgroonga lock - external storage
http://d.hatena.ne.jp/kurita1/20180614/1528985277
を発見したので試してみる

base/16384/pgrn.0000107 ファイルのあるところまで行って clearlock する

# sudo apt install groonga-bin
# cd /var/lib/postgresql/9.5/main/base/16384/
# groonga pgrn
> clearlock
[[0,1548666020.969831,1.750027894973755],true]
> quit
[[0,1548666025.186053,7.43865966796875e-05],true]

5. 解決

書き込めるようになった
これで、ようやくMattermostを更新できる..。
直すまでに8時間ほどかかりました。。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1