r12391: use the new periodic schedule system for the pull replication too
authorStefan Metzmacher <metze@samba.org>
Tue, 20 Dec 2005 00:55:28 +0000 (00:55 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:47:34 +0000 (13:47 -0500)
metze

source/wrepl_server/config.mk
source/wrepl_server/wrepl_in_call.c
source/wrepl_server/wrepl_out_connection.c [deleted file]
source/wrepl_server/wrepl_out_pull.c [new file with mode: 0644]
source/wrepl_server/wrepl_periodic.c
source/wrepl_server/wrepl_server.h

index 53172864d504e89c59a249d067c3e1a8b6fe1fc6..dc9508dc5af70e67a108725e9d01e1d7bee7f889 100644 (file)
@@ -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
index d186152848f9f9b02b34ae67e9e7ce28bba5de31..23701541a82e4ae94d7bcda3a09efb54e85c2d5c 100644 (file)
@@ -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/source/wrepl_server/wrepl_out_connection.c b/source/wrepl_server/wrepl_out_connection.c
deleted file mode 100644 (file)
index 31a7230..0000000
+++ /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/source/wrepl_server/wrepl_out_pull.c b/source/wrepl_server/wrepl_out_pull.c
new file mode 100644 (file)
index 0000000..dc2605f
--- /dev/null
@@ -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;
+}
index 28c966879ae119f021975f6f6665bc692cbce28a..2cea3b8e7c3940c864a183bca5c07daf2ca2ae0e 100644 (file)
@@ -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);
 
index 3c283c1b6fe7fff4cd92c7720131d7f485cc2e99..56751b6f296d2b53613e73194f34e00f52c036b3 100644 (file)
@@ -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;