X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fextract.c;h=412bc6654ff9374987ddcbe9acfb585b2dfb9f57;hb=23b1af194b14847f3ba187e3c5c3015797ad3c4a;hp=09902fdbfdb3a386a209a8ff5e9e780c22b08d49;hpb=2a6f64379961f30bfe6376964ce279ab5242da1f;p=idzebra-moved-to-github.git diff --git a/index/extract.c b/index/extract.c index 09902fd..412bc66 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.147 2004-01-22 11:27:21 adam Exp $ +/* $Id: extract.c,v 1.149 2004-01-22 15:40:25 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -423,7 +423,7 @@ static int file_extract_record(ZebraHandle zh, { RecordAttr *recordAttr; int r; - char *matchStr; + const char *matchStr; SYSNO sysnotmp; Record rec; off_t recordOffset = 0; @@ -846,7 +846,7 @@ int buffer_extract_record (ZebraHandle zh, RecordAttr *recordAttr; struct recExtractCtrl extractCtrl; int i, r; - char *matchStr = 0; + const char *matchStr = 0; RecType recType = NULL; char subType[1024]; void *clientData; @@ -953,20 +953,22 @@ int buffer_extract_record (ZebraHandle zh, if (! *sysno) { char *rinfo; if (match_criteria && *match_criteria) { - matchStr = (char *)match_criteria; + matchStr = match_criteria; } else { if (zh->m_record_id && *zh->m_record_id) { matchStr = fileMatchStr (zh, &zh->reg->keys, pr_fname, zh->m_record_id); + if (!matchStr) + { + logf (LOG_WARN, "Bad match criteria (recordID)"); + return 1; + } } } if (matchStr) { rinfo = dict_lookup (zh->reg->matchDict, matchStr); if (rinfo) memcpy (sysno, rinfo+1, sizeof(*sysno)); - } else { - logf (LOG_WARN, "Bad match criteria (recordID)"); - return 0; } } @@ -1280,7 +1282,7 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, #endif if (zh->reg->key_buf_used + 1024 > (zh->reg->ptr_top -zh->reg->ptr_i)*sizeof(char*)) - extract_flushWriteKeys (zh); + extract_flushWriteKeys (zh,0); ++(zh->reg->ptr_i); (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] = (char*)zh->reg->key_buf + zh->reg->key_buf_used; @@ -1317,24 +1319,60 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, assert (off == reckeys->buf_used); } -void extract_flushWriteKeys (ZebraHandle zh) +void extract_flushWriteKeys (ZebraHandle zh, int final) + /* optimizing: if final=1, and no files written yet */ + /* push the keys directly to merge, sidestepping the */ + /* temp file altogether. Speeds small updates */ { FILE *outf; char out_fname[200]; char *prevcp, *cp; struct encode_info encode_info; int ptr_i = zh->reg->ptr_i; + int temp_policy; #if SORT_EXTRA int i; #endif if (!zh->reg->key_buf || ptr_i <= 0) + { + logf (LOG_DEBUG, " nothing to flush section=%d buf=%p i=%d", + zh->reg->key_file_no, zh->reg->key_buf, ptr_i); + logf (LOG_DEBUG, " buf=%p ", + zh->reg->key_buf); + logf (LOG_DEBUG, " ptr=%d ",zh->reg->ptr_i); + logf (LOG_DEBUG, " reg=%p ",zh->reg); + return; + } (zh->reg->key_file_no)++; logf (LOG_LOG, "sorting section %d", (zh->reg->key_file_no)); + logf (LOG_DEBUG, " sort_buff at %p n=%d", + zh->reg->key_buf + zh->reg->ptr_top - ptr_i,ptr_i); #if !SORT_EXTRA qsort (zh->reg->key_buf + zh->reg->ptr_top - ptr_i, ptr_i, sizeof(char*), key_qsort_compare); + + /* Case 1: always use temp files (old way) */ + /* Case 2: use temp files, if more than one (auto) */ + /* = if this is both the last and the first */ + /* Case 3: never bother with temp files (new) */ + temp_policy=2; + /* FIXME - will come from config file into zh */ + + if ( ( temp_policy ==3 ) || /* always from memory */ + ( ( temp_policy ==2 ) && /* automatic */ + (zh->reg->key_file_no == 1) && /* this is first time */ + (final) ) ) /* and last (=only) time */ + { /* go directly from memory */ + zh->reg->key_file_no =0; /* signal not to read files */ + zebra_index_merge(zh); + zh->reg->ptr_i = 0; + zh->reg->key_buf_used = 0; + return; /*!*/ + } + + /* Not doing directly from memory, write into a temp file */ extract_get_fname_tmp (zh, out_fname, zh->reg->key_file_no); if (!(outf = fopen (out_fname, "wb")))