Version:

libslave tutorial

libslave is a C++ library for reading data changes done by MysQL and,
optionally, writing them to a Tarantool database.
It works by acting as a replication slave.
The MySQL server writes data-change information to
a “binary log”, and transfers the information to
any client that says “I want to see the information
starting with this file and this record, continuously”.
So, libslave is primarily good for making a Tarantool database replica
(much faster than using a conventional MySQL slave server),
and for keeping track of data changes so they can be searched.

We will not go into the many details here – the
API documentation has them.
We will only show an exercise: a minimal program that uses the library.

Note

Use a test machine. Do not use a production machine.

STEP 1: Make sure you have:

a recent version of Linux (versions such as Ubuntu 14.04 will not do),

a recent version of MySQL 5.6 or MySQL 5.7 server (MariaDB will not do),

MySQL client development package. For example, on Ubuntu you can download
it with this command:

Everything unnecessary has been stripped so that you can
see quickly how it works. At the start of main(), there are
some settings used for connecting – host, port, user, password.
Then there is an initialization call with the binary log file
name = “mysql-bin”. Pay particular attention to the setCallback
statement, which passes database name = “test”, table name = “test”,
and callback function address = callback. The program will be
looping and invoking this callback function. See how, earlier
in the program, the callback function prints “UPDATE” or “DELETE”
or “INSERT” depending on what is passed to it.

STEP 5: Put the program in the tarantool-libslave directory and
name it example.cpp.