WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH 3 of 3] CA-34933: Do not GC sessions which are internal

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH 3 of 3] CA-34933: Do not GC sessions which are internal or which are used by pending tasks
From: Thomas Gazagnaire <thomas.gazagnaire@xxxxxxxxxx>
Date: Tue, 8 Dec 2009 14:54:36 +0000
Delivery-date: Tue, 08 Dec 2009 06:57:49 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1260284073@steel>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
# 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