-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
(dev/core#174) Forms/Sessions - Store state via Civi::cache('session') #12362
Conversation
(Standard links)
|
56a9a1f
to
524df41
Compare
One consideration I'm mulling -- today, if one clears the On the other hand, some of them don't entirely make sense to me, and I remember some feedback (from @mlutfy?) that the system is a bit too zealous about clearing sessions. Rather than arguing theory, here's a breakdown of code which has traditionally called https://docs.google.com/spreadsheets/d/1FxuIvr2noelBvhu5eja9_ps3YUWnkmGhqijBO3gH8Po/edit?usp=sharing Which of these should now call (Update: I've included an example commit to sprinkle in some |
524df41
to
0af65c9
Compare
In the past, if one clears the `civicrm_cache` table (i.e. by calling `CRM_Core_Config::clearDBCache()` ==> `TRUNCATE TABLE civicrm_cache`), then it has the effect of destroying any active sessions/forms. Now, in allowing sessions to be stored elsewhere, we lose that side-effect. If we want strictly equivalent behavior (from a business-logic perspective), then we'd want the patch to go a bit further -- calling Civi::cache('session')->clear() at the same time that it does `clearDBCache()`. This revision adds `clear()` calls to various spots discussed here: * https://docs.google.com/spreadsheets/d/1FxuIvr2noelBvhu5eja9_ps3YUWnkmGhqijBO3gH8Po/edit?usp=sharing * civicrm#12362 (comment)
My main worry with cache-clearing, was that folks using CiviCase can often end up entering data for 1h. They might be talking with someone, take a few notes, then submit the form after 1h, and then the cache may have been cleared so their QF key is lost. I've been debugging this issue again, since it popped up again after upgrading a 4.6 client to 4.7. Seeing places like In any case, it seems like you're leaning to reduce the qty of full cache-clear, and I support that. I suspect that the code did a |
0af65c9
to
e003b97
Compare
In the past, if one clears the `civicrm_cache` table (i.e. by calling `CRM_Core_Config::clearDBCache()` ==> `TRUNCATE TABLE civicrm_cache`), then it has the effect of destroying any active sessions/forms. Now, in allowing sessions to be stored elsewhere, we lose that side-effect. If we want strictly equivalent behavior (from a business-logic perspective), then we'd want the patch to go a bit further -- calling Civi::cache('session')->clear() at the same time that it does `clearDBCache()`. This revision adds `clear()` calls to various spots discussed here: * https://docs.google.com/spreadsheets/d/1FxuIvr2noelBvhu5eja9_ps3YUWnkmGhqijBO3gH8Po/edit?usp=sharing * civicrm#12362 (comment)
Rebased. (One of the dependencies was merged.) In line with a chat with @seamuslee001 (MM/GDoc), I've added a commit to trigger session-clear in some of those spots (including the debated one
Yeah, I really agree. TBH, I'm fiddling at the edges here. The various cache clearing functions functions feel mysterious because they're all over the map (stylistically and functionally). We probably need more organizational tooling (e.g. ability to list all caches; e.g. ability to tag related caches). That would be interesting to work on sometime, but I'm gonna punt it for the moment. |
I guess this needs a rebase now |
Overview ---------------------------------------- When using forms based on CiviQuickForm (specifically `CRM_Core_Controller`), `CRM_Core_Session` stores form-state via `CRM_Core_BAO_Cache::storeSessionToCache` and `::restoreSessionFromCache`, which in turn calls `CRM_Core_BAO_Cache::setItem()` and `::getItem()`. However, using `CRM_Core_BAO_Cache::setItem()` and `::getItem()` means that all session state **must** be written to MySQL. For dev/core#174, we seek the **option** to store via Redis/Memcache. Before ---------------------------------------- * (a) Form/session state is always stored via `CRM_Core_BAO_Cache::setItem()` and `civicrm_cache` table. * (b) To ensure that old sessions are periodically purged, there is special purpose logic that accesses `civicrm_cache` (roughly `delete where group_name=Sessions and created_date < now()-ttl`). * (c) On Memcache/Redis-enabled systems, the cache server functions as an extra tier. The DB provides canonical storage for form/session state. After ---------------------------------------- * (a) Form/session state is stored via `CRM_Utils_CacheInterface`. * On a typical server, this defaults to `CRM_Utils_Cache_SqlGroup` and `civicrm_cache` table. * (b) To ensure that old sessions are periodically purged, the call to `CRM_Utils_CacheInterface::set()` specifies a TTL. * It is the responsibility of the cache driver to handle TTLs. With civicrm#12360, TTL's are supported in `ArrayCache`, `SqlGroup`, and `Redis`. * (c) On Memcache/Redis-enabled systems, the cache server provides canonical storage for form/session state.
In the past, if one clears the `civicrm_cache` table (i.e. by calling `CRM_Core_Config::clearDBCache()` ==> `TRUNCATE TABLE civicrm_cache`), then it has the effect of destroying any active sessions/forms. Now, in allowing sessions to be stored elsewhere, we lose that side-effect. If we want strictly equivalent behavior (from a business-logic perspective), then we'd want the patch to go a bit further -- calling Civi::cache('session')->clear() at the same time that it does `clearDBCache()`. This revision adds `clear()` calls to various spots discussed here: * https://docs.google.com/spreadsheets/d/1FxuIvr2noelBvhu5eja9_ps3YUWnkmGhqijBO3gH8Po/edit?usp=sharing * civicrm#12362 (comment)
e003b97
to
0a12cd4
Compare
Yup. Rebased and updated title/description to remove references to the PR-dependencies. |
@totten So I've read through this & I feel fairly comfortable about merging it. You raise that it will cause a behaviour change for Redis & Memcache users (not apc?) I feel like we know @herbdool uses Redis & @lcdservices uses Memcached & possibly Community Services do. I'm inclined to merge this & email the dev list and / or post a blog to try to find out who actually uses these & try to get them to test the rc. Annecdotally I know some have tried & given up on Memcache so I think we might be dealing with something that is not well used because it doesn't work all that well at the moment. |
@adixon @lcdservices @herbdool I'm merging this so it will be in 5.4 rc - if you have any chance to test 5.4 rc on Redis / Memcache that would be great. If the edge case @totten describes turns out to be a real thing then we will do something before 5.4 is cut to mitigate |
I've checked code and fine with it. If I get a chance to test I'll let you know here. |
Overview
When using forms based on CiviQuickForm (specifically
CRM_Core_Controller
),CRM_Core_Session
stores form-state viaCRM_Core_BAO_Cache::storeSessionToCache
and::restoreSessionFromCache
, which in turn callsCRM_Core_BAO_Cache::setItem()
and::getItem()
.However, using
CRM_Core_BAO_Cache::setItem()
and::getItem()
means that all session state must be written to MySQL. For dev/core#174, we seek the option to store via Redis/Memcache.Before
CRM_Core_BAO_Cache::setItem()
andcivicrm_cache
table.civicrm_cache
(roughlydelete where group_name=Sessions and created_date < now()-ttl
).After
CRM_Utils_CacheInterface
.CRM_Utils_Cache_SqlGroup
andcivicrm_cache
table.CRM_Utils_CacheInterface::set()
specifies a TTL.ArrayCache
,SqlGroup
, andRedis
.Comments
This should generally be a drop-in replacement (i.e. the TTLs and performance should be the same or better), but there are a couple considerations which leave me ambivalent:
The(Resolved)CRM_Utils_Cache_Memcache
andCRM_Utils_Cache_Memcached
drivers don't currently support TTL. (Addressing should be somewhat rote after fixing the other cache drivers.)If the second point is an issue, then we'd still write this patch in the same basic way, but we'd need another configuration-management patch so that sysadmins can influence the construction of the
cache.session
service. Basically, these are interesting policies forcache.session
:In an ideal world, it'd be fine to expose those configuration options. Practically speaking, we would need (a) an implementation of
CRM_Utils_Cache_Chained
and (b) a configuration mechanism. The thing I'm not sure about is how much to care about the above. Treat them as blockers on the critical path (to yield stricter drop-in compatibbility) -- or as nice-to-haves that someone can figure out in a future release?