>From 91c0a69ed570716e314ce973c5f678889330fd2d Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Fri, 25 Jan 2013 01:02:41 -0800 Subject: [PATCH] dsdb-drepl: create a new schedulable task for running pending operations So instead of running dreplsrv_periodic_schedule when receiving a DRS_REPLICA_SYNC request which will force the DC to look for changes with all the DC it usually replicate to, we reduce it to the DC specified in the DRS_REPLICA_SYNC request. It will allow also to do have the correct options as set by the client who send the DRS_REPLICA_SYNC. Signed-off-by: Matthieu Patou --- source4/dsdb/repl/drepl_pending.c | 98 +++++++++++++++++++++++++++++++++++++ source4/dsdb/repl/drepl_service.c | 2 +- source4/dsdb/repl/drepl_service.h | 17 +++++++ source4/dsdb/wscript_build | 2 +- 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 source4/dsdb/repl/drepl_pending.c diff --git a/source4/dsdb/repl/drepl_pending.c b/source4/dsdb/repl/drepl_pending.c new file mode 100644 index 0000000..930c130 --- /dev/null +++ b/source4/dsdb/repl/drepl_pending.c @@ -0,0 +1,98 @@ +/* + Unix SMB/CIFS mplementation. + + DSDB replication service pending operations scheduling + + Copyright (C) Matthieu Patou 2013 + based on drepl_periodic + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "dsdb/samdb/samdb.h" +#include "auth/auth.h" +#include "smbd/service.h" +#include "dsdb/repl/drepl_service.h" +#include +#include "../lib/util/dlinklist.h" +#include "librpc/gen_ndr/ndr_misc.h" +#include "librpc/gen_ndr/ndr_drsuapi.h" +#include "librpc/gen_ndr/ndr_drsblobs.h" +#include "libcli/composite/composite.h" +#include "../lib/util/tevent_ntstatus.h" + + +static void dreplsrv_pending_run(struct dreplsrv_service *service); + +static void dreplsrv_pending_handler_te(struct tevent_context *ev, struct tevent_timer *te, + struct timeval t, void *ptr) +{ + struct dreplsrv_service *service = talloc_get_type(ptr, struct dreplsrv_service); + + service->pending.te = NULL; + + dreplsrv_pending_run(service); +} + +WERROR dreplsrv_pendingops_schedule(struct dreplsrv_service *service, uint32_t next_interval) +{ + TALLOC_CTX *tmp_mem; + struct tevent_timer *new_te; + struct timeval next_time; + + /* prevent looping */ + if (next_interval == 0) { + next_interval = 1; + } + + next_time = timeval_current_ofs(next_interval, 50); + + if (service->pending.te) { + /* + * if the timestamp of the new event is higher, + * as current next we don't need to reschedule + */ + if (timeval_compare(&next_time, &service->pending.next_event) > 0) { + return WERR_OK; + } + } + + /* reset the next scheduled timestamp */ + service->pending.next_event = next_time; + + new_te = tevent_add_timer(service->task->event_ctx, service, + service->pending.next_event, + dreplsrv_pending_handler_te, service); + W_ERROR_HAVE_NO_MEMORY(new_te); + + tmp_mem = talloc_new(service); + DEBUG(0,("dreplsrv_pending_schedule(%u) %sscheduled for: %s\n", + next_interval, + (service->pending.te?"re":""), + nt_time_string(tmp_mem, timeval_to_nttime(&next_time)))); + talloc_free(tmp_mem); + + talloc_free(service->pending.te); + service->pending.te = new_te; + + return WERR_OK; +} + +static void dreplsrv_pending_run(struct dreplsrv_service *service) +{ + dreplsrv_run_pending_ops(service); +} diff --git a/source4/dsdb/repl/drepl_service.c b/source4/dsdb/repl/drepl_service.c index 3d28676..bd33377 100644 --- a/source4/dsdb/repl/drepl_service.c +++ b/source4/dsdb/repl/drepl_service.c @@ -338,7 +338,7 @@ static NTSTATUS drepl_replica_sync(struct irpc_message *msg, * schedule replication event to force * replication as soon as possible */ - dreplsrv_periodic_schedule(service, 0); + dreplsrv_pendingops_schedule(service, 0); done: return NT_STATUS_OK; diff --git a/source4/dsdb/repl/drepl_service.h b/source4/dsdb/repl/drepl_service.h index 6daf82d..edba4c4 100644 --- a/source4/dsdb/repl/drepl_service.h +++ b/source4/dsdb/repl/drepl_service.h @@ -187,6 +187,23 @@ struct dreplsrv_service { struct tevent_timer *te; } periodic; + /* some stuff for running only the pendings ops */ + struct { + /* + * the interval between notify runs + */ + uint32_t interval; + + /* + * the timestamp for the next event, + * this is the timstamp passed to event_add_timed() + */ + struct timeval next_event; + + /* here we have a reference to the timed event the schedules the notifies */ + struct tevent_timer *te; + } pending; + /* some stuff for notify processing */ struct { /* diff --git a/source4/dsdb/wscript_build b/source4/dsdb/wscript_build index a80c45c..b1dff0f 100755 --- a/source4/dsdb/wscript_build +++ b/source4/dsdb/wscript_build @@ -28,7 +28,7 @@ bld.SAMBA_SUBSYSTEM('SAMDB_SCHEMA', bld.SAMBA_MODULE('service_drepl', - source='repl/drepl_service.c repl/drepl_periodic.c repl/drepl_partitions.c repl/drepl_out_pull.c repl/drepl_out_helpers.c repl/drepl_notify.c repl/drepl_ridalloc.c repl/drepl_extended.c repl/drepl_fsmo.c repl/drepl_secret.c repl/drepl_replica.c', + source='repl/drepl_service.c repl/drepl_periodic.c repl/drepl_partitions.c repl/drepl_out_pull.c repl/drepl_out_helpers.c repl/drepl_notify.c repl/drepl_ridalloc.c repl/drepl_extended.c repl/drepl_fsmo.c repl/drepl_secret.c repl/drepl_replica.c repl/drepl_pending.c', autoproto='repl/drepl_service_proto.h', subsystem='service', init_function='server_service_drepl_init', -- 1.7.9.5