Skip to content

Commit fbf21c9

Browse files
committed
Add an assert checking if raftable has been configured.
1 parent 10ca191 commit fbf21c9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

contrib/raftable/raftable.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static int get_connection(void)
153153

154154
char *raftable_get(const char *key, size_t *len)
155155
{
156+
Assert(wcfg.id >= 0);
156157
return state_get(shared.state, key, len);
157158
}
158159

@@ -249,6 +250,8 @@ bool raftable_set(const char *key, const char *value, size_t vallen, int timeout
249250
TimestampTz now;
250251
int elapsed_ms;
251252

253+
Assert(wcfg.id >= 0);
254+
252255
keylen = strlen(key) + 1;
253256

254257
size += sizeof(RaftableField) - 1;
@@ -308,6 +311,7 @@ void raftable_every(void (*func)(const char *, const char *, size_t, void *), vo
308311
char *key, *value;
309312
size_t len;
310313
Assert(shared.state);
314+
Assert(wcfg.id >= 0);
311315

312316
scan = state_scan(shared.state);
313317
while (state_next(shared.state, scan, &key, &value, &len))
@@ -327,6 +331,7 @@ raftable_sql_list(PG_FUNCTION_ARGS)
327331
MemoryContext oldcontext;
328332

329333
Assert(shared.state);
334+
Assert(wcfg.id >= 0);
330335

331336
if (SRF_IS_FIRSTCALL())
332337
{
@@ -399,8 +404,8 @@ _PG_init(void)
399404

400405
DefineCustomIntVariable("raftable.id",
401406
"Raft peer id of current instance", NULL,
402-
&wcfg.id, 0,
403-
0, RAFTABLE_PEERS_MAX-1,
407+
&wcfg.id, -1,
408+
-1, RAFTABLE_PEERS_MAX-1,
404409
PGC_POSTMASTER, 0, NULL, NULL, NULL
405410
);
406411

@@ -452,13 +457,18 @@ _PG_init(void)
452457
&peerstr, "0:127.0.0.1:6543",
453458
PGC_POSTMASTER, 0, NULL, NULL, NULL
454459
);
455-
parse_peers(wcfg.peers, peerstr);
456-
457-
request_shmem();
458-
worker_register(&wcfg);
459460

460461
PreviousShmemStartupHook = shmem_startup_hook;
461-
shmem_startup_hook = startup_shmem;
462+
463+
if (wcfg.id >= 0)
464+
{
465+
parse_peers(wcfg.peers, peerstr);
466+
467+
request_shmem();
468+
worker_register(&wcfg);
469+
470+
shmem_startup_hook = startup_shmem;
471+
}
462472
}
463473

464474
void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy