Skip to content

Commit 98eb87d

Browse files
knizhnikkelvich
authored andcommitted
Rename paxos to taftable and make last one optionally included
1 parent 0f23a54 commit 98eb87d

File tree

2 files changed

+40
-60
lines changed

2 files changed

+40
-60
lines changed

multimaster.c

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
#include "multimaster.h"
5959
#include "ddd.h"
60-
#include "paxos.h"
60+
#include "raftable.h"
6161

6262
typedef struct {
6363
TransactionId xid; /* local transaction ID */
@@ -178,6 +178,7 @@ static int MtmWorkers;
178178
static int MtmVacuumDelay;
179179
static int MtmMinRecoveryLag;
180180
static int MtmMaxRecoveryLag;
181+
static bool MtmUseRaftable;
181182

182183
static ExecutorFinish_hook_type PreviousExecutorFinishHook;
183184
static ProcessUtility_hook_type PreviousProcessUtilityHook;
@@ -1102,7 +1103,7 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
11021103
int i, j, n = MtmNodes;
11031104
for (i = 0; i < n; i++) {
11041105
if (i+1 != MtmNodeId) {
1105-
void* data = PaxosGet(psprintf("node-mask-%d", i+1), NULL, NULL, nowait);
1106+
void* data = RaftableGet(psprintf("node-mask-%d", i+1), NULL, NULL, nowait);
11061107
if (data == NULL) {
11071108
return false;
11081109
}
@@ -1132,7 +1133,7 @@ bool MtmRefreshClusterStatus(bool nowait)
11321133
int clique_size;
11331134
int i;
11341135

1135-
if (!MtmBuildConnectivityMatrix(matrix, nowait)) {
1136+
if (!MtmUseRaftable || !MtmBuildConnectivityMatrix(matrix, nowait)) {
11361137
/* RAFT is not available */
11371138
return false;
11381139
}
@@ -1192,7 +1193,7 @@ void MtmCheckQuorum(void)
11921193
void MtmOnNodeDisconnect(int nodeId)
11931194
{
11941195
BIT_SET(Mtm->connectivityMask, nodeId-1);
1195-
PaxosSet(psprintf("node-mask-%d", MtmNodeId), &Mtm->connectivityMask, sizeof Mtm->connectivityMask, false);
1196+
RaftableSet(psprintf("node-mask-%d", MtmNodeId), &Mtm->connectivityMask, sizeof Mtm->connectivityMask, false);
11961197

11971198
/* Wait more than socket KEEPALIVE timeout to let other nodes update their statuses */
11981199
MtmSleep(MtmKeepaliveTimeout);
@@ -1211,52 +1212,9 @@ void MtmOnNodeDisconnect(int nodeId)
12111212
void MtmOnNodeConnect(int nodeId)
12121213
{
12131214
BIT_CLEAR(Mtm->connectivityMask, nodeId-1);
1214-
PaxosSet(psprintf("node-mask-%d", MtmNodeId), &Mtm->connectivityMask, sizeof Mtm->connectivityMask, false);
1215+
RaftableSet(psprintf("node-mask-%d", MtmNodeId), &Mtm->connectivityMask, sizeof Mtm->connectivityMask, false);
12151216
}
12161217

1217-
/*
1218-
* Paxos function stubs (until them are miplemented)
1219-
*/
1220-
void* PaxosGet(char const* key, int* size, PaxosTimestamp* ts, bool nowait)
1221-
{
1222-
unsigned enclen, declen, len;
1223-
char *enc, *dec;
1224-
Assert(ts == NULL); // not implemented
1225-
1226-
enc = raftable_get(key);
1227-
if (enc == NULL)
1228-
{
1229-
*size = 0;
1230-
return NULL;
1231-
}
1232-
1233-
enclen = strlen(enc);
1234-
declen = hex_dec_len(enc, enclen);
1235-
dec = palloc(declen);
1236-
len = hex_decode(enc, enclen, dec);
1237-
pfree(enc);
1238-
Assert(len == declen);
1239-
1240-
if (size != NULL) {
1241-
*size = declen;
1242-
}
1243-
return dec;
1244-
}
1245-
1246-
void PaxosSet(char const* key, void const* value, int size, bool nowait)
1247-
{
1248-
unsigned enclen, declen, len;
1249-
char *enc, *dec;
1250-
1251-
enclen = hex_enc_len(value, size);
1252-
enc = palloc(enclen) + 1;
1253-
len = hex_encode(value, size, enc);
1254-
Assert(len == enclen);
1255-
enc[len] = '\0';
1256-
1257-
raftable_set(key, enc, nowait ? 1 : INT_MAX);
1258-
pfree(enc);
1259-
}
12601218

12611219

12621220
/*
@@ -1483,6 +1441,19 @@ _PG_init(void)
14831441
NULL
14841442
);
14851443

1444+
DefineCustomBoolVariable(
1445+
"multimaster.use_raftable",
1446+
"Use raftable plugin for internode communication",
1447+
NULL,
1448+
&MtmUseRaftable,
1449+
false,
1450+
PGC_BACKEND,
1451+
0,
1452+
NULL,
1453+
NULL,
1454+
NULL
1455+
);
1456+
14861457
DefineCustomIntVariable(
14871458
"multimaster.workers",
14881459
"Number of multimaster executor workers per node",
@@ -1773,6 +1744,10 @@ MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
17731744
break;
17741745
}
17751746
}
1747+
if (isRecoverySession) {
1748+
MTM_INFO("%d: PGLOGICAL startup hook\n", MyProcPid);
1749+
sleep(30);
1750+
}
17761751
MtmLock(LW_EXCLUSIVE);
17771752
if (isRecoverySession) {
17781753
elog(WARNING, "Node %d start recovery of node %d", MtmNodeId, MtmReplicationNodeId);
@@ -1805,7 +1780,7 @@ MtmReplicationTxnFilterHook(struct PGLogicalTxnFilterArgs* args)
18051780
bool res = Mtm->status != MTM_RECOVERY
18061781
&& (args->origin_id == InvalidRepOriginId
18071782
|| MtmIsRecoveredNode(MtmReplicationNodeId));
1808-
MTM_INFO("%d: MtmReplicationTxnFilterHook->%d\n", MyProcPid, res);
1783+
MTM_TRACE("%d: MtmReplicationTxnFilterHook->%d\n", MyProcPid, res);
18091784
return res;
18101785
}
18111786

@@ -2373,16 +2348,16 @@ MtmDetectGlobalDeadLock(PGPROC* proc)
23732348

23742349
ByteBufferAlloc(&buf);
23752350
EnumerateLocks(MtmSerializeLock, &buf);
2376-
PaxosSet(psprintf("lock-graph-%d", MtmNodeId), buf.data, buf.used, true);
2351+
RaftableSet(psprintf("lock-graph-%d", MtmNodeId), buf.data, buf.used, true);
23772352
MtmGraphInit(&graph);
23782353
MtmGraphAdd(&graph, (GlobalTransactionId*)buf.data, buf.used/sizeof(GlobalTransactionId));
23792354
ByteBufferFree(&buf);
23802355
for (i = 0; i < MtmNodes; i++) {
23812356
if (i+1 != MtmNodeId && !BIT_CHECK(Mtm->disabledNodeMask, i)) {
23822357
int size;
2383-
void* data = PaxosGet(psprintf("lock-graph-%d", i+1), &size, NULL, true);
2358+
void* data = RaftableGet(psprintf("lock-graph-%d", i+1), &size, NULL, true);
23842359
if (data == NULL) {
2385-
return true; /* Just temporary hack until no Paxos */
2360+
return true; /* If using Raftable is disabled */
23862361
} else {
23872362
MtmGraphAdd(&graph, (GlobalTransactionId*)data, size/sizeof(GlobalTransactionId));
23882363
}

paxos.h renamed to raftable.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef __PAXOS_H__
2-
#define __PAXOS_H__
1+
#ifndef __RAFTABLE_H__
2+
#define __RAFTABLE_H__
33

4-
typedef struct PaxosTimestamp {
4+
typedef struct RaftableTimestamp {
55
time_t time; /* local time at master */
66
uint32 master; /* master node for this operation */
7-
uint32 psn; /* PAXOS serial number */
8-
} PaxosTimestamp;
7+
uint32 psn; /* RAFTABLE serial number */
8+
} RaftableTimestamp;
99

1010
/*
1111
* Get key value.
@@ -15,18 +15,23 @@ typedef struct PaxosTimestamp {
1515
* If "ts" is not NULL, then it is assigned timestamp of last update of this value
1616
* If RAFT master is not accessible, then depending non value of "nowait" parameter, this funciton should either block until RAFT quorum is reached, either report error.
1717
*/
18-
extern void* PaxosGet(char const* key, int* size, PaxosTimestamp* ts, bool nowait);
18+
extern void* RaftableGet(char const* key, int* size, RaftableTimestamp* ts, bool nowait);
1919

2020
/*
2121
* Set new value for the specified key. IF value is NULL, then key should be deleted.
2222
* If RAFT master is not accessible, then depending non value of "nowait" parameter, this funciton should either block until RAFT quorum is reached, either report error.
2323
*/
24-
extern void PaxosSet(char const* key, void const* value, int size, bool nowait);
24+
extern void RaftableSet(char const* key, void const* value, int size, bool nowait);
2525

2626
/*
2727
* If key doesn't exists or its value is not equal to the specified value then store this value and return true.
2828
* Otherwise do nothing and return false.
2929
* If RAFT master is not accessible, then depending non value of "nowait" parameter, this funciton should either block until RAFT quorum is reached, either report error.
3030
*/
31-
extern bool PaxosCAS(char const* key, char const* value, bool nowait);
31+
extern bool RaftableCAS(char const* key, char const* value, bool nowait);
32+
33+
typedef void* (*raftable_get_t)(char const* key, int* size, int timeout);
34+
typedef void (*raftable_set_t)(char const* key, void const* value, int size, int timeout);
35+
36+
3237
#endif

0 commit comments

Comments
 (0)