0 // debug_mode
};
+struct client_list {
+ struct client *client;
+ struct client_list *next;
+};
+
static void log_xml_doc(xmlDoc *doc)
{
FILE *lf = yaz_log_file();
static void session_enter(struct session *s)
{
- yaz_mutex_enter(s->mutex);
+ yaz_mutex_enter(s->session_mutex);
}
static void session_leave(struct session *s)
{
- yaz_mutex_leave(s->mutex);
+ yaz_mutex_leave(s->session_mutex);
}
// Recursively traverse query structure to extract terms.
{
struct session *se = (struct session*) context;
struct client *cl = client_create();
+ struct client_list *l;
client_set_database(cl, db);
+
client_set_session(cl, se);
+ l = xmalloc(sizeof(*l));
+ l->client = cl;
+ l->next = se->clients;
+ se->clients = l;
}
static void session_remove_clients(struct session *se)
{
- while (se->clients)
+ struct client_list *l;
+
+ session_enter(se);
+ l = se->clients;
+ se->clients = 0;
+ session_leave(se);
+
+ while (l)
{
- struct client *cl = se->clients;
- client_remove_from_session(cl);
- client_destroy(cl);
+ struct client_list *l_next = l->next;
+ client_lock(l->client);
+ client_set_session(l->client, 0);
+ client_set_database(l->client, 0);
+ client_unlock(l->client);
+ client_destroy(l->client);
+ xfree(l);
+ l = l_next;
}
}
// setting overrides
static int select_targets(struct session *se, const char *filter)
{
- session_remove_clients(se);
return session_grep_databases(se, filter, select_targets_callback);
}
int session_active_clients(struct session *s)
{
- struct client *c;
+ struct client_list *l;
int res = 0;
- for (c = s->clients; c; c = client_next_in_session(c))
- if (client_is_active(c))
+ for (l = s->clients; l; l = l->next)
+ if (client_is_active(l->client))
res++;
return res;
int live_channels = 0;
int no_working = 0;
int no_failed = 0;
- struct client *cl;
+ struct client_list *l;
yaz_log(YLOG_DEBUG, "Search");
*addinfo = 0;
+
+ session_remove_clients(se);
session_enter(se);
reclist_destroy(se->reclist);
}
se->reclist = reclist_create(se->nmem);
- for (cl = se->clients; cl; cl = client_next_in_session(cl))
+ for (l = se->clients; l; l = l->next)
{
+ struct client *cl = l->client;
+
if (maxrecs)
client_set_maxrecs(cl, atoi(maxrecs));
if (startrecs)
client_set_startrecs(cl, atoi(startrecs));
if (prepare_session_database(se, client_get_database(cl)) < 0)
- continue;
- // Parse query for target
- if (client_parse_query(cl, query) < 0)
+ ;
+ else if (client_parse_query(cl, query) < 0)
no_failed++;
else
{
reclist_destroy(s->reclist);
nmem_destroy(s->nmem);
service_destroy(s->service);
- yaz_mutex_destroy(&s->mutex);
+ yaz_mutex_destroy(&s->session_mutex);
wrbuf_destroy(s->wrbuf);
}
session->watchlist[i].fun = 0;
}
session->normalize_cache = normalize_cache_create();
- session->mutex = 0;
-
- pazpar2_mutex_create(&session->mutex, name);
+ session->session_mutex = 0;
+ pazpar2_mutex_create(&session->session_mutex, name);
return session;
}
struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem)
{
struct hitsbytarget *res = 0;
- struct client *cl;
+ struct client_list *l;
size_t sz = 0;
session_enter(se);
- for (cl = se->clients; cl; cl = client_next_in_session(cl))
+ for (l = se->clients; l; l = l->next)
sz++;
res = nmem_malloc(nmem, sizeof(*res) * sz);
*count = 0;
- for (cl = se->clients; cl; cl = client_next_in_session(cl))
+ for (l = se->clients; l; l = l->next)
{
+ struct client *cl = l->client;
WRBUF w = wrbuf_alloc();
const char *name = session_setting_oneval(client_get_database(cl),
PZ_NAME);
void statistics(struct session *se, struct statistics *stat)
{
- struct client *cl;
+ struct client_list *l;
int count = 0;
memset(stat, 0, sizeof(*stat));
- for (cl = se->clients; cl; cl = client_next_in_session(cl))
+ for (l = se->clients; l; l = l->next)
{
+ struct client *cl = l->client;
if (!client_get_connection(cl))
stat->num_no_connection++;
switch (client_get_state(cl))
int record_no, NMEM nmem)
{
struct session *se = client_get_session(cl);
- int ret;
+ int ret = 0;
struct session_database *sdb = client_get_database(cl);
struct conf_service *service = se->service;
xmlDoc *xdoc = normalize_record(sdb, service, rec, nmem);
xmlFreeDoc(xdoc);
return -1;
}
+ client_unlock(cl);
session_enter(se);
- ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm);
+ client_lock(cl);
+ if (client_get_session(cl) == se)
+ ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm);
+ client_unlock(cl);
session_leave(se);
+ client_lock(cl);
xmlFreeDoc(xdoc);
return ret;