Repopulating the Newsfeed Cache after a Server Restart

In SharePoint 2013, the Newsfeed relies on data cached in the distributed cache service which behind the scenes is using the appfabric cluster service. Newsfeed data is lost when you restart a server in your farm running this service without doing a graceful shutdown (http://technet.microsoft.com/en-us/library/jj219613.aspx#graceful).

Stop-SPDistributedCacheServiceInstance -Graceful
Remove-SPDistributedCacheServiceInstance

Sometimes you have to restart all servers in the farm and then your newsfeed will be empty.  There is a timer job that runs every 5 minutes called “Feed Cache Repopulation Job” which according to this website http://technet.microsoft.com/en-us/library/jj219560.aspx is supposed to autopopulate the newsfeed cache from the content stored in SharePoint.  Our SharePoint 2013 farm is on the March 2013 PU and this job did not seem to be repopulating the cache.

The article seemed to imply you could run some powershell scripts as well to accomplish the same thing.  I tried these:

Update-SPRepopulateMicroblogLMTCache
Update-SPRepopulateMicroblogFeedCache

The parameter for the first one was easy, just pass in your UPA proxy.  The second one also needed this proxy but it could also include an account name or a site url (http://technet.microsoft.com/en-us/library/jj219749.aspx).  The wording states that when using the account name use the “user account name for the user profile service application”.  I took this to mean the UPA service account.  I tried that and even after waiting several hours, there still wasn’t any repopulation.  So I tried the site url option passing in the mysite host url.  Still nothing.

I finally figured out after using reflector on the source code that the account name it was expecting was an account of a user to repopulate THAT user’s information.  I updated my script to the code below to run the Update-SPRepopulateMicroblogFeedCache for EACH user in the UPA and my newfeed cache started coming back to life!

$proxy  = Get-SPServiceApplicationProxy | ? {$_.Name -eq "MySite User Profile Service"}
Update-SPRepopulateMicroblogLMTCache -ProfileServiceApplicationProxy $proxy

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")

$url = "https://mysite.company.com"
$contextWeb = New-Object Microsoft.SharePoint.SPSite($url);
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($contextWeb);

$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);

$Profiles = $UserProfileManager.GetEnumerator();

foreach ($oUser in $Profiles ) {
	if ($oUser.item("SPS-PersonalSiteCapabilities").Value -eq 14 ){
		$personalurl = $url + $oUser.item("personalspace").Value
		Write-Host $oUser.item("AccountName").Value
		Update-SPRepopulateMicroblogFeedCache -ProfileServiceApplicationProxy $proxy -accountname $oUser.item("AccountName").Value 
		#-siteurl $personalurl
	}
}

$contextWeb.Dispose()

The first time through I got a couple of errors so I added the if statement to check for the personalsitecapabilities being equal to 14.  After that I got less errors but there still were a few.  That’s when I tried going the site url route.  I was thinking if I send in the url of a user’s personal site, that it might work better.  I didn’t get any errors but it also didn’t repopulate the newsfeed for the users.  Oh well…

I now believe that the siteurl parameter is to repopulate the newsfeed cache for any sites that have the newsfeed on the homepage like the new SP 2013 team site template.  I know our environment doesn’t have any of these so I skipped this part.  I was thinking at some point I will need to figure this out though.  Hopefully it won’t involve looping through all sites in my farm but my gut says it will.  If someone else has figured out a good solution, please post the powershell code in the comments.  Thanks.

Update 3/29/2014:  

This issue has been resolved in Service Pack 1 (SP1).

18 Replies to “Repopulating the Newsfeed Cache after a Server Restart”

  1. I still have my case open with MS. They have not provided an automatic fix for this yet. Your best bet is to run the powershell script I provided above whenever you restart the server(s) running the distributed cache.

  2. Hello Steve,

    would you please be so Kind to post the link to the News from Microsoft containing the actual info about Fixing the issue. I looked through the description of SP1 but did not find anything about a fix for this issue there.
    This would be very Kind of you.

    Thank you,
    Andy

  3. Andy, that’s the weird thing. They couldn’t find any type of bug report internally regarding this issue. The engineer I talked to actually had it working using the August 2013 CU whereas I was on the March 2013 PU. Other MS engineers were able to repro the issue using RTM and the March 2013 PU. So it seems like the fix was slid in under the covers somewhere and wasn’t properly documented.

  4. Thank you for the starter piece, I took it and expanded a bit.

    # This script is for the purpose of repopulating the Newsfeed following a server crash
    
    # MySite Host URL
    $mySiteUrl = "***Fill_in_the_Blank***"
    # Name of User Profile Service Proxy used by the MySite Host
    $proxyName = "User Profile Service Application Proxy"
    
    # ***********************************************
    #   Processes are below, EDIT ONLY IF NECESSARY
    # ***********************************************
    
    # Validate the current user is the Farm Account
    $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
    $farmAcct = (Get-SPFarm).DefaultServiceAccount.Name
    IF ($currentUser -ne $farmAcct){
        Write-Host "$($currentUser): You are not the farm account..."
        Write-Error "This script must be executed as the Farm account!" -ErrorAction Stop
    }
    
    # Validate the current user is a local admin and the console has been launched as an administrator
    $currentPrincipal = new-object Security.Principal.WindowsPrincipal ([System.Security.Principal.WindowsIdentity]::GetCurrent())
    $isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    if ($isAdmin -ne $true){
        Write-Host "$($currentUser): You are not using elevated permissions..."
        Write-Error “This script must be executed with elevated permissions!” -ErrorAction Stop
    }
    # Load SharePoint Snap-In
    $snapin = (Get-PSSnapin -name Microsoft.SharePoint.PowerShell -EA SilentlyContinue)
    IF ($snapin -ne $null){
        write-host -ForegroundColor Green "SharePoint Snapin is loaded... No Action taken`n"
    }
    ELSE {
        write-host -f Yellow "SharePoint Snapin not found... Loading now"
        Add-PSSnapin Microsoft.SharePoint.PowerShell
        write-host -ForegroundColor Green "SharePoint Snapin is now loaded`n"
    } 
    
    # Allocate process memory
    Start-SPAssignment -Global
    
    # Get the UPS Proxy for use with the cache commands
    $proxy  = Get-SPServiceApplicationProxy | ? {$_.Name -eq $proxyName}
    
    # Initialize the distributed cache repopulation
    Update-SPRepopulateMicroblogLMTCache -ProfileServiceApplicationProxy $proxy
    
    # Obtain Service Context based on URL
    $mySiteHost = Get-SPSite $mySiteUrl
    $context = Get-SPServiceContext $mySiteHost
    
    # Access the user profiles through the context
    $UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
    $profiles = $UserProfileManager.GetEnumerator();
    
    # Perform the cache repopulation for each user
    foreach ($profile in $profiles ) {
        if ($profile.item("SPS-PersonalSiteCapabilities").Value -eq 14 ){
            $AccountName = $profile.item("AccountName").Value
            Write-Host "Updating the Newsfeed for $AccountName"
            Update-SPRepopulateMicroblogFeedCache -ProfileServiceApplicationProxy $proxy -AccountName $AccountName
        }
    }
    
    # Dispose of process memory
    Stop-SPAssignment -Global
    • Check the Proxy name variable and ensure it matches your environment.
      Other than that you can try altering line 57 from:
      if ($profile.item(“SPS-PersonalSiteCapabilities”).Value -eq 14 ) {
      to:
      if ($profile.item(“PersonalSpace”).Value -like “/personal/*” ) {

  5. Also running SP1 with Sept 2014 CU, and restarting every night to backup the farm virtual machines. Newsfeed still not repopulated automatically. Anyone making progress with this?

    • That is weird, because since SP1 this has worked correctly for me. I’ve had to restart my servers running my distributed cache service a few times since then and all of my feeds eventually show up again. Now, not everything will show up back up. Some activities such as tag activities and document activities are ONLY written to the cache, and since it’s been wiped, they will not repopulate. See this article: http://technet.microsoft.com/en-us/library/jj219700(v=office.15).aspx

  6. Hi Steve,

    may be you can give a hint to look for:

    Some probs with User profile sync.
    I can access “Manage User Properties” through the individual tenant admin site. Accessing through central administration a error is thrown.
    Application error when access /_layouts/15/MgrProperty.aspx, Error=UserProfileApplicationNotAvailableException_Logging :: UserProfileApplication.PartitionProperties does not have paritionID0c37852b-34d0-418e-91c6-2ac25af4be5b at Microsoft.Office.Server.Administration.UserProfileApplication.PartitionPropertiesCache.GetPartitionProperties(Guid partitionID)

    Due some problem during installation/ setup I had some ou twice. Due lack of possibilties I delete then manually from the database. Can this be problem? And if how to “clean it up”.

    Thanks
    Bernhard

  7. Hi Steve,
    Thanks for this great blog-post. We also do have SP1 installed and have troubles with lost feeds.
    You told that the script above only repopulates the user feeds and not site feeds. Do you have an example for repopulating also the site feeds?
    Could not find a script for this… Thanks in advance.
    Regards,
    Simon

  8. Hi Steve,

    I am facing the issue in Newsfeed , I have activated Feature required for the newsfeed. however though i am still getting error “SharePoint returned the following error: A required SharePoint feature is not enabled. Internal type name: Microsoft.Office.Server.Microfeed.MicrofeedException. Internal error code: 46. Contact your system administrator for help in resolving this problem.” Eventvwr log details: The Execute method of job definition Microsoft.Office.Server.UserProfiles.LMTRepopulationJob (ID 09695e4b-e5aa-409f-9891-79548e454c67) threw an exception. More information is included below.

    Unexpected exception in FeedCacheService.BulkLMTUpdate: Region not found..

    My SharePoint server is updated with September CU . I have tried various option including your script to repopulate user feeds.
    Other Options are detaching distrubuted services and adding it back.

    Our server –> SharePoint + SQL + PHA .

    I have been struggling on this for about 2 weeks time. Your help would be saving me. Thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*