Thursday 18 July 2013

cacheHostInfo is null

While starting  Distributed Cache service, I got this ugly message "cacheHostInfo is null"
After googling, I found different solutions but the better one was posted by rakasatria as follows:

$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
if([System.String]::IsNullOrEmpty($cacheClusterInfo.CacheHostsInfoCollection))
{
    #here's the key. we can't provision, unprovision, start, or stop a Cache Service because we still have a Cache Service that have no server attached 
    $serviceInstance.Delete()
    Add-SPDistributedCacheServiceInstance
    $cacheClusterInfo.CacheHostsInfoCollection
}

But it's not working for me.

Then I traverse the script to found the issue. For this I have done following:

$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
 Write-Host $cacheClusterInfo -ForegroundColor DarkCyan
if([System.String]::IsNullOrEmpty($cacheClusterInfo.CacheHostsInfoCollection))
if{
    #here's the key. we can't provision, unprovision, start, or stop a Cache Service because we still have a Cache Service that have no server attached 
    $serviceInstance.Delete()
    Add-SPDistributedCacheServiceInstance
    $cacheClusterInfo.CacheHostsInfoCollection
}

Here $cacheClusterInfo giving me value. and the above code will only run when this variable will be empty.

So I removed if condition and left rest as it is.
$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
 Write-Host $cacheClusterInfo -ForegroundColor DarkCyan

    $serviceInstance.Delete()
    Add-SPDistributedCacheServiceInstance
    $cacheClusterInfo.CacheHostsInfoCollection

And now it worked!!!!


9 comments :

  1. Replies
    1. This comment has been removed by the author.

      Delete
  2. Thanks, saved my time :)

    ReplyDelete
  3. Your solution worked perfectly...You saved my life too

    ReplyDelete
  4. You are a Jedi, dude! Thank's a lot!

    ReplyDelete
  5. working this issue for more than 4 days and finally solved using your tip. Thanks a zillion !!!! :)

    ReplyDelete
  6. Thank you, Thank you, Thank you...you saved my bacon!

    ReplyDelete