August 11, 2016

Sitecore Config Transforms - Use Replace instead of Remove

By: Craig Taylor
August 11, 2016

Sitecore Config Transforms - Use Replace instead of Remove

I love config transforms.  I love being able to have a single file that can be transformed for any number of my build destinations.  It's much, much better than trying to maintain separate config files for each destination.  Many times, I have config files that should *only* exist on either a CM or CD server.  Originally, I used the "Remove" method to remove the entire contents of a config file like so:


While it doesn't technically break anything, it leads to errors in the logs on Sitecore startup that complain about "Reader is in incorrect state":


The fix is actually really easy.  Instead of removing the entire "sitecore" node in the file, just replace it:

Now Sitecore be all happy.


June 28, 2016

Using Config Transforms to Manage Sitecore Indexes

By: Craig Taylor
June 28, 2016

Using Config Transforms to Manage Sitecore Indexes

In my previous post, I talked about setting up your Solr indexes to use the "SwitchOnRebuildSolrSearchIndex" index type to avoid index downtime.  In that post, I mentioned that I was using Config Transforms in order to manage the configuration settings across my different environments.  Here's a quick example of how to set up an index for the different environments:

The 'Default' or 'Standard' Index configuration that I have in my solution:

What's going on?:

  • I have separate configurations for "Web" vs "Master" databases. This configuration is for the "Web index. 
  •  I'm using the 'onPublishEndAsync' indexing strategy since this is my "Web" database.  This tells Solt to update the index when a publish is complete.

I then "Add Transform" in Visual Studio to create the specific versions for the other environments.

Note: In order to add the tranformations, you have to have separate solution configurations configured for each environment.

I'll skip all my local/dev/qa/stage environments and just show what I've got for production, but note that each environment can and usually *should* have its own transformation.

Production CM server configuration:

What's going on?:

  • I tell the transform to look for all indexes in the parent config file and change the index type to "SwitchOnRebuildSolrSearchIndex."  I like to keep only one index per configuration file, but if you had multiple indexes defined, this will change all of them.
  • I'm inserting the "rebuildcore" parameter into the index configuration.  This is required so that Sitecore knows which Solr core to swap to after the rebuild is complete.  It's also very important that it goes in in the third position as Sitecore expects it there.

When the transformation is applied, it looks like this:

For the Production CD server, I have the following transform:

What's going on?:

  • As with the CM server, I'm changing the index type to "SwitchOnRebuildSolrSearchIndex", but as you will see with the next point, it doesn't really matter.
  • We are setting the index strategy to "manual."  Our Solr indexes are centrally located on another server and we want the indexing to only happen once.  The rebuilding of the indexes are controlled by the actions of the CM server.
Setting up different configurations based on environment is easily accomplished using config transforms.  It keeps your configuration files clean and easy to manage.


March 26, 2016

Solr in Production for Sitecore - SwitchOnRebuildSolrSearchIndex

By: Craig Taylor
March 26, 2016

Solr in Production for Sitecore - SwitchOnRebuildSolrSearchIndex

The configuration for running Solr in your local dev environment is likely going to be different than running it in the production environment.  Oftentimes, your local indexes will be configured as a type of "Sitecore.ContentSearch.SolrProvider.SolrSearchIndex" while using the "syncMaster" indexing strategy.  This strategy rebuilds the index after data changes are saved in the master database.  It works well locally if you want to avoid having to publish to the Web database to see your indexes update, but this doesn't work in a production environment where your Content Delivery (CD) servers don't have access to the master database.  Not to mention, you don't want to be indexing content that hasn't been published yet.

In a production environment, it is much more common to use the "SwitchOnRebuildSolrSearchIndex" index type while using the "onPublishEndAsync" indexing strategy.  This type keeps your indexes up and running even when they are rebuilding.  This is accomplished by building to a secondary index and when the rebuild is complete, Sitecore uses that index as the primary index.  The rebuild is triggered when items are published to the 'Web' database.

Note: I should also note here that the CD servers should actually have their indexing strategies set to "manual" due to the Content Management (CM) server controlling when the central Solr indexes are being rebuilt .  More on this below.

Since I have different strategies defined for the different environments and have different build configurations in my Visual Studio solution, I utilized config transforms to allow the correct type and strategy to be used in the different environments.  I'll detail these transforms in a future blog post.

For this example, my local development instance has a custom index used for indexing products defined as follows:

          <index id="product_search_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="core">$(id)</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
            <configuration ref="contentSearch/indexConfigurations/productSearchIndexConfiguration" />
            <strategies hint="list:AddStrategy">
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/syncMaster" />
            </strategies>
            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
              <policies hint="list:AddCommitPolicy">
                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>web</Database>
                <Root>/sitecore/Content/Products</Root>
              </crawler>
            </locations>
          </index>

My local dev instance is a CM/CD combined instance and as you can see in my config, it uses the "Sitecore.ContentSearch.SolrProvider.SolrSearchIndex" type, with the "syncMaster" strategy on the "master" database.  I can now update items and have them immediately available in my index without having to go through the trouble of publishing.

When deploying to a dev, stage or prod CM server, I want to ensure that my products index is always available and only contains data that has been published.  We can accomplish this with the "SwitchOnRebuildSolrSearchIndex" index type and the "onPublishEndAsync" indexing strategy.  I have the following defined for a dedicated CM server:

          <index id="product_search_index" type="Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSorlSearchIndex, Sitecore.ContentSearch">
            <param desc="name">$(id)</param>
            <param desc="core">$(id)</param>
            <param desc="rebuildcore">$(id)_sec</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
            <configuration ref="contentSearch/indexConfigurations/productSearchIndexConfiguration" />
            <strategies hint="list:AddStrategy">
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
            </strategies>
            <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
              <policies hint="list:AddCommitPolicy">
                <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
              </policies>
            </commitPolicyExecutor>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>web</Database>
                <Root>/sitecore/Content/Products</Root>
              </crawler>
            </locations>
          </index>

Note: These two index configurations are shown to illustrate the process for both switching and utilizing the onPublishEndAsync strategy.  In an actual production environment, you should separate your indexes so that you have one for the master database and one for the web database.

The changes of note here are:
  1. The index type was changed to "Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSorlSearchIndex"
  2. We added a new parameter named "rebuildcore".  This tells Sitecore the name of the secondary core to utilize while building.  Note that you need to have an additional core created to facilitate this.
  3. The strategy has been changed to "onPublishEndAsync"
  4. The "Database" we are indexing is the "Web" database.
This is a configuration for a CM server.  In order to keep the CD servers from kicking off a rebuild of the indexes, you should set their index strategy type to "contentSearch/indexConfigurations/indexUpdateStrategies/manual".

Now, each time you publish an item, the index will be automatically updated and you don't have to worry about the rebuild time taking it offline as Sitecore will be using the secondary core you defined.

Additional Reading