See http://drupal.org/node/837200#comment-3617440

bibo reports that on a site with attachments that are lacking helper applications for SBP Attachments, such as jpg and zip files, the watchdog logs are constantly full of "Content was skipped", and my search index is never at 100%.

Comments

bibo’s picture

Thanks for making a new case out of this. That should have been my job :)

I'll do some tests and post more specs when I have time to debug this. For now, it seems like the indexing process goess into some kind of loop, doing all the same files every cron run (up till the maximum of items per cron run).

Eventhough new content is not added, each cron run now last minutes, after I upped the items per cron run to 500.

bibo’s picture

Issue tags: +Search Files

I researched this further and did a clean Drupal install. The problem is easily reproduceable.

1. Install clean D6.

2. Create a filefield called "files".

3. Download and enable search_by_page and search_files

4. Autodetect file helpers (I had all helpers that search_files supports installed and enabled)

5. Create a node with the files-field, and upload several filesincluding:
* some.txt
* some.doc
* some.jpg
* some.zip

6. Run cron.

7. Visit admin/settings/search and admin/reports/dblog. Notice:
* Search index doesnt get to 100% no matter how many times you run cron
* Watchdog-log is full of "Content was skipped - PID (xxx)".

8. The search works for some.txt and some.doc, as it should. However when there are too many non-indexable items and the itemlimit per cron run is smaller, even the normal files never get to be indexed.

Repeating 6. and 7. will result in the the same thing happing again and again. The same files generate each message, just incrementing the PID. I'm currently at PID 2082295. Yeah, over 2 million, thanks to my often run cron - despite the site having less than 1000 attachments!

It seems the underlying problem causing the loop is because of this logic.

search_by_page.module, L516:

    // Get page title from module and optional content
    $info = module_invoke($item->from_module, 'sbp_details', $item->modid, $item->environment);

    if (!$info) {
      // Module indicated not to index this page after all
      watchdog('search_by_page', 'Content was skipped - PID (%pid), path (%path)',
        array(
          '%pid' => $item->pid,
          '%path' => $item->page_path),
        WATCHDOG_NOTICE);

      _search_by_page_remove_path($item->pid);
      continue;
    }

.. which means "empty" index items will be cleared with:

/**
 * Internal function: removes a path item from the paths and search database.
 *
 * @param $pid
 *   ID of the path to remove.
 */
function _search_by_page_remove_path($pid) {
  db_query('DELETE FROM {sbp_path} WHERE pid=%d', $pid);
  _search_by_page_remove_searchinfo($pid);
}

/**
 * Internal function: removes a path item from the search database.
 *
 * @param $pid
 *   ID of the path to remove.
 */
function _search_by_page_remove_searchinfo($pid) {
  db_query("DELETE FROM {search_dataset} WHERE type='search_by_page' AND sid=%d", $pid);
  db_query("DELETE FROM {search_index} WHERE type='search_by_page' AND sid=%d", $pid);
  db_query("DELETE FROM {search_node_links} WHERE type='search_by_page' AND sid=%d", $pid);

}

So, if the submodule returns nothing, the index information will be removed. Next time we try to run cron, the process notices the missing indexes, and tries to recreate it - and fails again. The loop never ends. And if there are more non-indexable filetypes than the "index search items per cron run", the search index (probably) just never gets all the files indexed.

A simple fix which would work in this case is to just return something to $info, and we can avoid the problem. The something should of course be something relevant, such as the filename of a file and, that has unindexable content. Or the title of the node to which it belongs. Those strings should be search-index worthy (but currently afaik dont make it to the index)?

Another way I guess would be to just not delete the path with
_search_by_page_remove_path($item->pid);

.. but I don't know these modules well enough to be sure this wouldn't break anything. So I'll try to fix this the simple way first.

bibo’s picture

Priority: Normal » Critical

Hmm, after looking at the sbp_path table, I noticed the non-supported filetypes always have "0" in the "last_index_time".

One row for example:

pid last_index_time page_path from_module modid language environment role
2023935 0 sites/default/files/some.zip sbp_attach 656 fi 1 5

I looked further, and it seems "last_index_time"=0 is true for all non-indexable files, but never indexable files! There was one exception: a file named test.txt. That makes sense though, because this particular text file was empty, so there was nothing to index. Even so, it had been indexed, but I assume the last_index_time was set to 0 anyway.

This means that the looping problem is not only about non-handled filetypes, but empty files aswell. And I guess any other failed index-operation may lead to the same problem. I think it's enough reason to mark this as critical.

bibo’s picture

StatusFileSize
new821 bytes

Here is a patch for the "simple" solution. It just changes 2 lines in sbp_attach.module like this:

  return NULL;

to

  // We can still return at least the filename.
  $content = basename($fname);

I tested it, and it seems to work great. Cron runs finally index the content and no more "Content was skipped"-messages. Hooray.

.. However, I noticed a new problem: after all the normal indexing (for non-existent files) was done, there were still 9 unindexed items, and now the complaint was:
Content not rendered () - PID (250), path (node/66), realpath (node/66), language (fi)

Each cron run now results in 12 of these messages, which are from 6 different nodes (apparently each node creates two of these messages). The nodes are of a few different nodetypes, but they have no files attached.

It seems this new problem is not really related to the issue with the files, however it fits into the topic of this issue (incomplete search index).

Anyway, the problem with no helpers for some filetypes should be fixed with this patch. I somehow feel that the looping condition still might occur under other circumstances, so maybe it needs to be reviewed.

bibo’s picture

Status: Active » Needs review

Setting to "needs review". I'm wondering why no one else seems to have encountered this problem?

bibo’s picture

Title: Search index never gets to 100% if there are no helpers for attachments » Search index never gets to 100% if there are no helpers for attachments OR if some nodes have no visible fields

More debugging, and seems like the "new" render-issue is caused by nodes that have no visible fields to render.

It just happens that all the 6 nodes have:
- bodytext disabled
- no visible cck fields

With visible I mean that some fields are set to hidden on the "Display fields"-page for the content type. I'm outputting those fields with other means (such as views blocks).

This piece of code apparently don't care about my views blocks, and sees the node content as empty:
$content = menu_execute_active_handler($path);
.. which would be totally ok, if it wouldn't lead to this endless loop.

A very easy and similar solution to the patch above, would be to simply add "some info" that is always available as $content, if there is no other content. Something like the $node->title, or such. There must be more elegant ways to fix this, but.. let's see.

bibo’s picture

I probably should have created a new case, but here goes: a patch that fixes the render errors.

As I said it simply puts node title as $content, if $content is empty and there is nothing else to render. Fixed my problem, and I FINALLY have search index at 100% without errors in my logs :D!

Again, this underlying logic that causes the loop in some cases still needs to be fixed, but these simplistics fixes worked for me.

jhodgdon’s picture

Thanks for all the research! Please do file a separate issue for your rendering problem.

I'll take a look at the patches soon. Just as a note, if you supply patches that follow Drupal coding standards, and are created from the CVS repository root, they're easier to deal with.
http://drupal.org/coding-standards
http://drupal.org/patch/create

And by the way, the reason probably most people don't see this error is probably that they are indexing fields that have file types that Search Files knows how to read, rather than fields that contain a lot of files that cannot be indexed. Nevertheless, I agree that this should be fixed.

jhodgdon’s picture

On second thought, I think these two issues are related enough that they should be handled together, so let's leave them both on this issue.

I really appreciate you tracking down the causes of these problems -- it will save me a lot of time. I'm not sure if I will implement your solutions, but I'll do something to fix them. I should have a proposed solution in the next day or two.

bibo’s picture

Status: Needs review » Needs work

Im not sure if my approach works as well as it should. It does help: my search index is finally full and I get no unnecessary notices in my logs, however the search_indexing cron is still qute slow. It averages on around 60 seconds, which is way too much for a site this size.

There is no "endless loop" anymore, however I believe search_by_page for some reason still goes through all the files/nodes during each cron run, even if they haven't changed. If I disable search_by_page (and the submodules), the search indexing lasts 1 to 4 seconds. So, 1 minutes long indexing when there is nothing new to index, doesnt sound like it's working as intended.

jhodgdon’s picture

Right. I'm not planning on using your solution exactly.... And I know about that other issue - see #738382: Better handling of decision on when to index

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new4.44 KB

Here's the fix I came up with. I'll be committing this to the 6.x development branch shortly (along with some new test cases), and then porting to Drupal 7 version as well.

bibo: I think this should fix both of your issues. If you can possibly test, that would be great! Thanks for reporting this and tracking it down.

jhodgdon’s picture

I've committed fixes for this to both Drupal 6 and 7 development branches of this project. They should be downloadable within 24 hours in the zip, or immediately via CVS. And I expect the automatic test above to fail, since it won't be able to apply the patch (I already applied it).

Anyone who can test it - I'd be most grateful!

bibo’s picture

I will your patch tomorrow. (unfortunately I don't have a chance to do it sooner.

bibo’s picture

Status: Needs review » Needs work

I tested your patch (well actually I just updated to the latest dev-version). Unfortunately it doesnt fix the problem.

My searchindex was at 100% before updating the module. After the update and running the hook once, it was "99% and 2 items missing". After a few test runs it's "99%, 18 items missing". I dont get any messages in my watchdog log though. With my previous patches it was at 100% (but running as slow).

The whole indexing operation still takes forever (40-150 seconds) even with no content changed - and the whole site slows down during the indexing. I started using elysia_cron, so I can execute invidual hooks at given time intervals (which allows me to index during the night + manually for testing).

I now understand sbp actually tries to reindex "everything" during each run. I have to wonder why and what will happen when using the module on very large sites (or often on smaller sites, like my case)?

Could there be an UI option to only index updated items, and not unchanged content? Or a timebased setting how often this is run? I should probably make a new case though, right :)? Or should I post it here: #738382: Better handling of decision on when to index?

jhodgdon’s picture

Check out my message on the other issue about how to increase your cron speed and reduce the number of items indexed.

I'll take a look at the percentage message and see if I can figure out why it is not getting to 100%... But I'm not sure why that would be, if you don't have any messages in your watchdog log. You might try clicking the button to clear your search index and starting over though.

Also, are you running any other search modules? The percentage is a composite of the core Search module and any other search modules... I have an idea actually. I'll make a display section that shows status for just Search by Page, so we can track this down.

jhodgdon’s picture

StatusFileSize
new2.87 KB

Here's a patch that adds to the Search settings page. There should be a new section at the bottom in the Search by Page section, which gives you a breakdown of what it thinks is not yet indexed. I also just committed this to the Drupal 6 DEV version, and then port to Drupal 7. Please try it out and see what it says is unindexed, so we can debug further.

Also, note that the DEV version zip downloads on the Search by Page project home page are only created every 12-24 hours, and unfortunately they are not showing the time created any more when they post them on the project page. So I'm not sure whether you got the latest version or not for your testing. This commit put the following text at the top of the search_by_page.module file:
$Id: search_by_page.module,v 1.1.2.38 2010/11/11 16:07:11 jhodgdon Exp $

jhodgdon’s picture

Priority: Critical » Normal

I don't think this is a critical error any more, since the part that was causing you to not be able to index the site has been fixed.

jhodgdon’s picture

I have also added the above fix from #17 to the Drupal 7 dev version.

bibo’s picture

Status: Needs work » Fixed

Thank you jhodgdon, and sorry for being so slow to respond! I've been overworked for a while now.
I tried the latest version, ran cron a few times times, and search index fibally reaches 100%.

Still the search indexing process seems not very optimal for my use case, since I have no need the re-indes and pages every 5 minutes (thats how often I run cron). I will continue about that in the other case. Anyway thanks again for this. Also, I'm glad to hear you've become the new Drupal documentation project lead. Please keep doing hat you do :)

Status: Fixed » Closed (fixed)
Issue tags: -Search Files

Automatically closed -- issue fixed for 2 weeks with no activity.