What happens to session information about an xDB Contact if MongoDB is unavailable when the session end event fires and Sitecore attempts to flush it to the collections database?
That is a great question, and one a client asked me earlier this week. Since we always recommend highly-available solutions to our clients, including MongoDB replica sets, it’s an edge case we haven’t encountered and honestly, one I hadn’t considered.
After about five minutes of unfruitful googling, I figured I’d reach out to the Queen of Sitecore Documentation herself, Martina Welander (who recently wrote a FANTASTIC article on session state, by the way!).
Naturally, she delivered! By reaching out to the product team, she received this response from Akinori Taira:
In the event that the collections database is unavailable, there is a special ‘Submit Queue’ mechanism that flushes captured data to the local hard drive (the ‘Data\Submit Queue’ folder by default). When the collections database comes back online, a background worker process submits the data from the ‘Submit Queue’ on disk.
As with most everything else in Sitecore, this mechanism is controlled by entries, scattered across a few config files.
In Sitecore 8.0 (and its updates) there is a setting called Analytics.FailOnDatabaseErrors in Sitecore.Analytics.config:
<!-- ANALYTICS FAIL ON DATABASE ERRORS Note: This is a diagnostics setting that should not be enabled on a live system. If set to true, web pages crash and show exception details in case an operation cannot access the database. If set to false, exceptions are suppressed and logged, and visit data is queued until the database is back up. See <submitQueue> section. Default: false --> <setting name="Analytics.FailOnDatabaseErrors" value="false" />
However, in Sitecore 8.1+, the property Analytics.UseSubmitQueue is used from Sitecore.Analytics.Tracking.config:
<!-- ANALYTICS USE SUBMIT QUEUE Specifies if the submit queue should be used when the contact or session submit operations cannot access the database. If set to true, the contact or session is queued until the database is backed up (see the <submitQueue> section). Default: true --> <setting name="Analytics.UseSubmitQueue" value="true" />
Finally, from the Sitecore.Analytics.Tracking.config and Sitecore.Analytics.Tracking.Database.config, you get the following:
<submitQueue> <queue type="Sitecore.Analytics.Data.DataAccess.SubmitQueue.FileSubmitQueue, Sitecore.Analytics" singleInstance="true" /> <backgroundService type="Sitecore.Analytics.SubmitQueueService, Sitecore.Analytics"> <!-- Service wakeup interval in seconds. --> <Interval>60</Interval> </backgroundService> </submitQueue>
I have not tested this failover scenario myself yet, so your mileage may vary, but feel free to comment if you have and how well it works.
Happy Sitecore trails, my friends!