Enable compilation of the load balancer as a module

To compile the balancer as a slapd module, pass --enable-balancer=mod to ./configure
Use --enable-balancer(=yes) to compile as standalone server.
This commit is contained in:
Nadezhda Ivanova 2018-01-11 17:43:18 +02:00 committed by Ondřej Kuzník
parent 8bc7650a7c
commit 37cd5f21d5
8 changed files with 310 additions and 37 deletions

View file

@ -414,7 +414,8 @@ dnl ----------------------------------------------------------------
dnl BALANCER OPTIONS dnl BALANCER OPTIONS
AC_ARG_ENABLE(balanceroptions,[ AC_ARG_ENABLE(balanceroptions,[
LLOADD (Load Balancer Daemon) Options:]) LLOADD (Load Balancer Daemon) Options:])
OL_ARG_ENABLE(balancer,[ --enable-balancer enable building load balancer], auto)dnl OL_ARG_ENABLE(balancer, [AS_HELP_STRING([--enable-balancer], [enable load balancer])],
no, [no yes mod])
dnl ---------------------------------------------------------------- dnl ----------------------------------------------------------------
AC_ARG_ENABLE(xxliboptions,[ AC_ARG_ENABLE(xxliboptions,[
@ -445,13 +446,18 @@ if test $ol_enable_slapd = no ; then
eval "ol_enable_$i=no" eval "ol_enable_$i=no"
fi fi
done done
if test $ol_enable_balancer = mod ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-balancer=mod argument])
ol_enable_balancer=no
fi
else else
dnl If slapd enabled and loadable module support disabled dnl If slapd enabled and loadable module support disabled
dnl then require at least one built-in backend dnl then require at least one built-in backend
if test $ol_enable_modules = no; then if test $ol_enable_modules = no; then
for i in backends overlays $Backends $Overlays; do for i in backends overlays balancer $Backends $Overlays; do
eval "ol_tmp=\$ol_enable_$i" eval "ol_tmp=\$ol_enable_$i"
if test -n "$ol_tmp" && test "$ol_tmp" = mod ; then if test -n "$ol_tmp" && test "$ol_tmp" = mod ; then
AC_MSG_ERROR([--enable-$i=mod requires --enable-modules]) AC_MSG_ERROR([--enable-$i=mod requires --enable-modules])
@ -487,7 +493,7 @@ if test $ol_enable_modules = yes ; then
ol_enable_dynamic=yes ol_enable_dynamic=yes
fi fi
if test $ol_enable_balancer = yes ; then if test $ol_enable_balancer != no ; then
dnl Load Balancer was specifically enabled dnl Load Balancer was specifically enabled
if test $ol_with_threads = no ; then if test $ol_with_threads = no ; then
AC_MSG_ERROR([Load balancer requires threads]) AC_MSG_ERROR([Load balancer requires threads])
@ -524,6 +530,7 @@ CLIENT_LIBS=
SLAPD_LIBS= SLAPD_LIBS=
BALANCER_LIBS= BALANCER_LIBS=
BALANCER_INCLUDE=
BUILD_SLAPD=no BUILD_SLAPD=no
BUILD_BALANCER=no BUILD_BALANCER=no
@ -2967,8 +2974,14 @@ fi
if test "$ol_enable_balancer" != no \ if test "$ol_enable_balancer" != no \
-a "$ol_with_threads" != no \ -a "$ol_with_threads" != no \
-a "$have_libevent" = yes ; then -a "$have_libevent" = yes ; then
if test "$ol_enable_balancer" = mod; then
BALANCER_INCLUDE=Makefile.module
BUILD_BALANCER=mod
else
BALANCER_INCLUDE=Makefile.server
BUILD_BALANCER=yes BUILD_BALANCER=yes
fi fi
fi
if test "$ol_enable_slapi" != no ; then if test "$ol_enable_slapi" != no ; then
AC_DEFINE(ENABLE_SLAPI,1,[define to enable slapi library]) AC_DEFINE(ENABLE_SLAPI,1,[define to enable slapi library])
@ -3088,6 +3101,8 @@ AC_SUBST(SLAPD_SQL_INCLUDES)
AC_SUBST(WT_INCS) AC_SUBST(WT_INCS)
AC_SUBST(WT_LIBS) AC_SUBST(WT_LIBS)
AC_SUBST(BALANCER_INCLUDE)
dnl ---------------------------------------------------------------- dnl ----------------------------------------------------------------
dnl final help output dnl final help output
AC_ARG_WITH(xxinstall,[ AC_ARG_WITH(xxinstall,[
@ -3134,7 +3149,9 @@ AC_CONFIG_FILES([Makefile:build/top.mk:Makefile.in:build/dir.mk]
[servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk] [servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk]
[servers/slapd/slapi/Makefile:build/top.mk:servers/slapd/slapi/Makefile.in:build/lib.mk:build/lib-shared.mk] [servers/slapd/slapi/Makefile:build/top.mk:servers/slapd/slapi/Makefile.in:build/lib.mk:build/lib-shared.mk]
[servers/slapd/overlays/Makefile:build/top.mk:servers/slapd/overlays/Makefile.in:build/lib.mk] [servers/slapd/overlays/Makefile:build/top.mk:servers/slapd/overlays/Makefile.in:build/lib.mk]
[servers/lloadd/Makefile:build/top.mk:servers/lloadd/Makefile.in:build/srv.mk] [servers/lloadd/Makefile:build/top.mk:servers/lloadd/Makefile.in]
[servers/lloadd/Makefile.server:servers/lloadd/Makefile_server.in:build/srv.mk]
[servers/lloadd/Makefile.module:servers/lloadd/Makefile_module.in:build/mod.mk]
[tests/Makefile:build/top.mk:tests/Makefile.in:build/dir.mk] [tests/Makefile:build/top.mk:tests/Makefile.in:build/dir.mk]
[tests/run] [tests/run]
[tests/progs/Makefile:build/top.mk:tests/progs/Makefile.in:build/rules.mk]) [tests/progs/Makefile:build/top.mk:tests/progs/Makefile.in:build/rules.mk])

View file

@ -215,6 +215,41 @@ This allows one to specifically query the SLP DAs for LDAP servers holding the
.I production .I production
tree in case multiple trees are available. tree in case multiple trees are available.
.RE .RE
.SH RELATION TO SLAPD(8)
.B Lloadd
can be compiled as a
.B slapd
loadable module. In that case, it can be loaded as such:
.LP
.nf
.ft tt
moduleload path/to/lloadd.la lloadd.conf "listening URLs"
.ft
.fi
This enables
.B lloadd
to provide additional features through the host slapd process like access to
run-time statistics in
.B cn=monitor
and dynamic configuration from
.BR cn=config .
The listening sockets specified will be under direct control of
.B lloadd
and need to be different from the sockets slapd is configured to listen on.
Clients connecting to these are completely separate from regular LDAP clients
connecting to the usual
.B slapd
sockets -
.B lloadd
clients have no access to slapd databases, similarly,
.B slapd
client traffic does not propagate to the
.B lloadd
backend servers in any way.
.SH EXAMPLES .SH EXAMPLES
To start To start
.I lloadd .I lloadd
@ -237,9 +272,22 @@ on voluminous debugging which will be printed on standard error, type:
LIBEXECDIR/lloadd \-f /var/tmp/lloadd.conf \-d 255 LIBEXECDIR/lloadd \-f /var/tmp/lloadd.conf \-d 255
.ft .ft
.fi .fi
.LP
To start
.B lloadd
as a module inside a slapd process listening on ldap://:1389 and ldaps://,
put the following in your slapd.conf (or its equivalent in cn=config):
.LP
.nf
.ft tt
moduleload lloadd.la /var/tmp/lloadd.conf "ldap://:1389 ldaps://"
.ft
.fi
.SH "SEE ALSO" .SH "SEE ALSO"
.BR ldap (3), .BR ldap (3),
.BR lloadd.conf (5), .BR lloadd.conf (5),
.BR slapd-config (5),
.BR slapd-monitor (5),
.BR slapd (8). .BR slapd (8).
.LP .LP
"OpenLDAP Administrator's Guide" (http://www.OpenLDAP.org/doc/admin/) "OpenLDAP Administrator's Guide" (http://www.OpenLDAP.org/doc/admin/)

View file

@ -13,28 +13,21 @@
## top-level directory of the distribution or, alternatively, at ## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>. ## <http://www.OpenLDAP.org/license.html>.
PROGRAMS = lloadd
XPROGRAMS = slloadd
XSRCS = version.c XSRCS = version.c
NT_SRCS = nt_svc.c NT_SRCS = nt_svc.c
NT_OBJS = nt_svc.o ../../libraries/liblutil/slapdmsg.res NT_OBJS = nt_svc.o ../../libraries/liblutil/slapdmsg.res
SRCS = main.c globals.c backend.c bind.c config.c connection.c client.c \ SRCS = backend.c bind.c config.c connection.c client.c \
daemon.c ch_malloc.c init.c operation.c user.c sl_malloc.c \ daemon.c extended.c operation.c \
upstream.c value.c libevent_support.c extended.c \ upstream.c libevent_support.c \
$(@PLAT@_SRCS) $(@PLAT@_SRCS)
OBJS = $(patsubst %.c,%.o,$(SRCS)) $(@PLAT@_OBJS)
LDAP_INCDIR= ../../include -I$(srcdir) LDAP_INCDIR= ../../include -I$(srcdir) -I$(srcdir)/../slapd
LDAP_LIBDIR= ../../libraries LDAP_LIBDIR= ../../libraries
BUILD_OPT = "--enable-balancer"
BUILD_SRV = @BUILD_BALANCER@
all-local-srv: $(PROGRAMS)
# $(LTHREAD_LIBS) must be last! # $(LTHREAD_LIBS) must be last!
XLIBS = $(LLOADD_L) XLIBS = $(LLOADD_L)
@ -50,25 +43,6 @@ UNIX_OBJECTS = $(OBJS) version.o
LLOADD_DEPENDS = $(@PLAT@_DEPENDS) LLOADD_DEPENDS = $(@PLAT@_DEPENDS)
LLOADD_OBJECTS = $(@PLAT@_OBJECTS) LLOADD_OBJECTS = $(@PLAT@_OBJECTS)
lloadd: $(LLOADD_DEPENDS) version.o include @BALANCER_INCLUDE@
$(LTLINK) -o $@ $(OBJS) version.o $(LIBS)
slloadd: version.o
$(LTLINK) -static -o $@ $(OBJS) version.o $(LIBS)
version.c: Makefile
@-$(RM) $@
$(MKVERSION) -s -n Versionstr lloadd > $@
version.o: version.c $(OBJS) $(LLOADD_L)
install-local-srv: FORCE
-$(MKDIR) $(DESTDIR)$(libexecdir)
@-$(INSTALL) -m 700 -d $(DESTDIR)$(localstatedir)/openldap-lloadd
@( \
for prg in $(PROGRAMS); do \
$(LTINSTALL) $(INSTALLFLAGS) $(STRIP) -m 755 $$prg$(EXEEXT) \
$(DESTDIR)$(libexecdir); \
done \
)

View file

@ -0,0 +1,45 @@
# Makefile.in for Load Balancer
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2020 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
XSRCS = version.c
NT_SRCS = nt_svc.c
NT_OBJS = nt_svc.o ../../libraries/liblutil/slapdmsg.res
SRCS += module_init.c
OBJS = $(patsubst %.c,%.lo,$(SRCS)) $(@PLAT@_OBJS)
BUILD_OPT = "--enable-balancer=mod"
BUILD_MOD = @BUILD_BALANCER@
LIBBASE=lloadd
# $(LTHREAD_LIBS) must be last!
XLIBS = $(LLOADD_L)
XXLIBS = $(LLOADD_LIBS) $(SECURITY_LIBS) $(LUTIL_LIBS)
XXXLIBS = $(LTHREAD_LIBS)
NT_DEPENDS = slapd.exp
NT_OBJECTS = slapd.exp symdummy.o $(LLOADD_OBJS) version.o
UNIX_DEPENDS = version.o $(LLOADD_L)
UNIX_OBJECTS = $(OBJS) version.o
LLOADD_DEPENDS = $(@PLAT@_DEPENDS)
LLOADD_OBJECTS = $(@PLAT@_OBJECTS)
LINK_LIBS=$(LLOADD_LIBS)
MOD_DEFS = -DSLAPD_IMPORT -DBALANCER_MODULE

View file

@ -0,0 +1,69 @@
# Makefile.in for Load Balancer
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2020 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
PROGRAMS = lloadd
XPROGRAMS = slloadd
XSRCS = version.c
NT_SRCS = nt_svc.c
NT_OBJS = nt_svc.o ../../libraries/liblutil/slapdmsg.res
SRCS += main.c init.c value.c \
ch_malloc.c sl_malloc.c user.c
OBJS = $(patsubst %.c,%.o,$(SRCS)) $(@PLAT@_OBJS)
BUILD_OPT = "--enable-balancer"
BUILD_SRV = @BUILD_BALANCER@
all-local-srv: $(PROGRAMS)
# $(LTHREAD_LIBS) must be last!
XLIBS = $(LLOADD_L)
XXLIBS = $(LLOADD_LIBS) $(SECURITY_LIBS) $(LUTIL_LIBS)
XXXLIBS = $(LTHREAD_LIBS)
NT_DEPENDS = slapd.exp
NT_OBJECTS = slapd.exp symdummy.o $(LLOADD_OBJS) version.o
UNIX_DEPENDS = version.o $(LLOADD_L)
UNIX_OBJECTS = $(OBJS) version.o
LLOADD_DEPENDS = $(@PLAT@_DEPENDS)
LLOADD_OBJECTS = $(@PLAT@_OBJECTS)
lloadd: $(LLOADD_DEPENDS) version.o
$(LTLINK) -o $@ $(OBJS) version.o $(LIBS)
slloadd: version.o
$(LTLINK) -static -o $@ $(OBJS) version.o $(LIBS)
version.c: Makefile
@-$(RM) $@
$(MKVERSION) -s -n Versionstr lloadd > $@
version.o: version.c $(OBJS) $(LLOADD_L)
install-local-srv: FORCE
-$(MKDIR) $(DESTDIR)$(libexecdir)
@-$(INSTALL) -m 700 -d $(DESTDIR)$(localstatedir)/openldap-lloadd
@( \
for prg in $(PROGRAMS); do \
$(LTINSTALL) $(INSTALLFLAGS) $(STRIP) -m 755 $$prg$(EXEEXT) \
$(DESTDIR)$(libexecdir); \
done \
)

View file

@ -150,9 +150,13 @@ lload_libevent_init( void )
lload_libevent_cond_timedwait lload_libevent_cond_timedwait
}; };
#ifndef BALANCER_MODULE
/* only necessary if lload is a server, slapd already calls
* ldap_pvt_thread_initialize() */
if ( ldap_pvt_thread_initialize() ) { if ( ldap_pvt_thread_initialize() ) {
return -1; return -1;
} }
#endif
evthread_set_lock_callbacks( &cbs ); evthread_set_lock_callbacks( &cbs );
evthread_set_condition_callbacks( &cond_cbs ); evthread_set_condition_callbacks( &cond_cbs );

View file

@ -0,0 +1,110 @@
/* module_init.c - module initialization functions */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2020 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* Portions Copyright (c) 1995 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of Michigan at Ann Arbor. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include "../servers/slapd/slap.h"
#include "lload.h"
#include "lber_pvt.h"
#include "ldap_rq.h"
int
lload_start_daemon()
{
struct event_base *daemon_base = event_base_new();
int rc = 0, i;
if ( !daemon_base ) {
Debug( LDAP_DEBUG_ANY, "lload_start_daemon: "
"main event base allocation failed\n" );
rc = 1;
return rc;
}
rc = lloadd_daemon( daemon_base );
return rc;
}
/* from init.c */
int
lload_conn_pool_init()
{
int rc = 0;
ldap_pvt_thread_mutex_init( &backend_mutex );
ldap_pvt_thread_mutex_init( &clients_mutex );
lload_exop_init();
Debug( LDAP_DEBUG_TRACE, "lload_conn_pool_init: "
"mutexes initialized.\n" );
return rc;
}
void *
lload_module_start_daemon( void *ctx, void *arg )
{
lload_start_daemon();
return NULL;
}
int
init_module( int argc, char *argv[] )
{
if ( slapMode & SLAP_TOOL_MODE ) {
return 0;
}
if ( lload_libevent_init() ) {
return -1;
}
global_host = ldap_pvt_get_fqdn( NULL );
#ifdef HAVE_TLS
if ( ldap_create( &lload_tls_backend_ld ) ) {
return -1;
}
#endif /* HAVE_TLS */
if ( lloadd_daemon_init( argv[1] ) != 0 ) {
return -1;
}
lload_conn_pool_init();
if ( lload_read_config( argv[0], NULL ) != 0 ) {
return -1;
}
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
ldap_pvt_runqueue_insert( &slapd_rq, 0, lload_module_start_daemon, NULL,
"lload_module_start_daemon", "lloadd" );
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
return 0;
}

View file

@ -18,6 +18,7 @@ SUBDIRS= progs
BUILD_MDB=@BUILD_MDB@ BUILD_MDB=@BUILD_MDB@
BUILD_SQL=@BUILD_SQL@ BUILD_SQL=@BUILD_SQL@
BUILD_SLAPD=@BUILD_SLAPD@
BUILD_BALANCER=@BUILD_BALANCER@ BUILD_BALANCER=@BUILD_BALANCER@
# test primary backends (default) # test primary backends (default)
@ -54,7 +55,12 @@ lloadd test-lloadd: lloadd-$(BUILD_BALANCER)
lloadd-no: lloadd-no:
@echo "run configure with --enable-balancer to run the Load Balancer tests" @echo "run configure with --enable-balancer to run the Load Balancer tests"
lloadd-yes: FORCE lloadd-yes: lloadd-slapd-$(BUILD_SLAPD)
lloadd-slapd-no:
@echo "run configure with --enable-slapd to run the Load Balancer tests"
lloadd-slapd-yes: FORCE
@echo "Initiating LDAP tests for the Load Balancer..." @echo "Initiating LDAP tests for the Load Balancer..."
@$(RUN) lloadd-all @$(RUN) lloadd-all