diff options
author | Michal Zidek <mzidek@redhat.com> | 2014-07-07 16:46:18 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-07-31 11:50:24 +0200 |
commit | ab0ab5a30379b84d6e05e1f2dc457bd1dd97401f (patch) | |
tree | 53664c5eaa90baeef167a097f9522fa84abce548 | |
parent | b47449d8596d9573ff13e74b6984d080b414715a (diff) | |
download | sssd-ab0ab5a30379b84d6e05e1f2dc457bd1dd97401f.tar.gz sssd-ab0ab5a30379b84d6e05e1f2dc457bd1dd97401f.tar.xz sssd-ab0ab5a30379b84d6e05e1f2dc457bd1dd97401f.zip |
ptask: Allow adding random_offset to scheduled execution time
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
-rw-r--r-- | src/providers/data_provider_be.c | 2 | ||||
-rw-r--r-- | src/providers/dp_ptask.c | 12 | ||||
-rw-r--r-- | src/providers/dp_ptask.h | 5 | ||||
-rw-r--r-- | src/providers/ldap/ldap_id_cleanup.c | 7 | ||||
-rw-r--r-- | src/providers/ldap/ldap_id_enum.c | 1 |
5 files changed, 22 insertions, 5 deletions
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c index faa9f7ae9..a01bb066a 100644 --- a/src/providers/data_provider_be.c +++ b/src/providers/data_provider_be.c @@ -2580,7 +2580,7 @@ int be_process_init(TALLOC_CTX *mem_ctx, if (ctx->domain->refresh_expired_interval > 0) { ret = be_ptask_create(ctx, ctx, ctx->domain->refresh_expired_interval, - 30, 5, ctx->domain->refresh_expired_interval, + 30, 5, 0, ctx->domain->refresh_expired_interval, BE_PTASK_OFFLINE_SKIP, be_refresh_send, be_refresh_recv, ctx->refresh_ctx, "Refresh Records", NULL); diff --git a/src/providers/dp_ptask.c b/src/providers/dp_ptask.c index 8214112a0..4d0fec445 100644 --- a/src/providers/dp_ptask.c +++ b/src/providers/dp_ptask.c @@ -37,6 +37,8 @@ struct be_ptask { struct be_ctx *be_ctx; time_t period; time_t enabled_delay; + time_t random_offset; + unsigned int ro_seed; time_t timeout; enum be_ptask_offline offline; be_ptask_send_t send_fn; @@ -208,6 +210,10 @@ static void be_ptask_schedule(struct be_ptask *task, return; } + if (task->random_offset != 0) { + delay = delay + (rand_r(&task->ro_seed) % task->random_offset); + } + switch (from) { case BE_PTASK_SCHEDULE_FROM_NOW: tv = tevent_timeval_current_ofs(delay, 0); @@ -244,6 +250,7 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx, time_t period, time_t first_delay, time_t enabled_delay, + time_t random_offset, time_t timeout, enum be_ptask_offline offline, be_ptask_send_t send_fn, @@ -270,6 +277,8 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx, task->be_ctx = be_ctx; task->period = period; task->enabled_delay = enabled_delay; + task->random_offset = random_offset; + task->ro_seed = time(NULL) * getpid(); task->timeout = timeout; task->offline = offline; task->send_fn = send_fn; @@ -406,6 +415,7 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx, time_t period, time_t first_delay, time_t enabled_delay, + time_t random_offset, time_t timeout, enum be_ptask_offline offline, be_ptask_sync_t fn, @@ -426,7 +436,7 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx, ctx->pvt = pvt; ret = be_ptask_create(mem_ctx, be_ctx, period, first_delay, - enabled_delay, timeout, offline, + enabled_delay, random_offset, timeout, offline, be_ptask_sync_send, be_ptask_sync_recv, ctx, name, _task); if (ret != EOK) { diff --git a/src/providers/dp_ptask.h b/src/providers/dp_ptask.h index 11324db74..0f9873804 100644 --- a/src/providers/dp_ptask.h +++ b/src/providers/dp_ptask.h @@ -81,6 +81,9 @@ typedef errno_t * If the task is reenabled, it will be scheduled again to * 'now + enabled_delay'. * + * The random_offset is maximum number of seconds added to the + * expected delay. Set to 0 if no randomization is needed. + * * If an internal error occurred, the task is automatically disabled. */ errno_t be_ptask_create(TALLOC_CTX *mem_ctx, @@ -88,6 +91,7 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx, time_t period, time_t first_delay, time_t enabled_delay, + time_t random_offset, time_t timeout, enum be_ptask_offline offline, be_ptask_send_t send_fn, @@ -101,6 +105,7 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx, time_t period, time_t first_delay, time_t enabled_delay, + time_t random_offset, time_t timeout, enum be_ptask_offline offline, be_ptask_sync_t fn, diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c index 6b0bead28..0c473da30 100644 --- a/src/providers/ldap/ldap_id_cleanup.c +++ b/src/providers/ldap/ldap_id_cleanup.c @@ -86,9 +86,10 @@ errno_t ldap_setup_cleanup(struct sdap_id_ctx *id_ctx, } ret = be_ptask_create_sync(sdom, id_ctx->be, period, first_delay, - 5 /* enabled delay */, period /* timeout */, - BE_PTASK_OFFLINE_SKIP, ldap_cleanup_task, - cleanup_ctx, name, &sdom->cleanup_task); + 5 /* enabled delay */, 0 /* random offset */, + period /* timeout */, BE_PTASK_OFFLINE_SKIP, + ldap_cleanup_task, cleanup_ctx, name, + &sdom->cleanup_task); if (ret != EOK) { DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize cleanup periodic " "task for %s\n", sdom->dom->name); diff --git a/src/providers/ldap/ldap_id_enum.c b/src/providers/ldap/ldap_id_enum.c index 62db1c11c..25ee5f68b 100644 --- a/src/providers/ldap/ldap_id_enum.c +++ b/src/providers/ldap/ldap_id_enum.c @@ -74,6 +74,7 @@ errno_t ldap_setup_enumeration(struct be_ctx *be_ctx, period, /* period */ first_delay, /* first_delay */ 5, /* enabled delay */ + 0, /* random offset */ period, /* timeout */ BE_PTASK_OFFLINE_SKIP, send_fn, recv_fn, |