Skip to content

Commit

Permalink
chore: fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
heehehe committed Aug 21, 2023
2 parents d7c2c73 + 62a009c commit 68fa675
Show file tree
Hide file tree
Showing 16 changed files with 448 additions and 83 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ jobs:
run: |
docker compose create
docker compose start
# Wait for the services to accept connections,
# TODO: do that smarter, poll connection attempt until it succeeds
sleep 30
echo "wait mysql server"
while :
do
if mysql -h 127.0.0.1 --user=root --execute "SELECT version();" 2>&1 >/dev/null && mysql -h 127.0.0.1 --port=3307 --user=root --execute "SELECT version();" 2>&1 >/dev/null; then
break
fi
sleep 1
done
echo "run pytest"
- name: Install dependencies
run: |
Expand Down
23 changes: 23 additions & 0 deletions .mariadb/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock

# Import all .cnf files from configuration directory

!includedir /etc/mysql/mariadb.conf.d/
!includedir /etc/mysql/conf.d/


[mariadb]
plugin_load_add = file_key_management
# Key files that are not encrypted
loose_file_key_management_filename = /opt/key_file/no_encryption_key.key

# Encrypted key file
# loose_file_key_management_filename=/opt/key_file/keyfile.enc
# loose_file_key_management_filekey=FILE:/opt/key_file/no_encryption_key.key
# file_key_management_encryption_algorithm=aes_ctr

# Set encrypt_binlog
encrypt_binlog=ON
1 change: 1 addition & 0 deletions .mariadb/no_encryption_key.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1;dda0ccb18a28b0b4c2448b5f0217a134
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python-mysql-replication
<a href="https://travis-ci.org/noplay/python-mysql-replication"><img src="https://travis-ci.org/noplay/python-mysql-replication.svg?branch=master"></a>&nbsp;
<a href="https://pypi.python.org/pypi/mysql-replication"><img src="http://img.shields.io/pypi/dm/mysql-replication.svg"></a>

Pure Python Implementation of MySQL replication protocol build on top of PyMYSQL. This allow you to receive event like insert, update, delete with their datas and raw SQL queries.
Pure Python Implementation of MySQL replication protocol build on top of PyMYSQL. This allows you to receive event like insert, update, delete with their datas and raw SQL queries.

Use cases
===========
Expand Down Expand Up @@ -56,6 +56,11 @@ Limitations

https://python-mysql-replication.readthedocs.org/en/latest/limitations.html

Featured Books
=============

[Data Pipelines Pocket Reference](https://www.oreilly.com/library/view/data-pipelines-pocket/9781492087823/) (by James Densmore, O'Reilly): Introduced and exemplified in Chapter 4: Data Ingestion: Extracting Data.

Projects using this library
===========================

Expand Down
59 changes: 59 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: '3.2'
services:
percona-5.7:
platform: linux/amd64
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: pymysqlreplication_test
ports:
- 3306:3306
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates
restart: always
networks:
- default

percona-5.7-ctl:
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: pymysqlreplication_test
ports:
- 3307:3307
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307

pymysqlreplication:
build:
context: .
dockerfile: test.Dockerfile
args:
BASE_IMAGE: python:3.11-alpine
MYSQL_5_7: percona-5.7
MYSQL_5_7_CTL: percona-5.7-ctl

command:
- /bin/sh
- -ce
- |
echo "wait mysql server"
while :
do
if mysql -h percona-5.7 --user=root --execute "USE pymysqlreplication_test;" 2>&1 >/dev/null && mysql -h percona-5.7-ctl --port=3307 --user=root --execute "USE pymysqlreplication_test;" 2>&1 >/dev/null; then
break
fi
sleep 1
done
echo "run pytest"
pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos"
working_dir: /pymysqlreplication
networks:
- default
depends_on:
- percona-5.7
- percona-5.7-ctl

networks:
default: {}
24 changes: 22 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,30 @@ services:
- 3307:3307
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307

mariadb-10.6:
image: mariadb:10.6
environment:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
ports:
- "3308:3306"
command: |
--server-id=1
--default-authentication-plugin=mysql_native_password
--log-bin=master-bin
--binlog-format=row
--log-slave-updates=on
volumes:
- type: bind
source: ./.mariadb
target: /opt/key_file
- type: bind
source: ./.mariadb/my.cnf
target: /etc/mysql/my.cnf

percona-8.0:
image: percona:8.0
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
ports:
- 3308:3308
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3308
- 3309:3309
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3309
2 changes: 1 addition & 1 deletion docs/developement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ When it's possible we have an unit test.
*pymysqlreplication/tests/* contains the test suite. The test suite
use the standard *unittest* Python module.

**Be carefull** tests will reset the binary log of your MySQL server.
**Be careful** tests will reset the binary log of your MySQL server.

Make sure you have the following configuration set in your mysql config file (usually my.cnf on development env):

Expand Down
8 changes: 5 additions & 3 deletions examples/mariadb_gtid/read_event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pymysql

from pymysqlreplication import BinLogStreamReader, gtid
from pymysqlreplication.event import GtidEvent, RotateEvent, MariadbGtidEvent, QueryEvent
from pymysqlreplication.event import GtidEvent, RotateEvent, MariadbGtidEvent, QueryEvent,MariadbAnnotateRowsEvent
from pymysqlreplication.row_event import WriteRowsEvent, UpdateRowsEvent, DeleteRowsEvent

MARIADB_SETTINGS = {
Expand Down Expand Up @@ -65,10 +65,12 @@ def query_server_id(self):
RotateEvent,
WriteRowsEvent,
UpdateRowsEvent,
DeleteRowsEvent
DeleteRowsEvent,
MariadbAnnotateRowsEvent
],
auto_position=gtid,
is_mariadb=True
is_mariadb=True,
annotate_rows_event=True
)

print('Starting reading events from GTID ', gtid)
Expand Down
Loading

0 comments on commit 68fa675

Please sign in to comment.