• Facebook
  • Twitter(现为X)
  • Youtube
  • 内衬
  • RSS
  • 文档
  • 比较
  • 博客
  • 下载
  • 联系我们
下载
显示/隐藏目录

跨多个数据中心的 WAN 复制

NCache 通过桥接功能提供广域网复制,实现多站点复制和灾难恢复。在多个集群缓存之间建立桥接,数据通过该桥接从源站点复制到其他站点,而不会中断客户端的运行。

有关 Bridge 的更多概念和行为细节,您可以参考 桥梁架构 在管理员指南中。

Bridge 中可以有多个活动站点缓存,并且缓存操作可以同时进行。连接到一个活动站点缓存的客户端可能会添加一些键,而另一个活动节点也会执行相同的键操作。在这种情况下,Bridge 冲突解决器就会发挥作用。它会解决冲突,并根据定义的规则决定在缓存上应用哪个键。

如果用户没有配置任何冲突解决器规则,那么 NCache 使用默认解析器规则。在默认规则中,每次对缓存执行操作时都会添加一个时间跨度,并保留最新操作。系统会检查 Bridge 项的版本。如果该项具有较新的时间戳,或者版本是最新版本或相同,则用新条目替换该条目;如果是旧条目,则保留旧条目。

硬件需求

在使用 WAN 复制之前 NCache,请确保满足以下先决条件:

  • 。NET
  • 遗留 API
  • 安装 Alachisoft.NCache.SDK 应用程序中的 NuGet 包。
  • 要实现该接口,请在应用程序中包含以下命名空间:
    • Alachisoft.NCache。客户
    • Alachisoft.NCache.运行时.桥
  • 有关 API 详细信息,请参阅: 缓存, 缓存项, IBridge冲突解决器, 桥项版本, 提供者桥接项目, 解决冲突,解决行动, 桥项操作码.
  • 这应该是一个使用 Microsoft Visual Studio 的类库项目。
  • 确保 配置网桥 使用 NCache 管理中心实施本班后。
  • 在您的 .NET 客户端应用程序中安装以下 NuGet 包:
    • 企业版: Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
  • 确保要添加的数据是 可序列化.
  • 添加 NCache 案例 通过定位 %NCHOME%\NCache\bin\assembly\4.0 并添加 Alachisoft.NCache.Web 和 Alachisoft.NCache.Runtime 作为适当的。
  • 包括 Alachisoft.NCache.Runtime.Bridge 应用程序中的命名空间。
  • 要了解更多关于 NCache 旧版 API,请下载 NCache 4.9 可作为 邮编 文件在 Alachisoft 官方网站.
  • 这应该是一个使用 Microsoft Visual Studio 的类库项目。
  • 确保使用 NCache 实施此类后经理。

IBridgeConflictResolver 接口的示例实现

以下冲突解决器的示例实现包含解决从 Bridge 复制操作(针对缓存中已存在的键)时可能发生的任何冲突的逻辑。每当发生任何冲突时,缓存都会调用 Resolve 根据其中定义的规则来决定对缓存应用哪个操作。 它需要两个参数/条目,两者都是 ProviderBridgeItem 类型。

  • 。NET
  • 遗留 API
public class Resolver : IBridgeConflictResolver
{
    public void Init(System.Collections.IDictionary parameters)
    {
        // Initialize parameters
    }

    public ConflictResolution Resolve(ProviderBridgeItem oldEntry, ProviderBridgeItem newEntry)
    {   
        try
        {
            var conflictResolution = new ConflictResolution();

            switch (oldEntry.BridgeItemVersion)
            {
                case BridgeItemVersion.OLD:
                {
                conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                }
                break;

                case BridgeItemVersion.LATEST:
                {
                    conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                }
                break;

                case BridgeItemVersion.SAME:
                {
                    if (oldEntry.OpCode == BridgeItemOpCodes.Remove)
                    {
                        conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                    }
                    else
                    {
                    conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                    }
                }
            break;
            }
        }

        return conflictResolution;

        catch (Exception ex)
        {
            // Wrap and throw to ensure the Bridge service logs the specific synchronization failure
            throw new OperationFailedException("Error occurred during conflict resolution logic.", ex);
        }

        // Configure this implementation on cache
    }

    public void Dispose()
    {
        // Dispose resources
    }
}
public class Resolver : IBridgeConflictResolver
{
    private bool _enableLogging;
    private TextWriter _textLogger;
    private string streamLog = "bridgeResolverLog.txt";

    public void Init(System.Collections.IDictionary parameters)
    {
        try
        {
            // Initialize textWriter
            if(parameters.Contains("logging")){
                _enableLogging = Convert.ToBoolean(parameters["logging"]);
            }
            if (_enableLogging){
                _textLogger = new StreamWriter(streamLog);
            }
        }
        catch (Exception ex)
        {
            // If logging fails to initialize, we disable it to let the resolver continue
            _enableLogging = false;

            // Re-throw as ConfigurationException so NCache Bridge service logs the setup failure
            throw new ConfigurationException("Conflict Resolver failed to initialize logging.", ex);
        }
    }

    public ConflictResolution Resolve(ProviderBridgeItem oldEntry, ProviderBridgeItem newEntry)
    {
        try
        {
            ConflictResolution conflictResolution = new ConflictResolution();
            switch (oldEntry.BridgeItemVersion)
            {
                case BridgeItemVersion.OLD:
                {
                conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                }
                break;

                case BridgeItemVersion.LATEST:
                {
                    conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                }
                break;

                case BridgeItemVersion.SAME:
                {
                    if (oldEntry.OpCode == BridgeItemOpCodes.Remove){
                        conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                    }
                    else{
                    conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                    }
                }
                break;
            }
            if (_enableLogging){
            // Perform operations
            }
            return conflictResolution;
            }
        catch (Exception ex)
        {
            // Wrap in OperationFailedException to notify the Bridge service of the sync failure
            throw new OperationFailedException("Error during conflict resolution.", ex);
        }
    }

    public void Dispose()
    {   
    try
    {
        if (_enableLogging)
        {
            _textLogger.Close();
        }
    }
    catch (Exception)
    {
            // Silently fail during disposal to prevent process hang
    }
    }
}
注意:

为确保操作是故障安全的,建议处理应用程序中的任何潜在异常,如中所述 处理故障.

参见

入口处理器
为 WAN 复制配置网桥

联系我们

联系电话

+1 214-619-2601   (美国)

+44 20 7993 8327   (英国)

 
邮箱地址

sales@alachisoft.com

support@alachisoft.com

NCache
  • 版本比较
  • NCache 卓越
  • 基准
下载
定价
尝试游乐场

部署
  • 云(SaaS 和软件)
  • 内部部署
  • Kubernetes
  • Docker
技术用例
  • ASP.NET 会话
  • ASP.NET Core 会话
  • 发布/订阅消息
  • 实时 ASP.NET SignalR
  • 物联网(IOT)
  • NoSQL 数据库
  • 流处理
  • 微服务
相关资源
  • 杂志文章
  • 第三方文章
  • 专题文章
  • 视频
  • 白皮书
  • 作品
  • 会谈
  • 博客
  • 文档
客户案例研究
  • 评价
  • 客户
支持
  • 安排演示
  • 论坛(谷歌组)
  • 小技巧
关于我们
  • 领导团队
  • 合作伙伴
  • 新闻
  • 活动
  • 加入我们
联系我们

  • 英语简体中文法语版德语版意大利语版日语版韩语版葡萄牙语西班牙语

  • 联系我们
  •  
  • 网站地图
  •  
  • 使用条款
  •  
  • 隐私政策
©版权所有 Alachisoft 2002 - 版权所有。 NCache 是 Diyatech Corp. 的注册商标。
Back to top