mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-34705: Binlog in Engine: Refactor rpl_gtid.h
Move rpl_gtid and rpl_binlog_state_base into separate rpl_gtid_base.h include that can be used from engines implementing the binlog interface. Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
85
include/rpl_gtid_base.h
Normal file
85
include/rpl_gtid_base.h
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/* Copyright (c) 2013,2024, Kristian Nielsen and MariaDB Services Ab.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
||||||
|
|
||||||
|
#ifndef RPL_GTID_BASE_H
|
||||||
|
#define RPL_GTID_BASE_H
|
||||||
|
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Definitions for MariaDB global transaction ID (GTID). */
|
||||||
|
|
||||||
|
struct slave_connection_state;
|
||||||
|
|
||||||
|
struct rpl_gtid
|
||||||
|
{
|
||||||
|
uint32 domain_id;
|
||||||
|
uint32 server_id;
|
||||||
|
uint64 seq_no;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Binlog state.
|
||||||
|
|
||||||
|
A binlog state records the last GTID written to the binlog for every
|
||||||
|
distinct (domain_id, server_id) pair. Thus, each point in the binlog
|
||||||
|
corresponds to a specific binlog state.
|
||||||
|
|
||||||
|
When starting replication from a specific GTID position, the starting point
|
||||||
|
is identified as the most recent one where the binlog state has no higher
|
||||||
|
seq_no than the GTID position for any (domain_id, server_id) combination.
|
||||||
|
|
||||||
|
We also remember the most recent logged GTID for every domain_id. This is
|
||||||
|
used to know where to start when a master is changed to a slave. As a side
|
||||||
|
effect, it also allows to skip a hash lookup in the very common case of
|
||||||
|
logging a new GTID with same server id as last GTID.
|
||||||
|
|
||||||
|
This base class rpl_binlog_state_base contains just be basic data operations
|
||||||
|
to insert/update GTIDs, and is used eg. from Gtid_index_*.
|
||||||
|
*/
|
||||||
|
struct rpl_binlog_state_base
|
||||||
|
{
|
||||||
|
struct element {
|
||||||
|
uint32 domain_id;
|
||||||
|
HASH hash; /* Containing all server_id for one domain_id */
|
||||||
|
/* The most recent entry in the hash. */
|
||||||
|
rpl_gtid *last_gtid;
|
||||||
|
/* Counter to allocate next seq_no for this domain. */
|
||||||
|
uint64 seq_no_counter;
|
||||||
|
|
||||||
|
int update_element(const rpl_gtid *gtid);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Mapping from domain_id to collection of elements. */
|
||||||
|
HASH hash;
|
||||||
|
my_bool initialized;
|
||||||
|
|
||||||
|
rpl_binlog_state_base() : initialized(0) {}
|
||||||
|
~rpl_binlog_state_base();
|
||||||
|
void init();
|
||||||
|
void reset_nolock();
|
||||||
|
void free();
|
||||||
|
bool load_nolock(struct rpl_gtid *list, uint32 count);
|
||||||
|
bool load_nolock(rpl_binlog_state_base *orig_state);
|
||||||
|
int update_nolock(const struct rpl_gtid *gtid);
|
||||||
|
int alloc_element_nolock(const rpl_gtid *gtid);
|
||||||
|
uint32 count_nolock();
|
||||||
|
int get_gtid_list_nolock(rpl_gtid *gtid_list, uint32 list_size);
|
||||||
|
rpl_gtid *find_nolock(uint32 domain_id, uint32 server_id);
|
||||||
|
bool is_before_pos(slave_connection_state *pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* RPL_GTID_BASE_H */
|
@@ -16,9 +16,10 @@
|
|||||||
#ifndef RPL_GTID_H
|
#ifndef RPL_GTID_H
|
||||||
#define RPL_GTID_H
|
#define RPL_GTID_H
|
||||||
|
|
||||||
#include "hash.h"
|
|
||||||
#include "queues.h"
|
#include "queues.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include "rpl_gtid_base.h"
|
||||||
|
|
||||||
|
|
||||||
/* Definitions for MariaDB global transaction ID (GTID). */
|
/* Definitions for MariaDB global transaction ID (GTID). */
|
||||||
|
|
||||||
@@ -29,19 +30,9 @@ class String;
|
|||||||
#ifdef MYSQL_SERVER
|
#ifdef MYSQL_SERVER
|
||||||
struct TABLE;
|
struct TABLE;
|
||||||
#endif
|
#endif
|
||||||
struct slave_connection_state;
|
|
||||||
|
|
||||||
#define PARAM_GTID(G) G.domain_id, G.server_id, G.seq_no
|
|
||||||
|
|
||||||
#define GTID_MAX_STR_LENGTH (10+1+10+1+20)
|
#define GTID_MAX_STR_LENGTH (10+1+10+1+20)
|
||||||
#define PARAM_GTID(G) G.domain_id, G.server_id, G.seq_no
|
#define PARAM_GTID(G) (G).domain_id, (G).server_id, (G).seq_no
|
||||||
|
|
||||||
struct rpl_gtid
|
|
||||||
{
|
|
||||||
uint32 domain_id;
|
|
||||||
uint32 server_id;
|
|
||||||
uint64 seq_no;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator==(const rpl_gtid& lhs, const rpl_gtid& rhs)
|
inline bool operator==(const rpl_gtid& lhs, const rpl_gtid& rhs)
|
||||||
{
|
{
|
||||||
@@ -307,38 +298,6 @@ struct rpl_slave_state
|
|||||||
rpl_binlog_state builds server logic on top of that like mutex locking,
|
rpl_binlog_state builds server logic on top of that like mutex locking,
|
||||||
gtid_strict_mode handling, etc.
|
gtid_strict_mode handling, etc.
|
||||||
*/
|
*/
|
||||||
struct rpl_binlog_state_base
|
|
||||||
{
|
|
||||||
struct element {
|
|
||||||
uint32 domain_id;
|
|
||||||
HASH hash; /* Containing all server_id for one domain_id */
|
|
||||||
/* The most recent entry in the hash. */
|
|
||||||
rpl_gtid *last_gtid;
|
|
||||||
/* Counter to allocate next seq_no for this domain. */
|
|
||||||
uint64 seq_no_counter;
|
|
||||||
|
|
||||||
int update_element(const rpl_gtid *gtid);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Mapping from domain_id to collection of elements. */
|
|
||||||
HASH hash;
|
|
||||||
my_bool initialized;
|
|
||||||
|
|
||||||
rpl_binlog_state_base() : initialized(0) {}
|
|
||||||
~rpl_binlog_state_base();
|
|
||||||
void init();
|
|
||||||
void reset_nolock();
|
|
||||||
void free();
|
|
||||||
bool load_nolock(struct rpl_gtid *list, uint32 count);
|
|
||||||
bool load_nolock(rpl_binlog_state_base *orig_state);
|
|
||||||
int update_nolock(const struct rpl_gtid *gtid);
|
|
||||||
int alloc_element_nolock(const rpl_gtid *gtid);
|
|
||||||
uint32 count_nolock();
|
|
||||||
int get_gtid_list_nolock(rpl_gtid *gtid_list, uint32 list_size);
|
|
||||||
rpl_gtid *find_nolock(uint32 domain_id, uint32 server_id);
|
|
||||||
bool is_before_pos(slave_connection_state *pos);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct rpl_binlog_state : public rpl_binlog_state_base
|
struct rpl_binlog_state : public rpl_binlog_state_base
|
||||||
{
|
{
|
||||||
/* Mutex protecting access to the state. */
|
/* Mutex protecting access to the state. */
|
||||||
|
@@ -51,6 +51,7 @@ Created 11/29/1995 Heikki Tuuri
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "trx0undo.h"
|
#include "trx0undo.h"
|
||||||
#include "trx0trx.h"
|
#include "trx0trx.h"
|
||||||
|
#include "rpl_gtid_base.h"
|
||||||
|
|
||||||
/** Returns the first extent descriptor for a segment.
|
/** Returns the first extent descriptor for a segment.
|
||||||
We think of the extent lists of the segment catenated in the order
|
We think of the extent lists of the segment catenated in the order
|
||||||
|
Reference in New Issue
Block a user