svn commit: samba r11865 - in branches/SAMBA_3_0/source/rpc_server: .

jra at samba.org jra at samba.org
Tue Nov 22 20:26:23 GMT 2005


Author: jra
Date: 2005-11-22 20:26:23 +0000 (Tue, 22 Nov 2005)
New Revision: 11865

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11865

Log:
The only way to stop multiple LDAP searches is to agressively cache
results. We now cache them for 10 seconds, down from 30 seconds 
(however each re-use will refresh the idle timeout). Any set calls
will flush the cache.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/rpc_server/srv_samr_nt.c


Changeset:
Modified: branches/SAMBA_3_0/source/rpc_server/srv_samr_nt.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_server/srv_samr_nt.c	2005-11-22 19:48:33 UTC (rev 11864)
+++ branches/SAMBA_3_0/source/rpc_server/srv_samr_nt.c	2005-11-22 20:26:23 UTC (rev 11865)
@@ -40,7 +40,7 @@
 		  SA_RIGHT_USER_CHANGE_PASSWORD	| \
 		  SA_RIGHT_USER_SET_LOC_COM )
 
-#define DISP_INFO_CACHE_TIMEOUT 30
+#define DISP_INFO_CACHE_TIMEOUT 10
 
 extern rid_name domain_group_rids[];
 extern rid_name domain_alias_rids[];
@@ -303,9 +303,9 @@
  Function to free the per SID data.
  ********************************************************************/
 
-static void free_samr_cache(DISP_INFO *disp_info)
+static void free_samr_cache(DISP_INFO *disp_info, const char *sid_str)
 {
-	DEBUG(10,("free_samr_cache: deleting cache\n"));
+	DEBUG(10,("free_samr_cache: deleting cache for SID %s\n", sid_str));
 
 	if (disp_info->users) {
 		DEBUG(10,("free_samr_cache: deleting users cache\n"));
@@ -352,7 +352,9 @@
 	   a timeout. */
 
 	if (info->disp_info && info->disp_info->di_cache_timeout_event == (smb_event_id_t)0) {
-		free_samr_cache(info->disp_info);
+		fstring sid_str;
+		sid_to_string(sid_str, &info->disp_info->sid);
+		free_samr_cache(info->disp_info, sid_str);
 	}
 
 	talloc_destroy(info->mem_ctx);
@@ -366,16 +368,19 @@
 					time_t *ev_interval,
 					time_t ev_now)
 {
+	fstring sid_str;
 	DISP_INFO *disp_info = (DISP_INFO *)(*private_data);
 
-	free_samr_cache(disp_info);
+	sid_to_string(sid_str, &disp_info->sid);
 
+	free_samr_cache(disp_info, sid_str);
+
 	/* Remove the event. */
 	smb_unregister_idle_event(disp_info->di_cache_timeout_event);
 	disp_info->di_cache_timeout_event = (smb_event_id_t)0;
 
-	DEBUG(10,("disp_info_cache_idle_timeout_handler: caching timed out at %u\n",
-		(unsigned int)ev_now));
+	DEBUG(10,("disp_info_cache_idle_timeout_handler: caching timed out for SID %s at %u\n",
+		sid_str, (unsigned int)ev_now));
 }
 
 /*******************************************************************
@@ -384,6 +389,10 @@
 
 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
 {
+	fstring sid_str;
+
+	sid_to_string(sid_str, &disp_info->sid);
+
 	/* Remove any pending timeout and update. */
 
 	if (disp_info->di_cache_timeout_event) {
@@ -391,8 +400,8 @@
 		disp_info->di_cache_timeout_event = (smb_event_id_t)0;
 	}
 
-	DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for %u seconds\n",
-		(unsigned int)secs_fromnow ));
+	DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for SID %s for %u seconds\n",
+		sid_str, (unsigned int)secs_fromnow ));
 
 	disp_info->di_cache_timeout_event =
 		smb_register_idle_event(disp_info_cache_idle_timeout_handler,
@@ -401,27 +410,23 @@
 }
 
 /*******************************************************************
- Remove the cache removal idle event handler.
- ********************************************************************/
-
-static void clear_disp_info_cache_timeout(DISP_INFO *disp_info)
-{
-	if (disp_info->di_cache_timeout_event) {
-		smb_unregister_idle_event(disp_info->di_cache_timeout_event);
-		disp_info->di_cache_timeout_event = (smb_event_id_t)0;
-		DEBUG(10,("clear_disp_info_cache_timeout: clearing idle event.\n"));
-	}
-}
-
-/*******************************************************************
  Force flush any cache. We do this on any samr_set_xxx call.
+ We must also remove the timeout handler.
  ********************************************************************/
 
 static void force_flush_samr_cache(DISP_INFO *disp_info)
 {
 	if (disp_info) {
-		clear_disp_info_cache_timeout(disp_info);
-		free_samr_cache(disp_info);
+		fstring sid_str;
+
+		sid_to_string(sid_str, &disp_info->sid);
+		if (disp_info->di_cache_timeout_event) {
+			smb_unregister_idle_event(disp_info->di_cache_timeout_event);
+			disp_info->di_cache_timeout_event = (smb_event_id_t)0;
+			DEBUG(10,("force_flush_samr_cache: clearing idle event for SID %s\n",
+				sid_str));
+		}
+		free_samr_cache(disp_info, sid_str);
 	}
 }
 
@@ -792,13 +797,14 @@
 		return r_u->status;
 
 	if (max_entries <= num_account) {
-		/* Ensure we cache this enumeration. */
-		set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
 		r_u->status = STATUS_MORE_ENTRIES;
 	} else {
-		clear_disp_info_cache_timeout(info->disp_info);
+		r_u->status = NT_STATUS_OK;
 	}
 
+	/* Ensure we cache this enumeration. */
+	set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
+
 	DEBUG(5, ("_samr_enum_dom_users: %d\n", __LINE__));
 
 	init_samr_r_enum_dom_users(r_u, q_u->start_idx + num_account,
@@ -1158,14 +1164,14 @@
 	total_data_size=num_account*struct_size;
 
 	if (num_account) {
-		/* Ensure we cache this enumeration. */
-		set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
 		r_u->status = STATUS_MORE_ENTRIES;
 	} else {
-		clear_disp_info_cache_timeout(info->disp_info);
 		r_u->status = NT_STATUS_OK;
 	}
 
+	/* Ensure we cache this enumeration. */
+	set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
+
 	DEBUG(5, ("_samr_query_dispinfo: %d\n", __LINE__));
 
 	init_samr_r_query_dispinfo(r_u, num_account, total_data_size,



More information about the samba-cvs mailing list