server upgrade hangs or do not upgrade the database

Resolves: #664433
This commit is contained in:
Jan Vcelak 2011-03-18 21:14:22 +01:00
parent 86c082e423
commit 1db8d2e348
3 changed files with 105 additions and 21 deletions

View File

@ -0,0 +1,61 @@
fix: openldap-servers upgrade hangs
Resolves: #664433
Upstream ITS: #6853
--- openldap-2.4.24.orig/servers/slapd/back-bdb/tools.c
+++ openldap-2.4.24/servers/slapd/back-bdb/tools.c
@@ -90,8 +90,10 @@
#ifdef USE_TRICKLE
static ldap_pvt_thread_mutex_t bdb_tool_trickle_mutex;
static ldap_pvt_thread_cond_t bdb_tool_trickle_cond;
+static ldap_pvt_thread_cond_t bdb_tool_trickle_cond_end;
static void * bdb_tool_trickle_task( void *ctx, void *ptr );
+static int bdb_tool_trickle_active;
#endif
static void * bdb_tool_index_task( void *ctx, void *ptr );
@@ -127,6 +129,7 @@
#ifdef USE_TRICKLE
ldap_pvt_thread_mutex_init( &bdb_tool_trickle_mutex );
ldap_pvt_thread_cond_init( &bdb_tool_trickle_cond );
+ ldap_pvt_thread_cond_init( &bdb_tool_trickle_cond_end );
ldap_pvt_thread_pool_submit( &connection_pool, bdb_tool_trickle_task, bdb->bi_dbenv );
#endif
@@ -159,7 +162,16 @@
slapd_shutdown = 1;
#ifdef USE_TRICKLE
ldap_pvt_thread_mutex_lock( &bdb_tool_trickle_mutex );
+
+ /* trickle thread may not have started yet */
+ while ( !bdb_tool_trickle_active )
+ ldap_pvt_thread_cond_wait( &bdb_tool_trickle_cond_end,
+ &bdb_tool_trickle_mutex );
+
ldap_pvt_thread_cond_signal( &bdb_tool_trickle_cond );
+ while ( bdb_tool_trickle_active )
+ ldap_pvt_thread_cond_wait( &bdb_tool_trickle_cond_end,
+ &bdb_tool_trickle_mutex );
ldap_pvt_thread_mutex_unlock( &bdb_tool_trickle_mutex );
#endif
ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
@@ -1249,6 +1261,8 @@
int wrote;
ldap_pvt_thread_mutex_lock( &bdb_tool_trickle_mutex );
+ bdb_tool_trickle_active = 1;
+ ldap_pvt_thread_cond_signal( &bdb_tool_trickle_cond_end );
while ( 1 ) {
ldap_pvt_thread_cond_wait( &bdb_tool_trickle_cond,
&bdb_tool_trickle_mutex );
@@ -1256,6 +1270,8 @@
break;
env->memp_trickle( env, 30, &wrote );
}
+ bdb_tool_trickle_active = 0;
+ ldap_pvt_thread_cond_signal( &bdb_tool_trickle_cond_end );
ldap_pvt_thread_mutex_unlock( &bdb_tool_trickle_mutex );
return NULL;

View File

@ -30,6 +30,7 @@ Patch7: openldap-ldaprc-currentdir.patch
Patch8: openldap-userconfig-setgid.patch
Patch9: openldap-nss-nofork.patch
Patch10: openldap-nss-null-pointer.patch
Patch11: openldap-slapadd-hang.patch
# patches for the evolution library (see README.evolution)
Patch200: openldap-evolution-ntlm.patch
@ -132,6 +133,7 @@ pushd openldap-%{version}
%patch8 -p1 -b .userconfig-setgid
%patch9 -p1 -b .nss-nofork
%patch10 -p1 -b .nss-null-pointer
%patch11 -p1 -b .slapadd-hang
cp %{_datadir}/libtool/config/config.{sub,guess} build/
@ -407,30 +409,50 @@ if [ $1 -eq 2 ]; then
fi
if ls *.bdb &>/dev/null; then
# symlink to last backup
rm -f upgrade.ldif
# backup location
backupdir=backup.$(date +%%s)
backupfile=${backupdir}/backup.ldif
backupcmd="cp -a"
mkdir -p ${backupdir}
# database recovery tool
# (this is necessary to handle upgrade from old openldap, which had embedded db4)
if [ -f /usr/sbin/slapd_db_recover ]; then
db_recover=/usr/sbin/slapd_db_recover
else
db_recover=/usr/bin/db_recover
fi
# make sure the database is consistent
runuser -m -s /usr/bin/db_recover -- "ldap" -h %{_sharedstatedir}/ldap &>/dev/null
runuser -m -s $db_recover -- "ldap" -h %{_sharedstatedir}/ldap &>/dev/null
# export the database
if [ -f %{_sysconfdir}/openldap/slapd.conf ]; then
slapcat -f %{_sysconfdir}/openldap/slapd.conf -l upgrade.ldif &>/dev/null
else
slapcat -F %{_sysconfdir}/openldap/slapd.d -l upgrade.ldif &>/dev/null
fi
# backup the old database
# export the database if possible
if [ $? -eq 0 ]; then
chown ldap:ldap upgrade.ldif
chmod 0400 upgrade.ldif
if [ -f %{_sysconfdir}/openldap/slapd.conf ]; then
slapcat -f %{_sysconfdir}/openldap/slapd.conf -l $backupfile &>/dev/null
else
slapcat -F %{_sysconfdir}/openldap/slapd.d -l $backupfile &>/dev/null
fi
rm -rf backup
mkdir -m 0700 backup
chown 0500 backup
mv alock *.bdb __db.* log.* backup &>/dev/null
cp -f backup/DB_CONFIG DB_CONFIG &>/dev/null
else
rm -f upgrade.ldif
if [ $? -eq 0 ]; then
chmod 0400 $backupfile
ln -sf $backupfile upgrade.ldif
backupcmd=mv
fi
fi
# move or copy to backup directory
find -maxdepth 1 -type f \( -name alock -o -name "*.bdb" -o -name "__db.*" -o -name "log.*" \) \
| xargs -I '{}' $backupcmd '{}' $backupdir
cp -af DB_CONFIG $backupdir &>/dev/null
# fix permissions
chown -R ldap: $backupdir
chmod -R a-w $backupdir
fi
popd &>/dev/null
@ -498,8 +520,8 @@ fi
# finish database migration (see %pre)
if [ -f %{_sharedstatedir}/ldap/upgrade.ldif ]; then
runuser -m -s /usr/sbin/slapadd -- ldap -q -l %{_sharedstatedir}/ldap/upgrade.ldif >/dev/null
mv -f %{_sharedstatedir}/ldap/upgrade.ldif %{_sharedstatedir}/ldap/backup.ldif
runuser -m -s /usr/sbin/slapadd -- ldap -q -l %{_sharedstatedir}/ldap/upgrade.ldif &>/dev/null
rm -f %{_sharedstatedir}/ldap/upgrade.ldif
fi
# restart after upgrade

1
series
View File

@ -9,4 +9,5 @@ openldap-ldaprc-currentdir.patch
openldap-userconfig-setgid.patch
openldap-nss-nofork.patch
openldap-nss-null-pointer.patch
openldap-slapadd-hang.patch
openldap-evolution-ntlm.patch