-/* $Id: zebraapi.c,v 1.201 2006-02-09 08:31:02 adam Exp $
+/* $Id: zebraapi.c,v 1.208 2006-03-29 10:43:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
int rw, int useshadow,
Res res,
const char *reg_path);
-static void zebra_register_close (ZebraService zs, struct zebra_register *reg);
+static void zebra_register_close(ZebraService zs, struct zebra_register *reg);
ZebraHandle zebra_open(ZebraService zs, Res res)
{
const char *passwd_plain = 0;
const char *passwd_encrypt = 0;
const char *dbaccess = 0;
- ZebraService zh = xmalloc(sizeof(*zh));
+ ZebraService zh = 0;
if (configName)
- res_read_file(res, configName);
-
+ {
+ ZEBRA_RES ret = res_read_file(res, configName);
+ if (ret != ZEBRA_OK)
+ {
+ res_close(res);
+ return 0;
+ }
+ }
+ zh = xmalloc(sizeof(*zh));
zh->global_res = res;
zh->sessions = 0;
const char *recordCompression = 0;
const char *profilePath;
char cwd[1024];
+ ZEBRA_RES ret = ZEBRA_OK;
ASSERTZS;
yaz_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);
+ reg->dh = data1_create();
if (!reg->dh)
{
+ xfree(reg->name);
xfree(reg);
return 0;
}
if (!reg->bfs)
{
data1_destroy(reg->dh);
+ xfree(reg->name);
xfree(reg);
return 0;
}
{
bfs_destroy(reg->bfs);
data1_destroy(reg->dh);
+ xfree(reg->name);
xfree(reg);
return 0;
}
data1_set_tabroot (reg->dh, reg_path);
reg->recTypes = recTypes_init (zs->record_classes, reg->dh);
- reg->zebra_maps = zebra_maps_open (res, reg_path);
+ reg->zebra_maps =
+ zebra_maps_open(res, reg_path, profilePath);
+ if (!reg->zebra_maps)
+ {
+ recTypes_destroy(reg->recTypes);
+ bfs_destroy(reg->bfs);
+ data1_destroy(reg->dh);
+ xfree(reg->name);
+ xfree(reg);
+ return 0;
+ }
reg->rank_classes = NULL;
reg->key_buf = 0;
if (!strcmp (recordCompression, "bzip2"))
record_compression = REC_COMPRESS_BZIP2;
+ if (1)
+ {
+ const char *index_fname = res_get_def(res, "index", "default.idx");
+ if (index_fname && *index_fname)
+ {
+ if (zebra_maps_read_file(reg->zebra_maps, index_fname) != ZEBRA_OK)
+ ret = ZEBRA_FAIL;
+ }
+ }
+
if (!(reg->records = rec_open (reg->bfs, rw, record_compression)))
{
yaz_log (YLOG_WARN, "rec_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
if (rw)
{
if (!(reg->dict = dict_open_res (reg->bfs, FNAME_DICT, 40, rw, 0, res)))
{
yaz_log (YLOG_WARN, "dict_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
if (!(reg->sortIdx = sortIdx_open (reg->bfs, rw)))
{
yaz_log (YLOG_WARN, "sortIdx_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
{
key_isams_m(res, &isams_m))))
{
yaz_log (YLOG_WARN, "isams_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
}
if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
rw, key_isamc_m(res, &isamc_m))))
{
yaz_log (YLOG_WARN, "isamc_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
}
if (res_get_match (res, "isam", "b", ISAM_DEFAULT))
rw, key_isamc_m(res, &isamc_m), 0)))
{
yaz_log (YLOG_WARN, "isamb_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
}
if (res_get_match (res, "isam", "bc", ISAM_DEFAULT))
rw, key_isamc_m(res, &isamc_m), 1)))
{
yaz_log (YLOG_WARN, "isamb_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
}
if (res_get_match (res, "isam", "null", ISAM_DEFAULT))
rw, key_isamc_m(res, &isamc_m), -1)))
{
yaz_log (YLOG_WARN, "isamb_open failed");
- return 0;
+ ret = ZEBRA_FAIL;
}
}
- reg->zei = zebraExplain_open (reg->records, reg->dh,
- res, rw, reg,
- explain_extract);
- if (!reg->zei)
+ if (reg->records)
{
- yaz_log (YLOG_WARN, "Cannot obtain EXPLAIN information");
+ reg->zei = zebraExplain_open(reg->records, reg->dh,
+ res, rw, reg,
+ explain_extract);
+ if (!reg->zei)
+ {
+ yaz_log (YLOG_WARN, "Cannot obtain EXPLAIN information");
+ ret = ZEBRA_FAIL;
+ }
+ }
+
+ if (ret != ZEBRA_OK)
+ {
+ zebra_register_close(zs, reg);
return 0;
}
-
- reg->active = 2;
yaz_log (YLOG_DEBUG, "zebra_register_open ok p=%p", reg);
return reg;
}
return ZEBRA_OK;
}
-static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
+static void zebra_register_close(ZebraService zs, struct zebra_register *reg)
{
ASSERTZS;
assert(reg);
yaz_log(YLOG_DEBUG, "zebra_register_close p=%p", reg);
reg->stop_flag = 0;
zebra_chdir (zs);
- if (reg->records)
- {
- zebraExplain_close (reg->zei);
- dict_close (reg->dict);
- if (reg->matchDict)
- dict_close (reg->matchDict);
- sortIdx_close (reg->sortIdx);
- if (reg->isams)
- isams_close (reg->isams);
- if (reg->isamc)
- isamc_close (reg->isamc);
- if (reg->isamb)
- isamb_close (reg->isamb);
- rec_close (®->records);
- }
+
+ zebraExplain_close (reg->zei);
+ dict_close (reg->dict);
+ if (reg->matchDict)
+ dict_close (reg->matchDict);
+ sortIdx_close (reg->sortIdx);
+ if (reg->isams)
+ isams_close (reg->isams);
+ if (reg->isamc)
+ isamc_close (reg->isamc);
+ if (reg->isamb)
+ isamb_close (reg->isamb);
+ rec_close (®->records);
recTypes_destroy (reg->recTypes);
zebra_maps_close (reg->zebra_maps);
resultSetDestroy (zh, -1, 0, 0);
if (zh->reg)
- zebra_register_close (zh->service, zh->reg);
+ zebra_register_close(zh->service, zh->reg);
zebra_close_res (zh);
res_close(zh->session_res);
if (zh->reg)
{
resultSetInvalidate (zh);
- zebra_register_close (zh->service, zh->reg);
+ zebra_register_close(zh->service, zh->reg);
zh->reg = 0;
}
zebra_close_res(zh);
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->reg)
{
resultSetInvalidate (zh);
- zebra_register_close (zh->service, zh->reg);
+ zebra_register_close(zh->service, zh->reg);
}
zh->trans_w_no = zh->trans_no;
yaz_log (YLOG_WARN, "previous transaction didn't reach commit");
bf_commitClean (bfs, rval);
bfs_destroy (bfs);
- }
+ }
else
{
yaz_log (YLOG_WARN, "your previous transaction didn't finish");
if (zh->reg)
{
resultSetInvalidate (zh);
- zebra_register_close (zh->service, zh->reg);
+ zebra_register_close(zh->service, zh->reg);
}
zh->reg = zebra_register_open(zh->service, zh->reg_name,
0, val == 'c' ? 1 : 0,
resultSetInvalidate (zh);
- zebra_register_close (zh->service, zh->reg);
+ zebra_register_close(zh->service, zh->reg);
zh->reg = 0;
yaz_log (YLOG_LOG, "Records: "ZINT_FORMAT" i/u/d "
zh->errString = nmem_strdup(zh->nmem_error, vstr);
}
+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, "/");
+}
+