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

Commit 5e1f612

Browse files
committed
Fix raftable_set freeze when timeout < 0 and the leader gets disconnected.
1 parent d34581b commit 5e1f612

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

contrib/raftable/raftable.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ bool raftable_set(const char *key, const char *value, size_t vallen, int timeout
332332
size_t size = sizeof(RaftableUpdate);
333333
size_t keylen = 0;
334334
timeout_t timeout;
335-
timeout_start(&timeout, timeout_ms);
336335

337336
Assert(wcfg.id >= 0);
338337

@@ -352,17 +351,37 @@ bool raftable_set(const char *key, const char *value, size_t vallen, int timeout
352351
memcpy(f->data, key, keylen);
353352
memcpy(f->data + keylen, value, vallen);
354353

355-
TIMEOUT_LOOP_START(&timeout);
354+
if (timeout_ms < 0)
356355
{
357-
if (try_sending_update(ru, size, &timeout))
356+
while (true)
358357
{
359-
pfree(ru);
360-
return true;
358+
timeout_start(&timeout, 100);
359+
360+
if (try_sending_update(ru, size, &timeout))
361+
{
362+
pfree(ru);
363+
return true;
364+
}
365+
else
366+
disconnect_leader();
367+
}
368+
}
369+
else
370+
{
371+
timeout_start(&timeout, timeout_ms);
372+
373+
TIMEOUT_LOOP_START(&timeout);
374+
{
375+
if (try_sending_update(ru, size, &timeout))
376+
{
377+
pfree(ru);
378+
return true;
379+
}
380+
else
381+
disconnect_leader();
361382
}
362-
else
363-
disconnect_leader();
383+
TIMEOUT_LOOP_END(&timeout);
364384
}
365-
TIMEOUT_LOOP_END(&timeout);
366385

367386
pfree(ru);
368387
elog(WARNING, "failed to set raftable value after %d ms", timeout_elapsed_ms(&timeout));

0 commit comments

Comments
 (0)