* All rights reserved.
*
* $Log: zebraapi.c,v $
- * Revision 1.30 2000-04-05 09:49:35 adam
+ * Revision 1.37 2000-10-17 12:37:09 adam
+ * Fixed notification of live-updates. Fixed minor problem with mf_init
+ * where it didn't handle shadow area file names correctly.
+ *
+ * Revision 1.36 2000/09/06 08:59:36 adam
+ * Using read-only (for now) for server.
+ *
+ * Revision 1.35 2000/07/07 12:49:20 adam
+ * Optimized resultSetInsert{Rank,Sort}.
+ *
+ * Revision 1.34 2000/06/09 13:56:38 ian
+ * Added some logging on Authentication and searches.
+ *
+ * Revision 1.33 2000/05/18 12:01:36 adam
+ * System call times(2) used again. More 64-bit fixes.
+ *
+ * Revision 1.32 2000/04/19 14:35:59 adam
+ * WIN32 update (this version is known not to work on Windows).
+ *
+ * Revision 1.31 2000/04/05 10:07:02 adam
+ * Minor zebra compile fix.
+ *
+ * Revision 1.30 2000/04/05 09:49:35 adam
* On Unix, zebra/z'mbol uses automake.
*
* Revision 1.29 2000/03/20 19:08:36 adam
static void zebra_register_unlock (ZebraHandle zh);
+static int zebra_register_activate (ZebraService zh, int rw);
+static int zebra_register_deactivate (ZebraService zh);
+
static int zebra_register_lock (ZebraHandle zh)
{
+ time_t lastChange;
+ int state;
zh->errCode = 0;
zh->errString = 0;
if (!zh->service->active)
zh->errCode = 1019;
return 1;
}
+
+#if HAVE_SYS_TIMES_H
+ times (&zh->tms1);
+#endif
+
+ state = zebra_server_lock_get_state(zh->service, &lastChange);
+
+ zebra_server_lock (zh->service, state);
+
+ switch (state)
+ {
+ case 'c':
+ state = 1;
+ break;
+ default:
+ state = 0;
+ }
+ if (zh->service->registerState == state)
+ {
+ if (zh->service->registerChange >= lastChange)
+ return 0;
+ logf (LOG_LOG, "Register completely updated since last access");
+ }
+ else if (zh->service->registerState == -1)
+ logf (LOG_LOG, "Reading register using state %d pid=%ld", state,
+ (long) getpid());
+ else
+ logf (LOG_LOG, "Register has changed state from %d to %d",
+ zh->service->registerState, state);
+ zh->service->registerChange = lastChange;
+
+ zebra_register_deactivate (zh->service);
+
+ zh->service->registerState = state;
+
+ zebra_register_activate (zh->service, 0);
return 0;
}
+
static void zebra_register_unlock (ZebraHandle zh)
{
+ if (zh->service->registerState != -1)
+ zebra_server_unlock (zh->service, zh->service->registerState);
+#if HAVE_SYS_TIMES_H
+ times (&zh->tms2);
+ logf (LOG_LOG, "user/system: %ld/%ld",
+ (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
+ (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
+
+#endif
}
ZebraHandle zebra_open (ZebraService zs)
assert (zs);
if (zs->stop_flag)
- {
- zh->errCode = 1019;
return 0;
- }
zh = (ZebraHandle) xmalloc (sizeof(*zh));
zs->sessions = zh;
zebra_mutex_cond_unlock (&zs->session_lock);
+
return zh;
}
-static int zebra_register_activate (ZebraService zh);
-static int zebra_register_deactivate (ZebraService zh);
ZebraService zebra_start (const char *configName)
{
zh->configName = xstrdup(configName);
zh->sessions = 0;
zh->stop_flag = 0;
- zh->active = 0;
- zebra_mutex_cond_init (&zh->session_lock);
- zebra_register_activate (zh);
- return zh;
-}
+ zh->active = 1;
+
+ zh->registerState = -1;
+ zh->registerChange = 0;
-static int zebra_register_activate (ZebraService zh)
-{
- if (zh->active)
- return 0;
- yaz_log (LOG_LOG, "zebra_register_activate");
if (!(zh->res = res_open (zh->configName)))
{
logf (LOG_WARN, "Failed to read resources `%s'", zh->configName);
- return -1;
+ return zh;
}
zebra_chdir (zh);
+ zebra_server_lock_init (zh);
+ zebra_mutex_cond_init (&zh->session_lock);
+ return zh;
+}
+
+static int zebra_register_activate (ZebraService zh, int rw)
+{
+ if (zh->active > 1)
+ return 0;
+ yaz_log (LOG_LOG, "zebra_register_activate shadow=%s",
+ zh->registerState ? "yes" : "no");
+
zh->dh = data1_create ();
if (!zh->dh)
return -1;
return -1;
}
bf_lockDir (zh->bfs, res_get (zh->res, "lockDir"));
+ bf_cache (zh->bfs, zh->registerState ? res_get (zh->res, "shadow") : NULL);
data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath"));
- zh->registerState = -1; /* trigger open of registers! */
- zh->registerChange = 0;
zh->recTypes = recTypes_init (zh->dh);
recTypes_default_handlers (zh->recTypes);
zh->dict = 0;
zh->sortIdx = 0;
zh->isams = 0;
+#if ZMBOL
zh->isam = 0;
zh->isamc = 0;
zh->isamd = 0;
+#endif
zh->zei = 0;
zebraRankInstall (zh, rank1_class);
passwd_db_file (zh->passwd_db, res_get (zh->res, "passwd"));
}
- if (!(zh->records = rec_open (zh->bfs, 1, 0)))
+ if (!(zh->records = rec_open (zh->bfs, rw, 0)))
{
logf (LOG_WARN, "rec_open");
return -1;
}
- if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 40, 1, 0)))
+ if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 80, rw, 0)))
{
logf (LOG_WARN, "dict_open");
return -1;
}
- if (!(zh->sortIdx = sortIdx_open (zh->bfs, 0)))
+ if (!(zh->sortIdx = sortIdx_open (zh->bfs, rw)))
{
logf (LOG_WARN, "sortIdx_open");
return -1;
if (res_get_match (zh->res, "isam", "s", ISAM_DEFAULT))
{
struct ISAMS_M_s isams_m;
- if (!(zh->isams = isams_open (zh->bfs, FNAME_ISAMS, 1,
+ if (!(zh->isams = isams_open (zh->bfs, FNAME_ISAMS, rw,
key_isams_m(zh->res, &isams_m))))
{
logf (LOG_WARN, "isams_open");
#if ZMBOL
else if (res_get_match (zh->res, "isam", "i", ISAM_DEFAULT))
{
- if (!(zh->isam = is_open (zh->bfs, FNAME_ISAM, key_compare, 1,
+ if (!(zh->isam = is_open (zh->bfs, FNAME_ISAM, key_compare, rw,
sizeof (struct it_key), zh->res)))
{
logf (LOG_WARN, "is_open");
{
struct ISAMC_M_s isamc_m;
if (!(zh->isamc = isc_open (zh->bfs, FNAME_ISAMC,
- 1, key_isamc_m(zh->res, &isamc_m))))
+ rw, key_isamc_m(zh->res, &isamc_m))))
{
logf (LOG_WARN, "isc_open");
return -1;
struct ISAMD_M_s isamd_m;
if (!(zh->isamd = isamd_open (zh->bfs, FNAME_ISAMD,
- 1, key_isamd_m(zh->res, &isamd_m))))
+ rw, key_isamd_m(zh->res, &isamd_m))))
{
logf (LOG_WARN, "isamd_open");
return -1;
}
#endif
zh->zei = zebraExplain_open (zh->records, zh->dh,
- zh->res, 1, 0 /* rGroup */,
+ zh->res, rw, 0 /* rGroup */,
explain_extract);
if (!zh->zei)
{
logf (LOG_WARN, "Cannot obtain EXPLAIN information");
return -1;
}
- zh->active = 1;
+ zh->active = 2;
yaz_log (LOG_LOG, "zebra_register_activate ok");
return 0;
}
void zebra_admin_shutdown (ZebraHandle zh)
{
+ zebra_register_lock (zh);
zebraExplain_flush (zh->service->zei, 1, zh);
extract_index (zh);
+ zebra_register_unlock (zh);
zebra_mutex_cond_lock (&zh->service->session_lock);
zh->service->stop_flag = 1;
if (!zh->service->sessions)
zebra_register_deactivate(zh->service);
+ zh->service->active = 0;
zebra_mutex_cond_unlock (&zh->service->session_lock);
}
zh->errCode = 0;
zebra_mutex_cond_lock (&zs->session_lock);
if (!zs->stop_flag)
- zebra_register_activate(zs);
+ zh->service->active = 1;
zebra_mutex_cond_unlock (&zs->session_lock);
}
static int zebra_register_deactivate (ZebraService zh)
{
zh->stop_flag = 0;
- if (!zh->active)
+ if (zh->active <= 1)
return 0;
yaz_log(LOG_LOG, "zebra_register_deactivate");
zebra_chdir (zh);
if (zh->records)
{
- zebraExplain_close (zh->zei, 1);
+ zebraExplain_close (zh->zei, 0);
dict_close (zh->dict);
sortIdx_close (zh->sortIdx);
if (zh->isams)
if (zh->passwd_db)
passwd_db_close (zh->passwd_db);
- res_close (zh->res);
- zh->active = 0;
+ zh->active = 1;
return 0;
}
zebra_mutex_cond_destroy (&zh->session_lock);
zebra_register_deactivate(zh);
+ res_close (zh->res);
xfree (zh->configName);
xfree (zh);
}
resultSetAddRPN (zh, stream, decode, query, num_bases, basenames, setname);
zebra_register_unlock (zh);
+
+ logf(LOG_APP,"SEARCH:%d:",zh->hits);
}
void zebra_records_retrieve (ZebraHandle zh, ODR stream,
int zebra_auth (ZebraService zh, const char *user, const char *pass)
{
if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass))
+ {
+ logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS");
return 0;
+ }
+
+ logf(LOG_APP,"AUTHFAIL:%s", user?user:"ANONYMOUS");
return 1;
}