When creating new multi-site instances on an existing code base, the
usual approach is to clone an already existing instance (including
the database). I recently ran into an issue where I had created a new
instance with the above approach, however I was using the
module to implement Apache Solr.
A few baffling (at the time) symptoms included:
- Wrong item count on views
- Wrong item count on pagers
- Indexed content from the ‘Other Multi-site Instance’ displayed
After a few hours of crawling through issues and attempted Googling, I was completely stumped. I had no idea why this was happening. It wasn’t until a colleague asked:
How does the Search API module separate indexed content from each multi-site instance?
We knew that they were separated by a hash by reading issue queues, however we didn’t know how they were hashed.
Sure enough, we found a clue in the
search_api_solr_site_hash (default: random) A unique hash specific to the local site, created the first time it is needed. Only change this if you want to display another server's results and you know what you are doing. Old indexed items will be lost when the hash is changed and all items will have to be reindexed. Can only contain alphanumeric characters.
Which led me to find the following code:
This meant that when the multi-site’s database was cloned, the
search_api_solr_site_hash variable was cloned with it. The problem was
that when a new site is created, the hash is not recreated, the same one
was used. So now both multi-site instances shared the same index.
The fix was fairly simple, we just needed to recreate the hash. This
was implemented by a
The only thing left to do was run the command on the new multi-site instance:
What Did I Learn
- You shouldn’t assume that things are done ‘magically’, in this instance
I assumed the
search_apimodule ‘magically’ could tell the different between two sites
- RTFD -
I could have just read the modules
READMEand saved myself hours of pain instead of crawling through issues queues
- Next time, let’s try that rubber duck debugging method every one keeps talking about.