【问题标题】:Missing cache role behavior of Windows Azure Caching 2.1 in compute emulator计算模拟器中缺少 Windows Azure 缓存 2.1 的缓存角色行为
【发布时间】:2024-01-04 20:53:01
【问题描述】:

我在一个托管服务上工作,该服务在 Web 角色的实例上部署了 Windows Azure 缓存。缓存在生产中启用,但在计算模拟器中我们禁用它,因为我们经常遇到缓存模拟器的减速和异常。特别是,在计算模拟器中,我们不会在csdef 中加载缓存模块,并且在运行时我们通过创建DataCacheFactory 并捕获客户端库配置中指示的角色时抛出的特定异常来检测是否启用了缓存。在csdef 中找不到。

这在 Windows Azure 缓存 2.0 之前一直正常工作——当我们升级到 Windows Azure 缓存 2.1(和 Azure SDK 2.1)时,行为发生了变化:

  • DataCacheFactory 构造函数没有异常;
  • 当我们尝试从DataCacheFactory 实例化DataCache 时,该角色似乎挂起,3 分钟后它返回并出现以下异常(可在here 找到完整的文本):

    Microsoft.ApplicationServer.Caching.DataCacheException was unhandled by
    user code
    Message=ErrorCode<ERRCA0017>:SubStatus<ES0006>:There is a temporary failure.
    Please retry later. (<snip>). Additional Information :
    The client was trying to communicate with the server:
    net.tcp://WebRole:24233.
    InnerException: System.Net.Sockets.SocketException
    Message=No such host is known
    

请注意,这不是以下 SO 问题的重复:

因为

  • 我确定我使用的是 Azure SDK 2.1(我已在调试中检查库版本是否正确);
  • 我的问题只有在我故意禁用缓存角色时才会出现。

【问题讨论】:

    标签: .net azure azure-web-roles azure-worker-roles azure-caching


    【解决方案1】:

    使用下面SO answer 中描述的过程并在 ILSpy 的帮助下,我已经能够理解为什么会发生此异常:在 Windows Azure 缓存 2.1 中,当未找到客户端配置中指定的角色时,将其视为一个地址并继续执行,而在旧版本中它会抛出一个异常(我发现它是为了理解缓存未启用)。

    相关的日志信息是:

    WaWorkerHost.exe Information: 0 : INFORMATION:
    <DistributedCache.CacheFactory.1> TryAutoDiscoverServersWithinDeployment
    for Instance 'WebRole' failed to connect as RoleName type with exception
    System.Reflection.TargetInvocationException: Exception has been thrown by
    the target of an invocation. --->
    Microsoft.ApplicationServer.Caching.DataCacheException:
    ErrorCode<UnspecifiedErrorCode>:SubStatus<ES0001>:The role WebService
    was not found in the current deployment.
    at Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtility.
      GetCacheRoleIPList(String roleName, String portIdentifier)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
      Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
      Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, 
      BindingFlags invokeAttr, Binder binder, Object[] parameters,
      CultureInfo culture)
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
    at Microsoft.ApplicationServer.Caching.DataCacheFactory.
       AutoDiscoverServersWithinDeployment()
    at Microsoft.ApplicationServer.Caching.DataCacheFactory.
       TryAutoDiscoverServersWithinDeployment()
    Assuming it as EndPoint.
    

    WaWorkerHost.exe Warning: 0 : WARNING: <DistributedCache.SocketClientChannel.1>
    Request 1 to host net.tcp://webrolw:24233/ failed 
    Status=ChannelOpenFailed[System.Net.Sockets.SocketException (0x80004005):
    No such host is known
    

    要解决此问题,您可以:

    • 分析刚刚创建的DataCacheFactory,查看Servers属性中是否有地址与缓存角色名称相同的项——表明指定角色没有配置缓存;
    • 在托管服务的调试配置中,降低DataCacheFactoryCacheReadyRetryPolicy 属性中的重试次数(这导致出现异常前的3 分钟延迟),如果抛出异常,则假定缓存不可用。

    【讨论】:

      最近更新 更多