* Copyright (C) 1995-2002, Index Data
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
- * $Id: index.h,v 1.73 2002-02-20 17:30:01 adam Exp $
+ * $Id: index.h,v 1.74 2002-03-21 10:25:42 adam Exp $
*/
#ifndef INDEX_H
#define FNAME_TOUCH_TIME "zebraidx.time"
typedef struct zebra_lock_info *ZebraLockHandle;
-ZebraLockHandle zebra_lock_create(const char *file, int excl_flag);
+ZebraLockHandle zebra_lock_create(const char *dir,
+ const char *file, int excl_flag);
void zebra_lock_destroy (ZebraLockHandle h);
int zebra_lock (ZebraLockHandle h);
int zebra_lock_nb (ZebraLockHandle h);
int zebra_unlock (ZebraLockHandle h);
int zebra_lock_fd (ZebraLockHandle h);
void zebra_lock_prefix (Res res, char *dst);
+char *zebra_mk_fname (const char *dir, const char *name);
int zebra_lock_w (ZebraLockHandle h);
int zebra_lock_r (ZebraLockHandle h);
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: lockutil.c,v 1.13 2002-02-20 17:30:01 adam Exp $
+ * $Id: lockutil.c,v 1.14 2002-03-21 10:25:42 adam Exp $
*/
#include <stdio.h>
#include <assert.h>
int excl_flag;
};
-ZebraLockHandle zebra_lock_create (const char *name, int excl_flag)
+char *zebra_mk_fname (const char *dir, const char *name)
{
+ int dlen = dir ? strlen(dir) : 0;
+ char *fname = xmalloc (dlen + strlen(name) + 3);
+
+#ifdef WIN32
+ if (dlen)
+ {
+ int last_one = dir[dlen-1];
+
+ if (!strchr ("/\\:", last_one))
+ sprintf (fname, "%s\\%s", dir, name);
+ else
+ sprintf (fname, "%s%s", dir, name);
+ }
+ else
+ sprintf (fname, "%s", name);
+#else
+ if (dlen)
+ {
+ int last_one = dir[dlen-1];
+
+ if (!strchr ("/", last_one))
+ sprintf (fname, "%s/%s", dir, name);
+ else
+ sprintf (fname, "%s%s", dir, name);
+ }
+ else
+ sprintf (fname, "%s", name);
+#endif
+ return fname;
+}
+
+ZebraLockHandle zebra_lock_create (const char *dir,
+ const char *name, int excl_flag)
+{
+ int dlen = dir ? strlen(dir) : 0;
+ char *fname = zebra_mk_fname(dir, name);
ZebraLockHandle h = (ZebraLockHandle) xmalloc (sizeof(*h));
+
h->excl_flag = excl_flag;
h->fd = -1;
+
+
#ifdef WIN32
if (!h->excl_flag)
h->fd = open (name, O_BINARY|O_RDONLY);
if (h->fd == -1)
- h->fd = open (name, ((h->excl_flag > 1) ? O_EXCL : 0)|
+ h->fd = open (fname, ((h->excl_flag > 1) ? O_EXCL : 0)|
(O_BINARY|O_CREAT|O_RDWR), 0666);
#else
- h->fd= open (name, ((h->excl_flag > 1) ? O_EXCL : 0)|
+ h->fd= open (fname, ((h->excl_flag > 1) ? O_EXCL : 0)|
(O_BINARY|O_CREAT|O_RDWR|O_SYNC), 0666);
#endif
if (h->fd == -1)
{
if (h->excl_flag <= 1)
- logf (LOG_WARN|LOG_ERRNO, "open %s", name);
+ logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
xfree (h);
- return NULL;
+ h = 0;
}
+ xfree (fname);
return h;
}
* Copyright (C) 1995-2002, Index Data
* All rights reserved.
*
- * $Id: zebraapi.c,v 1.48 2002-03-20 20:24:29 adam Exp $
+ * $Id: zebraapi.c,v 1.49 2002-03-21 10:25:42 adam Exp $
*/
#include <assert.h>
zh->seqno = 0;
zh->last_val = 0;
- zh->lock_normal = zebra_lock_create ("norm.LCK", 0);
- zh->lock_shadow = zebra_lock_create ("shadow.LCK", 0);
+ zh->lock_normal = zebra_lock_create (res_get(zs->res, "lockDir"),
+ "norm.LCK", 0);
+ zh->lock_shadow = zebra_lock_create (res_get(zs->res, "lockDir"),
+ "shadow.LCK", 0);
zh->key_buf = 0;
zh->admin_databaseName = 0;
}
-void zebra_set_state (int val, int seqno)
+void zebra_set_state (ZebraHandle zh, int val, int seqno)
{
+ char *fname = zebra_mk_fname (res_get(zh->service->res, "lockDir"),
+ "state.LCK");
long p = getpid();
- FILE *f = fopen ("state.LCK", "w");
+ FILE *f = fopen (fname, "w");
fprintf (f, "%c %d %ld\n", val, seqno, p);
fclose (f);
+ xfree (fname);
}
-void zebra_get_state (char *val, int *seqno)
+void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
{
- FILE *f = fopen ("state.LCK", "r");
+ char *fname = zebra_mk_fname (res_get(zh->service->res, "lockDir"),
+ "state.LCK");
+ FILE *f = fopen (fname, "r");
*val = 'o';
*seqno = 0;
fscanf (f, "%c %d", val, seqno);
fclose (f);
}
+ xfree (fname);
}
static int zebra_begin_read (ZebraHandle zh)
return 0;
}
- zebra_get_state (&val, &seqno);
+ zebra_get_state (zh, &val, &seqno);
if (val == 'd')
val = 'o';
if (seqno != zh->seqno)
zebra_lock_w (zh->lock_shadow);
}
- zebra_get_state (&val, &seqno);
+ zebra_get_state (zh, &val, &seqno);
if (val == 'c')
{
yaz_log (LOG_LOG, "previous transaction didn't finish commit");
abort();
return;
}
- zebra_set_state ('d', seqno);
+ zebra_set_state (zh, 'd', seqno);
zebra_register_activate (zh, 1, rval ? 1 : 0);
zh->seqno = seqno;
zebra_register_deactivate (zh);
- zebra_get_state (&val, &seqno);
+ zebra_get_state (zh, &val, &seqno);
if (val != 'd')
{
BFiles bfs = bfs_create (res_get (zh->service->res, "shadow"));
}
if (!rval)
seqno++;
- zebra_set_state ('o', seqno);
+ zebra_set_state (zh, 'o', seqno);
zebra_unlock (zh->lock_shadow);
zebra_unlock (zh->lock_normal);
bfs = bfs_create (res_get (zh->service->res, "register"));
- zebra_get_state (&val, &seqno);
+ zebra_get_state (zh, &val, &seqno);
if (rval && *rval)
bf_cache (bfs, rval);
if (bf_commitExists (bfs))
{
- zebra_set_state ('c', seqno);
+ zebra_set_state (zh, 'c', seqno);
logf (LOG_LOG, "commit start");
bf_commitExec (bfs);
logf (LOG_LOG, "commit clean");
bf_commitClean (bfs, rval);
seqno++;
- zebra_set_state ('o', seqno);
+ zebra_set_state (zh, 'o', seqno);
}
else
{
bf_reset (bfs);
bfs_destroy (bfs);
- zebra_set_state ('o', 0);
+ zebra_set_state (zh, 'o', 0);
}
void zebra_compact (ZebraHandle zh)
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: zrpn.c,v 1.110 2002-03-20 20:24:29 adam Exp $
+ * $Id: zrpn.c,v 1.111 2002-03-21 10:25:42 adam Exp $
*/
#include <stdio.h>
#include <assert.h>
char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type);
const char *termp = termz;
+ *term_dst = 0;
if (grep_info_prepare (zh, zapt, &grep_info, reg_type, stream))
return 0;
while (1)
{
rset_null_parms parms;
- parms.rset_term = rset_term_create (term_dst, -1, rank_type);
+ parms.rset_term = rset_term_create (termz, -1, rank_type);
return rset_create (rset_kind_null, &parms);
}
else if (rset_no == 1)
{
rset_null_parms parms;
- parms.rset_term = rset_term_create (term_dst, -1, rank_type);
+ parms.rset_term = rset_term_create (termz, -1, rank_type);
return rset_create (rset_kind_null, &parms);
}
result = rset[0];
{
rset_null_parms parms;
- parms.rset_term = rset_term_create (term_dst, -1, rank_type);
+ parms.rset_term = rset_term_create (termz, -1, rank_type);
return rset_create (rset_kind_null, &parms);
}
result = rset[0];
Z_AttributeElement *ae;
int oid[OID_SIZE];
oident oe;
+ char termz[20];
attr_init (&sort_relation_type, zapt, 7);
sort_relation_value = attr_find (&sort_relation_type, &attributeSet);
zapt->term->u.general->len);
if (i >= sort_sequence->num_specs)
i = 0;
+ sprintf (termz, "%d", i);
oe.proto = PROTO_Z3950;
oe.oclass = CLASS_ATTSET;
sort_sequence->specs[i] = sks;
- parms.rset_term = rset_term_create ("", -1, rank_type);
+ parms.rset_term = rset_term_create (termz, -1, rank_type);
return rset_create (rset_kind_null, &parms);
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsnull.c,v $
- * Revision 1.12 1999-05-26 07:49:14 adam
+ * Revision 1.13 2002-03-21 10:25:42 adam
+ * use lockDir. Fixes for searchResult for null/sort sets
+ *
+ * Revision 1.12 1999/05/26 07:49:14 adam
* C++ compilation.
*
* Revision 1.11 1999/02/02 14:51:36 adam
ct->no_rset_terms = 1;
ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
- if (parms)
+ if (parms && null_parms->rset_term)
ct->rset_terms[0] = null_parms->rset_term;
else
ct->rset_terms[0] = rset_term_create ("term", -1, "rank-0");