简体   繁体   English

Ruby on Rails查询到MySQL并不总是返回新添加的信息

[英]Ruby on Rails query to MySQL doesn't always return newly-added information

I've taken over a Red Hat Enterprise Linux 5 system running Ruby (v1.8.5) on Rails (v2.3.5) with Passenger (v2.2.9), Thinking Sphinx (v1.3.14) and MySQL (v5.0.77-log). 我已经接管了在Rails(v2.3.5),Passenger(v2.2.9),Thinking Sphinx(v1.3.14)和MySQL(v5.0.77-log)上运行Ruby(v1.8.5)和Rails(v2.3.5)的Red Hat Enterprise Linux 5系统。 。 I know they're all out of date, but that's not the problem. 我知道他们都已经过时了,但这不是问题所在。

The users of that system have noticed that data input recently doesn't show up on a query like older data does. 该系统的用户已经注意到,最近的数据输入不会像旧数据那样显示在查询中。 For instance, here's a snippet from the log when older data is looked up: 例如,这是查找较旧数据时的日志片段:

  7 Query SELECT * FROM `patients` WHERE (`patients`.`id` = 618) 7 Query SELECT count(*) AS count_all FROM `notes` WHERE (patient_id = 618) 7 Query SELECT * FROM `notes` WHERE (`notes`.`id` IN (2238,2237,2092,2088)) 7 Query SHOW FIELDS FROM `categories` 7 Query SELECT * FROM `categories` WHERE (`categories`.`id` = 3) 7 Query SELECT * FROM `users` WHERE (`users`.`id` = 2) 7 Query SELECT * FROM `categories` WHERE (`categories`.`id` = 2) 7 Query SELECT * FROM `categories` WHERE (`categories`.`id` = 1) 7 Query SELECT * FROM `users` WHERE (`users`.`id` = 6) 7 Query BEGIN 7 Query UPDATE `sessions` SET `data` = '[removed]\\n', `updated_at` = '2013-04-12 20:08:26' WHERE `id` = 1836 7 Query COMMIT 

So MySQL is returning four notes (with ids of 2238, 2237, 2092, and 2088) for patient 618. 因此,MySQL为患者618返回了四个笔记(ID为2238、2237、2092和2088)。

On the other hand, if I pick a patient added to the system last Tuesday that I know has three notes associated with him, I get this: 另一方面,如果我在上周二选择了一个添加到系统中的患者,并且该患者与他相关联的三个便笺,我将得到:

  8 Query SELECT * FROM `patients` WHERE (`patients`.`id` = 1157) 8 Query SELECT count(*) AS count_all FROM `notes` WHERE (patient_id = 1157) 8 Query BEGIN 8 Query UPDATE `sessions` SET `data` = '[removed]=\\n', `updated_at` = '2013-04-12 20:19:00' WHERE `id` = 1836 8 Query COMMIT 

The whole "SELECT * FROM notes " section is missing. 整个“ SELECT * FROM notes ”部分丢失。 I know that the notes are there because I can see them if I search for them by hand. 我知道这里有注释,因为如果我手动搜索它们,便可以看到它们。

A few extra potentially-salient points: 一些额外的潜在显着点:

  • This system hadn't been rebooted in over three years, and things like httpd and sqld weren't set up to autostart on reboot, so I'm not sure if there is something else that needs to be restarted. 该系统已超过三年未重启,并且未将诸如httpd和sqld之类的内容设置为在重启时自动启动,因此我不确定是否还有其他需要重启的东西。
  • I have no background in Ruby on Rails. 我没有Ruby on Rails的背景。 I have no idea what Thinking Sphinx is, but I do know that I was getting HTTP 500 errors before I ran the command "rake -f ~user/project/Rakefile ts:start RAILS_ENV=production". 我不知道什么是Think Sphinx,但是我确实知道在运行命令“ rake -f〜user / project / Rakefile ts:start RAILS_ENV = production”之前遇到HTTP 500错误。
  • The system had just been migrated from one virtual machine farm to another (V-to-V, in other words), but I've examined all the ways in which this might have affected the RoR installation, and have come to the conclusion that it couldn't have affected any of the files or functionality. 该系统刚刚从一个虚拟机服务器场迁移到另一个虚拟机服务器场(换句话说就是V到V),但是我研究了所有可能影响RoR安装的方式,并得出以下结论:它不会影响任何文件或功能。

Any help you could give me would be greatly appreciated! 您能给我的任何帮助将不胜感激!

It turned out to be a problem with Thinking Sphinx. 事实证明,这是Think Sphinx的问题。

TS was set up to run its reindexing service (rake ts:reindex) hourly as the user who owns the project. TS设置为以拥有项目的用户的身份每小时运行一次其重新索引服务(rake ts:reindex)。 When I was debugging the issue, I ran it as root, which changed the ownership of all the index files to root. 在调试问题时,我以root身份运行,将所有索引文件的所有权更改为root。 When the user's reindexing job ran afterwards, it returned either a 用户的重新编制索引作业随后运行时,返回了一个

Permission denied, will not index. 权限被拒绝,将不会编制索引。 Try --rotate option. 尝试--rotate选项。

error, or a 错误或

Resource temporarily unavailable, will not index. 资源暂时不可用,将不会编制索引。 Try --rotate option. 尝试--rotate选项。

error. 错误。

I ended up recreating the index files from scratch as the non-root user, and now it works again. 我最终以非root用户身份从头开始重新创建索引文件,现在它又可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM