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

Commit b84a9f5

Browse files
committed
Rounding up timespec_diff_millis to avoid polling.
Previously diff was rounded down, so we were woken up some nanoseconds ( <= million) before actual wake time and polled continiously until they passed, with calculated diff in milliseconds 0. Besided, some typos fixed.
1 parent 79e37a9 commit b84a9f5

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

postgresql.conf.lord.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ shardman.shardlord = on # this instance is shardlord?
22
shardman.shardlord_dbname = ars # shardlord's dbname
33
shardman.shardlord_connstring = 'port=5432' # shardlord's connstring
44
shardman.cmd_retry_naptime = 500 # sleep milliseconds after failure
5-
shardman.poll_interval = 500 # long operations poll frequency
5+
shardman.poll_interval = 500 # long operations poll frequency in milliseconds

src/copypart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ exec_tasks(CopyPartState **tasks, int ntasks)
465465
switch (cps->exec_res)
466466
{
467467
case TASK_WAKEMEUP:
468-
/* We need to wake this task again, to keep it in
468+
/* We need to wake this task again, so keep it in
469469
* in the list and just continue */
470470
continue;
471471

@@ -523,7 +523,7 @@ calc_timeout(slist_head *timeout_states)
523523
CopyPartState *cps = cps_node->cps;
524524

525525
/* If waketm is not set, what this node does in this list? */
526-
Assert(cps->waketm.tv_nsec != 0);
526+
Assert(!(cps->waketm.tv_sec == 0 && cps->waketm.tv_nsec == 0));
527527
if (!waketm_set || timespeccmp(cps->waketm, waketm) < 0)
528528
{
529529
shmn_elog(DEBUG5, "Waketm updated, old %d s, new %d s",
@@ -599,7 +599,7 @@ exec_task(CopyPartState *cps)
599599
}
600600

601601
/*
602-
* One iteration of move primary task execution.
602+
* One iteration of move partition task execution.
603603
*
604604
* Maximum 4 nodes are actively involved here: src, dst, previous replica (or
605605
* primary) and next replica. The whole task workflow:

src/timeutils.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ timespec_add_millis(struct timespec t, long millis)
4242
}
4343

4444
/*
45-
* Get t1 - t2 difference in milliseconds. Not reliable if time_t is unsigned
45+
* Get t1 - t2 difference in milliseconds. Not reliable if time_t is unsigned.
46+
* The result is rounded up.
4647
*/
4748
int
4849
timespec_diff_millis(struct timespec t1, struct timespec t2)
4950
{
5051
int sec_diff = t1.tv_sec - t2.tv_sec;
5152
long nsec_diff = t1.tv_nsec - t2.tv_nsec;
52-
return sec_diff * 1000 + nsec_diff / MILLION;
53+
/* We add (MILLION - 1) to get the division result rounded up */
54+
return sec_diff * 1000 + (nsec_diff + (MILLION - 1)) / MILLION;
5355
}

0 commit comments

Comments
 (0)