7.4 Channels (troubleshooting)

This tutorial is a continuation of tutorials Deploy MySQL DB System with Terraform and access the system and Endpoints

I strongly advise you to read them before moving on to this one.

In our previous tutorials we deployed one MySQL DB System. To access it, we provisioned one instance with MySQL client, respectively MySQL shell, making it possible to analyze the endpoints options.

What can we do from here on? A logical approach, since we have two instances - one instance (on which we deployed MySQL Client & mysql-shell), and one instance on which is deployed MySQL DB System, would be to perform a replication.

Enter "Channels"

Briefly put, a replication channel is the path of transactions transmitted from a master to a slave.

If you are new to channels, you can think of a "replication channel" as a "networking socket" through which the server listens for a client to make a connection, for transfering the data.

How to perform replication with a channel

The MySQL OCI documentation provides the following information:

Inbound Replication requires a replication channel configured in MySQL Database Service, connecting a correctly configured MySQL Source to a DB System target.

--documentation source: Replication

What does that mean?

For a MySQL replication, we usually need, at least, one master and one slave.

In this scenario, the master will be a MySQL source we will provision (along with a replication user), while the slave will be the MySQL DB System.

Since these tutorials are supposed to be implemented using as much automation as possible, the provisioning of MySQL & replication user should be done just the same.

In this example, the provisioning of MySQL and replica user will be done with the help of an ansible playbook.

The MySQL source will listen on port 3307.

For example, in below excerpt from playbook "mysql.yml", creating the replication user, changing host permissions and applying the changes:

For more details on integrating Terraform with Ansible, check the tutorial

VCN, Terraform and Ansible (Nginx example)

Adapting the Terraform code

From the previous tutorial, Deploy MySQL DB System with Terraform and access the system, we have 13 terraform files that would deploy an instance, a MySQL DB along with the compartment &networking setup:

As you might have guessed in this tutorial we need to add the code for creating and configuring the channel.

First thing first, let's start with file remote.tf, where there will be added the firewall rule on the instance for port 3307 (on which MySQL source will listen), and a provisioner "local-exec" for running the ansible-playbook:

Since I have mentioned firewall rules on the instance, we need to make the change on the Ingress security lists, for variable "portz" from file variables.tf (by adding 3307 port):

Channel resources (for this example)

To clarify a couple of terms:

  • source is the MySQL which is installed and configured on the instance

  • target is the MySQL DB System

Resource oci mysql channel - creates a channel

The required fields of oci_mysql_channel: source, target, compartment and is_enabled

source

hostname - fully qualified domain name of the MySQL source

password - The password for the replication user. The password must be between 8 and 32 characters long, and must contain at least 1 numeric character, 1 lowercase character, 1 uppercase character, and 1 special (nonalphanumeric) character.

port - the port on which MySQL source listens to

source type - The specific source identifier

ssl_mode - ssl status - enabled or disabled

username - the replication user

--------------------------------------------------------------

Changing the variables.tf, by adding the following:

target

db_system_id - OCID of the target MySQL DB System.

target_type - The specific target identifier

--------------------------------------------------------------

compartment - the Channel must be deployed in the same compartment as the MySQL DB System (the target)

is_enabled - set to "true", the Channel will be asynchronously started as a result of the create Channel operation.

--------------------------------------------------------------

The new terraform file, for setting up the Channel, create_channel.tf:

Discussion about source_type and target_type

The Terraform documentation for MySQL OCI DB could provide a bit more information.

For the "target_type" it is mentioned only:

target_type - (Required) (Updatable) The specific target identifier.

source_type - The specific source identifier.

No other options/specifications

However, as a work around, pass no value to either target_type or source type...

... and when you perform a terraform plan, the errors should provide following output:

Data sources (for this example)

Data source oci mysql channel

Setting up the data.tf, by adding the following:

Output

And just in case, let's add an output file, output.tf, to extract the Public IP of the instance:

My folder now has 15 terraform files that will implement the creation of an instance, the deployment of a MDS, and the configuration of Channel (along with compartment and networking configurations):

Obviously, we are not done yet... as mentioned in the beginning we need to automatically configure the MySQL source and the replication user.

Integrate Terraform with Ansible

A step-by-step implementation for Terraform-Ansible integration can be found at tutorial VCN, Terraform and Ansible (Nginx example), and at (a bit advanced) MySQL Replication (Compute Instances)

This tutorial will focus on Ansible files for MySQL service only, and not explaining the entire process of Terraform-Ansible integration

In the same folder, where the Terraform files exist, you will have to add:

  • ansible.cfg file (for setting up the default ansible configuration):

  • the mysql.yml playbook, which will make possible the installing and configuring of MySQL service on the instance, along with creating the replication user

  • the my.cnf configuration file for MySQL service (the source)

Discussion for my.cnf configuration file

Configurations implemented by following the recommendations/limitations of the Official Documentation:

Limitations

Current limitations of MySQL Database Service Inbound Replication:

  • Only Row-based replication supported.

  • Only GTID-based replication is supported.

  • Multi-source replication is not supported.

  • Replication filters are not supported.

  • Changes to the mysql schema are not replicated and cause replication to stop.

  • Source must run with the same lower_case_table_names value, as the DB System. This value is 0. It is not currently possible to change it.

-- documentation source: Replication

Now, my working directory contains 18 files in total:

Code example 1

The code example is at Github repository: https://github.com/MuchTest/MySqlDbSystemExample2

Comments are added for guidance - you will need to provide certain info if you want the environment to work (tenancy ocid, user ocid ... etc). Find a "how to" guide at this tutorial from Chapter 1.

Checking the deployed environment in Oracle Cloud UI

Deploy the environment by using the main terraform commands:

  • terraform init

  • terraform plan

  • terraform apply

Let's check the status of our MySQL source (MySQL service installed on instance), that runs on port 3307:

  • Check the MySQL DB System from OCI UI:

Notice the Inbound replication Channel state

  • Check the Channel

With message error:

The Channel is not applying transactions due to errors (MY-1227, Fri Mar 19 12:11:32 GMT 2021). A Resume action may be needed to continue.

Check from UI, just in case, if the configuration has been setup properly for target and source:

What we have so far: a created Channel that presents MY-1227 error.

Troubleshooting

As a reminder, we have two database systems that communicate through the Channel:

  • the master - the MySQL source

  • the slave - the MySQL DB System targe

1. Investigations on the Target (MySQL DB System)

Let's check the slave's status on MySQL DB System

we have already discussed how to connect to MySQL DB System at tutorial Endpoints

Check what errors appear in the status of the slave

Check the transactions status:

2. Investigations on the Source (MySQL service installed on OCI Instance)

As already suggested in the target logs, we need to check the binlog.000004 for more information:

Check transactionc585489e-88ab-11eb-802b-000017024f83:2

Check transaction c585489e-88ab-11eb-802b-000017024f83:3

Check transaction c585489e-88ab-11eb-802b-000017024f83:4

Confused much...

3 ... and let's go back to target MySQL DB System,

...and run a basic query:

So, far this error appears to be caused by my user's lack of super privileges.

Also, as mentioned in the documentation: "Replication filters are not supported." So, you can't make your way around.

However, how can one grant these privileges for a user on a MySQL OCI System?

There's a documentation about Configuring DB System (still, not sure if this can provide me more control over the user's privileges).

Edit: at next section ("...more Troubleshooting") you will find the right documentation; I still suggest you do read the Configuring DB System, too. You never know when it comes in handy for you.

... more Troubleshooting

I have mentioned at the ending of the previous "Troubleshooting" section that I needed to provide higher privileges to my user.

The information I was looking for (or at least, something related to) was found in the documentation Import and Exporting Databases (Compatibility Between On-Premise MySQL and MySQL Database Service section) and I quote:

strip_restricted_grants: certain privileges are restricted in the MySQL Database Service. Privileges such as RELOAD, FILE, SUPER, BINLOG_ADMIN, and SET_USER_ID. It is not possible to create users granting these privileges. This option strips these privileges from dumped GRANT statements.

That "RELOAD" privilege sounds familiar, eh?

Things to take in consideration at this step

The documentation Import and Exporting Databases mentions the following:

This task describes how to export data from a supported MySQL Server source to an Object Storage bucket using the MySQL Shell dumpInstance utility.This task requires the following:

  • MySQL Shell 8.0.21, or higher.

  • MySQL Server 5.7.9, or higher.

  • Access to Object Storage and an existing bucket.

[.... snip ... ]

-- source Exporting Data to Object Storage with MySQL Shell (Import and Exporting Databases)

Continuation at Fixed "MySQL source - MDS" replication

Last updated