A High Availability Data Synchronization Architecture

本文探讨了如何通过数据库镜像技术和负载均衡实现数据同步系统的高可用性,确保在24/7环境中数据始终可用。

Introduction

Data synchronization has become an important part of many corporate information systems. Synchronizing high availability databases and setting up synchronization systems without single points of failure are two challenges that organizations face as they bring synchronization systems to the 24/7 requirements of modern data systems.

Data Synchronization

In data synchronization environments, there is a transport mechanism to facilitate data transfer from the remote database to the consolidated database and vice-versa.


Figure 1 – Synchronization Process

Each database management solution has different mechanisms to resolve data synchronization. Sybase iAnywhere’s MobiLink Synchronization software provides a highly scalable session-based synchronization system that allows bi-directional synchronization between a main database, called the consolidated database, and many remote databases. The consolidated database can be one of several ODBC-compliant databases, including SQL Anywhere, Sybase Adaptive Server Enterprise, Oracle, Microsoft SQL Server, and IBM DB2.


Figure 2 – Sybase iAnywhere’s MobiLink Synchronization System

To create a synchronization system without a single point of failure, redundancy must be built in to each component of the system.

Database Mirroring

As corporations move towards always available data and occasionally connected applications, it is increasingly important to ensure enterprise database management systems remain functional and online in 24/7 environments. Database mirroring is an availability and disaster-recovery technology for database management systems to ensure data and data synchronization is available anytime.

A database mirroring system is a configuration of either two or three database servers, each running on separate computers, which cooperate to maintain copies of a database. Database mirroring consists of a primary server, mirror server, and arbiter server. The primary server and mirror server each maintain a copy of the database files while the arbiter server helps determine which of the other two servers can take ownership of the database. The arbiter server does not maintain a copy of the database.


Figure 3 – Database Management System Configured with High Availability

High Availability for Consolidated Database

Database mirroring builds high availability into the consolidated database. The dotted line in figure 4 represents the failover of the synchronization server if a role switch occurs in the database mirroring environment.


Figure 4 – High Availability for Consolidated Databases

High Availability for Synchronization Servers

Configuring a database mirroring environment still leaves a single point a failure in the data synchronization system. Figure 4 shows a single point of failure with the synchronization server. Using multiple synchronization servers and load balancers (failover cluster) can remove the single point of failure in the system. The dotted lines in figure 5 represent the failover of the synchronization server if a role switch occurs in the database mirroring environment or if there is a failure of synchronization server #1.


Figure 5 – High Availability Data Synchronization with No Single Failure

With the introduction of load balancers (failover cluster) and multiple synchronization servers, each component of the data synchronization environment is redundant. The data synchronization system will now function even if hardware or software failures occur in the environment.

High Availability for Remote Databases

A database mirroring environment can be used for configuring the remote database system, but initiating data synchronization is more complex. Data synchronization is initiated when the synchronization client establishes a connection with the remote database and synchronization server. However, in a database mirroring environment it is not always known which database is acting as the primary server.

The synchronization client needs to establish a connection with the primary server (or mirror server if role switch has occurred), so logically the synchronization client should be located on the same machine as the remote database. This allows the synchronization client to connect to the active database and prevents a single point of failure in the system.

High Availability for Synchronization Clients

A solution is to install the synchronization client on both the primary and mirror server machines then initiate synchronization through an external procedure.


Figure 6 – High Availability for Remote Databases

This can be accomplished with xp_cmdshell. The xp_cmdshell system procedure allows the execution of operating system commands directly to the Windows command shell via SQL code. This does not require knowing which machine is designated as the primary server, because:

    • When an application calls this external procedure, it will only be fired on the computer that is currently designated as the primary database server.
    • The synchronization client is called relative to the database server, so will not have any problem finding the database files.

Here is an example of an external procedure to initiate synchronization:

CALL xp_cmdshell( 'START dbmlsync -c dsn=MyDB -k -o c://out//ml.out 
-n MyPub -e sv=Version1', 'no_output' )

The xp_cmdshell process can be initiated through an application connection or via system process on the database server machine.

Removing Single Point of Failure with High Availability Synchronization Clients

In a database mirroring system, at least two machines must fail before the entire synchronization system fails. However, in the above solution, if the machine running the synchronization client fails then synchronization fails. To avoid this single point of failure an implementation using an external procedure called via a scheduled event that is stored in the database on both database servers will be sufficient. This prevents the need for an external application to initiate data synchronization. Scheduled events are a feature of Sybase iAnywhere’s SQL Anywhere that allows logic to be triggered based on a predefined schedule. The event will only fire on the server that is currently the primary server.

Here is an example of a scheduled event to call the external procedure:

CREATE EVENT "SyncEvent" 
HANDLER
BEGIN
event_parameter( 'NumActive' )
IF CAST( event_parameter('NumActive' ) AS INTEGER ) > 1 THEN RETURN;
END IF;
CALL xp_cmdshell( 'START dbmlsync -c dsn=MyDB -k -o c://out//ml.out
-n MyPub -e sv=Version1', 'no_output' )
END;
ALTER EVENT "SyncEvent"
ADD SCHEDULE "daily_sync"
EVERY 10 MINUTES BETWEEN '09:00:00' AND '22:00:00';

In this statement, the event parameter NumActive is used to ensure that an instance of synchronization is not already running. Synchronization is scheduled to occur every 10 minutes during business hours.

Summary

Corporations are going to continue to move towards always available data and occasionally connected applications. This will continue to increase the importance of enterprise database management systems to remain functional and online in 24/7 environments.

Database mirroring is an effective way to provide database availability and disaster-recovery for data synchronization environments. Failover of database mirroring environments is both fast and automatic, providing seamless, reliable service. Coupled with initiating synchronization from the remote database using the xp_cmdshell in a scheduled event will eliminate single points of failure in the mirrored architecture.

References

http://www.ianywhere.com/developer/product_manuals/sqlanywhere/

Author

Joshua Savill is a Product Manager of data synchronization technologies for Sybase iAnywhere.

### 高可用性概述 高可用性架构旨在确保系统能够持续提供服务,即使遇到硬件故障或其他中断情况也能保持正常运行。显然,没有任何单一系统可以解决所有问题;因此,评估具体情况并决定最适合的选项至关重要[^1]。 ### 实现方法 为了构建具备高可用性的解决方案,通常会采用多种技术组合的方式。例如,在SQL Server环境中,可以通过集成不同技术来实现既具有高可用性又拥有灾难恢复能力的部署方案。具体来说,这可能涉及到创建混合环境下的VPN隧道连接至Azure虚拟网络等措施[^3]。 对于微服务体系结构而言,建立高可用性和弹性设计同样重要。通过合理规划API网关、负载均衡器以及数据库层等方面的工作,可以使整个应用更加健壮可靠[^2]。 ### 最佳实践 在快速迭代开发过程中,质量保证(QA)不应作为独立环节存在于业务变更之前或发布之后。理想的QA流程应当贯穿于开发、运维及数据分析之中。借助灵活的质量检测手段,即便每日进行多次上线操作也能够在控制风险的同时保障产品质量[^4]。 存储过程往往包含了复杂的逻辑判断点,这些决策依赖于数据获取状况、延迟时间、用户权限或是并发冲突等因素的影响。所以务必针对各种场景下对该类程序进行全面测试与性能优化工作,从而发现潜在改进空间并加以完善[^5]。 ```python def check_high_availability(): """ A function to simulate checking components for high availability. This pseudo-code demonstrates how one might structure checks within an application designed with HA principles in mind. """ services = ["web_server", "database", "cache"] statuses = {} for service in services: status = perform_health_check(service) statuses[service] = status if not status["is_healthy"]: handle_failover_or_recovery(service) return all(statuses.values()) def perform_health_check(component): pass # Placeholder for actual health-check logic def handle_failover_or_recovery(failed_component): pass # Logic for handling failures according to predefined strategies ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值