ZOOM_resultset resultset;
YAZ_MUTEX mutex;
int ref_count;
- /* copy of database->url */
char *url;
};
connection_continue(co);
}
-struct client *client_create(void)
+struct client *client_create(const char *url)
{
struct client *cl = xmalloc(sizeof(*cl));
cl->maxrecs = 100;
pazpar2_mutex_create(&cl->mutex, "client");
cl->preferred = 0;
cl->ref_count = 1;
- cl->url = 0;
+ assert(url);
+ cl->url = xstrdup(url);
client_use(1);
return cl;
return 0;
}
-
Odr_int client_get_hits(struct client *cl)
{
return cl->hits;
void client_set_database(struct client *cl, struct session_database *db)
{
cl->database = db;
- /* Copy the URL for safe logging even after session is gone */
- if (db) {
- cl->url = xstrdup(db->database->url);
- }
-}
-
-struct host *client_get_host(struct client *cl)
-{
- return client_get_database(cl)->database->host;
}
const char *client_get_url(struct client *cl)
{
- if (cl->url)
- return cl->url;
- else
- /* This must not happen anymore, as the url is present until destruction of client */
- return "NOURL";
+ return cl->url;
}
void client_set_maxrecs(struct client *cl, int v)
void client_continue(struct client *cl);
-struct client *client_create(void);
+struct client *client_create(const char *url);
int client_destroy(struct client *c);
void client_set_connection(struct client *cl, struct connection *con);
int client_get_diagnostic(struct client *cl);
void client_set_diagnostic(struct client *cl, int diagnostic);
void client_set_database(struct client *cl, struct session_database *db);
-struct host *client_get_host(struct client *cl);
const char *client_get_url(struct client *cl);
void client_set_maxrecs(struct client *cl, int v);
int client_get_maxrecs(struct client *cl);
// Creates a new connection for client, associated with the host of
// client's database
static struct connection *connection_create(struct client *cl,
+ struct host *host,
int operation_timeout,
int session_timeout,
iochan_man_t iochan_man)
{
struct connection *co;
- struct host *host = client_get_host(cl);
co = xmalloc(sizeof(*co));
co->host = host;
const struct timeval *abstime)
{
struct connection *co;
- struct host *host = client_get_host(cl);
struct session_database *sdb = client_get_database(cl);
const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
+ const char *url = session_setting_oneval(sdb, PZ_URL);
+ struct host *host = 0;
if (zproxy && zproxy[0] == '\0')
zproxy = 0;
- if (!host)
- return 0;
+ if (!url || !*url)
+ url = sdb->database->url;
- co = client_get_connection(cl);
+ host = find_host(client_get_session(cl)->service->server->database_hosts,
+ url);
+
+ yaz_log(YLOG_DEBUG, "client_prep_connection: target=%s url=%s",
+ client_get_url(cl), url);
- yaz_log(YLOG_DEBUG, "Client prep %s", client_get_url(cl));
+ co = client_get_connection(cl);
+ if (co)
+ {
+ assert(co->host);
+ if (co->host == host)
+ ; /* reusing connection. It's ours! */
+ else
+ {
+ client_incref(cl);
+ connection_release(co);
+ co = 0;
+ }
+ }
if (!co)
{
int max_connections = 0;
PZ_MAX_CONNECTIONS);
if (v && *v)
max_connections = atoi(v);
-
+
v = session_setting_oneval(client_get_database(cl),
PZ_REUSE_CONNECTIONS);
if (v && *v)
int num_connections = 0;
for (co = host->connections; co; co = co->next)
num_connections++;
- if (reuse_connections) {
+ if (reuse_connections)
+ {
for (co = host->connections; co; co = co->next)
{
if (connection_is_idle(co) &&
else
{
yaz_mutex_leave(host->mutex);
- co = connection_create(cl, operation_timeout, session_timeout,
+ co = connection_create(cl, host, operation_timeout, session_timeout,
iochan_man);
}
+ assert(co->host);
}
if (co && co->link)
return host;
}
-static struct host *find_host(database_hosts_t hosts,
- const char *hostport)
+struct host *find_host(database_hosts_t hosts, const char *hostport)
{
struct host *p;
yaz_mutex_enter(hosts->mutex);
return p;
}
-int resolve_database(struct conf_service *service, struct database *db,
- const char *hostport)
-{
- if (db->host == 0)
- {
- struct host *host;
- if (!(host = find_host(service->server->database_hosts, hostport)))
- return -1;
- db->host = host;
- }
- return 0;
-}
-
struct database *new_database(const char *id, NMEM nmem)
{
struct database *db;
memset(db, 0, sizeof(*db));
db->url = nmem_strdup(nmem, id);
- db->errors = 0;
- db->host = 0;
db->num_settings = PZ_MAX_EOF;
db->settings = nmem_malloc(nmem, sizeof(struct settings*) *
int predef_grep_databases(void *context, struct conf_service *service,
void (*fun)(void *context, struct database *db));
int match_zurl(const char *zurl, const char *pattern);
-int resolve_database(struct conf_service *service, struct database *db,
- const char *hostport);
struct database *new_database(const char *id, NMEM nmem);
database_hosts_t database_hosts_create(void);
void database_hosts_destroy(database_hosts_t *);
+struct host *find_host(database_hosts_t hosts, const char *hostport);
+
#endif
static void select_targets_callback(struct session *se,
struct session_database *db)
{
- struct client *cl = client_create();
+ struct client *cl = client_create(db->database->url);
struct client_list *l;
const char *url = session_setting_oneval(db, PZ_URL);
if (!url || !*url)
url = db->database->url;
- resolve_database(se->service, db->database, url);
-
client_set_database(cl, db);
client_set_session(cl, se);
PAZPAR2_LAST_ERROR
};
-struct host;
-// Represents a (virtual) database on a host
+// Represents a database
struct database {
- struct host *host;
char *url;
- int errors;
int num_settings;
struct setting **settings;
struct database *next;
void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
const char *session_setting_oneval(struct session_database *db, int offset);
-int host_getaddrinfo(struct host *host, iochan_man_t iochan_man);
-
int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem);
void session_alert_watch(struct session *s, int what);
void add_facet(struct session *s, const char *type, const char *value, int count);