projects
/
pazpar2-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
conf_get_fname takes conf_config as arg
[pazpar2-moved-to-github.git]
/
src
/
session.c
diff --git
a/src/session.c
b/src/session.c
index
c41960d
..
6327ba9
100644
(file)
--- a/
src/session.c
+++ b/
src/session.c
@@
-57,6
+57,7
@@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <yaz/timing.h>
#endif
#include <yaz/timing.h>
#endif
+#include "ppmutex.h"
#include "parameters.h"
#include "session.h"
#include "eventl.h"
#include "parameters.h"
#include "session.h"
#include "eventl.h"
@@
-80,6
+81,11
@@
struct parameters global_parameters =
0 // debug_mode
};
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 log_xml_doc(xmlDoc *doc)
{
FILE *lf = yaz_log_file();
@@
-100,12
+106,12
@@
static void log_xml_doc(xmlDoc *doc)
static void session_enter(struct session *s)
{
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)
{
}
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.
}
// Recursively traverse query structure to extract terms.
@@
-353,7
+359,7
@@
static int prepare_map(struct session *se, struct session_database *sdb)
}
}
sdb->map = normalize_cache_get(se->normalize_cache,
}
}
sdb->map = normalize_cache_get(se->normalize_cache,
- se->service, s);
+ se->service->server->config, s);
if (!sdb->map)
return -1;
}
if (!sdb->map)
return -1;
}
@@
-414,6
+420,7
@@
int session_set_watch(struct session *s, int what,
void session_alert_watch(struct session *s, int what)
{
void session_alert_watch(struct session *s, int what)
{
+ assert(s);
session_enter(s);
if (s->watchlist[what].fun)
{
session_enter(s);
if (s->watchlist[what].fun)
{
@@
-443,21
+450,36
@@
static void select_targets_callback(void *context, struct session_database *db)
{
struct session *se = (struct session*) context;
struct client *cl = client_create();
{
struct session *se = (struct session*) context;
struct client *cl = client_create();
+ struct client_list *l;
client_set_database(cl, db);
client_set_database(cl, db);
+
client_set_session(cl, se);
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)
{
}
static void session_remove_clients(struct session *se)
{
- struct client *cl = se->clients;
- while (cl)
+ struct client_list *l;
+
+ session_enter(se);
+ l = se->clients;
+ se->clients = 0;
+ session_leave(se);
+
+ while (l)
{
{
- struct client *cl_next = client_next_in_session(cl);
- client_remove_from_session(cl);
- client_destroy(cl);
- cl = cl_next;
+ 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;
}
}
- se->clients = 0;
}
// Associates a set of clients with a session;
}
// Associates a set of clients with a session;
@@
-465,17
+487,16
@@
static void session_remove_clients(struct session *se)
// setting overrides
static int select_targets(struct session *se, const char *filter)
{
// 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)
{
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;
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;
res++;
return res;
@@
-491,18
+512,20
@@
enum pazpar2_error_code search(struct session *se,
int live_channels = 0;
int no_working = 0;
int no_failed = 0;
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;
yaz_log(YLOG_DEBUG, "Search");
*addinfo = 0;
+
+ session_remove_clients(se);
session_enter(se);
session_enter(se);
- nmem_reset(se->nmem);
- se->relevance = 0;
- se->total_records = se->total_hits = se->total_merged = 0;
reclist_destroy(se->reclist);
se->reclist = 0;
reclist_destroy(se->reclist);
se->reclist = 0;
+ relevance_destroy(&se->relevance);
+ nmem_reset(se->nmem);
+ se->total_records = se->total_hits = se->total_merged = 0;
se->num_termlists = 0;
live_channels = select_targets(se, filter);
if (!live_channels)
se->num_termlists = 0;
live_channels = select_targets(se, filter);
if (!live_channels)
@@
-512,16
+535,17
@@
enum pazpar2_error_code search(struct session *se,
}
se->reclist = reclist_create(se->nmem);
}
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)
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
{
no_failed++;
else
{
@@
-650,14
+674,16
@@
void destroy_session(struct session *s)
for (sdb = s->databases; sdb; sdb = sdb->next)
session_database_destroy(sdb);
normalize_cache_destroy(s->normalize_cache);
for (sdb = s->databases; sdb; sdb = sdb->next)
session_database_destroy(sdb);
normalize_cache_destroy(s->normalize_cache);
+ relevance_destroy(&s->relevance);
reclist_destroy(s->reclist);
nmem_destroy(s->nmem);
service_destroy(s->service);
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);
}
wrbuf_destroy(s->wrbuf);
}
-struct session *new_session(NMEM nmem, struct conf_service *service)
+struct session *new_session(NMEM nmem, struct conf_service *service,
+ const char *name)
{
int i;
struct session *session = nmem_malloc(nmem, sizeof(*session));
{
int i;
struct session *session = nmem_malloc(nmem, sizeof(*session));
@@
-683,8
+709,8
@@
struct session *new_session(NMEM nmem, struct conf_service *service)
session->watchlist[i].fun = 0;
}
session->normalize_cache = normalize_cache_create();
session->watchlist[i].fun = 0;
}
session->normalize_cache = normalize_cache_create();
- session->mutex = 0;
- yaz_mutex_create(&session->mutex);
+ session->session_mutex = 0;
+ pazpar2_mutex_create(&session->session_mutex, name);
return session;
}
return session;
}
@@
-692,17
+718,18
@@
struct session *new_session(NMEM nmem, struct conf_service *service)
struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem)
{
struct hitsbytarget *res = 0;
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);
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;
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);
WRBUF w = wrbuf_alloc();
const char *name = session_setting_oneval(client_get_database(cl),
PZ_NAME);
@@
-852,12
+879,13
@@
void show_range_stop(struct session *s, struct record_cluster **recs)
void statistics(struct session *se, struct statistics *stat)
{
void statistics(struct session *se, struct statistics *stat)
{
- struct client *cl;
+ struct client_list *l;
int count = 0;
memset(stat, 0, sizeof(*stat));
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))
if (!client_get_connection(cl))
stat->num_no_connection++;
switch (client_get_state(cl))
@@
-949,10
+977,9
@@
static int get_mergekey_from_doc(xmlDoc *doc, xmlNode *root, const char *name,
{
const char *norm_str;
pp2_relevance_token_t prt =
{
const char *norm_str;
pp2_relevance_token_t prt =
- pp2_relevance_tokenize(
- service->mergekey_pct,
- (const char *) value, 0);
+ pp2_relevance_tokenize(service->mergekey_pct);
+ pp2_relevance_first(prt, (const char *) value, 0);
if (wrbuf_len(norm_wr) > 0)
wrbuf_puts(norm_wr, " ");
wrbuf_puts(norm_wr, name);
if (wrbuf_len(norm_wr) > 0)
wrbuf_puts(norm_wr, " ");
wrbuf_puts(norm_wr, name);
@@
-989,10
+1016,9
@@
static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no,
{
const char *norm_str;
pp2_relevance_token_t prt =
{
const char *norm_str;
pp2_relevance_token_t prt =
- pp2_relevance_tokenize(
- service->mergekey_pct,
- (const char *) mergekey, 0);
-
+ pp2_relevance_tokenize(service->mergekey_pct);
+
+ pp2_relevance_first(prt, (const char *) mergekey, 0);
while ((norm_str = pp2_relevance_token_next(prt)))
{
if (*norm_str)
while ((norm_str = pp2_relevance_token_next(prt)))
{
if (*norm_str)
@@
-1110,7
+1136,7
@@
int ingest_record(struct client *cl, const char *rec,
int record_no, NMEM nmem)
{
struct session *se = client_get_session(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);
struct session_database *sdb = client_get_database(cl);
struct conf_service *service = se->service;
xmlDoc *xdoc = normalize_record(sdb, service, rec, nmem);
@@
-1137,9
+1163,14
@@
int ingest_record(struct client *cl, const char *rec,
xmlFreeDoc(xdoc);
return -1;
}
xmlFreeDoc(xdoc);
return -1;
}
+ client_unlock(cl);
session_enter(se);
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);
session_leave(se);
+ client_lock(cl);
xmlFreeDoc(xdoc);
return ret;
xmlFreeDoc(xdoc);
return ret;
@@
-1272,9
+1303,10
@@
static int ingest_to_cluster(struct client *cl,
nmem_malloc(se->nmem,
sizeof(union data_types));
nmem_malloc(se->nmem,
sizeof(union data_types));
- prt = pp2_relevance_tokenize(
- service->sort_pct,
- rec_md->data.text.disp, skip_article);
+ prt = pp2_relevance_tokenize(service->sort_pct);
+
+ pp2_relevance_first(prt, rec_md->data.text.disp,
+ skip_article);
pp2_relevance_token_next(prt);
pp2_relevance_token_next(prt);