WordPressPopularPostsでdie lock発生?

ちょっと前から、自社サーバが一時的にアクセス不能になったことがあります。調べてみると、下記エラーログを見つかりました。
エラーログ
| 1 | [Thu May 08 13:56:30 2014] [error] [client 203.114.217.181] WordPress \xe3\x83\x87\xe3\x83\xbc\xe3\x82\xbf\xe3\x83\x99\xe3\x83\xbc\xe3\x82\xb9\xe3\x82\xa8\xe3\x83\xa9\xe3\x83\xbc: Lock wait timeout exceeded; try restarting transaction for query INSERT INTO wp_popularpostsdata (postid, day, last_viewed) VALUES (1466, '2014-05-08 13:55:00', '2014-05-08 13:55:00') ON DUPLICATE KEY UPDATE last_viewed = '2014-05-08 13:55:00', pageviews = pageviews + 1; made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/sterfield/single.php'), the_content, apply_filters('the_content'), call_user_func_array, WordpressPopularPosts->wpp_update, referer: https://www.google.co.jp/ | 
| 1 2 | [Thu May 08 13:59:34 2014] [error] [client 203.114.217.181] WordPress   : Lock wait timeout exceeded; try restarting transaction for query INSERT INTO wp_popularpostsdatacache (id, day, day_no_time) VALUES (1466, '2014-05-08 13:58:14', '2014-05-08') ON DUPLICATE KEY UPDATE pageviews = pageviews + 1, day = '2014-05-08 13:58:14', day_no_time = '2014-05-08'; made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/sterfield/single.php'), get_header, locate_template, load_template, require_once('/themes/sterfield/header.php'), wp_head, do_action('wp_head'), call_user_func_array, HeadSpace2->wp_head, HeadSpace2->get_current_settings, HS_InlineTags->replace, HS_InlineTags->get_excerpt, apply_filters('the_content'), call_user_func_array, WordpressPopularPosts->wpp_update, referer: https://www.google.co.jp/ | 
wordpressのエラーメッセージは?
| 1 | \xe3\x83\x87\xe3\x83\xbc\xe3\x82\xbf\xe3\x83\x99\xe3\x83\xbc\xe3\x82\xb9\xe3\x82\xa8\xe3\x83\xa9\xe3\x83\xbc | 
はurlencodeされたもので、decodeしたら
| 1 | 「データベースエラー」 | 
になります。
| 1 | Lock wait timeout exceeded | 
は字面通り、mysqlのプロセスが、他のプロセスのロック解除を待っているですが、タイムアウトで終了しました。
「ON DUPLICATE KEY UPDATE」は何の意味?
同じキーのデータがあれば、そのデータを更新するとの意味でし。
die lockとは?
プロセス1 : テーブルAの行xを更新 → テーブルBの行yを更新(今ここ) → 終了
プロセス2 : テーブルBの行yを更新 → テーブルAの行xを更新(今ここ) → 終了
MySQL(Innodb)が更新作業を行うとき、行ロックをかかりますから、
お互いにロック解除を待っていて、ロック解除が不能の状態を指します。
WordPressPopularPostsのテーブル構造
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | mysql> desc wp_popularpostsdata; +-------------+----------+------+-----+---------------------+-------+ | Field       | Type     | Null | Key | Default             | Extra | +-------------+----------+------+-----+---------------------+-------+ | postid      | int(10)  | NO   | PRI | NULL                |       | | day         | datetime | NO   |     | 0000-00-00 00:00:00 |       | | last_viewed | datetime | NO   |     | 0000-00-00 00:00:00 |       | | pageviews   | int(10)  | YES  |     | 1                   |       | +-------------+----------+------+-----+---------------------+-------+ 4 rows in set (0.00 sec) mysql> desc wp_popularpostsdatacache; +-------------+----------+------+-----+---------------------+-------+ | Field       | Type     | Null | Key | Default             | Extra | +-------------+----------+------+-----+---------------------+-------+ | id          | int(10)  | NO   | PRI | NULL                |       | | day         | datetime | NO   |     | 0000-00-00 00:00:00 |       | | day_no_time | date     | NO   | PRI | 0000-00-00          |       | | pageviews   | int(10)  | YES  |     | 1                   |       | +-------------+----------+------+-----+---------------------+-------+ 4 rows in set (0.00 sec) | 
推測
先にwp_popularpostsdataを更新してからwp_popularpostsdatacacheを更新するプログラムがあって、
先にwp_popularpostsdatacacheを更新してからwp_popularpostsdataを更新するプログラムがあります。
両者でdie lockを形成していたかと推測します。
Author Profile

スターフィールド編集部
SHARE




