From 9f5eb0f6613b79e544bf687f5fa8c5bc0a63801a Mon Sep 17 00:00:00 2001
From: William Brown <firstyear@redhat.com>
Date: Thu, 9 Jun 2016 12:56:36 +1000
Subject: [PATCH] Ticket 48873 - Backend should accept the reduced cache
 allocation when issane == 1

Bug Description:  We introduced a stricter cache checking mode, and corrected
our cache check behaviours. Sadly, at some sites, this will cause pain as
the admins may not be ready for this.

Fix Description:  Make the error messages clearer. We also DO NOT prevent
server start up on an invalid config, but we do WARN that this behaviour
will change.

https://fedorahosted.org/389/ticket/48873

Author: wibrown

Review by: ???
---
 ldap/servers/slapd/back-ldbm/ldbm_config.c | 4 ++--
 ldap/servers/slapd/back-ldbm/start.c       | 6 ++++--
 ldap/servers/slapd/util.c                  | 9 ++++++---
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/ldap/servers/slapd/back-ldbm/ldbm_config.c b/ldap/servers/slapd/back-ldbm/ldbm_config.c
index 37ce02d..6100898 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_config.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_config.c
@@ -425,8 +425,8 @@ static int ldbm_config_dbcachesize_set(void *arg, void *value, char *errorbuf, i
         } else if (val > li->li_dbcachesize) {
             delta = val - li->li_dbcachesize;
             if (!util_is_cachesize_sane(&delta)){
-                slapi_create_errormsg(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: dbcachememsize value is too large.");
-                LDAPDebug0Args(LDAP_DEBUG_ANY,"Error: dbcachememsize value is too large.\n");
+                slapi_create_errormsg(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: nsslapd-cachememsize value is too large.");
+                LDAPDebug0Args(LDAP_DEBUG_ANY,"Error: nsslapd-cachememsize value is too large.\n");
                 return LDAP_UNWILLING_TO_PERFORM;
             }
         }
diff --git a/ldap/servers/slapd/back-ldbm/start.c b/ldap/servers/slapd/back-ldbm/start.c
index acac2aa..299e5f0 100644
--- a/ldap/servers/slapd/back-ldbm/start.c
+++ b/ldap/servers/slapd/back-ldbm/start.c
@@ -266,7 +266,8 @@ ldbm_back_start( Slapi_PBlock *pb )
   issane = util_is_cachesize_sane(&total_size);
   if (!issane) {
     /* Right, it's time to panic */
-    LDAPDebug( LDAP_DEBUG_ANY, "CRITICAL: It is highly likely your memory configuration will EXCEED your systems memory.\n", 0, 0, 0 );
+    LDAPDebug( LDAP_DEBUG_ANY, "CRITICAL: It is highly likely your memory configuration of all backends will EXCEED your systems memory.\n", 0, 0, 0 );
+    LDAPDebug( LDAP_DEBUG_ANY, "CRITICAL: In a future release this WILL prevent server start up. You MUST alter your configuration.\n", 0, 0, 0 );
     LDAPDebug(LDAP_DEBUG_ANY,
               "Total entry cache size: %llu B; "
               "dbcache size: %llu B; "
@@ -278,7 +279,8 @@ ldbm_back_start( Slapi_PBlock *pb )
 #endif
     );
     LDAPDebug(LDAP_DEBUG_ANY, msg, 0,0,0);
-    return SLAPI_FAIL_GENERAL;
+    /* WB 2016 - This should be UNCOMMENTED in a future release */
+    /* return SLAPI_FAIL_GENERAL; */
   }
 
 
diff --git a/ldap/servers/slapd/util.c b/ldap/servers/slapd/util.c
index 3f17461..e96b32b 100644
--- a/ldap/servers/slapd/util.c
+++ b/ldap/servers/slapd/util.c
@@ -1787,8 +1787,11 @@ int util_is_cachesize_sane(size_t *cachesize)
          * the remaining system mem to the cachesize instead, and log a warning
          */
         *cachesize = (size_t)((availpages * 0.75 ) * pagesize);
-        slapi_log_error(SLAPI_LOG_FATAL, "util_is_cachesize_sane", "Available pages %lu, requested pages %lu, pagesize %lu\n", (unsigned long)availpages, (unsigned long)cachepages, (unsigned long)pagesize);
-        slapi_log_error(SLAPI_LOG_FATAL, "util_is_cachesize_sane", "WARNING adjusted cachesize to %lu\n", (unsigned long)*cachesize);
+        /* These are now trace warnings, because it was to confusing to log this *then* kill the request anyway.
+         * Instead, we will let the caller worry about the notification, and we'll just use this in debugging and tracing.
+         */
+        slapi_log_error(SLAPI_LOG_TRACE, "util_is_cachesize_sane", "Available pages %lu, requested pages %lu, pagesize %lu\n", (unsigned long)availpages, (unsigned long)cachepages, (unsigned long)pagesize);
+        slapi_log_error(SLAPI_LOG_TRACE, "util_is_cachesize_sane", "WARNING adjusted cachesize to %lu\n", (unsigned long)*cachesize);
     }
 #else
     size_t freepages = 0;
@@ -1808,7 +1811,7 @@ int util_is_cachesize_sane(size_t *cachesize)
 #endif
 out:
     if (!issane) {
-        slapi_log_error(SLAPI_LOG_FATAL,"util_is_cachesize_sane", "WARNING: Cachesize not sane \n");
+        slapi_log_error(SLAPI_LOG_TRACE,"util_is_cachesize_sane", "WARNING: Cachesize not sane \n");
     }
 
     return issane;
-- 
2.5.5

