-/* $Id: zebraapi.c,v 1.118 2004-03-29 15:48:14 adam Exp $
+/* $Id: zebraapi.c,v 1.120.2.20 2006-12-05 21:14:40 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
#include <assert.h>
#include <unistd.h>
#endif
+#include <yaz/log.h>
#include <yaz/diagbib1.h>
#include <yaz/pquery.h>
#include <yaz/sortspec.h>
#define ASSERTZHRES assert(zh && zh->service && zh->res)
#define ASSERTZS assert(zs)
-/* A simple log macro */
-/* don't break with older yazen that lack log_app2 */
-#ifdef LOG_APP2
#define LOG_API LOG_APP2
-#else
-#define LOG_API LOG_DEBUG
-#endif
static Res zebra_open_res (ZebraHandle zh);
static void zebra_close_res (ZebraHandle zh);
{
const char *dir ;
ASSERTZS;
- yaz_log(LOG_API,"zebra_chdir");
+ yaz_log(YLOG_DEBUG, "zebra_chdir");
dir = res_get (zs->global_res, "chdir");
if (!dir)
return;
- logf (LOG_DEBUG, "chdir %s", dir);
+ yaz_log(YLOG_DEBUG, "chdir %s", dir);
#ifdef WIN32
_chdir(dir);
#else
static void zebra_flush_reg (ZebraHandle zh)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_flush_reg");
+ yaz_log(YLOG_DEBUG, "zebra_flush_reg");
zh->errCode=0;
zebraExplain_flush (zh->reg->zei, zh);
ZebraHandle zh;
const char *default_encoding;
ASSERTZS;
- yaz_log(LOG_API,"zebra_open");
if (!zs)
return 0;
zh = (ZebraHandle) xmalloc (sizeof(*zh));
- yaz_log (LOG_DEBUG, "zebra_open zs=%p returns %p", zs, zh);
+ yaz_log(YLOG_DEBUG, "zebra_open zs=%p returns %p", zs, zh);
zh->service = zs;
zh->reg = 0; /* no register attached yet */
zh->iconv_to_utf8 =
yaz_iconv_open ("UTF-8", default_encoding);
if (zh->iconv_to_utf8 == 0)
- yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported",
+ yaz_log(YLOG_WARN, "iconv: %s to UTF-8 unsupported",
default_encoding);
zh->iconv_from_utf8 =
yaz_iconv_open (default_encoding, "UTF-8");
if (zh->iconv_to_utf8 == 0)
- yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported",
+ yaz_log(YLOG_WARN, "iconv: UTF-8 to %s unsupported",
default_encoding);
zebra_mutex_cond_lock (&zs->session_lock);
return zh;
}
-ZebraService zebra_start (const char *configName, Res def_res, Res over_res)
+ZebraService zebra_start (const char *configName)
+{
+ return zebra_start_res(configName, 0, 0);
+}
+
+ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
{
Res res;
- yaz_log(LOG_API|LOG_LOG,"zebra_start %s",configName);
+ yaz_log(YLOG_LOG, "zebra_start %s %s", configName, ZEBRAVER);
+
+ zebra_flock_init();
if ((res = res_open (configName, def_res, over_res)))
{
+ const char *passwd_plain = 0;
+ const char *passwd_encrypt = 0;
ZebraService zh = xmalloc (sizeof(*zh));
- yaz_log (LOG_DEBUG, "Read resources `%s'", configName);
+ yaz_log(YLOG_DEBUG, "Read resources `%s'", configName);
zh->global_res = res;
zh->configName = xstrdup(configName);
zebra_chdir (zh);
zebra_mutex_cond_init (&zh->session_lock);
- if (!res_get (zh->global_res, "passwd"))
+ passwd_plain = res_get (zh->global_res, "passwd");
+ passwd_encrypt = res_get (zh->global_res, "passwd.c");
+
+ if (!passwd_plain && !passwd_encrypt)
zh->passwd_db = NULL;
else
{
- zh->passwd_db = passwd_db_open ();
+ zh->passwd_db = passwd_db_open();
if (!zh->passwd_db)
- logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "passwd_db_open failed");
else
- passwd_db_file (zh->passwd_db,
- res_get (zh->global_res, "passwd"));
+ {
+ if (passwd_plain)
+ if (passwd_db_file_plain(zh->passwd_db, passwd_plain))
+ {
+ yaz_log(YLOG_WARN,
+ "Failed to read passwords %s (or unsupported)",
+ passwd_plain);
+ }
+ if (passwd_encrypt)
+ {
+ if (passwd_db_file_crypt(zh->passwd_db, passwd_encrypt))
+ {
+ yaz_log(YLOG_WARN,
+ "Failed to read encrypted pwds %s "
+ "(or unsupported)", passwd_encrypt);
+ }
+ }
+
+ }
}
zh->path_root = res_get (zh->global_res, "root");
return zh;
assert (res);
- yaz_log (LOG_LOG|LOG_API, "zebra_register_open rw = %d useshadow=%d p=%p,n=%s,rp=%s",
+ yaz_log(YLOG_LOG|YLOG_DEBUG, "zebra_register_open rw = %d useshadow=%d p=%p,n=%s,rp=%s",
rw, useshadow, reg, name, reg_path ? reg_path : "(none)");
reg->dh = data1_createx (DATA1_FLAG_XML);
getcwd(cwd, sizeof(cwd)-1);
profilePath = res_get_def(res, "profilePath", DEFAULT_PROFILE_PATH);
- yaz_log(LOG_LOG, "profilePath=%s cwd=%s", profilePath, cwd);
+ yaz_log(YLOG_LOG, "profilePath=%s cwd=%s", profilePath, cwd);
data1_set_tabpath (reg->dh, profilePath);
data1_set_tabroot (reg->dh, reg_path);
if (!(reg->records = rec_open (reg->bfs, rw, record_compression)))
{
- logf (LOG_WARN, "rec_open");
+ yaz_log(YLOG_WARN, "rec_open");
return 0;
}
if (rw)
}
if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0)))
{
- logf (LOG_WARN, "dict_open");
+ yaz_log(YLOG_WARN, "dict_open");
return 0;
}
if (!(reg->sortIdx = sortIdx_open (reg->bfs, rw)))
{
- logf (LOG_WARN, "sortIdx_open");
+ yaz_log(YLOG_WARN, "sortIdx_open");
return 0;
}
if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
if (!(reg->isams = isams_open (reg->bfs, FNAME_ISAMS, rw,
key_isams_m(res, &isams_m))))
{
- logf (LOG_WARN, "isams_open");
+ yaz_log(YLOG_WARN, "isams_open");
return 0;
}
}
if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw,
sizeof (struct it_key), res)))
{
- logf (LOG_WARN, "is_open");
+ yaz_log(YLOG_WARN, "is_open");
return 0;
}
}
if (!(reg->isamc = isc_open (reg->bfs, FNAME_ISAMC,
rw, key_isamc_m(res, &isamc_m))))
{
- logf (LOG_WARN, "isc_open");
+ yaz_log(YLOG_WARN, "isc_open");
return 0;
}
}
if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD,
rw, key_isamd_m(res, &isamd_m))))
{
- logf (LOG_WARN, "isamd_open");
+ yaz_log(YLOG_WARN, "isamd_open");
return 0;
}
}
if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
rw, key_isamc_m(res, &isamc_m), 0)))
{
- logf (LOG_WARN, "isamb_open");
+ yaz_log(YLOG_WARN, "isamb_open");
return 0;
}
}
if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
rw, key_isamc_m(res, &isamc_m), 1)))
{
- logf (LOG_WARN, "isamb_open");
+ yaz_log(YLOG_WARN, "isamb_open");
return 0;
}
}
if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
rw, key_isamc_m(res, &isamc_m), -1)))
{
- logf (LOG_WARN, "isamb_open");
+ yaz_log(YLOG_WARN, "isamb_open");
return 0;
}
}
explain_extract);
if (!reg->zei)
{
- logf (LOG_WARN, "Cannot obtain EXPLAIN information");
+ yaz_log(YLOG_WARN, "Cannot obtain EXPLAIN information");
return 0;
}
reg->active = 2;
- yaz_log (LOG_DEBUG, "zebra_register_open ok p=%p", reg);
+ yaz_log(YLOG_DEBUG, "zebra_register_open ok p=%p", reg);
return reg;
}
int zebra_admin_shutdown (ZebraHandle zh)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_shutdown");
+ yaz_log(YLOG_DEBUG, "zebra_admin_shutdown");
zh->errCode=0;
zebra_mutex_cond_lock (&zh->service->session_lock);
{
ZebraService zs;
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_start");
+ yaz_log(YLOG_DEBUG, "zebra_admin_start");
zh->errCode=0;
zs = zh->service;
zebra_mutex_cond_lock (&zs->session_lock);
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
{
ASSERTZS;
- yaz_log(LOG_LOG|LOG_API, "zebra_register_close p=%p", reg);
+ yaz_log(YLOG_LOG|YLOG_DEBUG, "zebra_register_close p=%p", reg);
reg->stop_flag = 0;
zebra_chdir (zs);
if (reg->records)
{
if (!zs)
return 0;
- yaz_log (LOG_LOG|LOG_API, "zebra_stop");
+ yaz_log(YLOG_LOG|YLOG_DEBUG, "zebra_stop");
while (zs->sessions)
{
struct zebra_session **sp;
int i;
- yaz_log(LOG_API,"zebra_close");
+ yaz_log(YLOG_DEBUG, "zebra_close");
if (!zh)
return 0;
ASSERTZH;
zh->errCode=0;
zs = zh->service;
- yaz_log (LOG_DEBUG, "zebra_close zh=%p", zh);
+ yaz_log(YLOG_DEBUG, "zebra_close zh=%p", zh);
resultSetDestroy (zh, -1, 0, 0);
if (zh->reg)
}
else
{
- yaz_log (LOG_WARN, "no register root specified");
+ yaz_log(YLOG_WARN, "no register root specified");
return 0; /* no path for register - fail! */
}
return res;
res_set (zh->res, "lockDir", zh->path_reg);
sprintf (fname, "norm.%s.LCK", zh->reg_name);
zh->lock_normal =
- zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
+ zebra_lock_create (res_get(zh->res, "lockDir"), fname);
sprintf (fname, "shadow.%s.LCK", zh->reg_name);
zh->lock_shadow =
- zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
+ zebra_lock_create (res_get(zh->res, "lockDir"), fname);
+ if (!zh->lock_normal || !zh->lock_shadow)
+ {
+ if (zh->lock_normal)
+ {
+ zebra_lock_destroy(zh->lock_normal);
+ zh->lock_normal = 0;
+ }
+ if (zh->lock_shadow)
+ {
+ zebra_lock_destroy(zh->lock_shadow);
+ zh->lock_shadow = 0;
+ }
+ zebra_close_res(zh);
+
+ return -1;
+ }
}
return 1;
}
struct map_baseinfo *p = &info;
int i;
ASSERTZH;
- yaz_log(LOG_API,"map_basenames ");
+ yaz_log(YLOG_DEBUG, "map_basenames ");
zh->errCode=0;
info.zh = zh;
*num_bases = info.new_num_bases;
*basenames = info.new_basenames;
for (i = 0; i<*num_bases; i++)
- logf (LOG_LOG, "base %s", (*basenames)[i]);
+ yaz_log(YLOG_LOG, "base %s", (*basenames)[i]);
+}
+
+int zebra_select_default_database(ZebraHandle zh)
+{
+ if (!zh->res)
+ {
+ /* no database has been selected - so we select based on
+ resource setting (including group)
+ */
+ const char *group = res_get(zh->service->global_res, "group");
+ const char *v = res_get_prefix(zh->service->global_res,
+ "database", group, "Default");
+ return zebra_select_database(zh, v);
+ }
+ return 0;
}
int zebra_select_database (ZebraHandle zh, const char *basename)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_select_database %s",basename);
- zh->errCode=0;
+ yaz_log(YLOG_DEBUG, "zebra_select_database %s",basename);
return zebra_select_databases (zh, 1, &basename);
}
int len = 0;
char *new_reg = 0;
ASSERTZH;
- yaz_log(LOG_API,"zebra_select_databases n=%d [0]=%s",
+ yaz_log(YLOG_DEBUG, "zebra_select_databases n=%d [0]=%s",
num_bases,basenames[0]);
- zh->errCode=0;
+ zebra_clearError(zh);
if (num_bases < 1)
{
Z_RPNQuery *query, const char *setname, int *hits)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_search_rpn");
- zh->errCode=0;
+ yaz_log(YLOG_DEBUG, "zebra_search_rpn");
+
+ zebra_clearError(zh);
zh->hits = 0;
*hits = 0;
ZebraPosSet poset;
int i, *pos_array, ret = 0;
ASSERTZH;
- yaz_log(LOG_API,"zebra_records_retrieve n=%d",num_recs);
- zh->errCode=0;
+ yaz_log(YLOG_DEBUG, "zebra_records_retrieve n=%d",num_recs);
+
+ zebra_clearError(zh);
if (!zh->res)
{
return -1;
}
- zh->errCode = 0;
-
if (zebra_begin_read (zh))
return -1;
poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
if (!poset)
{
- logf (LOG_DEBUG, "zebraPosSetCreate error");
+ yaz_log(YLOG_DEBUG, "zebraPosSetCreate error");
zh->errCode = 30;
zh->errString = nmem_strdup (stream->mem, setname);
ret = -1;
int *is_partial)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_scan");
+ yaz_log(YLOG_DEBUG, "zebra_scan");
zh->errCode=0;
if (zebra_begin_read (zh))
{
int *sort_status)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_sort");
+ yaz_log(YLOG_DEBUG, "zebra_sort");
zh->errCode=0;
if (zebra_begin_read (zh))
return 1;
{
int i, status;
ASSERTZH;
- yaz_log(LOG_API,"zebra_deleleResultSet n=%d",num_setnames);
+ yaz_log(YLOG_DEBUG, "zebra_deleleResultSet n=%d",num_setnames);
zh->errCode=0;
if (zebra_begin_read(zh))
return Z_DeleteStatus_systemProblemAtTarget;
switch (function)
{
- case Z_DeleteRequest_list:
+ case Z_DeleteResultSetRequest_list:
resultSetDestroy (zh, num_setnames, setnames, statuses);
break;
- case Z_DeleteRequest_all:
+ case Z_DeleteResultSetRequest_all:
resultSetDestroy (zh, -1, 0, statuses);
break;
}
{
if (zh)
{
- yaz_log(LOG_API,"zebra_errCode: %d",zh->errCode);
+ yaz_log(YLOG_DEBUG, "zebra_errCode: %d",zh->errCode);
return zh->errCode;
}
- yaz_log(LOG_API,"zebra_errCode: o");
+ yaz_log(YLOG_DEBUG, "zebra_errCode: o");
return 0;
}
const char *e="";
if (zh)
e= diagbib1_str (zh->errCode);
- yaz_log(LOG_API,"zebra_errString: %s",e);
+ yaz_log(YLOG_DEBUG, "zebra_errString: %s",e);
return e;
}
char *a="";
if (zh)
a= zh->errString;
- yaz_log(LOG_API,"zebra_errAdd: %s",a);
+ yaz_log(YLOG_DEBUG, "zebra_errAdd: %s",a);
return a;
}
xfree (zh->user_perm);
zh->user_perm = xstrdup(p ? p : "r");
+ yaz_log(YLOG_LOG, "User perm for %s: %s", u, zh->user_perm);
+
/* users that don't require a password .. */
if (zh->user_perm && strchr(zh->user_perm, 'a'))
return 0;
const char *record_type)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_import_begin db=%s rt=%s",
+ yaz_log(YLOG_DEBUG, "zebra_admin_import_begin db=%s rt=%s",
database, record_type);
zh->errCode=0;
if (zebra_select_database(zh, database))
int zebra_admin_import_end (ZebraHandle zh)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_import_end");
+ yaz_log(YLOG_DEBUG, "zebra_admin_import_end");
zh->errCode=0;
zebra_end_trans (zh);
return 0;
int sysno;
int i;
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_import_segment");
+ yaz_log(YLOG_DEBUG, "zebra_admin_import_segment");
zh->errCode=0;
for (i = 0; i<segment->num_segmentRecords; i++)
{
&sysno,
0, /* match */
0, /* fname */
- oct->buf, oct->len,
+ (char *) oct->buf, oct->len,
0);
}
}
char *rinfo = 0;
char recid_z[256];
ASSERTZH;
- yaz_log(LOG_API,"zebra_admin_exchange_record ac=%d", action);
+ yaz_log(YLOG_DEBUG, "zebra_admin_exchange_record ac=%d", action);
zh->errCode=0;
if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z))
return 0;
}
-int zebra_drop_database (ZebraHandle zh, const char *database)
+int zebra_drop_database (ZebraHandle zh, const char *database)
{
int ret = 0;
ASSERTZH;
- yaz_log(LOG_API,"zebra_drop_database");
- zh->errCode = 0;
+ yaz_log(YLOG_DEBUG, "zebra_drop_database");
+
+ zebra_clearError(zh);
if (zebra_select_database (zh, database))
return -1;
}
else
{
- yaz_log(LOG_WARN, "drop database only supported for isam:b");
+ yaz_log(YLOG_WARN, "drop database only supported for isam:b");
ret = -1;
}
zebra_end_trans (zh);
int zebra_create_database (ZebraHandle zh, const char *database)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_create_database");
+ yaz_log(YLOG_DEBUG, "zebra_create_database");
zh->errCode=0;
if (zebra_select_database (zh, database))
{
WRBUF wrbuf;
ASSERTZH;
- yaz_log(LOG_API,"zebra_string_norm ");
+ yaz_log(YLOG_DEBUG, "zebra_string_norm ");
zh->errCode=0;
if (!zh->reg->zebra_maps)
return -1;
long p = getpid();
FILE *f;
ASSERTZH;
- yaz_log(LOG_API,"zebra_set_state v=%d seq=%d", val, seqno);
+ yaz_log(YLOG_DEBUG, "zebra_set_state v=%d seq=%d", val, seqno);
zh->errCode=0;
sprintf (state_fname, "state.%s.LCK", zh->reg_name);
fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
f = fopen (fname, "w");
- yaz_log (LOG_DEBUG, "%c %d %ld", val, seqno, p);
+ yaz_log(YLOG_DEBUG, "%c %d %ld", val, seqno, p);
fprintf (f, "%c %d %ld\n", val, seqno, p);
fclose (f);
xfree (fname);
FILE *f;
ASSERTZH;
- yaz_log(LOG_API,"zebra_get_state ");
+ yaz_log(YLOG_DEBUG, "zebra_get_state ");
zh->errCode=0;
sprintf (state_fname, "state.%s.LCK", zh->reg_name);
fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
int zebra_begin_trans (ZebraHandle zh, int rw)
{
+ zebra_select_default_database(zh);
if (!zh->res)
{
zh->errCode = 2;
return -1;
}
ASSERTZHRES;
- yaz_log(LOG_API,"zebra_begin_trans rw=%d",rw);
+ yaz_log(YLOG_DEBUG, "zebra_begin_trans rw=%d",rw);
if (zh->user_perm)
{
(zh->trans_no++);
if (zh->trans_w_no)
+ {
+ read_res_for_transaction(zh);
return 0;
+ }
if (zh->trans_no != 1)
{
zh->errCode = 2;
zebra_get_state (zh, &val, &seqno);
if (val == 'c')
{
- yaz_log (LOG_LOG, "previous transaction didn't finish commit");
+ yaz_log(YLOG_LOG, "previous transaction didn't finish commit");
zebra_unlock (zh->lock_shadow);
zebra_unlock (zh->lock_normal);
zebra_commit (zh);
{
BFiles bfs = bfs_create (res_get (zh->res, "shadow"),
zh->path_reg);
- yaz_log (LOG_LOG, "previous transaction didn't reach commit");
+ yaz_log(YLOG_LOG, "previous transaction didn't reach commit");
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
}
else
{
- yaz_log (LOG_WARN, "your previous transaction didn't finish");
+ yaz_log(YLOG_WARN, "your previous transaction didn't finish");
}
}
break;
}
if (pass == 2)
{
- yaz_log (LOG_FATAL, "zebra_begin_trans couldn't finish commit");
+ yaz_log(YLOG_FATAL, "zebra_begin_trans couldn't finish commit");
abort();
return -1;
}
zh->errCode = 2;
zh->errString = "zebra_begin_trans: cannot open register";
- yaz_log(LOG_FATAL, zh->errString);
+ yaz_log(YLOG_FATAL, zh->errString);
return -1;
}
}
dirty = 1;
else if (seqno != zh->reg->seqno)
{
- yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d",
+ yaz_log(YLOG_LOG, "reopen seqno cur/old %d/%d",
seqno, zh->reg->seqno);
dirty = 1;
}
else if (zh->reg->last_val != val)
{
- yaz_log (LOG_LOG, "reopen last cur/old %d/%d",
+ yaz_log(YLOG_LOG, "reopen last cur/old %d/%d",
val, zh->reg->last_val);
dirty = 1;
}
int zebra_end_trans (ZebraHandle zh)
{
ZebraTransactionStatus dummy;
- yaz_log(LOG_API,"zebra_end_trans");
+ yaz_log(YLOG_DEBUG, "zebra_end_trans");
return zebra_end_transaction(zh, &dummy);
}
const char *rval;
ASSERTZH;
- yaz_log(LOG_API,"zebra_end_transaction");
+ yaz_log(YLOG_DEBUG, "zebra_end_transaction");
status->processed = 0;
status->inserted = 0;
zh->trans_no--;
zh->trans_w_no = 0;
- yaz_log (LOG_LOG, "zebra_end_trans");
+ yaz_log(YLOG_LOG, "zebra_end_trans");
rval = res_get (zh->res, "shadow");
zebraExplain_runNumberIncrement (zh->reg->zei, 1);
zebra_register_close (zh->service, zh->reg);
zh->reg = 0;
- yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
+ yaz_log(YLOG_LOG, "Records: %7d i/u/d %d/%d/%d",
zh->records_processed, zh->records_inserted,
zh->records_updated, zh->records_deleted);
if (val != 'd')
{
BFiles bfs = bfs_create (rval, zh->path_reg);
- yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val);
+ yaz_log(YLOG_LOG, "deleting shadow stuff val=%c", val);
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
}
}
#if HAVE_SYS_TIMES_H
times (&zh->tms2);
- logf (LOG_LOG, "user/system: %ld/%ld",
+ yaz_log(YLOG_LOG, "user/system: %ld/%ld",
(long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
(long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
{
ASSERTZH;
zh->errCode=0;
- logf (LOG_LOG|LOG_API, "updating %s", path);
repositoryUpdate (zh, path);
return zh->errCode;
}
{
ASSERTZH;
zh->errCode=0;
- logf (LOG_LOG|LOG_API, "deleting %s", path);
repositoryDelete (zh, path);
return zh->errCode;
}
int zebra_repository_show (ZebraHandle zh, const char *path)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_repository_show");
zh->errCode=0;
repositoryShow (zh, path);
return zh->errCode;
ASSERTZH;
zh->errCode=0;
+ zebra_select_default_database(zh);
if (!zh->res)
{
zh->errCode = 109;
rval = res_get (zh->res, "shadow");
if (!rval)
{
- logf (LOG_WARN, "Cannot perform commit");
- logf (LOG_WARN, "No shadow area defined");
+ yaz_log(YLOG_WARN, "Cannot perform commit");
+ yaz_log(YLOG_WARN, "No shadow area defined");
return 0;
}
zebra_get_state (zh, &val, &seqno);
+ if (val == 'd')
+ {
+ yaz_log(YLOG_WARN, "previous transaction didn't reach commit");
+ clean_only = 1;
+ }
+
if (rval && *rval)
bf_cache (bfs, rval);
if (bf_commitExists (bfs))
{
zebra_set_state (zh, 'c', seqno);
- logf (LOG_LOG, "commit start");
+ yaz_log(YLOG_LOG, "commit start");
bf_commitExec (bfs);
-#ifndef WIN32
- sync ();
-#endif
}
- logf (LOG_LOG, "commit clean");
- bf_commitClean (bfs, rval);
seqno++;
zebra_set_state (zh, 'o', seqno);
+
+ zebra_unlock (zh->lock_shadow);
+ zebra_unlock (zh->lock_normal);
+
+ zebra_lock_w(zh->lock_shadow);
+ bf_commitClean (bfs, rval);
+ zebra_unlock (zh->lock_shadow);
}
else
{
- logf (LOG_LOG, "nothing to commit");
+ zebra_unlock (zh->lock_shadow);
+ zebra_unlock (zh->lock_normal);
+ yaz_log(YLOG_LOG, "nothing to commit");
}
bfs_destroy (bfs);
- zebra_unlock (zh->lock_shadow);
- zebra_unlock (zh->lock_normal);
return 0;
}
int zebra_clean (ZebraHandle zh)
{
- yaz_log(LOG_API,"zebra_clean");
+ yaz_log(YLOG_DEBUG, "zebra_clean");
return zebra_commit_ex(zh, 1);
}
int zebra_commit (ZebraHandle zh)
{
- yaz_log(LOG_API,"zebra_commit");
+ yaz_log(YLOG_DEBUG, "zebra_commit");
return zebra_commit_ex(zh, 0);
}
const char *rval;
BFiles bfs = 0;
ASSERTZH;
- yaz_log(LOG_API,"zebra_init");
+ yaz_log(YLOG_DEBUG, "zebra_init");
zh->errCode=0;
+ zebra_select_default_database(zh);
if (!zh->res)
{
zh->errCode = 109;
}
rval = res_get (zh->res, "shadow");
- bfs = bfs_create (res_get (zh->service->global_res, "register"),
- zh->path_reg);
+ bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
+ if (!bfs)
+ return -1;
if (rval && *rval)
bf_cache (bfs, rval);
{
BFiles bfs;
ASSERTZH;
- yaz_log(LOG_API,"zebra_compact");
+ yaz_log(YLOG_DEBUG, "zebra_compact");
zh->errCode=0;
if (!zh->res)
{
int zebra_result (ZebraHandle zh, int *code, char **addinfo)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_result");
+ yaz_log(YLOG_DEBUG, "zebra_result");
*code = zh->errCode;
*addinfo = zh->errString;
return 0;
int zebra_shadow_enable (ZebraHandle zh, int value)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_shadow_enable");
+ yaz_log(YLOG_DEBUG, "zebra_shadow_enable");
zh->errCode=0;
zh->shadow_enable = value;
return 0;
int zebra_record_encoding (ZebraHandle zh, const char *encoding)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_record_encoding");
+ yaz_log(YLOG_DEBUG, "zebra_record_encoding");
zh->errCode=0;
xfree (zh->record_encoding);
zh->record_encoding = xstrdup (encoding);
- logf(LOG_DEBUG, "Reset record encoding: %s", encoding);
+ yaz_log(YLOG_DEBUG, "Reset record encoding: %s", encoding);
zh->iconv_to_utf8 =
yaz_iconv_open ("UTF-8", encoding);
if (zh->iconv_to_utf8 == 0)
- yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported", encoding);
+ yaz_log(YLOG_WARN, "iconv: %s to UTF-8 unsupported", encoding);
zh->iconv_from_utf8 =
yaz_iconv_open (encoding, "UTF-8");
if (zh->iconv_to_utf8 == 0)
- yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported", encoding);
+ yaz_log(YLOG_WARN, "iconv: UTF-8 to %s unsupported", encoding);
return 0;
}
int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_set_resource %s:%s",name,value);
+ yaz_log(YLOG_DEBUG, "zebra_set_resource %s:%s",name,value);
zh->errCode=0;
res_set(zh->res, name, value);
return 0;
ASSERTZH;
v= res_get_def( zh->res, name, (char *)defaultvalue);
zh->errCode=0;
- yaz_log(LOG_API,"zebra_get_resource %s:%s",name,v);
+ yaz_log(YLOG_DEBUG, "zebra_get_resource %s:%s",name,v);
return v;
}
int zebra_trans_no (ZebraHandle zh)
{
ASSERTZH;
- yaz_log(LOG_API,"zebra_trans_no");
+ yaz_log(YLOG_DEBUG, "zebra_trans_no");
return zh->trans_no;
}
int zebra_get_shadow_enable (ZebraHandle zh)
{
- yaz_log(LOG_API,"zebra_get_shadow_enable");
+ yaz_log(YLOG_DEBUG, "zebra_get_shadow_enable");
return (zh->shadow_enable);
}
int zebra_set_shadow_enable (ZebraHandle zh, int value)
{
- yaz_log(LOG_API,"zebra_set_shadow_enable %d",value);
+ yaz_log(YLOG_DEBUG, "zebra_set_shadow_enable %d",value);
zh->shadow_enable = value;
return 0;
}
{
ZebraPosSet poset;
int i, *pos_array;
- yaz_log(LOG_API,"api_records_retrieve s=%s n=%d",setname,num_recs);
+ yaz_log(YLOG_DEBUG, "api_records_retrieve s=%s n=%d",setname,num_recs);
if (!zh->res)
{
poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
if (!poset)
{
- logf (LOG_DEBUG, "zebraPosSetCreate error");
+ yaz_log(YLOG_DEBUG, "zebraPosSetCreate error");
zh->errCode = 30;
zh->errString = nmem_strdup (stream->mem, setname);
}
int zebra_insert_record (ZebraHandle zh,
const char *recordType,
int *sysno, const char *match, const char *fname,
- const char *buf, int buf_size)
+ const char *buf, int buf_size, int force_update)
{
int res;
- yaz_log(LOG_API,"zebra_insert_record sysno=%d", *sysno);
+ yaz_log(YLOG_DEBUG, "zebra_insert_record sysno=%d", *sysno);
if (buf_size < 1) buf_size = strlen(buf);
{
int res;
- yaz_log(LOG_API,"zebra_update_record sysno=%d", *sysno);
+ yaz_log(YLOG_DEBUG, "zebra_update_record sysno=%d", *sysno);
if (buf_size < 1) buf_size = strlen(buf);
match, fname,
force_update,
1); /* allow_update */
+ yaz_log(YLOG_LOG, "zebra_update_record returned res=%d", res);
zebra_end_trans(zh);
return res;
}
int force_update)
{
int res;
- yaz_log(LOG_API,"zebra_delete_record sysno=%d", *sysno);
+ yaz_log(YLOG_DEBUG, "zebra_delete_record sysno=%d", *sysno);
if (buf_size < 1) buf_size = strlen(buf);
Z_RPNQuery *query;
ODR odr = odr_createmem(ODR_ENCODE);
- yaz_log(LOG_API,"zebra_search_PQF s=%s q=%s",setname, pqf_query);
+ yaz_log(YLOG_DEBUG, "zebra_search_PQF s=%s q=%s",setname, pqf_query);
query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
if (!query)
- yaz_log (LOG_WARN, "bad query %s\n", pqf_query);
+ yaz_log(YLOG_WARN, "bad query %s\n", pqf_query);
else
res=zebra_search_RPN (zh, odr, query, setname, &hits);
odr_destroy(odr);
- yaz_log(LOG_API,"Hits: %d",hits);
+ yaz_log(YLOG_DEBUG, "Hits: %d",hits);
if (numhits)
*numhits=hits;
int num_input_setnames = 0;
int sort_status = 0;
Z_SortKeySpecList *sort_sequence = yaz_sort_spec (stream, sort_spec);
- yaz_log(LOG_API,"sort (FIXME) ");
+ yaz_log(YLOG_DEBUG, "sort (FIXME) ");
if (!sort_sequence)
{
- logf(LOG_WARN,"invalid sort specs '%s'", sort_spec);
+ yaz_log(YLOG_WARN, "invalid sort specs '%s'", sort_spec);
zh->errCode = 207;
return -1;
}
zebra_end_read(zh);
return sort_status;
}
+
+void zebra_lock_prefix (Res res, char *path)
+{
+ const char *lock_dir = res_get_def (res, "lockDir", "");
+
+ strcpy (path, lock_dir);
+ if (*path && path[strlen(path)-1] != '/')
+ strcat (path, "/");
+}
+