Fixed bug #944: Allow extraction of multiple records per ES update.
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 13 Mar 2007 13:46:11 +0000 (13:46 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 13 Mar 2007 13:46:11 +0000 (13:46 +0000)
Based on patch from Hans-Werner Hilse.

index/extract.c
index/zebraapi.c
index/zebrasrv.c
test/api/t13.c
test/xslt/xslt2.c

index 51d2b94..65a6be9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: extract.c,v 1.250 2007-03-01 10:35:46 adam Exp $
+/* $Id: extract.c,v 1.251 2007-03-13 13:46:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -319,6 +319,20 @@ static void all_matches_add(struct recExtractCtrl *ctrl)
                               "", 0);
 }
 
+ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, 
+                                       struct ZebraRecStream *stream,
+                                       int delete_flag,
+                                       int test_mode, 
+                                       const char *recordType,
+                                       zint *sysno,
+                                       const char *match_criteria,
+                                       const char *fname,
+                                       int force_update,
+                                       int allow_update,
+                                       RecType recType,
+                                       void *recTypeClientData);
+
+
 ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname, 
                             int deleteFlag)
 {
@@ -417,26 +431,16 @@ ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname,
         streamp = &stream;
         zebra_create_stream_fd(streamp, fd, 0);
     }
-    while(1)
-    {
-        int more = 0;
-        r = zebra_extract_record_stream(zh, streamp,
-                                        deleteFlag,
-                                        0, /* tst_mode */
-                                        zh->m_record_type,
-                                        sysno,
-                                        0, /*match_criteria */
-                                        fname,
-                                        1, /* force_update */
-                                        1, /* allow_update */
-                                        recType, recTypeClientData, &more);
-        if (!more)
-            break;
-       if (sysno)
-       {
-           break;
-       }
-    }
+    r = zebra_extract_records_stream(zh, streamp,
+                                     deleteFlag,
+                                     0, /* tst_mode */
+                                     zh->m_record_type,
+                                     sysno,
+                                     0, /*match_criteria */
+                                     fname,
+                                     1, /* force_update */
+                                     1, /* allow_update */
+                                     recType, recTypeClientData);
     if (streamp)
         stream.destroy(streamp);
     zh->m_record_type = original_record_type;
@@ -465,7 +469,6 @@ ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
     ZEBRA_RES res;
     void *clientData;
     RecType recType = 0;
-    int more = 0;
 
     if (recordType && *recordType)
     {
@@ -496,20 +499,60 @@ ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
 
     zebra_create_stream_mem(&stream, buf, buf_size);
 
-    res = zebra_extract_record_stream(zh, &stream,
-                                      delete_flag,
-                                      test_mode, 
-                                      recordType,
-                                      sysno,
-                                      match_criteria,
-                                      fname,
-                                      force_update,
-                                      allow_update,
-                                      recType, clientData, &more);
+    res = zebra_extract_records_stream(zh, &stream,
+                                       delete_flag,
+                                       test_mode, 
+                                       recordType,
+                                       sysno,
+                                       match_criteria,
+                                       fname,
+                                       force_update,
+                                       allow_update,
+                                       recType, clientData);
     stream.destroy(&stream);
     return res;
 }
 
+ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, 
+                                       struct ZebraRecStream *stream,
+                                       int delete_flag,
+                                       int test_mode, 
+                                       const char *recordType,
+                                       zint *sysno,
+                                       const char *match_criteria,
+                                       const char *fname,
+                                       int force_update,
+                                       int allow_update,
+                                       RecType recType,
+                                       void *recTypeClientData)
+{
+    ZEBRA_RES res = ZEBRA_OK;
+    while (1)
+    {
+        int more = 0;
+        res = zebra_extract_record_stream(zh, stream,
+                                          delete_flag,
+                                          test_mode, 
+                                          recordType,
+                                          sysno,
+                                          match_criteria,
+                                          fname,
+                                          force_update,
+                                          allow_update,
+                                          recType, recTypeClientData, &more);
+        if (!more)
+        {
+            res = ZEBRA_OK;
+            break;
+        }
+        if (res != ZEBRA_OK)
+            break;
+        if (sysno)
+            break;
+    }
+    return res;
+}
+
 
 ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, 
                                       struct ZebraRecStream *stream,
@@ -667,6 +710,13 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh,
             yaz_log (YLOG_WARN, "cannot delete record above (seems new)");
             return ZEBRA_FAIL;
         }
+       else if (!force_update)
+       {
+           yaz_log (YLOG_LOG, "update %s %s " ZINT_FORMAT, recordType,
+                        pr_fname, (zint) start_offset);
+            yaz_log (YLOG_WARN, "cannot update record above (seems new)");
+            return ZEBRA_FAIL;
+       }
        if (show_progress)
            yaz_log (YLOG_LOG, "add %s %s " ZINT_FORMAT, recordType, pr_fname,
                     (zint) start_offset);
index e2cf847..12bbae0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.249 2007-02-24 17:05:40 adam Exp $
+/* $Id: zebraapi.c,v 1.250 2007-03-13 13:46:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -1482,7 +1482,7 @@ ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
                                       &sysno, 
                                       0, /* match */
                                       0, /* fname */
-                                      0, /* force update */
+                                      1, /* force update */
                                       1  /* allow update */
        );
     if (res == ZEBRA_FAIL)
@@ -2305,7 +2305,7 @@ void zebra_set_shadow_enable (ZebraHandle zh, int value)
 ZEBRA_RES zebra_add_record(ZebraHandle zh,
                            const char *buf, int buf_size)
 {
-    return zebra_update_record(zh, 0, 0 /* sysno */, 0, 0, buf, buf_size, 0);
+    return zebra_update_record(zh, 0, 0 /* sysno */, 0, 0, buf, buf_size, 1);
 }
 
 ZEBRA_RES zebra_insert_record(ZebraHandle zh, 
@@ -2331,7 +2331,7 @@ ZEBRA_RES zebra_insert_record(ZebraHandle zh,
                                       recordType,
                                       sysno,   
                                       match, fname,
-                                      0, 
+                                      1, 
                                       0); /* allow_update */
     if (zebra_end_trans(zh) != ZEBRA_OK)
     {
index d798977..0980f8e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebrasrv.c,v 1.10 2007-02-02 13:48:13 adam Exp $
+/* $Id: zebrasrv.c,v 1.11 2007-03-13 13:46:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -712,7 +712,6 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                }
                                break;
                            case 2:
-                           case 4:
                                r = zebra_update_record(
                                    zh,
                                    0, /* recordType */
@@ -721,7 +720,8 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    0, /* fname */
                                    (const char *) rec->u.octet_aligned->buf,
                                    rec->u.octet_aligned->len,
-                                   1);
+                                   0  /* force_update=0: action is a replace, so abort update if no corresponding record exists */
+                                   );
                                if (r == ZEBRA_FAIL)
                                {
                                    rr->errcode =
@@ -746,6 +746,24 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    rr->errstring = "delete_record failed";
                                }
                                break;
+                           case 4:
+                               r = zebra_update_record(
+                                   zh,
+                                   0, /* recordType */
+                                   sysno,
+                                   0, /* match */
+                                   0, /* fname */
+                                   (const char *) rec->u.octet_aligned->buf,
+                                   rec->u.octet_aligned->len,
+                                   1  /* force_update=1: action is a specialUpdate, so allow replace or insert */
+                                   );
+                               if (r == ZEBRA_FAIL)
+                               {
+                                   rr->errcode =
+                                       YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
+                                   rr->errstring = "update_record failed";
+                               }
+                               break;
                            }                           
                        }
                     }
index 3214908..d0d7730 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t13.c,v 1.12 2007-01-15 15:10:20 adam Exp $
+/* $Id: t13.c,v 1.13 2007-03-13 13:46:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -102,7 +102,7 @@ static void tst_no_config(void)
                                     &sysno, 0 /* match */,
                                     0 /* fname */,
                                     xml_buf, strlen(xml_buf),
-                                    0 /* force_update */),
+                                    1 /* force_update */),
              ZEBRA_OK);
 
     zebra_close(zh);
index d45bb31..ece3504 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xslt2.c,v 1.12 2007-01-15 15:10:26 adam Exp $
+/* $Id: xslt2.c,v 1.13 2007-03-13 13:46:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -71,7 +71,7 @@ static void tst(int argc, char **argv)
     YAZ_CHECK(tl_init_data(zh, records_array));
 
     /* only get hits from first record .. */
-    YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
+    YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));