From: Adam Dickmeiss Date: Fri, 6 Aug 2004 13:14:46 +0000 (+0000) Subject: Remove oldest isam (isam:i) X-Git-Tag: snippet.version.1~434 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=f7e93f016e75e43d037b5c3e89aeb27b7176513a Remove oldest isam (isam:i) --- diff --git a/Makefile.am b/Makefile.am index e584a43..9cb40d4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,8 @@ -## $Id: Makefile.am,v 1.14 2004-07-28 11:15:10 adam Exp $ +## $Id: Makefile.am,v 1.15 2004-08-06 13:14:46 adam Exp $ AUTOMAKE_OPTIONS=foreign -SUBDIRS=util bfile dfa dict isams isamb isamc isam rset data1 \ +SUBDIRS=util bfile dfa dict isams isamb isamc rset data1 \ recctrl tab index test examples include doc SPEC_FILE=$(PACKAGE).spec diff --git a/configure.in b/configure.in index 20a4a4b..c8589fe 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Zebra, Index Data Aps, 1995-2004 -dnl $Id: configure.in,v 1.92 2004-08-04 08:35:22 adam Exp $ +dnl $Id: configure.in,v 1.93 2004-08-06 13:14:46 adam Exp $ dnl AC_INIT(include/zebraver.h) AM_INIT_AUTOMAKE(idzebra,1.4.0) @@ -371,7 +371,6 @@ AC_OUTPUT([ isamb/Makefile isams/Makefile isamc/Makefile - isam/Makefile rset/Makefile data1/Makefile recctrl/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index 6ee6333..17a5a78 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,8 +1,8 @@ noinst_HEADERS = bfile.h bset.h charmap.h d1_attset.h d1_map.h \ data1.h dfa.h dict.h direntz.h isam-codec.h isamb.h isamc.h isamg.h \ -isam.h isams.h mfile.h passwddb.h recctrl.h \ -res.h rsbetween.h rsbool.h rset.h rsisamb.h rsisamc.h rsisam.h \ +isams.h mfile.h passwddb.h recctrl.h \ +res.h rsbetween.h rsbool.h rset.h rsisamb.h rsisamc.h \ rsisams.h rsm_or.h rsnull.h rsprox.h rstemp.h set.h \ sortidx.h str.h zebra-lock.h zebramap.h zebrautl.h \ zebra_xpath.h diff --git a/include/isam.h b/include/isam.h deleted file mode 100644 index 0e4488a..0000000 --- a/include/isam.h +++ /dev/null @@ -1,129 +0,0 @@ -/* $Id: isam.h,v 1.15 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#ifndef ISAM_H -#define ISAM_H - -#include -#include - -#include "../isam/memory.h" -#include "../isam/physical.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define IS_MAX_BLOCKTYPES 4 -#define IS_MAX_RECORD 512 -#define IS_DEF_REPACK_PERCENT "30" /* how much relative change before repack */ - -/* - * Description of a blocktype (part of an isam file) - */ -typedef struct isam_blocktype -{ - BFile bf; /* blocked file */ - int blocksize; - int first_block; /* position of first data block */ - int max_keys_block; /* max num of keys per block */ - int max_keys_block0; /* max num of keys in first block */ - int nice_keys_block; /* nice number of keys per block */ - int max_keys; /* max number of keys per table */ - int freelist; /* first free block */ - int top; /* first unused block */ - int index; /* placeholder. Always 0. */ - char *dbuf; /* buffer for use in I/O operations */ -} isam_blocktype; - -/* - * Handle to an open isam complex. - */ -typedef struct isam_struct -{ - isam_blocktype types[IS_MAX_BLOCKTYPES]; /* block_types used in this file */ - int num_types; /* number of block types used */ - int writeflag; - int keysize; /* size of the keys (records) used */ - int repack; /* how many percent to grow before repack */ - int (*cmp)(const void *k1, const void *k2); /* compare function */ -} isam_struct; - -typedef struct ispt_struct -{ - struct is_mtable tab; - struct ispt_struct *next; /* freelist */ -} ispt_struct, *ISPT; - -#define is_type(x) ((x) & 3) /* type part of position */ -#define is_block(x) ((x) >> 2) /* block # part of position */ - -#define is_keysize(is) ((is)->keysize) - -/* - * Public Prototypes. - ******************************************************************* - */ - -/* - * Open isam file. - */ -ISAM is_open(BFiles bfs, const char *name, - int (*cmp)(const void *p1, const void *p2), - int writeflag, int keysize, Res res); - -/* - * Close isam file. - */ -int is_close(ISAM is); - -/* - * Locate a table of keys in an isam file. The ISPT is an individual - * position marker for that table. - */ -ISPT is_position(ISAM is, ISAM_P pos); - -/* - * Release ISPT. - */ -void is_pt_free(ISPT ip); - -/* - * Read a key from a table. - */ -int is_readkey(ISPT ip, void *buf); - -int is_writekey(ISPT ip, const void *buf); - -int is_numkeys(ISPT ip); - -void is_rewind(ISPT ip); - -ISAM_P is_merge(ISAM is, ISAM_P pos, int num, char *data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/rsisam.h b/include/rsisam.h deleted file mode 100644 index 01880d7..0000000 --- a/include/rsisam.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $Id: rsisam.h,v 1.6 2002-08-02 19:26:55 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#ifndef RSET_ISAM_H -#define RSET_ISAM_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern const struct rset_control *rset_kind_isam; - -typedef struct rset_isam_parms -{ - ISAM is; - ISAM_P pos; - RSET_TERM rset_term; -} rset_isam_parms; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/index/index.h b/index/index.h index 5d9bcfa..2c38a58 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.110 2004-08-04 08:35:23 adam Exp $ +/* $Id: index.h,v 1.111 2004-08-06 13:14:46 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -36,10 +36,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include #include #include -#define ISAM_DEFAULT "c" #include #include #include "recindex.h" @@ -50,6 +48,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA YAZ_BEGIN_CDECL +#define ISAM_DEFAULT "b" + #define SU_SCHEME 1 #define IT_MAX_WORD 256 @@ -237,7 +237,6 @@ struct zebra_register { char *name; ISAMS isams; - ISAM isam; ISAMC isamc; ISAMB isamb; Dict dict; diff --git a/index/invstat.c b/index/invstat.c index a02a1a6..5001186 100644 --- a/index/invstat.c +++ b/index/invstat.c @@ -1,4 +1,4 @@ -/* $Id: invstat.c,v 1.38 2004-08-06 12:55:01 adam Exp $ +/* $Id: invstat.c,v 1.39 2004-08-06 13:14:46 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -114,15 +114,6 @@ static int inv_stat_handle (char *name, const char *info, int pos, stat_info->no_isam_entries[0] += occur; isams_pp_close (pp); } - if (stat_info->zh->reg->isam) - { - ISPT ispt; - - ispt = is_position (stat_info->zh->reg->isam, (int) isam_p); - occur = is_numkeys (ispt); - stat_info->no_isam_entries[is_type(isam_p)] += occur; - is_pt_free (ispt); - } if (stat_info->zh->reg->isamc) { ISAMC_PP pp; diff --git a/index/kinput.c b/index/kinput.c index 3ed7512..5ee8829 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -1,4 +1,4 @@ -/* $Id: kinput.c,v 1.60 2004-08-04 08:35:23 adam Exp $ +/* $Id: kinput.c,v 1.61 2004-08-06 13:14:46 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -704,77 +704,6 @@ int heap_inpb (struct heap_info *hi) return 0; } -int heap_inp (struct heap_info *hi) -{ - char *info; - char next_name[INP_NAME_MAX]; - char cur_name[INP_NAME_MAX]; - int key_buf_size = INP_BUF_START; - int key_buf_ptr; - char *next_key; - char *key_buf; - int more; - - next_key = (char *) xmalloc (KEY_SIZE); - key_buf = (char *) xmalloc (key_buf_size); - more = heap_read_one (hi, cur_name, key_buf); - while (more) /* EOF ? */ - { - int nmemb; - key_buf_ptr = KEY_SIZE; - while (1) - { - if (!(more = heap_read_one (hi, next_name, next_key))) - break; - if (*next_name && strcmp (next_name, cur_name)) - break; - memcpy (key_buf + key_buf_ptr, next_key, KEY_SIZE); - key_buf_ptr += KEY_SIZE; - if (key_buf_ptr+(int) KEY_SIZE >= key_buf_size) - { - char *new_key_buf; - new_key_buf = (char *) xmalloc (key_buf_size + INP_BUF_ADD); - memcpy (new_key_buf, key_buf, key_buf_size); - key_buf_size += INP_BUF_ADD; - xfree (key_buf); - key_buf = new_key_buf; - } - } - hi->no_diffs++; - nmemb = key_buf_ptr / KEY_SIZE; - assert (nmemb * (int) KEY_SIZE == key_buf_ptr); - if ((info = dict_lookup (hi->reg->dict, cur_name))) - { - ISAM_P isam_p, isam_p2; - memcpy (&isam_p, info+1, sizeof(ISAM_P)); - isam_p2 = is_merge (hi->reg->isam, isam_p, nmemb, key_buf); - if (!isam_p2) - { - hi->no_deletions++; - if (!dict_delete (hi->reg->dict, cur_name)) - abort (); - } - else - { - hi->no_updates++; - if (isam_p2 != isam_p) - dict_insert (hi->reg->dict, cur_name, - sizeof(ISAM_P), &isam_p2); - } - } - else - { - ISAM_P isam_p; - hi->no_insertions++; - isam_p = is_merge (hi->reg->isam, 0, nmemb, key_buf); - dict_insert (hi->reg->dict, cur_name, sizeof(ISAM_P), &isam_p); - } - memcpy (key_buf, next_key, KEY_SIZE); - strcpy (cur_name, next_name); - } - return 0; -} - int heap_inps (struct heap_info *hi) { struct heap_cread_info hci; @@ -913,8 +842,6 @@ void zebra_index_merge (ZebraHandle zh) heap_inps (hi); if (zh->reg->isamc) heap_inpc (hi); - if (zh->reg->isam) - heap_inp (hi); if (zh->reg->isamb) heap_inpb (hi); diff --git a/index/trunc.c b/index/trunc.c index 47bcdf1..261685e 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -1,5 +1,5 @@ -/* $Id: trunc.c,v 1.30 2004-08-06 12:28:22 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: trunc.c,v 1.31 2004-08-06 13:14:46 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -30,7 +30,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include #include #include #if NEW_TRUNC @@ -217,62 +216,6 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, xfree (rsfd); heap_close (ti); } - else if (zi->reg->isam) - { - ISPT *ispt; - int i; - struct trunc_info *ti; - - ispt = (ISPT *) xmalloc (sizeof(*ispt) * (to-from)); - - ti = heap_init (to-from, sizeof(struct it_key), - key_compare_it); - for (i = to-from; --i >= 0; ) - { - ispt[i] = is_position (zi->reg->isam, isam_p[from+i]); - if (is_readkey (ispt[i], ti->tmpbuf)) - heap_insert (ti, ti->tmpbuf, i); - else - is_pt_free (ispt[i]); - } - while (ti->heapnum) - { - int n = ti->indx[ti->ptr[1]]; - - rset_write (result, result_rsfd, ti->heap[ti->ptr[1]]); - nn++; - if (preserve_position) - { -/* section that preserve all keys */ - heap_delete (ti); - if (is_readkey (ispt[n], ti->tmpbuf)) - heap_insert (ti, ti->tmpbuf, n); - else - is_pt_free (ispt[n]); - } - else - { -/* section that preserve all keys with unique sysnos */ - while (1) - { - if (!is_readkey (ispt[n], ti->tmpbuf)) - { - heap_delete (ti); - is_pt_free (ispt[n]); - break; - } - if ((*ti->cmp)(ti->tmpbuf, ti->heap[ti->ptr[1]]) > 1) - { - heap_delete (ti); - heap_insert (ti, ti->tmpbuf, n); - break; - } - } - } - } - heap_close (ti); - xfree (ispt); - } else if (zi->reg->isamc) { ISAMC_PP *ispt; @@ -441,23 +384,11 @@ static int isams_trunc_cmp (const void *p1, const void *p2) if (i1 > i2) return 1; - if (i1 < i2) + else if (i1 < i2) return -1; return 0; } -static int isam_trunc_cmp (const void *p1, const void *p2) -{ - ISAM_P i1 = *(ISAM_P*) p1; - ISAM_P i2 = *(ISAM_P*) p2; - int d; - - d = is_type (i1) - is_type (i2); - if (d) - return d; - return is_block (i1) - is_block (i2); -} - static int isamc_trunc_cmp (const void *p1, const void *p2) { ISAMC_P i1 = *(ISAMC_P*) p1; @@ -500,20 +431,6 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, } qsort (isam_p, no, sizeof(*isam_p), isams_trunc_cmp); } - else if (zi->reg->isam) - { - if (no == 1) - { - rset_isam_parms parms; - - parms.pos = *isam_p; - parms.is = zi->reg->isam; - parms.rset_term = rset_term_create (term, length, flags, - term_type); - return rset_create (rset_kind_isam, &parms); - } - qsort (isam_p, no, sizeof(*isam_p), isam_trunc_cmp); - } else if (zi->reg->isamc) { if (no == 1) diff --git a/index/zebraapi.c b/index/zebraapi.c index 3e98491..d1c4baa 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.122 2004-08-04 09:05:17 adam Exp $ +/* $Id: zebraapi.c,v 1.123 2004-08-06 13:14:46 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -261,7 +261,6 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->sortIdx = 0; reg->isams = 0; reg->matchDict = 0; - reg->isam = 0; reg->isamc = 0; reg->isamb = 0; reg->zei = 0; @@ -308,15 +307,6 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, return 0; } } - if (res_get_match (res, "isam", "i", ISAM_DEFAULT)) - { - if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw, - sizeof (struct it_key), res))) - { - logf (LOG_WARN, "is_open"); - return 0; - } - } if (res_get_match (res, "isam", "c", ISAM_DEFAULT)) { struct ISAMC_M_s isamc_m; @@ -412,8 +402,6 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) sortIdx_close (reg->sortIdx); if (reg->isams) isams_close (reg->isams); - if (reg->isam) - is_close (reg->isam); if (reg->isamc) isc_close (reg->isamc); if (reg->isamb) diff --git a/isam/Makefile.am b/isam/Makefile.am deleted file mode 100644 index df9da5b..0000000 --- a/isam/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -## $Id: Makefile.am,v 1.3 2004-06-16 20:49:18 adam Exp $ - -noinst_LIBRARIES = libisam.a - -AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC) - -LDADD = ../util/libutil.a ../bfile/libbfile.a $(YAZLIB) $(TCL_LIB) - -libisam_a_SOURCES = isam.c isutil.c rootblk.c memory.c physical.c \ - isutil.h keyops.h memory.h physical.h rootblk.h diff --git a/isam/isam.c b/isam/isam.c deleted file mode 100644 index 6b55f50..0000000 --- a/isam/isam.c +++ /dev/null @@ -1,541 +0,0 @@ -/* $Id: isam.c,v 1.28 2004-01-22 11:27:21 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#include -#include -#include -#include - -#include -#include -#include -#include "isutil.h" -#include "rootblk.h" -#include "keyops.h" - -static ispt_struct *ispt_freelist = 0; - -static struct -{ - int total_merge_operations; - int total_items; - int dub_items_removed; - int new_items; - int failed_deletes; - int skipped_inserts; - int delete_insert_noop; - int delete_replace; - int deletes; - int remaps; - int block_jumps; - int tab_deletes; - int new_tables; -} statistics; - -static ISPT ispt_alloc() -{ - ISPT p; - - if (ispt_freelist) - { - p = ispt_freelist; - ispt_freelist = ispt_freelist->next; - } - else - p = (ISPT) xmalloc(sizeof(ispt_struct)); - return p; -} - -static void ispt_free(ISPT pt) -{ - pt->next = ispt_freelist; - ispt_freelist = pt; -} - -static int splitargs(const char *s, char *bf[], int max) -{ - int ct = 0; - for (;;) - { - while (*s && isspace(*s)) - s++; - bf[ct] = (char *) s; - if (!*s) - return ct; - ct++; - if (ct > max) - { - logf (LOG_WARN, "Ignoring extra args to is resource"); - bf[ct] = '\0'; - return(ct - 1); - } - while (*s && !isspace(*s)) - s++; - } -} - -/* - * Open isam file. - * Process resources. - */ -ISAM is_open(BFiles bfs, const char *name, - int (*cmp)(const void *p1, const void *p2), - int writeflag, int keysize, Res res) -{ - ISAM inew; - char *nm, *pp[IS_MAX_BLOCKTYPES+1], m[2]; - int num, size, rs, tmp, i; - const char *r; - is_type_header th; - - logf (LOG_DEBUG, "is_open(%s, %s)", name, writeflag ? "RW" : "RDONLY"); - if (writeflag) - { - statistics.total_merge_operations = 0; - statistics.total_items = 0; - statistics.dub_items_removed = 0; - statistics.new_items = 0; - statistics.failed_deletes = 0; - statistics.skipped_inserts = 0; - statistics.delete_insert_noop = 0; - statistics.delete_replace = 0; - statistics.deletes = 0; - statistics.remaps = 0; - statistics.new_tables = 0; - statistics.block_jumps = 0; - statistics.tab_deletes = 0; - } - - inew = (ISAM) xmalloc(sizeof(*inew)); - inew->writeflag = writeflag; - for (i = 0; i < IS_MAX_BLOCKTYPES; i++) - inew->types[i].index = 0; /* dummy */ - - /* determine number and size of blocktypes */ - if (!(r = res_get_def(res, - nm = strconcat(name, ".", - "blocktypes", 0), "64 512 4K 32K")) || - !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES))) - { - logf (LOG_FATAL, "Failed to locate resource %s", nm); - return 0; - } - inew->num_types = num; - for (i = 0; i < num; i++) - { - if ((rs = sscanf(pp[i], "%d%1[bBkKmM]", &size, m)) < 1) - { - logf (LOG_FATAL, "Error in resource %s: %s", r, pp[i]); - return 0; - } - if (rs == 1) - *m = 'b'; - switch (*m) - { - case 'b': case 'B': - inew->types[i].blocksize = size; break; - case 'k': case 'K': - inew->types[i].blocksize = size * 1024; break; - case 'm': case 'M': - inew->types[i].blocksize = size * 1048576; break; - default: - logf (LOG_FATAL, "Illegal size suffix: %c", *m); - return 0; - } - inew->types[i].dbuf = (char *) xmalloc(inew->types[i].blocksize); - m[0] = 'A' + i; - m[1] = '\0'; - if (!(inew->types[i].bf = bf_open(bfs, strconcat(name, m, 0), - inew->types[i].blocksize, writeflag))) - { - logf (LOG_FATAL, "bf_open failed"); - return 0; - } - if ((rs = is_rb_read(&inew->types[i], &th)) > 0) - { - if (th.blocksize != inew->types[i].blocksize) - { - logf (LOG_FATAL, "File blocksize mismatch in %s", name); - exit(1); - } - inew->types[i].freelist = th.freelist; - inew->types[i].top = th.top; - } - else if (writeflag) /* write dummy superblock to determine top */ - { - if ((rs = is_rb_write(&inew->types[i], &th)) <=0) /* dummy */ - { - logf (LOG_FATAL, "Failed to write initial superblock."); - exit(1); - } - inew->types[i].freelist = -1; - inew->types[i].top = rs; - } - /* ELSE: this is an empty file opened in read-only mode. */ - } - if (keysize > 0) - inew->keysize = keysize; - else - { - if (!(r = res_get_def(res, nm = strconcat(name, ".", - "keysize", 0), "4"))) - { - logf (LOG_FATAL, "Failed to locate resource %s", nm); - return 0; - } - if ((inew->keysize = atoi(r)) <= 0) - { - logf (LOG_FATAL, "Must specify positive keysize."); - return 0; - } - } - - /* determine repack percent */ - if (!(r = res_get_def(res, nm = strconcat(name, ".", "repack", - 0), IS_DEF_REPACK_PERCENT))) - { - logf (LOG_FATAL, "Failed to locate resource %s", nm); - return 0; - } - inew->repack = atoi(r); - - /* determine max keys/blocksize */ - if (!(r = res_get_def(res, - nm = strconcat(name, ".", - "maxkeys", 0), "50 640 10000")) || - !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES))) - { - logf (LOG_FATAL, "Failed to locate resource %s", nm); - return 0; - } - if (num < inew->num_types -1) - { - logf (LOG_FATAL, "Not enough elements in %s", nm); - return 0; - } - for (i = 0; i < num; i++) - { - if ((rs = sscanf(pp[i], "%d", &tmp)) < 1) - { - logf (LOG_FATAL, "Error in resource %s: %s", r, pp[i]); - return 0; - } - inew->types[i].max_keys = tmp; - } - - /* determine max keys/block */ - for (i = 0; i < inew->num_types; i++) - { - if (!inew->types[i].index) - { - inew->types[i].max_keys_block = (inew->types[i].blocksize - 2 * - sizeof(int)) / inew->keysize; - inew->types[i].max_keys_block0 = (inew->types[i].blocksize - 3 * - sizeof(int)) / inew->keysize; - } - else - inew->types[i].max_keys_block = inew->types[i].max_keys_block0 / - inew->keysize; - if (inew->types[i].max_keys_block0 < 1) - { - logf (LOG_FATAL, "Blocksize too small in %s", name); - exit(1); - } - } - - /* determine nice fill rates */ - if (!(r = res_get_def(res, - nm = strconcat(name, ".", - "nicefill", 0), "90 90 90 95")) || - !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES))) - { - logf (LOG_FATAL, "Failed to locate resource %s", nm); - return 0; - } - if (num < inew->num_types) - { - logf (LOG_FATAL, "Not enough elements in %s", nm); - return 0; - } - for (i = 0; i < num; i++) - { - if ((rs = sscanf(pp[i], "%d", &tmp)) < 1) - { - logf (LOG_FATAL, "Error in resource %s: %s", r, pp[i]); - return 0; - } - inew->types[i].nice_keys_block = (inew->types[i].max_keys_block0 * tmp) / - 100; - if (inew->types[i].nice_keys_block < 1) - inew->types[i].nice_keys_block = 1; - } - - inew->cmp = cmp ? cmp : is_default_cmp; - return inew; -} - -/* - * Close isam file. - */ -int is_close(ISAM is) -{ - int i; - is_type_header th; - - logf (LOG_DEBUG, "is_close()"); - for (i = 0; i < is->num_types; i++) - { - if (is->types[i].bf) - { - if (is->writeflag) - { - th.blocksize = is->types[i].blocksize; - th.keysize = is->keysize; - th.freelist = is->types[i].freelist; - th.top = is->types[i].top; - if (is_rb_write(&is->types[i], &th) < 0) - { - logf (LOG_FATAL, "Failed to write headerblock"); - exit(1); - } - } - bf_close(is->types[i].bf); - } - } - for (i = 0; i < is->num_types; i++) - xfree (is->types[i].dbuf); - - if (is->writeflag) - { - logf(LOG_LOG, "ISAM statistics:"); - logf(LOG_LOG, "total_merge_operations %d", - statistics.total_merge_operations); - logf(LOG_LOG, "total_items %d", statistics.total_items); - logf(LOG_LOG, "dub_items_removed %d", - statistics.dub_items_removed); - logf(LOG_LOG, "new_items %d", statistics.new_items); - logf(LOG_LOG, "failed_deletes %d", - statistics.failed_deletes); - logf(LOG_LOG, "skipped_inserts %d", - statistics.skipped_inserts); - logf(LOG_LOG, "delete_insert_noop %d", - statistics.delete_insert_noop); - logf(LOG_LOG, "delete_replace %d", - statistics.delete_replace); - logf(LOG_LOG, "delete %d", statistics.deletes); - logf(LOG_LOG, "remaps %d", statistics.remaps); - logf(LOG_LOG, "block_jumps %d", statistics.block_jumps); - logf(LOG_LOG, "tab_deletes %d", statistics.tab_deletes); - } - xfree(is); - return 0; -} - -static ISAM_P is_address(int type, int pos) -{ - ISAM_P r; - - r = pos << 2; - r |= type; - return r; -} - -ISAM_P is_merge(ISAM is, ISAM_P pos, int num, char *data) -{ - is_mtable tab; - int res; - char keybuf[IS_MAX_RECORD]; - int oldnum, oldtype, i; - char operation, *record; - - statistics.total_merge_operations++; - statistics.total_items += num; - if (!pos) - statistics.new_tables++; - - is_m_establish_tab(is, &tab, pos); - if (pos) - if (is_m_read_full(&tab, tab.data) < 0) - { - logf (LOG_FATAL, "read_full failed"); - exit(1); - } - oldnum = tab.num_records; - oldtype = tab.pos_type; - while (num) - { - operation = *(data)++; - record = (char*) data; - data += is_keysize(is); - num--; - while (num && !memcmp(record - 1, data, is_keysize(tab.is) + 1)) - { - data += 1 + is_keysize(is); - num--; - statistics.dub_items_removed++; - } - if ((res = is_m_seek_record(&tab, record)) > 0) /* no match */ - { - if (operation == KEYOP_INSERT) - { - logf (LOG_DEBUG, "XXInserting new record."); - is_m_write_record(&tab, record); - statistics.new_items++; - } - else - { - logf (LOG_DEBUG, "XXDeletion failed to find match."); - statistics.failed_deletes++; - } - } - else /* match found */ - { - if (operation == KEYOP_INSERT) - { - logf (LOG_DEBUG, "XXSkipping insertion - match found."); - statistics.skipped_inserts++; - continue; - } - else if (operation == KEYOP_DELETE) - { - /* try to avoid needlessly moving data */ - if (num && *(data) == KEYOP_INSERT) - { - /* next key is identical insert? - NOOP - skip it */ - if (!memcmp(record, data + 1, is_keysize(is))) - { - logf (LOG_DEBUG, "XXNoop delete. skipping."); - data += 1 + is_keysize(is); - num--; - while (num && !memcmp(data, data + is_keysize(tab.is) + - 1, is_keysize(tab.is) + 1)) - { - data += 1 + is_keysize(is); - num--; - statistics.dub_items_removed++; - } - statistics.delete_insert_noop++; - continue; - } - /* else check if next key can fit in this position */ - if (is_m_peek_record(&tab, keybuf) && - (*is->cmp)(data + 1, keybuf) < 0) - { - logf (LOG_DEBUG, "XXReplacing record."); - is_m_replace_record(&tab, data + 1); - data += 1 + is_keysize(is); - num--; - while (num && !memcmp(data, data + is_keysize(tab.is) + - 1, is_keysize(tab.is) + 1)) - { - data += 1 + is_keysize(is); - num--; - statistics.dub_items_removed++; - } - statistics.delete_replace++; - continue; - } - } - logf (LOG_DEBUG, "Deleting record."); - is_m_delete_record(&tab); - statistics.deletes++; - } - } - } - i = tab.pos_type; - while (i < tab.is->num_types - 1 && tab.num_records > - tab.is->types[i].max_keys) - i++; - if (i != tab.pos_type) - { - /* read remaining blocks */ - for (; tab.cur_mblock; tab.cur_mblock = tab.cur_mblock->next) - if (tab.cur_mblock->state < IS_MBSTATE_CLEAN) - is_m_read_full(&tab, tab.cur_mblock); - is_p_unmap(&tab); - tab.pos_type = i; - if (pos) - statistics.block_jumps++; - } - if (!oldnum || tab.pos_type != oldtype || (abs(oldnum - tab.num_records) * - 100) / oldnum > tab.is->repack) - { - is_p_remap(&tab); - statistics.remaps++; - } - else - is_p_align(&tab); - if (tab.data) - { - is_p_sync(&tab); - pos = is_address(tab.pos_type, tab.data->diskpos); - } - else - { - pos = 0; - statistics.tab_deletes++; - } - is_m_release_tab(&tab); - return pos; -} - -/* - * Locate a table of keys in an isam file. The ISPT is an individual - * position marker for that table. - */ -ISPT is_position(ISAM is, ISAM_P pos) -{ - ispt_struct *p; - - p = ispt_alloc(); - is_m_establish_tab(is, &p->tab, pos); - return p; -} - -/* - * Release ISPT. - */ -void is_pt_free(ISPT ip) -{ - is_m_release_tab(&ip->tab); - ispt_free(ip); -} - -/* - * Read a key from a table. - */ -int is_readkey(ISPT ip, void *buf) -{ - return is_m_read_record(&ip->tab, buf, 0); -} - -int is_numkeys(ISPT ip) -{ - return is_m_num_records(&ip->tab); -} - -void is_rewind(ISPT ip) -{ - is_m_rewind(&ip->tab); -} diff --git a/isam/issh.c b/isam/issh.c deleted file mode 100644 index 7d77fce..0000000 --- a/isam/issh.c +++ /dev/null @@ -1,187 +0,0 @@ -/* $Id: issh.c,v 1.6 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#include -#include -#include -#include - -#include - -static ISAM is = 0; - -int c_open(char *p); -int c_close(char *p); -int c_write(char *p); -int c_merge(char *p); -int c_rewind(char *p); -int c_read(char *p); -int c_exit(char *p); -int c_help(char *p); -int c_list(char *p); -int c_pos(char *p); - -struct -{ - char *word; - int (*fun)(char *p); -} cmdl[] = -{ - {"open", c_open}, - {"close", c_close}, - {"write", c_write}, - {"merge", c_merge}, - {"rewind", c_rewind}, - {"read", c_read}, - {"exit", c_exit}, - {"quit", c_exit}, - {"help", c_help}, - {"list", 0}, - {"pos", c_pos}, - - {0,0} -}; - - -int c_pos(char *p) -{ -} - -int c_open(char *p) -{ - if (!*p) - { - printf("Usage: open name\n"); - return -1; - } - if (!(is = is_open(p, 1))) - return -1; - return 0; -} - -int c_close(char *p) -{ - if (!is) - { - printf("Open first.\n"); - return -1; - } - is_close(is); - return 0; -} - -int c_write(char *p) {} - -int c_merge(char *p) -{ - char line[100], buf[1024], ch; - int pos = 0, num = 0; - int op, key; - int val; - - if (!is) - { - printf("Open first.\n"); - return -1; - } - if (!sscanf(p, "%d", &val)) - { - printf("Usage: merge
\n"); - return -1; - } - printf("Enter pairs of . Terminate with '.'\n"); - while (gets(line) && *line != '.') - { - if (sscanf(line, "%d %d", &op, &key) < 2) - { - printf("Error in input\n"); - return -1; - } - ch = op; - *(buf + pos++) = ch; - memcpy(buf + pos, &key, sizeof(key)); - pos += sizeof(key); - num++; - } - printf("is_merge(-->%d) returns: %d\n", val, is_merge(is, val, num , buf)); - return 0; -} - -int c_rewind(char *p) -{ - if (!is) - { - printf("Open first.\n"); - return -1; - } -} - -int c_read(char *p) {} - -int c_exit(char *p) -{ - exit(0); -} - -int c_help(char *p) -{ - int i; - - printf("ISSH: ISAM debugging shell.\n"); - printf("Commands:\n"); - for (i = 0; cmdl[i].word; i++) - printf(" %s %s\n", cmdl[i].word, cmdl[i].fun ? "": "UNDEFINED"); - return 0; -} - -int main() -{ - char line[1024]; - static char word[1024] = "help", arg[1024] = ""; - int i; - - log_init(LOG_ALL, "issh", 0); - - common_resource = res_open("testres"); - assert(common_resource); - - for (;;) - { - printf("ISSH> "); - fflush(stdout); - if (!gets(line)) - return 0; - *arg = '\0'; - if (*line && sscanf(line, "%s %[^;]", word, arg) < 1) - abort(); - for (i = 0; cmdl[i].word; i++) - if (!strncmp(cmdl[i].word, word, strlen(word))) - { - printf("%s\n", (*cmdl[i].fun)(arg) == 0 ? "OK" : "FAILED"); - break; - } - if (!cmdl[i].word) - (*c_help)(""); - } -} diff --git a/isam/isutil.c b/isam/isutil.c deleted file mode 100644 index 215bee8..0000000 --- a/isam/isutil.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $Id: isutil.c,v 1.5 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -/* - * Small utilities needed by the isam system. Some or all of these - * may move to util/ along the way. - */ - -#include -#include -#include - -#include -#include "isutil.h" - -char *strconcat(const char *s1, ...) -{ - va_list ap; - static char buf[512]; - char *p; - - va_start(ap, s1); - strcpy(buf, s1); - while ((p = va_arg(ap, char *))) - strcat(buf, p); - va_end(ap); - - return buf; -} - -int is_default_cmp(const void *k1, const void *k2) -{ - int b1, b2; - - memcpy(&b1, k1, sizeof(b1)); - memcpy(&b2, k2, sizeof(b2)); - return b1 - b2; -} diff --git a/isam/isutil.h b/isam/isutil.h deleted file mode 100644 index e2772cc..0000000 --- a/isam/isutil.h +++ /dev/null @@ -1,45 +0,0 @@ -/* $Id: isutil.h,v 1.4 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -/* - * Small utilities needed by the isam system. Some or all of these - * may move to util/ along the way. - */ - -#ifndef ISUTIL_H -#define ISUTIL_H - -#ifdef __cplusplus -extern "C" { -#endif - -char *strconcat(const char *s1, ...); - -int is_default_cmp(const void *k1, const void *k2); /* compare function */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/isam/keyops.h b/isam/keyops.h deleted file mode 100644 index 7a384cb..0000000 --- a/isam/keyops.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $Id: keyops.h,v 1.3 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#ifndef KEYOPS_H -#define KEYOPS_H - -#define KEYOP_DELETE 0 -#define KEYOP_INSERT 1 - -#endif diff --git a/isam/memory.c b/isam/memory.c deleted file mode 100644 index 800d74e..0000000 --- a/isam/memory.c +++ /dev/null @@ -1,429 +0,0 @@ -/* $Id: memory.c,v 1.18 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -/* - * This module accesses and rearranges the records of the tables. - */ - -#include -#include -#include -#include - -#include -#include - -int is_mbuf_size[3] = { 0, 1024, 4096 }; - -static is_mblock *mblock_tmplist = 0, *mblock_freelist = 0; -static is_mbuf *mbuf_freelist[3] = {0, 0, 0}; - -#define MALLOC_CHUNK 20 - -is_mblock *xmalloc_mblock() -{ - is_mblock *tmp; - int i; - - if (!mblock_freelist) - { - mblock_freelist = (is_mblock *) - xmalloc(sizeof(is_mblock) * MALLOC_CHUNK); - for (i = 0; i < MALLOC_CHUNK - 1; i++) - mblock_freelist[i].next = &mblock_freelist[i+1]; - mblock_freelist[i].next = 0; - } - tmp = mblock_freelist; - mblock_freelist = mblock_freelist->next; - tmp->next = 0; - tmp->state = IS_MBSTATE_UNREAD; - tmp->data = 0; - return tmp; -} - -is_mbuf *xmalloc_mbuf(int type) -{ - is_mbuf *tmp; - - if (mbuf_freelist[type]) - { - tmp = mbuf_freelist[type]; - mbuf_freelist[type] = tmp->next; - } - else - { - tmp = (is_mbuf*) xmalloc(sizeof(is_mbuf) + is_mbuf_size[type]); - tmp->type = type; - } - tmp->refcount = type ? 1 : 0; - tmp->offset = tmp->num = tmp->cur_record = 0; - tmp->data = (char*) tmp + sizeof(is_mbuf); - tmp->next = 0; - return tmp; -} - -void xfree_mbuf(is_mbuf *p) -{ - p->next = mbuf_freelist[p->type]; - mbuf_freelist[p->type] = p; -} - -void xfree_mbufs(is_mbuf *l) -{ - is_mbuf *p; - - while (l) - { - p = l->next; - xfree_mbuf(l); - l = p; - } -} - -void xfree_mblock(is_mblock *p) -{ - xfree_mbufs(p->data); - p->next = mblock_freelist; - mblock_freelist = p; -} - -void xrelease_mblock(is_mblock *p) -{ - p->next = mblock_tmplist; - mblock_tmplist = p; -} - -void xfree_mblocks(is_mblock *l) -{ - is_mblock *p; - - while (l) - { - p = l->next; - xfree_mblock(l); - l = p; - } -} - -void is_m_establish_tab(ISAM is, is_mtable *tab, ISAM_P pos) -{ - tab->data = xmalloc_mblock(); - if (pos > 0) - { - tab->pos_type = is_type(pos); - tab->num_records = -1; - tab->data->num_records = -1; - tab->data->diskpos = is_block(pos); - tab->data->state = IS_MBSTATE_UNREAD; - tab->data->data = 0; - tab->cur_mblock = tab->data; - tab->cur_mblock->cur_mbuf = 0; - tab->last_mbuf = 0; - } - else /* new block */ - { - tab->pos_type = 0; - tab->num_records = 0; - tab->data->num_records = 0; - tab->data->diskpos = -1; - tab->data->state = IS_MBSTATE_CLEAN; - tab->data->data = xmalloc_mbuf(IS_MBUF_TYPE_LARGE); - tab->cur_mblock = tab->data; - tab->cur_mblock->cur_mbuf = tab->data->data; - tab->cur_mblock->cur_mbuf->cur_record = 0; - tab->last_mbuf = 0; - } - tab->is = is; -} - -void is_m_release_tab(is_mtable *tab) -{ - xfree_mblocks(tab->data); - xfree_mblocks(mblock_tmplist); - mblock_tmplist = 0; -} - -void is_m_rewind(is_mtable *tab) -{ - tab->cur_mblock = tab->data; - if (tab->data) - { - tab->data->cur_mbuf = tab->data->data; - if (tab->data->data) - tab->data->data->cur_record = 0; - } -} - -static int read_current_full(is_mtable *tab, is_mblock *mblock) -{ - if (is_p_read_full(tab, mblock) < 0) - return -1; - if (mblock->nextpos && !mblock->next) - { - mblock->next = xmalloc_mblock(); - mblock->next->diskpos = mblock->nextpos; - mblock->next->state = IS_MBSTATE_UNREAD; - mblock->next->data = 0; - } - mblock->cur_mbuf = mblock->data; - mblock->data->cur_record = 0; - return 0; -} - -int is_m_read_full(is_mtable *tab, is_mblock *mblock) -{ - return read_current_full(tab, mblock); -} - -/* - * replace the record right behind the pointer. - */ -void is_m_replace_record(is_mtable *tab, const void *rec) -{ - is_mbuf *mbuf = tab->cur_mblock->cur_mbuf; - - /* we assume that block is already in memory and that we are in the - * right mbuf, and that it has space for us. */ - memcpy(mbuf->data + mbuf->offset + (mbuf->cur_record - 1) * - is_keysize(tab->is), rec, is_keysize(tab->is)); - tab->cur_mblock->state = IS_MBSTATE_DIRTY; -} - -/* - * Delete the record right behind the pointer. - */ -void is_m_delete_record(is_mtable *tab) -{ - is_mbuf *mbuf, *inew; - - mbuf = tab->cur_mblock->cur_mbuf; - if (mbuf->cur_record >= mbuf->num) /* top of mbuf */ - { - mbuf->num--; - mbuf->cur_record--; - } - else if (mbuf->cur_record == 1) /* beginning of mbuf */ - { - mbuf->num--; - mbuf->offset +=is_keysize(tab->is); - mbuf->cur_record = 0; - } - else /* middle of mbuf */ - { - /* insert block after current one */ - inew = xmalloc_mbuf(IS_MBUF_TYPE_SMALL); - inew->next = mbuf->next; - mbuf->next = inew; - - /* virtually transfer everything after current record to new one. */ - inew->data = mbuf->data; - mbuf->refcount++; - inew->offset = mbuf->offset + mbuf->cur_record * is_keysize(tab->is); - inew->num = mbuf->num - mbuf->cur_record; - - /* old buf now only contains stuff before current record */ - mbuf->num = mbuf->cur_record -1; - tab->cur_mblock->cur_mbuf = inew; - } - tab->num_records--; - tab->cur_mblock->num_records--; - tab->cur_mblock->state = tab->data->state = IS_MBSTATE_DIRTY; -} - -int is_m_write_record(is_mtable *tab, const void *rec) -{ - is_mbuf *mbuf, *oldnext, *dmbuf; - - /* make sure block is all in memory */ - if (tab->cur_mblock->state <= IS_MBSTATE_PARTIAL) - if (read_current_full(tab, tab->cur_mblock) < 0) - return -1; - mbuf = tab->cur_mblock->cur_mbuf; - if (mbuf->cur_record >= mbuf->num) /* top of mbuf */ - { - /* mbuf is reference or full */ - if (mbuf->refcount != 1 || mbuf->offset + (mbuf->num + 1) * - is_keysize(tab->is) > is_mbuf_size[mbuf->type]) - { - oldnext = mbuf->next; - mbuf->next = xmalloc_mbuf(IS_MBUF_TYPE_LARGE); - mbuf->next->next = oldnext; - mbuf = mbuf->next; - tab->cur_mblock->cur_mbuf = mbuf; - mbuf->cur_record = 0; - } - } - else - { - oldnext = mbuf->next; - mbuf->next = xmalloc_mbuf(IS_MBUF_TYPE_MEDIUM); - mbuf->next->next = dmbuf = xmalloc_mbuf(IS_MBUF_TYPE_SMALL); - dmbuf->data = mbuf->data; - dmbuf->next = oldnext; - dmbuf->offset = mbuf->offset + mbuf->cur_record * is_keysize(tab->is); - dmbuf->num = mbuf->num - mbuf->cur_record; - mbuf->num -= dmbuf->num; - mbuf->refcount++; - mbuf = tab->cur_mblock->cur_mbuf = mbuf->next; - mbuf->cur_record = 0; - } - /* - logf (LOG_DEBUG, "is_m_write_rec(rec == %d)", mbuf->cur_record); - */ - memcpy(mbuf->data + mbuf->offset + mbuf->cur_record * is_keysize(tab->is), - rec, is_keysize(tab->is)); - mbuf->num++; - mbuf->cur_record++; - tab->num_records++; - tab->cur_mblock->num_records++; - tab->cur_mblock->state = tab->data->state = IS_MBSTATE_DIRTY; - return 0; -} - -void is_m_unread_record(is_mtable *tab) -{ - assert(tab->cur_mblock->cur_mbuf->cur_record); - if (tab->last_mbuf) - tab->cur_mblock->cur_mbuf = tab->last_mbuf; - else - tab->cur_mblock->cur_mbuf->cur_record--; -} - -/* - * non-destructive read. - */ -int is_m_peek_record(is_mtable *tab, void *rec) -{ - is_mbuf *mbuf; - is_mblock *mblock; - - /* make sure block is all in memory */ - if (tab->cur_mblock->state <= IS_MBSTATE_PARTIAL) - if (read_current_full(tab, tab->cur_mblock) < 0) - return -1; - mblock = tab->cur_mblock; - mbuf = mblock->cur_mbuf; - if (mbuf->cur_record >= mbuf->num) /* are we at end of mbuf? */ - { - if (!mbuf->next) /* end of mblock */ - { - if (mblock->next) - { - mblock = mblock->next; - if (mblock->state <= IS_MBSTATE_PARTIAL) - if (read_current_full(tab, mblock) < 0) - return -1; - mbuf = mblock->data; - } - else - return 0; /* EOTable */ - } - else - mbuf = mbuf->next; - mbuf->cur_record = 0; - } - memcpy(rec, mbuf->data + mbuf->offset + mbuf->cur_record * - is_keysize(tab->is), is_keysize(tab->is)); - return 1; -} - -int is_m_read_record(is_mtable *tab, void *buf, int keep) -{ - is_mbuf *mbuf; - - /* make sure block is all in memory */ - if (tab->cur_mblock->state <= IS_MBSTATE_PARTIAL) - if (read_current_full(tab, tab->cur_mblock) < 0) - return -1; - mbuf = tab->cur_mblock->cur_mbuf; - if (mbuf->cur_record >= mbuf->num) /* are we at end of mbuf? */ - { - if (!mbuf->next) /* end of mblock */ - { - if (!keep && tab->cur_mblock->state == IS_MBSTATE_CLEAN && - tab->cur_mblock->diskpos > 0) - { - xfree_mbufs(tab->cur_mblock->data); - tab->cur_mblock->data = 0; - tab->cur_mblock->state = IS_MBSTATE_UNREAD; - } - if (tab->cur_mblock->next) - { - tab->cur_mblock = tab->cur_mblock->next; - if (tab->cur_mblock->state <= IS_MBSTATE_PARTIAL) - if (read_current_full(tab, tab->cur_mblock) < 0) - return -1; - tab->cur_mblock->cur_mbuf = mbuf = tab->cur_mblock->data; - tab->last_mbuf = 0; - } - else - return 0; /* EOTable */ - } - else - { - tab->last_mbuf = mbuf; - tab->cur_mblock->cur_mbuf = mbuf = mbuf->next; - } - mbuf->cur_record = 0; - } - else - tab->last_mbuf = 0; - memcpy(buf, mbuf->data + mbuf->offset + mbuf->cur_record * - is_keysize(tab->is), is_keysize(tab->is)); - mbuf->cur_record++; - return 1; -} - -/* - * TODO: optimize this function by introducing a higher-level search. - */ -int is_m_seek_record(is_mtable *tab, const void *rec) -{ - char peek[IS_MAX_RECORD]; - int rs; - - for (;;) - { - if (is_m_read_record(tab, &peek, 1) <= 0) - return 1; - if ((rs = (*tab->is->cmp)(peek, rec)) > 0) - { - is_m_unread_record(tab); - return rs; - } - else if (rs == 0) - return 0; - } -} - -int is_m_num_records(is_mtable *tab) -{ - if (tab->data->state < IS_MBSTATE_PARTIAL) - if (read_current_full(tab, tab->data) < 0) - { - logf (LOG_FATAL, "read full failed"); - exit(1); - } - return tab->num_records; -} diff --git a/isam/memory.h b/isam/memory.h deleted file mode 100644 index 77bc660..0000000 --- a/isam/memory.h +++ /dev/null @@ -1,114 +0,0 @@ -/* $Id: memory.h,v 1.8 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#ifndef MEMORY_H -#define MEMORY_H - -#ifdef __cplusplus -extern "C" { -#endif - -extern int is_mbuf_size[3]; - -typedef unsigned int ISAM_P; - -/* - * Memory buffer. Used to manage records (keys) in memory for - * reading and insertion/deletion. - */ -typedef struct is_mbuf -{ - int refcount; - int type; -#define IS_MBUF_TYPE_SMALL 0 -#define IS_MBUF_TYPE_MEDIUM 1 -#define IS_MBUF_TYPE_LARGE 2 - int offset; - int num; - int cur_record; - struct is_mbuf *next; - char *data; /* dummy */ -} is_mbuf; - -/* - * Structure describing the virtual image of a disk block. - * (these blocks may grow beyond the blocksize during insertion). - */ -typedef struct is_mblock -{ - int num_records; /* number of records */ - int diskpos; /* positive if this block is mapped */ - int nextpos; /* pos of nxt blk. Only valid imm aft. rd. */ - int bread; /* number of bytes read */ - int state; /* state of block in rel. to disk block */ -#define IS_MBSTATE_UNREAD 0 /* block hasn't been read */ -#define IS_MBSTATE_PARTIAL 1 /* block has been partially read */ -#define IS_MBSTATE_CLEAN 2 /* block is clean (unmodified) */ -#define IS_MBSTATE_DIRTY 3 /* block has been modified */ - is_mbuf *cur_mbuf; - is_mbuf *data; /* data contained in block */ - - struct is_mblock *next; /* next diskblock */ -} is_mblock; - -typedef struct isam_struct *ISAM; -/* - * Descriptor for a specific table. - */ -typedef struct is_mtable -{ - int num_records; /* total number of records */ - int pos_type; /* blocktype */ - is_mblock *cur_mblock; - is_mbuf *last_mbuf; - is_mblock *data; /* blocks contained in this table */ - ISAM is; -} is_mtable; - -is_mblock *xmalloc_mblock(); -is_mbuf *xmalloc_mbuf(int type); -void xfree_mblock(is_mblock *p); -void xfree_mblocks(is_mblock *l); -void xfree_mbuf(is_mbuf *p); -void xfree_mbufs(is_mbuf *l); -void xrelease_mblock(is_mblock *p); -void is_m_establish_tab(ISAM is, is_mtable *tab, ISAM_P pos); -void is_m_release_tab(is_mtable *tab); -void is_m_rewind(is_mtable *tab); -void is_m_replace_record(is_mtable *tab, const void *rec); -int is_m_write_record(is_mtable *tab, const void *rec); -void is_m_unread_record(is_mtable *tab); -int is_m_read_record(is_mtable *tab, void *buf, int keep); -int is_m_seek_record(is_mtable *tab, const void *rec); -void is_m_delete_record(is_mtable *tab); -int is_m_peek_record(is_mtable *tab, void *rec); -int is_m_read_full(is_mtable *tab, is_mblock *mblock); -int is_m_num_records(is_mtable *tab); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/isam/physical.c b/isam/physical.c deleted file mode 100644 index 48b04c5..0000000 --- a/isam/physical.c +++ /dev/null @@ -1,420 +0,0 @@ -/* $Id: physical.c,v 1.18 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -/* - * This module handles the representation of tables in the bfiles. - */ - -#include -#include -#include - -#include -#include - -static int is_freestore_alloc(ISAM is, int type) -{ - int tmp; - - if (is->types[type].freelist >= 0) - { - tmp = is->types[type].freelist; - if (bf_read(is->types[type].bf, tmp, 0, sizeof(tmp), - &is->types[type].freelist) <=0) - { - logf (LOG_FATAL, "Failed to allocate block"); - exit(1); - } - } - else - tmp = is->types[type].top++; - - logf (LOG_DEBUG, "Allocating block #%d", tmp); - return tmp; -} - -static void is_freestore_free(ISAM is, int type, int block) -{ - int tmp; - - logf (LOG_DEBUG, "Releasing block #%d", block); - tmp = is->types[type].freelist; - is->types[type].freelist = block; - if (bf_write(is->types[type].bf, block, 0, sizeof(tmp), &tmp) < 0) - { - logf (LOG_FATAL, "Failed to deallocate block."); - exit(1); - } -} - -/* this code must be modified to handle an index */ -int is_p_read_partial(is_mtable *tab, is_mblock *block) -{ - int toread; - is_mbuf *buf; - - assert(block->state == IS_MBSTATE_UNREAD); - block->data = buf = xmalloc_mbuf(IS_MBUF_TYPE_LARGE); - toread = tab->is->types[tab->pos_type].blocksize; - if (toread > is_mbuf_size[buf->type]) - { - toread = is_mbuf_size[buf->type]; - block->state = IS_MBSTATE_PARTIAL; - } - else - block->state = IS_MBSTATE_CLEAN; - if (bf_read(tab->is->types[tab->pos_type].bf, block->diskpos, 0, toread, - buf->data) < 0) - { - logf (LOG_FATAL, "bfread failed."); - return -1; - } - /* extract header info */ - buf->offset = 0; - memcpy(&block->num_records, buf->data, sizeof(block->num_records)); - assert(block->num_records > 0); - buf->offset += sizeof(block->num_records); - memcpy(&block->nextpos, buf->data + buf->offset, - sizeof(block->nextpos)); - buf->offset += sizeof(block->nextpos); - if (block == tab->data) /* first block */ - { - memcpy(&tab->num_records, buf->data + buf->offset, - sizeof(tab->num_records)); - buf->offset +=sizeof(tab->num_records); - } - logf(LOG_DEBUG, "R: Block #%d: num %d nextpos %d total %d", - block->diskpos, block->num_records, block->nextpos, - block == tab->data ? tab->num_records : -1); - buf->num = (toread - buf->offset) / is_keysize(tab->is); - if (buf->num >= block->num_records) - { - buf->num = block->num_records; - block->state = IS_MBSTATE_CLEAN; - } - else - block->bread = buf->offset + buf->num * is_keysize(tab->is); - return 0; -} - -int is_p_read_full(is_mtable *tab, is_mblock *block) -{ - is_mbuf *buf; - int dread, toread; - - if (block->state == IS_MBSTATE_UNREAD && is_p_read_partial(tab, block) < 0) - { - logf (LOG_FATAL, "partial read failed."); - return -1; - } - if (block->state == IS_MBSTATE_PARTIAL) - { - buf = block->data; - dread = block->data->num; - while (dread < block->num_records) - { - buf->next = xmalloc_mbuf(IS_MBUF_TYPE_LARGE); - buf = buf->next; - - toread = is_mbuf_size[buf->type] / is_keysize(tab->is); - if (toread > block->num_records - dread) - toread = block->num_records - dread; - - if (bf_read(tab->is->types[tab->pos_type].bf, block->diskpos, block->bread, toread * - is_keysize(tab->is), buf->data) < 0) - { - logf (LOG_FATAL, "bfread failed."); - return -1; - } - buf->offset = 0; - buf->num = toread; - dread += toread; - block->bread += toread * is_keysize(tab->is); - } - block->state = IS_MBSTATE_CLEAN; - } - logf (LOG_DEBUG, "R: Block #%d contains %d records.", block->diskpos, block->num_records); - return 0; -} - -/* - * write dirty blocks to bfile. - * Allocate blocks as necessary. - */ -void is_p_sync(is_mtable *tab) -{ - is_mblock *p; - is_mbuf *b; - int sum, v; - isam_blocktype *type; - - type = &tab->is->types[tab->pos_type]; - for (p = tab->data; p; p = p->next) - { - if (p->state < IS_MBSTATE_DIRTY) - continue; - /* make sure that blocks are allocated. */ - if (p->diskpos < 0) - p->diskpos = is_freestore_alloc(tab->is, tab->pos_type); - if (p->next) - { - if (p->next->diskpos < 0) - p->nextpos = p->next->diskpos = is_freestore_alloc(tab->is, - tab->pos_type); - else - p->nextpos = p->next->diskpos; - } - else - p->nextpos = 0; - sum = 0; - memcpy(type->dbuf, &p->num_records, sizeof(p->num_records)); - sum += sizeof(p->num_records); - memcpy(type->dbuf + sum, &p->nextpos, sizeof(p->nextpos)); - sum += sizeof(p->nextpos); - if (p == tab->data) /* first block */ - { - memcpy(type->dbuf + sum, &tab->num_records, - sizeof(tab->num_records)); - sum += sizeof(tab->num_records); - } - logf (LOG_DEBUG, "W: Block #%d contains %d records.", p->diskpos, - p->num_records); - assert(p->num_records > 0); - for (b = p->data; b; b = b->next) - { - logf(LOG_DEBUG, " buf: offset %d, keys %d, type %d, ref %d", - b->offset, b->num, b->type, b->refcount); - if ((v = b->num * is_keysize(tab->is)) > 0) - memcpy(type->dbuf + sum, b->data + b->offset, v); - - sum += v; - assert(sum <= type->blocksize); - } - if (bf_write(type->bf, p->diskpos, 0, sum, type->dbuf) < 0) - { - logf (LOG_FATAL, "Failed to write block."); - exit(1); - } - } -} - -/* - * Free all disk blocks associated with table. - */ -void is_p_unmap(is_mtable *tab) -{ - is_mblock *p; - - for (p = tab->data; p; p = p->next) - { - if (p->diskpos >= 0) - { - is_freestore_free(tab->is, tab->pos_type, p->diskpos); - p->diskpos = -1; - } - } -} - -static is_mbuf *mbuf_takehead(is_mbuf **mb, int *num, int keysize) -{ - is_mbuf *p = 0, **pp = &p, *inew; - int toget = *num; - - if (!toget) - return 0; - while (*mb && toget >= (*mb)->num) - { - toget -= (*mb)->num; - *pp = *mb; - *mb = (*mb)->next; - (*pp)->next = 0; - pp = &(*pp)->next; - } - if (toget > 0 && *mb) - { - inew = xmalloc_mbuf(IS_MBUF_TYPE_SMALL); - inew->next = (*mb)->next; - (*mb)->next = inew; - inew->data = (*mb)->data; - (*mb)->refcount++; - inew->offset = (*mb)->offset + toget * keysize; - inew->num = (*mb)->num - toget; - (*mb)->num = toget; - *pp = *mb; - *mb = (*mb)->next; - (*pp)->next = 0; - toget = 0; - } - *num -= toget; - return p; -} - -/* - * Split up individual blocks which have grown too large. - * is_p_align and is_p_remap are alternative functions which trade off - * speed in updating versus optimum usage of disk blocks. - */ -void is_p_align(is_mtable *tab) -{ - is_mblock *mblock, *inew, *last = 0, *next; - is_mbuf *mbufs, *mbp; - int blocks, recsblock; - - logf (LOG_DEBUG, "Realigning table."); - for (mblock = tab->data; mblock; mblock = next) - { - next = mblock->next; - if (mblock->state == IS_MBSTATE_DIRTY && mblock->num_records == 0) - { - if (last) - { - last->next = mblock->next; - last->state = IS_MBSTATE_DIRTY; - next = mblock->next; - } - else - { - next = tab->data->next; - if (next) - { - if (next->state < IS_MBSTATE_CLEAN) - { - if (is_p_read_full(tab, next) < 0) - { - logf(LOG_FATAL, "Error during re-alignment"); - abort(); - } - if (next->nextpos && !next->next) - { - next->next = xmalloc_mblock(); - next->next->diskpos = next->nextpos; - next->next->state = IS_MBSTATE_UNREAD; - next->next->data = 0; - } - } - next->state = IS_MBSTATE_DIRTY; /* force re-process */ - tab->data = next; - } - } - if (mblock->diskpos >= 0) - is_freestore_free(tab->is, tab->pos_type, mblock->diskpos); - xrelease_mblock(mblock); - } - else if (mblock->state == IS_MBSTATE_DIRTY && mblock->num_records > - (mblock == tab->data ? - tab->is->types[tab->pos_type].max_keys_block0 : - tab->is->types[tab->pos_type].max_keys_block)) - { - blocks = tab->num_records / - tab->is->types[tab->pos_type].nice_keys_block; - if (tab->num_records % - tab->is->types[tab->pos_type].nice_keys_block) - blocks++; - recsblock = tab->num_records / blocks; - if (recsblock < 1) - recsblock = 1; - mbufs = mblock->data; - while ((mbp = mbuf_takehead(&mbufs, &recsblock, - is_keysize(tab->is))) && recsblock) - { - if (mbufs) - { - inew = xmalloc_mblock(); - inew->diskpos = -1; - inew->state = IS_MBSTATE_DIRTY; - inew->next = mblock->next; - mblock->next = inew; - } - mblock->data = mbp; - mblock->num_records = recsblock; - last = mblock; - mblock = mblock->next; - } - next = mblock; - } - else - last = mblock; - } -} - -/* - * Reorganize data in blocks for minimum block usage and quick access. - * Free surplus blocks. - * is_p_align and is_p_remap are alternative functions which trade off - * speed in updating versus optimum usage of disk blocks. - */ -void is_p_remap(is_mtable *tab) -{ - is_mbuf *mbufs, **bufpp, *mbp; - is_mblock *blockp, **blockpp; - int recsblock, blocks; - - logf (LOG_DEBUG, "Remapping table."); - /* collect all data */ - bufpp = &mbufs; - for (blockp = tab->data; blockp; blockp = blockp->next) - { - if (blockp->state < IS_MBSTATE_CLEAN && is_m_read_full(tab, blockp) < 0) - { - logf (LOG_FATAL, "Read-full failed in remap."); - exit(1); - } - *bufpp = blockp->data; - while (*bufpp) - bufpp = &(*bufpp)->next; - blockp->data = 0; - } - blocks = tab->num_records / tab->is->types[tab->pos_type].nice_keys_block; - if (tab->num_records % tab->is->types[tab->pos_type].nice_keys_block) - blocks++; - if (blocks == 0) - blocks = 1; - recsblock = tab->num_records / blocks + 1; - if (recsblock > tab->is->types[tab->pos_type].nice_keys_block) - recsblock--; - blockpp = &tab->data; - while ((mbp = mbuf_takehead(&mbufs, &recsblock, is_keysize(tab->is))) && - recsblock) - { - if (!*blockpp) - { - *blockpp = xmalloc_mblock(); - (*blockpp)->diskpos = -1; - } - (*blockpp)->data = mbp; - (*blockpp)->num_records = recsblock; - (*blockpp)->state = IS_MBSTATE_DIRTY; - blockpp = &(*blockpp)->next; - } - if (mbp) - xfree_mbufs(mbp); - if (*blockpp) - { - for (blockp = *blockpp; blockp; blockp = blockp->next) - if (blockp->diskpos >= 0) - is_freestore_free(tab->is, tab->pos_type, blockp->diskpos); - xfree_mblocks(*blockpp); - *blockpp = 0; - } -} diff --git a/isam/physical.h b/isam/physical.h deleted file mode 100644 index 02f2f49..0000000 --- a/isam/physical.h +++ /dev/null @@ -1,46 +0,0 @@ -/* $Id: physical.h,v 1.6 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#ifndef PHYSICAL_H -#define PHYSICAL_H - -#include "memory.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void is_p_sync(is_mtable *tab); -void is_p_unmap(is_mtable *tab); -void is_p_align(is_mtable *tab); -void is_p_remap(is_mtable *tab); -int is_p_read_partial(is_mtable *tab, is_mblock *block); -int is_p_read_full(is_mtable *tab, is_mblock *block); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/isam/rootblk.c b/isam/rootblk.c deleted file mode 100644 index 592fecc..0000000 --- a/isam/rootblk.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $Id: rootblk.c,v 1.4 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -/* - * Read and write the blocktype header. - */ - -#include -#include -#include "rootblk.h" - -int is_rb_write(isam_blocktype *ib, is_type_header *hd) -{ - int pt = 0, ct = 0, towrite; - - while ((towrite = sizeof(*hd) - pt) > 0) - { - if (towrite > bf_blocksize(ib->bf)) - towrite = bf_blocksize(ib->bf); - if (bf_write(ib->bf, ct, 0, towrite, (char *)hd + pt) < 0) - return -1; - pt += bf_blocksize(ib->bf); - ct++; - } - return ct; -} - -int is_rb_read(isam_blocktype *ib, is_type_header *hd) -{ - int pt = 0, ct = 0, rs, toread; - - while ((toread = sizeof(*hd) - pt) > 0) - { - if (toread > bf_blocksize(ib->bf)) - toread = bf_blocksize(ib->bf); - if ((rs = bf_read(ib->bf, ct, 0, toread, (char*)hd + pt)) <= 0) - return rs; - pt += bf_blocksize(ib->bf); - ct++; - } - return ct; -} diff --git a/isam/rootblk.h b/isam/rootblk.h deleted file mode 100644 index c1440d3..0000000 --- a/isam/rootblk.h +++ /dev/null @@ -1,49 +0,0 @@ -/* $Id: rootblk.h,v 1.4 2002-08-02 19:26:56 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - - -#ifndef ROOTBLK_H -#define ROOTBLK_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct is_type_header -{ - int blocksize; /* for sanity-checking */ - int keysize; /* -do- */ - int freelist; /* first free block */ - int top; /* first unused block */ -} is_type_header; - -int is_rb_write(isam_blocktype *ib, is_type_header *hd); -int is_rb_read(isam_blocktype *ib, is_type_header *hd); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rset/Makefile.am b/rset/Makefile.am index 1d26827..e06ec8c 100644 --- a/rset/Makefile.am +++ b/rset/Makefile.am @@ -1,7 +1,7 @@ -## $Id: Makefile.am,v 1.7 2004-08-04 08:35:26 adam Exp $ +## $Id: Makefile.am,v 1.8 2004-08-06 13:14:47 adam Exp $ noinst_LIBRARIES = librset.a -librset_a_SOURCES = rset.c rstemp.c rsisam.c rsnull.c rsbool.c rsbetween.c \ +librset_a_SOURCES = rset.c rstemp.c rsnull.c rsbool.c rsbetween.c \ rsisamc.c rsm_or.c rsisams.c rsisamb.c rsprox.c AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC) diff --git a/rset/rsisam.c b/rset/rsisam.c deleted file mode 100644 index d8f7225..0000000 --- a/rset/rsisam.c +++ /dev/null @@ -1,155 +0,0 @@ -/* $Id: rsisam.c,v 1.26 2004-08-03 14:54:41 heikki Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 - Index Data Aps - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -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. -*/ - - -#include -#include -#include -#include - -static void *r_create(RSET ct, const struct rset_control *sel, void *parms); -static RSFD r_open (RSET ct, int flag); -static void r_close (RSFD rfd); -static void r_delete (RSET ct); -static void r_rewind (RSFD rfd); -static int r_read (RSFD rfd, void *buf, int *term_index); -static int r_write (RSFD rfd, const void *buf); - -static const struct rset_control control = -{ - "isam", - r_create, - r_open, - r_close, - r_delete, - r_rewind, - rset_default_forward, - rset_default_pos, - r_read, - r_write, -}; - -const struct rset_control *rset_kind_isam = &control; - -struct rset_ispt_info { - ISPT pt; - struct rset_ispt_info *next; - struct rset_isam_info *info; -}; - -struct rset_isam_info { - ISAM is; - ISAM_P pos; - struct rset_ispt_info *ispt_list; -}; - -static void *r_create(RSET ct, const struct rset_control *sel, void *parms) -{ - rset_isam_parms *pt = (rset_isam_parms *) parms; - struct rset_isam_info *info; - - ct->flags |= RSET_FLAG_VOLATILE; - info = (struct rset_isam_info *) xmalloc (sizeof(struct rset_isam_info)); - info->is = pt->is; - info->pos = pt->pos; - info->ispt_list = NULL; - - ct->no_rset_terms = 1; - ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms)); - ct->rset_terms[0] = pt->rset_term; - return info; -} - -RSFD r_open (RSET ct, int flag) -{ - struct rset_isam_info *info = (struct rset_isam_info *) ct->buf; - struct rset_ispt_info *ptinfo; - - logf (LOG_DEBUG, "risam_open"); - if (flag & RSETF_WRITE) - { - logf (LOG_FATAL, "ISAM set type is read-only"); - return NULL; - } - ptinfo = (struct rset_ispt_info *) xmalloc (sizeof(*ptinfo)); - ptinfo->next = info->ispt_list; - info->ispt_list = ptinfo; - ptinfo->pt = is_position (info->is, info->pos); - ptinfo->info = info; - - if (ct->rset_terms[0]->nn < 0) - ct->rset_terms[0]->nn = is_numkeys (ptinfo->pt); - return ptinfo; -} - -static void r_close (RSFD rfd) -{ - struct rset_isam_info *info = ((struct rset_ispt_info*) rfd)->info; - struct rset_ispt_info **ptinfop; - - for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next) - if (*ptinfop == rfd) - { - is_pt_free ((*ptinfop)->pt); - *ptinfop = (*ptinfop)->next; - xfree (rfd); - return; - } - logf (LOG_FATAL, "r_close but no rfd match!"); - assert (0); -} - -static void r_delete (RSET ct) -{ - struct rset_isam_info *info = (struct rset_isam_info *) ct->buf; - - logf (LOG_DEBUG, "rsisam_delete"); - assert (info->ispt_list == NULL); - rset_term_destroy (ct->rset_terms[0]); - xfree (ct->rset_terms); - xfree (info); -} - -static void r_rewind (RSFD rfd) -{ - logf (LOG_DEBUG, "rsisam_rewind"); - is_rewind( ((struct rset_ispt_info*) rfd)->pt); -} - -/* -static int r_count (RSET ct) -{ - return 0; -} -*/ - -static int r_read (RSFD rfd, void *buf, int *term_index) -{ - *term_index = 0; - return is_readkey( ((struct rset_ispt_info*) rfd)->pt, buf); -} - -static int r_write (RSFD rfd, const void *buf) -{ - logf (LOG_FATAL, "ISAM set type is read-only"); - return -1; -} diff --git a/rset/rsm_or.c b/rset/rsm_or.c index 953c9f8..1fee32e 100644 --- a/rset/rsm_or.c +++ b/rset/rsm_or.c @@ -1,4 +1,4 @@ -/* $Id: rsm_or.c,v 1.17 2004-08-06 12:55:03 adam Exp $ +/* $Id: rsm_or.c,v 1.18 2004-08-06 13:14:47 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -29,7 +29,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include #include #include @@ -62,7 +61,7 @@ struct rset_mor_info { int no_rec; int (*cmp)(const void *p1, const void *p2); ISAMC isc; - ISAM_P *isam_positions; + ISAMC_P *isam_positions; int no_isam_positions; int no_save_positions; @@ -192,7 +191,7 @@ static void *r_create (RSET ct, const struct rset_control *sel, void *parms) info->isc = r_parms->isc; info->no_isam_positions = r_parms->no_isam_positions; - info->isam_positions = (ISAM_P *) + info->isam_positions = (ISAMC_P *) xmalloc (sizeof(*info->isam_positions) * info->no_isam_positions); memcpy (info->isam_positions, r_parms->isam_positions, sizeof(*info->isam_positions) * info->no_isam_positions);