I have seen this error repeatedly, and the only combination that produces this error is when Acquia Search is being installed with CTools already enabled. I haven't been able to replicate on a clean install, but if I disable and uninstall Acquia Search (and even all Apache Solr / Acquia modules) I get the error every time without fail when I run through the installations steps. This bug is confirmed with the 7.x-1.x branch of Apache Solr / 7.x-2.x branch of Acquia Connector as well as the latest stable versions of both modules. I have also heard scattered reports of this same error from multiple customers.

I am posting here because I cannot replicate with only Apache Solr + CTools, however the root cause could actually be in the Apache Solr Search Integration module. Will change projects if it is determined that this is the case.

Comments

pwolanin’s picture

So, looks like the environemtn remains after acquia_search is uninstalled and re-installed? At the least, we should be able to work aroudn using db_merge or similar.

cpliakas’s picture

Well, once I hit this issue I can replicate on a clean install of all modules. So I uninstall the Apache Solr / Acquia modules so that all of the related schema is gone, yet I still encounter the issue. This leads me to believe that the environment is somehow getting added twice.

pwolanin’s picture

Project: Acquia Connector » Apache Solr Search
Version: 7.x-2.x-dev » 7.x-1.x-dev

I don't see how this could be happening, unless the ctools code is saving the env a second time and somehow the drupal_static_reset() doesn't work properly?

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new2.83 KB

This patch switches to db_merge and removes a bunch of duplicate or unneeded code.

cpliakas’s picture

Yeah, I am totally stumped. If other people weren't reporting this, I'd dismiss it as something wrong with my installs.

cpliakas’s picture

Priority: Major » Critical
Status: Needs review » Needs work

OK, I think I found the root cause of this. See #1784770: acquia_search_enable_acquia_solr_environment() called multiple times during cron runs and when module is installed. Short version, acquia_search_enable_acquia_solr_environment() is called (at least) twice and therefore calls apachesolr_environment_save() multiple times on the same pageload. The apachesolr_environment_save() function correctly checks whether the environment already exists so that it can perform either the insert or update, bit although it clears the static caches, the problem is that it does not perform a cache_clear_all() on the "apachesolr:environments" cid. Therefore apachesolr_load_all_environments() returns stale data and the module things the environment doesn't exist and performs another insert. Obviously the Acquia Search stuff has to get fixed, but in terms of the Apache Solr Search Integration module, I think that the cache_clear_all() on that cid will fix this issue.

cpliakas’s picture

So scratch that. The root cause is still the same, but it looks like the appropriate caches are cleared. I missed that one. Regardless, I was able to replicate and determine that calling apachesolr_environment_save() on a new environment twice on the same page will produce this error.

nick_vh’s picture

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

the root cause is that the specific cache for ctools is not cleared when the load_all_environments is loaded. This can be avoided using :
ctools_export_load_object_reset('apachesolr_environment');

I did a bunch of testing and cache_clear_all was way too hard for this one, this simple snippet fixes the complete issue.

Also, I merged pwolanins suggestions and I added a reset flag to the load function so this cache can be cleared using the api and avoid further confusions for people that load the environment, save something and load it again and they do not see the change.

And just to clarify, I was able to replicate this issue and this patch fixes it for me. The changes from pwolanin are not necessary actually, as we could now, during save, say that it should not use the cache when loading the environment. However, I do like those changes so that is why I merged them

pwolanin’s picture

Status: Needs review » Needs work

Seems like the reset should be handled at the top but just setting the static to NULL?

nick_vh’s picture

Status: Needs work » Needs review
StatusFileSize
new5.85 KB

This might be better. Added all reset logic to the top and cleaned up the function a little bit. Not tested yet, doing so now

Status: Needs review » Needs work

The last submitted patch, 1778050-10.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review

So the patch is not calling apachesolr_load_all_environments() with $reset any place?

pwolanin’s picture

#10: 1778050-10.patch queued for re-testing.

nick_vh’s picture

StatusFileSize
new5.91 KB
nick_vh’s picture

Basically its an API improvement. For example, I added it to clone now, but I can imagine more useful places?

pwolanin’s picture

Status: Needs review » Needs work

The logic is wrong also if the tables are missing - you return NULL rather than array()

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new5.2 KB

I think the logic here is better.

pwolanin’s picture

ok, I'm confused by Nick's changes and why they would make any difference to this bug. we never use the $reset flag, so ctools_export_load_object_reset() is never being called.

pwolanin’s picture

StatusFileSize
new5.58 KB

Seems like the missing piece is to clear the ctools cache in the save function too?

nick_vh’s picture

I started working on this patch since I wanted to know the root cause of the problem. it is true that the merge just overwrites the environment, but up to that moment we still did not understand why it would see the environment as $is_new while it was added just some milliseconds before.

The reason was this ctools cache, and this error only appears if you have ctools enabled. To get rid of this, I started adding a reset variable (before merging in your db_merge patch). I was using the reset with success, using the old $is_new variable.
When I merged your patch into this, this logic got removed.

Whenever someone does apachesolr_environment_save and then he loads that specific page a little later in the same page call, it could be that the page can't be found. To allow developers to avoid this problem, there is a $reset variable that allows to get a fresh load of all the environments, without ctools cache being in the way.

I would also be ok in adding this to the doxygen of that function as a caution/warning for developers. And only keep the reset in the save function.

pwolanin’s picture

Well, I'm happier to not add a $reset flag - if devs use the API functions correctly, it should never be neeeded.

pwolanin’s picture

StatusFileSize
new3.89 KB

here's such a simpler patch.

nick_vh’s picture

Status: Needs review » Reviewed & tested by the community

hurray for things that make life and code easier!

pwolanin’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

committed to 7.x

pwolanin’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new4.17 KB

Need to decide how to handle the update or insert logic - this ought to be robust enough, even if not totally optimized.

pwolanin’s picture

StatusFileSize
new4.19 KB

missed a argument for the db_query()

pwolanin’s picture

Title: PDOException thrown on Acquia Search module install when CTools is enabled » Stale cache when CTools is already enabled.
Status: Needs review » Fixed

This seems to work ok for me.

pwolanin’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev

ugh - apparently I didn't actually commit #22!

committing now.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.