bsr (Block Sync & Replication) is a solution for real-time replication of block devices on the host in software over the network.

Based on Windows DRBD (wdrbd) forked from drbd (http://www.drbd.org), it is is an open source project built as a cross-platform common engine to support both Windows and Linux platforms. It inherits all the basic concepts and functions of Windows DRBD, and provides solutions to build a more stable and efficient replication environment by supplementing the problems and functions of DRBD9.

bsr is free to contribute and participate in development through the open source community (bsr) (For technical support or inquiries regarding bsr, please contact to github issues for bsr or Mantech's dev3@mantech.co.kr )

bsr is distributed under the GPL v2 license. 

Basic

bsr replicates in the following way:

Kernel Driver

The core engine of bsr was developed as a kernel driver.

The kernel driver is located at the disk volume layer, and controls write I/O from the file system in block units. And as it performs replication in the lower layer of the file system, it is suitable for high availability by providing a transparent replication environment independent of the file system and application. However, since it is located in the lower layer of the file system, it cannot control general operations related to files. For example, it is not possible to detect damage to the file system or control pure file data. It is only replicate in blocks written to disk.

bsr provides Active-Passive clustering by default, not support Active-Active clustering.

Management tools

bsr provides management tools for organizing and managing resources. It consists of bsradm, bsrsetup, bsrmeta, and bsrcon described below. Administrator-level privileges are required to use administrative commands.

bsradm

bsrsetup

bsrmeta

bsrcon

Resource

Resources are the abstraction of everything needed to construct a replicated data set. Users configure a resource and then control it to operate a replication environment.

In order to configure resources, the following basic options (resource name, volume, network connection) must be specified.

Resource Name

Volume

Network Connection

Resource Role

Resources have the role of a Primary or Secondary.

The role of a resource can be changed through the bsr utility command. When changing the resource role from Secondary to Primary, it is called Promotion, and the opposite is Demotion.

Main Functions

Replication Cluster

bsr defines a set of nodes for replication as a replication cluster, and basically supports a single primary mode that can act as a primary resource on only one node of the replication cluster member. Dual or multiple primary modes are not supported. The single primary mode, the Active-Passive model, is the standard approach to handling data storage media in a highly available cluster for failover.

Replication Protocol

bsr supports three replication methods.

Protocol A. Asynchronous

The asynchronous method considers replication complete when the primary node finishes writing to the local disk and simultaneously writes to the send buffer of TCP. Therefore, this method is used locally when fail-over, but the data in the buffer may not be able to completely pass to the standby node. The data on the standby node after transfer is consistent, but some unsuccessful updates to the writes that occurred during transfer may be lost. This method has good local I / O responsiveness and is suitable for WAN remote replication environments.

Protocol B. Semi Synchronous

In the case of a semi-synchronous method, when a local disk write occurs on the primary node, replication is considered complete when the replication packet is received from the other node.

Normally, data loss does not occur during a fail-over, but if both nodes are powered off simultaneously or irreparable damage occurs in the primary storage, the most recently recorded data in the primary may be lost.

Protocol C. Synchronous

The synchronous method is considered complete when the primary node has completed writing to both the local and remote disks. This ensures that no data is lost in the event of loss on either node.

Of course, loss of data is inevitable if both nodes (or a node's storage subsystem) suffer irreparable damage at the same time.

In general, bsr uses the Protocol C method a lot.

The replication method should be determined by data consistency, local I / O latency performance, and throughput.

Synchronous replication completely guarantees the consistency of the active and standby node, but because the local I/O is completed after writing to the standby node for one write I/O, the local I/O latency There is a performance penalty. Depending on the I/O depth, latency can be reduced from several times to as many as tens of times or more, and on a throughput basis, it averages 70 MB/s on a 1 Gbps network.

For an example of configuring the replication mode, refer to create resources.

Replication Transport Protocol

bsr's replication transport network supports the TCP/IP transport protocol.

TCP(IPv4/v6)

It is the basic transport protocol of bsr and is a standard protocol that can be used on all systems that support IPv4/v6.

Efficient synchronization

In bsr, replication and (re)synchronization are separate concepts. Replication is a process that reflects all disk write operations of the resource of the primary role in real time to a secondary node, and synchronization is a process of copying block data from the perspective of all block devices excluding real-time write I/O. Replication and synchronization work individually, but they can be processed simultaneously.

If the connection between the primary and secondary is maintained, replication continues. However, if the replication connection is interrupted due to a failure of the primary or secondary node, or the replication network is disconnected, synchronization between the primary and secondary is required.

When synchronizing, bsr does not synchronize blocks in the order in which the original I/O was written to disk. Synchronization sequentially synchronizes only the areas that are not synchronized from sector 0 to the last sector based on the information in the metadata and efficiently processes as follows.

During synchronization, some of the Standby node's entire dataset is past and some are updated to the latest. The status of this data is called Inconsistent, and the status that all blocks are synchronized with the latest data is called UpToDate. Nodes in an inconsistent state are generally in a state where the volume is not available, so it is desirable to keep this state as short as possible.

Of course, even if synchronization is performed in the background, the application service of the Active node can be operated continuously with or without interruption.

Fixed-rate synchronization

In fixed-rate synchronization, the data rate synchronized to the peer node can be adjusted within the upper limit in seconds (this is called the synchronization rate), and can be specified as the minimum (c-min-rate) and maximum (c-max-rate).

Variable-rate synchronization

In Variable-rate synchronization bsr detects the available network bandwidth and compares it to I/O received from the application, automatically calculates the appropriate synchronization speed. bsr defaults to variable-band synchronization.

Checksum-based synchronization

Checksum data summarization can further improve the efficiency of the synchronization algorithm. Checksum-based synchronization reads blocks before synchronization, obtains a hash summary of what is currently on disk, and then compares the obtained hash summary by reading the same sector from the other node. If the hash values match, the re-write of the block is omitted. This method can be advantageous in performance compared to simply overwriting a block that needs to be synchronized, and if the file system rewrites the same data to a sector while disconnected (disconnected), resynchronization is skipped for that sector, so you can shorten the synchronization time in overall.

Congestion Mode

bsr provides a congestion mode function that can actively operate by detecting the congestion of the replication network during asynchronous replication. The congestion mode provides three operation modes: Blocking, Disconnect, and Ahead.

Online Verification

Online Verification is a function that checks the integrity of block-specific data between nodes during device operation. Integrity checks efficiently use network bandwidth and do not duplicate checks.

Online Verification is a cryptographic digest of all data blocks on a specific resource storage in one node (verification source), and the summary is compared to the contents of the same block location by transmitting the summarized content to a verification target. To do. If the summarized ㅗhash does not match, the block is marked out-of-sync and is later synchronized. Here, network bandwidth is effectively used because only the smallest summary is transmitted, not the entire block.

Since the operation of verifying the integrity of the resource is checked online, there may be a slight decrease in replication performance when online checking and replication are performed simultaneously. However, there is an advantage that there is no need to stop the service, and there is no downtime of the system during the scan or synchronization process after the scan. And since bsr executes FastSync as the basic logic, it is more efficient by performing an online scan only on the disk area used by the file system.

It is common practice to perform tasks according to Online Verification as scheduled tasks at the OS level and periodically perform them during times of low operational I / O load. For more information on how to configure online integrity checking, see Using on-line device verification.

Integrity check of replication traffic

bsr은 암호화 메시지 요약 알고리즘을 사용하여 양 노드 간의 복제 트래픽에 대한 무결성을 실시간 검증할 수 있습니다.

이 기능을 사용하게 되면 Primary는 모든 데이터 블록의 메시지 요약본을 생성하고 그것을 Secondary 노드에게 전달하여 복제 트래픽의 무결성을 확인합니다. 만약 요약된 블럭이 일치하지 않으면 재전송을 요청합니다. bsr은 이러한 복제 트래픽 무결성 검사를 통해 다음과 같은 에러 상황들에 대해 소스 데이터를 보호합니다. 만약 이러한 상황들에 대해 미리 대응하지 않는다면 복제 중 잠재적인 데이터 손상이 유발될 수 있습니다.

스플릿 브레인 통지와 복구

스플릿 브레인(Split brain)은 클러스터 노드들 사이에 모든 네트워크가 단절된 일시적인 장애 상황에서 클러스터 관리 소프트웨어나 관리자의 수동 개입으로 인해 두 개 이상의 노드가 Primary 역할을 가졌던 상황을 말합니다. 이것은 데이터에 대한 수정이 상대 측으로 복제되지 않고 각각의 노드에서 이루어졌다는 것을 암시하며 잠재적인 문제를 발생시킬 수 있는 상황입니다. 이 때문에 데이터가 병합되지 못하고 두 개의 데이터 셋이 만들어질 수도 있습니다.

핫빗(Heartbeat)과 같은 클러스터 노드 간을 관리하는 관리 모듈에서 모든 연결이 끊어졌을 때 판단하는 일반적인 HA 클러스터의 스플릿 브레인과 복제 스플릿 브레인은 구별되어야 합니다. 혼란을 피하기 위하여 앞으로 설명에서는 다음과 같은 규칙을 사용합니다.

bsr에서 스플릿 브레인을 감지하면(이메일 또는 다른 방법을 통해) 자동적으로 운영자에게 알릴 수 있습니다.

디스크 에러 처리 정책

디스크 장비에서 장애가 발생할 경우 bsr은 디스크 장애 정책의 사전 설정을 통해 해당 I/O 에러를 상위 계층(대부분 파일시스템)으로 단순히 전달해서 처리하거나 복제 디스크를 detach 하여 복제를 중단하도록 합니다. 전자는 패스스루 정책, 후자는 분리 정책입니다.

패스스루(passthrough)

하위 디스크 계층에서 에러 발생 시 별도 처리없이 상위(파일시스템) 계층으로 에러 내용을 전달합니다. 에러에 따른 적절한 처리는 상위 계층에게 맡깁니다. 예를 들어, 파일 시스템이 에러 내용을 보고 디스크 쓰기 재시도를 하거나 read-only 방식으로 다시 마운트를 시도할 수 있습니다. 이렇게 오류를 상위 계층으로 전달하는 방식을 통해 파일시스템 스스로가 에러를 인지할 수 있도록 하여 스스로 에러에 대처할 수 있는 기회를 부여합니다.

복제 서비스 운영 경험에 따르면 디스크 장애는 생각보다 자주 발생합니다. 이러한 결과는 하위 디스크 계층에 의존적이며 디스크 계층 즉, 표준 SCSI 계층의 에러는 임의의 시점에 언제든지 발생할 수 있다는 점에 비추어 보면 디스크 계층의 안정성과는 별도로 다루어야 하고, 복제 측면에서도 유연하게 대처할 수 있어야 함을 의미합니다. 그동안 디스크 장애 정책으로 제공해 왔던 detach 정책은 서비스 운영관점에선 복제가 특정시점에 일방적으로 중단되는 정책이었습니다. 이러한 방식은 사후 복구도 어렵고 서비스 운영 지속 측면에서도 불리합니다. 우리는 이러한 문제를 해결하기 위해 passthrough 정책을 고안하였으며 bsr의 기본정책으로 설정하게 되었습니다. 패스스루 정책은 I/O 에러가 발생할 경우 해당 블럭에 대해서 OOS 를 기록하고 실패된 I/O 결과를 파일시스템으로 전달합니다. 이 때 파일시스템이 에러가 발생한 블럭에 대해 쓰기 재시도하여 성공하고 이를 통해 OOS를 해소한다면 이는 일시적인 디스크 계층의 에러를 파일시스템 스스로 극복하도록 유도하게 됩니다. 비록 파일시스템의 동작 특성에 따라 완전히 OOS가 해소되지 못한다고 하더라도 일부 남겨진 OOS 는 연결 재시도 등을 통해 재동기화 하여 해결할 수도 있습니다. 즉 패스스루 정책은 에러 블럭을 FS가 스스로 해결하거나 동기화를 통해 해소하도록 유도하고, 기본적으로 디스크 I/O에 문제가 있더라도 서비스 운영을 지속하도록 보장합니다.

분리(detach)

에러 정책을 detach 방식으로 구성하였다면 하위 계층에서 에러 발생 시 bsr이 자동으로 디스크를 분리(detach)하는 방식으로 처리합니다. 디스크가 detach 되면 diskless 상태가 되고 디스크로의 I/O 가 차단되며, 이에 따라 디스크 장애가 인지되고 장애 후속조치가 취해져야 합니다. bsr에서 diskless 상태는 디스크에 I/O 가 유입되지 못하도록 차단된 상태로 정의합니다. I/O 에러 처리 정책 설정 에서 설정 파일을 구성하는 방법에 대해 설명하고 있습니다.

Outdated 데이터 정책

bsr은 Inconsistent 데이터와 Outdated 데이터를 구분합니다. Inconsistent 데이터란 어떤 방식으로든 접근이 불가능하거나 사용할 수  없는 데이터를 말합니다. 대표적인 예로 동기화 진행 중인 타겟 쪽 데이터가 Inconsistent 상태 입니다. 동기화가 진행 중인 타깃 데이터는 일부는 최신 이지만 일부는 지난 시점의 데이터 이므로 이를 한 시점의 데이터로 간주할 수 없습니다. 또한 이 때에는 장치에 적재 되었을 파일시스템이 마운트(mount)될 수 없거나 파일시스템 자동 체크 조차도 할 수 없는 상태 일 수 있습니다.

Outdated 디스크 상태는 데이터의 일관성은 보장되지만 Primary 노드와 최신의 데이터로 동기화되지 않았거나 이를 암시하는 데이터 입니다. 이런 경우는 임시적이든 영구적이든 복제 링크가 중단할 경우 발생합니다. 연결이 끊어진 Oudated 데이터는 결국 지난 시점의 데이터 이기 때문에 이러한 상태의 데이터에서 서비스가 되는 것을 막기 위해 bsr은 Outdated 데이터를 가진 노드에 대해 승격(promoting a resource)하는 것을 기본적으로 허용하지 않습니다. 그러나 필요하다면(긴급한 상황에서) Outdated 데이터를 강제로 승격할 수는 있습니다. 이와 관련하여 bsr은 네트워크 단절이 발생하자마자 응용프로그램이 측에서 즉시 Secondary노드를 Outdated 상태가 되도록 만들 수 있는 인터페이스를 갖추고 있습니다. Outdated 상태가 된 리소스에서 해당 복제링크가 다시 연결된다면 Outdated 상태 플래그는 자동으로 지워지며 백그라운드로 동기화(background synchronization)가 완료되어 최종 최신 데이터(UpToDate)로 갱신됩니다.

Primary 가 Crash 되었거나 연결이 단절된 Secondary 노드는 디스크 상태가 Outdated 일 수 있습니다.

운송 동기화

디스크를 직접 가져와서 구성하는 운송 동기화(Truck based replication)는 아래와 같은 상황에 적합합니다.

위의 경우 직접 디스크를 가져다가 동기화 하지 않고 bsr의 일반적인 초기 동기화를 진행한다면 매우 오랜 시간이 걸릴 것입니다. 디스크 크기가 크고 물리적으로 직접 복사하여 초기화를 시킬 수 있다면 이 방법을 권장합니다.  운송 동기화 사용을 참고 하세요.