Home
%3CLINGO-SUB%20id%3D%22lingo-sub-334009%22%20slang%3D%22en-US%22%3EWhat%20really%20happens%20when%20HADR_CLUSAPI_CALL%20wait%20type%20is%20set%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-334009%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Aug%2018%2C%202017%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3EIn%26nbsp%3Ba%20customer%20scenario%20we%20saw%20a%20query%20against%20system%20views%20related%20to%20AlwaysOn%20taking%20a%20fairly%20long%20time.%20%3CBR%20%2F%3E%3CBR%20%2F%3ESELECT%26nbsp%3B*%20%3CBR%20%2F%3EFROM%26nbsp%3B%26nbsp%3B%26nbsp%3Bsys.availability_databases_cluster%26nbsp%3Badc%20%3CBR%20%2F%3EINNER%26nbsp%3BJOIN%26nbsp%3Bsys.availability_replicas%26nbsp%3Bar%20%3CBR%20%2F%3EON%26nbsp%3Badc.group_id%26nbsp%3B%3D%26nbsp%3Bar.group_id%20%3CBR%20%2F%3EWHERE%26nbsp%3B%26nbsp%3Badc.database_name%26nbsp%3B%3D%26nbsp%3B'db1'%20%3CBR%20%2F%3E%3CBR%20%2F%3EInvestigation%20showed%20that%20the%20query%20was%20predominantly%20waiting%20on%20HADR_CLUSAPI_CALL.%20As%20the%20name%20suggests%2C%20this%20is%20coming%20from%20the%20HADR%20(High-Availability-Disaster-Recovery)%20functionality%20of%20SQL%2C%20known%20as%20AlwaysOn.%20Also%20CLUSAPI_CALL%20is%20short%20(but%20not%20too%20short)%20for%20%22Cluster%20API%20calls%22.%26nbsp%3B%20In%20other%20words%2C%20whenever%20AlwaysOn%20calls%20into%20the%20WFCS%20for%20some%20work%2C%20it%20sets%20this%20wait%20type.%20You%20may%20wonder%20what%20type%20of%20%22work%22%20is%20being%20requested%2C%20i.e.%20what%20are%20these%20API%20calls%3F%20%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20is%20a%20list%20that%20an%20hour%20or%20two%20of%20source%20code%20research%20yielded%20(these%20are%20listed%20in%20no%20particular%20order)%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3ECheck%20remote%20cluster%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa371774(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20OpenCluster()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fwindows%2Fdesktop%2Fms724301(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20GetComputerNameEx()%20%3C%2FA%3E%20-not%20a%20cluster%20API%20per%20se%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa371779(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20OpenClusterNode()%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EGet%20resource%20name%20of%20virtual%20server%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368834(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterEnum()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa371780(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20OpenClusterResource()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa369016(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterResourceControl(....%20)%20%3C%2FA%3E%20using%20control%20codes%20CLUSCTL_RESOURCE_GET_DNS_NAME%20and%20CLUSCTL_RESOURCE_GET_NETWORK_NAME%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EEnumerate%20cluster%20resources%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368834(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterEnum()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368980(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterNodeEnum()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368846(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterNetInterfaceControl()%20%3C%2FA%3E%20-%20CLUSCTL_NETINTERFACE_GET_NODE%2C%20CLUSCTL_NETINTERFACE_GET_NETWORK%20%2C%20etc.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3ERead%20network%20Information%20from%20Cluster%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa371778(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20OpenClusterNetwork()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368967(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterNetworkControl()%20%3C%2FA%3E%20-%20CLUSCTL_NETWORK_GET_RO_COMMON_PROPERTIES%20%2C%20CLUSCTL_NETWORK_GET_COMMON_PROPERTIES%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa372340(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ResUtilFindDwordProperty(%20...'role'%20...)%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa372344(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ResUtilFindMultiSzProperty()%20%3C%2FA%3E%20-%26nbsp%3B%26nbsp%3BIPv4%20and%20IPv6%20Addresses%2C%26nbsp%3B%20IPv4%20and%20IPv6%20PrefixLengths%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EClosing%20handles%20on%20Cluster%20resources%20(not%20likely%20that%20any%20of%20the%20Close*%20functions%20were%20delaying%20things%2C%20but%20possible)%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367197(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECloseCluster()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367201(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CloseClusterNode()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367198(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CloseClusterGroup()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367203(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CloseClusterResource()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa369014(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterResourceCloseEnum()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368975(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterNodeCloseEnum()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368989(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterRegCloseKey()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa368832(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20ClusterCloseEnum()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367200(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CloseClusterNetwork()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367199(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CloseClusterNetInterface()%20%3C%2FA%3E%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Faa367202(v%3Dvs.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CloseClusterNotifyPort()%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EWhat%20to%20do%3F%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20encounter%20this%20issue%2C%20you%20should%20investigate%20the%20WFCS%20in%20more%20depth.%20Run%20%3CA%20href%3D%22https%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fcc732035(v%3Dws.10).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Cluster%20Validation%20%3C%2FA%3E%20(but%20do%20it%20when%20SQL%20Server%20is%20not%20online)%20%26nbsp%3Bcheck%20your%20network%20adapters%2C%20cables%2C%20DNS%20resolution%2C%20correctness%20of%20IP%20addresses%20and%20subnets%2C%20disk%20resources.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-334009%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Aug%2018%2C%202017%20In%26nbsp%3Ba%20customer%20scenario%20we%20saw%20a%20query%20against%20system%20views%20related%20to%20AlwaysOn%20taking%20a%20fairly%20long%20time.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-334009%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHigh%20Availability%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Etroubleshooting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on MSDN on Aug 18, 2017
In a customer scenario we saw a query against system views related to AlwaysOn taking a fairly long time.

SELECT *
FROM   sys.availability_databases_cluster adc
INNER JOIN sys.availability_replicas ar
ON adc.group_id = ar.group_id
WHERE  adc.database_name = 'db1'

Investigation showed that the query was predominantly waiting on HADR_CLUSAPI_CALL. As the name suggests, this is coming from the HADR (High-Availability-Disaster-Recovery) functionality of SQL, known as AlwaysOn. Also CLUSAPI_CALL is short (but not too short) for "Cluster API calls".  In other words, whenever AlwaysOn calls into the WFCS for some work, it sets this wait type. You may wonder what type of "work" is being requested, i.e. what are these API calls?

Here is a list that an hour or two of source code research yielded (these are listed in no particular order):

    1. Check remote cluster
      OpenCluster()
      GetComputerNameEx() -not a cluster API per se
      OpenClusterNode()

 

    1. Get resource name of virtual server
      ClusterEnum()
      OpenClusterResource()
      ClusterResourceControl(.... ) using control codes CLUSCTL_RESOURCE_GET_DNS_NAME and CLUSCTL_RESOURCE_GET_NETWORK_NAME

 

    1. Enumerate cluster resources
      ClusterEnum()
      ClusterNodeEnum()
      ClusterNetInterfaceControl() - CLUSCTL_NETINTERFACE_GET_NODE, CLUSCTL_NETINTERFACE_GET_NETWORK , etc.

 

    1. Read network Information from Cluster
      OpenClusterNetwork()
      ClusterNetworkControl() - CLUSCTL_NETWORK_GET_RO_COMMON_PROPERTIES , CLUSCTL_NETWORK_GET_COMMON_PROPERTIES
      ResUtilFindDwordProperty( ...'role' ...)
      ResUtilFindMultiSzProperty() -  IPv4 and IPv6 Addresses,  IPv4 and IPv6 PrefixLengths

 

    1. Closing handles on Cluster resources (not likely that any of the Close* functions were delaying things, but possible)



CloseCluster()
CloseClusterNode()
CloseClusterGroup()
CloseClusterResource()
ClusterResourceCloseEnum()
ClusterNodeCloseEnum()
ClusterRegCloseKey()
ClusterCloseEnum()
CloseClusterNetwork()
CloseClusterNetInterface()
CloseClusterNotifyPort()


What to do?

If you encounter this issue, you should investigate the WFCS in more depth. Run Cluster Validation (but do it when SQL Server is not online)  check your network adapters, cables, DNS resolution, correctness of IP addresses and subnets, disk resources.