Skip to content

Commit c75e222

Browse files
authored
Merge pull request #5557 from sysown/feature/gtid-range-update
Add support for GTID Range
2 parents 6cab7bd + 04b258e commit c75e222

14 files changed

Lines changed: 1206 additions & 640 deletions

include/Base_HostGroups_Manager.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class MetricsCollector;
1818

1919
#include "proxysql.h"
2020
#include "cpp.h"
21-
#include "proxysql_gtid.h"
21+
#include "GTID_Server_Data.h"
22+
2223

2324
#include <atomic>
2425
#include <thread>
@@ -153,37 +154,6 @@ class MyHGC;
153154
struct peer_runtime_mysql_servers_t;
154155
struct peer_mysql_servers_v2_t;
155156

156-
std::string gtid_executed_to_string(gtid_set_t& gtid_executed);
157-
void addGtid(const gtid_t& gtid, gtid_set_t& gtid_executed);
158-
159-
#include "GTID_Server_Data.h"
160-
161-
/*
162-
class GTID_Server_Data {
163-
public:
164-
char *address;
165-
uint16_t port;
166-
uint16_t mysql_port;
167-
char *data;
168-
size_t len;
169-
size_t size;
170-
size_t pos;
171-
struct ev_io *w;
172-
char uuid_server[64];
173-
unsigned long long events_read;
174-
gtid_set_t gtid_executed;
175-
bool active;
176-
GTID_Server_Data(struct ev_io *_w, char *_address, uint16_t _port, uint16_t _mysql_port);
177-
void resize(size_t _s);
178-
~GTID_Server_Data();
179-
bool readall();
180-
bool writeout();
181-
bool read_next_gtid();
182-
bool gtid_exists(char *gtid_uuid, uint64_t gtid_trxid);
183-
void read_all_gtids();
184-
void dump();
185-
};
186-
*/
187157

188158

189159
class MySrvConnList {

include/GTID_Server_Data.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <cstddef>
55
#include <cstdint>
6-
#include <string>
76
#include <proxysql_gtid.h>
87

98
class GTID_Server_Data {
@@ -18,7 +17,7 @@ class GTID_Server_Data {
1817
struct ev_io *w;
1918
char uuid_server[64];
2019
unsigned long long events_read;
21-
gtid_set_t gtid_executed;
20+
GTID_Set gtid_executed;
2221
bool active;
2322
GTID_Server_Data(struct ev_io *_w, char *_address, uint16_t _port, uint16_t _mysql_port);
2423
void resize(size_t _s);
@@ -31,6 +30,4 @@ class GTID_Server_Data {
3130
void dump();
3231
};
3332

34-
bool addGtidInterval(gtid_set_t& gtid_executed, std::string server_uuid, int64_t txid_start, int64_t txid_end);
35-
3633
#endif // CLASS_GTID_Server_Data_H

include/MySQL_HostGroups_Manager.h

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66

77
#include <atomic>
88
#include <thread>
9-
#include <iostream>
109
#include <mutex>
1110

11+
#include "ev.h"
12+
#include "wqueue.h"
13+
1214
// Headers for declaring Prometheus counters
1315
#include "prometheus/counter.h"
1416
#include "prometheus/gauge.h"
1517

16-
#include "thread.h"
17-
#include "wqueue.h"
18-
19-
#include "ev.h"
20-
2118
#ifndef SPOOKYV2
2219
#include "SpookyV2.h"
2320
#define SPOOKYV2
@@ -28,16 +25,18 @@
2825
#include "../deps/json/json_fwd.hpp"
2926
#endif // PROXYJSON
3027

28+
#include "proxysql.h"
29+
#include "cpp.h"
30+
#include "Base_HostGroups_Manager.h"
31+
#include "GTID_Server_Data.h"
32+
3133
#ifdef DEBUG
3234
/* */
3335
// Enabling STRESSTEST_POOL ProxySQL will do a lot of loops in the connection pool
3436
// This is for internal testing ONLY!!!!
3537
//#define STRESSTEST_POOL
3638
#endif // DEBUG
3739

38-
39-
#include "Base_HostGroups_Manager.h"
40-
4140
// we have 2 versions of the same tables: with (debug) and without (no debug) checks
4241
#ifdef DEBUG
4342
#define MYHGM_MYSQL_SERVERS "CREATE TABLE mysql_servers ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , gtid_port INT NOT NULL DEFAULT 0 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3, 4)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED CHECK (max_latency_ms>=0) NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , mem_pointer INT NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )"
@@ -138,37 +137,6 @@ class MyHGC;
138137
struct peer_runtime_mysql_servers_t;
139138
struct peer_mysql_servers_v2_t;
140139

141-
std::string gtid_executed_to_string(gtid_set_t& gtid_executed);
142-
void addGtid(const gtid_t& gtid, gtid_set_t& gtid_executed);
143-
144-
#include "GTID_Server_Data.h"
145-
146-
/*
147-
class GTID_Server_Data {
148-
public:
149-
char *address;
150-
uint16_t port;
151-
uint16_t mysql_port;
152-
char *data;
153-
size_t len;
154-
size_t size;
155-
size_t pos;
156-
struct ev_io *w;
157-
char uuid_server[64];
158-
unsigned long long events_read;
159-
gtid_set_t gtid_executed;
160-
bool active;
161-
GTID_Server_Data(struct ev_io *_w, char *_address, uint16_t _port, uint16_t _mysql_port);
162-
void resize(size_t _s);
163-
~GTID_Server_Data();
164-
bool readall();
165-
bool writeout();
166-
bool read_next_gtid();
167-
bool gtid_exists(char *gtid_uuid, uint64_t gtid_trxid);
168-
void read_all_gtids();
169-
void dump();
170-
};
171-
*/
172140

173141

174142
class MySrvConnList {

include/proxysql_gtid.h

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,55 @@
22
#define PROXYSQL_GTID
33
// highly inspired by libslave
44
// https://github.com/vozbu/libslave/
5+
#include <list>
56
#include <string>
67
#include <unordered_map>
7-
#include <list>
8-
#include <utility>
98

10-
typedef std::pair<std::string, int64_t> gtid_t;
11-
typedef std::pair<int64_t, int64_t> gtid_interval_t;
12-
typedef std::unordered_map<std::string, std::list<gtid_interval_t>> gtid_set_t;
9+
typedef int64_t trxid_t;
10+
11+
// Encapsulates an interval of Transaction IDs.
12+
class TrxId_Interval {
13+
public:
14+
trxid_t start;
15+
trxid_t end;
16+
17+
public:
18+
explicit TrxId_Interval(const trxid_t _start, const trxid_t _end);
19+
explicit TrxId_Interval(const trxid_t trxid);
20+
explicit TrxId_Interval(const char* s);
21+
explicit TrxId_Interval(const std::string& s);
22+
23+
const bool contains(const TrxId_Interval& other);
24+
const bool contains(trxid_t trxid);
25+
const std::string to_string(void);
26+
const bool append(const TrxId_Interval& other);
27+
const bool merge(const TrxId_Interval& other);
28+
29+
const int cmp(const TrxId_Interval& other);
30+
const bool operator<(const TrxId_Interval& other);
31+
const bool operator==(const TrxId_Interval& other);
32+
const bool operator!=(const TrxId_Interval& other);
33+
};
34+
35+
// Encapsulates a map of UUID -> trxid intervals.
36+
class GTID_Set {
37+
public:
38+
std::unordered_map<std::string, std::list<TrxId_Interval>> map;
1339

14-
/*
15-
class Gtid_Server_Info {
1640
public:
17-
gtid_set_t executed_gtid_set;
18-
char *hostname;
19-
uint16_t mysql_port;
20-
uint16_t gtid_port;
21-
bool active;
22-
Gtid_Server_Info(char *_h, uint16_t _mp, uint16_t _gp) {
23-
hostname = strdup(_h);
24-
mysql_port = _mp;
25-
gtid_port = _gp;
26-
active = true;
27-
};
28-
~Gtid_Server_Info() {
29-
free(hostname);
30-
};
41+
GTID_Set();
42+
43+
GTID_Set copy();
44+
void clear();
45+
46+
bool add(const std::string& uuid, const TrxId_Interval& iv);
47+
bool add(const std::string& uuid, const trxid_t& trxid);
48+
bool add(const std::string& uuid, const trxid_t& start, const trxid_t& end);
49+
bool add(const std::string& uuid, const char *s);
50+
bool add(const std::string& uuid, const std::string &s);
51+
52+
const bool has_gtid(const std::string& uuid, const trxid_t trxid);
53+
const std::string to_string(void);
3154
};
32-
*/
3355

34-
#endif /* PROXYSQL_GTID */
56+
#endif /* PROXYSQL_GTID */

0 commit comments

Comments
 (0)