@@ -166,6 +166,7 @@ int MtmConnectAttempts;
166
166
int MtmConnectTimeout ;
167
167
int MtmKeepaliveTimeout ;
168
168
int MtmReconnectAttempts ;
169
+ MtmConnectionInfo * MtmConnections ;
169
170
170
171
static char * MtmConnStrs ;
171
172
static int MtmQueueSize ;
@@ -420,8 +421,13 @@ MtmAdjustOldestXid(TransactionId xid)
420
421
oldestSnapshot = Mtm -> nodes [i ].oldestSnapshot ;
421
422
}
422
423
}
423
- for (ts = Mtm -> transListHead ; ts != NULL && ts -> csn < oldestSnapshot ; prev = ts , ts = ts -> next ) {
424
- Assert (ts -> status == TRANSACTION_STATUS_COMMITTED || ts -> status == TRANSACTION_STATUS_ABORTED || ts -> status == TRANSACTION_STATUS_IN_PROGRESS );
424
+ for (ts = Mtm -> transListHead ;
425
+ ts != NULL
426
+ && ts -> csn < oldestSnapshot
427
+ && (ts -> status == TRANSACTION_STATUS_COMMITTED || ts -> status == TRANSACTION_STATUS_ABORTED )
428
+ && TransactionIdPrecedes (ts -> xid , xid );
429
+ prev = ts , ts = ts -> next )
430
+ {
425
431
if (prev != NULL ) {
426
432
/* Remove information about too old transactions */
427
433
hash_search (MtmXid2State , & prev -> xid , HASH_REMOVE , NULL );
@@ -989,7 +995,7 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
989
995
for (i = 0 ; i < n ; i ++ ) {
990
996
if (i + 1 != MtmNodeId ) {
991
997
void * data = PaxosGet (psprintf ("node-mask-%d" , i + 1 ), NULL , NULL , nowait );
992
- matrix [i ] = * (nodemask_t * )data ;
998
+ matrix [i ] = data ? * (nodemask_t * )data : 0 ;
993
999
} else {
994
1000
matrix [i ] = Mtm -> connectivityMask ;
995
1001
}
@@ -1153,6 +1159,7 @@ static void MtmInitialize()
1153
1159
for (i = 0 ; i < MtmNodes ; i ++ ) {
1154
1160
Mtm -> nodes [i ].oldestSnapshot = 0 ;
1155
1161
Mtm -> nodes [i ].transDelay = 0 ;
1162
+ Mtm -> nodes [i ].con = MtmConnections [i ];
1156
1163
}
1157
1164
PGSemaphoreCreate (& Mtm -> votingSemaphore );
1158
1165
PGSemaphoreReset (& Mtm -> votingSemaphore );
@@ -1178,17 +1185,17 @@ MtmShmemStartup(void)
1178
1185
MtmInitialize ();
1179
1186
}
1180
1187
1181
- void MtmUpdateNodeConnStr ( int nodeId , char const * connStr )
1188
+ void MtmUpdateNodeConnectionInfo ( MtmConnectionInfo * conn , char const * connStr )
1182
1189
{
1183
1190
char const * host ;
1184
1191
char const * end ;
1185
1192
int hostLen ;
1186
1193
1187
1194
if (strlen (connStr ) >= MULTIMASTER_MAX_CONN_STR_SIZE ) {
1188
- elog (ERROR , "Too long (%d) connection string '%s' for node %d, limit is %d" ,
1189
- (int )strlen (connStr ), connStr , nodeId , MULTIMASTER_MAX_CONN_STR_SIZE - 1 );
1195
+ elog (ERROR , "Too long (%d) connection string '%s': limit is %d" ,
1196
+ (int )strlen (connStr ), connStr , MULTIMASTER_MAX_CONN_STR_SIZE - 1 );
1190
1197
}
1191
- strcpy (Mtm -> nodes [ nodeId - 1 ]. connStr , connStr );
1198
+ strcpy (conn -> connStr , connStr );
1192
1199
1193
1200
host = strstr (connStr , "host=" );
1194
1201
if (host == NULL ) {
@@ -1198,30 +1205,46 @@ void MtmUpdateNodeConnStr(int nodeId, char const* connStr)
1198
1205
for (end = host ; * end != ' ' && * end != '\0' ; end ++ );
1199
1206
hostLen = end - host ;
1200
1207
if (hostLen >= MULTIMASTER_MAX_HOST_NAME_SIZE ) {
1201
- elog (ERROR , "Too long (%d) host name '%.*s' for node %d, limit is %d" ,
1202
- hostLen , hostLen , host , nodeId , MULTIMASTER_MAX_HOST_NAME_SIZE - 1 );
1208
+ elog (ERROR , "Too long (%d) host name '%.*s': limit is %d" ,
1209
+ hostLen , hostLen , host , MULTIMASTER_MAX_HOST_NAME_SIZE - 1 );
1203
1210
}
1204
- memcpy (Mtm -> nodes [ nodeId - 1 ]. hostName , host , hostLen );
1205
- Mtm -> nodes [ nodeId - 1 ]. hostName [hostLen ] = '\0' ;
1211
+ memcpy (conn -> hostName , host , hostLen );
1212
+ conn -> hostName [hostLen ] = '\0' ;
1206
1213
}
1207
1214
1208
1215
static void MtmSplitConnStrs (void )
1209
1216
{
1210
1217
int i ;
1211
- char * copy = strdup (MtmConnStrs );
1218
+ char * copy = pstrdup (MtmConnStrs );
1212
1219
char * connStr = copy ;
1213
1220
char * connStrEnd = connStr + strlen (connStr );
1214
1221
1222
+ for (i = 0 ; connStr < connStrEnd ; i ++ ) {
1223
+ char * p = strchr (connStr , ',' );
1224
+ if (p == NULL ) {
1225
+ p = connStrEnd ;
1226
+ }
1227
+ connStr = p + 1 ;
1228
+ }
1229
+ if (i > MAX_NODES ) {
1230
+ elog (ERROR , "Multimaster with more than %d nodes is not currently supported" , MAX_NODES );
1231
+ }
1232
+ if (i < 2 ) {
1233
+ elog (ERROR , "Multimaster should have at least two nodes" );
1234
+ }
1235
+ MtmNodes = i ;
1236
+ MtmConnections = (MtmConnectionInfo * )palloc (i * sizeof (MtmConnectionInfo ));
1237
+ connStr = copy ;
1238
+
1215
1239
for (i = 0 ; connStr < connStrEnd ; i ++ ) {
1216
1240
char * p = strchr (connStr , ',' );
1217
1241
if (p == NULL ) {
1218
1242
p = connStrEnd ;
1219
1243
}
1220
- if (i == MAX_NODES ) {
1221
- elog (ERROR , "Multimaster with more than %d nodes is not currently supported" , MAX_NODES );
1222
- }
1223
1244
* p = '\0' ;
1224
- MtmUpdateNodeConnStr (i + 1 , connStr );
1245
+
1246
+ MtmUpdateNodeConnectionInfo (& MtmConnections [i ], connStr );
1247
+
1225
1248
if (i + 1 == MtmNodeId ) {
1226
1249
char * dbName = strstr (connStr , "dbname=" );
1227
1250
char * end ;
@@ -1232,20 +1255,13 @@ static void MtmSplitConnStrs(void)
1232
1255
dbName += 7 ;
1233
1256
for (end = dbName ; * end != ' ' && * end != '\0' ; end ++ );
1234
1257
len = end - dbName ;
1235
- MtmDatabaseName = (char * )malloc (len + 1 );
1258
+ MtmDatabaseName = (char * )palloc (len + 1 );
1236
1259
memcpy (MtmDatabaseName , dbName , len );
1237
1260
MtmDatabaseName [len ] = '\0' ;
1238
1261
}
1239
1262
connStr = p + 1 ;
1240
1263
}
1241
- free (copy );
1242
- if (i < 2 ) {
1243
- elog (ERROR , "Multimaster should have at least two nodes" );
1244
- }
1245
- MtmNodes = i ;
1246
- if (MtmNodeId > MtmNodes ) {
1247
- elog (ERROR , "Invalid node id %d for specified nubmer of nodes %d" , MtmNodeId , MtmNodes );
1248
- }
1264
+ pfree (copy );
1249
1265
}
1250
1266
1251
1267
void
0 commit comments