🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #7593

Re: expire performance enhancement

#7593
From: Mike Bird
Date: Tue, 14 May 1996 00:00
215 lines
6769 bytes
A patch was posted here a couple of weeks ago to implement an X flag
in expire.ctl to signify that an article should be removed from all
cross-posts when it expires in the flagged group.

The patch seems to have two problems:

(1) A minor typo causes postings of an article to be removed based on
the expiration of the first posting only.

(2) Removal of some "shouldn't happen" (but apparently necessary) code
results in lots of "Bad Entry" messages during subsequent expires.  We
haven't figured out the exact circumstances under which this occurs.

The following patch has been in use for a week and does the same job.
We haven't noticed any problems.  Remove the previous patch before
applying this.  (This patch is smaller than the original because it is
closer to the original logic of expire.)  (We originally used the
P=Poison flag but have changed to X for compatibility with the
previous patch.)

NOTE: To clean bad entries from the previous patch use something like:

  awk <history >history.n -F '\t' 'NF!=3 || /\t.*\t.*\// {print}'

- then follow the directions for makehistory -r in news-recovery(8).

Your mileage may vary.  Caveat emptor.  ...

======================================== 
--- expire.c.SAFE	Sat Apr 27 17:40:54 1996
+++ expire.c	Mon May  6 07:58:33 1996
@@ -26,7 +26,7 @@
 */
 #define NGH_HASH(Name, p, j)    \
 	for (p = Name, j = 0; *p; ) j = (j << 5) + j + *p++
-#define NGH_SIZE	128
+#define NGH_SIZE	2048
 #define NGH_BUCKET(j)	&NGHtable[j & (NGH_SIZE - 1)]
 
 typedef struct _BUFFER {
@@ -44,6 +44,8 @@
     time_t		Keep;
     time_t		Default;
     time_t		Purge;
+    /* X flag => remove entire article when it expires in this group
*/
+    BOOL                Poison;
 } NEWSGROUP;
 
 typedef struct _NGHASH {
@@ -97,6 +99,8 @@
 
 extern double		atof();
 
+enum KRP {Keep, Remove, Poison};
+
 
 
 /*
@@ -334,6 +338,7 @@
 		ngp->Keep      = v->Keep;
 		ngp->Default   = v->Default;
 		ngp->Purge     = v->Purge;
+		ngp->Poison    = v->Poison;
 		if (EXPverbose > 4) {
 		    (void)printf("%s", ngp->Name);
 		    (void)printf(" %13.13s", ctime(&v->Keep) + 3);
@@ -412,6 +417,7 @@
 	    (void)fprintf(stderr, "Line %d bad modflag\n", i);
 	    return FALSE;
 	}
+	v.Poison = (strchr(fields[1], 'X') != NULL);
 	if (!EXPgetnum(i, fields[2], &v.Keep,    "keep")
 	 || !EXPgetnum(i, fields[3], &v.Default, "default")
 	 || !EXPgetnum(i, fields[4], &v.Purge,   "purge"))
@@ -440,6 +446,7 @@
 	    EXPdefault.Keep    = v.Keep;
 	    EXPdefault.Default = v.Default;
 	    EXPdefault.Purge   = v.Purge;
+	    EXPdefault.Poison  = v.Poison;
 	    SawDefault = TRUE;
 	}
 
@@ -510,7 +517,7 @@
 /*
 **  Should we keep the specified article?
 */
-STATIC BOOL
+STATIC enum KRP
 EXPkeepit(Entry, when, Expires)
     char		*Entry;
     time_t		when;
@@ -522,7 +529,7 @@
     if ((p = strchr(Entry, '/')) == NULL) {
 	(void)fflush(stdout);
 	(void)fprintf(stderr, "Bad entry, \"%s\"\n", Entry);
-	return TRUE;
+	return Keep;
     }
     *p = '\0';
     if ((ngp = NGfind(Entry)) == NULL)
@@ -549,12 +556,17 @@
     }
 
     /* If no expiration, make sure it wasn't posted before the
default. */
-    if (Expires == 0)
-	return when >= ngp->Default;
+    if (Expires == 0) {
+	if (when >= ngp->Default)
+	    return Keep;
 
     /* Make sure it's not posted before the purge cut-off and
      * that it's not due to expire. */
-    return when >= ngp->Purge && (Expires >= Now || when >=
ngp->Keep);
+    } else {
+        if (when >= ngp->Purge && (Expires >= Now || when >=
ngp->Keep))
+	    return Keep;
+    }
+    return ngp->Poison ? Poison : Remove;
 }
 
 
@@ -604,11 +616,12 @@
 **  Do the work of expiring one line.
 */
 STATIC BOOL
-EXPdoline(out, line, length, arts)
+EXPdoline(out, line, length, arts, krps)
     FILE		*out;
     char		*line;
     int			length;
     char		**arts;
+    enum KRP            *krps;
 {
     static char		IGNORING[] = "Ignoring bad line, \"%.20s...\"\n";
     static long		Offset;
@@ -628,6 +641,7 @@
     datum		key;
     datum		value;
     char 		date[20];
+    BOOL                poisoned;
 
     /* Split up the major fields. */
     i = EXPsplit(line, HIS_FIELDSEP, fields, SIZEOF(fields));
@@ -704,6 +718,14 @@
 	    RENEW(New.Data, char, New.Size);
 	}
 
+	/* First check all postings */
+
+	poisoned = FALSE;
+	for (i = 0; i < count; ++i) {
+	  if ((krps[i] = EXPkeepit(arts[i], when, Expires)) == Poison)
+	      poisoned = TRUE;
+	}
+
 	/* The "first" variable tells us if we haven't saved the first
 	 * article yet.  This only matters if we're doing link-saving.
*/
 	first = EXPlinks && count > 1 ? arts[0] : (char *)NULL;
@@ -714,7 +736,7 @@
 	    if (*p == '\0')
 		/* Shouldn't happen. */
 		continue;
-	    if (EXPkeepit(p, when, Expires)) {
+	    if (!poisoned && krps[i] == Keep) {
 		if (EXPverbose > 1)
 		    (void)printf("keep %s\n", p);
 		if (first != NULL) {
@@ -873,6 +895,7 @@
     FILE		*F;
     char		*active;
     char		**arts;
+    enum KRP            *krps;
     STRING		History;
     STRING		HistoryText;
     STRING		HistoryPath;
@@ -1055,6 +1078,7 @@
 
     /* Main processing loop. */
     arts = NEW(char*, nGroups);
+    krps = NEW(enum KRP, nGroups);
     if ((qp = QIOopen(HistoryText, QIO_BUFFER)) == NULL) {
 	(void)fprintf(stderr, "Can't open history file, %s\n",
 		strerror(errno));
@@ -1062,7 +1086,7 @@
     }
     for (Bad = FALSE, line = 1, Paused = FALSE; ; line++) {
 	if ((p = QIOread(qp)) != NULL) {
-	    if (!EXPdoline(out, p, QIOlength(qp), arts)) {
+	    if (!EXPdoline(out, p, QIOlength(qp), arts, krps)) {
 		Bad = TRUE;
 		if (errno == ENOSPC) {
 		    (void)unlink(NHistory);
@@ -1100,6 +1124,7 @@
 	Paused = TRUE;
     }
     QIOclose(qp);
+    DISPOSE(krps);
     DISPOSE(arts);
 
     if (Writing) {


----------------------------------------------------------
 Mike Bird          Tel: 209-742-5000   FAX: 209-966-3177
 President          POP: 209-742-5333   NOC: 209-742-9979 
 Iron Mtn Systems      http://www.ims.mariposa.ca.us/


Technical Details
Message-ID: <4n8oib$4hc@news.ims.mariposa.ca.us>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <Dqp091.7q3@twwells.com> <4m6tue$5rp@sunrise.gv.ssi1.com> <DqrFKK.DCr@twwells.com>

Show Full Headers
Complete Article Headers
Message-ID: <4n8oib$4hc@news.ims.mariposa.ca.us>
Subject: Re: expire performance enhancement
Date: Tue, 14 May 1996 00:00:00 +0000
From: mgb@ims.mariposa.ca.us (Mike Bird)
References: <Dqp091.7q3@twwells.com> <4m6tue$5rp@sunrise.gv.ssi1.com> <DqrFKK.DCr@twwells.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 154677612
Organization: Iron Mtn Systems
Newsgroups: news.software.nntp