From 6a395dd488e0f34f54ea44bafcde9c959292c252 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 30 Jun 2003 19:37:12 +0000 Subject: [PATCH] Implemented drop database --- include/zebraapi.h | 4 +- index/extract.c | 7 ++-- index/main.c | 22 +++++++++-- index/zebraapi.c | 55 +++++++++++++++++++++++++-- index/zebrash.c | 50 +++++++++++++++++++++---- index/zinfo.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++-- index/zinfo.h | 7 +++- 7 files changed, 224 insertions(+), 25 deletions(-) diff --git a/include/zebraapi.h b/include/zebraapi.h index d619baf..9818c4c 100644 --- a/include/zebraapi.h +++ b/include/zebraapi.h @@ -1,4 +1,4 @@ -/* $Id: zebraapi.h,v 1.8 2003-06-20 14:21:23 heikki Exp $ +/* $Id: zebraapi.h,v 1.9 2003-06-30 19:37:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -184,7 +184,7 @@ YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id, */ YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db); - +YAZ_EXPORT int zebra_drop_database (ZebraHandle zh, const char *db); YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh); YAZ_EXPORT int zebra_admin_start (ZebraHandle zh); diff --git a/index/extract.c b/index/extract.c index e325528..5a179b8 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.144 2003-04-15 16:46:18 adam Exp $ +/* $Id: extract.c,v 1.145 2003-06-30 19:37:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -1303,8 +1303,9 @@ int explain_extract (void *handle, Record rec, data1_node *n) extractCtrl.zebra_maps = zh->reg->zebra_maps; extractCtrl.flagShowRecords = 0; extractCtrl.handle = handle; - - grs_extract_tree(&extractCtrl, n); + + if (n) + grs_extract_tree(&extractCtrl, n); if (rec->size[recInfo_delKeys]) { diff --git a/index/main.c b/index/main.c index cf2546d..11dbfb3 100644 --- a/index/main.c +++ b/index/main.c @@ -1,5 +1,5 @@ -/* $Id: main.c,v 1.104 2003-05-20 21:39:57 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: main.c,v 1.105 2003-06-30 19:37:12 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps This file is part of the Zebra server. @@ -96,6 +96,8 @@ int main (int argc, char **argv) " update Update index with files below .\n" " If is empty filenames are read from stdin.\n" " delete Delete index with files below .\n" + " create Create database \n" + " drop Drop database \n" " commit Commit changes\n" " clean Clean shadow files\n" "Options:\n" @@ -172,6 +174,14 @@ int main (int argc, char **argv) { zebra_init (zh); } + else if (!strcmp(arg, "drop")) + { + cmd = 'D'; + } + else if (!strcmp(arg, "create")) + { + cmd = 'C'; + } else if (!strcmp (arg, "commit")) { zebra_commit (zh); @@ -184,7 +194,7 @@ int main (int argc, char **argv) { zebra_register_statistics (zh,0); } - else if (!strcmp (arg, "dump") || !strcmp (arg, "dumpdict")) + else if (!strcmp (arg, "dumpdict")) { zebra_register_statistics (zh,1); } @@ -221,6 +231,12 @@ int main (int argc, char **argv) zebra_repository_show (zh); nsections = 0; break; + case 'C': + zebra_create_database(zh, rGroupDef.path); + break; + case 'D': + zebra_drop_database(zh, rGroupDef.path); + break; default: nsections = 0; } diff --git a/index/zebraapi.c b/index/zebraapi.c index 750c326..31c7a9c 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.108 2003-06-23 14:35:41 heikki Exp $ +/* $Id: zebraapi.c,v 1.109 2003-06-30 19:37:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -1098,11 +1098,59 @@ int zebra_admin_exchange_record (ZebraHandle zh, return 0; } +int delete_w_handle(const char *info, void *handle) +{ + ZebraHandle zh = (ZebraHandle) handle; + ISAMC_P pos; + + if (*info == sizeof(pos)) + { + memcpy (&pos, info+1, sizeof(pos)); + isamb_unlink(zh->reg->isamb, pos); + } + return 0; +} + +static int delete_SU_handle(void *handle, int ord) +{ + ZebraHandle zh = (ZebraHandle) handle; + char ord_buf[20]; + int ord_len; + + ord_len = key_SU_encode (ord, ord_buf); + ord_buf[ord_len] = '\0'; + + assert (zh->reg->isamb); + dict_delete_subtree(zh->reg->dict, ord_buf, + zh, delete_w_handle); + return 0; +} + +int zebra_drop_database (ZebraHandle zh, const char *database) +{ + ASSERTZH; + yaz_log(LOG_API,"zebra_drop_database"); + zh->errCode = 0; + + if (zebra_select_database (zh, database)) + return -1; + if (zebra_begin_trans (zh, 1)) + return -1; + if (zh->reg->isamb) + { + zebraExplain_curDatabase (zh->reg->zei, database); + + zebraExplain_trav_ord(zh->reg->zei, zh, delete_SU_handle); + zebraExplain_removeDatabase(zh->reg->zei, zh); + } + zebra_end_trans (zh); + return 0; +} + int zebra_create_database (ZebraHandle zh, const char *database) { - ZebraService zs; ASSERTZH; - yaz_log(LOG_API,"zebra_admin_create"); + yaz_log(LOG_API,"zebra_create_database"); zh->errCode=0; if (zebra_select_database (zh, database)) @@ -1110,7 +1158,6 @@ int zebra_create_database (ZebraHandle zh, const char *database) if (zebra_begin_trans (zh, 1)) return -1; - zs = zh->service; /* announce database */ if (zebraExplain_newDatabase (zh->reg->zei, database, 0 /* explainDatabase */)) diff --git a/index/zebrash.c b/index/zebrash.c index f86abad..b4ee5d9 100644 --- a/index/zebrash.c +++ b/index/zebrash.c @@ -1,10 +1,29 @@ -/* zebrash.c - command-line interface to zebra API - * $Id: zebrash.c,v 1.13 2003-06-23 15:38:16 adam Exp $ - * - * Copyrigth 2003 Index Data Aps - * - */ - +/* $Id: zebrash.c,v 1.14 2003-06-30 19:37:12 adam Exp $ + Copyright (C) 2002,2003 + 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. +*/ + +/* + zebrash.c - command-line interface to zebra API +*/ + #include #include #include @@ -295,6 +314,18 @@ static int cmd_create_database( char *args[], char *outbuff) return zebra_create_database(zh, db); } +static int cmd_drop_database( char *args[], char *outbuff) +{ + char *db=args[1]; + if (!db) + db="Default"; + strcat(outbuff,"Dropping database "); + strcat(outbuff,db); + strcat(outbuff,"\n"); + + return zebra_drop_database(zh, db); +} + static int cmd_begin_trans( char *args[], char *outbuff) { int rw=0; @@ -437,8 +468,11 @@ struct cmdstruct cmds[] = { "Selects a database", cmd_select_database}, { "create_database", "basename", - "Creates a database", + "Create database", cmd_create_database}, + { "drop_database", "basename", + "Drop database", + cmd_drop_database}, { "begin_trans", "[rw]", "Begins a transaction. rw=1 means write, otherwise read-only", cmd_begin_trans}, diff --git a/index/zinfo.c b/index/zinfo.c index de9be50..67060ef 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -1,5 +1,5 @@ -/* $Id: zinfo.c,v 1.36 2003-01-15 07:26:40 oleg Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: zinfo.c,v 1.37 2003-06-30 19:37:12 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps This file is part of the Zebra server. @@ -20,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #include #include #include @@ -273,6 +271,52 @@ void zebraExplain_mergeAccessInfo (ZebraExplainInfo zei, data1_node *n, } } +/* Explain structure + root record + of type targetInfo + and has sysno = 1 + + databaseList (list of databases) +*/ +/* +Example root: +explain: + targetInfo: TargetInfo + name: Zebra + namedResultSets: 1 + multipleDbSearch: 1 + nicknames: + name: Zebra + commonInfo: + dateAdded: 20030630190601 + dateChanged: 20030630190601 + languageCode: EN + accessinfo: + unitSystems: + string: ISO + attributeSetIds: + oid: 1.2.840.10003.3.2 + oid: 1.2.840.10003.3.5 + oid: 1.2.840.10003.3.1 + schemas: + oid: 1.2.840.10003.13.1000.81.2 + oid: 1.2.840.10003.13.2 + zebraInfo: + version: 1.3.12 + databaseList: + database: + name: Default + id: 50 + attributeDetailsId: 51 + database: + name: IR-Explain-1 + id: 52 + attributeDetailsId: 53 + ordinalSU: 38 + runNumber: 1 +nextResultSetPosition = 2 +*/ + ZebraExplainInfo zebraExplain_open ( Records records, data1_handle dh, Res res, @@ -598,6 +642,45 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei, rec_rm (&rec); } +int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *update_handle) +{ + struct zebDatabaseInfoB **zdip = &zei->databaseInfo; + + while (*zdip) + { + if (*zdip == zei->curDatabaseInfo) + { + struct zebDatabaseInfoB *zdi = *zdip; + Record rec; + + zei->dirty = 1; + zei->updateHandle = update_handle; + + if (zdi->attributeDetails) + { + /* remove attribute details keys and delete it */ + zebAttributeDetails zad = zdi->attributeDetails; + + rec = rec_get(zei->records, zad->sysno); + (*zei->updateFunc)(zei->updateHandle, rec, 0); + rec_rm(&rec); + } + /* remove database record keys and delete it */ + rec = rec_get (zei->records, zdi->sysno); + (*zei->updateFunc)(zei->updateHandle, rec, 0); + rec_rm(&rec); + + /* remove from list */ + *zdip = zdi->next; + + /* current database is IR-Explain-1 */ + return 0; + } + zdip = &(*zdip)->next; + } + return -1; +} + int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database) { struct zebDatabaseInfoB *zdi; @@ -1227,6 +1310,19 @@ int zebraExplain_lookupSU (ZebraExplainInfo zei, int set, int use) return -1; } +int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle, + int (*f)(void *handle, int ord)) +{ + struct zebDatabaseInfoB *zdb = zei->curDatabaseInfo; + if (zdb) + { + struct zebSUInfoB *zsui = zdb->attributeDetails->SUInfo; + for ( ;zsui; zsui = zsui->next) + (*f)(handle, zsui->info.ordinal); + } + return 0; +} + int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord, const char **db, int *set, int *use) { diff --git a/index/zinfo.h b/index/zinfo.h index 2f75d5a..25b9c4f 100644 --- a/index/zinfo.h +++ b/index/zinfo.h @@ -1,4 +1,4 @@ -/* $Id: zinfo.h,v 1.15 2002-10-22 12:51:08 adam Exp $ +/* $Id: zinfo.h,v 1.16 2003-06-30 19:37:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -55,6 +55,11 @@ void zebraExplain_flush (ZebraExplainInfo zei, void *updateHandle); int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord, const char **db, int *set, int *use); +int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle, + int (*f)(void *handle, int ord)); + +int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *updateHandle); + typedef struct { int recordSize; off_t recordOffset; -- 1.7.10.4