Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 839d890

Browse files
kvapkelvich
authored andcommitted
Merge branch 'master' into raftable-dynamic
1 parent a7c4878 commit 839d890

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

multimaster.c

+21-28
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,26 @@ static void MtmLoadLocalTables(void)
17081708
}
17091709
}
17101710

1711+
static void MtmRaftableInitialize()
1712+
{
1713+
int i;
1714+
1715+
for (i = 0; i < MtmNodes; i++)
1716+
{
1717+
char const* raftport = strstr(MtmConnections[i].connStr, "raftport=");
1718+
int port;
1719+
if (raftport != NULL) {
1720+
if (sscanf(raftport+9, "%d", &port) != 1) {
1721+
elog(ERROR, "Invalid raftable port: %s", raftport+9);
1722+
}
1723+
} else {
1724+
port = MtmRaftablePort + i;
1725+
}
1726+
raftable_peer(i, MtmConnections[i].hostName, port);
1727+
}
1728+
raftable_start(MtmNodeId - 1);
1729+
}
1730+
17111731

17121732
static void MtmInitialize()
17131733
{
@@ -1863,33 +1883,6 @@ static void MtmSplitConnStrs(void)
18631883
pfree(copy);
18641884
}
18651885

1866-
static void MtmRaftableInitialize()
1867-
{
1868-
int i;
1869-
WorkerConfig wcfg;
1870-
1871-
for (i = 0; i < RAFTABLE_PEERS_MAX; i++)
1872-
{
1873-
wcfg.peers[i].up = false;
1874-
}
1875-
1876-
for (i = 0; i < MtmNodes; i++)
1877-
{
1878-
char const* raftport = strstr(MtmConnections[i].connStr, "raftport=");
1879-
if (raftport != NULL) {
1880-
if (sscanf(raftport+9, "%d", &wcfg.peers[i].port) != 1) {
1881-
elog(ERROR, "Invalid raftable port: %s", raftport+9);
1882-
}
1883-
} else {
1884-
wcfg.peers[i].port = MtmRaftablePort + i;
1885-
}
1886-
wcfg.peers[i].up = true;
1887-
strncpy(wcfg.peers[i].host, MtmConnections[i].hostName, sizeof(wcfg.peers[i].host));
1888-
}
1889-
wcfg.id = MtmNodeId-1;
1890-
worker_register(&wcfg);
1891-
}
1892-
18931886
void
18941887
_PG_init(void)
18951888
{
@@ -2249,7 +2242,7 @@ _PG_init(void)
22492242

22502243
BgwPoolStart(MtmWorkers, MtmPoolConstructor);
22512244

2252-
//MtmRaftableInitialize();
2245+
MtmRaftableInitialize();
22532246
MtmArbiterInitialize();
22542247

22552248
/*

raftable.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,36 @@
99
*/
1010
void* RaftableGet(char const* key, size_t* size, RaftableTimestamp* ts, bool nowait)
1111
{
12+
void *value;
13+
size_t vallen;
1214
if (!MtmUseRaftable) {
1315
return NULL;
1416
}
15-
return raftable_get(key, size);
17+
value = raftable_get(key, &vallen, MtmHeartbeatSendTimeout);
18+
if (size != NULL) {
19+
*size = vallen;
20+
}
21+
return value;
1622
}
1723

1824

1925
void RaftableSet(char const* key, void const* value, size_t size, bool nowait)
2026
{
2127
if (MtmUseRaftable) {
28+
int tries = 10;
2229
timestamp_t start, stop;
2330
start = MtmGetSystemTime();
2431
if (nowait) {
2532
raftable_set(key, value, size, 0);
2633
} else {
27-
while (!raftable_set(key, value, size, MtmHeartbeatSendTimeout)) {
34+
while (!raftable_set(key, value, size, MtmHeartbeatSendTimeout))
35+
{
2836
MtmCheckHeartbeat();
37+
if (tries-- <= 0)
38+
{
39+
MTM_LOG1("RaftableSet nowait=%d, all attempts failed", nowait);
40+
break;
41+
}
2942
}
3043
}
3144
stop = MtmGetSystemTime();

0 commit comments

Comments
 (0)