Happy new year
[pazpar2-moved-to-github.git] / src / session.c
index b590001..f597d7c 100644 (file)
@@ -113,7 +113,7 @@ static int session_use(int delta)
     return sessions;
 }
 
-int sessions_count(void)
+int sessions_get_count(void)
 {
     return session_use(0);
 }
@@ -570,7 +570,6 @@ static void select_targets_callback(struct session *se,
         l->next = se->clients_cached;
         se->clients_cached = l;
     }
-    /* set session always. If may be 0 if client is not active */
     client_set_session(cl, se);
 
     l = xmalloc(sizeof(*l));
@@ -619,6 +618,7 @@ static void session_remove_cached_clients(struct session *se)
         client_lock(l->client);
         client_set_session(l->client, 0);
         client_set_database(l->client, 0);
+        client_mark_dead(l->client);
         client_unlock(l->client);
         client_destroy(l->client);
         xfree(l);
@@ -834,7 +834,11 @@ enum pazpar2_error_code session_search(struct session *se,
     int no_sortmap = 0;
     struct client_list *l;
 
-    session_log(se, YLOG_DEBUG, "Search");
+    session_log(se, YLOG_LOG, "search query %s", query);
+    if (filter)
+        session_log(se, YLOG_LOG, "search filter %s", filter);
+    if (limit)
+        session_log(se, YLOG_LOG, "search limit %s", limit);
 
     *addinfo = 0;
 
@@ -886,6 +890,7 @@ enum pazpar2_error_code session_search(struct session *se,
         *addinfo = "limit";
         session_leave(se, "session_search");
         se->clients_starting = 0;
+        session_reset_active_clients(se, 0);
         return PAZPAR2_MALFORMED_PARAMETER_VALUE;
     }
 
@@ -919,8 +924,9 @@ enum pazpar2_error_code session_search(struct session *se,
             no_working++;
         }
     }
-    yaz_log(YLOG_LOG, "session_search: no_working=%d no_sortmap=%d",
-            no_working, no_sortmap);
+    session_log(se, YLOG_LOG, "search "
+                "working %d sortmap %d failed-query %d failed-limit %d",
+                no_working, no_sortmap, no_failed_query, no_failed_limit);
     session_enter(se, "session_search2");
     if (no_working == 1 && no_sortmap == 1)
     {
@@ -1047,8 +1053,17 @@ void session_apply_setting(struct session *se, const char *dbname,
 void session_destroy(struct session *se)
 {
     struct session_database *sdb;
-    session_log(se, YLOG_LOG, "destroy");
-    session_use(-1);
+    struct facet_id *t;
+    int sessions_total = session_use(-1);
+    int no_facet_ids = 0;
+
+    for (t = se->facet_id_list; t; t = t->next)
+        no_facet_ids++;
+    session_log(se, YLOG_LOG, "destroy "
+                "session-total %d nmem-op %zd nmem-ses %zd facets-ids %d",
+                sessions_total,
+                nmem_total(se->nmem), nmem_total(se->session_nmem),
+                no_facet_ids);
     session_remove_cached_clients(se);
 
     for (sdb = se->databases; sdb; sdb = sdb->next)
@@ -1058,10 +1073,6 @@ void session_destroy(struct session *se)
     reclist_destroy(se->reclist);
     xfree(se->mergekey);
     xfree(se->rank);
-    if (nmem_total(se->nmem))
-        session_log(se, YLOG_DEBUG, "NMEN operation usage %zd", nmem_total(se->nmem));
-    if (nmem_total(se->session_nmem))
-        session_log(se, YLOG_DEBUG, "NMEN session usage %zd", nmem_total(se->session_nmem));
     facet_limits_destroy(se->facet_limits);
     nmem_destroy(se->nmem);
     service_destroy(se->service);
@@ -1079,8 +1090,8 @@ size_t session_get_memory_status(struct session *session) {
 }
 
 
-struct session *new_session(NMEM nmem, struct conf_service *service,
-                            unsigned session_id)
+struct session *session_create(NMEM nmem, struct conf_service *service,
+                               unsigned session_id)
 {
     int i;
     struct session *session = nmem_malloc(nmem, sizeof(*session));
@@ -1120,9 +1131,9 @@ struct session *new_session(NMEM nmem, struct conf_service *service,
     session->normalize_cache = normalize_cache_create();
     session->session_mutex = 0;
     pazpar2_mutex_create(&session->session_mutex, tmp_str);
-    session_log(session, YLOG_LOG, "create");
 
-    session_use(1);
+    i = session_use(1);
+    session_log(session, YLOG_LOG, "create session-total %d", i);
     return session;
 }
 
@@ -2184,6 +2195,8 @@ static int ingest_to_cluster(struct client *cl,
             if (!value0 || !*value0)
             {
                 const char *empty = yaz_xml_get_prop(n, "empty");
+                if (value0)
+                    xmlFree(value0);
                 if (!empty)
                     continue;
                 wrbuf_puts(wrbuf_disp, (const char *) empty);
@@ -2191,9 +2204,8 @@ static int ingest_to_cluster(struct client *cl,
             else
             {
                 wrbuf_puts(wrbuf_disp, (const char *) value0);
-            }
-            if (value0)
                 xmlFree(value0);
+            }
             ser_md = &service->metadata[md_field_id];
 
             // non-merged metadata