/* This file is part of the Zebra server.
- Copyright (C) 1994-2009 Index Data
+ Copyright (C) 1994-2011 Index Data
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
/* eventually this the 0-case code will be removed */
#define FLUSH2 1
-void extract_flush_record_keys2(ZebraHandle zh, zint sysno,
- zebra_rec_keys_t ins_keys,
- zint ins_rank,
- zebra_rec_keys_t del_keys,
- zint del_rank);
+#if FLUSH2
+static void extract_flush_record_keys2(ZebraHandle zh, zint sysno,
+ zebra_rec_keys_t ins_keys,
+ zint ins_rank,
+ zebra_rec_keys_t del_keys,
+ zint del_rank);
+#else
+static void extract_flush_record_keys(ZebraHandle zh, zint sysno,
+ int cmd,
+ zebra_rec_keys_t reckeys,
+ zint staticrank);
+#endif
static void zebra_init_log_level(void)
{
{
struct snip_rec_info *h = p->extractCtrl->handle;
ZebraHandle zh = h->zh;
- zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, p->index_type);
+ zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, p->index_type);
if (zm)
{
return ZEBRA_OK;
}
+void zebra_it_key_str_dump(ZebraHandle zh, struct it_key *key,
+ const char *str, size_t slen, NMEM nmem, int level)
+{
+ char keystr[200]; /* room for zints to print */
+ char *dst_term = 0;
+ int ord = CAST_ZINT_TO_INT(key->mem[0]);
+ const char *index_type;
+ int i;
+ const char *string_index;
+
+ zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type,
+ 0/* db */, &string_index);
+ assert(index_type);
+ zebra_term_untrans_iconv(zh, nmem, index_type,
+ &dst_term, str);
+ *keystr = '\0';
+ for (i = 0; i < key->len; i++)
+ {
+ sprintf(keystr + strlen(keystr), ZINT_FORMAT " ", key->mem[i]);
+ }
+
+ if (*str < CHR_BASE_CHAR)
+ {
+ int i;
+ char dst_buf[200]; /* room for special chars */
+
+ strcpy(dst_buf , "?");
+
+ if (!strcmp(str, ""))
+ strcpy(dst_buf, "alwaysmatches");
+ if (!strcmp(str, FIRST_IN_FIELD_STR))
+ strcpy(dst_buf, "firstinfield");
+ else if (!strcmp(str, CHR_UNKNOWN))
+ strcpy(dst_buf, "unknown");
+ else if (!strcmp(str, CHR_SPACE))
+ strcpy(dst_buf, "space");
+
+ for (i = 0; i<slen; i++)
+ {
+ sprintf(dst_buf + strlen(dst_buf), " %d", str[i] & 0xff);
+ }
+ yaz_log(level, "%s%s %s %s", keystr, index_type,
+ string_index, dst_buf);
+
+ }
+ else
+ yaz_log(level, "%s%s %s \"%s\"", keystr, index_type,
+ string_index, dst_term);
+}
+
void extract_rec_keys_log(ZebraHandle zh, int is_insert,
zebra_rec_keys_t reckeys,
int level)
while(zebra_rec_keys_read(reckeys, &str, &slen, &key))
{
- char keystr[200]; /* room for zints to print */
- char *dst_term = 0;
- int ord = CAST_ZINT_TO_INT(key.mem[0]);
- const char *index_type;
- int i;
- const char *string_index;
-
- zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type,
- 0/* db */, &string_index);
- assert(index_type);
- zebra_term_untrans_iconv(zh, nmem, index_type,
- &dst_term, str);
- *keystr = '\0';
- for (i = 0; i<key.len; i++)
- {
- sprintf(keystr + strlen(keystr), ZINT_FORMAT " ", key.mem[i]);
- }
-
- if (*str < CHR_BASE_CHAR)
- {
- int i;
- char dst_buf[200]; /* room for special chars */
-
- strcpy(dst_buf , "?");
-
- if (!strcmp(str, ""))
- strcpy(dst_buf, "alwaysmatches");
- if (!strcmp(str, FIRST_IN_FIELD_STR))
- strcpy(dst_buf, "firstinfield");
- else if (!strcmp(str, CHR_UNKNOWN))
- strcpy(dst_buf, "unknown");
- else if (!strcmp(str, CHR_SPACE))
- strcpy(dst_buf, "space");
-
- for (i = 0; i<slen; i++)
- {
- sprintf(dst_buf + strlen(dst_buf), " %d", str[i] & 0xff);
- }
- yaz_log(level, "%s%s %s %s", keystr, index_type,
- string_index, dst_buf);
-
- }
- else
- yaz_log(level, "%s%s %s \"%s\"", keystr, index_type,
- string_index, dst_term);
-
+ zebra_it_key_str_dump(zh, &key, str, slen, nmem, level);
nmem_reset(nmem);
}
nmem_destroy(nmem);
}
}
-void extract_flush_record_keys2(ZebraHandle zh, zint sysno,
- zebra_rec_keys_t ins_keys, zint ins_rank,
- zebra_rec_keys_t del_keys, zint del_rank)
+#if FLUSH2
+static void extract_flush_record_keys2(
+ ZebraHandle zh, zint sysno,
+ zebra_rec_keys_t ins_keys, zint ins_rank,
+ zebra_rec_keys_t del_keys, zint del_rank)
{
ZebraExplainInfo zei = zh->reg->zei;
int normal = 0;
}
yaz_log(log_level_extract, "normal=%d optimized=%d", normal, optimized);
}
+#else
+static void extract_flush_record_keys(
+ ZebraHandle zh, zint sysno, int cmd,
+ zebra_rec_keys_t reckeys,
+ zint staticrank)
+{
+ ZebraExplainInfo zei = zh->reg->zei;
+
+ extract_rec_keys_adjust(zh, cmd, reckeys);
+ if (log_level_details)
+ {
+ yaz_log(log_level_details, "Keys for record " ZINT_FORMAT " %s",
+ sysno, cmd ? "insert" : "delete");
+ extract_rec_keys_log(zh, cmd, reckeys, log_level_details);
+ }
+
+ if (!zh->reg->key_block)
+ {
+ int mem = 1024*1024 * atoi( res_get_def( zh->res, "memmax", "8"));
+ const char *key_tmp_dir = res_get_def(zh->res, "keyTmpDir", ".");
+ int use_threads = atoi(res_get_def(zh->res, "threads", "1"));
+ zh->reg->key_block = key_block_create(mem, key_tmp_dir, use_threads);
+ }
+ zebraExplain_recordCountIncrement(zei, cmd ? 1 : -1);
+
+#if 0
+ yaz_log(YLOG_LOG, "sysno=" ZINT_FORMAT " cmd=%d", sysno, cmd);
+ print_rec_keys(zh, reckeys);
+#endif
+ if (zebra_rec_keys_rewind(reckeys))
+ {
+ size_t slen;
+ const char *str;
+ struct it_key key_in;
+ while(zebra_rec_keys_read(reckeys, &str, &slen, &key_in))
+ {
+ key_block_write(zh->reg->key_block, sysno,
+ &key_in, cmd, str, slen,
+ staticrank, zh->m_staticrank);
+ }
+ }
+}
+#endif
ZEBRA_RES zebra_rec_keys_to_snippets1(ZebraHandle zh,
zebra_rec_keys_t reckeys,