> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cennso-db/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cennso-db/latest/deployment-guides/binary-donor.md).

# Enable `binary-donor`

With asynchronous replication, the primary MySQL instance streams binary log events to replicas in the background. When the primary instance unexpectedly fails or restarts, it may happen that recently committed transactions exist only in the primary's binary logs on disk. A standard failover would promote the replica as a new primary, losing those transactions.

`binary-donor` is a lightweight MySQL binary log server that runs with each MySQL instance and serves its binary logs when the MySQL server instance goes down. This allows replicas to catch up to the primary's last committed transaction before promotion, ensuring zero data loss during failover.

Each `binary-donor` pod reads the binary logs directly from the data volume of its MySQL instance. To do that, it must run on the same node as that MySQL instance and mount the same volume.

The storage class specified in **spec.storage.className** of the `DBInstance` CR must support mounting the same volume by two pods on the same node. Node-local volumes and storage classes created by the Cennso Database Operator support this by default.

Some storage drivers attach a volume to only one pod by default. In this case, you must enable shared access in the `StorageClass`. For example, the [OpenEBS LVM LocalPV](https://openebs.io/docs/user-guides/local-storage-user-guide/local-pv-lvm/lvm-overview) driver requires the `shared: "yes"` parameter:

```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: {STORAGE-CLASS-NAME}
provisioner: local.csi.openebs.io
parameters:
  storage: lvm
  shared: "yes"
```

If the storage class does not allow this, the `binary-donor` pods cannot mount the volume and do not start.

## Enable `binary-donor` in the `DBInstance` CR

> [!IMPORTANT]
> Enabling `binary-donor` adds the following changes to the configruation of the `XDBInstance` composition:
>
> - Activates the `binary-donor` pre-failover hooks bundled in the default Orchestrator image (`registry.cennso.com/cennso/mysql-orchestrator:v3.2.6-19-cennso-0.3`). When `binary-donor` is disabled, the same image runs with the default Orchestrator configuration.
> - Always disables the MySQL [CLONE](https://dev.mysql.com/doc/refman/8.0/en/clone-plugin.html) operation, even if **spec.mysql.cloneRequiredOnAsyncCluster** is set to `true`. For more information, see the [Cloning database instances](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-instance.md#cloning-database-instances) section.

To enable `binary-donor`, set the **spec.binaryDonor.enabled** configuration option to `true` in your `DBInstance` CR. The following example shows a minimal `DBInstance` CR with `binary-donor` enabled:

```yaml
apiVersion: db.contrib.cennso.com/v1alpha1
kind: DBInstance
metadata:
  name: {DATABASE-CLUSTER-NAME}
  namespace: cennso-infra
spec:
  connectionSecretRef:
    name: {CORE-CLUSTER-NAME}
    namespace: cennso-infra
  namespace: {DATABASE-CLUSTER-NAMESPACE}
  storage:
    capacity: 20Gi
    className: mysql-cluster-storage
  instances:
    0:
      storage:
        node: {NODE-0-NAME}
        path: /opt/local-path-provisioner/mysql-cluster/mysql-instance-0
    1:
      storage:
        node: {NODE-1-NAME}
        path: /opt/local-path-provisioner/mysql-cluster/mysql-instance-1
  binaryDonor:
    enabled: true
    image:
      registry: registry.cennso.com/cennso/binlog-donor
      tag: v1.0.1
      pullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 500m
        memory: 500Mi
      limits:
        cpu: 500m
        memory: 500Mi
```

> [!NOTE]
> For more information about configuration options not related to `binary-donor`, such as **spec.storage** and **spec.instances**, see the [Deploy Cennso Database Instance](https://docs.cennso.com/cennso/cennso-db/latest/deployment-guides/cennso-database.md#deploy-cennso-database-instance) document.

After you have prepared the `DBInstance` CR with `binary-donor` enabled, apply it to your Management Cluster:

```bash
kubectl apply -f database-cluster-cr.yaml
```

Verify that the `binary-donor` pods are running alongside the MySQL instances:

```bash
kubectl get pods -n {DATABASE-CLUSTER-NAMESPACE}
```

For more information about the available configuration options for `binary-donor`, see the [Cennso Database Instance](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-instance.md#binary-log-donor-server) document.

## MySQL requirements

> [!IMPORTANT]
> A primary instance with more than one replica is not supported yet. If your deployment has more than one replica, do not enable `binary-donor`, but use the **spec.mysql.cloneRequiredOnAsyncCluster** instead.

The source MySQL instance must be configured with the following settings for `binary-donor` to function correctly:

| Setting | Required value |
|---|---|
| [`log_bin`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_log_bin) | `ON` |
| [`sync_binlog`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_sync_binlog) | `1` |
| [`gtid_mode`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-gtids.html#sysvar_gtid_mode) | `ON` |
| [`binlog_format`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_format) | `ROW` |
| [`binlog_order_commits`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_order_commits) | `ON` |
| [`binlog_checksum`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#option_mysqld_binlog-checksum) | `CRC32` |
| [`binlog_transaction_compression`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_transaction_compression) | `OFF` |
| [`binlog_encryption`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_encryption) | `OFF` |

These settings are configured by default in the MySQL instances deployed by the Cennso Database extension.
