Problem/Motivation

Using Method #1 and saving a Article with a tags field with shs module and Redis. ConsistentCacheBase::matchKey is returning the same result for each key.

To reproduce I create more than 1 new tag and save the node, seems one term doesn't have a problem and I think shs is just priming it's own cache with a shs.module:828, shs_term_get_children() which calls taxonomy_term_load_multiple().

Then after the all the entities are the same, everything busts from there and end with an error page about entity_label() can't get bundle... nice rabbit hole to fall down:)

Proposed resolution

Maybe don't use strpos() on integers? My only wild guess here because this code is beyond me.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

joelpittet’s picture

Yeah from the screenshot this evaluates to TRUE. I think both sides need to be cast to strings. I'll give that a try and post a patch but just some rough though noting here:

php -r 'var_dump(strpos(1960, 1329) === 0);'

http://3v4l.org/fG06S

joelpittet’s picture

Status: Active » Needs review
StatusFileSize
new693 bytes

This resolved it for me and should be a tiny bit faster if they are exact matches.

gielfeldt’s picture

Thanks. Nice catch. I wonder if this is actually what caused the problem for you with ConsistentCacheLookup as well. It seems to suffer from the same issue, although the symptom was a bit different.

  • gielfeldt committed ec81abf on 7.x-2.x
    Issue #2533274, #2530334 by joelpittet, gielfeldt: Fix bug in strpos()...

  • gielfeldt committed 75996dd on 7.x-1.x
    Issue #2533274, #2530334 by joelpittet, gielfeldt: Fix bug in strpos()...
gielfeldt’s picture

I've added your fix, and I've also added the fix to the CacheConsistentLookup class. I've also added test-cases for the issue.

Please let me know if it works. And if possible, please let me know if the CacheConsistentLookup is now fixed wrt #2530334: Notice: Undefined offset: 92 in ConsistentCacheBuffer->lookup() (line 179 of cache_consistent/cache_consistent.lookup.inc).

joelpittet’s picture

Thanks @gielfeldt, not sure which one I should stick with but for now it's not the lookup. The lookup did sound better for me with this commerce + redis site but I don't know...

gielfeldt’s picture

Ok. Just let me know if the regular one works, if possible. The lookup version is probably only better on paper anyways :-)

joelpittet’s picture

Well I have one weird problem with cache loosing property info for commerce_line_item bundles but I don't think it's related to this class (yet...).

So far 24 hours of goodness.

:)

joelpittet’s picture

Ran into a bunch of these in my local logs just now:

Warning: strpos(): Empty needle in ConsistentCacheBase->matchKey() (line 180 of cache_consistent/cache_consistent.inc).

Should that be possible? And if so, then I guess we need to check $key !== ''?

gielfeldt’s picture

Darn it. It is possible, if someone calls cache_set or cache_clear_all with an "" for cid. Which I have encountered before. And by looking at the code, the only way I can see that this warning should occur, is if indeed someone calls cache_set or cache_clear_all with an "" for cid. But you never know ...

If you're on a local setup, could you perhaps check do some debugging in line 260 and 292, and check if someone is actually performing cache-operations with empty string cache ids?

gielfeldt’s picture

Wait a minute ... cache_clear_all() accepts an empty $cid, of course. I think the check you propose might suffice as a fix. I'll get back to you.

gielfeldt’s picture

Looks like I need some extra logic for handling cache flushes...

joelpittet’s picture

Yay, extra logics!

gielfeldt’s picture

Holy mother of God, I may have to refactor quite a bit :-(

gielfeldt’s picture

I've fixed some bugs regarding flushes and minimum cache lifetime. I've also added more tests, that should cover the issues we've seen. Could you try out the latest dev-version?

After the refactoring the buffering logic became a bit more complex, making me consider I might phase out the regular class, so that it's only the lookup version that remains.

Also, the syntax of the configuration has changed:

$conf['cache_default_class'] = 'ConsistentCache';
$conf['consistent_cache_default_buffer_mechanism'] = 'ConsistentCacheBufferAdvanced';

If I remove the regular buffering class, the default buffer class will become "ConsistentCacheBufferAdvanced", so that line 2 above will be unnecessary.

If it works, I may also refactor some of the naming ("cache consistent" vs "consistent cache") before a next release candidate.

gielfeldt’s picture

Status: Needs review » Postponed (maintainer needs more info)
joelpittet’s picture

Why was the configuration needing to change?

I'll see if I can give this a try today but a bit leary to put large changes in production with commerce without having at least another person testing(besides you who wrote the fixes).

joelpittet’s picture

you may want to put php = 5.3 in the info file because I noticed you were using __DIR__ magic constant and it was introduced then.

gielfeldt’s picture

Thx for the heads up. I might change it to dirname(__FILE__) instead though.

The configuration didn't need to change as such, but I generalised the buffer classes, so that I could easier maintain them. In any case, I will most likely remove the simple class, so the configuration (when I'm done) will just be:

$conf['cache_default_class'] = 'ConsistentCache';

Also, currently in the dev-version, using:

$conf['cache_default_class'] = 'ConsistentCacheLookup';

is equivalent to:

$conf['cache_default_class'] = 'ConsistentCache';
$conf['consistent_cache_default_buffer_mechanism'] = 'ConsistentCacheBufferAdvanced';

But that will change.

joelpittet’s picture

Well, just updating to latest -dev this seemed to fix an issue where some menu items went missing... correlation maybe but that was nice to see:)

Should $conf['cache_default_class'] = 'ConsistentCache'; still work with the latest -dev if I don't want to use the lookup?

gielfeldt’s picture

Yes, that should still work.

gielfeldt’s picture

wrt menus, was the problem you had somewhat similar to this one? #2469925: Child menu items disappear

joelpittet’s picture

Yes I think that is the problem it sounds very very similar.

gielfeldt’s picture

I've merged my refactoring into 7.x-2.x-dev.

I've removed the Lookup class. You now only need to:

<?php
$conf['cache_default_class'] = 'ConsistentCache';
?>
joelpittet’s picture

Thanks, I'll upgrade.

joelpittet’s picture

Status: Postponed (maintainer needs more info) » Needs work

Noticed this in my logs regarding a elysia cron job. It may not be a problem here but should probably be checked into.

Notice: Undefined offset: 76 in ConsistentCacheBuffer->lookup() (line 280 of cache_consistent/cache_consistent.buffer.inc).

gielfeldt’s picture

I have a hard time reproducing this. But I have a theory. Could you try to remove or comment line 327 in cache_consistent.buffer.inc ? And see if that eliminates the warning.

gielfeldt’s picture

Nevermind. I found the bug.

gielfeldt’s picture

There. Could you try the latest dev version? Again :-)

joelpittet’s picture

Thanks, I'll give it a try.

Should I worry about this change?

   public function prune() {
-    foreach ($this->lookupTable as $cid => &$operations) {
-      if ($operations) {
-        $only = array_pop($operations);
-        foreach ($operations as $idx => $operation) {
-          unset($this->buffer[$idx]);
-        }
-        $operations = array($only => $only);
-      }
-    }
+    // @todo Make this work.
   }
gielfeldt’s picture

No, it was just a performance optimisation that wasn't working as well as it should. So I removed it. I've since then re-implemented it so that it works better, but I haven't pushed it to the dev-branch yet.

joelpittet’s picture

So it seems to be throwing notices, but to the end user on admin_menu cache clears it's showing like an exception error.

Notice: Undefined offset: 42 in ConsistentCacheBuffer->lookup() (line 280 of cache_consistent/cache_consistent.buffer.inc)

I noticed no new changes have been made since yesterday when I applied that so I assume this is from the new changes.

Edit: before patch applied.

joelpittet’s picture

Whoops, hold up didn't push my changes live yet. Just did that... ignore #33

gielfeldt’s picture

No news is good news, I hope? Since last time, I've fixed a couple of edge-cases, which you probably haven't run into. I'm gonna merge them into 2.x-dev tonight.

joelpittet’s picture

No news is good news:) squeaky logs get the grease.

gielfeldt’s picture

Dev-version is now up-to-date with the latest fixes. Hopefully we're nearing/at the end now.

gielfeldt’s picture

Status: Needs work » Postponed (maintainer needs more info)
joelpittet’s picture

Do you need more info from me? How are you using "Postponed (maintainer needs more info)"?

gielfeldt’s picture

Sorry, I missed this. I was just wondering if we could call this one closed.

joelpittet’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Yes

joelpittet’s picture

Status: Closed (fixed) » Fixed

Whoops

Status: Fixed » Closed (fixed)

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