Skip to content

Commit

Permalink
doc: add a tutorial to setup replica with Dolt (apecloud#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
TianyuZhang1214 authored Nov 11, 2024
1 parent 6522da3 commit b13a144
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
8 changes: 4 additions & 4 deletions devtools/replica-setup/checker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ check_server_params() {
echo "Checking MySQL server parameters..."

# Retrieve the required MySQL server variables using mysqlsh
result=$(mysqlsh --host="$MYSQL_HOST" --user="$MYSQL_USER" --password="$MYSQL_PASSWORD" --sql -e "
result=$(mysqlsh --host="$MYSQL_HOST" --user="$MYSQL_USER" --port="$MYSQL_PORT" --password="$MYSQL_PASSWORD" --sql -e "
SHOW VARIABLES WHERE variable_name IN ('binlog_format', 'enforce_gtid_consistency', 'gtid_mode', 'log_bin');
")

Expand Down Expand Up @@ -50,8 +50,8 @@ check_server_params() {
fi

# Validate log_bin
if [[ "$log_bin" != "ON" ]]; then
echo "Error: log_bin is not set to 'ON', it is set to '$log_bin'."
if [[ "$log_bin" != "ON" && "$log_bin" != "1" ]]; then
echo "Error: log_bin is not enabled. Current value is '$log_bin'."
return 1
fi

Expand Down Expand Up @@ -102,7 +102,7 @@ check_if_source_mysql_is_empty() {
check_command "retrieving database list"

# Check if the output contains only the default databases
NON_DEFAULT_DBs=$(echo "$OUTPUT" | grep -v -E "^(Database|information_schema|mysql|performance_schema|sys)$" | wc -l)
NON_DEFAULT_DBs=$(echo "$OUTPUT" | grep -cv -E "^(Database|information_schema|mysql|performance_schema|sys)$")

if [[ "$NON_DEFAULT_DBs" -gt 0 ]]; then
return 1
Expand Down
62 changes: 62 additions & 0 deletions docs/tutorial/replica-setup-dolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Connecting to Dolt

[Dolt](https://www.dolthub.com) is a MySQL-compatible database with integrated Git-like version control, designed to manage database state over time.
Unlike traditional databases, Dolt requires some initial setup to support replication.
Follow this guide for configuring Dolt via Docker or the Dolt CLI.

## Pre-configuring Dolt

### Option 1: Docker

Using Docker is a convenient way to configure Dolt with a `config.json` file for replication setup.

```shell
# Create a directory for configuration and navigate to it
mkdir doltcfg && cd doltcfg

# Write configuration settings to config.json
cat <<EOF > config.json
{
"sqlserver.global.enforce_gtid_consistency": "ON",
"sqlserver.global.gtid_mode": "ON",
"sqlserver.global.log_bin": "1"
}
EOF

# Run Dolt in Docker with the configuration file
docker run -p 11229:3306 -v "$(pwd)":/etc/dolt/doltcfg.d/ dolthub/dolt-sql-server:latest
```

This configuration enables `GTID mode` and binary logging, which are essential for replication.

### Option 2: Dolt CLI

You can also configure Dolt directly with the Dolt CLI, allowing for the manual setup and additional control.

```shell
# Create a directory for the Dolt database and initialize it
mkdir doltPrimary && cd doltPrimary
dolt init --fun

# Configure replication settings
dolt sql -q "SET @@PERSIST.log_bin=1;"
dolt sql -q "SET @@PERSIST.gtid_mode=ON;"
dolt sql -q "SET @@PERSIST.enforce_gtid_consistency=ON;"

# Start Dolt SQL server on port 11229
dolt sql-server --loglevel DEBUG --port 11229
```

### Verify the Connection

After setup, you can verify the connection to Dolt:

```shell
mysql -h127.0.0.1 -uroot -P11229
```

## Next Steps

With Dolt configured, refer to [replica-setup-rds.md](replica-setup-rds.md) to complete the setup process for replication.
Only data from the `main` branch can be replicated to MyDuckServer.
To replicate data from other branches, please refer to the [Dolt to MySQL Replication guide](https://www.dolthub.com/blog/2024-07-05-binlog-source-preview/), which offers detailed instructions and additional options for working with different branches in Dolt.

0 comments on commit b13a144

Please sign in to comment.