Tuesday, August 7, 2018

Sharepoint Configuration Cache Issue

Sharepoint Configuration Cache Overview:


There are many types of cache available in sharepoint environment like Blob cache, Page output cache, Object Cache, Anonymous search results cache, but in this article we are discussing about sharepoint configuration cache which is little bit different than what its mentioned earlier. 

So what is configuration cache. 

Basically all the sharepoint farm configuration details will be cached in system drive in %system drive%\\ProgramData\Microsoft\SharePoint\Config

If we open this folder we can see bunch of folders with GUID as the name, but we wont understand what its corresponds to. The main file which will be used for caching the config data is cache.ini(the statement is false, since it doesn't contain anything except 5/6 digit number). If the environment is having many Guid folder then we can search for cache.ini file

Next question, who will create this files?


There is sharepoint timer job called "Config Refresh" which will create this xml file and update the cache.ini file. So it means first point to trouble shoot the issue(if we have any) is the account which is running sharepoint timer service have enough access permission for R/W operation in that folder. Just cross verify account is having enough permission.

What is the significance of  this XML files.


These XML files points to sharepoint configuration entry which are locally stored in the server. Means whenever there is request for accessing the sharepoint config DB, it will be served from local file system in order to avoid the round trip to SQL server, in order to make response fast.

Ex: If we want to deploy the wsp in the farm using powershell script, these cache files should be in sync with sharepoint config DB else it will start throwing error(some weird errors like operation is not valid due to current state of the object)

Other type of issue is Timer job get paused, and it wont come back to active unless its hit again(start again)

Like this we will face so many issue if config cache folder is not sync. The timer job "Config Refresh" will always make attempt to make it up to date with DB, but there will be few occasions like windows updates/ patch update/ cumulative update might break this relation, after that we will start seeing weird behavior in the environment.

In order to fix this issue there are options available 

The below steps needs to be performed in all the servers in the farm, here I am providing the steps for stand alone system

1) Manually clean up the things

a)    Stop the SharePoint Timer service
.      Here we can goto services and stop the sharepoint timer service else use command       prompt to stop the service(net stop SPTimerv4), reason behind stopping timer service is to stop running "Config Refresh" job to execute else we wont be able to perform the below steps, it will give files are in use.
b)     Navigate to the directory: C:\ProgramData\Microsoft\SharePoint\Config\GUID.
c)     Delete only the XML files in the folder, after this step we should be able to see only cache.ini file in the folder
d)     Open the cache.ini with Notepad(its advisable to open it with admin privilege) and reset the number to 1. Save and close the file.
e)      Start the SharePoint Timer service either manually or through command prompt.
in couple of minutes XML files start creating in this location which indicates config refresh job started running and cache is in sync with config db

We can perform the same activity in other server if the environment is configured  for farm- This activity needs to be performed in all the servers including WFE also)

2) Use Powershell script

In Microsoft TechNet gallery we can find script for cleaning up the cache

Here

By above steps we should be make our environment in sync, but there are few odd sceanrios where accidently we deleted cache.ini files or if the XML files not starting generating again after 5/10 minutes

In that scenario we need to clean all the folder in the %system drive%\\ProgramData\Microsoft\SharePoint\Config (again before doing this we need to stop the timer service)

Then follow the below steps


a) Open Regedit(Registry editor) from start menu

b) Navigate to the below path
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14\Secure\ConfigDB
Get the GUID value from the ID attribute
c) Create folder with that GUID(copied) in the %system drive%\\ProgramData\Microsoft\SharePoint\Config folder and create new file from your favorite editor and call it as cache.ini and enter the number 1 and save, close
d) Again start the timer job and after couple of minutes xml files should  start appearing in the folder and if we open the cache.ini file the value will be 5/6 digit number.

Hopefully we should get some basic idea about what is config cache and how to clean up the things if it is not in sync and also its good  idea to clean up the things once in a month to avoid abrupt changes/scenarios