Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemCacheStore's move to dalli as a backend broke :race_condition_ttl support #7913

Merged
merged 1 commit into from Oct 12, 2012

Conversation

mje113
Copy link
Contributor

@mje113 mje113 commented Oct 11, 2012

Sending dalli an expires_in integer that matches the Entry instance's expires_at will invalidate the cached value in Memcache at the same time the Entry is expired. This breaks the ability for Cache#fetch to determine if the :race_condition_ttl has occurred since the value will never make it back from Memcached.

@mje113
Copy link
Contributor Author

mje113 commented Oct 11, 2012

Sorry for no test coverage, but this is pretty hard to test.

@jwinter
Copy link

jwinter commented Oct 12, 2012

You can see where the additional 5.minutes used to be added to the expires_in sent to memcached here:

# Set the memcache expire a few minutes in the future to support race condition ttls on read

Without that padding, there will never be a window where both your entry is expired (via its expired_at) and memcached still has its value, so you'll never be able to serve the cached value to the other readers.

@guilleiguaran
Copy link
Member

The removal of race_condition_ttl was discussed here: http://github.com/rails/rails/pull/6903/files#r1078311

@mje113
Copy link
Contributor Author

mje113 commented Oct 12, 2012

What if someone is relying on race_condition_ttl to work correctly when upgrading to 4.0? Perhaps the removal of the functionality should be pointed out--or if it's agreed that it's up to the user to implement their own race_condition_ttl functionality, shouldn't it also be yanked from ActiveSupport::Cache#fetch?

Finally, if ActiveSupport::Cache isn't keeping its own tabs on the expires_in, and modifying that value to avoid multiple concurrent fetches on a key miss, why wrap the cached value in an Entity instance at all? The overhead with the extra marshaling and compressing (Dalli also will marshal and compress the value sent to it) just doesn't seem worth it.

@fxn
Copy link
Member

fxn commented Oct 12, 2012

race_condition_ttl is provided by the cache store, see https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb#L23, and we recently had a thread about this feature and the ability to distinguish between an unset key and a cached nil value. Those two are the ones that justify having ActiveSupport::Cache::Entry objects serialized.

The outcome of the discussion was that we want to support them, and @bdurand provided a patch that made serialized entry objects much lighter. If someone wants to store raw values in a different cache store implementation at the cost of losing those features, he can do it in a plugin.

So, we need to bring those 5 minutes back.

fxn added a commit that referenced this pull request Oct 12, 2012
MemCacheStore's move to dalli as a backend broke :race_condition_ttl support
@fxn fxn merged commit 168df24 into rails:master Oct 12, 2012
@whatbird
Copy link

FWIW: there is currently a pull request on Dalli to support :race_condition_ttl

petergoldstein/dalli#277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants