Implemented options -f <n> that limits the log to the first <n>
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 12 Feb 1997 20:39:45 +0000 (20:39 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 12 Feb 1997 20:39:45 +0000 (20:39 +0000)
records.
Changed some log messages also.

index/extract.c
index/index.h
index/kinput.c
index/lockidx.c
index/main.c
index/recindex.c
index/trav.c

index a9885fb..611ce7f 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: extract.c,v $
- * Revision 1.67  1996-11-15 15:02:14  adam
+ * Revision 1.68  1997-02-12 20:39:45  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.67  1996/11/15 15:02:14  adam
  * Minor changes regarding logging.
  *
  * Revision 1.66  1996/11/14  09:52:21  adam
@@ -903,7 +908,7 @@ static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
 
 struct recordLogInfo {
     const char *fname;
-    char *op;
+    int recordOffset;
     struct recordGroup *rGroup;
 };
      
@@ -914,9 +919,8 @@ static void recordLogPreamble (int level, const char *msg, void *info)
 
     if (level & LOG_LOG)
         return ;
-    if (p->op) 
-        fprintf (outf, "%s of ", p->op);
-    fprintf (outf, "%s type %s\n", p->rGroup->recordType, p->fname);
+    fprintf (outf, "File %s, offset %d, type %s\n",
+             p->rGroup->recordType, p->recordOffset, p->fname);
     log_event_start (NULL, NULL);
 }
 
@@ -933,11 +937,6 @@ static int recordExtract (SYSNO *sysno, const char *fname,
     Record rec;
     struct recordLogInfo logInfo;
 
-    logInfo.fname = fname;
-    logInfo.op = NULL;
-    logInfo.rGroup = rGroup;
-    log_event_start (recordLogPreamble, &logInfo);
-    
     if (fi->fd != -1)
     {
         /* we are going to read from a file, so prepare the extraction */
@@ -960,24 +959,35 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         extractCtrl.flagShowRecords = rGroup->flagShowRecords;
         if (rGroup->flagShowRecords)
             printf ("File: %s %ld\n", fname, (long) recordOffset);
+
+        logInfo.fname = fname;
+        logInfo.recordOffset = recordOffset;
+        logInfo.rGroup = rGroup;
+        log_event_start (recordLogPreamble, &logInfo);
+
         r = (*recType->extract)(&extractCtrl);
 
+        log_event_start (NULL, NULL);
+
         if (r)      
         {
             /* error occured during extraction ... */
-            if (!rGroup->flagShowRecords)
-                logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r);
+            if (!rGroup->flagShowRecords &&
+                    records_processed < rGroup->fileVerboseLimit)
+            {
+                logf (LOG_WARN, "fail %s %s %ld code = %d", rGroup->recordType,
+                      fname, (long) recordOffset, r);
+            }
             return 0;
         }
         if (reckeys.buf_used == 0)
         {
             /* the extraction process returned no information - the record
-               is probably empty */
-            if (!rGroup->flagShowRecords)
-            {
-                logf (LOG_WARN, "No keys generated for file %s", fname);
-                logf (LOG_WARN, " The file is probably empty");
-            }
+               is probably empty - unless flagShowRecords is in use */
+            if (rGroup->flagShowRecords)
+                return 1;
+            logf (LOG_WARN, "No keys generated for file %s", fname);
+            logf (LOG_WARN, " The file is probably empty");
             return 0;
         }
     }
@@ -1017,8 +1027,7 @@ static int recordExtract (SYSNO *sysno, const char *fname,
             logf (LOG_LOG, "Cannot delete new record");
             return 1;
         }
-        logInfo.op = "add";
-        if (rGroup->fileVerboseFlag)
+        if (records_processed < rGroup->fileVerboseLimit)
             logf (LOG_LOG, "add %s %s %ld", rGroup->recordType,
                   fname, (long) recordOffset);
         rec = rec_new (records);
@@ -1045,14 +1054,15 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         if (deleteFlag)
         {
             /* record going to be deleted */
-            logInfo.op = "delete";
             if (!delkeys.buf_used)
             {
-                logf (LOG_WARN, "cannot delete; storeKeys false");
+                logf (LOG_LOG, "delete %s %s %ld", rGroup->recordType,
+                      fname, (long) recordOffset);
+                logf (LOG_WARN, "cannot delete file above, storeKeys false");
             }
             else
             {
-                if (rGroup->fileVerboseFlag)
+                if (records_processed < rGroup->fileVerboseLimit)
                     logf (LOG_LOG, "delete %s %s %ld", rGroup->recordType,
                           fname, (long) recordOffset);
                 records_deleted++;
@@ -1066,14 +1076,15 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         else
         {
             /* record going to be updated */
-            logInfo.op = "update";
             if (!delkeys.buf_used)
             {
-                logf (LOG_WARN, "cannot update; storeKeys false");
+                logf (LOG_LOG, "update %s %s %ld", rGroup->recordType,
+                      fname, (long) recordOffset);
+                logf (LOG_WARN, "cannot update file above, storeKeys false");
             }
             else
             {
-                if (rGroup->fileVerboseFlag)
+                if (records_processed < rGroup->fileVerboseLimit)
                     logf (LOG_LOG, "update %s %s %ld", rGroup->recordType,
                           fname, (long) recordOffset);
                 flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); 
@@ -1199,7 +1210,7 @@ int fileExtract (SYSNO *sysno, const char *fname,
             sprintf (ext_res, "%srecordType", gprefix);
             if (!(rGroup->recordType = res_get (common_resource, ext_res)))
             {
-                if (rGroup->fileVerboseFlag)
+                if (records_processed < rGroup->fileVerboseLimit)
                     logf (LOG_LOG, "? %s", fname);
                 return 0;
             }
@@ -1207,7 +1218,7 @@ int fileExtract (SYSNO *sysno, const char *fname,
     }
     if (!rGroup->recordType)
     {
-        if (rGroup->fileVerboseFlag)
+        if (records_processed < rGroup->fileVerboseLimit)
             logf (LOG_LOG, "? record %s", fname);
         return 0;
     }
@@ -1285,7 +1296,6 @@ int fileExtract (SYSNO *sysno, const char *fname,
         r = recordExtract (sysno, fname, rGroup, deleteFlag, fi,
                            recType, subType);
     } while (r && !sysno && fi->file_more);
-    log_event_start (NULL, NULL);
     file_read_stop (fi);
     if (fd != -1)
         close (fd);
index fc62511..a82f719 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: index.h,v $
- * Revision 1.47  1996-12-23 15:30:44  adam
+ * Revision 1.48  1997-02-12 20:39:45  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.47  1996/12/23 15:30:44  adam
  * Work on truncation.
  * Bug fix: result sets weren't deleted after server shut down.
  *
@@ -210,7 +215,7 @@ struct recordGroup {
     int  flagStoreData;
     int  flagStoreKeys;
     int  flagShowRecords;
-    int  fileVerboseFlag;
+    int  fileVerboseLimit;
 };
 
 void getFnameTmp (char *fname, int no);
index 8a9fb0e..d356783 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: kinput.c,v $
- * Revision 1.21  1996-11-08 11:10:23  adam
+ * Revision 1.22  1997-02-12 20:39:45  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.21  1996/11/08 11:10:23  adam
  * Buffers used during file match got bigger.
  * Compressed ISAM support everywhere.
  * Bug fixes regarding masking characters in queries.
@@ -640,7 +645,7 @@ void key_input (int nkeys, int cache)
         is_close (isam);
     if (isamc)
         isc_close (isamc);
-    
+   
     for (i = 1; i<=nkeys; i++)
     {
         getFnameTmp (rbuf, i);
index 91b5ddb..286bd41 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: lockidx.c,v $
- * Revision 1.7  1996-10-29 14:08:13  adam
+ * Revision 1.8  1997-02-12 20:39:46  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.7  1996/10/29 14:08:13  adam
  * Uses resource lockDir instead of lockPath.
  *
  * Revision 1.6  1996/03/26 16:01:13  adam
@@ -158,12 +163,11 @@ void zebraIndexLock (int commitNow)
                 logf (LOG_FATAL|LOG_ERRNO, "open %s", path);
                 exit (1);
             }
-            logf (LOG_LOG, "zebraLockNB");
             if (zebraLockNB (lock_fd, 1) == -1)
             {
                 if (errno == EWOULDBLOCK)
                 {
-                    logf (LOG_LOG, "Waiting for other index process");
+                    logf (LOG_LOG, "waiting for other index process");
                     zebraLock (lock_fd, 1);
                     zebraUnlock (lock_fd);
                     close (lock_fd);
@@ -177,11 +181,11 @@ void zebraIndexLock (int commitNow)
             }
             else
             {
-                logf (LOG_WARN, "Unlocked %s", path);
+                logf (LOG_WARN, "unlocked %s", path);
                 r = read (lock_fd, buf, 256);
                 if (r == 0)
                 {
-                    logf (LOG_WARN, "Zero length %s", path);
+                    logf (LOG_WARN, "zero length %s", path);
                     close (lock_fd);
                     unlink (path);
                     continue;
@@ -193,7 +197,7 @@ void zebraIndexLock (int commitNow)
                 }
                 if (*buf == 'r')
                 {
-                    logf (LOG_WARN, "Previous transaction didn't"
+                    logf (LOG_WARN, "previous transaction didn't"
                           " reach commit");
                     close (lock_fd);
                     bf_commitClean ();
@@ -202,7 +206,7 @@ void zebraIndexLock (int commitNow)
                 }
                 else if (*buf == 'd')
                 {
-                    logf (LOG_WARN, "Commit file wan't deleted after commit");
+                    logf (LOG_WARN, "commit file wan't deleted after commit");
                     close (lock_fd);
                     bf_commitClean ();
                     unlink (path);
@@ -210,7 +214,7 @@ void zebraIndexLock (int commitNow)
                 }                    
                 else if (*buf == 'w')
                 {
-                    logf (LOG_WARN, "Your index may be inconsistent");
+                    logf (LOG_WARN, "your index may be inconsistent");
                     exit (1);
                 }
                 else if (*buf == 'c')
@@ -221,13 +225,13 @@ void zebraIndexLock (int commitNow)
                         close (lock_fd);
                         continue;
                     }
-                    logf (LOG_FATAL, "Previous transaction didn't"
+                    logf (LOG_FATAL, "previous transaction didn't"
                           " finish commit. Commit now!");
                     exit (1);
                 }
                 else 
                 {
-                    logf (LOG_FATAL, "Unknown id 0x%02x in %s", *buf,
+                    logf (LOG_FATAL, "unknown id 0x%02x in %s", *buf,
                           path);
                     exit (1);
                 }
index c8e3a28..a4e72d4 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: main.c,v $
- * Revision 1.46  1997-02-10 10:20:13  adam
+ * Revision 1.47  1997-02-12 20:39:46  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.46  1997/02/10 10:20:13  adam
  * Flag fileVerboseFlag set to 0 (default).
  *
  * Revision 1.45  1996/11/08 11:10:26  adam
@@ -205,7 +210,7 @@ int main (int argc, char **argv)
     rGroupDef.flagStoreData = -1;
     rGroupDef.flagStoreKeys = -1;
     rGroupDef.flagShowRecords = 0;
-    rGroupDef.fileVerboseFlag = 0;
+    rGroupDef.fileVerboseLimit = 100000;
 
     prog = *argv;
     if (argc < 2)
@@ -223,15 +228,15 @@ int main (int argc, char **argv)
        " -g <group>    Index files according to group settings.\n"
        " -d <database> Records belong to Z39.50 database <database>.\n"
        " -m <mbytes>   Use <mbytes> before flushing keys to disk.\n"
-        " -n            Don't use shadow system\n"
-       " -s            Show analysis on stdout, but do no work\n"
-       " -v <level>    Set logging to <level>\n"
-        " -V            Show version\n"
+        " -n            Don't use shadow system.\n"
+       " -s            Show analysis on stdout, but do no work.\n"
+       " -v <level>    Set logging to <level>.\n"
+        " -f <n>        Display information for the first <n> records.\n"
+        " -V            Show version.\n"
                  );
         exit (1);
     }
-    log_event_end (abort_func, NULL);
-    while ((ret = options ("sVt:c:g:d:m:v:n", argv, argc, &arg)) != -2)
+    while ((ret = options ("sVt:c:g:d:m:v:nf:", argv, argc, &arg)) != -2)
     {
         if (ret == 0)
         {
@@ -240,11 +245,13 @@ int main (int argc, char **argv)
             {
                 if (!common_resource)
                 {
+                    logf (LOG_LOG, "zebra version %s %s",
+                          ZEBRAVER, ZEBRADATE);
                     common_resource = res_open (configName ?
                                                 configName : FNAME_CONFIG);
                     if (!common_resource)
                     {
-                        logf (LOG_FATAL, "Cannot open resource `%s'",
+                        logf (LOG_FATAL, "cannot open resource `%s'",
                               configName);
                         exit (1);
                     }
@@ -277,19 +284,19 @@ int main (int argc, char **argv)
                     }
                     if (bf_commitExists ())
                     {
-                        logf (LOG_LOG, "Commit start");
+                        logf (LOG_LOG, "commit start");
                         zebraIndexLockMsg ("c");
                         zebraIndexWait (1);
-                        logf (LOG_LOG, "Commit execute");
+                        logf (LOG_LOG, "commit execute");
                         bf_commitExec ();
                         sync ();
                         zebraIndexLockMsg ("d");
                         zebraIndexWait (0);
-                        logf (LOG_LOG, "Commit clean");
+                        logf (LOG_LOG, "commit clean");
                         bf_commitClean ();
                     }
                     else
-                        logf (LOG_LOG, "Nothing to commit");
+                        logf (LOG_LOG, "cothing to commit");
                 }
                 else if (!strcmp (arg, "clean"))
                 {
@@ -298,11 +305,11 @@ int main (int argc, char **argv)
                     {
                         zebraIndexLockMsg ("d");
                         zebraIndexWait (0);
-                        logf (LOG_LOG, "Commit clean");
+                        logf (LOG_LOG, "commit clean");
                         bf_commitClean ();
                     }
                     else
-                        logf (LOG_LOG, "Nothing to clean");
+                        logf (LOG_LOG, "nothing to clean");
                 }
                 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
                 {
@@ -318,7 +325,7 @@ int main (int argc, char **argv)
                 }
                 else
                 {
-                    logf (LOG_FATAL, "Unknown command: %s", arg);
+                    logf (LOG_FATAL, "unknown command: %s", arg);
                     exit (1);
                 }
             }
@@ -326,6 +333,7 @@ int main (int argc, char **argv)
             {
                 struct recordGroup rGroup;
 
+                log_event_end (abort_func, NULL);
                 zebraIndexLock (0);
                 rval = res_get (common_resource, "shadow");
                 if (rval && *rval && !disableCommit)
@@ -346,25 +354,25 @@ int main (int argc, char **argv)
                 {
                 case 'u':
                     key_open (mem_max);
-                    logf (LOG_LOG, "Updating %s", rGroup.path);
+                    logf (LOG_LOG, "updating %s", rGroup.path);
                     repositoryUpdate (&rGroup);
                     nsections = key_close ();
                     break;
                 case 'U':
                     key_open (mem_max);
-                    logf (LOG_LOG, "Updating (pass 1) %s", rGroup.path);
+                    logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
                     repositoryUpdate (&rGroup);
                     key_close ();
                     nsections = 0;
                     break;
                 case 'd':
                     key_open (mem_max);
-                    logf (LOG_LOG, "Deleting %s", rGroup.path);
+                    logf (LOG_LOG, "deleting %s", rGroup.path);
                     repositoryDelete (&rGroup);
                     nsections = key_close ();
                     break;
                 case 's':
-                    logf (LOG_LOG, "Dumping %s", rGroup.path);
+                    logf (LOG_LOG, "dumping %s", rGroup.path);
                     repositoryShow (&rGroup);
                     nsections = 0;
                     break;
@@ -377,38 +385,29 @@ int main (int argc, char **argv)
                 cmd = 0;
                 if (nsections)
                 {
-                    logf (LOG_LOG, "Merging with index");
+                    logf (LOG_LOG, "merging with index");
                     key_input (nsections, 60);
                     sync ();
                 }
+                log_event_end (NULL, NULL);
             }
         }
         else if (ret == 'V')
         {
-            fprintf (stderr, "Zebra %s %s\n",
-                     ZEBRAVER, ZEBRADATE);
+            fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
         }
         else if (ret == 'v')
-        {
             log_init (log_mask_str(arg), prog, NULL);
-        }
         else if (ret == 'm')
-        {
             mem_max = 1024*1024*atoi(arg);
-        }
         else if (ret == 'd')
-        {
             rGroupDef.databaseName = arg;
-        }
        else if (ret == 's')
-       {
            rGroupDef.flagShowRecords = 1;
-            rGroupDef.fileVerboseFlag = 1;
-       }
         else if (ret == 'g')
-        {
             rGroupDef.groupName = arg;
-        }
+        else if (ret == 'f')
+            rGroupDef.fileVerboseLimit = atoi(arg);
         else if (ret == 'c')
             configName = arg;
         else if (ret == 't')
@@ -417,7 +416,7 @@ int main (int argc, char **argv)
             disableCommit = 1;
         else
         {
-            logf (LOG_FATAL, "Unknown option '-%s'", arg);
+            logf (LOG_FATAL, "unknown option '-%s'", arg);
             exit (1);
         }
     }
index 3e562f4..979d067 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: recindex.c,v $
- * Revision 1.16  1996-06-04 10:19:00  adam
+ * Revision 1.17  1997-02-12 20:39:46  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.16  1996/06/04 10:19:00  adam
  * Minor changes - removed include of ctype.h.
  *
  * Revision 1.15  1996/05/13  14:23:06  adam
@@ -498,7 +503,7 @@ Record rec_new (Records p)
 
     assert (p);
     rec = xmalloc (sizeof(*rec));
-    if (p->head.index_free == 0)
+    if (1 || p->head.index_free == 0)
         sysno = (p->head.index_last)++;
     else
     {
index 994445e..b3ffb45 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: trav.c,v $
- * Revision 1.28  1996-11-01 08:58:44  adam
+ * Revision 1.29  1997-02-12 20:39:47  adam
+ * Implemented options -f <n> that limits the log to the first <n>
+ * records.
+ * Changed some log messages also.
+ *
+ * Revision 1.28  1996/11/01 08:58:44  adam
  * Interface to isamc system now includes update and delete.
  *
  * Revision 1.27  1996/10/29 14:06:56  adam
@@ -132,7 +137,7 @@ static void repositoryExtractR (int deleteFlag, char *rep,
     e = dir_open (rep);
     if (!e)
         return;
-    logf (LOG_LOG, "Dir: %s", rep);
+    logf (LOG_LOG, "dir %s", rep);
     if (rep[rep_len-1] != '/')
         rep[rep_len] = '/';
     else
@@ -195,7 +200,7 @@ static void fileUpdateR (struct dirs_info *di, struct dirs_entry *dst,
 
     sprintf (tmppath, "%s%s", base, src);
     e_src = dir_open (tmppath);
-    logf (LOG_LOG, "Dir: %s", tmppath);
+    logf (LOG_LOG, "dir %s", tmppath);
 
 #if 0
     if (!dst || repComp (dst->path, src, src_len))