summaryrefslogtreecommitdiff
path: root/source4/wrepl_server
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-12-20 00:55:28 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:47:34 -0500
commitadb30c5b2f91ae4918750beb8c4df1aa2c194c9d (patch)
treeae1792bf27b0d2122721b5abf0be5023ae3e980c /source4/wrepl_server
parent28411a5c04daadc7141cc200bb6d388036889b38 (diff)
downloadsamba-adb30c5b2f91ae4918750beb8c4df1aa2c194c9d.tar.gz
samba-adb30c5b2f91ae4918750beb8c4df1aa2c194c9d.tar.bz2
samba-adb30c5b2f91ae4918750beb8c4df1aa2c194c9d.zip
r12391: use the new periodic schedule system for the pull replication too
metze (This used to be commit 3383568c31545a6716eb7045b56d516d507c0b4d)
Diffstat (limited to 'source4/wrepl_server')
-rw-r--r--source4/wrepl_server/config.mk6
-rw-r--r--source4/wrepl_server/wrepl_in_call.c4
-rw-r--r--source4/wrepl_server/wrepl_out_connection.c174
-rw-r--r--source4/wrepl_server/wrepl_out_pull.c153
-rw-r--r--source4/wrepl_server/wrepl_periodic.c12
-rw-r--r--source4/wrepl_server/wrepl_server.h3
6 files changed, 164 insertions, 188 deletions
diff --git a/source4/wrepl_server/config.mk b/source4/wrepl_server/config.mk
index 53172864d5..dc9508dc5a 100644
--- a/source4/wrepl_server/config.mk
+++ b/source4/wrepl_server/config.mk
@@ -7,11 +7,11 @@ INIT_OBJ_FILES = \
wrepl_server.o \
wrepl_in_connection.o \
wrepl_in_call.o \
- wrepl_out_connection.o \
- wrepl_out_helpers.o \
wrepl_apply_records.o \
wrepl_periodic.o \
- wrepl_out_push.o
+ wrepl_out_pull.o \
+ wrepl_out_push.o \
+ wrepl_out_helpers.o
REQUIRED_SUBSYSTEMS = \
LIBCLI_WREPL WINSDB
# End SUBSYSTEM WREPL_SRV
diff --git a/source4/wrepl_server/wrepl_in_call.c b/source4/wrepl_server/wrepl_in_call.c
index d186152848..23701541a8 100644
--- a/source4/wrepl_server/wrepl_in_call.c
+++ b/source4/wrepl_server/wrepl_in_call.c
@@ -373,14 +373,12 @@ static NTSTATUS wreplsrv_in_update2(struct wreplsrv_in_call *call)
static NTSTATUS wreplsrv_in_inform(struct wreplsrv_in_call *call)
{
struct wrepl_table *inform_in = &call->req_packet.message.replication.info.table;
- NTSTATUS status;
DEBUG(2,("WREPL_REPL_INFORM: partner[%s] initiator[%s] num_owners[%u]\n",
call->wreplconn->partner->address,
inform_in->initiator, inform_in->partner_count));
- status = wreplsrv_sched_inform_action(call->wreplconn->partner, inform_in);
- NT_STATUS_NOT_OK_RETURN(status);
+ wreplsrv_out_partner_pull(call->wreplconn->partner, inform_in);
/* we don't reply to WREPL_REPL_INFORM messages */
return ERROR_INVALID_PARAMETER;
diff --git a/source4/wrepl_server/wrepl_out_connection.c b/source4/wrepl_server/wrepl_out_connection.c
deleted file mode 100644
index 31a72307d7..0000000000
--- a/source4/wrepl_server/wrepl_out_connection.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- WINS Replication server
-
- Copyright (C) Stefan Metzmacher 2005
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-#include "dlinklist.h"
-#include "lib/events/events.h"
-#include "lib/socket/socket.h"
-#include "smbd/service_task.h"
-#include "smbd/service_stream.h"
-#include "lib/messaging/irpc.h"
-#include "librpc/gen_ndr/ndr_winsrepl.h"
-#include "wrepl_server/wrepl_server.h"
-#include "nbt_server/wins/winsdb.h"
-#include "ldb/include/ldb.h"
-#include "libcli/composite/composite.h"
-#include "libcli/wrepl/winsrepl.h"
-#include "wrepl_server/wrepl_out_helpers.h"
-
-static void wreplsrv_pull_handler_te(struct event_context *ev, struct timed_event *te,
- struct timeval t, void *ptr);
-
-static void wreplsrv_pull_handler_creq(struct composite_context *creq)
-{
- struct wreplsrv_partner *partner = talloc_get_type(creq->async.private_data, struct wreplsrv_partner);
- uint32_t interval;
-
- partner->pull.last_status = wreplsrv_pull_cycle_recv(partner->pull.creq);
- partner->pull.creq = NULL;
- talloc_free(partner->pull.cycle_io);
- partner->pull.cycle_io = NULL;
-
- if (!NT_STATUS_IS_OK(partner->pull.last_status)) {
- interval = partner->pull.error_count * partner->pull.retry_interval;
- interval = MIN(interval, partner->pull.interval);
- partner->pull.error_count++;
-
- DEBUG(1,("wreplsrv_pull_cycle(%s): %s: next: %us\n",
- partner->address, nt_errstr(partner->pull.last_status),
- interval));
- } else {
- interval = partner->pull.interval;
- partner->pull.error_count = 0;
-
- DEBUG(2,("wreplsrv_pull_cycle(%s): %s: next: %us\n",
- partner->address, nt_errstr(partner->pull.last_status),
- interval));
- }
-
- partner->pull.te = event_add_timed(partner->service->task->event_ctx, partner,
- timeval_current_ofs(interval, 0),
- wreplsrv_pull_handler_te, partner);
- if (!partner->pull.te) {
- DEBUG(0,("wreplsrv_pull_handler_creq: event_add_timed() failed! no memory!\n"));
- }
-}
-
-static void wreplsrv_pull_handler_te(struct event_context *ev, struct timed_event *te,
- struct timeval t, void *ptr)
-{
- struct wreplsrv_partner *partner = talloc_get_type(ptr, struct wreplsrv_partner);
-
- partner->pull.te = NULL;
-
- partner->pull.cycle_io = talloc(partner, struct wreplsrv_pull_cycle_io);
- if (!partner->pull.cycle_io) {
- goto requeue;
- }
-
- partner->pull.cycle_io->in.partner = partner;
- partner->pull.cycle_io->in.num_owners = 0;
- partner->pull.cycle_io->in.owners = NULL;
- partner->pull.cycle_io->in.wreplconn = NULL;
- partner->pull.creq = wreplsrv_pull_cycle_send(partner->pull.cycle_io, partner->pull.cycle_io);
- if (!partner->pull.creq) {
- DEBUG(1,("wreplsrv_pull_cycle_send(%s) failed\n",
- partner->address));
- goto requeue;
- }
-
- partner->pull.creq->async.fn = wreplsrv_pull_handler_creq;
- partner->pull.creq->async.private_data = partner;
-
- return;
-requeue:
- talloc_free(partner->pull.cycle_io);
- partner->pull.cycle_io = NULL;
- /* retry later */
- partner->pull.te = event_add_timed(partner->service->task->event_ctx, partner,
- timeval_add(&t, partner->pull.retry_interval, 0),
- wreplsrv_pull_handler_te, partner);
- if (!partner->pull.te) {
- DEBUG(0,("wreplsrv_pull_handler_te: event_add_timed() failed! no memory!\n"));
- }
-}
-
-NTSTATUS wreplsrv_sched_inform_action(struct wreplsrv_partner *partner, struct wrepl_table *inform_in)
-{
- if (partner->pull.creq) {
- /* there's already a pull in progress, so we're done */
- return NT_STATUS_OK;
- }
-
- /* remove the scheduled pull */
- talloc_free(partner->pull.te);
- partner->pull.te = NULL;
-
- partner->pull.cycle_io = talloc(partner, struct wreplsrv_pull_cycle_io);
- if (!partner->pull.cycle_io) {
- goto requeue;
- }
-
- partner->pull.cycle_io->in.partner = partner;
- partner->pull.cycle_io->in.num_owners = inform_in->partner_count;
- partner->pull.cycle_io->in.owners = inform_in->partners;
- talloc_steal(partner->pull.cycle_io, inform_in->partners);
- partner->pull.cycle_io->in.wreplconn = NULL;
- partner->pull.creq = wreplsrv_pull_cycle_send(partner->pull.cycle_io, partner->pull.cycle_io);
- if (!partner->pull.creq) {
- DEBUG(1,("wreplsrv_pull_cycle_send(%s) failed\n",
- partner->address));
- goto requeue;
- }
-
- partner->pull.creq->async.fn = wreplsrv_pull_handler_creq;
- partner->pull.creq->async.private_data = partner;
-
- return NT_STATUS_OK;
-requeue:
- talloc_free(partner->pull.cycle_io);
- partner->pull.cycle_io = NULL;
- /* retry later */
- partner->pull.te = event_add_timed(partner->service->task->event_ctx, partner,
- timeval_current_ofs(partner->pull.retry_interval, 0),
- wreplsrv_pull_handler_te, partner);
- if (!partner->pull.te) {
- DEBUG(0,("wreplsrv_pull_handler_te: event_add_timed() failed! no memory!\n"));
- }
-
- return NT_STATUS_OK;
-}
-
-NTSTATUS wreplsrv_setup_out_connections(struct wreplsrv_service *service)
-{
- struct wreplsrv_partner *cur;
-
- for (cur = service->partners; cur; cur = cur->next) {
- if ((cur->type & WINSREPL_PARTNER_PULL) && cur->pull.interval) {
- cur->pull.te = event_add_timed(service->task->event_ctx, cur,
- timeval_zero(), wreplsrv_pull_handler_te, cur);
- NT_STATUS_HAVE_NO_MEMORY(cur->pull.te);
- }
- }
-
- return NT_STATUS_OK;
-}
diff --git a/source4/wrepl_server/wrepl_out_pull.c b/source4/wrepl_server/wrepl_out_pull.c
new file mode 100644
index 0000000000..dc2605f11b
--- /dev/null
+++ b/source4/wrepl_server/wrepl_out_pull.c
@@ -0,0 +1,153 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ WINS Replication server
+
+ Copyright (C) Stefan Metzmacher 2005
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "dlinklist.h"
+#include "lib/events/events.h"
+#include "lib/socket/socket.h"
+#include "smbd/service_task.h"
+#include "smbd/service_stream.h"
+#include "lib/messaging/irpc.h"
+#include "librpc/gen_ndr/ndr_winsrepl.h"
+#include "wrepl_server/wrepl_server.h"
+#include "nbt_server/wins/winsdb.h"
+#include "ldb/include/ldb.h"
+#include "libcli/composite/composite.h"
+#include "libcli/wrepl/winsrepl.h"
+#include "wrepl_server/wrepl_out_helpers.h"
+
+static void wreplsrv_out_pull_reschedule(struct wreplsrv_partner *partner, uint32_t interval)
+{
+ NTSTATUS status;
+
+ partner->pull.next_run = timeval_current_ofs(interval, 0);
+ status = wreplsrv_periodic_schedule(partner->service, interval);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("wreplsrv_periodic_schedule() failed\n"));
+ }
+}
+
+static void wreplsrv_pull_handler_creq(struct composite_context *creq)
+{
+ struct wreplsrv_partner *partner = talloc_get_type(creq->async.private_data, struct wreplsrv_partner);
+ struct wreplsrv_pull_cycle_io *old_cycle_io;
+ struct wrepl_table inform_in;
+
+ partner->pull.last_status = wreplsrv_pull_cycle_recv(partner->pull.creq);
+ partner->pull.creq = NULL;
+
+ old_cycle_io = partner->pull.cycle_io;
+ partner->pull.cycle_io = NULL;
+
+ if (NT_STATUS_IS_OK(partner->pull.last_status)) {
+ partner->pull.error_count = 0;
+ DEBUG(2,("wreplsrv_pull_cycle(%s): %s\n",
+ partner->address, nt_errstr(partner->pull.last_status)));
+ goto done;
+ }
+
+ partner->pull.error_count++;
+
+ if (partner->pull.error_count > 1) {
+ uint32_t retry_interval;
+
+ retry_interval = partner->pull.error_count * partner->pull.retry_interval;
+ retry_interval = MIN(retry_interval, partner->pull.interval);
+
+ DEBUG(1,("wreplsrv_pull_cycle(%s): %s: error_count: %u: reschedule(%u)\n",
+ partner->address, nt_errstr(partner->pull.last_status),
+ partner->pull.error_count, retry_interval));
+
+ wreplsrv_out_pull_reschedule(partner, retry_interval);
+ goto done;
+ }
+
+ DEBUG(1,("wreplsrv_pull_cycle(%s): %s: error_count:%u retry\n",
+ partner->address, nt_errstr(partner->pull.last_status),
+ partner->pull.error_count));
+ inform_in.partner_count = old_cycle_io->in.num_owners;
+ inform_in.partners = old_cycle_io->in.owners;
+ wreplsrv_out_partner_pull(partner, &inform_in);
+done:
+ talloc_free(old_cycle_io);
+}
+
+void wreplsrv_out_partner_pull(struct wreplsrv_partner *partner, struct wrepl_table *inform_in)
+{
+ /* there's already a pull in progress, so we're done */
+ if (partner->pull.creq) return;
+
+ partner->pull.cycle_io = talloc(partner, struct wreplsrv_pull_cycle_io);
+ if (!partner->pull.cycle_io) {
+ goto nomem;
+ }
+
+ partner->pull.cycle_io->in.partner = partner;
+ partner->pull.cycle_io->in.wreplconn = NULL;
+ if (inform_in) {
+ partner->pull.cycle_io->in.num_owners = inform_in->partner_count;
+ partner->pull.cycle_io->in.owners = inform_in->partners;
+ talloc_steal(partner->pull.cycle_io, inform_in->partners);
+ } else {
+ partner->pull.cycle_io->in.num_owners = 0;
+ partner->pull.cycle_io->in.owners = NULL;
+ }
+ partner->pull.creq = wreplsrv_pull_cycle_send(partner->pull.cycle_io, partner->pull.cycle_io);
+ if (!partner->pull.creq) {
+ DEBUG(1,("wreplsrv_pull_cycle_send(%s) failed\n",
+ partner->address));
+ goto nomem;
+ }
+
+ partner->pull.creq->async.fn = wreplsrv_pull_handler_creq;
+ partner->pull.creq->async.private_data = partner;
+
+ return;
+nomem:
+ talloc_free(partner->pull.cycle_io);
+ partner->pull.cycle_io = NULL;
+ DEBUG(0,("wreplsrv_out_partner_pull(%s): no memory? (ignoring)\n",
+ partner->address));
+ return;
+}
+
+NTSTATUS wreplsrv_out_pull_run(struct wreplsrv_service *service)
+{
+ struct wreplsrv_partner *partner;
+
+ for (partner = service->partners; partner; partner = partner->next) {
+ /* if it's not a pull partner, go to the next partner */
+ if (!(partner->type & WINSREPL_PARTNER_PULL)) continue;
+
+ /* if pulling is disabled for the partner, go to the next one */
+ if (partner->pull.interval == 0) continue;
+
+ /* if the next timer isn't reached, go to the next partner */
+ if (!timeval_expired(&partner->pull.next_run)) continue;
+
+ wreplsrv_out_pull_reschedule(partner, partner->pull.interval);
+
+ wreplsrv_out_partner_pull(partner, NULL);
+ }
+
+ return NT_STATUS_OK;
+}
diff --git a/source4/wrepl_server/wrepl_periodic.c b/source4/wrepl_server/wrepl_periodic.c
index 28c966879a..2cea3b8e7c 100644
--- a/source4/wrepl_server/wrepl_periodic.c
+++ b/source4/wrepl_server/wrepl_periodic.c
@@ -39,6 +39,9 @@ static NTSTATUS wreplsrv_periodic_run(struct wreplsrv_service *service)
{
NTSTATUS status;
+ status = wreplsrv_out_pull_run(service);
+ NT_STATUS_NOT_OK_RETURN(status);
+
status = wreplsrv_out_push_run(service);
NT_STATUS_NOT_OK_RETURN(status);
@@ -74,7 +77,7 @@ NTSTATUS wreplsrv_periodic_schedule(struct wreplsrv_service *service, uint32_t n
/* prevent looping */
if (next_interval == 0) next_interval = 1;
- next_time = timeval_current_ofs(next_interval, 0);
+ next_time = timeval_current_ofs(next_interval, 5000);
if (service->periodic.te) {
/*
@@ -111,13 +114,6 @@ NTSTATUS wreplsrv_setup_periodic(struct wreplsrv_service *service)
{
NTSTATUS status;
- /*
- * TODO: this should go away, and we should do everything
- * within the wreplsrv_periodic_run()
- */
- status = wreplsrv_setup_out_connections(service);
- NT_STATUS_NOT_OK_RETURN(status);
-
status = wreplsrv_periodic_schedule(service, 0);
NT_STATUS_NOT_OK_RETURN(status);
diff --git a/source4/wrepl_server/wrepl_server.h b/source4/wrepl_server/wrepl_server.h
index 3c283c1b6f..56751b6f29 100644
--- a/source4/wrepl_server/wrepl_server.h
+++ b/source4/wrepl_server/wrepl_server.h
@@ -148,6 +148,9 @@ struct wreplsrv_partner {
/* the status of the last pull cycle */
NTSTATUS last_status;
+ /* the timestamp of the next pull try */
+ struct timeval next_run;
+
/* this is a list of each wins_owner the partner knows about */
struct wreplsrv_owner *table;