Skip to content

Commit

Permalink
update sieve to handle mariadb gtid information
Browse files Browse the repository at this point in the history
This changes the directory format to append the MariaDB GTID
section to replication_info.sql[.ext] and otherwise is just
pass through for the stream writer.

Resolves issue #78
  • Loading branch information
abg committed Jan 7, 2015
1 parent 0596851 commit 9201f99
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions dbsake/core/mysql/sieve/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def extract_identifier(value):
DISCRIMINATORS = [
(b'-- MySQL dump', 'header'),
(b'-- Position', 'replication_info'),
(b'-- GTID to start replication from', 'replication_info'),
(b'-- Current Database', 'createdatabase'),
(b'-- Table structure', 'tablestructure'),
(b'-- Dumping data for table', 'tabledata'),
Expand Down
8 changes: 7 additions & 1 deletion dbsake/core/mysql/sieve/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def command_to_ext(command):
class DirectoryWriter(SimpleWriter):
# track the first view, so we can initialize a file as needed
first_view = False
replication_info = False

def _open(self, parts, mode='ab'):
basedir = self.options.directory.encode('utf8')
Expand All @@ -85,7 +86,12 @@ def open_header(self, section):
return self.open_devnull(section)

def open_replication_info(self, section):
return self._open([b'replication_info.sql'], mode='wb')
if not self.replication_info:
mode = 'wb'
self.replication_info = True
else:
mode = 'ab'
return self._open([b'replication_info.sql'], mode=mode)

def open_createdatabase(self, section):
return self._open([section.database, section.database + b'.createdb'],
Expand Down
Binary file added tests/mariadb_gtid_master_data.sql.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ def test_sieve_directory():
with runner.isolated_filesystem():
result = runner.invoke(sieve_cli, args, obj={})
assert result.exit_code == 0


def test_sieve_w_mariadb10_gtid():
runner = CliRunner()
path = os.path.join(os.path.dirname(__file__),
'mariadb_gtid_master_data.sql.gz')

args = ['--format=stream', '--input-file=' + path, '-O']
result = runner.invoke(sieve_cli, args, obj={})
assert result.exit_code == 0

0 comments on commit 9201f99

Please sign in to comment.