[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH 3 of 3] CA-34933: Do not GC sessions which are internal or which are used by pending tasks



# HG changeset patch
# User Thomas Gazagnaire <thomas.gazagnaire@xxxxxxxxxx>
# Date 1260283600 0
# Node ID fb3787ea1b73217538607a45bac0b9378c918330
# Parent  3698135f9161a996255caf7d74cb3f5a829c5609
CA-34933: Do not GC sessions which are internal or which are used by pending 
tasks.

Signed-off-by: Thomas Gazagnaire <thomas.gazagnaire@xxxxxxxxxx>

diff -r 3698135f9161 -r fb3787ea1b73 ocaml/xapi/db_gc.ml
--- a/ocaml/xapi/db_gc.ml       Tue Dec 08 14:42:44 2009 +0000
+++ b/ocaml/xapi/db_gc.ml       Tue Dec 08 14:46:40 2009 +0000
@@ -205,11 +205,15 @@
 
 let timeout_sessions ~__context =
   let all_sessions = Db.Session.get_internal_records_where ~__context 
~expr:Db_filter_types.True in
+  let external_sessions = List.filter (fun (_, y) -> not 
y.Db_actions.session_pool) all_sessions in
+  let unused_sessions = List.filter
+    (fun (_, y) -> List.for_all (fun t -> Db.Task.get_status ~__context 
~self:t <> `Pending) y.Db_actions.session_tasks
+    ) external_sessions in
   (* Only keep a list of (ref, last_active, uuid) *)
-  let all_sessions = List.map (fun (x, y) -> x, Date.to_float 
y.Db_actions.session_last_active, y.Db_actions.session_uuid) all_sessions in
+  let unused_sessions = List.map (fun (x, y) -> x, Date.to_float 
y.Db_actions.session_last_active, y.Db_actions.session_uuid) unused_sessions in
   (* Definitely invalidate sessions last used long ago *)
   let threshold_time = Unix.time () -. Xapi_globs.inactive_session_timeout in
-  let young, old = List.partition (fun (_, y, _) -> y > threshold_time) 
all_sessions in
+  let young, old = List.partition (fun (_, y, _) -> y > threshold_time) 
unused_sessions in
   (* If there are too many young sessions then we need to delete the oldest *)
   let lucky, unlucky = 
     if List.length young <= Xapi_globs.max_sessions
@@ -225,7 +229,8 @@
         ) sessions in
   (* Only the 'lucky' survive: the 'old' and 'unlucky' are destroyed *)
   if unlucky <> [] 
-  then debug "Number of sessions in database (%d) exceeds limit (%d): will 
delete the oldest" (List.length all_sessions) Xapi_globs.max_sessions;
+  then debug "Number of unused sessions in database (%d/%d) exceeds limit 
(%d): will delete the oldest"
+     (List.length unused_sessions) (List.length all_sessions) 
Xapi_globs.max_sessions;
   cancel "Timed out session because of its age" old;
   cancel "Timed out session because max number of sessions was exceeded" 
unlucky
 
1 file changed, 8 insertions(+), 3 deletions(-)
ocaml/xapi/db_gc.ml |   11 ++++++++---


Attachment: xen-api.hg-3.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.