浏览代码

Ticket 511 - allow turning off vattr lookup in search entry return

Bug Description:  Functions vattr_map_namespace_sp_getlist and slapi_vattr_namespace_values_get_sp,
                  take a long time, even if there are no vattrs being used.

Fix Description:  Added a new atomic config setting to ignore vattrs.  Then we bypass the expensive
                  vattr code when disabled.

                  New config setting:   nsslapd-ignore-virtual-attrs: on|off  default is "off"

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

Reviewed by: ?
Mark Reynolds 13 年之前
父节点
当前提交
1e2745f875
共有 4 个文件被更改,包括 52 次插入9 次删除
  1. 27 0
      ldap/servers/slapd/libglobs.c
  2. 2 0
      ldap/servers/slapd/proto-slap.h
  3. 4 0
      ldap/servers/slapd/slap.h
  4. 19 9
      ldap/servers/slapd/vattr.c

+ 27 - 0
ldap/servers/slapd/libglobs.c

@@ -1010,6 +1010,10 @@ static struct config_get_and_set {
 		NULL, 0,
 		NULL, 0,
 		(void**)&global_slapdFrontendConfig.allowed_sasl_mechs,
 		(void**)&global_slapdFrontendConfig.allowed_sasl_mechs,
 		CONFIG_STRING, (ConfigGetFunc)config_get_allowed_sasl_mechs, DEFAULT_ALLOWED_TO_DELETE_ATTRS},
 		CONFIG_STRING, (ConfigGetFunc)config_get_allowed_sasl_mechs, DEFAULT_ALLOWED_TO_DELETE_ATTRS},
+	{CONFIG_IGNORE_VATTRS, config_set_ignore_vattrs,
+		NULL, 0,
+		(void**)&global_slapdFrontendConfig.ignore_vattrs,
+		CONFIG_STRING, (ConfigGetFunc)config_get_ignore_vattrs, DEFAULT_ALLOWED_TO_DELETE_ATTRS},
 #ifdef MEMPOOL_EXPERIMENTAL
 #ifdef MEMPOOL_EXPERIMENTAL
 	,{CONFIG_MEMPOOL_SWITCH_ATTRIBUTE, config_set_mempool_switch,
 	,{CONFIG_MEMPOOL_SWITCH_ATTRIBUTE, config_set_mempool_switch,
 		NULL, 0,
 		NULL, 0,
@@ -1436,6 +1440,7 @@ FrontendConfig_init () {
   init_disk_logging_critical = cfg->disk_logging_critical = LDAP_OFF;
   init_disk_logging_critical = cfg->disk_logging_critical = LDAP_OFF;
   init_ndn_cache_enabled = cfg->ndn_cache_enabled = LDAP_OFF;
   init_ndn_cache_enabled = cfg->ndn_cache_enabled = LDAP_OFF;
   cfg->ndn_cache_max_size = NDN_DEFAULT_SIZE;
   cfg->ndn_cache_max_size = NDN_DEFAULT_SIZE;
+  cfg->ignore_vattrs = slapi_counter_new();
 
 
 #ifdef MEMPOOL_EXPERIMENTAL
 #ifdef MEMPOOL_EXPERIMENTAL
   init_mempool_switch = cfg->mempool_switch = LDAP_ON;
   init_mempool_switch = cfg->mempool_switch = LDAP_ON;
@@ -1561,6 +1566,20 @@ config_value_is_null( const char *attrname, const char *value, char *errorbuf,
 	return 0;
 	return 0;
 }
 }
 
 
+int
+config_set_ignore_vattrs (const char *attrname, char *value, char *errorbuf, int apply )
+{
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+    int retVal = LDAP_SUCCESS;
+    int val;
+
+    retVal = config_set_onoff ( attrname, value, &val, errorbuf, apply);
+    if(retVal == LDAP_SUCCESS){
+        slapi_counter_set_value(slapdFrontendConfig->ignore_vattrs, val);
+    }
+    return retVal;
+}
+
 int
 int
 config_set_disk_monitoring( const char *attrname, char *value, char *errorbuf, int apply )
 config_set_disk_monitoring( const char *attrname, char *value, char *errorbuf, int apply )
 {
 {
@@ -4127,6 +4146,14 @@ config_get_port(){
 
 
 }
 }
 
 
+int
+config_get_ignore_vattrs()
+{
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+
+    return slapi_counter_get_value(slapdFrontendConfig->ignore_vattrs);
+}
+
 int
 int
 config_get_disk_monitoring(){
 config_get_disk_monitoring(){
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();

+ 2 - 0
ldap/servers/slapd/proto-slap.h

@@ -552,6 +552,8 @@ int config_get_ndn_cache_enabled();
 char *config_get_allowed_sasl_mechs();
 char *config_get_allowed_sasl_mechs();
 int config_set_allowed_sasl_mechs(const char *attrname, char *value, char *errorbuf, int apply);
 int config_set_allowed_sasl_mechs(const char *attrname, char *value, char *errorbuf, int apply);
 int config_get_schemamod();
 int config_get_schemamod();
+int config_set_ignore_vattrs(const char *attrname, char *value, char *errorbuf, int apply);
+int config_get_ignore_vattrs();
 
 
 PLHashNumber hashNocaseString(const void *key);
 PLHashNumber hashNocaseString(const void *key);
 PRIntn hashNocaseCompare(const void *v1, const void *v2);
 PRIntn hashNocaseCompare(const void *v1, const void *v2);

+ 4 - 0
ldap/servers/slapd/slap.h

@@ -2053,6 +2053,7 @@ typedef struct _slapdEntryPoints {
 #define CONFIG_NDN_CACHE "nsslapd-ndn-cache-enabled"
 #define CONFIG_NDN_CACHE "nsslapd-ndn-cache-enabled"
 #define CONFIG_NDN_CACHE_SIZE "nsslapd-ndn-cache-max-size"
 #define CONFIG_NDN_CACHE_SIZE "nsslapd-ndn-cache-max-size"
 #define CONFIG_ALLOWED_SASL_MECHS "nsslapd-allowed-sasl-mechanisms"
 #define CONFIG_ALLOWED_SASL_MECHS "nsslapd-allowed-sasl-mechanisms"
+#define CONFIG_IGNORE_VATTRS "nsslapd-ignore-virtual-attrs"
 
 
 #ifdef MEMPOOL_EXPERIMENTAL
 #ifdef MEMPOOL_EXPERIMENTAL
 #define CONFIG_MEMPOOL_SWITCH_ATTRIBUTE "nsslapd-mempool"
 #define CONFIG_MEMPOOL_SWITCH_ATTRIBUTE "nsslapd-mempool"
@@ -2275,6 +2276,9 @@ typedef struct _slapdFrontendConfig {
   /* normalized dn cache */
   /* normalized dn cache */
   int ndn_cache_enabled;
   int ndn_cache_enabled;
   size_t ndn_cache_max_size;
   size_t ndn_cache_max_size;
+
+  /* atomic settings */
+  Slapi_Counter *ignore_vattrs;
 } slapdFrontendConfig_t;
 } slapdFrontendConfig_t;
 
 
 /* possible values for slapdFrontendConfig_t.schemareplace */
 /* possible values for slapdFrontendConfig_t.schemareplace */

+ 19 - 9
ldap/servers/slapd/vattr.c

@@ -850,21 +850,26 @@ int slapi_vattr_namespace_values_get_sp(vattr_context *c,
 	vattr_sp_handle_list *list = NULL;
 	vattr_sp_handle_list *list = NULL;
 	vattr_get_thang *my_get = NULL;
 	vattr_get_thang *my_get = NULL;
 	int attr_count = 0;
 	int attr_count = 0;
+	int ignore_vattrs;
 
 
-	rc = vattr_context_grok(&c);
-	if (0 != rc) {
-		/* Print a handy error log message */
-		if(!vattr_context_is_loop_msg_displayed(&c))
-		{
-			LDAPDebug(LDAP_DEBUG_ANY,"Detected virtual attribute loop in get on entry %s, attribute %s\n", slapi_entry_get_dn_const(e), type, 0);
-			vattr_context_set_loop_msg_displayed(&c);
+	ignore_vattrs = config_get_ignore_vattrs();
+
+	if(!ignore_vattrs){
+		rc = vattr_context_grok(&c);
+		if (0 != rc) {
+			/* Print a handy error log message */
+			if(!vattr_context_is_loop_msg_displayed(&c))
+			{
+				LDAPDebug(LDAP_DEBUG_ANY,"Detected virtual attribute loop in get on entry %s, attribute %s\n", slapi_entry_get_dn_const(e), type, 0);
+				vattr_context_set_loop_msg_displayed(&c);
+			}
+			return rc;
 		}
 		}
-		return rc;
 	}
 	}
 
 
 	/* Having done that, we now consult the attribute map to find service providers who are interested */
 	/* Having done that, we now consult the attribute map to find service providers who are interested */
 	/* Look for attribute in the map */
 	/* Look for attribute in the map */
-	if(!(flags & SLAPI_REALATTRS_ONLY))
+	if(!(flags & SLAPI_REALATTRS_ONLY) && !ignore_vattrs)
 	{
 	{
 		/* we use the vattr namespace aware version of this */
 		/* we use the vattr namespace aware version of this */
 		list = vattr_map_namespace_sp_getlist(namespace_dn, type);
 		list = vattr_map_namespace_sp_getlist(namespace_dn, type);
@@ -2185,6 +2190,11 @@ vattr_sp_handle_list *vattr_map_namespace_sp_getlist(Slapi_DN *dn, const char *t
 	vattr_map_entry *result = NULL;
 	vattr_map_entry *result = NULL;
 	vattr_sp_handle_list* return_list = 0;
 	vattr_sp_handle_list* return_list = 0;
 
 
+	if(config_get_ignore_vattrs()){
+		/* we don't care about vattrs */
+		return NULL;
+	}
+
 	ret = vattr_map_lookup(type_to_find,&result);
 	ret = vattr_map_lookup(type_to_find,&result);
 	if (0 == ret) {
 	if (0 == ret) {
 		return_list = (vattr_sp_handle_list*) result->sp_list;
 		return_list = (vattr_sp_handle_list*) result->sp_list;