72
72
73
73
#include "multimaster.h"
74
74
#include "ddd.h"
75
- #include "raftable_wrapper.h"
76
- #include "raftable.h"
77
- #include "worker.h"
78
75
79
76
typedef struct {
80
77
TransactionId xid ; /* local transaction ID */
@@ -215,7 +212,6 @@ int MtmNodes;
215
212
int MtmNodeId ;
216
213
int MtmReplicationNodeId ;
217
214
int MtmArbiterPort ;
218
- int MtmRaftablePort ;
219
215
int MtmConnectTimeout ;
220
216
int MtmReconnectTimeout ;
221
217
int MtmNodeDisableDelay ;
@@ -225,7 +221,6 @@ int MtmHeartbeatSendTimeout;
225
221
int MtmHeartbeatRecvTimeout ;
226
222
int MtmMin2PCTimeout ;
227
223
int MtmMax2PCRatio ;
228
- bool MtmUseRaftable ;
229
224
bool MtmUseDtm ;
230
225
bool MtmPreserveCommitOrder ;
231
226
bool MtmVolksWagenMode ;
@@ -1745,7 +1740,7 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
1745
1740
1746
1741
for (i = 0 ; i < n ; i ++ ) {
1747
1742
if (i + 1 != MtmNodeId ) {
1748
- void * data = RaftableGet ( psprintf ( "node-mask-%d" , i + 1 ), NULL , NULL , nowait ) ;
1743
+ void * data = & Mtm -> nodes [ i ]. connectivityMask ;
1749
1744
if (data == NULL ) {
1750
1745
return false;
1751
1746
}
@@ -1901,17 +1896,6 @@ void MtmOnNodeDisconnect(int nodeId)
1901
1896
MTM_LOG1 ("Disconnect node %d connectivity mask %llx" , nodeId , (long long ) Mtm -> connectivityMask );
1902
1897
MtmUnlock ();
1903
1898
1904
- if (!RaftableSet (psprintf ("node-mask-%d" , MtmNodeId ), & Mtm -> connectivityMask , sizeof Mtm -> connectivityMask , false))
1905
- {
1906
- elog (WARNING , "Disable node which is in minority according to RAFT" );
1907
- MtmLock (LW_EXCLUSIVE );
1908
- if (Mtm -> status == MTM_ONLINE ) {
1909
- MtmSwitchClusterMode (MTM_IN_MINORITY );
1910
- }
1911
- MtmUnlock ();
1912
- return ;
1913
- }
1914
-
1915
1899
MtmSleep (MSEC_TO_USEC (MtmHeartbeatSendTimeout ));
1916
1900
MtmRefreshClusterStatus (false);
1917
1901
}
@@ -1922,9 +1906,6 @@ void MtmOnNodeConnect(int nodeId)
1922
1906
BIT_CLEAR (Mtm -> connectivityMask , nodeId - 1 );
1923
1907
BIT_CLEAR (Mtm -> reconnectMask , nodeId - 1 );
1924
1908
MtmUnlock ();
1925
-
1926
- MTM_LOG1 ("Reconnect node %d, connectivityMask=%llx" , nodeId , (long long ) Mtm -> connectivityMask );
1927
- RaftableSet (psprintf ("node-mask-%d" , MtmNodeId ), & Mtm -> connectivityMask , sizeof Mtm -> connectivityMask , false);
1928
1909
}
1929
1910
1930
1911
@@ -2034,21 +2015,6 @@ static void MtmLoadLocalTables(void)
2034
2015
heap_close (rel , RowExclusiveLock );
2035
2016
}
2036
2017
}
2037
-
2038
- static void MtmRaftableInitialize ()
2039
- {
2040
- int i ;
2041
-
2042
- for (i = 0 ; i < MtmNodes ; i ++ )
2043
- {
2044
- int port = MtmConnections [i ].raftablePort ;
2045
- if (port == 0 ) {
2046
- port = MtmRaftablePort + i ;
2047
- }
2048
- raftable_peer (i , MtmConnections [i ].hostName , port );
2049
- }
2050
- raftable_start (MtmNodeId - 1 );
2051
- }
2052
2018
2053
2019
static void MtmCheckControlFile (void )
2054
2020
{
@@ -2197,19 +2163,10 @@ void MtmUpdateNodeConnectionInfo(MtmConnectionInfo* conn, char const* connStr)
2197
2163
memcpy (conn -> hostName , host , hostLen );
2198
2164
conn -> hostName [hostLen ] = '\0' ;
2199
2165
2200
- port = strstr (connStr , "raftport =" );
2166
+ port = strstr (connStr , "arbiter_port =" );
2201
2167
if (port != NULL ) {
2202
- if (sscanf (port + 9 , "%d" , & conn -> raftablePort ) != 1 ) {
2203
- elog (ERROR , "Invalid raftable port: %s" , port + 9 );
2204
- }
2205
- } else {
2206
- conn -> raftablePort = 0 ;
2207
- }
2208
-
2209
- port = strstr (connStr , "arbiterport=" );
2210
- if (port != NULL ) {
2211
- if (sscanf (port + 12 , "%d" , & conn -> arbiterPort ) != 1 ) {
2212
- elog (ERROR , "Invalid arbiter port: %s" , port + 12 );
2168
+ if (sscanf (port + 13 , "%d" , & conn -> arbiterPort ) != 1 ) {
2169
+ elog (ERROR , "Invalid arbiter port: %s" , port + 13 );
2213
2170
}
2214
2171
} else {
2215
2172
conn -> arbiterPort = MULTIMASTER_DEFAULT_ARBITER_PORT ;
@@ -2538,19 +2495,6 @@ _PG_init(void)
2538
2495
NULL
2539
2496
);
2540
2497
2541
- DefineCustomBoolVariable (
2542
- "multimaster.use_raftable" ,
2543
- "Use raftable plugin for internode communication" ,
2544
- NULL ,
2545
- & MtmUseRaftable ,
2546
- true,
2547
- PGC_BACKEND ,
2548
- 0 ,
2549
- NULL ,
2550
- NULL ,
2551
- NULL
2552
- );
2553
-
2554
2498
DefineCustomBoolVariable (
2555
2499
"multimaster.ignore_tables_without_pk" ,
2556
2500
"Do not replicate tables withpout primary key" ,
@@ -2708,21 +2652,6 @@ _PG_init(void)
2708
2652
NULL
2709
2653
);
2710
2654
2711
- DefineCustomIntVariable (
2712
- "multimaster.raftable_port" ,
2713
- "Base value for assigning raftable ports" ,
2714
- NULL ,
2715
- & MtmRaftablePort ,
2716
- 6543 ,
2717
- 0 ,
2718
- INT_MAX ,
2719
- PGC_BACKEND ,
2720
- 0 ,
2721
- NULL ,
2722
- NULL ,
2723
- NULL
2724
- );
2725
-
2726
2655
DefineCustomStringVariable (
2727
2656
"multimaster.conn_strings" ,
2728
2657
"Multimaster node connection strings separated by commas, i.e. 'replication=database dbname=postgres host=localhost port=5001,replication=database dbname=postgres host=localhost port=5002'" ,
@@ -2813,9 +2742,6 @@ _PG_init(void)
2813
2742
2814
2743
BgwPoolStart (MtmWorkers , MtmPoolConstructor );
2815
2744
2816
- if (MtmUseRaftable ) {
2817
- MtmRaftableInitialize ();
2818
- }
2819
2745
MtmArbiterInitialize ();
2820
2746
2821
2747
/*
@@ -3516,8 +3442,7 @@ PGconn *PQconnectdb_safe(const char *conninfo)
3516
3442
{
3517
3443
PGconn * conn ;
3518
3444
char * safe_connstr = pstrdup (conninfo );
3519
- erase_option_from_connstr ("raftport" , safe_connstr );
3520
- erase_option_from_connstr ("arbiterport" , safe_connstr );
3445
+ erase_option_from_connstr ("arbiter_port" , safe_connstr );
3521
3446
3522
3447
conn = PQconnectdb (safe_connstr );
3523
3448
@@ -3626,11 +3551,17 @@ Datum mtm_dump_lock_graph(PG_FUNCTION_ARGS)
3626
3551
int i ;
3627
3552
for (i = 0 ; i < Mtm -> nAllNodes ; i ++ )
3628
3553
{
3629
- size_t size ;
3630
- char * data = RaftableGet (psprintf ("lock-graph-%d" , i + 1 ), & size , NULL , false);
3631
- if (data ) {
3632
- GlobalTransactionId * gtid = (GlobalTransactionId * )data ;
3633
- GlobalTransactionId * last = (GlobalTransactionId * )(data + size );
3554
+ size_t lockGraphSize ;
3555
+ char * lockGraphData ;
3556
+ MtmLockNode (i + MtmMaxNodes , LW_SHARED );
3557
+ lockGraphSize = Mtm -> nodes [i ].lockGraphUsed ;
3558
+ lockGraphData = palloc (lockGraphSize );
3559
+ memcpy (lockGraphData , Mtm -> nodes [i ].lockGraphData , lockGraphSize );
3560
+ MtmUnlockNode (i + MtmMaxNodes );
3561
+
3562
+ if (lockGraphData ) {
3563
+ GlobalTransactionId * gtid = (GlobalTransactionId * ) lockGraphData ;
3564
+ GlobalTransactionId * last = (GlobalTransactionId * ) (lockGraphData + lockGraphSize );
3634
3565
appendStringInfo (s , "node-%d lock graph: " , i + 1 );
3635
3566
while (gtid != last ) {
3636
3567
GlobalTransactionId * src = gtid ++ ;
@@ -4543,19 +4474,28 @@ MtmDetectGlobalDeadLockFortXid(TransactionId xid)
4543
4474
4544
4475
ByteBufferAlloc (& buf );
4545
4476
EnumerateLocks (MtmSerializeLock , & buf );
4546
- RaftableSet (psprintf ("lock-graph-%d" , MtmNodeId ), buf .data , buf .used , false);
4477
+
4478
+ Assert (replorigin_session_origin == InvalidRepOriginId );
4479
+ XLogFlush (LogLogicalMessage ("L" , buf .data , buf .used , false));
4480
+
4547
4481
MtmSleep (MSEC_TO_USEC (DeadlockTimeout ));
4548
4482
MtmGraphInit (& graph );
4549
4483
MtmGraphAdd (& graph , (GlobalTransactionId * )buf .data , buf .used /sizeof (GlobalTransactionId ));
4550
4484
ByteBufferFree (& buf );
4551
4485
for (i = 0 ; i < Mtm -> nAllNodes ; i ++ ) {
4552
4486
if (i + 1 != MtmNodeId && !BIT_CHECK (Mtm -> disabledNodeMask , i )) {
4553
- size_t size ;
4554
- void * data = RaftableGet (psprintf ("lock-graph-%d" , i + 1 ), & size , NULL , false);
4555
- if (data == NULL ) {
4487
+ size_t lockGraphSize ;
4488
+ void * lockGraphData ;
4489
+ MtmLockNode (i + MtmMaxNodes , LW_SHARED );
4490
+ lockGraphSize = Mtm -> nodes [i ].lockGraphUsed ;
4491
+ lockGraphData = palloc (lockGraphSize );
4492
+ memcpy (lockGraphData , Mtm -> nodes [i ].lockGraphData , lockGraphSize );
4493
+ MtmUnlockNode (i + MtmMaxNodes );
4494
+
4495
+ if (lockGraphData == NULL ) {
4556
4496
return true; /* If using Raftable is disabled */
4557
4497
} else {
4558
- MtmGraphAdd (& graph , (GlobalTransactionId * )data , size /sizeof (GlobalTransactionId ));
4498
+ MtmGraphAdd (& graph , (GlobalTransactionId * )lockGraphData , lockGraphSize /sizeof (GlobalTransactionId ));
4559
4499
}
4560
4500
}
4561
4501
}
0 commit comments